Skip to content

Instantly share code, notes, and snippets.

@yangjuven
yangjuven / run.py
Created February 11, 2012 14:07
find bottleneck of wsgi service using python cProfile
#!/usr/bin/env python
# -*- coding: gb2312 -*-
# $Id$
import os, sys, cProfile
from wsgi_handler import application
def wsgi():
environ = dict(os.environ.items())
environ.update({
@yangjuven
yangjuven / md5sum.py
Created February 14, 2012 09:23
Get md5 of file without getting all content. It's very pythonic
#!/usr/bin/env python
import sys, hashlib
m = hashlib.md5()
with open(sys.argv[1], "rb") as fp:
for chunk in iter(lambda :fp.read(128 * m.block_size), ""):
m.update(chunk)
@yangjuven
yangjuven / webpy_queue.py
Created March 7, 2012 16:08
Test gevent.queue in web.py.
#!/usr/bin/env python
# -*- coding: utf8 -*-
import web
import gevent
from gevent import queue
from gevent.timeout import Timeout
from gevent.hub import Waiter
from gevent.pywsgi import WSGIServer
from gevent import monkey
@yangjuven
yangjuven / absolutizeURL.js
Created March 19, 2012 12:24
absolutize url.
function absolutizeURL(url){
var img = document.createElement("img");
img.src = url; // set string url
url = img.src; // get qualified url
img.src = null; // no server request
return url;
}
@yangjuven
yangjuven / cgi_testing.py
Created November 8, 2012 15:33
test for python cgi.
#!/usr/bin/env python
# -*- coding: utf8 -*-
import os
import sys
import subprocess
environ = {
"QUERY_STRING": "name=juven",
"REQUEST_METHOD": "GET",