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 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(): |
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 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 |
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 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])): |
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: 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 |
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
$ cat ~/bin/shurl | |
#!/bin/bash | |
curl -i http://shurl.im/ -F "url=$1" -s | grep Location | awk '{print $2}' | |
$ shurl http://lyxint.com/ | |
http://shurl.im/1 | |
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: utf8 | |
from __future__ import with_statement, absolute_import | |
import os | |
import re | |
import sys | |
import signal | |
import string | |
import random |
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 timeit | |
def f1(list): | |
string = "" | |
for item in list: | |
string = string + chr(item) | |
return string | |
def f2(list): | |
return reduce(lambda string, item: string + chr(item), list, "") |
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 txt_wrap_by(begin, end, html): | |
if not html: | |
return '' | |
start = html.find(begin) | |
if start >= 0: | |
start += len(begin) | |
end = html.find(end, start) | |
if end >= 0: | |
return html[start:end].strip() |
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
#!/bin/env python | |
#-*- coding: utf-8 -*- | |
import sys | |
import os | |
from urlfetch import get | |
user = sys.argv[1] | |
r = get('https://api.github.com/users/%s/repos' % user) |
OlderNewer