Skip to content

Instantly share code, notes, and snippets.

View adamghill's full-sized avatar

Adam Hill adamghill

View GitHub Profile
<!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'
@adamghill
adamghill / docker.md
Created May 25, 2024 17:44
Useful docker CLI commands that I always forget

Note: IMAGE_NAME should be replaced with some unique name.

  • Build the Dockerfile in the current directory: docker build -t IMAGE_NAME .
  • Get the size of the resulting Docker image: docker image save IMAGE_NAME | wc -c | numfmt --to=si
  • Run the resulting Docker image for web apps: docker run -p 127.0.0.1:80:3000 IMAGE_NAME
  • Open a shell in a Docker image: docker run -it --rm IMAGE_NAME /bin/bash
@adamghill
adamghill / Dockerfile
Last active June 1, 2024 03:30
Multi-stage Dockerfile with Python and `uv`
# Layer with Python and some shared environment variables
FROM python:3.10-slim-bullseye as python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Layer for installing Python dependencies
FROM python as dependencies
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
// This was an initial prototype, but https://github.com/adamghill/conjure has the latest version