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\]"
How I created a Google Apps jtauber@jtauber.com gmail account when I already had a Google Account called
jtauber@jtauber.com:
1) While signed in to jtauber@jtauber.com Google Account, I created a temporary @gmail.com email address.
This effectively enabled me to alternatively log into my existing Google Account via that @gmail.com address
2) I logged out and signed up for Google Apps with username admin@jtauber.com
3) I added a 'jtauber' user under the jtauber.com Google Apps domain and gave it Super Admin privileges.
That effectively shut out my ability to log into my original Google Account with jtauber@jtauber.com but
I still can using the temporary @gmail.com address created in step 1.
import colorsys
VALUE = 0.8
def to_hex(h, s, v):
return "#%02X%02X%02X" % tuple(int(255 * i) for i in colorsys.hsv_to_rgb(h, s, v))
def generate_colour():
a = 1
while True:
@jtauber
jtauber / trim_zip.py
Created February 27, 2012 20:48
trim extra data off end of zipfile
import struct
ECD_SIG = "\x50\x4B\x05\x06"
ECD_LEN = 22
def trim_zip(filename_in, filename_out):
"""
trims the zipfile give by filename `filename_in`, removing any bytes
after the end of central directory record and writing the result to
a file with filename `filename_out`.