Skip to content

Instantly share code, notes, and snippets.

View neilmayhew's full-sized avatar

Neil Mayhew neilmayhew

View GitHub Profile
@neilmayhew
neilmayhew / notify-gh-run-completion.sh
Created September 29, 2026 13:43
Post a notification when a GitHub CI run completes
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
# Post a notification when a GitHub CI run completes
#
# Usage: notify-gh-run-completion URL
#
# Example URL: https://github.com/owner/repo/actions/runs/123456789
@neilmayhew
neilmayhew / GracefulTermination.hs
Last active September 29, 2026 14:41
Graceful handling of SIGTERM for Haskell programs
module System.GracefulTermination where
import Control.Concurrent.Async (race)
import Control.Concurrent.MVar
import Data.Functor (void)
import System.Posix.Signals
-- | Ensure that @SIGTERM@ is handled gracefully, because it's how containers are stopped.
--
-- @action@ will receive an 'AsyncCancelled' exception if @SIGTERM@ is received by the process.
@chgeuer
chgeuer / create_json_functionally.md
Last active November 19, 2021 22:35
Creates a JSON structure in the shell

A purely functional JSON processing pipeline using jq in bash

It starts with an empty JSON object, and each jq step in the pipeline further augments the structure. In case you want to step-by-step build up a JSON string in a shell.

How does it work

The --arg binds a string variable from bash to the jq-variable x.

The jq expression ($x | fromjson) parses the string into whatever JSON would be appropriate. So the bash variable true becomes the proper true boolean in the JSON. If we only would use $x (instead of ($x | fromjson)), the bash variable true would become the JSON string "true".

@neilmayhew
neilmayhew / digraphs.py
Last active June 5, 2021 22:10
Python script to print a counted list of all digraphs in a set of files
#!/usr/bin/env python
import fileinput, re
counts = {}
for l in fileinput.input():
l = l.lower()
for m in re.finditer(r'[a-z](?=[a-z])', l):
graph = l[m.start():m.end()+1]
@neilmayhew
neilmayhew / close-branches.sh
Last active February 27, 2020 19:16 — forked from matiasgarciaisaia/hg-to-git.sh
Script to convert from hg to git that wraps hg-fast-export and performs some additional fixups
#!/bin/bash
USAGE="Usage: $(basename "$0" .sh) SOURCE-HG DEST-GIT"
SRC=${1?$USAGE} || exit 1
DST=${2?$USAGE} || exit 1
SANITIZE=$(dirname "$0")/sanitize.py
(cd "$SRC" &&