Skip to content

Instantly share code, notes, and snippets.

View gabrielgrant's full-sized avatar

Gabriel Grant gabrielgrant

View GitHub Profile
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 / dumpmaps.py
Created September 22, 2011 18:53
print gdb commands to dump memory from running process
import os.path
import sys
def main(pid):
f = open(os.path.join('/proc', pid, 'maps'))
for l in f.readlines():
col = l.split()
if len(col) == 5:
address, perms, offset, device, inode = col
pathname = ''
@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 / testapp.py
Created February 9, 2012 01:43
Simple wsgi streaming response
pip install gunicorn
gunicorn testapp:app
@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 }
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 = {};
@gabrielgrant
gabrielgrant / choice-output.json
Created September 4, 2013 01:28
Arrrg, shouldn't django-rest-framework `viewsets.ModelViewSet` use `serializers.ModelSerializer` by default? It seems to be using `HyperlinkedModelSerializer` instead. Do I really need to create and specify a custom serializer just to get an ID output rather than a hyperlink?
{
"url": "http://localhost:8000/api/v1/choices/1/",
"poll": "http://localhost:8000/api/v1/polls/1/",
"choice_text": "Pretty confusing",
"votes": 0
}