Skip to content

Instantly share code, notes, and snippets.

View seanjensengrey's full-sized avatar

Sean Jensen-Grey seanjensengrey

View GitHub Profile
#!/usr/bin/env python
import optparse
import simplejson as json
import time
LONGNAME = "%s@en-US"
def load_file(filename):
'''
Load a json file and return the resulting object
#!/bin/bash
hadoop jar /usr/lib/hadoop/contrib/streaming/hadoop-streaming*jar \
-D mapred.map.tasks=1 \
-D mapred.reduce.tasks=0 \
-D mapred.min.split.size=9223372036854775807L \
-input '/newspapers/1/text/Job17/newspapersText-1055094522681797772.avro' \
-output _md5test \
-mapper shim_md5sum.sh \
-file shim_md5sum.sh \
@seanjensengrey
seanjensengrey / Rationale.md
Created July 11, 2011 16:31 — forked from leegao/Rationale.md
JIT for dummies: JIT compiling RPN in python

If you don't care about the explanation, scroll down to find the code, it's 50 some odd lines and written by someone who doesn't know any better. You have been warned.

What it does

This is a very simple proof of concept jitting RPN calculator implemented in python. Basically, it takes the source code, tokenizes it via whitespace, and asks itself one simple question: am I looking at a number or not?

First, let's talk about the underlying program flow. Pretend that you are a shoe connoisseur with a tiny desk. You may only have two individual shoes on that desk at any one time, but should you ever purchase a new one or get harassed by an unruly shoe salesman without realizing that you have the power to say no (or even maybe?), you can always sweep aside one of the two shoes on the desk (the one on the right, because you're a lefty and you feel that the left side is always superior) onto the messy floor, put the other shoe on the right hand side, and then place your newly acquired shoe in

require 'formula'
class Gmp < Formula
url 'ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.2.tar.bz2'
homepage ''
md5 '0bbaedc82fb30315b06b1588b9077cd3'
def install
# fix for CC defaulting to llvm
ENV.gcc_4_2
@seanjensengrey
seanjensengrey / rdfind.rb
Created September 6, 2011 23:13
hardlink duplicate files
require 'formula'
class Rdfind < Formula
url 'http://rdfind.pauldreik.se/rdfind-1.3.0.tar.gz'
homepage ''
md5 'c68e1bd0b6cb07dfae1a85ce4968b55b'
depends_on 'nettle'
def install
@seanjensengrey
seanjensengrey / mrisc.rb
Created September 17, 2011 18:08 — forked from pachacamac/mrisc.rb
A Simple Assembler Language and VM
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1
@seanjensengrey
seanjensengrey / Ray.py
Created December 7, 2011 07:15
python ray tracer
from math import sqrt
import pdb
DELTA = 1.5e-8
INFINITY = 1e5000
def Vec(x=0.0,y=0.0,z=0.0):
return [float(x),float(y),float(z)]
@seanjensengrey
seanjensengrey / gist:1441834
Created December 7, 2011 07:18
pypy profiler output
## profile output from, https://gist.github.com/1441828
pythonray zel$ pypy -m cProfile Ray.py --run 5 512
52623770 function calls (47268030 primitive calls) in 11.745 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.001 0.001 11.745 11.745 Ray.py:1(<module>)
341/1 0.004 0.000 0.007 0.007 Ray.py:112(create)
@seanjensengrey
seanjensengrey / gist:1686149
Created January 27, 2012 00:34 — forked from anonymous/gist:1686070
Bash function to open a multiline text file that contains a single URL
# can split up a long url into multiple lines in a file url.txt
# and then go to it by typing "ffue url.txt"
function ffue() {
open -a FireFox $(paste -s -d '\0' $1)
}
@seanjensengrey
seanjensengrey / tlc.lua
Created March 28, 2012 16:04 — forked from fjolnir/tlc.lua
LuaJIT ObjC bridge
-- TLC - The Tiny Lua Cocoa bridge
-- Note: Only tested with LuaJit 2 Beta 9 on x86_64 with OS X >=10.7.3 & iPhone 4 with iOS 5
-- Copyright (c) 2012, Fjölnir Ásgeirsson
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES