Skip to content

Instantly share code, notes, and snippets.

@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 {
@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 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 / 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 / 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 / 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: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: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:5235674
Created March 25, 2013 08:29
MDS example
# MDS example from http://www.analytictech.com/networks/mds.htm
import numpy as np
from sklearn import manifold
import matplotlib.pyplot as plt
cities = ["BOST", "NY", "DC", "MIAM", "CHIC", "SEAT", "SF", "LA", "DENV"]
dis = np.array([[0, 206, 429, 1504, 963, 2976, 3095, 2979, 1949],
[206, 0, 233, 1308, 802, 2815, 2934, 2786, 1771],
[429, 233, 0, 1075, 671, 2684, 2799, 2631, 1616],
[1504, 1308, 1075, 0, 1329, 3273, 3053, 2687, 2037],
import re
_SPACING_RE = re.compile(ur'\n[\s]+', re.DOTALL)
text = "\r\n Grand Hotel, Malahide, County Dublin, Ireland\r\n Tel. +353 1 845 0000 Fax +353 1 816 8225\r\n Email: [email protected]"
print _SPACING_RE.sub(u'', text)
print _SPACING_RE.sub(u'\n', text)
# output on my machine:
#Email: [email protected] +353 1 816 8225eland