Skip to content

Instantly share code, notes, and snippets.

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 / pull-request-title
Created Dec 23, 2022
A Bash script that uses OpenAI's API to generate a pull request title
View 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 Dec 23, 2022
A Python script that generates a pull request body
View pull-request-summary
#!/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 Dec 8, 2022
Use OpenAI's GPT3 model to generate pull request descriptions.
View pull-request-summary
#!/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 Jun 29, 2022
Bash script for listing the users who have access to a 1Password item
View 1pw-item-users
#!/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 Aug 9, 2022
Google Apps Script for building a CSV report from Gmail threads
View gmail-report.js
// 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) {
@codeinthehole
codeinthehole / fix-json-frontmatter.py
Created Mar 3, 2022
Correctly wrap JSON front-matter in markdown files
View fix-json-frontmatter.py
#!/usr/bin/env python
#
# Script to wrap JSON front-matter in markdown files with `---` delimiters.
#
# This allows Prettier to be used on the markdown file (and it won't try and format the JSON front
# matter).
#
# I needed this to convert old Hugo markdown files that had JSON front-matter.
import os
import sys
@codeinthehole
codeinthehole / github-team-report.sh
Created Feb 2, 2022
Open Github pull request list page filtered to closed PRs from the last week from a given team
View github-team-report.sh
#!/bin/bash
#
# Script that opens the Github pull request search page filtered to show closed pull
# requests from the last week, from members of a specified set of users.
#
# This can be useful for team leads when writing progress reports.
# Config
# ------
@codeinthehole
codeinthehole / python-testing.md
Last active Jan 26, 2023
Python testing reference
View python-testing.md

Python testing reference

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

Contents:

@codeinthehole
codeinthehole / test_timezones.py
Last active Mar 9, 2021
A Python unit test that demonstrates the problem with Django's `make_aware` function
View test_timezones.py
import datetime
import pytz
from django.utils import timezone
from dateutil import tz
# This test passes.
def test_pytz_vs_dateutil_timezones():
timezone_name = "Europe/London"
# Start with a naive dt.
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