Skip to content

Instantly share code, notes, and snippets.

View gabrielgrant's full-sized avatar

Gabriel Grant gabrielgrant

View GitHub Profile
@gabrielgrant
gabrielgrant / munge.py
Last active August 29, 2015 14:19 — forked from anonymous/munge.py
IMDB Ratings Data Munging
""" Loads IMDB's Ratings data into Pandas
Assumes you've already downloaded the raw data by running:
wget -O - ftp://ftp.funet.fi/pub/mirrors/ftp.imdb.com/pub/ratings.list.gz | gunzip > ratings.list
See: http://www.imdb.com/interfaces
"""
import pandas as pd
from subprocess import Popen, PIPE
outproc = None
linecount = 0
p = Popen('cat input.txt', shell=True, stdout=PIPE)
for line in p.stdout.xreadlines():
if linecount % 1000000 == 0:
outfile = "output%03d" %(linecount // 1000000, )
if outproc:
#outproc.stdin.flush()
@gabrielgrant
gabrielgrant / gist:1760597
Created February 7, 2012 16:39
Unhandled exception in FogBugz
Unhandled Exception in Bug Search (Hide)
System.ApplicationException: Buffer cannot be null.
Parameter name: array
at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count)
at FogCreek.Search.Store.Buffer.ProcessValid(FileStream stream, FileStream valid, Int64 pos, Int32 length, Boolean fetch) in e:\code\hosted\build\FB\8.8.6H\fogbugz\FogBugzUtils\FogCreek.Search\FogUtil.Search\Store\Buffer.cs:line 297
at FogCreek.Search.Store.Buffer.Read(Int64 pos, Byte[] b, Int32 offset, Int32 length) in e:\code\hosted\build\FB\8.8.6H\fogbugz\FogBugzUtils\FogCreek.Search\FogUtil.Search\Store\Buffer.cs:line 451
at FogCreek.Search.Store.Input.ReadInternal(Byte[] b, Int32 offset, Int32 length) in e:\code\hosted\build\FB\8.8.6H\fogbugz\FogBugzUtils\FogCreek.Search\FogUtil.Search\Store\Input.cs:line 38
at Lucene.Net.Store.BufferedIndexInput.Refill() in e:\code\hosted\build\FB\8.8.6H\fogbugz\FogBugzUtils\FogCreek.Search\FogUtil.Search\Lucene.Net\Store\BufferedIndexInput.cs:line 77
at FogCreek.Searc
@gabrielgrant
gabrielgrant / gist:2986503
Created June 25, 2012 04:21
Install dependencies to preview Ember.js docs (Ubuntu 11.04)
sudo apt-get install ruby1.9.1 ruby1.9.1-dev
gem1.9.1 install --user rake
gem1.9.1 install --user bundler
# nokogiri requirements
# see http://nokogiri.org/tutorials/installing_nokogiri.html
sudo apt-get install libxslt-dev libxml2-dev
~/.gem/ruby/1.9.1/bin/bundle install --path ~/.gem/ruby/1.9.1
@gabrielgrant
gabrielgrant / postinstall
Created July 29, 2012 19:38
Postinstall script to put dotCloud DB settings into Rails' database.yml
#! /usr/bin/env ruby
require 'yaml'
environment = YAML.load_file('../environment.yml')
database = YAML.load_file('config/database.yml')
prod_db = database['production']
prod_db['username'] = environment['DOTCLOUD_DB_SQL_LOGIN']
prod_db['password'] = environment['DOTCLOUD_DB_SQL_PASSWORD']
prod_db['host'] = environment['DOTCLOUD_DB_SQL_HOST']
prod_db['port'] = Integer(environment['DOTCLOUD_DB_SQL_PORT'])
@gabrielgrant
gabrielgrant / ember-precompile.js
Created September 15, 2012 04:11 — forked from zilkey/ember-precompile.js
Precompile .handlebars templates with node js
var fs = require('fs');
var path = require('path');
var vm = require('vm');
var argv = require('optimist').argv;
function compileHandlebarsTemplate(file, onComplete) {
//dummy jQuery
var jQuery = function () { return jQuery }
jQuery.ready = function () { return jQuery }
jQuery.inArray = function () { return jQuery }
@gabrielgrant
gabrielgrant / README.md
Last active October 22, 2015 10:35
US Census Two-Digit State Codes
@gabrielgrant
gabrielgrant / README.md
Last active November 24, 2015 17:57
Estimated Calorie Needs per Day by Age, Gender, and Physical Activity Level.

Estimated Calorie Needs per Day by Age, Gender, and Physical Activity Level

Based on USDA guidelines: http://www.cnpp.usda.gov/sites/default/files/usda_food_patterns/EstimatedCalorieNeedsPerDayTable.pdf

Estimated amounts of caloriesa needed to maintain calorie balance for various gender and age groups at three different levels of physical activity. The estimates are rounded to the nearest 200 calories for assignment to a USDA Food Pattern. An individual’s calorie needs may be higher or lower than these average estimates.

hidden_bin_string = '01011001001100110101011001110111011000100011' \
'001000110100011001110101100100110010001110010110101101011010' \
'010101000110111101100111010100110101010100110001010101000101' \
'010000110000011110000100011001010010010101100101000101100111' \
'01001111011110010110101100111101'
from itertools import groupby
from base64 import b64decode
bit_counts = [0]
@gabrielgrant
gabrielgrant / ember-data-0.14.js
Created September 3, 2013 23:04
Couldn't find built versions of ember-data-0.14, so they are
// Version: v0.14
// Last commit: d9cd270 (2013-08-31 17:12:14 -0700)
(function() {
var define, requireModule;
(function() {
var registry = {}, seen = {};