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
#Python 装饰器 | |
#http://programmingbits.pythonblogs.com/27_programmingbits/archive/50_function_decorators.html | |
def memoize(f): | |
cache = {} | |
def helper(x): | |
if x not in cache: | |
cache[x] = f(x) | |
return cache[x] | |
return helper |
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
//JavaScript : The Good Parts | |
//闭包,存储数据 | |
var memoizer = function (memo, formula) { | |
var recur = function(n){ | |
var result = memo[n]; | |
if (typeof result !== 'number') { | |
result = formula(recur, n); | |
memo[n] = result; | |
}; | |
return result; |
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
#代码来自Python 2.7 Lib/wsgiref/utils.py | |
#__contains__判断一个字典中是否有key, 等同于has_key | |
_hoppish = { | |
'connection':1, 'keep-alive':1, 'proxy-authenticate':1, | |
'proxy-authorization':1, 'te':1, 'trailers':1, 'transfer-encoding':1, | |
'upgrade':1 | |
}.__contains__ | |
def is_hop_by_hop(header_name): |
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
#C数组下标的实现 | |
""" | |
其实一个例子就能说明,C中数组下标的实现方法。 | |
................ | |
int array[4]; | |
array[2] 和 2[array]是等价的。 | |
................ | |
2[array],这是个什么玩意儿。 | |
2[array]等价于: |
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
#include <cstdio> | |
#include <cstring> | |
#include <iostream> | |
using namespace std; | |
void match_list(char * pattern, int match[] , size_t len) | |
{ | |
memset(match, 0 ,sizeof(int)*len); |
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 sqlalchemy.exc import IntegrityError | |
from flask import g, request, session, redirect, flash | |
import urllib | |
import urllib2 | |
from app import models | |
@app.route('/douban/login') | |
def get_auth_code(): | |
return redirect("https://www.douban.com/service/auth2/auth?client_id=0fb837361a070e2d2f28a5a24e152a87&redirect_uri=https://douping.sinaapp.com/auth&response_type=code") |
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
/*写多了Java和Python,写C++全是坑。。。。。:| */ | |
#include <cstdio> | |
#include <string> | |
#include <iostream> | |
#include <vector> | |
#include <sstream> | |
#include <cstdlib> | |
#include <cassert> | |
class Student |
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
#heap sort | |
#intruduction to algorithm | |
import sys | |
from math import floor | |
def Max_Heapify(data,i): | |
l = 2*i | |
r = 2*i + 1 | |
if l <= len(data) - 1 and data[l] > data[i]: | |
largest = l |
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
_escape_map = {ord('&'): '&', ord('<'): '<', ord('>'): '>'} | |
_escape_map_full = {ord('&'): '&', ord('<'): '<', ord('>'): '>', | |
ord('"'): '"', ord('\''): '''} | |
# NB: this is a candidate for a bytes/string polymorphic interface | |
def escape(s, quote=True): | |
""" | |
Replace special characters "&", "<" and ">" to HTML-safe sequences. | |
If the optional flag quote is true (the default), the quotation mark |
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 re | |
cctlds = ['AC','AD','AE','AF','AG','AI','AL','AM','AN','AO','AQ','AR','AS','AT','AU','AW','AX','AZ','BA','BB','BD',\ | |
'BE','BF','BG','BH','BI','BJ','BL','BM','BN','BO','BQ','BR','BS','BT','BV','BW','BY','BZ','CA','CC','CD',\ | |
'CF','CG','CH','CI','CK','CL','CM','CN','CO','CO','CR','CU','CV','CW','CX','CY','CZ','DE','DJ','DK','DM',\ | |
'DO','DZ','EC','EE','EG','EH','ER','ES','ET','EU','FI','FJ','FK','FM','FO','FR','GA','GB','GD','GE','GF',\ | |
'GG','GH','GI','GL','GM','GN','GP','GQ','GR','GS','GT','GU','GW','GY','HK','HM','HN','HR','HT','HU','ID',\ | |
'IE','IL','IM','IN','IO','IQ','IR','IS','IT','JE','JM','JO','JP','KE','KG','KH','KI','KM','KN','KP','KR',\ | |
'KW','KY','KZ','LA','LB','LC','LI','LK','LR','LS','LT','LU','LV','LY','MA','MC','MD','ME','MF','MG','MH',\ | |
'MK','ML','MM','MN','MO','MP','MQ','MR','MS','MT','MU','MV','MW','MX','MY','MZ','NA','NC','NE','NF','NG',\ |
OlderNewer