Skip to content

Instantly share code, notes, and snippets.

View ernstki's full-sized avatar

Kevin Ernst ernstki

  • Earth, Sol
View GitHub Profile
@ernstki
ernstki / !multised.md
Last active October 20, 2025 01:14
Multi-line replacement in sed - https://stackoverflow.com/q/75220171

Multi-line text replacement with sed

Original question: "Catch an entire function with grep" on Stack Overflow

It is possible to use (GNU) grep to do multiline matching[^fn1], but you're probably making more work for yourself that way, because sed can do basically everything grep can plus make replacements.

Using grep -zoP to do multiline matching is fundamentally the same trick as what's proposed below: turning your file into one long string, separated by

@ernstki
ernstki / nextlocalport.py
Created October 18, 2025 22:06
Get me the next available local TCP port, given a start port
import sys
import socket
import logging
logging.getLogger().setLevel(logging.DEBUG)
port = None
startport = 8000
MAXTRIES = 10
@ernstki
ernstki / flatpak-orphans.py
Last active October 17, 2025 19:00
List space used by Flatpak ~/.var/app directories for apps that are no longer installed
#!/usr/bin/env python3
##
## flatcrap - lists orphaned Flatpak data in ~/.var/app
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## Date: 16 October 2025
## License: MPL 2.0
## Homepage: https://gist.github.com/ernstki/f3e279e8a050c2df94e9fcfd69d67c2f
##
## Originally based on `main.py` from Flatsweep by giantpinkrobots[1], but
@ernstki
ernstki / dehectonanoseconds.py
Last active October 14, 2025 16:11
Convert LDAP timestamps (100-nanosecond intervals since 1 Jan, 1614) to human-readable times in your local timezone
#!/usr/bin/env python3
##
## Convert LDAP’s “number of 100-nanosecond intervals since January 1, 1601
## (UTC)” timestamps to human-readable dates, in the local timezone. See
## reference [1] for more details.
##
## Does not use f-strings, so should work in any old Python 3.
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## Date: 13 Oct 2025
@ernstki
ernstki / rdscert
Last active October 8, 2025 21:50
rdscert - list Windows Remote Desktop machine certs in the format used by Remmina on Linux
#!/usr/bin/bash
HASHALG=sha256
files=()
args=(-$HASHALG)
while (( $# )); do
case $1 in
-*)
for arg in "${args[@]}"; do
if [[ $1 == $arg ]]; then
@ernstki
ernstki / p5which
Last active June 27, 2025 00:58
`which` for Perl, R, and Python libraries
#!/usr/bin/env perl
##
## Print where a Perl 5 library was included from
##
## Author: Symkat
## Source: http://www.symkat.com/find-a-perl-modules-path
## License: Distributed under the same terms as Perl itself
## <https://perldoc.perl.org/perlartistic>
##
use warnings;
@ernstki
ernstki / macman
Last active May 9, 2025 16:09
Render a roff man page from the apple-oss-distributions GitHub org
#!/usr/bin/env bash
##
## Fetch macOS manual pages from the apple-oss-distributions GitHub org
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## Date: 8 May 2025
## Source: https://gist.github.com/ernstki/ea2649e5ec34dacd9b1d13a8eae10a54
## License: WTFPL
##
## To do: caching
@ernstki
ernstki / Makefile
Created March 29, 2025 17:40
Mkdocs Makefile (before I realised it already *does* all that stuff on its own)
TITLE = Lyrion.org documentation tasks
SHELL = bash
PYTHON = python3
VIRTUALENV = venv
REQUIREMENTS = mkdocs-requirements.txt
OUTPUTDIR = site
BINDADDR = 127.0.0.1
PORT = 8888
help: # prints this help
@ernstki
ernstki / Makefile
Last active January 14, 2025 13:30
Test multiple versions of Package X against multiple versions of Package Y
##
## Test multiple versions of delta[1] against multiple versions of bat[2]
## and stop when there's a failure
##
## Tested with GNU Make 4.x on Linux; YMMV with macOS or BSD
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## Source: https://gist.github.com/ernstki/7dbb17c42911708660dc3c4eee3c1002
## License: released to the public domain
##
@ernstki
ernstki / flatpak-link
Last active November 23, 2024 19:16
Create symlinks in your ~/bin for Flatpak apps, with sensible names