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 selectors | |
import errno | |
import sys | |
class IOLoop(object): | |
@classmethod |
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 socket | |
import time | |
tic = lambda x: '\nat %1.1f second' % (time.time() - x) | |
def get_request(path): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect(('127.0.0.1', 8088)) | |
sock.setblocking(0) |
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 selectors | |
import errno | |
import sys | |
class IOLoop(object): | |
@classmethod |
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 bisect | |
import heapq | |
import time | |
from collections import namedtuple | |
timeouts = namedtuple('Timeouts', ['deadline', 'task']) | |
class Task(object): | |
def __init__(self, schedule, name): |
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 ngetmprint(list, ans, m): | |
if m == len(list): | |
ans = ans + list | |
print ans | |
elif m == 0: | |
print ans | |
else: | |
ngetmprint(list[1:], ans + list[0:1], m - 1) | |
ngetmprint(list[1:], ans, m) |
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 full_permutation(arr, cursor): | |
if cursor == len(arr) - 1: | |
print arr | |
return | |
for i in range(cursor, len(arr)): | |
arr[cursor], arr[i] = arr[i], arr[cursor] | |
full_permutation(arr, cursor + 1) | |
arr[cursor], arr[i] = arr[i], arr[cursor] |
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 urllib import urlencode | |
from urlparse import urlparse, urlunparse, parse_qsl | |
url = 'https://www.baidu.com?fuxk=true&m=1' | |
url_parts = list(urlparse(url)) | |
query = dict(parse_qsl(url_parts[4])) | |
query.update({'nimabi': 1111}) | |
url_parts[4] = urlencode(query) | |
print urlunparse(url_parts) |
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
_filename_gbk_strip_re = re.compile(u"^[\u4e00-\u9fa5A-Za-z0-9_.-]+$") | |
def secure_filename(filename): | |
if isinstance(filename, text_type): | |
from unicodedata import normalize | |
filename = normalize('NFKD', filename).encode('utf-8', 'ignore') | |
if not PY2: | |
filename = filename.decode('utf-8') | |
for sep in os.path.sep, os.path.altsep: |
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
# coding=utf-8 | |
import os, logging | |
import random | |
import signal | |
import time | |
import sys |
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 signal | |
def handle_hup(sig, frame): | |
print "get signal: %s"%sig | |
signal.signal(signal.SIGHUP, handle_hup) | |
if __name__ == '__main__': | |
ign = signal.SIG_IGN |