Skip to content

Instantly share code, notes, and snippets.

View seanjensengrey's full-sized avatar

Sean Jensen-Grey seanjensengrey

View GitHub Profile
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
class HandlerClass(SimpleHTTPRequestHandler):
def do_GET(self):
SimpleHTTPRequestHandler.do_GET(self)
with open("not_found.html") as f:
HandlerClass.error_message_format = f.read()
@seanjensengrey
seanjensengrey / red_square.html
Last active August 29, 2015 14:24
red square
<!DOCTYPE html>
<html lang="en">
<head>
<style>
canvas {
border-style: solid;
border-width: 1px;
}
</style>
In [1]: from collections import namedtuple
In [2]: T = namedtuple("T","a b c",verbose=True)
class T(tuple):
'T(a, b, c)'
__slots__ = ()
_fields = ('a', 'b', 'c')
@seanjensengrey
seanjensengrey / stack_search.py
Last active August 29, 2015 14:25
dynamic scope like in the good old days
import sys
import pdb
import types
__doc__ = """
This example shows how to search back through the stack
for a local and return a reference to calling function.
Useful hack for when you are deep in the hierarchy and
#!/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
def pad(s,n,c):
if len(s) < n:
return (c * (n - len(s))) + s
else:
return s
def mk_add(base_vec):
base_m = dict(zip(base_vec,range(len(base_vec))))
assert len(base_vec) == len(base_m), "duplicate base token"
base_len = len(base_vec)
#!/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