Skip to content

Instantly share code, notes, and snippets.

View adamghill's full-sized avatar

Adam Hill adamghill

View GitHub Profile
@adamghill
adamghill / justfile
Last active September 17, 2025 12:13
Get Python versions for testing based on `project.requires-python` in pyproject.toml
# Run tests across all supported Python versions
test-all-versions:
#!/usr/bin/env bash
set -euo pipefail
for version in $(yq '.project.requires-python' pyproject.toml | uv run versionator.py); do
echo -e "\n=== Testing with Python $version ==="
uv run --all-extras --python "$version" pytest
echo -e "\n=== Tests completed for Python $version ===\n"
done
@adamghill
adamghill / justfile.md
Last active August 16, 2025 14:21
Some default `just` commands for Django projects

just manage

# Manage
manage *ARGS='':
  uv run --all-extras python3 manage.py {{ ARGS }}

just run

@adamghill
adamghill / index.html
Created July 31, 2025 23:11
Django middleware to collect basic statistics and show on a template
{% if request.user.is_superuser %}
<div class="p-4 bg-gray-100">
<div class="font-bold">
DEBUG-O-MATIC
</div>
<!-- DEBUG STATS -->
<div class="pt-2 font-bold">
Current user
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="./favicon.ico" />
<!-- Preload is necessary because we show these images when we disconnect from the server,
but at that point we cannot load these images from the server -->
<link rel="preload" href="./assets/gradient-yHQUC_QB.png" as="image" />
<link rel="preload" href="./assets/noise-60BoTA8O.png" as="image" />
<!-- Preload the fonts -->
@adamghill
adamghill / fields.py
Last active May 3, 2025 13:13
A field for `IntegerChoices` which does not generate a new migration when the choices change
class IntegerChoicesField(models.IntegerField):
"""A field for `IntegerChoices` where changing the choices does not generate a new migration. To be used instead of an `IntegerField`.
Based on a suggestion from https://mastodon.social/@bmispelon at https://mastodon.social/@bmispelon/114438157173090099.
"""
def deconstruct(self):
deconstructed_field = super().deconstruct()
if len(deconstructed_field) >= 4 and "choices" in deconstructed_field[3]:
@adamghill
adamghill / ajax-form.js
Last active March 17, 2025 11:53
Custom Element that calls the form action via fetch and replaces itself with the response's result
/**
* A custom element which enhances a form so it submits via AJAX and replaces itself.
*
* Based on https://gomakethings.com/progressively-enhancing-forms-with-an-html-web-component-part-2/ with a few tweaks.
*/
class AjaxForm extends HTMLElement {
constructor() {
super()
// Define options
@adamghill
adamghill / config
Created February 11, 2025 12:29
ghostty settings config
theme = Dracula+
keybind = cmd+opt+right=next_tab
keybind = cmd+opt+left=previous_tab
<!--
Just playing around with https://github.com/hawkticehurst/stellar/blob/vnext/signal-element.js from https://hawkticehurst.com/2024/12/declarative-signals/.
There are also some silly utility functions here to clean up the examples below.
How-to:
1. Grab my fork at https://github.com/adamghill/stellar/blob/remove-custom-renderer/signal-element.js
2. Grab this HTML
3. `python -m http.server 8000`
4. Go to http://localhost:8000/signal-element-example.html
@adamghill
adamghill / bluesky-convert-starter-pack-to-list.py
Last active November 8, 2024 13:06
Convert a starter pack to a list for Bluesky
# Python port of https://github.com/sbm12/bsky-Pack2List/blob/main/bskyList2StarterPack.php with some fixes / features
# Handle is username or email address
# Password is the regular login password or a specific app password
import json
from datetime import datetime
import requests
@adamghill
adamghill / justfile
Created July 6, 2024 20:20
Example justfile for Python projects
# https://just.systems
set quiet
set dotenv-load
set export
# List commands
_default:
just --list --unsorted --justfile {{justfile()}} --list-heading $'Available commands:\n'