This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def roulette_wheel_select(groups): | |
""" | |
Groups should format in list: | |
(weigth (positive), content) | |
More weight more chance that we pick this content | |
BUT not every time | |
i.e. | |
[(1, '1'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 新手专用 :) | |
countdown() | |
( | |
IFS=: | |
set -- $* | |
secs=$(( ${1#0} )) | |
while [ $secs -gt 0 ] | |
do | |
sleep 1 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Can reload after file changed/modified/created/deleted | |
echo "Auto reload" | |
while true; do | |
ps aux | grep start.py | awk '{print $2}' | xargs kill > /dev/null | |
$VIRTUAL_ENV/bin/python $PWD/start.py -c ~/config.ini & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import os | |
from ConfigParser import SafeConfigParser | |
PREFIX = 'ZTY' | |
setting = SafeConfigParser() | |
setting.read(['/etc/zty-site.conf', | |
'~/zty-site.conf']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
def binary2grey(n): | |
return n >> 1 ^ n | |
def grey2binary(g): | |
mask = g >> 1 | |
while mask: | |
g = g ^ mask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import signal | |
import logging | |
logger = logging.getLogger(__name__) | |
import sys | |
import os | |
import multiprocessing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
The MIT License (MIT) | |
Copyright (c) <2014> <Meng Zhou [email protected]> | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import route, run | |
@route('/echo') | |
def echo(): | |
return {'status':'ok'} | |
run(host='0.0.0.0', port=8998, reloader=False, | |
reloader=False, quiet=True, server='gevent') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_port_conflict(port, show_logging=True): | |
"""Check whether Shadowsock bind port conflicted with services | |
registered in services database from Linux /etc/services | |
If conflicted, show logging warning and return tuple that conflicted | |
else, return None | |
:port: int bind port (TCP/UDP) | |
:returns: None/tuple that conflicted | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gevent import monkey | |
monkey.patch_all() | |
from dns import resolver | |
from tuck import tuck | |
def get_mail_server(receiver=''): | |
user, domain = receiver.split('@') | |
dest_list = sorted([x.to_text().strip('.').split(' ') |