Skip to content

Instantly share code, notes, and snippets.

View jtauber's full-sized avatar

James Tauber jtauber

View GitHub Profile
# Bash snippet to open new shells in most recently visited dir.
# Useful if you want to open a new terminal tab at the present
# tab's location.
#
# Put this in your .bashrc or whatever.
pathed_cd () {
if [ "$1" == "" ]; then
cd
else
# brainf*** Interpreter in Python
# Copyright (c) 2002 & 2006, James Tauber
#
# see http://en.wikipedia.org/wiki/Brainfuck
import sys
class brainf:
def __init__(self, program):
# Python implementation of the Gibbons-Lester-Bird algorithm[1] for enumerating
# the positive rationals.
#
# James Tauber 2004-07-01
# http://jtauber.com/
#
# [1] http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/rationals.pdf
def rationals():
"""
@jtauber
jtauber / gist:167009
Created August 13, 2009 05:33
Pi in Hex
# Implementation of Simon Plouffe's formula for Pi in Hex
#
# James Tauber 2007-03-14
# http://jtauber.com/blog/2007/03/14/generating_the_hex_digits_of_pi/
def pi():
N = 0
n, d = 0, 1
while True:
xn = (120*N**2 + 151*N + 47)
#!/usr/bin/env python
import os
import os.path
for root, dirs, files in os.walk("."):
for filename in files:
path = os.path.join(root, filename)
if any(filename.endswith(ending) for ending in [".py", ".html", ".txt", ".css"]):
tabs = False
#!/usr/bin/env python
import os
import os.path
for root, dirs, files in os.walk("."):
for filename in files:
path = os.path.join(root, filename)
if any(filename.endswith(ending) for ending in [".py", ".html", ".txt", ".css"]):
marked = []
@jtauber
jtauber / .bash_profile
Created September 3, 2011 10:55
OS X 10.7 Setup
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/share/python:$PATH
RED="\[\033[01;31m\]"
GREEN="\[\033[32m\]"
LGREEN="\[\033[01;32m\]"
YELLOW="\[\033[01;33m\]"
BLUE="\[\033[01;34m\]"
PURPLE="\[\033[01;35m\]"
CYAN="\[\033[01;36m\]"
def bitstruct(structure, value):
result = []
index = 8
for part in structure:
result.append((value & ((2 ** index - 1) - (2 ** (index - part) - 1))) >> (index - part))
index -= part
return tuple(result)
if __name__ == "__main__":
assert bitstruct((8, ), 42) == (42, )
@zacharyvoase
zacharyvoase / prob-m2m.md
Created August 22, 2012 01:11
Probabilistic M2M relationships using Bloom filters

Here’s an idea that’s been kicking around inside my head recently.

A standard M2M relationship, as represented in SQL, looks like this:

CREATE TABLE movie (
  id SERIAL PRIMARY KEY,
  name VARCHAR(255)
);
NEWTON is riding his bicycle in Lincolnshire when he comes across
SOCRATES on the road.
SOCRATES: For what purpose do you return to Woolsthorpe my dear sir?
NEWTON: Cambridge has been closed due to the plague.
SOCRATES: By Zeus! Closed?
NEWTON: Indeed.
SOCRATES: And so what are you doing with your time here? Surely not
farming.