Skip to content

Instantly share code, notes, and snippets.

@rob-b
rob-b / gist:5363236
Created April 11, 2013 13:10
nose-progressive missing test collection
vagrant@precise:/tmp/tests ⚡
> ll
total 12K
-rw-r--r-- 1 vagrant vagrant 25 Apr 11 13:04 test_a.py
-rw-r--r-- 1 vagrant vagrant 25 Apr 11 13:04 test_b.py
-rw-r--r-- 1 vagrant vagrant 25 Apr 11 13:04 test_c.py
vagrant@precise:/tmp/tests ⚡
> cd -1
~/.virtualenvs
@rob-b
rob-b / object.py
Created March 13, 2013 16:06
Default implementation of object.__repr__
def repr(obj):
mod = obj.__class__.__module__
cls = obj.__class__.__name__
mem = '0x' + hex(id(obj))[2:]
return '<{0}.{1} instance at {2}>'.format(mod, cls, mem)
@rob-b
rob-b / vivification.py
Created March 6, 2013 14:18
vivification in python. Courtesy of Alex Martelli
import collections
def vivify():
return collections.defaultdict(vivify)
@rob-b
rob-b / AdaptiveSearch.py
Created December 20, 2012 13:54
Basically the same as ElasticSearch.py but aggregates the values of all nodes instead of representing them individually
#!/usr/bin/env python
'''
ISC style license
http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/share/misc/license.template?rev=HEAD
---
Copyright (c) 2011, 2012 Curve <justin@curvehq.com>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
@rob-b
rob-b / project_vars.sh
Created December 19, 2012 15:03
Setting project specific env vars such as these in my zshrc is annoying. Source this and then run set_controller_vars instead
#!/bin/sh
set_project_vars() {
if [ "$1" == 'on' ]
then
export SOMA_BUILD_DIR=~/Projects/al/soma_git_dump
export AWS_CREDENTIAL_FILE=~/Projects/al/creds/boto
echo SOMA_BUILD_DIR=$SOMA_BUILD_DIR
echo AWS_CREDENTIAL_FILE=$AWS_CREDENTIAL_FILE
date --iso-8601=minutes | sed 's/://' | cut -d"+" -f1
@rob-b
rob-b / authentication_helpers.rb
Created November 10, 2012 17:53 — forked from mattsnyder/authentication_helpers.rb
Easy faking of user authentication in RSpec when using Devise
module AuthenticationHelpers
# Example usage: login mock_user(Editor)
def login(user)
request.env['warden'] = mock(Warden,
:authenticate => user,
:authenticate! => user)
end
def mock_user(type, stubs={})
mock_model(type, stubs).as_null_object
@rob-b
rob-b / gist:3992928
Created November 1, 2012 10:22
git-vary
> cat ~/.bin/git-vary
#!/bin/sh
(
set -e
target=$1
git log --oneline --graph --decorate $(git merge-base $target HEAD)^.. $target HEAD
)
> git checkout some_branch && git vary master
@rob-b
rob-b / gist:3979655
Created October 30, 2012 11:15
Multiple return values with mock.py
def templates():
results = ['I am html', 'I am text', 'I am subject']
def side_effect(*args):
return results.pop(0)
return side_effect
render_to_string = Mock(side_effect=templates())
@rob-b
rob-b / gist:3906313
Created October 17, 2012 15:51
Change default project logging
from .settings import *
LOGGING['formatters']['logsna'] = {'()': 'logsna.Formatter'}
db_handler = {'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': here('logs', 'db.log'),
'maxBytes': 4194304,
'formatter': 'logsna',