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 / postgis-restore.rst
Created July 15, 2013 14:35
Draft blog article on restoring a PostGIS database.

Problem

You have a Django site using GeoDjango with Postgres and PostGIS and want to take a backup copy of your production database and restore it on a different server with a different owner.

Solution

@codeinthehole
codeinthehole / stockrecords.rst
Created July 18, 2013 12:10
Description of the multi-stockrecord problem for Oscar and a few possible solutions

Problem

We need to support multiple stockrecords per product.

Example stories:

  • Customers in the UK use a stockrecord from a UK partner, customers from the US use a stockrecord from a US partner etc. We use IP lookup to determine which stockrecord is appropriate for a customer (this is the Meridian problem).
@codeinthehole
codeinthehole / post-merge
Created January 8, 2014 21:22
Git post-merge hook that looks for South migrations that have the same numbers. Duplicate migration numbers can be introduced when two different branches add migrations for the same app. This is easy to miss and can cause pesky out-of-order issues when the migrations are applied.
#!/usr/bin/env python
"""
Search for migrations that share the same number.
"""
import subprocess
# You will probably want to replace 'oscar' with the appropriate folder for
# your project. I tried using '.' but it finds lots of migrations in .tox which
# I don't want to consider.
find_args = ['find', 'oscar', '-name', '*.py']
@codeinthehole
codeinthehole / .bashrc
Created February 3, 2017 11:24
Prompt in bashrc
# ======
# PROMPT
# ======
# Set the prompt
# - Specify colors using \e[31;40m where 31 is the color and 40 is the background or
# - Select 1 for bold.
# - Wrap color specifiers in \[ and \] to ensure they don't affect word wrapping
# - Colours 30=black, 31=red, 32=green, 33=yellow, 34=blue, 35=purple, 36=teal, 37=white
@codeinthehole
codeinthehole / logger.js
Created May 15, 2013 10:54
A Javascript logger which has a similar API to Python's logging module
var logger = (function(console){
var log = console.log.bind(console) || function(){};
var obj = {
info: (console.info) ? console.info.bind(console) : log,
error: (console.error) ? console.error.bind(console) : log
};
if (console.warn) {
obj.warning = console.warn.bind(console);
} else if (console.warning) {
obj.warning = console.warning.bind(console);
@codeinthehole
codeinthehole / fetch_pyvideo.py
Created March 11, 2012 22:36
Fetch PyCon videos from pyvideo.org and convert them to M4V so they can be synced to your iPhone
# Hacky script for downloading videos from PyVideo and converting them to m4v
# format so they can be synced onto your apple device. Useful if you
# want to see everything that happened at PyCon while commuting.
#
# Requirements:
# * pip install requests BeautifulSoup
# * youtube-dl (from https://github.com/rg3/youtube-dl/) - add this to the
# directory where this script runs and ensure its execute bit is set.
# This was the only YouTube downloader I found that worked. It doesn't
# really have a good Python API so I call it through os.system.
@codeinthehole
codeinthehole / values.py
Created June 21, 2017 13:55
Example value objects using Python 3.6's typing.NamedTuple functionality
import typing
import datetime
class Period(typing.NamedTuple):
"""
Value object representing a period in time
"""
start_dt: datetime.datetime # noqa (as flake8 doesn't support this syntax as of v3.3)
end_dt: datetime.datetime # noqa
@codeinthehole
codeinthehole / boo
Created April 15, 2016 08:20
Notifier script to use with long-running commands
#!/usr/bin/env bash
#
# Show an OSX alert
#
# This is useful when used in conjunction with a long-running script. Use this script to
# get a notification when te long-running script finishes.
#
# Eg:
#
# $ ./someprocess ; boo
@codeinthehole
codeinthehole / user-data.sh
Created August 1, 2014 14:32
Minimal "user-data" for an AWS EC2 instance
#!/bin/bash
BUCKET=tangent-boilerplate
# Install AWS CLI
apt-get update
apt-get install -y python-pip
pip install awscli
# Fetch and run bootstrap file. For this to work, the EC2 instance needs to have an IAM role
@codeinthehole
codeinthehole / .bashrc
Last active February 12, 2019 09:07
Bash functions for private Docker registries
# Add these functions to your ~/.bashrc in order to be able to query private
# Docker registries from the commandline. You'll need the JQ library
# (http://stedolan.github.io/jq/) to be installed. Alternatively, you can just
# pipe to " python -mjson.tool" to get pretty JSON formatting
# TODO Enter the correct details here
DOCKER_REGISTRY_HOST=docker.yourcompany.com
DOCKER_REGISTRY_AUTH=someuser:somepassword
function _docker_fetch() {