Skip to content

Instantly share code, notes, and snippets.

View jhamrick's full-sized avatar

Jessica B. Hamrick jhamrick

View GitHub Profile
@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 / reconstruct_3d.py
Created April 5, 2016 04:01
CS280 Python version of reconstruct_3d.m
import os
import numpy as np
import scipy.misc
import scipy.io
import matplotlib.pyplot as plt
def reconstruct_3d(name, plot=True):
"""
Homework 2: 3D reconstruction from two Views
@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 / make_feedback_notebook.py
Created February 9, 2016 16:29
An example of how to programmatically generate a feedback notebook for nbgrader
import os
import pandas as pd
from nbgrader.api import Gradebook
from nbformat import write as write_nb
from nbformat.v4 import new_notebook, new_markdown_cell
def gradebook():
if os.environ.get('NBGRADER_DB_URL', ''):
gb = Gradebook(os.environ['NBGRADER_DB_URL'])
@jhamrick
jhamrick / return_feedback.py
Created October 9, 2015 19:46
Return nbgrader feedback to students
"""Return feedback to students that was generated with `nbgrader feedback`.
This must be run from the root of the nbgrader directory. You probably need to run
it with sudo since you need to write to other users' directories.
Usage:
sudo python return_feedback.py problem_set_name
"""
@jhamrick
jhamrick / passenger_wsgi.py
Last active December 30, 2019 22:35
Passenger configuration for psiTurk on DreamHost
import sys
import os
import logging
from logging.handlers import RotatingFileHandler
# This script assumes you have created a subdomain on DreamHost
# that is configured for Passenger. It also assumes you have created
# a Python virtual environment in the root of that subdomain and
# installed psiTurk inside it.
@jhamrick
jhamrick / Dockerfile
Last active April 11, 2020 16:27
nbgrader docker image
FROM jupyter/notebook
# Install nbgrader
RUN pip2 install nbgrader && pip3 install nbgrader
# Add any other dependencies you might want, e.g. numpy, scipy, etc.
#RUN pip2 install numpy scipy matplotlib
#RUN pip3 install numpy scipy matplotlib
# Configure grader user
@jhamrick
jhamrick / custom.css
Last active October 7, 2020 15:34
IPython customizations
/* Solarized color pallet */
.solarized.base03 { color: #002b36; }
.solarized.base02 { color: #073642; }
.solarized.base01 { color: #586e75; }
.solarized.base00 { color: #657b83; }
.solarized.base0 { color: #839496; }
.solarized.base1 { color: #93a1a1; }
.solarized.base2 { color: #eee8d5; }
.solarized.base3 { color: #fdf6e3; }
.solarized.solar-yellow { color: #b58900; }
@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):