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
import signal | |
class TimeoutError(Exception): | |
pass | |
class TimeoutHandler(object): | |
def __init__(self, seconds=60, error_message='Timeout'): | |
self.seconds = seconds |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from requests import Session | |
from requests.adapters import HTTPAdapter, DEFAULT_POOLSIZE, DEFAULT_RETRIES, DEFAULT_POOLBLOCK | |
class DNSResolverHTTPSAdapter(HTTPAdapter): | |
def __init__(self, | |
common_name, |
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 -*- | |
""" | |
Get images from http://www.douban.com/photos/album/145486923/. | |
""" | |
__author__ = 'demonkit' | |
import re | |
import threading |
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 -*- | |
def dijkstra(graph, source=0): | |
nodes = dict.fromkeys(range(len(graph)), 0) | |
# all visited nodes, source is the first entry. | |
visited = {source: 0} | |
# previous node dict |
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
import numpy | |
def lcs_length(X, Y): | |
m, n = len(X), len(Y) | |
min_len = min(m, n) | |
max_len = max(m, n) | |
C = numpy.zeros(shape=(2, min_len+1)) | |
if m == min_len: | |
min_list = X | |
max_list = Y |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import threading | |
class Node(object): | |
def __init__(self, | |
key, value, | |
pre=None, next=None): |