Skip to content

Instantly share code, notes, and snippets.

@tpeng
tpeng / gist:5180501
Created March 17, 2013 07:29
python coroutine
def coroutine(func):
def start(*args, **kwargs):
cr = func(*args, **kwargs)
cr.next()
return cr
return start
@coroutine
def grep(pattern):
@tpeng
tpeng / gist:5035495
Created February 26, 2013 03:01
download from videolectures.net
import re
import subprocess
from urllib2 import urlopen
url = 'http://videolectures.net/ecmlpkdd08_carlson_bief/'
re_flv = re.compile(r'(flv:[\w/]+)')
html = urlopen(url).read()
m = re.search(re_flv, html)
if m:
@tpeng
tpeng / gist:4492006
Created January 9, 2013 09:54
login Quora programmatically but got HTTP Error 500
# login the Quora and get notifications with unofficial API (http://www.quora.com/Edmond-Lau/Edmond-Laus-Posts/Quora-Extension-API)
# tpeng <[email protected]> 2013/1/7
# some references
# https://gist.github.com/2341517
# http://www.ruby-doc.org/gems/docs/q/quora-client-0.1.2/Quora/Auth.html
# http://stackoverflow.com/questions/10616449/how-to-programmatically-log-in-to-quora-by-java-code
import cookielib
import json
@tpeng
tpeng / gist:4244614
Created December 9, 2012 12:11
Python27 on Windows 7 64 bit
WindWindows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Python]
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\Help]
@tpeng
tpeng / MinHash.java
Created August 28, 2012 09:17
A simple minhash implementation in Java.
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
/**
* A simple MinHash implementation inspired by https://github.com/jmhodges/minhash
*
* @author tpeng ([email protected])
*/
public class MinHash {
@tpeng
tpeng / dabblet.css
Created May 13, 2012 12:16
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
a { color: #00c; text-decoration: none; }
a:visited { color: #00c; }
a:hover { text-decoration: underline; }
.clear {clear:both;}
#content {
@tpeng
tpeng / dabblet.css
Created May 12, 2012 15:04
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
a { color: #00c; text-decoration: none; }
a:visited { color: #00c; }
a:hover { text-decoration: underline; }
.clear {clear:both;}
#content {
@tpeng
tpeng / dabblet.css
Created May 9, 2012 16:28
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
a { color: #00c; text-decoration: none; }
a:visited { color: #00c; }
a:hover { text-decoration: underline; }
.clear {clear:both;}
.hl {