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
| class Profiler(type): | |
| def __new__(mcl, name, bases, dict): | |
| from time import clock | |
| from types import FunctionType | |
| def timing(func): | |
| def wrapper(*args, **kwds): | |
| start = clock() | |
| value = func(*args, **kwds) | |
| end = clock() |
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 collections | |
| import functools | |
| from itertools import ifilterfalse | |
| from heapq import nsmallest | |
| from operator import itemgetter | |
| class Counter(dict): | |
| 'Mapping where default values are zero' |
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 imp | |
| import os | |
| import sys | |
| from marshal import Unmarshaller | |
| from classpathhacker import * | |
| jarloader=ClassPathHacker() | |
| __debugging__ = True | |
| def __readPycHeader(file): |
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 __future__ import with_statement | |
| from com.ziclix.python.sql import zxJDBC | |
| import sys | |
| #sys.path+=[r'/home/linker/jars/mysql-connector-java.jar'] | |
| #sys.path+=[r'/home/linker/jarss/'] | |
| from classpathhacker import * | |
| jarloader=classPathHacker() | |
| #jarloader.addFile(r'/home/linker/jars/mysql-connector-java.jar') |
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
| class ClassPathHacker : | |
| ########################################################## | |
| # from http://forum.java.sun.com/thread.jspa?threadID=300557 | |
| # | |
| # Author: SG Langer Jan 2007 translated the above Java to this | |
| # Jython class | |
| # Modified by: Linker Lin linker.lin@me.com | |
| # Purpose: Allow runtime additions of new Class/jars either from | |
| # local files or URL | |
| ###################################################### |
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 cached(function): | |
| cache = {} | |
| def wrapper(*args): | |
| if args in cache: | |
| ret=cache[args] | |
| if random.randint(1,100)>95: memo.pop(args) # random forget something | |
| return ret | |
| else: | |
| result = function(*args) |
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 -*- | |
| import sys | |
| reload(sys) | |
| sys.setdefaultencoding('utf-8') | |
| print sys.defaultencoding,u"中文" | |
| from java.awt import Color | |
| from javax.swing import ImageIcon |
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 -*- | |
| import sys | |
| reload(sys) | |
| sys.setdefaultencoding('utf-8') |
NewerOlder