Skip to content

Instantly share code, notes, and snippets.

@ylt6
ylt6 / last_commit_for_path_within_head_repo_method
Created July 16, 2015 03:25
Find out the last commit for specific file using rugged
def last_commit_for_path_within_head_repo(path)
# equal to `git rev-list --max-count 1 HEAD #{path}`
walker = Rugged::Walker.new(Rugged:Repository)
walker.sorting(Rugged::SORT_DATE)
walker.push(head_commit)
walker.hide(base_commit)
walker.each { |commit|
return commit.oid if commit.diff(paths: [path]).size > 0
}
base_commit
@ylt6
ylt6 / batchrun.sh
Created February 3, 2017 01:30
batch run command which takes 1 date argument in shell
START=$1
END=$2
curr="$START"
while true; do
<command> $curr
[ "$curr" \< "$END" ] || break
curr=$( date +%Y-%m-%d --date "$curr +1 day" )
done
@ylt6
ylt6 / deployUser.md
Created February 24, 2017 15:26 — forked from learncodeacademy/deployUser.md
Adding a deploy user in Linux

(wherever it says url.com, use your server's domain or IP)

Login to new server as root, then add a deploy user

sudo useradd --create-home -s /bin/bash deploy
sudo adduser deploy sudo
sudo passwd deploy

And Update the new password

@ylt6
ylt6 / cloudflare_fw_setup.sh
Last active March 3, 2017 13:07
cloudflare_fw_setup.sh
iptables -I INPUT -p tcp -m multiport --dports http,https -s 103.21.244.0/22 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 103.22.200.0/22 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 103.31.4.0/22 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 104.16.0.0/12 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 108.162.192.0/18 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 131.0.72.0/22 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 141.101.64.0/18 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 162.158.0.0/15 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 172.64.0.0/13 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports http,https -s 173.245.48.0/20 -j ACCEPT
@ylt6
ylt6 / showip.sh
Created March 5, 2017 06:00
Print host IP on linux server
ifconfig eth0 | grep 'inet addr:' | awk -F'inet addr:' '{ print $2}' | awk '{ print $1}'
@ylt6
ylt6 / RedisSubPubWorker.py
Created March 10, 2017 02:10 — forked from jobliz/RedisPythonPubSub1.py
A short script exploring Redis pubsub functions in Python
# coding=utf-8
import redis
class Subscriber(object):
def __init__(self,
redis_client,
ignore_subscribe_messages=True,
@ylt6
ylt6 / deco.py
Created March 20, 2017 06:11
python decorator that accepts 0 or multiple arguments
def deco(*dargs):
def wrapper(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
for _ in range(dargs[0]):
print('has argument')
func(*args, **kwargs)
return wrapped
if len(dargs) > 1 or not callable(dargs[0]):
@ylt6
ylt6 / 0_reuse_code.js
Created April 18, 2017 08:50
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
### Keybase proof
I hereby claim:
* I am yiliangt5 on github.
* I am yiliangt5 (https://keybase.io/yiliangt5) on keybase.
* I have a public key ASBTWxGh2Bq4Bc7jg82WPTuwcqJYG-tLXaa6Mj6AyqqeWgo
To claim this, I am signing this object:
@ylt6
ylt6 / express_signed_cookie.js
Created November 28, 2017 17:03
signed cookie