Skip to content

Instantly share code, notes, and snippets.

@cpylua
cpylua / Google Charts Data Interface
Last active August 29, 2015 14:16
Google Charts Data Interface
# Google Charts Data Interface
There're two ways to pass data into chart:
* *DataTable*: A grid like table, there're various ways to populate a DataTable
* *DataView*: Just a read-only view of DataTable.
## DataTable
All charts store their data in `DataTable`, the structure is very similar to `MOJO` grid data. Different charts require different number of cols/rows in the table.
* `DataTable.addColumn()` to add a column. `addRows()`, `addRow()`, `setCell()`
* Rows and Cells, Cells can contain a value and a display value
* `arrayToDataTable` convenient function for converting an array to `DataTable`
@cpylua
cpylua / bdyun.py
Created January 27, 2013 01:45
BaiduYun share link decoder
# -*- 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]>
@cpylua
cpylua / pfds
Created December 7, 2012 07:27
Notes about Purely Functional Data Structures
http://cybertiggyr.com/amo/
@cpylua
cpylua / hilber.py
Created September 21, 2012 06:30
Hilbert Curve
# 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()))
@cpylua
cpylua / strlen.c
Created September 19, 2012 01:32
strlen with no conditional statement
/*
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; }
@cpylua
cpylua / tsort.py
Created September 5, 2012 06:19
Graph topological sort
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" : []},
@cpylua
cpylua / roc.py
Created August 29, 2012 02:30
ROC and AUC
"""
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 = [
@cpylua
cpylua / simple-equal.lisp
Created June 20, 2012 12:55
(simple-equal nil '(nil nil))
(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)
@cpylua
cpylua / csdn-passwords
Created May 16, 2012 06:21
CSDN leaked passwords summary
----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
@cpylua
cpylua / decorator.py
Created May 13, 2012 14:10
python meta-decorator
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):