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 / docker-osx-shared-folders.rst
Last active November 11, 2023 01:22
How to share folders with docker containers on OSX

How to share a folder with a docker container on OSX

Mounting shared folders between OSX and the docker container is tricky due to the intermediate boot2docker VM. You can't use the usual docker -v option as the docker server knows nothing about the OSX filesystem - it can only mount folders from the boot2docker filesystem. Fortunately, you can work around this using SSHFS.

" ==================================================
" 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 / uwsgi_stats
Last active May 15, 2019 22:00
Zabbix plugin script for extracting uWSGI metrics from a log file
#!/usr/bin/env python
"""
Extract metrics from a uWSGI log file
This should be saved as /etc/zabbix/pluginx/uwsgi_stats and called from
/etc/zabbix/zabbix_agentd.conf.d/uwsgi.conf, which should have contents:
UserParameter=uwsgi.stats[*],/etc/zabbix/plugins/uwsgi_stats $1 $2
To gather these metrics in Zabbix, create a new item which calls this plugin and
@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')
@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 / 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 / comparison.py
Last active March 20, 2019 06:13
Comparison of three ways of assigning excluded fields to a model when creating via a form
# Question - how best to handle model fields that are excluded from a form's
# fields.
# ------------------------------------------------------------
# Option 1: assign fields to instance before passing into form
# ------------------------------------------------------------
# views.py
instance = Vote(review=review, user=request.user)
form = VoteForm(data=request.POST, instance=instance)
@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 / 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 / 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);