Skip to content

Instantly share code, notes, and snippets.

@rhaberkorn
rhaberkorn / aes.apl
Last active November 11, 2023 14:07
AES in GNU APL
⍝ Left rotate ⍺ bit
Rot8 ← {2⊥⍺⌽(8⍴2)⊤⍵}
⍝ Addition and subtraction in finite field GF(2)
Add2 ← {⍺ ⊤≠ ⍵}
⍝ Multiplication in GF(2) [x]/(x8 + x4 + x3 + x + 1)
Mul2 ← {⊤≠/({⍵,$FF ⊤∧ ($11B×$80≤¯1↑⍵) ⊤≠ 2ׯ1↑⍵}⍣7 ⍺) × ⌽(8⍴2)⊤⍵}
⍝ Multiplicative inverse, calculated by brute force
Mul2Inv ← {$FF ⊤∧ 1⍳⍨⍵ Mul2¨⍳255}
SBox ← {⊤≠/$63,(1-⍨⍳5) Rot8¨Mul2Inv ⍵}¨1-⍨⍳256
@rhaberkorn
rhaberkorn / tecat.lua
Last active August 29, 2024 13:12
Pretty-print TECO macros
#!/usr/local/bin/lua52
-- Replace all control characters with printable representations as in SciTECO.
-- These characters are printed in reverse using ANSI escape sequences.
-- This is especially useful as the diff textconv filter for Git as in
-- git config --global diff.teco.textconv tecat
local file = #arg > 0 and io.open(arg[1], 'rb') or io.stdin
while true do
local buf = file:read(1024)
if not buf then break end
io.write((buf:gsub("[\00-\08\11\12\14-\31]", function(c)
#! perl
=head1 NAME
52-osc - Implement OSC 52 ; Interact with X11 clipboard
=head1 SYNOPSIS
urxvt -pe 52-osc
@rhaberkorn
rhaberkorn / SciTEStartup.lua
Created October 19, 2024 12:22
Primitive syntax-aware spell checker for the SciTE editor
-- This is a spell checker based on aspell.
-- It only requires the aspell CLI tool to be installed, but perhaps it won't work on
-- Windows.
-- You can just copy this into SciTEStartup.lua.
--
-- TODO: Dictionaries should be configurable per file
-- TODO: Support named styles in aspell.styles.lexer?
--
-- The following should be copied into SciTEUser.properties and adapted:
--[[
@rhaberkorn
rhaberkorn / git-fixup.sh
Created March 14, 2025 18:59
Squash changes into the last commit
#!/bin/sh
# Creates a commit from the given files and automatically
# squashes it into the last commit on HEAD.
set -e
if [ "x`git branch -r --contains HEAD`" != x ]; then
echo "HEAD commit already pushed?"
exit 1
fi
@rhaberkorn
rhaberkorn / timebutler.sh
Created May 16, 2025 21:46
Minimalist Timebutler CLI interface
#!env bash
# ./timebutler start|pause|resume|stop|cancel|status [project]
# You have to set USERID and AUTH variables in ~/.timebutler!
# Run `curl -X POST 'https://timebutler.de/api/v1/users' -d "auth=$AUTH"` to fetch user ids.
set -e
. ~/.timebutler
test -n "$AUTH" -a -n "$USERID"
COMMAND=$1