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 python3 | |
# coding: utf-8 | |
import asyncio | |
import time | |
import fcntl | |
import os | |
import ctypes | |
import errno | |
""" Async file wrapper for asyncio. |
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 | |
# coding:utf-8 | |
from tornado.web import RequestHandler, Application | |
from tornado.ioloop import IOLoop | |
import urllib | |
class ChineseHandler(RequestHandler): |
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 | |
# coding:utf-8 | |
from os import urandom | |
from base64 import urlsafe_b64decode, urlsafe_b64encode | |
import redis | |
import binascii | |
redis = redis.StrictRedis('localhost') | |
R_SESION = "SESSION:%s" |
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 | |
# coding:utf-8 | |
from collections import defaultdict | |
from random import uniform | |
from math import sqrt | |
def point_avg(points): | |
""" 计算并返回给定点的中心值 | |
""" |
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
class Node: | |
__slots__ = ('val', 'next') | |
def __init__(self, value=None, next=None): | |
self.val = value | |
self.next = next | |
def __str__(self): |
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 collections import defaultdict | |
def find_anagram(input_data): | |
""" find all the anagram from a dictionary | |
Anagram: contruct by the same word but have a different order | |
e.g. 'abc' 'acb' 'bca' is anagram | |
this solution comes from <Programming Pearls> chapter 2: |
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/python3 | |
import requests | |
from bs4 import BeautifulSoup | |
try: | |
from urllib.parse import urljoin # python 3.x | |
except: | |
from urlparse import urljoin # python 2.x | |
class Spider: |