This file contains hidden or 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/env python | |
import threading | |
import functools | |
global mutex | |
mutex = threading.Lock() | |
This file contains hidden or 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/env python | |
# Tested with Python 2.7.9, Linux & Mac OS X | |
import socket | |
import StringIO | |
import sys | |
This file contains hidden or 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/env python | |
#-*- coding: utf-8 -*- | |
""" 此脚本作为参考: | |
根据私钥增加 DNS 正向和反向记录. | |
""" | |
import os |
This file contains hidden or 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/env python | |
import urllib | |
import contextlib | |
with contextlib.closing(urllib.urlopen("http://www.baidu.com")) as x: | |
print x.code |
This file contains hidden or 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/env python | |
#-*- coding: utf-8 -*- | |
""" | |
包含 yield 指令的函数执行的时候就是一个生成器, 其实一个协程对象, | |
启动后执行到 yield 指令后返回 yield 后的内容, 然后让出, 等待下一次执行. | |
""" | |
def create_generator(): |
This file contains hidden or 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/env python | |
# -*- coding: utf-8 -*- | |
import subprocess | |
text=""" | |
test0 test10 | |
test1 test11 | |
""" |
This file contains hidden or 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 | |
# set the path to nginx log files | |
log_files_path="/home/work/nginx/logs/" | |
#log_files_dir=${log_files_path}/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m") | |
log_files_dir="$log_files_path" | |
# set nginx log files you want to cut | |
log_files_type=(access error) |
This file contains hidden or 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
#-*- coding: utf-8 -*- | |
""" | |
方法1, 实现 __new__ 方法 | |
并在将一个类的实例绑定到类变量 _instance上, | |
如果 cls._instance 为 None 说明该类还没有实例化过,实例化该类,并返回 | |
如果 cls._instance 不为 None , 直接返回 cls._instance | |
""" |
This file contains hidden or 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/env python | |
# -*- coding: utf-8 -*- | |
import os | |
import time | |
import logging | |
from logging.handlers import TimedRotatingFileHandler | |
LOG_DIR = "/tmp/" |
This file contains hidden or 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 concurrent.futures import ThreadPoolExecutor | |
from functools import partial, wraps | |
import time | |
import tornado.ioloop | |
import tornado.web | |
EXECUTOR = ThreadPoolExecutor(max_workers=4) |