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 sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') |
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 sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
print sys.defaultencoding,u"中文" | |
from java.awt import Color | |
from javax.swing import ImageIcon |
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 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 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 [email protected] | |
# Purpose: Allow runtime additions of new Class/jars either from | |
# local files or URL | |
###################################################### |
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 __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 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 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 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 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 Timer(object): | |
def __init__(self, name): | |
print("%s: " % name, end="") | |
def __enter__(self): | |
self.t0 = time.time() | |
def __exit__(self, *args): | |
print("%.3fs" % (time.time() - self.t0)) | |
with Timer("XXX"): | |
call_function() |
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
this.class.classLoader.rootLoader.addURL(new URL("file:////Users/linkerlin/.m2/repository/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar")) | |
import groovy.sql.Sql | |
sql = Sql.newInstance("jdbc:mysql://localhost:3306/test", "root", "", "com.mysql.jdbc.Driver") | |
sql.eachRow("SELECT id, username FROM users") | |
{ | |
println "The employee's name is ${it.username}" | |
} | |
// Or using grape | |
@GrabConfig(systemClassLoader=true) // this is very important... |
OlderNewer