Skip to content

Instantly share code, notes, and snippets.

@seanhsu0102
seanhsu0102 / gist:0733daadee3c8ee678e05de86dd3a40b
Created December 22, 2023 03:30
Ubuntu 16.04 install asdf
sudo apt-get update
sudo apt-get install -y build-essential git libreadline-dev zlib1g-dev libssl-dev libbz2-dev libsqlite3-dev libncurses-dev
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.13.1
echo ". \"$HOME/.asdf/asdf.sh\"" >> ~/.bashrc
echo ". \"$HOME/.asdf/completions/asdf.bash\"" >> ~/.bashrc
#取得前十名 access 最多的 IP 位址
cat access_log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10
#取得前十名 access 最多的網頁
cat access_log|awk '{print $11}'|sort|uniq -c|sort -nr|head -10
#取得前十名下載流量最大的 zip 檔案
cat access.log |awk '($7~/\.zip/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -10
#取得前十名 Loading 最大的頁面 (大於60秒的 php 頁面)
[core]
# The home folder for airflow, default is ~/airflow
airflow_home = /Users/p1nox/airflow
# The folder where your airflow pipelines live, most likely a
# subfolder in a code repository
dags_folder = /Users/p1nox/airflow/dags
# The folder where airflow should store its log files. This location
base_log_folder = /Users/p1nox/airflow/logs
@seanhsu0102
seanhsu0102 / Vagrantfile
Created March 6, 2018 07:17 — forked from leifg/Vagrantfile
Add a second disk to system using vagrant
file_to_disk = './tmp/large_disk.vdi'
Vagrant::Config.run do |config|
config.vm.box = 'base'
config.vm.customize ['createhd', '--filename', file_to_disk, '--size', 500 * 1024]
config.vm.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
end
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group database
group mysql
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 protocol mysql with timeout 15 seconds for 3 times within 4
cycles then restart
if failed unixsocket /var/run/mysqld/mysqld.sock protocol mysql for 3 times within 4 cycles then restart
@seanhsu0102
seanhsu0102 / nginx_secure
Last active January 25, 2020 21:49
nginx secure link
# Nginx config example
```
location /asset {
secure_link $arg_md5,$arg_expires;
secure_link_md5 "secret$uri$arg_expires";
if ($secure_link = "") {
return 403;
}
@seanhsu0102
seanhsu0102 / varnish_50x
Created February 1, 2016 09:13
varnish handle 50x status
# 如果碰到 50x 則回 stale content,10 分鐘後會真的看到 50x
if (beresp.status == 500 || beresp.status == 501 || beresp.status == 502 || beresp.status == 503 || beresp.status
== 504) {
set beresp.uncacheable = "True";
set beresp.grace = 10m;
return (abandon);
}
@seanhsu0102
seanhsu0102 / iptables_forward
Last active January 27, 2016 10:17
iptables foward port to other IP
```bash
# 啟用 IP forward 預設為 0 = off 避免被當跳板
$ echo '1' > /proc/sys/net/ipv4/ip_forward
# 把你要導的 port 導到想導的 IP:PORT 去
$ iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 192.168.1.1:443
# 使用你的外部 IP 當做 forward 出去所看到的 PORT
$ iptables -t nat -A POSTROUTING -j MASQUERADE
@seanhsu0102
seanhsu0102 / mysql_grant
Last active January 27, 2016 10:18
MySQL add User (Grant)
GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE ON db_name.* TO 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'127.0.0.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT REPLICATION SLAVE ON *.* TO repl@"192.168.1.%" IDENTIFIED BY 'password';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE ON db_name.* TO 'username'@'%' IDENTIFIED BY 'password';
GRANT SELECT, LOCK TABLES ON *.* TO ‘backup’@’localhost’
IDENTIFIED BY ‘backup_password’; # mysqldump
GRANT SELECT ON *.* TO ‘backup’@’localhost’
IDENTIFIED BY ‘backup_password’; # mysqldump
FLUSH PRIVILEGES;
@seanhsu0102
seanhsu0102 / awknote.txt
Created January 15, 2016 03:52
shell awk
將檔案內不重複的行列出來
awk '!seen[$0]++' <filename>
同效
awk '{ if (!seen[$0]) print $0; seen[$0]++ }’
# Print first two fields in opposite order:
awk '{ print $2, $1 }' file
# Print lines longer than 72 characters:
awk 'length > 72' file