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 / 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 / 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. \
@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");
@olsner
olsner / Makefile
Created January 21, 2020 18:23
Setting -jN in Makefile
MAKEFLAGS += -j21
all: test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12 test13 test14 test15 test16 test17 test18 test19 test20 test21
test%:
sleep 1
@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 / marquee.cc
Last active December 14, 2018 21:58
cowsay marqueeeeeeee | lolcat -f | marquee => scrolling lolcow
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <cstdio>
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>
@olsner
olsner / thue_mod_rewrite.sed
Last active October 17, 2018 20:58
Thue->mod_rewrite compiler in sed
1 i\
RewriteEngine on\
RewriteCond /var/www/rewrite%{REQUEST_FILENAME} -f\
RewriteRule ^.*$ - [L]\
RewriteRule ^/([^q].*)$ qq^$1\
RewriteRule ^/(.*)$ $1\
RewriteRule ^(q.*)q(.*)$ $1qr$2
s/^#.*$//
s/\?/Q/g