Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Pahud Hsieh pahud

🏠
Working from home
View GitHub Profile
@pahud
pahud / cron_flock
Last active Aug 29, 2015
execute cron job with flock
View cron_flock
MAILTO='your@gmail.com'
# my cronjob
MP_UPD_LOCK='/tmp/.your_lock_file.lock'
* * * * * pahud /usr/bin/flock -w1 ${MP_UPD_LOCK} /usr/bin/python -c "from xxxx import foo as f; f.FooBar().update()" > /dev/null || SUBJ="[ERROR] flock on ${MP_UPD_LOCK} failed"; mail -s "${SUBJ}" "${MAILTO}" > /dev/null
@pahud
pahud / datastore json api test
Last active Aug 29, 2015
Datastore JSON API non_transactional commit test
View datastore json api test
連續寫入30次,運行在google compute engine上,每次寫入時間大約0.3秒。
$ for i in `seq 30`; do curl -sH "Content-Type: application/json" -H "Authorization: Bearer xxxxxxxx" https://www.googleapis.com/datastore/v1beta2/datasets/project-id/commit -d @addbody -o /dev/null -w "total:%{time_total}\n"; done
total:0.364
total:0.353
total:0.362
total:0.352
total:0.354
total:0.357
@pahud
pahud / d2r.py
Created Jun 10, 2014
download to your MiWIFI router with python CLI
View d2r.py
#!/usr/bin/env python
#-*- coding:utf8 -*-
'''
Usage: ./d2r.py RESOURCE_URL
'''
import base64, sys, requests
@pahud
pahud / OmegaProfile_auto_switch.pac
Last active Aug 29, 2015
OmegaProfile_auto_switch.pac
View OmegaProfile_auto_switch.pac
var FindProxyForURL = function(init, profiles) {
return function(url, host) {
"use strict";
var result = init, scheme = url.substr(0, url.indexOf(":"));
do {
result = profiles[result];
if (typeof result === "function") result = result(url, host, scheme);
} while (typeof result !== "string" || result.charCodeAt(0) === 43);
return result;
};
@pahud
pahud / cron-start.sh
Created Mar 30, 2015
start pahud/shadowsocks-python if it's not running
View cron-start.sh
#!/bin/bash
#set -x
dockercmd='/usr/bin/docker'
s=$( $dockercmd inspect --format='{{.State.Running }}' ss 2>&1)
if [ $? -ne 0 ]; then
echo "not 0"
/root/shadowsocks-python/start.sh
elif [ "${s}X" == "falseX" ]; then
@pahud
pahud / nginx
Last active Aug 29, 2015 — forked from vdel26/nginx
init script for OpenResty
View nginx
#!/bin/sh
#
# chkconfig: 2345 55 25
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
# For Debian, run: update-rc.d -f nginx defaults
# For CentOS, run: chkconfig --add nginx
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
@pahud
pahud / gist:92803665fdaf941a8ce0
Created Apr 3, 2015
backup full SD card as a img.gz file onto another server over SSH on-the-fly
View gist:92803665fdaf941a8ce0
$ dd if=/dev/mmcblk0 of=/dev/stdout | ssh pahud@192.168.31.193 "cat - | gzip - > x.img.gz"
@pahud
pahud / mount_xiaomi.sh
Created Apr 6, 2015
mount the share from XiaoMi router
View mount_xiaomi.sh
mount -t cifs -o username="root" //192.168.31.1/download /mnt/mi
@pahud
pahud / aliyun.sources.list.md
Last active Aug 29, 2015 — forked from xkou/ubuntu 源.txt
ubuntu 14.04 source from aliyun
View aliyun.sources.list.md
deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed universe restricted multiverse main
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe 
View fix_aliyun_route_table.md

Re阿里云支持docker吗? 改下路由表就可以了:

sudo route del -net 172.16.0.0 netmask 255.240.0.0