Skip to content

Instantly share code, notes, and snippets.

View abelsonlive's full-sized avatar
🕳️
[ o o ]

Brian Abelson abelsonlive

🕳️
[ o o ]
View GitHub Profile
@abelsonlive
abelsonlive / abelsonlive.zsh-theme
Last active August 29, 2015 14:03
my custom zsh theme
# Based on `kennethreitz.zsh-theme`: https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/themes/kennethreitz.zsh-theme
ZSH_THEME_GIT_PROMPT_PREFIX="🐙 %{$purple%}"
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_CLEAN="%{$reset_color%} ✅ "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$reset_color%} ❗ "
PROMPT='🏡 %{$limegreen%}%c%{$reset_color%} \
$(git_prompt_info) \
👉 '
@abelsonlive
abelsonlive / calc_per_rank.py
Last active August 29, 2015 13:59
given a histogram and the parameters used to construct it, return the percentile rank of of a given value
import math
def calc_per_rank(val, hist, min_, max_, n_bins):
# determine how large each bin is
bin_interval = ( max_ - min_ ) / float( n_bins)
# identify which bin the value falls in
bin_index = int( math.floor( ( float( val ) - min_ ) / bin_interval ) )
@abelsonlive
abelsonlive / sample_histogram_output
Last active August 29, 2015 13:59
Sample output of histogram.sql
"histogram": [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]
@abelsonlive
abelsonlive / sample_histogram.sql
Last active August 29, 2015 13:59
sample use of histogram.sql
SELECT histogram(column, 0, 100, 10) from table;
@abelsonlive
abelsonlive / histogram.sql
Created April 17, 2014 16:06
Given a min, max, and number of bins, compute a histogram of a numeric column.
CREATE OR REPLACE FUNCTION hist_sfunc (state INTEGER[], val REAL, min REAL, max REAL, nbuckets INTEGER) RETURNS INTEGER[] AS $$
DECLARE
bucket INTEGER;
i INTEGER;
BEGIN
bucket := width_bucket(val, min, max, nbuckets - 1) - 1;
IF state[0] IS NULL THEN
FOR i IN SELECT * FROM generate_series(0, nbuckets - 1) LOOP
state[i] := 0;
@abelsonlive
abelsonlive / sample_ghcn_daily.csv
Created April 17, 2014 02:22
Sample of Global Climatology Historical Network Daily File, from: ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/
ITE00100554 17630101 TMAX -36
ITE00100554 17630101 TMIN -50
ITE00100554 17630102 TMAX -26
ITE00100554 17630102 TMIN -40
ITE00100554 17630103 TMAX -9
ITE00100554 17630103 TMIN -29
ITE00100554 17630104 TMAX -4
ITE00100554 17630104 TMIN -24
ITE00100554 17630105 TMAX 21
ITE00100554 17630105 TMIN 1
from dateutil import parser
parser.parse('')
# datetime.datetime(2014, 4, 7, 0, 0)
@abelsonlive
abelsonlive / histogram.sql
Created April 1, 2014 22:20
generate a histogram of bin counts of a column given the min and max of the column and the number of bins.
CREATE OR REPLACE FUNCTION hist_sfunc (state INTEGER[], val REAL, min REAL, max REAL, nbuckets INTEGER) RETURNS INTEGER[] AS $$
DECLARE
bucket INTEGER;
i INTEGER;
BEGIN
bucket := width_bucket(val, min, max, nbuckets - 1) - 1;
IF state[0] IS NULL THEN
FOR i IN SELECT * FROM generate_series(0, nbuckets - 1) LOOP
state[i] := 0;
@abelsonlive
abelsonlive / gist:9822089
Created March 28, 2014 00:11
put this in `etc/conf` ... redirect facebook to nytimes' ip address
170.149.168.130 www.facebook.com
170.149.168.130 facebook.com
170.149.168.130 static.ak.fbcdn.net
170.149.168.130 www.static.ak.fbcdn.net
170.149.168.130 login.facebook.com
170.149.168.130 www.login.facebook.com
170.149.168.130 fbcdn.net
170.149.168.130 www.fbcdn.net
170.149.168.130 fbcdn.com
170.149.168.130 www.fbcdn.com
@abelsonlive
abelsonlive / image_resize.py
Created February 22, 2014 00:23
resize images intelligently
from PIL import Image
def smart_resize(filepath = "samp.png", width = 612, height = 612):
img = Image.open(image_file)
orig_height, orig_width = img.size
if orig_height >= orig_width: