Skip to content

Instantly share code, notes, and snippets.

🕳
[ o o ]

Brian Abelson abelsonlive

🕳
[ o o ]
Block or report user

Report or block abelsonlive

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@abelsonlive
abelsonlive / image_resize.py
Created Feb 22, 2014
resize images intelligently
View image_resize.py
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:
@abelsonlive
abelsonlive / histogram.sql
Created Apr 1, 2014
generate a histogram of bin counts of a column given the min and max of the column and the number of bins.
View histogram.sql
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;
View dateutil_is_stupid.py
from dateutil import parser
parser.parse('')
# datetime.datetime(2014, 4, 7, 0, 0)
@abelsonlive
abelsonlive / sample_ghcn_daily.csv
Created Apr 17, 2014
Sample of Global Climatology Historical Network Daily File, from: ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/
View sample_ghcn_daily.csv
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
@abelsonlive
abelsonlive / calc_per_rank.py
Last active Aug 29, 2015
given a histogram and the parameters used to construct it, return the percentile rank of of a given value
View calc_per_rank.py
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 Aug 29, 2015
Sample output of histogram.sql
View sample_histogram_output
"histogram": [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]
@abelsonlive
abelsonlive / sample_histogram.sql
Last active Aug 29, 2015
sample use of histogram.sql
View sample_histogram.sql
SELECT histogram(column, 0, 100, 10) from table;
@abelsonlive
abelsonlive / histogram.sql
Created Apr 17, 2014
Given a min, max, and number of bins, compute a histogram of a numeric column.
View histogram.sql
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 / abelsonlive.zsh-theme
Last active Aug 29, 2015
my custom zsh theme
View abelsonlive.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 / srccon-word-counts.json
Created Jul 31, 2014
Word counts from SRCCON transcripts.
View srccon-word-counts.json
[
{
"word": "people",
"count": 999
},
{
"word": "data",
"count": 749
},
{
You can’t perform that action at this time.