Raspberry配置Spacemacs

1、安装Emacs。

>> wget http://mirrors.ustc.edu.cn/gnu/emacs/emacs-25.1.tar.gz
>> tar zxvf emacs-25.1.tar.gz
>> cd emacs-25.1
>> sudo apt install libxpm-dev libgif-dev
>> sudo apt install libtinfo-dev
>> ./configure
>> sudo make
>> sudo make install

2、安装Spacemacs。

>> git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
>> vi .emacs.d/core/core-configuration-layer.el
    (defvar configuration-layer--elpa-archives
    '(("melpa" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
        ("org"   . "https://mirrors.tuna.tsinghua.edu.cn/elpa/org/")
        ("gnu"   . "https://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
        ("marmalade" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/marmalade/"))
    "List of ELPA archives required by Spacemacs.")
>> emacs

3、配置Spacemacs。

>> sudo apt install python-jedi python3-jedi python-virtualenv python-autopep8
>> emacs
>> M-x configuration-layer/create-layer
    myconf
>> C-x C-c
>> emacs ~/.emacs.d/private/myconf/config.el
    ;; 切换输入法
    (global-unset-key (kbd "C-SPC"))
    (global-set-key (kbd "M-SPC") 'set-mark-command)

    ;; 中文字体
    (set-fontset-font "fontset-default" 'unicode '("WenQuanYi Zen Hei"))

    ;; Code Review
    (defun add-code-review-note ()
    "Add note for current file and line number"
    (interactive)
    (let ((file-name (buffer-file-name))
            (file-line (line-number-at-pos)))
        (switch-to-buffer-other-window (get-buffer-create "NOTES"))
        (goto-char (point-min))
        (when (not (search-forward "-*- mode:compilation-shell-minor"
                                    nil t))
        (compilation-shell-minor-mode 1)
        (insert "-*- mode:compilation-shell-minor -*-\n\n"))
        (goto-char (point-max))
        (if (/= (current-column) 0)
            (newline))
        (insert file-name ":" (number-to-string file-line) ": ")))

    (global-set-key (kbd "C-c r") 'add-code-review-note)

    ;; Copy region or whole line
    (global-set-key "\M-w"
    (lambda ()
    (interactive)
    (if mark-active
        (kill-ring-save (region-beginning)
        (region-end))
        (progn
        (kill-ring-save (line-beginning-position)
        (line-end-position))
        (message "copied line")))))


    ;; Kill region or whole line
    (global-set-key "\C-w"
    (lambda ()
    (interactive)
    (if mark-active
        (kill-region (region-beginning)
    (region-end))
        (progn
        (kill-region (line-beginning-position)
    (line-end-position))
        (message "killed line")))))

    ;; 切换最大化
    (global-set-key [f12] 'my-maximized)
    (defun my-maximized ()
    (interactive)
    (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
                            '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
    (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
                            '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))

    ;; 切换半透明
    (global-set-key [f8] 'loop-alpha)
    (setq alpha-list '((100 100) (85 85) (35 35)))
    (defun loop-alpha ()
    (interactive)
    (let ((h (car alpha-list)))
        ((lambda (a ab)
        (set-frame-parameter (selected-frame) 'alpha (list a ab))
        (add-to-list 'default-frame-alist (cons 'alpha (list a ab)))
        ) (car h) (car (cdr h)))
        (setq alpha-list (cdr (append alpha-list (list h))))
        )
    )
    (loop-alpha)

    ;; 优化注释
    (defun qiang-comment-dwim-line (&optional arg)
    (interactive "*P")
    (comment-normalize-vars)
    (if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
        (comment-or-uncomment-region (line-beginning-position)
        (line-end-position))
        (comment-dwim arg)))
    (global-set-key "\M-;" 'qiang-comment-dwim-line)

    ;; Y or N
    (fset 'yes-or-no-p 'y-or-n-p)

    ;; Neotree
    (global-set-key [f9] 'neotree-toggle)

    ;; Line number
    (global-linum-mode 1)

    ;; Python mode
    (add-to-list 'auto-mode-alist '("\\.py?\\'" . python-mode))

    ;; autopep8
    (add-hook 'python-mode-hook 'py-autopep8-enable-on-save)

    ;; Fold
    (add-hook 'python-mode-hook 'hideshowvis-enable)

    ;; Mic-paren
    (add-hook 'python-mode-hook 'paren-activate)

    ;; Jedi
    (autoload 'jedi:setup "jedi" nil t)
    (add-hook 'python-mode-hook 'jedi:setup)
    (setq jedi:setup-keys t)
    (setq jedi:complete-on-dot t)

    ;; Python mode
    (setq py-python-command "ipython3")
    (global-set-key [f5]  'run-python)
    (add-hook 'python-mode-hook 'yas-global-mode)

    ;; Web mode
    (add-to-list 'auto-mode-alist '("\\.tpl\\'" . html-mode))
    (add-to-list 'auto-mode-alist '("\\.html\\'" . html-mode))
    (add-to-list 'auto-mode-alist '("\\.xml\\'" . html-mode))
    (add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
    (add-to-list 'auto-mode-alist '("\\.js\\'" . js-mode))
    (add-hook 'html-mode-hook 'web-mode)
    (add-hook 'css-mode-hook 'web-mode)
    (add-hook 'js-mode-hook 'web-mode)
    (add-hook 'web-mode-hook 'global-auto-complete-mode)
    (add-hook 'web-mode-hook 'rainbow-mode)
    (add-hook 'web-mode-hook 'emmet-mode)
    (add-hook 'web-mode-hook 'hideshowvis-enable)


    ;; Auto complete
    (add-hook 'c-mode-hook 'auto-complete-mode)
    (add-hook 'c-mode-hook 'yas-global-mode)
    (setq ac-quick-help-prefer-pos-tip t)
    (setq ac-use-quick-help t)
    (setq ac-quick-help-delay 1.0)
    (setq ac-fuzzy-enable t)
    (setq ac-auto-start 1)
    (setq ac-quick-help-delay 0.5)

    ;; Yas
    (global-set-key (kbd "C-c C-x 3") 'yas/expand)
    (global-set-key (kbd "C-c C-x 4") 'yas/next-field)
>> C-x C-s
>> C-x C-c
>> emacs ~/.spacemacs
    dotspacemacs-configuration-layers
    '(
        python
        ;; ----------------------------------------------------------------
        ;; Example of useful layers you may want to use right away.
        ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
        ;; <M-m f e R> (Emacs style) to install them.
        ;; ----------------------------------------------------------------
        helm
        auto-completion
        better-defaults
        emacs-lisp
        ;; git
        markdown
        org
        myconf
        ;; (shell :variables
        ;;        shell-default-height 30
        ;;        shell-default-position 'bottom)
        ;; spell-checking
        ;; syntax-checking
        ;; version-control
        )

    dotspacemacs-additional-packages '(
                                minimap
                                py-autopep8
                                jedi
                                mic-paren
                                hideshowvis
                                emmet-mode
                                python
                                python-mode
                                web-mode
                                auto-complete
                                pos-tip
                                fuzzy
                                popup
                                rainbow-mode
                                yasnippet)
>> C-x C-s
>> C-x C-c
>> emacs
>> M-x jedi:install-server

Docker配置weex开发环境

1、安装weex。

>> npm install -g cnpm --registry=https://registry.npm.taobao.org
>> cnpm install -g weex-toolkit

2、初始化weex项目。

>> weex init testapp

3、构建并测试项目。

>> cd testapp
>> npm install
>> npm run dev
>> npm run serve

4、主系统访问 http://192.168.99.100:8080/ 即可,这里只是实现浏览器预览,后面我们再进一步研究打包apk。

Docker配置vuejs开发环境

为了防止出现问题,需要先用管理员权限打开Docker终端。

1、安装wget,下载最新版nodejs。

>> apt udpate
>> apt install wget
>> cd ~
>> wget https://nodejs.org/dist/v7.7.2/node-v7.7.2-linux-x64.tar.xz

2、安装nodejs。

>> apt install xz-utils
>> xz -d node-v7.7.2-linux-x64.tar.xz
>> tar -xvf node-v7.7.2-linux-x64.tar
>> apt install emacs
>> emacs ~/.bashrc
export PATH=$PATH:/root/node-v7.7.2-linux-x64/bin/
>> source ~/.bashrc

3、安装vue和vue-cli。

>> npm install --global vue vue-cli

4、创建新项目。

>> cd ~
>> mkdir development
>> cd development
>> apt install git
>> vue init webpack test
>> cd test
>> npm install
>> npm run dev

5、主系统访问 http://192.168.99.100:8080 即可。

注意

如果容器如下这样启动的话:

>> docker run --name t1 -i -t -p 10001:8080  ~/share/:/usr/development/ ubuntu:14.04 /bin/bash

访问 http://192.168.99.100:10001 才可以看到虚拟机里的网站。

虚拟机里的网站用8080端口,那么主系统需要访问192.168.99.100的10001端口。

192.168.99.100是在docker终端启动时显示出来的。

Docker配置Python爬虫环境

1、新建容器。

>> docker run --name webcrawler -i -t -p 8080:8080 -v ~/share/:/usr/development/ ubuntu:14.04 /bin/bash

2、修改软件源。

>> vi /etc/apt/sources.list
:%s/archive.ubuntu/cn.archive.ubuntu/g
:wq

3、更新软件。

>> apt update

4、安装必要的软件和第三方库。

>> apt install python
>> apt install python-pip
>> apt install python-dev
>> pip install beautifulsoup4
>> apt install libdecodeqr-dev libopencv-dev
>> pip install pydecodeqr
>> apt install libcurl4-openssl-dev
>> pip install -U setuptools pip
>> apt install libxml2-dev libxslt-dev libssl-dev
>> pip install grab
>> pip install robobrowser
>> pip install pycurl
>> pip install splinter
>> pip install qrcode
>> pip install requests

参考

http://www.python-requests.org/en/master/

https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.html#

https://github.com/six519/pydecodeqr

https://github.com/lincolnloop/python-qrcode

http://pycurl.io/docs/latest/index.html

http://docs.grablib.org/en/latest/

http://robobrowser.readthedocs.io/en/latest/

http://splinter.readthedocs.io/en/latest/index.html

Supervisor实现Python脚本自启动

经过若干小时的反复试验,终于在树莓派上成功部署了homebank[https://codinglonglong.github.io/posts/xiao-jia-shou-zhang-wang-ye-ban-ji-ben-wan-cheng/],最困难的地方就是配置Supervisor,配置过程中出现了各种错误……

1、安装supervisor。

>> sudo pip install supervisor

2、编辑配置文件。

>> cd /home/pi/websites/
>> echo_supervisord_conf > supervisord.conf
>> sudo supervisord -c supervisord.conf
>> emacs supervisord.conf
[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9999        ; (ip_address:port specifier, *:port for all iface)
username=user              ; (default is no username (open server))
password=123               ; (default is no password (open server))

[program:homebank]
command=python main.py
directory=/home/pi/websites/homebank

3、启动服务。

>> sudo supervisorctl reload
>> sudo supervisorctl status homebank
homebank                         RUNNING   pid 2212, uptime 0:02:07

4、设置开机启动。

>> sudo emacs /etc/rc.local
sudo /usr/local/bin/supervisord -c /home/pi/websites/supervisord.conf

5、设置sudo免密。

>> sudo visudo
pi ALL = (ALL)NOPASSWD:ALL

6、重启。

>> sudo reboot