Skip to content

Instantly share code, notes, and snippets.

View neilmayhew's full-sized avatar

Neil Mayhew neilmayhew

View GitHub Profile
@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" &&