Skip to content

Instantly share code, notes, and snippets.

View zthomae's full-sized avatar

Zach Thomae zthomae

  • Goldman Sachs
  • Chicago, IL
View GitHub Profile
@zthomae
zthomae / cooksay
Created February 11, 2016 21:21
Cooksay
#!/usr/bin/env python
from math import ceil
from base64 import b64decode as b64
def wrap(txt, lines):
words = txt.split()
n = int(ceil(len(words) / (1.0 * lines)))
joined = []
i = 0
@zthomae
zthomae / find-abbreviations.rkt
Last active January 29, 2016 04:51
A program for finding all abbreviations of a string
#lang racket
(define (prepend-abbrev front abbr)
(cond [(and (number? front) (number? (car abbr)))
(cons (+ front (car abbr)) (cdr abbr))]
[(and (string? front) (string? (car abbr)))
(cons (string-append front (car abbr)) (cdr abbr))]
[else (cons front abbr)]))
(define (reduce-abbrev l)
@zthomae
zthomae / chrubuntu.bash
Last active December 30, 2015 13:49
Chromebook ubuntu script
#!/bin/bash
# Modified version of the original chrubuntu script, version s9ryd.
# Hard codes things for my purposes.
# save original pwd
CODE_DIR=`pwd`
# fw_type will always be developer for Mario.
# Alex and ZGB need the developer BIOS installed though.
@zthomae
zthomae / daysdecrypt.py
Created September 24, 2013 07:28
A one-off set of python functions for decrypting a small, toy ciphertext. Gisted because it may be interesting later.
import itertools
def ord_shift(x):
return ord(x.upper()) - ord('A')
def chr_shift(x):
return chr(x + ord('A')).upper()
def opcode(alpha, beta, op):
pairs = zip(list(alpha), list(beta))
@zthomae
zthomae / README.md
Last active December 21, 2015 23:39 — forked from mbostock/.block
Stacked area chart with focus on hover.

This is a variation on the standard stacked area chart that uses a hover action to combat the shifting baseline problem.

Stacked charts are harder to read than others because the baseline of an area is shifted by the areas below it. A normal bar or area chart makes visual comparisons in different positions easy, because height measurements are made from the same starting place. This is not true when multiple areas are stacked on top of one another -- here, you have to adjust for the moving baseline yourself, which can be tricky.

This is especially true for stacked area charts, where the areas are continuous. The height of an area is always plotted vertically, but we perceive thickness perpendicular to its movement. When the area bends, we no longer see thickness as it is plotted. This is explained much more effectively by Dr. Drang, in a post that is also the source of the data for this gist.

This

@zthomae
zthomae / special_collections_crawl.py
Created January 30, 2013 22:13
A Selenium (the poor man's API) test script for finding books in the UW Madison Special Collections library that are possibly not in EEBO/ECCO. More proof-of-concept than good idea.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import gdbm
EEBO_SEARCH = 'http://eebo.chadwyck.com/search?SCREEN=search_advanced.htx'
@zthomae
zthomae / gen_nocorrect.zsh
Last active December 11, 2015 05:38
Shell function for generating an alias file for nocorrect aliases.
function gen_nocorrect() {
if [ -f ~/.zsh_nocorrect ]; then
echo '# Aliases for nocorrect commands. Automatically generated' > ~/.aliases_nocorrect
while read -r COMMAND; do
echo "alias $COMMAND=\"nocorrect $COMMAND\"" >> ~/.aliases_nocorrect
done < ~/.zsh_nocorrect
fi
}
@zthomae
zthomae / split_keep.py
Last active July 4, 2018 17:24
A simple python function for splitting a string by multiple "splitters", remembering the splitter used each time.
def split_keep(string, splitters):
"""Split by a list of splitters, and preserve their locations.
Created for a case where a string needed to be split by
multiple characters, but the "splitter" used in each case needed
to be remembered.
Arguments:
string -- the string to split
splitters -- a list of strings to split with
@zthomae
zthomae / ssh_print.bat
Created December 17, 2012 07:32
A batch script that sends a file over to a linux machine for printing via ssh. Triviality rating: 9/10
@echo off
set /p file="Bring me the file: " %=%
plink print "lpr -P Officejet-H470" < %file%
@zthomae
zthomae / soundstretch.sh
Created December 14, 2012 00:13
A silly shell script for recursively finding mp3 files and making copies that are sped up +40%.
#!/bin/bash
#
# Brain hacking in action: A simple bash script for making "fast" versions of mp3 files.
#
# Usage: The script takes 2 arguments, a "getdir" and a "putdir".
#
# The script will recursively search for mp3 files in getdir and make "fast" versions of them
# (+40% speed). The full directory tree (from /) is recreated inside putdir, and the
# fast mp3s are placed in their corresponding locations in the new tree.
#