Skip to content

Instantly share code, notes, and snippets.

@ifduyue
ifduyue / httpsqs.py
Created December 14, 2011 04:04
httpsqs python client
#coding: utf8
import urllib
class HTTPSQS:
def __init__(self, host='127.0.0.1', port=1218, charset=None):
self.host = host
self.port = port
self.charset = charset
@ifduyue
ifduyue / benchmark.py
Created December 12, 2011 07:40
benchmark pylru, lrucache, lru
import lru
import lrucache
import pylru
import random
import sys
size = int(sys.argv[1])
data = []
range_ = int(sys.argv[2])
for i in xrange(int(sys.argv[3])):
@ifduyue
ifduyue / gist:1376898
Created November 18, 2011 16:11
mb_code.py
def mb_code(string, coding="utf-8"):
if isinstance(string, unicode):
return string.encode(coding)
for c in ('utf-8', 'gb2312', 'gbk', 'gb18030', 'big5'):
try:
return string.decode(c).encode(coding)
except: pass
return string
@ifduyue
ifduyue / gist:1183166
Created August 31, 2011 09:29
httplib example: publish a fanfou status
def setcookie2cookie(setcookie):
cookies = setcookie.split("\n")
result = []
for ck in cookies:
frags = ck.split(";")
i = frags[0].index("=")
name = frags[0][:i]
value = frags[0][i+1:]
#name = name.replace("+", " ")
if name.strip():