Skip to content

Instantly share code, notes, and snippets.

Jeff Terrace jterrace

Block or report user

Report or block jterrace

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jterrace /
Created Sep 20, 2018
Programmatically determine how to distribute your chips for Take Your Chances game
import sys
distribution = [0] * DICE_SIDES
for d1 in range(1, DICE_SIDES + 1):
for d2 in range(1, DICE_SIDES + 1):
delta = abs(d1 - d2)
distribution[delta] += 1
distribution = [
jterrace /
Last active Sep 17, 2019
An example of how to use Google Cloud Storage with git-annex
# Initialize git and git-annex
$ mkdir annex-gcs-test
$ cd annex-gcs-test/
$ git init
Initialized empty Git repository in /Users/jterrace/annex-gcs-test/.git/
$ git annex init "my machine"
init my machine ok
(Recording state in git...)
# Set up AWS credentials
jterrace /
Created Aug 30, 2012
Creates a graph comparing disk read throughput to Internet speeds over time
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rc
rc('text', usetex=True)
rc('font', family='sans-serif')
rc('font', size='16')
# source:
jterrace /
Created Jul 19, 2012
Drops python to a debugger on unhandled exceptions
"""Import this module to make python drop to the debugger
when an undhandled exception is raised.
Original script from:
import sys
__old_excepthook__ = sys.excepthook
jterrace / xvfb
Created Jun 11, 2012
xvfb init script for Ubuntu
View xvfb
XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset"
case "$1" in
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
jterrace / lang-llvm.js
Created Jun 1, 2012
LLVM plugin for google-code-prettify
View lang-llvm.js
* @fileoverview
* Registers a language handler for LLVM.
* To use, include prettify.js and this file in your HTML page.
* Then put your code in an HTML tag like
* <pre class="prettyprint lang-llvm">(my LLVM code)</pre>
jterrace /
Created Feb 23, 2012
A utility script for traffic shaping with tc
# ---------
# A utility script for traffic shaping using tc
# Usage
# -----
# start - starts the shaper
# stop - stops the shaper
jterrace /
Created Feb 14, 2012
A collection of fuzzy floating point utility functions for Python
import math
def almostEqual(a, b, rtol=1.0000000000000001e-05, atol=1e-08):
"""Checks if the given floats are almost equal. Uses the algorithm
from numpy.allclose."""
return math.fabs(a - b) <= (atol + rtol * math.fabs(b))
def floor(v):
"""Returns the floor of the given number, unless it is equal to its
ceiling (within floating point error)."""
jterrace / gist:1823320
Created Feb 14, 2012
Automatically log in user after django-registration activation
View gist:1823320
from registration.signals import user_activated
from django.contrib.auth import login, authenticate
def login_on_activation(sender, user, request, **kwargs):
"""Logs in the user after activation"""
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
# Registers the function with the django-registration user_activated signal
jterrace /
Created Nov 3, 2011
Removing duplicate triangles with numpy
import numpy as np
def remove_duplicates(array_data, return_index=False, return_inverse=False):
"""Removes duplicate rows of a multi-dimensional array. Returns the
array with the duplicates removed. If return_index is True, also
returns the indices of array_data that result in the unique array.
If return_inverse is True, also returns the indices of the unique
array that can be used to reconstruct array_data."""
unique_array_data, index_map, inverse_map = np.unique(
array_data.view([('', array_data.dtype)] * \
You can’t perform that action at this time.