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
# http://vdisk.weibo.com/s/azYuqTtsWXaEc | |
def analysis(fn): | |
with open(fn, 'rb') as f: | |
content = f.read() | |
word_dict = {} | |
cur_word = '' | |
total_word = 0 | |
for c in content: |
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 | |
# http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ | |
import sys, os, time, atexit | |
from signal import SIGTERM | |
class Daemon: | |
""" | |
A generic daemon class. | |
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
import functools | |
import sys | |
import pyinotify | |
import datetime | |
def restart(): | |
pass | |
class MyEventHandler(pyinotify.ProcessEvent): | |
def my_init(self, file_object=sys.stdout): |
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
import math,operator as op | |
Number = (int, float) | |
Symbol = str | |
class Env(dict): | |
"An environment: a dict of {'var':val} pairs, with an outer Env." | |
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 | |
# http://stackoverflow.com/questions/9166400/convert-rgba-png-to-rgb-with-pil | |
# http://stackoverflow.com/questions/1962795/how-to-get-alpha-value-of-a-png-image-with-pil | |
import sys | |
from PIL import Image | |
def main(): | |
png = Image.open(sys.argv[1]) | |
png.load() | |
background = Image.new("RGB", png.size, (255, 255, 255)) |
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/bash | |
welcome=( | |
'佛祖保佑 永无BUG' | |
'你好啊单身狗' | |
'壮士,干了这碗鸡汤!' | |
'上线了吗?' | |
'法海,你的头发怎么那么长!' | |
'少壮不努力,长大做挨踢.' | |
'佛祖,我好烦.' |
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
import os | |
import sys | |
import random | |
# more info | |
# http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py | |
# We need a crypt module, but Windows doesn't have one by default. Try to find | |
# one, and tell the user if we can't. | |
try: |
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
proxy_cache_path /data/nginx/cache/ levels=1:2 keys_zone=one:10m max_size=10g; | |
proxy_cache_key "$host$request_uri"; | |
upstream google_jp { | |
server 173.194.38.216:80; | |
server 173.194.38.215:80; | |
server 173.194.38.217:80; | |
server 173.194.38.218:80; | |
} | |
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/bash | |
BACKUP_DB="xx" | |
DUMP_CMD="/usr/bin/mongodump" | |
HOST="127.0.0.1" | |
PORT="27017" | |
TIMESTAMP=`date +%F-%H%M` | |
BACKUP_DIR="/opt/data/backup" | |
cd $BACKUP_DIR | |
BACKUP_NAME_PREFIX="app-db" |
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
import os | |
import inspect | |
import atexit | |
from functools import wraps | |
class OneProcess(object): | |
def __init__(self): | |
self.caller_file_name = inspect.getouterframes( |