Skip to content

Instantly share code, notes, and snippets.

View codeinthehole's full-sized avatar
🌏
The main difference between dinosaurs and us is we're building our own meteor.

David Winterbottom codeinthehole

🌏
The main difference between dinosaurs and us is we're building our own meteor.
View GitHub Profile
@codeinthehole
codeinthehole / private_repos.py
Created February 12, 2014 11:54
Dirty script for finding repos to archive
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 February 24, 2014 12:40
Execute custom SQL before tests run (uses the Nose testrunner)
import os
from django.db import connection
def setUp():
"""
Create custom database tables before test suite runs
"""
execute_from_file('stores_table.sql')
" ==================================================
" 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 August 14, 2014 11:06
Git aliases for quickly opening Github pages
[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 / SensibleTermarySniff.php
Created January 19, 2011 23:36
PHP_CodeSniffer sniff file for checking for idiotic ternary assignments
<?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 June 1, 2011 11:49
Twill TestCase for django
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 June 2, 2011 10:55
Environment-based logger
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 September 9, 2011 08:38
Lightweight subclassing using curry
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 January 19, 2012 17:31
Simple script for releasing python packages to PyPi
#!/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"
@codeinthehole
codeinthehole / poker.py
Created February 13, 2012 09:40
Determine how wins poker game from input file
#!/usr/bin/env python
import sys
from optparse import OptionParser
import unittest
from collections import defaultdict
# Constants for each hand
ROYAL_STRAIGHT_FLUSH = 10
STRAIGHT_FLUSH = 9
FOUR_OF_A_KIND = 8