Skip to content

Instantly share code, notes, and snippets.

View elfsternberg's full-sized avatar
💭
Breathing

Ken "Elf" Mathieu Sternberg elfsternberg

💭
Breathing
View GitHub Profile
@elfsternberg
elfsternberg / help.mk
Created September 27, 2023 17:26
A much simpler "make help"
# make help
#
# Usage: Download this file and put it somewhere. In a GNU Makefile, add the
# following line near the top of your Makefile:
#
# ```
# include /path/to/help.mk
# ```
#
# Alternatively, you could just cut and paste the code from this gist into your
@elfsternberg
elfsternberg / stwatch.sh
Last active September 7, 2023 16:20
A very (very!) simple screensaver for watching a folder with slow progressive downloads
#!/usr/bin/env bash
# Absolutely dumb progressive "screensaver". Basically, it watches a folder and, whenever a new
# image appears, puts that one up fullscreen, then tears down the prior one underneath. Useful for a
# folder where you're either doing slow downloads or rendering illustrations and just want to watch
# the results.
# Requires [feh](https://feh.finalrewind.org/),
# [tac](https://man7.org/linux/man-pages/man1/tac.1.html)
# inotifywait(https://github.com/inotify-tools/inotify-tools).
@elfsternberg
elfsternberg / important-shadow-context-demo.markdown
Last active August 20, 2023 15:52
Important Shadow Context Demo
@elfsternberg
elfsternberg / zolatoml.py
Last active February 10, 2023 22:59
Helper functions for manipulating Zola content files
import sys
import toml
from typing import List, Dict, Any
# I use Zola as my primary static site generator, and these are the functions I
# use regularly with python scripts to access, manipulate, and modify the
# headers and content.
def get_file_metablock_markers(lines: List[str], filename: str) -> List[int]:
@elfsternberg
elfsternberg / githelpers.py
Created February 10, 2023 22:53
Python `get git root` function, for build scripts
import subprocess
def get_root() -> str:
"""Return the current project root.
A lot of scripts written for build system need to know where they are
relative to a project's root. This function returns the root folder, giving
developers a concrete starting location for all file manipulation.
"""
@elfsternberg
elfsternberg / dreamwidth-to-markdown.py
Created January 29, 2023 18:24
Opens the 'jbak' (GDBM) file produced by the Dreamwidth backup tool, and converts each entry into a markdown file suitable for Zola or Hugo
from dbm import gnu
from collections import namedtuple
from markdownify import markdownify as md
from slugify import slugify
EVENT = b"event:event:"
elfs = gnu.open("./elfs.jbak", "r")
def key_extraction(key):
#!/usr/bin/env bash
set -o errexit
set -o nounset
shopt -s nullglob
function _die() {
echo "ERROR $? IN ${BASH_SOURCE[0]} AT LINE ${BASH_LINENO[0]}" 1>&2
exit 1
}
@elfsternberg
elfsternberg / mame-completions.sh
Created November 1, 2022 13:42
Bash completions for MAME
MAME_ROM_PATH="$HOME/.local/share/mame/roms"
_mame_completions()
{
COMPLETIONS=$(echo $(ls "$MAME_ROM_PATH" | sed 's/\.zip$//i'))
COMPREPLY=$(compgen -W "$COMPLETIONS" "${COMP_WORDS[1]}")
}
complete -F _mame_completions mame
@elfsternberg
elfsternberg / bash_template.sh
Created April 6, 2022 15:36 — forked from andremueller/bash_template.sh
A bash template with argument parsing and error handling
#!/bin/bash
# my bash template
set -o errexit
set -o nounset
shopt -s nullglob
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
function die() {
echo "ERROR $? IN ${BASH_SOURCE[0]} AT LINE ${BASH_LINENO[0]}" 1>&2
@elfsternberg
elfsternberg / onetab_backup.py
Last active October 26, 2021 15:13
A primitive "dump the current OneTab collection kept in my Chrome Browser" script.
import os
from subprocess import Popen, PIPE
import binascii
import json
import ast
# An extremely primitive dump of the
# [OneTab](https://www.one-tab.com/) local database.
# Logic is derived from [Recovering data from