Skip to content

Instantly share code, notes, and snippets.

@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 August 21, 2025 23:59
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>
@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 / format-srt.rb
Created April 4, 2016 12:21
Clean and format subrip subtitles that have been converted from ASS format by ffmpeg.
#!/usr/bin/env ruby
require 'text/format'
class Entry
attr_accessor :flighting, :body
def initialize
@body = []
end
@torbiak
torbiak / gtff.py
Last active April 17, 2016 19:01
Guess Tag From Filename
#!/usr/bin/env python
# Guess Tags From Filename, using python and mutagen.
import mutagen
from mutagen.easyid3 import EasyID3
import re
import os.path
import sys
@torbiak
torbiak / .Xmodmap
Created March 27, 2016 05:56
13" macbook air xmodmap
keycode 232 = XF86MonBrightnessDown
keycode 233 = XF86MonBrightnessUp
keycode 121 = XF86AudioMute
keycode 122 = XF86AudioRaiseVolume
keycode 123 = XF86AudioLowerVolume
keycode 173 = XF86AudioPrev
keycode 172 = XF86AudioPlay
keycode 171 = XF86AudioNext
@torbiak
torbiak / diffmon
Created October 9, 2015 19:05
Periodically monitor a command's output for changes.
#!/usr/bin/env bash
# Monitor a command's output for changes.
set -eu
usage="diffmon [-D] [-t INTERVAL] CMD ARGS...
-t INTERVAL Interval to sleep between command executions
-b Print a blank line between changes instead of the date"
interval=1
show_date=yes
while getopts "hbt:" o; do
case "$o" in
@torbiak
torbiak / spec_vim_formatter.rb
Created March 3, 2015 06:00
rspec formatter for vim :make
class VimFormatter
RSpec::Core::Formatters.register self, :example_failed, :example_passed, :dump_summary
def initialize(output)
@output = output
end
def example_passed(n)
@output << "PASSED: " << n.example.description << "\n\n"
end
@torbiak
torbiak / birthed.py
Created November 8, 2014 22:57
find files based on their Windows "birthtime"
#!/usr/bin/python
# Recursively print files created before/at/after (-//+) some number of days
# ago. This only works on Windows, which stores file "birthtime" in the
# filesystem
import sys
import os
from datetime import date, timedelta