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 / tdd.sh
Created October 13, 2024 14:58
A Bash script for running an iterative TDD loop using an LLM to make a set of tests pass
#!/usr/bin/env bash
#
# A Bash script to run a TDD loop for building a Python module to pass tests.
set -euo pipefail
# How many times to loop.
ATTEMPTS=4
# The system prompt to use when creating the initial version.
@codeinthehole
codeinthehole / user-data.sh
Created August 18, 2014 12:41
Get the value of an EC2 instance's tag
#!/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:
#
# {
@codeinthehole
codeinthehole / git-fixup-files
Created August 8, 2024 11:01
Custom version of `git absorb` which autosquashes unstaged changes
#!/usr/bin/env bash
#
# Try and squash unstaged changes into existing branch commits.
#
# This command examines each unstaged file and attempts to create a fix-up
# commit to squash it into its natural parent in the current branch.
#
# - If it's able to do this for all modified files, the fix-up files are
# automatically squashed in.
#
@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 / codeowner-breakdown
Created July 9, 2024 09:49
A Python script to categorise a list of filepaths by code owners
#!/usr/bin/env python
"""
Print a breakdown of the passed filepaths by CODEOWNER team.
This script requires the `codeowners` CLI tool to be installed and available on the $PATH.
https://github.com/hmarr/codeowners
Intended usage is to pipe filepaths into this script from the root of a repo:
cat filepaths.txt | codeowner-breakdown
@codeinthehole
codeinthehole / noxfile.py
Created May 24, 2024 09:33
A `noxfile.py` for running matrix testing of a Python package
import os
import time
import nox
@nox.session(python=["3.10", "3.11", "3.12"])
@nox.parametrize("django_constraint", ["<4.2", "<4.3", "<5.1"])
def tests(session: nox.Session, django_constraint: str) -> None:
"""
@codeinthehole
codeinthehole / osx_bootstrap.sh
Last active May 19, 2024 20:47
Script to install stuff I want on a new OSX machine
#!/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)
@codeinthehole
codeinthehole / run.py
Created November 21, 2012 13:46
Sample Celery chain usage for processing pipeline
from celery import chain
from django.core.management.base import BaseCommand
from . import tasks
class Command(BaseCommand):
def handle(self, *args, **kwargs):
@codeinthehole
codeinthehole / userdata.sh
Created February 2, 2016 21:21
Terraform config for an EC2 instance with a replaceable EBS volume
#!/bin/bash
DEVICE=/dev/$(lsblk -n | awk '$NF != "/" {print $1}')
FS_TYPE=$(file -s $DEVICE | awk '{print $2}')
MOUNT_POINT=/data
# If no FS, then this output contains "data"
if [ "$FS_TYPE" = "data" ]
then
echo "Creating file system on $DEVICE"
@codeinthehole
codeinthehole / python-testing.md
Last active April 9, 2024 00:37
Python testing reference

Python testing reference

This document is a reference for common testing patterns in a Django/Python project using Pytest.

Contents: