Skip to content

Instantly share code, notes, and snippets.

View bruth's full-sized avatar

Byron Ruth bruth

View GitHub Profile
@bruth
bruth / diff_metadata.py
Created May 6, 2015 14:31
Diff Avocado metadata
#!/usr/bin/env python
import os
import sys
import json
from cStringIO import StringIO
from django.core import management
def cmp_value(av, bv):
boot2docker down
boot2docker destroy
curl http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso > ~/.boot2docker/boot2docker.iso
boot2docker init
VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users
boot2docker up
boot2docker ssh "sudo modprobe vboxsf && sudo mkdir -v -p /Users && sudo mount -v -t vboxsf -o uid=0,gid=0 home /Users"
@bruth
bruth / catch_route.js
Created July 1, 2014 13:09
Document event handler that catches links and navigates to a Backbone route if one exists.
// Route based on the URL
$(document).on('click', 'a', function(event) {
// Path of the target link
var path = this.pathname;
// Handle IE quirk
if (path.charAt(0) !== '/') path = '/' + path;
// Trim off the root on the path if present
var root = Backbone.history.root || '/';
@bruth
bruth / email_based_user.py
Last active January 3, 2016 22:19
Email-based user
from random import choice
from string import ascii_lowercase, digits
from django.db import transaction
from django.db.models import User
USERNAME_CHARS = ascii_lowercase + digits
@transaction.commit_on_success
@bruth
bruth / gist:7467825
Created November 14, 2013 14:33
merge sorted
def merge_sorted(*iterables, **kwargs):
"""Returns a generator that merges N sorted iterables.
An optional `cmp` keyword argument may be supplied to customize the
comparison between values produced by the iterables.
"""
compare = kwargs.get('cmp', cmp)
direction = -1 if kwargs.get('reverse', False) else 1
@bruth
bruth / gist:7467784
Created November 14, 2013 14:30
UNION ALL + semantic graph idea

Notes

  • UNION removes duplicates from the set while UNION ALL does not which makes it much faster
    • Since this technique is being used for data integration, the UNION ALL is the
  • The number of columns must be the same for each select statement
    • A trick to fill in columns is to select a constant value such as null or ''

Example

@bruth
bruth / gist:7467130
Last active December 28, 2015 07:49
Django adhoc database
import string
from random import SystemRandom
from django.db import connections
key_chars = string.ascii_letters
random = SystemRandom()
class adhoc_db(object):
"""Context manager that temporarily adds a database connection.
@bruth
bruth / joinpath.coffee
Created November 4, 2013 14:31
Function to handle joining multiple paths together (behaves like Python's `os.path.join` function). This handles resolving relative and absolute paths, e.g. `['foo/', '.', 'bar/baz/..', 'qux']` => `foo/bar/qux`
joinPath = (paths...) ->
finalPath = []
for path in paths
for tok, i in path.split('/')
switch tok
when '.' then continue
when '..' then finalPath.pop()
else finalPath.push tok
@bruth
bruth / cliparser.scala
Last active December 24, 2015 01:59
Simple command line parser
object cli {
case class ArgumentsRequired(args: List[Any]) extends Exception {
override def getMessage: String = {
"required arguments: %s".format(this.args.mkString(", "))
}
}
case class UnknownArguments(args: List[Any]) extends Exception {
override def getMessage: String = {
@bruth
bruth / gist:6714020
Last active December 23, 2015 23:59
DataExpress opinions, ideas, and questions

DSL

  • [DONE] rename using_bind_vars to bind
    • copy query "SELECT ..." bind (1, 2, 3) from "source" to "target"
  • copy FOO from SOURCE to TARGET silently fails when no table exists in TARGET (filed chop-dbhi/dataexpress#42)
    • the right way is to add create TABLE_NAME

Questions

  • How to lookup a single row?