Skip to content

Instantly share code, notes, and snippets.

View caiguanhao's full-sized avatar
🇺🇦
#StandWithUkraine

CGH caiguanhao

🇺🇦
#StandWithUkraine
View GitHub Profile
@caiguanhao
caiguanhao / README.md
Last active December 4, 2016 05:38
generate flip rotate animation keyframes
@keyframes flip-rotate-5-3-60 {
  0%, 1.5% { margin-top: 60px; }
  1.5%, 19.7% { margin-top: 0px; }
  22.7%, 39.4% { margin-top: -60px; }
  42.4%, 59.1% { margin-top: -120px; }
  62.1%, 78.8% { margin-top: -180px; }
  81.8%, 98.5% { margin-top: -240px; }
  100% { margin-top: -300px; }
}
@caiguanhao
caiguanhao / log.awk
Last active November 23, 2019 16:44
separate a large Rails log file into multiple files by date
function p () {
if (last != "") {
month = substr(last, 1, 7)
day = substr(last, 9, 2)
print "mkdir -p", month"/"day
file = month"/"day"/production.log"
print "file="file
print "test -f $file && file=${file}.2"
printf "%s production.log", "tail -n+"NRs[last]
if (date != "") {
@caiguanhao
caiguanhao / split-nginx-logs.md
Last active August 2, 2017 04:01
Split nginx logs

Suppose you have these logs:

access.log
api.access.log
api.error.log
frontend.access.log
frontend.error.log
services.access.log
@caiguanhao
caiguanhao / iotop.stat.txt
Last active August 29, 2015 14:13
aliyun
TIME TID PRIO USER DISK READ DISK WRITE SWAPIN IO COMMAND
13:17:18 154 be/3 root 0.00 B/s 0.00 B/s 0.00 % 0.15 % [jbd2/xvda1-8]
13:17:19 4935 be/4 root 3.92 K/s 3.92 K/s 0.00 % 0.09 % python /usr/sbin/iotop -botqqq --iter=3
13:17:24 154 be/3 root 0.00 B/s 11.79 K/s 0.00 % 1.59 % [jbd2/xvda1-8]
13:17:24 2696 be/4 root 0.00 B/s 3.93 K/s 0.00 % 0.00 % nginx: worker process
13:17:26 4960 be/4 root 0.00 B/s 3.93 K/s 0.00 % 0.00 % sudo su
13:17:27 981 be/4 nobody 0.00 B/s 3.93 K/s 0.00 % 0.00 % nscd
13:17:29 154 be/3 root 0.00 B/s 19.66 K/s 0.00 % 0.38 % [jbd2/xvda1-8]
13:17:33 2696 be/4 root 0.00 B/s 3.93 K/s 0.00 % 0.00 % nginx: worker process
13:17:36 154 be/3 root 0.00 B/s 0.00 B/s 0.00 % 0.34 % [jbd2/xvda1-8]

Move NAMES to first column

dpsa | awk 'NR==1{I=index($0,"NAMES");J=length($0);K=substr($0,I);L=substr($0,0,I-1)}NR==2{print K sprintf("%*s",length($0)-J,"") L}NR>1{print substr($0,I)substr($0,0,I-1)}' | less -XSF

Move NAMES after CONTAINER ID before IMAGE

dpsa | awk 'NR==1{A=index($0,"IMAGE");B=substr($0,0,A-1);C=index($0,"NAMES");D=substr($0,A,C-A-1);E=length($0);F=substr($0,C)}NR==2{print B F sprintf("%*s",length($0)-E,"") D}NR>1{print substr($0,0,A-1)substr($0,C)substr($0,A,C-A-1)}' | less -XSF
@caiguanhao
caiguanhao / gist:789a6a3b190fdb6b3718
Created November 20, 2014 06:19
fig installation on CoreOS
sudo bash -c 'sudo mkdir -p /opt/bin; curl -L https://github.com/docker/fig/releases/download/1.0.1/fig-`uname -s`-`uname -m` > /opt/bin/fig; chmod +x /opt/bin/fig'
@caiguanhao
caiguanhao / openssl.md
Last active August 29, 2015 14:08
handy openssl commands to make (self signed) certificates

Get list of subject alternative names of a domain

lssan () {
  [[ $# -ne 1 ]] && echo 'Usage: lssan <DOMAIN>' || {
    openssl s_client -connect $1:443 -servername $1 </dev/null 2>/dev/null | \
    openssl x509 -text -noout | grep 'X509v3 Subject Alternative Name' -A 1 | \
    tail -1 | tr ',' '\n' | awk -F: '{print $2}'
  }
}
@caiguanhao
caiguanhao / twitter
Last active August 29, 2015 14:07
twitter proxy (but lacks a filter to replace cookie response header, so can't log in)
server {
listen 443;
server_name t.cgh.io;
subs_filter_types text/html text/css text/javascript application/javascript;
subs_filter "(https:)?//([^.]+?)\.twimg\.com/" "//t.cgh.io/__twimg/$2/" r;
subs_filter "(https:)?//twitter\.com/" "//t.cgh.io/" r;
subs_filter "\"twitter.com\"" "\"t.cgh.io\"";
location ~ /__twimg/([^/]+)/ {
resolver 8.8.8.8;
proxy_pass https://$1.twimg.com;
@caiguanhao
caiguanhao / go.sh
Created October 4, 2014 03:18
watch go (golang) file changes and restart it (esp. for server app)
watchgo() {
eval "$@ &; lastpid=\$\!;"; \
fswatch -0 *.go | while read -d ""; \
do pkill -P $lastpid; \
eval "$@ &; lastpid=\$\!;"; \
done
}
# watchgo "go run *.go"
@caiguanhao
caiguanhao / windows.bat
Created June 24, 2014 16:15
Unix/Linux commands on Windows
(echo @echo ^%cd^%) > C:\WINDOWS\pwd.bat
(echo @copy %*) > C:\WINDOWS\cp.bat
(echo @move %*) > C:\WINDOWS\mv.bat
(echo @dir /d %*) > C:\WINDOWS\ls.bat
(echo @dir %*) > C:\WINDOWS\ll.bat
(echo @dir /b %*) > C:\WINDOWS\l.bat
(echo @del %*) > C:\WINDOWS\rm.bat
(echo @explorer %*) > C:\WINDOWS\open.bat
(echo @type %*) > C:\WINDOWS\cat.bat
(echo @more %*) > C:\WINDOWS\less.bat