Skip to content

Instantly share code, notes, and snippets.

View izabera's full-sized avatar

Isabella Bosia izabera

  • DDN
  • Flitwick, UK
View GitHub Profile
@izabera
izabera / recursive_exp.md
Last active January 7, 2025 11:20
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
{n=$1;r=n":";for(p=2;p*p<=n;p++)while(n%p==0){r=r" "p;n/=p}$1=n>1?r" "n:r}1
@izabera
izabera / query
Last active January 2, 2025 12:06
query certain useful terminal attributes
#!/bin/bash
printf %b%.b \
'\e7' 'save cursor position' \
'\e[9999;9999H' 'move to bottom right' \
'\e[6n' 'get cursor position' \
'\e8' 'restore cursor' \
'\e[?u' 'kitty kbd proto' \
'\e[?2026$p' 'synchronised output' \
'\e[m' 'reset colours' \
@izabera
izabera / array
Last active December 15, 2024 08:18
bash arrays
#!/bin/bash
a=({1..1000000})
TIMEFORMAT=%R
for mult in {1..100}; do
printf "%s " "$mult"
RANDOM=0
time for i in {1..100000}; do
: "${a[RANDOM*mult/10]}"
done
@izabera
izabera / maths
Last active December 10, 2024 16:02
#!/bin/bash
# max multiple of pi so our maths always fits in a signed 64 bit int
pi=314159
scale=100000
# bhaskara's formula
# https://en.wikipedia.org/wiki/Bh%C4%81skara_I's_sine_approximation_formula
@izabera
izabera / build.dumb
Created December 4, 2024 08:29
dumb "build system" in 10 lines of posix sh
#!/usr/bin/env dumb
input fentry.cpp count.hpp
output fentry.o
cmd clang++ -std=c++17 -ggdb3 -fPIC -mgeneral-regs-only -c fentry.cpp
input count.cpp count.hpp
output count.o
cmd clang++ -std=c++17 -ggdb3 -fPIC -c count.cpp
#!/usr/bin/env dumb
in: fentry.cpp
out: fentry.o
cmd: clang++ -std=c++23 -ggdb3 -fPIC -mgeneral-regs-only -c fentry.cpp
in: count.cpp
out: count.o
cmd: clang++ -std=c++23 -ggdb3 -fPIC -c count.cpp
@izabera
izabera / findcode.awk
Created November 30, 2024 11:07
easy way to be horrified by what's currently running on your system
#!/usr/bin/gawk -E
# prints a sorted list of all the current processes
# sorted by the number of executable bytes in their address space
BEGIN {
"echo /proc/[0-9]*/maps" | getline
ARGC = split($0, ARGV)
}
BEGINFILE {
@izabera
izabera / m2g.py
Last active November 23, 2024 10:34
a basic alternative to make2graph, significantly less painful to read
#!/usr/bin/env python3
# a basic alternative to make2graph, significantly less painful to read
import re
import sys
class Node:
def __init__(self, target):
self.target = target
import collections
import itertools
import signal
import os
import time
import errno
blocks = " ▁▂▃▄▅▆▇█"