Skip to content

Instantly share code, notes, and snippets.

View jhamrick's full-sized avatar

Jessica B. Hamrick jhamrick

View GitHub Profile
@jhamrick
jhamrick / savefig.py
Last active March 18, 2024 20:47
Function for saving figures from pyplot.
import os
import matplotlib.pyplot as plt
def save(path, ext='png', close=True, verbose=True):
"""Save a figure from pyplot.
Parameters
----------
path : string
The path (and filename, without the extension) to save the
@jhamrick
jhamrick / pets.py
Created April 5, 2013 17:06
Demonstration of python classes and inheritance.
class Pet(object):
def __init__(self, name, species):
self.name = name
self.species = species
def getName(self):
return self.name
def getSpecies(self):
@jhamrick
jhamrick / demise_of_for_loops.py
Created April 5, 2013 17:08
Script demonstrating speed differences between NumPy and native Python for loops.
from timeit import Timer
import numpy as np
import math
def timer(*funcs):
# find the maximum function name length
if len(funcs) > 1:
maxlen = max(*[len(func) for func in funcs])
elif len(funcs) == 1:
maxlen = len(funcs[0])
@jhamrick
jhamrick / omnigraffle-export_app_name.patch
Created April 15, 2013 23:58
omnigraffle-export: look for OmniGraffle Professional 5 if OmniGraffle 5 does not exist
From 1ebff43a47eea78643a903d85b13c91eb94d1e76 Mon Sep 17 00:00:00 2001
From: "Jessica B. Hamrick" <[email protected]>
Date: Mon, 15 Apr 2013 16:51:38 -0700
Subject: [PATCH] Look for OmniGraffle Professional 5 if OmniGraffle 5 does not
exist
---
omnigraffle_export/omnigraffle.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
def update_docstring(name, olddoc):
# make sure it has a docstring
if olddoc is None:
return None
# new docstring
prefix = "%s: " % name
if len(olddoc.split(": ")) > 1:
newdoc = prefix + olddoc.split(": ")[1]
else:
@jhamrick
jhamrick / indices.ipynb
Created July 7, 2013 19:35
Timing various methods of constructing list combinations.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhamrick
jhamrick / convert_cpo_to_sso.py
Last active December 21, 2015 21:39
Convert "towers of blocks" CPO files to SSO files.
"""Convert 'tower of blocks' CPO files to SSO files."""
# Standard
import os
import re
import colorsys
import sys
import pickle
# External
from path import path
import numpy as np
@jhamrick
jhamrick / enigma.py
Last active December 29, 2015 01:18 — forked from ivanov/enigma.py
# A template to demonstrate why we need to profile
# This instance written by Paul Ivanov (XXX: put your name / github id here)
import numpy as np
import random
def where_is_the_bottleneck(x):
return [random.randint(0, 100) for i in xrange(x)]
@jhamrick
jhamrick / About koans
Created April 10, 2014 05:10
This is a proof-of-concept for writing Python koans (https://github.com/gregmalcolm/python_koans) in an IPython notebook, based on the original about_strings.py (https://github.com/gregmalcolm/python_koans/blob/master/python2/koans/about_strings.py) koan.
{
"metadata": {
"name": "",
"signature": "sha256:68dde4e98d73981470a2678c04c4a291b230afea11aa551a38bac92ec836e42e"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@jhamrick
jhamrick / keep_assigning_hits.py
Created June 11, 2014 04:03
Extend HITs as assignments are completed
#!/usr/bin/env python
"""Extend HITs as assignments are completed.
If a HIT takes up a lot of bandwidth, then you may only want to have a
few workers doing it at a time. This script monitors how many
assignments are currently being worked on, and as they are completed,
extends the HIT with new assignments until a specified upper limit is
reached.