Skip to content

Instantly share code, notes, and snippets.

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