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 / 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 / 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 / convert
Created September 28, 2023 10:28
Alfred workflow script for converting numbers to durations
#!/usr/bin/python3
#
# This script can be used as a Alfred Script Filter in a custom workflow for converting numbers to durations.
# To do so, create a new workflow, add a script filter with contents './convert "$@"', ensuring that the
# query is passed as "with input as argv".
#
# It's useful to connect a "Copy to Clipboard" output action to make it easier to paste the duration string somewhere.
import argparse
import json
@codeinthehole
codeinthehole / pull-request-title
Created December 23, 2022 15:47
A Bash script that uses OpenAI's API to generate a pull request title
#!/usr/bin/env bash
#
# Print a title of the current pull request's commits.
#
# - For single commit pull requests, this prints the subject of the commit.
#
# - For multi-commit pull requests, this uses OpenAI's REST API to digest the
# commit messages of the pull request into a single sentence.
#
# Requires an OPENAI_API_KEY env var to authenticate requests - see:
@codeinthehole
codeinthehole / pull-request-summary
Created December 23, 2022 15:46
A Python script that generates a pull request body
#!/usr/bin/env python
#
# Print out a summary of the pull request.
#
# This combines the commit messages and removes the hard wrapping so the text renders better in
# Github's UI. The output won't be suitable as is, but provides a good start for moulding into a
# good description.
import subprocess
@codeinthehole
codeinthehole / pull-request-summary
Last active December 8, 2022 12:12
Use OpenAI's GPT3 model to generate pull request descriptions.
#!/usr/bin/env bash
#
# Print a summary of the current pull request's commits.
#
# Requires an OPENAI_API_KEY env var to authenticate requests - see:
# https://beta.openai.com/docs/api-reference/authentication
# Commit selection variables.
TARGET_BRANCH=master
@codeinthehole
codeinthehole / 1pw-item-users
Created June 29, 2022 21:29
Bash script for listing the users who have access to a 1Password item
#!/usr/bin/env bash
#
# Print the users who have access to a given 1Password item.
#
# Usage:
#
# 1pw-item-users "$ITEM_NAME"
#
# Note, the `op` tool must be authenticated before this command is run.
@codeinthehole
codeinthehole / gmail-report.js
Last active August 9, 2022 08:28
Google Apps Script for building a CSV report from Gmail threads
// To use this, create a new Apps Script project and paste this script in.
// https://developers.google.com/apps-script
function FetchReport() {
// Define a Gmail search query.
var searchQuery = "cluedo after:2022-01-01"
// Define a predicate that determines when to stop looping.
function shouldWeKeepLooping(thread) {