Skip to content

Instantly share code, notes, and snippets.

View bruth's full-sized avatar

Byron Ruth bruth

View GitHub Profile
@bruth
bruth / numbers.coffee
Created July 30, 2012 21:25
Prettifying numbers
# utils/numbers
#
# Utilities to formating numbers in a human-readable way.
#
# * toSuffixedNumber - for numbers greater than or equal to 1000,
# the output is a suffixed number
# * toDelimitedNumber - returns a delimited string representation
# of the number
define ->
@bruth
bruth / gist:4155168
Created November 27, 2012 16:16
vimrc
" Kick off pathogen
call pathogen#infect()
" Base
set autochdir " change to cwd
set autoindent " indent on next line
set backspace=2 " allow backspace over indent, eol, start insert
set colorcolumn=80 " color column 80
set nocompatible " explicitly turn off compaitable mode with Vi
set cursorbind " move cursor to corresponding line and column
class LdapBackend(ModelBackend):
"""Authenticate a user against LDAP.
Requires python-ldap to be installed.
Requires the following things to be in settings.py:
DEBUG - boolean
Uses logging module for debugging messages.
@bruth
bruth / gist:4444123
Created January 3, 2013 15:07
Conditional Vim colorscheme based on time of day
" Set color scheme according to current time of day.
let hr = str2nr(strftime('%H'))
if hr <= 6 || hr > 18
let cs = 'Tomorrow-Night'
else
let cs = 'Tomorrow'
endif
execute 'colorscheme '.cs
@bruth
bruth / flatten.py
Created January 4, 2013 21:30
Recursively flatten a list of lists and tuples
def flatten(l, output=None):
if output is None:
output = []
for x in l:
if isinstance(x, (list, tuple)):
flatten(x, output)
else:
output.append(x)
return output
@bruth
bruth / jsondiff.js
Last active December 12, 2015 04:38
JavaScript implementation for constructing objects diffs compatible with JSON PATCH syntax.
var jsondiff = (function() {
// Patch helper functions
function getParent(paths, path) {
return paths[path.substr(0, path.match(/\//g).length)];
}
// Checks if `obj` is an array or object
function isContainer(obj) {
return _.isArray(obj) || _.isObject(obj);
view = DataView(...)
context = DataContext(...)
queryset = view.apply(context.apply())
iterator = queryset.raw()
for row in iterator:
pass
@bruth
bruth / jquery.scrape.js
Last active December 17, 2015 07:08
DOM-to-string jQuery plugin
(function($) {
$.scrape = function(options) {
options = options || {};
var el, page = [], clone;
// start with doctype
page.push('<!doctype html>');
// build the html tag since this cannot be captured as a child
import logging
# http://stackoverflow.com/a/1049375/407954
class MockHandler(logging.Handler):
def __init__(self, *args, **kwargs):
self.reset()
logging.Handler.__init__(self, *args, **kwargs)
def emit(self, record):
self.messages[record.levelname.lower()].append(record.getMessage())
1-00031 2
rna 1
1-00696 1
diagno 1
fas 1
f 3
age 1
pheno 1
jacob 1
fyl 3