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 / .pythonstartup.py
Created December 30, 2020 11:41
Python start-up file
# 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 / analyse_codebase.sh
Last active February 23, 2022 11:06
Analyse the changes in a repo over the last year
#!/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 / find_dead_template_tags.sh
Last active May 20, 2021 05:45
Bash script to find unused custom template tags and filters
#!/usr/bin/env bash
#
# Helper script to look for unused template tags and filters.
#
# Run this in the root of your project and it will print out template tags and filters that
# aren't used anywhere.
#
# Requires ripgrep (rg).
set -e
@codeinthehole
codeinthehole / test_commits.py
Created October 11, 2019 15:52
Sample test module for validating the commits messages on a PR branch
import re
import subprocess
import pytest
@pytest.mark.parametrize(
"subject, error_msg",
[
("WIP: working on something", "is a WIP commit"),
@codeinthehole
codeinthehole / .vimrc
Last active April 13, 2021 13:47
~/.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 / client.py
Last active July 27, 2023 07:40
Sample Python client for working with the Octopus Energy REST API
# 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
@codeinthehole
codeinthehole / account_tweets.py
Created November 7, 2017 22:50
Python script for printing out an account's tweets
"""
Script for printing out tweets from a given account
Sample usage:
python account_tweets.py qikipedia
"""
import twitter
import sys
@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 / .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