Skip to content

Instantly share code, notes, and snippets.

View olsner's full-sized avatar

Simon Brenner olsner

View GitHub Profile
@olsner
olsner / giffeltruck.py
Last active March 14, 2024 10:25
giffeltruck v0.3.1
#!/usr/bin/env python3
################################################################################
# KEY MAP #
# #
# q Quit game #
# Arrow keys Turn towards the direction, or if already facing #
# it drive forwards. #
# x Drive backwards given the current direction. Use #
# arrow keys to turn if necessary. #
# u Lift forks, picking up a giffel (@@) if the forks #
@olsner
olsner / nested.c
Created April 17, 2023 17:39
Computed goto and nested functions don't seem to combine very well...
#include <stdio.h>
int bar (int *array, int offset, int size)
{
__label__ failure;
__label__ fail2;
int access (int *array, int index)
{
if (offset + index >= size) {
// This variant crashes GCC (9.4.0-1ubuntu1~20.04.1)
@olsner
olsner / solver.md
Last active February 10, 2023 15:06
Solecistic Versioning

Solecistic Versioning

Some general principles:

  • Guarantees (implied or otherwise) about stability will inevitably be broken, so attempting to stick to something like semantic versioning is just a lie. Acknowledge that you have no intention or ability to ensure compliance with such guidelines, and make this fact obvious (sometimes painfully so) in your versioning scheme.
@olsner
olsner / malloc.c
Created January 11, 2014 15:44
Silly malloc implementation :)
static char heap[1048576];
static char* heap_end;
void init_heap(void) {
printf("init_heap: %x..%x\n", heap, heap + sizeof(heap));
heap_end = heap;
}
#if 0
#define xprintf printf
@olsner
olsner / gol.sed
Created October 16, 2022 09:59
Game of Life in sed
#!/bin/bash
# Experiment with bash/sed polyglot for startup. Ideally this would take a seed
# on stdin though, and then the bootup code is a bit redundant...
set -euo pipefail
echo | sed -rnf <(sed '1,/^# STARTSED/s/^/#/' "$0")
exit # dummy for sed highlighting
# STARTSED
@olsner
olsner / elevator.bash
Last active September 20, 2022 18:13
Make long-running commands slightly less boring with some Muzak
#!/bin/bash
# Usage: source this script, probably in .bashrc
#
# Update paths to bash-preexec.sh and the elevator music track of your choice to finish up
# installation.
# Can be combined with wilhelm.bash (https://gist.github.com/olsner/85cf297adb2dc0ee8efa3ccf9c1ab00b)
# to indicate failure a bit more dramatically.
# from https://github.com/rcaloras/bash-preexec
source ~/homestuff/bash/bash-preexec.sh
@olsner
olsner / synsedizer
Created September 12, 2022 17:15
synsedizer (compact version)
#!/usr/bin/env -S LC_CTYPE=C sed -rnf
# https://github.com/olsner/synsedizer
:loop;s/#.*$//g;s/^\s+//;s/\s+$//;/^r (.*)$/{/ 8000$/s/.*/\x00\x00\x1f@/
/ 16000$/s/.*/\x00\x00\>\x80/;/ 44100$/s/.*/\x00\x00\xacD/
s/^/.snd\x00\x00\x00\x1c\xff\xff\xff\xff\x00\x00\x00\x03/
s/$/\x00\x00\x00\x01\x00\x00\x00\x00\x00/p;beat};/^s (.*)$/{s//S\1/g;H;bleep}
/^([abcde]) (.*)$/{s//W\1,1,0,\2,\2/g;H;beat};/^([ABCDE])$/{s/.*/\L&/;G
s/^(.)\n((.*\n)*)W\1,[^\n]*/\2/;s/^.\n//;h};:eat;z;n;bloop;:leep;
g;s/^\n*/\n/;s/\n*$/\n/;s/\n+/\n/g;s/\nAi*\n/\n/;/\nS/!beat;s/\nS[0-9]+/&-/
s/\nW[^,]*,1,[^\n]+/&-\nAi/g;s/\nW[^,]*,0,[^\n]+/&-\nA-/g;s/^/Aiiiii/;/\nAi/{:ip
@olsner
olsner / potato.sed
Last active September 7, 2022 13:03
The potato RPG (in sed)
#!/usr/bin/sed -rnf
# Based on: https://twitter.com/deathbybadger/status/1567425842526945280
# Unfortunately requires an initial line to get started. Press ENTER to start.
1{
i\
Poh-Tay-Toe \
=========== \
\
You are a halfling, just trying to exist. \
; vim:ts=8:sts=8:sw=8:filetype=nasm:
; This is the real bootstrap of the kernel, and
; it is this part that is loaded by the boot sector (boot.asm)
org 0
bits 16
%macro define_descriptor 6 ; 0-6 0,0,0,0,0,0
dw %1 ;seg_limit
dw %2 ;addr_00_15
@olsner
olsner / syscalls.h
Created July 14, 2020 15:28
syscall/ipc wrappers
static inline int64_t syscall5(uint64_t msg, uint64_t dest, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4) {
register int64_t r8 __asm__("r8") = arg3;
register int64_t r9 __asm__("r9") = arg4;
__asm__ __volatile__ ("syscall"
: /* return value(s) */
"=a" (msg),
/* clobbered inputs */
"=D" (dest), "=S" (arg1), "=d" (arg2), "=r" (r8), "=r" (r9)
: "a" (msg), "D" (dest), "S" (arg1), "d" (arg2), "r" (r8), "r" (r9)
: "r10", "r11", "%rcx", "memory");