Skip to content

Instantly share code, notes, and snippets.

View jlfwong's full-sized avatar

Jamie Wong jlfwong

View GitHub Profile
@jlfwong
jlfwong / handler.py
Created May 10, 2012 15:02
ENV server->js data pattern
Why this is useful:
1. All data in ENV is coming from the server, so it's easy to differentiate data coming from the server and static data when reading through JS.
2. If you put the {{ env_js }} in the root template, it'll be usable by in all templates that inherit from it. That means you don't need to adjust the template to share data to the client-side.
3. Only one new global variable instead of one per thing coming from the server.
@jlfwong
jlfwong / pdb_on_error.py
Created May 7, 2012 18:00
pdb debug decorator
from functools import wraps
import sys
import pdb
import traceback
def pdb_on_error(func):
@wraps(func)
def pdbd(*args, **kwargs):
try:
func(*args, **kwargs)
@jlfwong
jlfwong / java.vim
Created February 2, 2012 04:22
Java ftplugin for working with eclim
" Stick this in ~/.vim/ftplugin/java.vim
" eclim goodness
call SuperTabSetDefaultCompletionType("<c-x><c-u>")
augroup eclim
autocmd!
autocmd BufWrite *.java :JavaImportMissing
autocmd BufWrite *.java :JavaImportClean
augroup END
nnoremap <buffer> <Leader>r :Java<CR>
@jlfwong
jlfwong / gist:1667581
Created January 24, 2012 03:20
Billboards
import sys
case = 1
def fits_at_size(W, H, size, words):
cur_row = 0
cur_col = 0
for word in S:
if len(word) * size > W:
@jlfwong
jlfwong / gist:1392387
Created November 24, 2011 21:53
No block scope, no variable hoisting
// Let's assume we have neither block scope nor variable hoisting.
if (foo) {
var x = 7;
}
console.log(x);
// We now either have a 7 printed or a Reference error.
keepDiv :: Int -> Int -> Int
keepDiv x n
| x `mod` n == 0 = keepDiv (x `div` n) n
| otherwise = x
nfacts' :: Int -> Int -> Int
nfacts' 1 _ = 0
nfacts' x n
| x `mod` n == 0 = 1 + nfacts' (x `keepDiv` n) (n + 1)
| otherwise = nfacts' x (n + 1)
@jlfwong
jlfwong / gist:747692
Created December 19, 2010 21:14
ECE 222 - Restoring Binary Division Algorithm
/*
Output:
Q: 17, A: 0, M: 5 [00000000 00010001]
Q: 34, A: 0, M: 5 [00000000 00100010]
Q: 68, A: 0, M: 5 [00000000 01000100]
Q: 136, A: 0, M: 5 [00000000 10001000]
Q: 16, A: 1, M: 5 [00000001 00010000]
Q: 32, A: 2, M: 5 [00000010 00100000]
Q: 64, A: 4, M: 5 [00000100 01000000]
#include <iostream>
#include <set>
#include <utility>
using namespace std;
int main() {
FILE* fin = fopen("freq.txt","r");
set<double> freqs;
double n;
//TEST AC - CPP (g++)
#include <iostream>
using namespace std;
int main() {
int n;
while(1) {
cin >> n;
if (n == 42) break;
cout << n << endl;
syntax on
set backspace=2 "Make backspace work as expected on Mac OS X
set autoindent "Auto Indent code - This simply retains indentation level
set tabstop=2 "Set space width of tabs
set sw=2
set noexpandtab "I like my tabs to stay as tabs
set splitright "By default, split to the right
set number "Add line numbers