Skip to content

Instantly share code, notes, and snippets.

View rhaberkorn's full-sized avatar
💾

Robin Haberkorn rhaberkorn

💾
View GitHub Profile
@rhaberkorn
rhaberkorn / tecat.lua
Last active January 28, 2024 14:26
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)
@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 / git-rename-tag.sh
Created January 31, 2019 17:54
Rename an existing remote and local tag at the same time
#!/bin/bash
# git-rename-tag <old-name> <new-name>
# NOTE: This works on the "origin" remote and preserves
# annotations.
set -e
# Creates a new tag on the remote AND removes the old tag
git push origin refs/tags/$1:refs/tags/$2 :refs/tags/$1
# Remove the old local tag
git tag -d $1
@rhaberkorn
rhaberkorn / git-move-tag.sh
Created January 31, 2019 17:52
Rewrite Git tag to new commit, preserving annotations
#!/bin/bash
# git-move-tag <tag-name> <target>
tagName=$1
# Support passing branch/tag names (not just full commit hashes)
newTarget=$(git rev-parse $2^{commit})
git cat-file -p refs/tags/$tagName |
sed "1 s/^object .*$/object $newTarget/g" |
git hash-object -w --stdin -t tag |
@rhaberkorn
rhaberkorn / git-checkout-clean.sh
Last active January 31, 2019 17:50
Checkout a Git tag/branch reinitializing all submodules (needs to be registered as an alias)
#!/bin/sh
# This script performs a checkout with same arguments as `git checkout`
# but makes sure that submodules are initialized in exactly the way
# described in the branch/tag.
# This is useful to avoid having to cleanup the tree after checkout
# to prevent files interfering with Eclispe and updating submodules
# manually.
#
# NOTE: This does not prevent other untracked files from intefering
# with Eclipse.
@rhaberkorn
rhaberkorn / metraLine.sh
Created January 13, 2016 16:36
metraLine: A minimal UNIX terminal interface to metraTec devices
#!/bin/sh
# Requirements: socat, rlwrap
# To connect using a FTDI serial device node
# (requires the `ftdi_sio` driver or a native COM/UART port), e.g.: metraLine /dev/ttyUSB0
# To connect to a product with builtin ethernet via TCP, e.g.: metraLine 192.168.2.239
if [ -c $1 ]; then
# Assume $1 to be a serial device node
ADDRESS=FILE:$1,nonblock,raw,echo=0,b115200,cs8
else
@rhaberkorn
rhaberkorn / gtimelog-stats.lua
Last active July 8, 2022 15:43
Small helper script parsing gtimelog's timelog.txt to summarize the time spent on specific tasks. It takes a SNOBOL4/Lua pattern and optional start date and prints the sum of all timelog entries after the start date matching the pattern.Requires CSNOBOL4 or Lua 5.2
#!/usr/bin/lua5.2
local function parse_date(str)
local t = {hour = 0, min = 0}
t.day, t.month, t.year = str:match("^(%d+)%.(%d+)%.(%d+)$")
return os.time(t)
end
local pattern = arg[1] or ""
local time_begin = arg[2] and parse_date(arg[2]) or 0
@rhaberkorn
rhaberkorn / theco.rex
Created November 22, 2012 23:56
Abandoned (Video)TECO implementation on top of The Hessling Editor, written in Open Object Rexx
#!/usr/local/bin/nthe -p
if .environment~theco.initialized \= .nil then return
/*
* Initialize classic Rexx function packages
*/
call ReLoadFuncs
/*
@rhaberkorn
rhaberkorn / rearrange.for
Created December 30, 2010 04:33
'shuffle' wave files (quick Open Watcom FORTRAN hack)
* Rearranges patches of a wave-file (shuffles them like a card deck)
program REARRANGE
include 'fsublib.fi'
@rhaberkorn
rhaberkorn / gist:759458
Created December 30, 2010 04:29
ye olde FORTRAN 77 obfu (99 bottles of beer)
C This one is almost an obfu, but valid FORTRAN 77
C Demonstrated features: character format identifiers, arrays as
C internal files, implied-DO-loops, importance of the blank character,
C rules for continuation lines, substrings, implicit type declaration...
565760C H ARA C T ERM S G ( 4 ) * 1 3 7