Skip to content

Instantly share code, notes, and snippets.

View izabera's full-sized avatar

Isabella Bosia izabera

  • DDN
  • Flitwick, UK
View GitHub Profile

asking gemini to write some cube code

i'm writing another lil cube thing. if you've ever written a rubik's cube simulator/solver, you will know that some parts can be more akin to data than to code. one way or another, you always end up with lots and lots of tables to select the right pieces and move them to the right places. if good code reads like poetry and bad code reads like a phonebook, this is always easily in the top 10 most mind-numbingly boring programs of all time.

@izabera
izabera / magic_namerefs.md
Last active July 8, 2025 15:10
magic namerefs

namerefs (introduced in bash 4.0) act as aliases for other variables

var=meow
declare -n ref=var

echo $ref  # prints meow

ref=moo
echo $var  # prints moo
@izabera
izabera / check.awk
Last active July 8, 2025 11:06
floatcomplex nerd sniped me into testing how many sigwinches i can get per second via terminal resizes
1
/sent/ { stot += sent[s++] = $2 }
/recv/ { rtot += recv[r++] = $2 }
END {
if (r != s)
printf "error: s=%d r=%d\n", s, r
for (i in sent)
if (sent[i] < recv[i])
printf "error: sent[%d]=%d recv[%d]=%d\n", i, sent[i], i, recv[i]
printf "sent=%'d avg=%'d\n", stot, stot/s
#!/bin/bash
usage () {
cat << 'eof'
bgcmd manages a long running, interactive command in background
usage:
bgcmd START command [args...] # starts a command in background
@izabera
izabera / try-catch.sh
Last active June 28, 2025 09:44
silly try/catch
# try catch for bash/mksh/zsh/dash/busybox
[ "$BASH_VERSION" ] && shopt -s expand_aliases
alias try='tryblock ()'
alias throw='return'
alias catch='if tryblock; then :; else '
alias end_try='fi'
alias exceptions:='case $? in x) '
alias except=';;'
alias end_exceptions='esac'
alias always=' '
@izabera
izabera / recursive_exp.md
Last active June 9, 2025 21:26
recursive expansions

for the latest chapter of what's becoming a blog on the most cursed bash you can imagine, let's do some maths together

euclid's algorithm for gcd could be written like this in python:

>>> def gcd(a, b):
...     if b:
...         return gcd(b, a%b)
... return a

you know ${var?error message here} in sh? it produces an error and prints the message if $var is undefined. otherwise it expands to $var

introducing: ${var+${error message here}}

if $var is defined, the spaces in the error message cause a syntax error, which prints the message. otherwise it expands to nothing

(and similarly for all other outer expansions)

it reliably[^reliable] works[^works] perfectly[^dashzsh] in every[^shells] posix sh[^ext]

A funky shell thingy that I've never seen before

So you're in posix sh and you want to do the equivalent of this in bash:

foo | tee >(bar) >(baz) >/dev/null

(Suppose that bar and baz don't produce output. Add redirections where needed if that's not the case.)

@izabera
izabera / posixlist.c
Created May 4, 2025 00:50
minimal list of all posix function prototypes, forwarding everything (mostly correctly) and with zero includes
#if 0
#define _XOPEN_SOURCE 700
#include <aio.h>
#include <arpa/inet.h>
#include <assert.h>
#include <_Complex.h>
#include <ctype.h>
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
@izabera
izabera / 0.README.md
Last active April 22, 2025 10:11
tput codes

This is the table from man 5 terminfo.

Do NOT hardcode terminal escape sequences. Use tput with the cap-names from the table below to get the right code for your terminal.

(P) indicates that padding may be specified