0%

I used to use spacemacs as my daily environment for developing. Spacemacs is powerful and fancy. But sometimes I have to accept it’s concept and common usages. Yesterday I tried to upgrade my Emacs from 25 to 27 which broke the spacemacs config. Then I think it’s a good time to learn more detail about Emacs. So I decide to write my own config from the scratch.

It will be time cost but maybe it’s worth to do it. I would like to have fully control over the powerful Emacs ;)

This blog will keep updating as my simple .emacs file growing. Thanks for every suggestion and tutorial. I will later list all the resources and tutorials I have met during the configuration.

Features

  1. multiple cursor operations
  2. Alt+arrow key to jump between windows
  3. Alt+num (0~8) to switch to windows directly
  4. Side-bar imenu

flymake settings

  1. global config file is under ~/.config/flake8

TODO

  • C++ language support
  • better M-x menu
  • select multiple words and edit
  • better fuzzy search
  • add ivy for search
  • window management. restore or forth to windows status. save windows status
  • general jump in buffer. save bookmark etc.

Language support packages

Python

  1. python programming in emacs
  2. Elpy The package I used in this configuration.

shortcuts

.emacs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

;;; HOW TO DEBUG
;;; (toggle-debug-on-error)
;;; (toggle-debug-on-quit)


(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes
'("04232a0bfc50eac64c12471607090ecac9d7fd2d79e388f8543d1c5439ed81f5" "6e70d505e0957aaa67562ff0487b7b1b1e10f879655f2c47adf85949790fb687" default))
'(display-line-numbers t)
'(nil nil t)
'(package-selected-packages
'(magit-stgit counsel-projectile projectile zenburn-theme zenburn magit go-mode counsel ivy-hydra imenus multiple-cursors imenu-list use-package elpy winum)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(org-document-title ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 2.0 :underline nil))))
'(org-level-1 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.75))))
'(org-level-2 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.5))))
'(org-level-3 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.25))))
'(org-level-4 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif" :height 1.1))))
'(org-level-5 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif"))))
'(org-level-6 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif"))))
'(org-level-7 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif"))))
'(org-level-8 ((t (:inherit default :weight bold :foreground "black" :family "Sans Serif")))))

;; load emacs 24's package system. Add MELPA repository.
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
;; '("melpa" . "http://stable.melpa.org/packages/") ; many packages won't show if using stable
'("melpa" . "http://melpa.org/packages/")
t))
(package-initialize)

;; create prefix key. M-m
(define-prefix-command 'M-m
)
(global-set-key (kbd "M-m") M-m)

;; split window
(global-set-key (kbd "M-m w -") 'split-window-vertically)
(global-set-key (kbd "M-m w /") 'split-window-horizontally)


;; M-[arrow] jump to
;; use-package bind-key shortcuts instead of global-set-key to prevent major mode overwrite global key settings
;; from https://emacs.stackexchange.com/questions/352/how-to-override-major-mode-bindings
(global-set-key (kbd "M-<left>") 'windmove-left)
(global-set-key (kbd "M-<right>") 'windmove-right)
(global-set-key (kbd "M-<up>") 'windmove-up)
(global-set-key (kbd "M-<down>") 'windmove-down)

;; M-num jump to window directly
(global-set-key (kbd "C-`") 'winum-select-window-by-number)
(global-set-key (kbd "C-²") 'winum-select-window-by-number)
(global-set-key (kbd "M-0") 'winum-select-window-0-or-10)
(global-set-key (kbd "M-1") 'winum-select-window-1)
(global-set-key (kbd "M-2") 'winum-select-window-2)
(global-set-key (kbd "M-3") 'winum-select-window-3)
(global-set-key (kbd "M-4") 'winum-select-window-4)
(global-set-key (kbd "M-5") 'winum-select-window-5)
(global-set-key (kbd "M-6") 'winum-select-window-6)
(global-set-key (kbd "M-7") 'winum-select-window-7)
(global-set-key (kbd "M-8") 'winum-select-window-8)

(require 'winum)
(defun winum-assign-9-to-calculator-8-to-flycheck-errors ()
(cond
((equal (buffer-name) "*Calculator*") 9)
((equal (buffer-name) "*Flycheck errors*") 8)))

(defun winum-assign-0-to-neotree ()
(when (string-match-p (buffer-name) ".*\\*NeoTree\\*.*") 10))

(add-to-list 'winum-assign-functions #'winum-assign-9-to-calculator-8-to-flycheck-errors)
(add-to-list 'winum-assign-functions #'winum-assign-0-to-neotree)

(set-face-attribute 'winum-face nil :weight 'bold)


(setq window-numbering-scope 'global
winum-reverse-frame-list nil
winum-auto-assign-0-to-minibuffer t
winum-assign-func 'my-winum-assign-func
winum-auto-setup-mode-line t
winum-format " %s "
winum-mode-line-position 1
winum-ignored-buffers '(" *which-key*"))

(winum-mode)

;; python
;; elpy
(elpy-enable)
;; disable shortcuts under elpy-mode, these are conflit with windows management and not so useful
(define-key elpy-mode-map (kbd "M-<left>") nil)
(define-key elpy-mode-map (kbd "M-<right>") nil)
(define-key elpy-mode-map (kbd "M-<up>") nil)
(define-key elpy-mode-map (kbd "M-<down>") nil)


;; windows management
;; use 'winner-mode' to redo and undo windows. This is usefull when you want to maxinum one window and back to multiple windows later.
;; winner-redo C-c <right>
;; winner-undo C-c <left>
(winner-mode 1)


;; imenu-list
;; shortcuts: Ctrl-'

(use-package imenu-list
:ensure t
:bind ("C-." . imenu-list-minor-mode)
:config
(setq imenu-list-focus-after-activation t))

(global-set-key (kbd "C-'") 'imenu-list-smart-toggle)


;; use which-function-mode to show where I am. usefull when function/class is huge
(which-function-mode)
;; when it cannot determinted, show n/a instead of ???
(setq which-func-unknown "n/a")
;; show the position on top
(setq-default header-line-format
'((which-func-mode ("" which-func-format " "))))
(setq mode-line-misc-info
;; We remove Which Function Mode from the mode line, because it's mostly
;; invisible here anyway.
(assq-delete-all 'which-func-mode mode-line-misc-info))


;; multiple-cursors
;; mark different lines/words and edit: 1. select the word. 2. C-> to select next lines

(require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)


;; ivy search
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
(global-set-key "\C-s" 'swiper)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> l") 'counsel-find-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c j") 'counsel-git-grep)
(global-set-key (kbd "C-c k") 'counsel-ag)
(global-set-key (kbd "C-x l") 'counsel-locate)
(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)


(global-set-key (kbd "C-s-<right>") (lambda () (interactive) (enlarge-window-horizontally 5)))
(global-set-key (kbd "C-s-<left>") (lambda () (interactive) (shrink-window-horizontally 5)))
(global-set-key (kbd "C-s-<up>") (lambda () (interactive) (enlarge-window 5)))
(global-set-key (kbd "C-s-<down>") (lambda () (interactive) (shrink-window 5)))


;; ;; projectile
;; ;; (projectile-mode)
;; (counsel-projectile-mode 1)
;; (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
;; ;; set completion option
;; (setq projectile-completion-system 'ivy)
;; (setq 'projectile-globally-ignored-directories '(".git"
;; ".svn"
;; ".venv"))

;; (setq 'projectile-globally-ignored-files '(".pyc"
;; "~"))


;; (let ((projectile-project-root-files-top-down-recurring '(".git"))))
;; ;; enable projectile caching
;; (setq projectile-enable-caching t)
;; (setq projectile-use-native-indexing t)


;;====================================
;; Searching
;;====================================

;; use counsel-git to find file under current git repo
;; C-c g (counsel-git)


;; search buffer
;; I know that string is in my Emacs somewhere!
(require 'cl)
(defcustom search-all-buffers-ignored-files (list (rx-to-string '(and bos (or ".bash_history" "TAGS") eos)))
"Files to ignore when searching buffers via \\[search-all-buffers]."
:type 'editable-list)

(require 'grep)
(defun search-all-buffers (regexp prefix)
"Searches file-visiting buffers for occurence of REGEXP. With
prefix > 1 (i.e., if you type C-u \\[search-all-buffers]),
searches all buffers."
(interactive (list (grep-read-regexp)
current-prefix-arg))
(message "Regexp is %s; prefix is %s" regexp prefix)
(multi-occur
(if (member prefix '(4 (4)))
(buffer-list)
(remove-if
(lambda (b) (some (lambda (rx) (string-match rx (file-name-nondirectory (buffer-file-name b)))) search-all-buffers-ignored-files))
(remove-if-not 'buffer-file-name (buffer-list))))

regexp))

(global-set-key [f7] 'search-all-buffers)


;; hide welcome screen, show scratch directly
(setq inhibit-startup-screen t)

;; enable code folding by using hideshow
;; https://www.emacswiki.org/emacs/HideShow
;; C-c @ C-M-s show all
;; C-c @ C-M-h hide all
;; C-c @ C-s show block
;; C-c @ C-h hide block
;; C-c @ C-c toggle hide/show
;; (hs-minor-mode t)


;;
;; flymake
;; Finding Syntax Errors On The Fly
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Flymake.html
(define-key flymake-mode-map (kbd "M-n") 'flymake-goto-next-error)
(define-key flymake-mode-map (kbd "M-p") 'flymake-goto-prev-error)

;;
;; c++ mode setting up
;;
;; mapping for file extension and mode
;; set .h header file open in c++ mode
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))

(defun bucketzxm-c++-mode-hook ()
(setq c-basic-offset 4)
(c-set-offset 'substatement-open 0))

(add-hook 'c++-mode-hook 'bucketzxm-c++-mode-hook)


;;
;; markdown
;;
;; M-x (flymd-flyit) to start a browser
(require 'flymd)
(setq flymd-output-directory "/tmp")
;; set browser to firefox due to compatibility problem
;; https://github.com/mola-T/flymd/blob/master/browser.md#user-content-chrome-windows-or-uix
(defun my-flymd-browser-function (url)
(let ((browse-url-browser-function 'browse-url-firefox))
(browse-url url)))
(setq flymd-browser-open-function 'my-flymd-browser-function)



;;
;; org-mode
;;
;; reference: https://zzamboni.org/post/beautifying-org-mode-in-emacs/
;;

;; hide the emphasis markup(e.g. /.../ for italics
(setq org-hide-emphasis-markers t)

;; set font-lock subsitution for list markers (use - for list)
(font-lock-add-keywords 'org-mode
'(("^ *\\([-]\\) "
(0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
;; replace all headlines markers with different Unicode bullets
(use-package org-bullets
:config
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

;; set up a nice proportional font, in different sizes, for the headlines.
(let* ((variable-tuple
(cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
((x-list-fonts "Verdana") '(:font "Verdana"))
((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
(nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro."))))
(base-font-color (face-foreground 'default nil 'default))
(headline `(:inherit default :weight bold :foreground ,base-font-color)))

(custom-theme-set-faces
'user
`(org-level-8 ((t (,@headline ,@variable-tuple))))
`(org-level-7 ((t (,@headline ,@variable-tuple))))
`(org-level-6 ((t (,@headline ,@variable-tuple))))
`(org-level-5 ((t (,@headline ,@variable-tuple))))
`(org-level-4 ((t (,@headline ,@variable-tuple :height 1.1))))
`(org-level-3 ((t (,@headline ,@variable-tuple :height 1.25))))
`(org-level-2 ((t (,@headline ,@variable-tuple :height 1.5))))
`(org-level-1 ((t (,@headline ,@variable-tuple :height 1.75))))
`(org-document-title ((t (,@headline ,@variable-tuple :height 2.0 :underline nil))))))


;; change default font
(add-to-list 'default-frame-alist
'(font . "Fira Code-12:Regular"))

;; get a good theme
;; (add-to-list 'custom-theme-load-path "~/.emacs.d/themes/zenburn")
;; (load-theme 'zenburn 1)

剁手Realforce R2TLA 键盘

正在用这把新买的Realforce键盘写这篇文章,这把键盘是Realforce的新款,但是等US布局等了很久。因为HHKB BT在Linux上的蓝牙表现实在不行,今天兴起剁手了这把Realforce新出的键盘。

带税原价现在是2.8w左右,用了Bic camera的积分扣了5000日元,然后正好是Line Pay的月末20%Cash back活动,降低到1.8w左右,然后有10%的积分,所以最终价格约是17000日元.(虽然感觉还是挺贵的)

因为之前HHKB是45G的,公司用的archiss茶轴也很重,估计超过50g了。 所以这把realforce我选择了30g的最轻版本。

不多说上图

  1. 开箱
2. 箱内 2.1 一个拔键器和两个备用键帽 2.2 两张垫片

使用感受

30g敲起来还是很轻的,这个系列一共4个重量的版本,30g,40g,55g和变化的。尝试了一下变化版版好像感觉不出太大的差别,这款键盘还是带带APC功能的,但是我还不知道怎么调整键程 orz. 用起暂时来挺舒服的,终于不用忍受蓝牙HHKB在Linux上各种的问题了…..

这篇博客记录一些我比较有用但是的command, 方便自己查询, 标题加入了一些英语翻译,方便CTRL+F。 欢迎补充

  1. curl查询公网出口IP(use curl to query public IP)

    curl ifconfig.me

    some other useful webstite:

    1. ip.cn
    2. ipinfo.io
    3. cip.cc
    4. myip.ipip.net
  1. 设置ssh反向tunnel(ssh reverse tunnel)

    A机器在内网,B机器在外网,C机器可以连接B但是不能连接A。如果C想通过B链接到A机器

    1. 从A登录B机器
      ssh -fNR 8771:localhost:22 [email protected]_MACHINE_IP
    2. 这样C机器就可以访问 ssh -p 8771 [email protected]_MACHINE_IP
  2. 列出监听端口(list all listening port)

    1
    netstat -anlp | grep -w LISTEN

    or

    1
    sudo netstat -tulp
  3. 打开关闭网卡(up and down network interface)

    1
    ip link set eth0 up/down
  4. 用ssh执行远程命令(use ssh to execute remote commands)

    -t Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

    1
    ssh -t [email protected] "command1 & command2"

    For example, if you want to simply pull a docker images on multiple servers, you can write a simple bash script like this:

    1
    2
    3
    for remote in 192.168.1.1 192.168.1.2 192.168.1.3; do
    ssh -t [email protected] "docker pull image:tag"
    done

    if you want to execute remote command in background, you can try to use nohup or screen:

    1
    ssh [email protected] screen -d -m ./script

    and you can check the result with

    1
    screen -ls

文件查找和字符操作(counting, searching and string operation)

  1. grep查找包含特定文字的文件(use grep to find all files container specific text)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    grep -rnw '/path/to/somewhere/' -e 'pattern'

    -r or -R is recursive,
    -n is line number, and
    -w stands for match the whole word.
    -l (lower-case L) can be added to just give the file name of matching files.

    Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:

    This will only search through those files which have .c or .h extensions:

    grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

    This will exclude searching all the files ending with .o extension:

    grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

    For directories it's possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:

    grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
  2. grep从文件中过滤并统计特定字符数量(use grep to filter string in file and count number)

    1
    grep -n '2018-03-24' /var/log/xxx/xxx/xxx.log  | grep 'stringyouwant'  |     wc -l
  3. find查找并替换文件中内容(use find to filter string and replace)

    1
    find . -iname '*.txt' -exec sed -i 's/text-to-search/text-to-replace/g' {} \;
  4. find查找过滤文件中内容(use find to filter string from file)

    1
    find . -iname '*.txt' | xargs -n 1 grep -nR 'text-to-search'
  5. 查看当前目录下多少文件(Counting Files in the Current Directory

    1
    2
    ls -1 | wc -l
    ls -l | grep -v ^l | wc -l (exclude symbol file, that's an "L" not a "1" this time)

Shell

  1. 查看当前shell版本(show which shell are you using)
    1
    echo $0
  1. 如何压缩一个文件名是--开头的文件?
    如果遇到一个文件名是以--开头的,那么在linux命令行中会被认为是参数. 例如文件名--test_abc

    1
    tar cvf test.tar.gz --test_abc

    这时候只要用--来表示参数终结就可以了

    1
    tar cvf test.tar.gz -- --test.abc
  1. Showing Linux Kernel LOG/Query the system journal

    1
    sudo dmesg

    or use journalctl under debian/ubuntu

    1. all dmesg output in the last 2 hours
      1
      sudo journalctl -k
  1. all journal since last boot

    1
    sudo journalctl -b
  2. list boots in the journal

    1
    journalctl --list-boots
  1. Setting persistent logging for kernel log

    by default the log is written non-persistently to /run/systemd/journal/(a binary file)

    Edit the /etc/systemd/journald.conf and uncomment #Storage=auto and change auto to persistent

    Then you can restart the service

    1
    sudo systemctl restart system-journald
  2. Make a read-only filesystem writable

    remouting it read-write:

    1
    sudo mount -o remount,rw '/mount-point'
  3. Alternative different version of software

    If you have installed multiple versions of gcc, like gcc-6 and gcc-9. your /usr/bin/gcc is probably pointing to gcc-6 by default. You can use the following command to change the version.

    1
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 900

    open the windows for switching version

    1
    sudo update-alternatives --config gcc

Emacs

  1. compile .emacs.d directory

    1
    C-u 0 M-x byte-recompile-directory

    will compile all the .el files in the directory and in all subdirectories below.
    The C-u 0 part is to make it not ask about every .el file that does not have a .elc counterpart.

    From stackoverflow

  2. upgrade emacs packages

    1
    M-x list-packages
    1. press U to mark all upgradable packages to be upgrade
    2. press x to perform the new updates
  1. format code

    select the region you want to format

    1
    M-h
    1
    M-x (indent-region)

    see also : choosing mode

  1. Regex in emacs

Browser

  1. open recent closed tab (chrome)

    There are 3 ways to do it:

    1. Get it back by right-clicking in the tab bar and selecting Reopen closed tab from the menu
    2. By clicking Ctrl+Shift+T.
    3. You can also find a list of recently closed tabs in the Settings menu. Click on the 3 horizontal line icon top right and choose Recent tabs.

Other commands and tools

screen

1. killing all the detached screens    
1
screen -ls | grep detached | cut -d. -f1 | awk '{print $1}' | xargs kill
or inside screen
1
Ctrl-a \

Unclutter

Unclutter hides your X mouse cursor when you do not need it, to prevent it from getting in the way. You have only to move the mouse to restore the mouse cursor. Unclutter is very useful in tiling window managers where you do not need the mouse often.

Extract GPS Info from Photots (Python脚本提取照片中的GPS信息)

  1. pip install pillow

  2. run this code under the folder image

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    from PIL import Image
    from PIL.ExifTags import TAGS
    import glob


    types = ('*.JPG',)

    def demo(name):
    exifdata = {}
    imgfile = Image.open(name)
    info = imgfile._getexif()
    if info:
    for (tag, value) in info.items():
    # print(str(tag) + ' : ' + str(value))
    decoded = TAGS.get(tag, tag)
    # print str(decoded)
    exifdata[decoded] = value
    exifgps = exifdata.get('GPSInfo', '')
    if exifgps:
    print('it has founded ; ' + str(name) + " " + str(exifgps))
    def main():
    for t in types:
    filenames = glob.glob(t)
    [demo(f) for f in filenames]
    if __name__=='__main__':
    main()
  3. If you have multiple image types, you can change types tuple to add more, for exmaple, types = ('\*.JPG', '*.png')

时光飞逝,转眼就来到了2019..(标准作文开头…)
感觉时间过的越来越快了,从17年11月入职算起,在日本生活和工作已经超过一年了。

2018的计划

竟然已经找不到去年写的18年计划了…隐约记得这么几项:

  1. 存钱计划完成
  2. 健身计划(基本完成,每周跑步10公里+,还有一些简单的健身房运动,不算意外的出差时间上还是满足了的..只是每次去健身房都是深夜了..)
  3. 投资上股票惨不忍睹,今年A股大盘就跌的很惨。 我又去开了日本的证券账户,碍于日语实在不行还没有下手,默默的观察中,还好刚开户没有剁手,躲过了年底日经和美股的大跌。
  4. side project其实没有做太多,尝试了一些简单的项目但是因为想不到很好的出发点,所以也没有持续。 要完整的做完一个项目还是很难的,希望新年能有更多的朋友提供想法或者能一起合作。
  5. 认识了一些新的同事和朋友,感觉自从工作之后其实交际圈就变的比较小了,再加上生活在日本又不会日语,平时也很少出去玩orz…有小伙伴来玩请找我…
  6. 博客并没有坚持写什么,倒是通过了Google ADSense的审核,请大家不要Adblock我;)
  7. 日语断断续续的,年底也忘记报名考试了..
  8. 工作。现在对整体的系统从前到后都有了完整的认识,各个部分和架构已经基本的知识等。但对于核心的planning和robotics还只是停留在宽泛的认识上,没有太多的深入。工作还是主要集中在backend system,也包括写了一些PLC Library和工具等。去年一年出差的时间比较多,简单的统计了一下大概4个月是在上海/北京的onsite出差。这段时间对系统有了比较全面的认识,对于robotics这个行业来说动手操作还是很重要的,在现场集成和开发的过程中对抽象的只是就有了具体的认识。经常会有更深刻的理解。但是不好的地方就是现场的压力比较大,琐碎的事情也很多,很难静下心做一些开发的工作。
  9. 旅游。去年没去什么地方,本身就不是太在意旅游,基本也就是东京周边。 去了箱根,镰仓还有东京的迪士尼。 中间还有几次朋友来玩一起去了几次秋叶原之类的地方。

2019年的计划

  1. 赚钱(目标太少就不说了….去年的基础上1.5倍)
  2. 继续健身,每周去2次以上健身房,至少10公里跑步。
  3. 希望能继续多开发一些side project, 从中找一些机会
  4. 对于planning和数学有更进一步的学习
  5. 旅游目前只有计划2月去一次北海道
  6. 日语争取7月考一次N2
  7. 继续写博客,多写博客

昨天随手申请了一下google adsense, 没想到就顺利的过了。之前有申请过一次,不过被拒了,要求应该就是有较多的内容之类的,并且网站运行了一段时间。 于是这次就顺利给这个丝毫没有流量的博客加上了广告;)

其实申请非常简单, 到google adsense页面上登陆帐号,然后只要填入网站的URL就可以了。网站需要是自己的,也就是顶级域名,不能是github page之类的。 官方说一周,但是实际我审核也就过了一天就发邮件说通过了。

审核通过之后会给出一段代码:

1
2
3
4
5
6
7
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-3897139875615992",
enable_page_level_ads: true
});
</script>

我用的是hexo + Next主题,所以在 themes/hexo-theme-next/layout/_custom/ 下新建一个google_adsense.ejs文件,并把上面的代码复制进去。
最后只需要在 themes/hexo-theme-next/layout/_layout.swig<head>标签中include就可以了,完整的head如下;)

1
2
3
4
5
6
7
8
<head>
{% include '_partials/head.swig' %}
<title>{% block title %}{% endblock %}</title>
{% include '_third-party/analytics/index.swig' %}
<!--google adsense start-->
{% include '_custom/google_adsense.ejs' %}
<!--google adsense ends-->
</head>

这样就自动完成的广告的添加啦 ~ 不过一想到现在人人都用adblocks……..但总算是满足了一个给自己博客加广告的愿望;P