This file contains hidden or 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
| (defmacro once-only ((&rest names) &body body) | |
| (let ((gensyms (loop for n in names collect (gensym)))) | |
| `(let (,@(loop for g in gensyms collect `(,g (gensym)))) | |
| `(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n))) | |
| ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g))) | |
| ,@body))))) | |
| (defmacro do-primes ((var start end) &body body) | |
| (once-only (start end) | |
| `(do ((,var (next-prime ,start) (next-prime (1+ ,var)))) |
This file contains hidden or 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 functools | |
| def decorator(d): | |
| "Make function d a decorator: d wraps a function fn." | |
| def _d(fn): | |
| return functools.update_wrapper(d(fn), fn) | |
| return _d | |
| decorator = decorator(decorator)(decorator) | |
| def decorator(annotation): |
This file contains hidden or 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
| ----INVALID EMAIL-----hcat18012 | |
| ----INVALID EMAIL-----1111 | |
| ----INVALID EMAIL-----darrenhg5atom.com | |
| ----INVALID EMAIL-----hcat19000 | |
| ----INVALID EMAIL-----passport.csdn.net/modifyemail.aspx | |
| Total records: 6428627 | |
| 1620956(0.252147) user name is part of email account | |
| 1463691(0.227683, 0.902980) user name is identical to email account | |
| Distinct passwords: 4037919(0.628115) | |
| # of email service providers: 68815 |
This file contains hidden or 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
| (defun simple-equal (x y) | |
| "Tests if two lists or atoms are equal." | |
| (or (eql x y) | |
| (and (listp x) (listp y) | |
| (simple-equal (car x) (car y)) | |
| (simple-equal (cdr x) (cdr y))))) | |
| (defun simple-equal (x y) | |
| "Tests if two lists or atoms are equal." | |
| (or (eql x y) |
This file contains hidden or 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
| """ | |
| Calculate AUC of a sample | |
| Reference: | |
| http://binf.gmu.edu/mmasso/ROC101.pdf | |
| """ | |
| import matplotlib.pyplot as plt | |
| # each element is a tuple(positive, score) | |
| sample = [ |
This file contains hidden or 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 random | |
| import copy | |
| graph = { | |
| "3" : {"in" : [], "out" : ["8", "10"]}, | |
| "5" : {"in" : [], "out" : ["11"]}, | |
| "7" : {"in" : [], "out" : ["11", "8"]}, | |
| "11" : {"in" : ["5", "7"], "out" : ["2", "9", "10"]}, | |
| "8" : {"in" : ["3", "7"], "out" : ["9"]}, | |
| "2" : {"in" : ["11"], "out" : []}, |
This file contains hidden or 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
| /* | |
| http://blog.exodusintel.com/2012/09/18/reversing-the-interview-process/ | |
| */ | |
| typedef int (*ctr)(char *); | |
| int strlen(char *); | |
| int func_x(char *c) { return 1+strlen(c); } | |
| int func_0(char *c) { return 0; } |
This file contains hidden or 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
| # See http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves | |
| hilbert_map = { | |
| 'a': {(0, 0): (0, 'd'), (0, 1): (1, 'a'), (1, 0): (3, 'b'), (1, 1): (2, 'a')}, | |
| 'b': {(0, 0): (2, 'b'), (0, 1): (1, 'b'), (1, 0): (3, 'a'), (1, 1): (0, 'c')}, | |
| 'c': {(0, 0): (2, 'c'), (0, 1): (3, 'd'), (1, 0): (1, 'c'), (1, 1): (0, 'b')}, | |
| 'd': {(0, 0): (0, 'a'), (0, 1): (3, 'c'), (1, 0): (1, 'd'), (1, 1): (2, 'd')}, | |
| } | |
| subquad_map = dict( | |
| (k, dict((quad[0], (pt, quad[1])) for pt, quad in v.iteritems())) |
This file contains hidden or 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
| http://cybertiggyr.com/amo/ |
This file contains hidden or 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: utf-8 -*- | |
| """ | |
| Decode BaiduYun share link. | |
| http://pan.baidu.com/share/link?shareid=#####&uk=###### | |
| The download link expires in a few hours, check `expires` | |
| parameter in the url. | |
| (c) 2013 by Charles Lee<[email protected]> |