Skip to content

Instantly share code, notes, and snippets.

View pmallory's full-sized avatar

Philip Mallory pmallory

View GitHub Profile
@pmallory
pmallory / hist.py
Created February 8, 2012 20:03
Music Histogram
from Foundation import *
from ScriptingBridge import *
iTunes = SBApplication.applicationWithBundleIdentifier_(
"com.apple.iTunes")
years = {}
for track in iTunes.currentPlaylist().tracks():
if not track.year() in years:
@pmallory
pmallory / gist_line_numbers.css
Created February 8, 2012 20:50
CSS to add line numbers to embedded gists
/* gist formatting */
.line {
background-color: #f1fafb;
}
.gist-highlight {
border-left: 3ex solid #eee;
position: relative;
}
.gist-highlight pre {
counter-reset: linenumbers;
@pmallory
pmallory / .vimrc
Created February 24, 2012 19:00
My .vimrc
"enable syntax highlighting
syntax enable:
"set color scheme
set background=dark
"tab settings
set expandtab
set tabstop=4
set shiftwidth=4
@pmallory
pmallory / .bashrc
Last active October 1, 2015 02:28
My .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
export PS1="\n\[\e[32m\]\u@\h \e[37m\t \[\e[33m\]\w\[\e[0m\]\$(__git_ps1)\n\$ "
@pmallory
pmallory / .bash_profile
Created February 24, 2012 19:36
My .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
@pmallory
pmallory / life.py
Last active March 9, 2017 22:13
PyLife: Conway's Game of Life displayed in the terminal
import curses
from itertools import product, islice, cycle
import random
import time
# cycling iterator of a cell's eight neigbors
neighbors = cycle(filter(lambda x: x!=(0,0), product(range(-1,2), repeat=2)))
def iterate(board, board_size):
"""Given a board state generate the next generation and return it.
@pmallory
pmallory / benchmark.py
Created May 17, 2012 01:18 — forked from evan2m/benchmark.py
Benchmark counters in python
import timeit
from shakespeare import LETTERS, WORDS
if __name__ == '__main__':
# dict
t = timeit.Timer(stmt="""
counter = dict()
for k in LETTERS:
@pmallory
pmallory / Recursion IPython Notebook
Created April 1, 2014 17:44
Recursion IPython Notebook
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@pmallory
pmallory / gist:8f919bb007e45fd04634
Created September 26, 2014 20:48
A scatter plot with vertical positioning based on multiple categories
red_wine$volatile.acidity.cat <-
cut(red_wine$volatile.acidity,
breaks = quantile(red_wine$volatile.acidity,
probs = c(0, 0.25, 0.5, 0.75, 1.0)))
x_title = "Alcohol (percentage by volume)"
y_title = "Quality\n(0: very bad -> 10: very excellent)"
color_title = expression(paste("Volatile Acidity (", g / dm^{3}, ")"))
# Create label array for color legend.
@pmallory
pmallory / binary_search.py
Created October 30, 2014 17:39
Binary search
import matplotlib.pyplot as plt
import random
def binary_search(target, epsilon):
guess = 1.0
bottom = 1.0
top = float("inf")
steps = 0
while abs(target-guess)>epsilon: