Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
"A wet man doesn't fear rain" — Russian proverb

David Winterbottom codeinthehole

💭
"A wet man doesn't fear rain" — Russian proverb
View GitHub Profile
@codeinthehole
codeinthehole / private_repos.py
Created Feb 12, 2014
Dirty script for finding repos to archive
View private_repos.py
import requests
import datetime
import sys
# Pass your OAuth token
token = sys.argv[1]
# Fetch all private repos (lazy - assumes only two pages)
headers = {'Authorization': 'token %s' % token}
response = requests.get(
@codeinthehole
codeinthehole / __init__.py
Created Feb 24, 2014
Execute custom SQL before tests run (uses the Nose testrunner)
View __init__.py
import os
from django.db import connection
def setUp():
"""
Create custom database tables before test suite runs
"""
execute_from_file('stores_table.sql')
View .vimrc
" ==================================================
" VIMRC file for David Winterbottom (@codeinthehole)
" ==================================================
" Inspiration {{{
" -----------
" See http://www.youtube.com/watch?v=aHm36-na4-4
"
" Good articles:
" - http://alexpounds.com/blog/2014/06/06/the-vimrc-antiques-roadshow
@codeinthehole
codeinthehole / .gitconfig
Created Aug 14, 2014
Git aliases for quickly opening Github pages
View .gitconfig
[alias]
# Open the Github page for the...
# ...repo homepage (included for consistency)
open = !hub browse --
# ...repo commits
opencommits = !hub browse -- commits
# ...commit page for HEAD
@codeinthehole
codeinthehole / prettytitle.sh
Created Aug 20, 2014
Bash function for print pretty titles
View prettytitle.sh
#!/usr/bin/env bash
# Pretty printing function for Bash output
#
# Example usage:
#
# $ notify "hello world"
#
# +-------------+
# | hello world |
@codeinthehole
codeinthehole / SensibleTermarySniff.php
Created Jan 19, 2011
PHP_CodeSniffer sniff file for checking for idiotic ternary assignments
View SensibleTermarySniff.php
<?php
class TangentLabs_Sniffs_BestPractice_SensibleTernarysSniff implements PHP_CodeSniffer_Sniff
{
/**
* @return array
*/
public function register()
{
return array(T_INLINE_THEN);
}
@codeinthehole
codeinthehole / twill_testcase.py
Created Jun 1, 2011
Twill TestCase for django
View twill_testcase.py
class TwillTestCase(TestCase):
"""
Simple wrapper around Twill to make writing TestCases easier.
Commands availabel through self.command are:
- go -> visit a URL
- back -> back to previous URL
- reload -> reload URL
- follow -> follow a given link
- code -> assert the HTTP response code
@codeinthehole
codeinthehole / handler.py
Created Jun 2, 2011
Environment-based logger
View handler.py
from logging import FileHandler as BaseFileHandler
import os
class EnvFileHandler(BaseFileHandler):
"""
Custom filehandler that uses the LOG_ROOT setting to determine the folder
to store log files in.
We have to do some tricky stuff to avoid circular imports. To this end,
@codeinthehole
codeinthehole / curried_subclass.py
Created Sep 9, 2011
Lightweight subclassing using curry
View curried_subclass.py
def curry(f, *args, **kwargs):
def curried(*more_args, **more_kwargs):
return f(*(args+more_args), **dict(kwargs, **more_kwargs))
return curried
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
@codeinthehole
codeinthehole / release.sh
Created Jan 19, 2012
Simple script for releasing python packages to PyPi
View release.sh
#!/bin/bash
# Extract version number from setup.py
RELEASE_NUM=`grep version setup.py | cut -d\' -f2`
# Push to PyPi
python setup.py sdist upload
# Tag in Git and push to remote
git tag $RELEASE_NUM -m "Tagging release $RELEASE_NUM"