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 | |
| #^_^ encoding: utf-8 ^_^ | |
| # @date: 14-5-4 | |
| import threading | |
| import Queue | |
| class WorkerPoolError(Exception): | |
| pass |
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 | |
| #^_^ encoding: utf-8 ^_^ | |
| # @date: 14-5-4 | |
| import types | |
| def wrapper(*args, **kwargs): | |
| print args, kwargs |
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 -x | |
| # 一但有任何一个语句返回非真的值,则退出bash | |
| set -e | |
| # 你使用未初始化的变量时,让bash自动退出 | |
| set -u | |
| SCRIPT_PATH="${BASH_SOURCE[0]}"; |
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
| # ^_^ encoding: utf-8 ^_^ | |
| # @brief: | |
| # @class: | |
| # @date: 2013-8-31 | |
| # @author: wujiabin | |
| class SkipListError(Exception): | |
| pass | |
| class Node(object): |
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
| /* | |
| Example of Skip List source code for C: | |
| Skip Lists are a probabilistic alternative to balanced trees, as | |
| described in the June 1990 issue of CACM and were invented by | |
| William Pugh in 1987. | |
| This file contains source code to implement a dictionary using | |
| skip lists and a test driver to test the routines. |
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 | |
| """ Copied from http://code.activestate.com/recipes/82234-importing-a-dynamically-generated-module/. | |
| This is a sample code to show how to load python code string to a module dynamically. | |
| """ | |
| # Importing a dynamically generated module | |
| def importCode(code,name,add_to_sys_modules=0): | |
| """ |
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 | |
| # ^_^ encoding: utf-8 ^_^ | |
| # @date: 2014/8/8 | |
| """ | |
| worker_pool | |
| 简单的线程池, 提交任务即可, 会后台执行, 并将结果返回 | |
| 示例见main部分 | |
| TODO | |
| 1. 清空status的时机, 删除已经返回的key, 否则内存要爆 | |
| """ |
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
| """ | |
| Code to timeout with processes. | |
| >>> @timeout(.5) | |
| ... def sleep(x): | |
| ... print "ABOUT TO SLEEP {0} SECONDS".format(x) | |
| ... time.sleep(x) | |
| ... return x | |
| >>> sleep(1) |
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
| def sbv0(adict, reverse=False): | |
| return sorted(adict.iteritems(), key=lambda (k, v): (v, k), reverse=reverse) | |
| def sbv1(d, reverse=False): | |
| L = [(k, v) for (k, v) in d.iteritems()] | |
| return sorted(L, key=lambda x: x[1], reverse=reverse) | |
| def sbv2(d, reverse=False): |
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
| # based on Recipe 466302: Sorting big files the Python 2.4 way | |
| # by Nicolas Lehuen | |
| import os | |
| from tempfile import gettempdir | |
| from itertools import islice, cycle | |
| from collections import namedtuple | |
| import heapq | |
| Keyed = namedtuple("Keyed", ["key", "obj"]) |
OlderNewer