Skip to content

Instantly share code, notes, and snippets.

Ming Han Teh minghan

Block or report user

Report or block minghan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
minghan /
Created Jul 7, 2011
Python Memoize Example
# Memoize Example
class Pak(object):
# Do not use @staticmethod here
def memoize(key):
def decfunc(f):
def newfunc(self):
if not hasattr(self, key):
setattr(self, key, f(self))
minghan /
Created Jul 7, 2011
Indent profile for --linux for older versions of indent
-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -i4 -ip0 -l80 -lp -npcs -nprs -npsl -sai -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8000
minghan / sphinx-autopackage
Created Jul 8, 2011
Sphinx autopackage guide
View sphinx-autopackage
Example usage:
./ ~/path/to/some/package -d ~/dest/path/
minghan /
Created Jul 8, 2011
Python Compile and Exec test
# Compile and Exec test
# Just making sure that exec deals with scoping correctly
# Note that the compile statement compiles code into bytecode, but does not execute it
# Reference:
def pakrox2():
print "pakrox2 external"
code = ""
# Using @property
class Pakrox(object):
def __init__(self):
self._pak = 10
def pak(self):
return self._pak
minghan /
Created Jul 13, 2011
Camecase to Underscore lowercase
import re
def underscore(text):
def repl(m):
return "_" +
return re.sub(r"([A-Z])", repl, text)
print underscore("helloWorld")
View microbookmarklet.js
javascript: var script = document.createElement("script"); script.src=""; document.body.appendChild(script); void(0);
minghan /
Created Jul 27, 2011
Multiprocessing example
from multiprocessing import Pool, JoinableQueue, Manager
# Note that jqueue.task_done() must be called to decrement the count if jqueue.join() is to be used correctly.
import time, os, signal
def handler(signum, frame):
print "signal caught in %d" % os.getpid()
signal.signal(signal.SIGTERM, handler)
View gist:1277101
# Tips from
mkdir ~/eggs
export PATH=$PATH:~/eggs
# echo "export PYTHONPATH=$PYTHONPATH:~/eggs" >> ~/.bashrc
# echo "export PATH=$PATH:~/eggs" >> ~/.bashrc
curl -O
rmiregistry &
java EventManager &
echo "Started EM"
pkill rmiregistry
You can’t perform that action at this time.