Skip to content

Instantly share code, notes, and snippets.

@torbiak
torbiak / groff-install-font
Last active November 21, 2023 21:26
Install ttf and otf fonts for use with groff
#!/usr/bin/env bash
# groff-install-ttf converts a TrueType (ttf) or OpenType (otf) font to a
# Printer Font ASCII (pfa) font and a groff font (ditroff) and installs them to
# groff's site-font directory.
#
# Requires fontforge.
#
# You're the best, Peter Schaffter, but contrary to the verbose and
# difficult-to-follow http://www.schaffter.ca/mom/momdoc/appendices.html#fonts,
# the t42 file doesn't seem to be necessary, at least with recent versions of
@torbiak
torbiak / grabtest.c
Created January 5, 2017 05:05
Reproduce X11 bug where the second KeyRelease event is missing if two grabbed keys are released in quick succession.
// grabtest tries to reproduce an X11 bug where, when two keys grabbed using
// XGrabKey are held down and then quickly released, the second KeyRelease
// event never makes it to the event queue.
//
// make LDFLAGS=-lX11\ -lXtst grabtest
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
#include <X11/Xlib.h>
#!/bin/bash
set -eu
sync() {
local host=${1:?No host given}; shift
local src=${1:?No src dir given}; shift
local dst=${1:?No dst dir given}; shift
local bytes=${1:?No byte capacity given}; shift
local tmpdir
@torbiak
torbiak / test_mlr_strptime_vs_date
Created July 9, 2021 06:04
Test mlr strptime against GNU date
#!/bin/bash
set -euo pipefail
export TZ=America/Sao_Paulo
test_strptime_local() {
printf "\n$FUNCNAME\n"
local dates="\
2017-02-18 23:00:00
2017-02-18 23:59:59
@torbiak
torbiak / subcommands.sh
Created October 4, 2020 00:25
A straightforward way to have subcommands that each handle their own command lines, in a bash script.
#!/bin/bash
set -euo pipefail
a() {
# TODO: parse options or whatever.
echo "a called with args:" "$@"
}
b() {
echo "b called with args:" "$@"
@torbiak
torbiak / hide_sticky.js
Last active June 12, 2020 20:25
Try to make a webpage readable by hiding any fixed/sticky elements---popups, dickbars, etc---and changing overflow=hidden to visible.
// Try to make a webpage readable by hiding any fixed/sticky elements---popups,
// dickbars, etc---and changing overflow=hidden to visible.
//
// Adapted from [here](https://alisdair.mcdiarmid.org/kill-sticky-headers/).
//
// I like to use this as a bookmarklet bound to a keyword. To create a
// bookmarklet, use the below code as the url for a bookmark, prefixed by
// `javascript:`.
//
// Go over all elements and hide any fixed/sticky ones in multiple ways so that
#!/bin/bash
usage='usage taketilcap [-h|--help] <capacity>
-h Show help
Filter newline-delimited filenames provided on stdin'
[[ $# -lt 1 ]] && {
echo "$usage"
exit 1
@torbiak
torbiak / beef_stew.md
Created October 23, 2018 06:41
Beef Stew

Discussion

This stew hit such a sweet spot of convenience, tastiness, economy, and vegetable density that I cooked it weekly for about 2 years, eating the leftovers for several days of each week. It's mostly based off of Mark Bittman's Beef Stew with Guinness (the url is broken, sadly) and the Classic Beef Stew recipe from his How to Cook Everything (p. 435).

Beef

I get the packs of stewing beef at the closest Superstore. The price is usually fine and I enjoy the variety of cuts they contain and the intermediate fat content. Mark Bittman recommends round or chuck. In Canada I think chuck is called either blade or shoulder. Blade is the more flavourful of the two but it's maybe too fatty, and the flavour isn't always the best. Round is relatively tough, bland, and lean, but it's consistent and I consider it the safer choice. Round roast also seems more likely to be available.

I've cooked this many times, some browning the beef and some

@torbiak
torbiak / SplitCol.vba
Created January 30, 2018 03:28
Excel VBA subroutine to split a multi-value column into multiple boolean columns
' Split the selected column containing values like "a;b;c", "a;c" into boolean
' 0/1 columns for each of "a", "b", "c".
Sub SplitCol()
Dim c As Range
Dim newCols As Object
Dim ncols As Long
ncols = 0
Set newCols = CreateObject("Scripting.Dictionary")
For Each c In Intersect(ActiveSheet.UsedRange, Selection.EntireColumn).Offset(1)
Dim s As Variant
@torbiak
torbiak / tag-created
Last active November 8, 2017 06:57
Tag ogg, flac, and mp3 files with their Windows creation time.
#!/usr/bin/python
# Tag mp3, ogg, and flac files with a 'created' tag in the format 'YYYYMMDD',
# based on the file's birthtime, as stored by Windows. Unix doesn't store
# birthtimes, so this won't work there.
import os
import sys
from time import strftime, localtime
import mutagen # v1.21 works. Others probably do, too.