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 / 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 = " ▁▂▃▄▅▆▇█"

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]

@izabera
izabera / game.bash
Last active October 24, 2024 21:16
basic bash game loop
#!/bin/bash
# basic bash game loop
shopt -s extglob globasciiranges
gamesetup () {
exitfunc() { :; } # override this if you want something done at exit
trap exitfunc exit
if [[ -t 1 ]]; then
printf '\e[?%s' 1049h 25l
@izabera
izabera / readfile.md
Last active January 6, 2025 17:44
reading a file line by line in your shell

context: shells want to leave the seek position at the right offset so external commands can continue reading from the same fd


i saw this somewhat surprising tally of syscalls in bash. let's investigate

surprise

one iteration:

  • unblock all signals
@izabera
izabera / loop.s
Last active October 19, 2024 01:35
an 8 byte binary that does 1 syscall (exit) and that takes 8 seconds to run on my machine
.globl _start
_start:
dec %ecx # comment this out for a 6 byte binary that takes ~1090 years :)
loop:
loop loop
mov $60, %al
syscall
$ clang++ operator_symbols.cpp -c -std=c++23 -pedantic -Wall -Wextra
$ nm -C operator_symbols.o | grep meow
0000000000000000 T operator"" _meow(char const*)
0000000000000000 W meow::promise_type::final_suspend()
0000000000000000 W meow::promise_type::initial_suspend()
0000000000000000 W meow::promise_type::get_return_object()
0000000000000000 W meow::operator&&(int)
0000000000000000 W meow::operator&()
0000000000000000 W meow::operator&(int)
0000000000000000 W meow::operator&=(int)