Skip to content

Instantly share code, notes, and snippets.

View mondaychen's full-sized avatar

Mengdi Chen mondaychen

View GitHub Profile
@mondaychen
mondaychen / Stacking_rectangles.py
Last active August 29, 2015 14:17
Stacking rectangles
def lcs(x, y):
n = len(x)
m = len(y)
table = dict() # a hashtable, but we'll use it as a 2D array here
for i in range(n+1): # i=0,1,...,n
for j in range(m+1): # j=0,1,...,m
if i == 0 or j == 0:
table[i, j] = 0
elif x[i-1] == y[j-1]:
p{
width: 220px;
margin: 0;
}
@mondaychen
mondaychen / gist:1598350
Created January 12, 2012 03:17 — forked from getify/gist:670840
using LABjs to load from a CDN, with simple error detection (& timeout), and a local load fallback
function loadOrFallback(scripts,idx) {
var successfully_loaded = false;
function testAndFallback() {
clearTimeout(fallback_timeout);
if (successfully_loaded) return; // already loaded successfully, so just bail
try {
scripts.tester();
successfully_loaded = true; // won't execute if the previous "test" fails
scripts.success();
// console.log("success: " + scripts.src[idx]);