cURL Notes

  • curl -c cookie.txt URL: save cookies to cookie.txt
  • curl -b cookie.txt URL: read cookie from cookie.txt and put into request
  • curl -H 'User-Agent: FakeUA' URL: set HTTP header
  • curl -I URL: show header only
  • curl -L URL: follow 30x redirect
  • curl -o new_name/-O URL: save response to file
  • curl -X POST --data "data=xxx" URL: POST data to URL
  • curl -w "@curl-format.txt" URL: format details of request, which you can use this to timing request:
➜ cat curl-format.txt
    time_namelookup:  %{time_namelookup}\n
       time_connect:  %{time_connect}\n
    time_appconnect:  %{time_appconnect}\n
      time_redirect:  %{time_redirect}\n
   time_pretransfer:  %{time_pretransfer}\n
 time_starttransfer:  %{time_starttransfer}\n
         time_total:  %{time_total}\n

➜ curl -w "@curl-format.txt" -o /dev/null -s
    time_namelookup:  0.015
       time_connect:  0.015
    time_appconnect:  0.329
      time_redirect:  0.000
   time_pretransfer:  0.329
 time_starttransfer:  0.377
         time_total:  0.377



7 Years in Beijing


Converting MyISAM to InnoDB



然后现实是需要迁移表的数据量往往很大,不好直接 ALTER。一个办法是导出-修改表结构-导入,需要修改的有表名,engine,导入后重命名新/旧表。需要注意的是 mysqldump 默认有 DROP TABLE 命令,需要去掉,不然导入时候会直接删掉旧表。


CREATE TABLE innodb_table LIKE mytable;
ALTER TABLE innodb_table ENGINE=InnoDB;
INSERT INTO innodb_table SELECT * FROM mytable;


INSERT INTO innodb_table SELECT * FROM mytable WHERE id BETWEEN x AND y;


RENAME TABLE mytable TO mytable_old, innodb_table TO mytable;
//DROP TABLE mytable_old;

XDG Base Directory

XDG 是 X Desktop Group 的简称,现在叫,致力于推动 *nix 桌面环境的标准规范化。其中 XDG Base Directory 定义了文件配置基本目录:

  • $XDG_CONFIG_HOME 是配置文件目录,默认 $HOME/.config
  • $XDG_DATA_HOME 是用户文件的基本保存目录,默认 $HOME/.local/share
  • $XDG_DATA_DIRS 定义 $XDG_DATA_HOME 以外的文件基础目录,是一个有序目录集合,默认 /usr/local/share/:/usr/share/
  • $XDG_CONFIG_DIRS 同理,是扩展的配置文件目录,默认 /etc/xdg,需要注意的是目录顺序很重要,$XDG_CONFIG_HOME 优先级最高
  • $XDG_CACHE_HOME 缓存目录,默认 $HOME/.cache
  • $XDG_RUNTIME_DIR 指定非必需运行时文件保存目录

Neovim 支持 XDG Base Directory,配置文件是 $HOME/.config/nvim/init.vim,shada 文件在 $HOME/.local/share/nvim.

via XDG Base Directory Specification

Verify SSL certificate and key

You can use OpenSSL to verify whether a SSL certificate and a key is matched:

openssl x509 -noout -in certificate.crt | openssl md5
openssl rsa -noout -in privateKey.key | openssl md5
openssl req -noout -in CSR.csr | openssl md5

If both commands return same hash, the certificate and key is matched.

Development in Startup


Fix "Enter passphrase for key" on macOS

You will be asked ‘Enter passphrase for key’ when doing SSH operation:

Enter passphrase for key ‘/Users/fannheyward/.ssh/id_rsa’:

On macOS you can fix this by ssh-add -K.

pushd / popd

cd - can goto last directory that you just leave, - means $OLDPWD. This only support one directory.

pushd / popd / dirs works on multiple directories, as a directory stack:

pushd [dir1] # add dir to stack
popd [dir1] # pop dir from stack
dirs # list stack
dirs -c # cleanup stack

Ansible notes

Ansible 是基于 SSH 的自动化配置管理和部署工具,更多请参考官方文档

ansible -i hosts.ini all -m ping
ansible-playbook -i hosts.ini playbook.yaml

用 Ansible + Supervisor 部署/更新应用:

- hosts: server
  - name: check if exists
    stat: path=/path/to/app
    register: check_path
  - name: clone
    shell: git clone XXX && git checkout -b release
    when: check_path.stat.exists == false
  - name: pull
    shell: cd /path/to/app && git pull origin release
    when: check_path.stat.exists
  - name: is already running ?
    stat: path=/tmp/
    register: supervisord_stat
  - name: restart
    command: supervisorctl -c supervisord.conf restart all
      chdir: /path/to/app
    when: supervisord_stat.stat.exists
  - name: start
    command: supervisord -c supervisord.conf
      chdir: /path/to/app
    when: supervisord_stat.stat.exists == false