Skip to content

Instantly share code, notes, and snippets.

View dehowell's full-sized avatar

David Howell dehowell

View GitHub Profile
@dehowell
dehowell / README.md
Last active August 29, 2015 14:15 — forked from mbostock/.block
General Update Pattern, II - Broken for Educational Purposes

This is a deliberately broken fork of Mike Bostock's "General Update Pattern, II". Please see the original for an explanation of what's supposed to be happening. I've increased the pause between updates and switched to the default key function to illustrate how D3 calculates the enter, update, and exit selections. Open the console to see the data for each update.

@dehowell
dehowell / README.md
Last active August 29, 2015 14:07
Calculating Pi with Monte Carlo Methods

This is a demonstration of how to calculate π using Monte Carlo integration.

@dehowell
dehowell / gist:1cc3e5c57662535a520d
Last active August 29, 2015 14:07
Data clean-up script for CBCL export files, for @jabaied.
#!/usr/bin/env python
'''
usage: %s input_file output_file
'''
import collections
import csv
import sys
@dehowell
dehowell / keybase.md
Created February 25, 2014 00:45
keybase.md

Keybase proof

I hereby claim:

  • I am dehowell on github.
  • I am dehowell (https://keybase.io/dehowell) on keybase.
  • I have a public key whose fingerprint is EE13 6FE8 20BD 6768 1C1F F841 54EF 03F8 51F4 7BF4

To claim this, I am signing this object:

@dehowell
dehowell / ical_to_csv.py
Created December 31, 2012 15:03
Python script for converting iCal events (using the appscript module) to a CSV file.
import csv
import re
import sys
import appscript
def get_calendar(name):
calendar = appscript.app('iCal').calendars[name]
try:
calendar.get()
@dehowell
dehowell / bandit.py
Created December 28, 2012 16:18
Multi-armed bandit simulation.
#!/usr/bin/env python
import csv
import math
import random
import sys
import numpy
NUMBER_OF_LEVERS = 10
@dehowell
dehowell / gist:4188413
Created December 2, 2012 12:24
Plotting a bar graph
# Install the awesome ggplot graphics library
install.packages("ggplot2")
# Read in the data file, assuming a CSV and a header line
running <- read.table("running.csv", sep=",", header=TRUE)
# Plot!
ggplot(running, aes(x = as.Date(date), ymin = 0, ymax = ounces)) + geom_linerange()
@dehowell
dehowell / count_nef_files.py
Created May 5, 2012 11:16
Python script for searching a large binary file for .NEF file headers.
#!/usr/bin/env python
import sys
# .NEF (Nikon Electronic Format) headers
SIGNATURE = '\x4d\x4d\x00\x2a\x00\x00\x00\x08\x00'
def read_chunks(stream, overlap = len(SIGNATURE), size = 100 * 2 ** 20):
'''Read chunks from the stream with a small overlap.'''
data = stream.read(size)
while True:
@dehowell
dehowell / hadoop-tmux.sh
Created August 14, 2011 00:11
Script to initiate a single node Hadoop cluster in a tmux session
#!/bin/bash
#
# Script to initiate (or connect to) a single node Hadoop cluster in a
# tmux session. Requires that tmux and hadoop are on your path.
SESSION=hadoop
tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
echo "Session $SESSION already exists. Attaching."
@dehowell
dehowell / gist:884204
Created March 23, 2011 22:49
Python function to test if a file at a URL exists.
import urllib2
def file_exists(location):
request = urllib2.Request(location)
request.get_method = lambda : 'HEAD'
try:
response = urllib2.urlopen(request)
return True
except urllib2.HTTPError:
return False