Programming is the art of adding bugs to an empty text file
Louis Srygley:
Without requirements or design, programming is the art of adding bugs to an empty text file.
Vim folding
- zi - toggle folding
- za - toggle current fold open/close
- zR - open all folds
- zM - close all folds
- zc - close current fold
-
zo - open currrent fold
- zj - move down to next fold
- zk - move up to previous fold
nnoremap <Space> za
在所有子目录下执行 git
git config --global alias.all '!f() { ls -R -d */.git | sed 's,\/.git,,' | xargs -P10 -I{} git -C {} $1; }; f'
git all pull
setlock
setlock - runs another program with a file locked.
setlock [-nNxX] fn child
,简单说 setlock 会打开 fn 并加锁,然后执行 child。如果 lock 失败,可以指定 child 退出或等待:
-n: fn 被其他进程锁住,setlock 放弃执行 child
-N: fn 被其他进程锁住,setlock 会等待,直到重新加锁,并执行 child
-x: fn 打开失败或已加锁,setlock exit 0
-X: fn 打开失败或已加锁,setlock 输出错误并退出
setlock 可以和 crontab 搭配使用,比如某个任务每十分钟执行一次,如果上一次执行尚未退出,不再开启新任务:
*/10 * * * * /usr/bin/setlock -n /tmp/test.lock /home/x.sh
Stop
Stop, 是一个行程的中止。
Stop, 也是一个站点,下车,上车,继续前进。
2010.6 - 2018.5.
Nginx + Websocket
upstream ws {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 8090;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://ws;
}
}
在 Nginx reload 的时候,socket 连接并不会中断。
Linux Performance Analysis in 60s
uptime/w --------------------> load average
dmesg | tail ----------------> kernel errors
vmstat 1 --------------------> overall stats every second
mpstat -P ALL 1 -------------> CPU balance
pidstat 1 -------------------> process usage, every second
iostat -xz 1 ----------------> disk I/O
free -m ---------------------> memory usage
sar -n DEV 1 ----------------> network I/O
sar -n TCP,ETCP 1 -----------> TCP stats
top -------------------------> check overview
dmidecode
You can use dmidecode
to display server physical info, for example RAM max capacity.
dmidecode -t 16
Handle 0x0032, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 48 GB
Error Information Handle: Not Provided
Number Of Devices: 6