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 / client.py
Last active Jan 13, 2021
Sample Python client for working with the Octopus Energy REST API
View client.py
# Requires the requests library (install with 'pip install requests')
import requests
class APIClient(object):
BASE_URL = "https://api.octopus.energy/v1"
class DataUnavailable(Exception):
"""
Catch-all exception indicating we can't get data back from the API
View .vimrc
" ============= " VIMRC file for David Winterbottom (@codeinthehole) " ===========
" Inspiration {{{
" -----------
" Videos:
" - http://www.youtube.com/watch?v=aHm36-na4-4
"
" Articles:
"
" - http://alexpounds.com/blog/2014/06/06/the-vimrc-antiques-roadshow
@codeinthehole
codeinthehole / user-data.sh
Created Aug 18, 2014
Get the value of an EC2 instance's tag
View user-data.sh
#!/usr/bin/env bash
#
# Get the value of a tag for a running EC2 instance.
#
# This can be useful within bootstrapping scripts ("user-data").
#
# Note the EC3 instance needs to have an IAM role that lets it read tags. The policy
# JSON for this looks like:
#
# {
View .pythonstartup.py
# Python start-up file
# --------------------
# Ensure a PYTHONSTARTUP environment variable points to the location of this file.
# See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP
# Always have pp available
from pprint import pprint as pp
# Pre-emptively import datetime as I use it a lot.
import datetime
@codeinthehole
codeinthehole / osx_bootstrap.sh
Created Mar 30, 2015
Script to install stuff I want on a new OSX machine
View osx_bootstrap.sh
#!/usr/bin/env bash
#
# Bootstrap script for setting up a new OSX machine
#
# This should be idempotent so it can be run multiple times.
#
# Some apps don't have a cask and so still need to be installed by hand. These
# include:
#
# - Twitter (app store)
View analyse_codebase.sh
#!/usr/bin/env bash
#
# Fetch diff stats for the current repo from the last year
# Get a commit SHA from a year ago
OLD_SHA=$(git log --since="365 days ago" --until="364 days ago" -1 --pretty=format:"%H")
NEW_SHA=$(git rev-parse HEAD)
# Number of lines then and now
OLD_LINES=$(git diff --stat `git hash-object -t tree /dev/null`..$OLD_SHA | awk '/files changed/ {print $4}')
@codeinthehole
codeinthehole / portforward.sh
Last active Aug 8, 2020
Bash helper function for easier port forwarding - should be added to your ~/.bashrc
View portforward.sh
# Easier port forwarding - usage:
#
# $ portforward project-app1 5432
#
# where 'project-app1' is an alias from ~/.ssh/config and 5432 is the remote
# port that you want to forward to.
function portforward() {
HOST=$1
REMOTE_PORT=$2
# Pick a random port and check it is free
@codeinthehole
codeinthehole / run.py
Created Nov 21, 2012
Sample Celery chain usage for processing pipeline
View run.py
from celery import chain
from django.core.management.base import BaseCommand
from . import tasks
class Command(BaseCommand):
def handle(self, *args, **kwargs):
@codeinthehole
codeinthehole / account_tweets.py
Created Nov 7, 2017
Python script for printing out an account's tweets
View account_tweets.py
"""
Script for printing out tweets from a given account
Sample usage:
python account_tweets.py qikipedia
"""
import twitter
import sys
View .gitconfig
[user]
name = David Winterbottom
email = david.winterbottom@gmail.com
[alias]
# SHORT VERSIONS
co = checkout
ci = commit
You can’t perform that action at this time.