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 / gist:aab94aa0155234409a94d1f10b0790de
Created November 15, 2025 22:16
webcam-compress: Monitor a folder and as the webcam dumps JPGs into it, convert them to WEBP
#!/usr/bin/env bash
# A very simple script to watch a folder for new images. When new images
# are written to the folder, automatically convert them to webp and, if the
# conversion is successful, delete the JPG.
# Require ImageMagick and inotify-tools
set -o errexit
set -o nounset
@elfsternberg
elfsternberg / gist:bf97f6cf31edaa50d5c9c9717bc82945
Created November 15, 2025 22:13
swatch-cats: A simple monitor to watch the webcam watching my cats
#!/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 monitoring a webcam and want to check the results
# Requires [feh](https://feh.finalrewind.org/),
# inotifywait(https://github.com/inotify-tools/inotify-tools).
echo "$$" > $HOME/.swatch-pid
@elfsternberg
elfsternberg / start_of_line.rs
Created June 2, 2024 05:13
Rust Nom Parser that recognizes "at the beginning of a line."
use nom::{
bytes::complete::{tag, take_while},
combinator::recognize,
sequence::preceded,
IResult,
};
/**
* Using Rust Nom, show how to detect "content that begins at the start of a line." This particular
* variant rolls forward until it finds any content *other than* the start of a line, which is
;; Old-school noweb in poly mode for emacs, now with Markdown. This does require one
;; bit of sed (perl, whatever) to work properly: you'll have to find all the chunks
;; that start with '<<...>>=' and remove the polymode ending indicating the language type.
(use-package poly-noweb
:ensure
:config
(require 'poly-markdown)
(define-obsolete-variable-alias 'pm-host/markdown-for-noweb 'poly-noweb-markdown-hostmode "v0.2")
@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 / 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
}