Skip to content

Instantly share code, notes, and snippets.

View notsobad's full-sized avatar

notsobad notsobad

View GitHub Profile
DOMAIN_SUFFIX = (
'.gov.cn',
'.com.cn',
'.edu.cn',
'.net.cn',
'.org.cn',
)
def get_root_domain(domain):
from random import randrange
def generateIP():
blockOne = randrange(0, 255, 1)
blockTwo = randrange(0, 255, 1)
blockThree = randrange(0, 255, 1)
blockFour = randrange(0, 255, 1)
if blockOne in (10,172, 192):
return generateIP()
return str(blockOne) + '.' + str(blockTwo) + '.' + str(blockThree) + '.' + str(blockFour)
@notsobad
notsobad / run_worker.py
Last active December 20, 2015 22:49
A sample rq test using tornado. visit: http://localhost:9527/?n=1000 to add a job. then visit http://localhost:9527/check/?job_id=$job_id to check the job status.
from rq import Queue, Worker, Connection
if __name__ == '__main__':
with Connection():
q = Queue()
Worker(q).work()
@notsobad
notsobad / pid-age.sh
Created November 29, 2013 07:32
Get the age the of pid.
pid_age(){
pid=$1
start=`stat -t /proc/$pid | awk '{print $14}'`
now=`date +%s`
count=`expr $now - $start`
echo $count
}
pid_age $1
KEY_FILE=/root/.ssh/authorized_keys
add_ssh_key(){
key=$@
name=`echo $@ | cut -d " " -f3`
grep $name $KEY_FILE || {
echo "$@" >> $KEY_FILE
}
}
-startup
../../../plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
../../../plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.200.v20120913-144807
-product
com.android.ide.eclipse.adt.package.product
-showsplash
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
512m

参考:

gevent的所有greenlets是在操作系统的同一个进程、同一个线程内运行,所以一些阻塞的操作需要被替换为不阻塞的,这也就是monkey.patch_all()的作用。

spawn一个greenlet之后,它并不立即运行,gevent.sleep() 会yield到下一个greenlet。

gevent.joinall()会等待所有greenlets完成才退出。