Skip to content

Instantly share code, notes, and snippets.

View encoreshao's full-sized avatar

Encore Shao encoreshao

View GitHub Profile
@encoreshao
encoreshao / phistory.sh
Created December 23, 2023 15:21
Statistic of the frequnce of your command from your history
history | awk '{CMD[\$2]++;count++;} END { for (a in CMD)print CMD[a] \" \" CMD[a]/count*100 \"% \"; }' | grep -v './' | column -c3 -s ' ' -t | sort -nr | nl | head -n10
history | awk '{CMD[$2]++;count++;} END { for (a in CMD )print CMD[a] " " CMD[a]/count*100 "% " a }' | sort -nr | nl | column -t | head -n 10
@encoreshao
encoreshao / simplevpn.sh
Last active February 18, 2022 03:47
Port forward from external PostgreSQL to localhost in backend
❯ vim ~/scripts/startup/simplevpn.sh
#!/bin/bash
/usr/bin/ssh -vfNT -p 8020 -o Compression=yes -o DynamicForward=9090 -o ServerAliveInterval=1 -L 5444:127.0.0.1:5432 username@remote.ip &>/dev/null &
❯ ~/scripts/startup/simplevpn.sh
❯ psql -U pg_user -d db_name -h localhost -p 5444
@encoreshao
encoreshao / psql-with-gzip-cheatsheet.sh
Created December 22, 2021 03:32 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@encoreshao
encoreshao / v2ray_install.sh
Last active November 14, 2022 13:11
Install v2ray VPN Vultr
#!/bin/bash
red='\e[91m'
green='\e[92m'
yellow='\e[93m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
_red() { echo -e ${red}$*${none}; }
_green() { echo -e ${green}$*${none}; }
@encoreshao
encoreshao / Chinese.md
Last active June 13, 2020 10:41
名言

生气,是因为你不够大度

嫉妒,是因为你不够优秀

悲伤,是因为你不够坚强

郁闷,是因为你不够豁达

@encoreshao
encoreshao / resize_nocrop_noscale
Created June 11, 2020 03:06 — forked from maxivak/resize_nocrop_noscale
Crop and resize an image using MiniMagick in Ruby on Rails. Two approaches.
def resize_nocrop_noscale(image, w,h)
w_original = image[:width].to_f
h_original = image[:height].to_f
if w_original < w && h_original < h
return image
end
# resize
image.resize("#{w}x#{h}")
@encoreshao
encoreshao / PostgreSQL-12-Streaming-Replication-in-Ubuntu-18.04.md
Last active August 7, 2023 07:42
PostgreSQL 12 Streaming Replication in Ubuntu 18.04

How To Configure PostgreSQL 12 Streaming Replication in Ubuntu 18.04

  • Build two boxes and install ubuntu18.04

    • box1: master -> Ubuntu 18.04 with PG 12
      • static ip: 192.168.33.33
      • hostname: master
    • box2: slave -> Ubuntu 18.04 with PG 12
      • static ip: 192.168.33.44
      • hostname: slave
@encoreshao
encoreshao / PostgreSQL-10-Master-Slave-Replication.md
Last active June 7, 2022 15:19
PostgreSQL 10 Master-Slave Replication on Virtualbox

PostgreSQL 10 Master-Slave Replication on Virtualbox

Preparations

@encoreshao
encoreshao / git.md
Last active May 25, 2020 01:49
Git operation

To update the local list of remote branches:

git remote update origin --prune

Pull all updates from remote branches:

git pull --all

To update the local submodule list of remote repo

git submodule update --remote

Add alias gpa [~/.bash_alias]

@encoreshao
encoreshao / nginx-for-react.conf
Last active May 24, 2020 12:08
How to setup Nginx for react application - linktr.cn
server {
listen 80;
server_name linktr.cn;
include snippets/letsencrypt.conf;
return 301 https://$host$request_uri;
}
server {