Skip to content

Instantly share code, notes, and snippets.

View bagrow's full-sized avatar

Jim Bagrow bagrow

View GitHub Profile
#!/usr/bin/env python
# weather
# Jim Bagrow
# Last Modified: 2014-01-01
"""
This script requires:
1. a weather underground API key
@bagrow
bagrow / calc_diff.sh
Created February 1, 2011 00:50
Semi-automatic way to track changes in a latex file
#!/usr/bin/env bash
# these can also be commandline args...
OLD_TEX=paper_orig.tex # previous draft, submission, etc.
NEW_TEX=paper.tex # current working version
if [[ "$1" = 'clean' ]]; then
rm -f diff*
else
latexdiff $OLD_TEX $NEW_TEX > diff.tex
@bagrow
bagrow / colors
Created February 10, 2011 10:01
test colors in terminal.app
#!/bin/bash
echo -e "\033[0mCOLOR_NC (No color)"
echo -e "\033[1;37mCOLOR_WHITE\t\033[0;30mCOLOR_BLACK"
echo -e "\033[0;34mCOLOR_BLUE\t\033[1;34mCOLOR_LIGHT_BLUE"
echo -e "\033[0;32mCOLOR_GREEN\t\033[1;32mCOLOR_LIGHT_GREEN"
echo -e "\033[0;36mCOLOR_CYAN\t\033[1;36mCOLOR_LIGHT_CYAN"
echo -e "\033[0;31mCOLOR_RED\t\033[1;31mCOLOR_LIGHT_RED"
echo -e "\033[0;35mCOLOR_PURPLE\t\033[1;35mCOLOR_LIGHT_PURPLE"
echo -e "\033[0;33mCOLOR_YELLOW\t\033[1;33mCOLOR_LIGHT_YELLOW"
echo -e "\033[1;30mCOLOR_GRAY\t\033[0;37mCOLOR_LIGHT_GRAY"
@bagrow
bagrow / monex.py
Created February 14, 2011 05:32 — forked from yy/monex.py
MONiter & EXecute
#!/usr/bin/env python
# encoding: utf-8
"""
MONitor & EXecute
Yong-Yeol Ahn (http://yongyeol.com/)
This script monitors multiple files and executes the given command when
any of those files is changed.
@bagrow
bagrow / check.py
Created February 14, 2011 08:46
example pause/unpause/quit python script
#!/usr/bin/python
import sys, os, time
import tty
from select import select
class TerminalFile:
"""Adapted from http://code.activestate.com/recipes/203830/"""
def __init__(self,infile):
if not infile.isatty():
@bagrow
bagrow / Makefile
Created March 12, 2011 16:41
Compile and merge the latex cover letter, manuscript, and supporting info all at once
ENGINE = latexmk -pdf -silent -view=none
SOURCES = cover_letter paper paper_supp
MERGEFILE = paper_wCoverLetterSupp_$(shell date "+%Y%m%d").pdf
TEMPS = aux blg fdb_latexmk log out synctex.gz
MERGECMD=
ifneq ($(MERGEFILE),)
MERGECMD=gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$(MERGEFILE) $(SOURCES:=.pdf)
endif
@bagrow
bagrow / mutateyoutube.js
Created April 29, 2012 21:08
bookmarklet to reload youtube video at full browser width
javascript:
var youtubeid = getQueryVariable("v");
if (youtubeid != undefined){
window.location="http://youtube.googleapis.com/v/"+youtubeid+"&autoplay=1";
}
function getQueryVariable(variable) {
/* courtesy: http://stackoverflow.com/a/1623707 */
var query = window.location.search.substring(1);
var vars = query.split("&");
@bagrow
bagrow / weighted_choice.py
Created November 7, 2012 00:23
Sample non-uniformly from a set of choices
#!/usr/bin/env python
# weighted_choice.py
# Jim Bagrow
# Last Modified: 2012-11-06
import random, bisect
import pylab
def weighted_choice(choices, num_draws=1):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# exhaustive_search_linearRegression.py
# Jim Bagrow
# Last Modified: 2015-10-05
import sys, os
import numpy as np
import scipy, scipy.stats
#!/usr/bin/env python
# color_stuff.py
# Jim Bagrow
# Last Modified: 2016-12-01
import colorsys
def distinguishable_colors(num, sat=1.0, val=1.0):
"""Generate a list of `num' rgb hexadecimal color strings. The strings are