Skip to content

Instantly share code, notes, and snippets.

@torbiak
torbiak / pass
Last active April 9, 2016 18:21
Copy passwords from a vim-encrypted file to the clipboard.
#!/usr/bin/env bash
IFS=$'\t\n'
set -eu
set -o pipefail
PASS_FILE=${PASS_FILE:-~/notes/numbers.md}
PASS_CLIP_TIME=${PASS_CLIP_TIME:-30}
not_found=2
no_password=3
@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>
@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 / mrmgroup.pl
Created February 3, 2017 03:33
Print the group of files modified within an hour of the most recently modified file
#!/usr/bin/env perl
# Print the group of files modified within an hour of the most recently
# modified file.
use strict;
use List::Util qw[min max];
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
sub HELP_MESSAGE {
@torbiak
torbiak / syncxcode
Created July 28, 2017 09:19
Sync audio/video files in some format in SRC to another format in DST.
#!/bin/bash
# usage: syncxcode SRC DST
set -eu
max_procs=3
src_format=flac
dst_format=mp3
function sync {
set -eu
@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 / 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

#!/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 / 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
@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:" "$@"