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 / 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 / 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