Skip to content

Instantly share code, notes, and snippets.

View RocketRace's full-sized avatar

Olivia Palmu RocketRace

  • 22:40 (UTC +03:00)
View GitHub Profile
@RocketRace
RocketRace / utf8_grapheme_regex.py
Created January 29, 2024 11:56
This regular expression matches a single extended grapheme cluster (compliant withUAX #29 as of Unicode 15.1) from a sequence of bytes encoded as UTF-8. This can be used with any regex engine capable of matching bytes.
pattern = (
b'(?:\\\r\\\n|\\\r|\\\n)|(?:[\x00-\x08\x0e-\x1f\x7f]|(?:\\\t|\\\x0b|\\\x0c'
b')|\xc2[\x80-\x9f\xad]|\xd8\x9c|\xe1\xa0\x8e|\xe2(?:\x80[\x8b\x8e\x8f\xa8'
b'-\xae]|\x81[\xa0-\xaf])|\xef(?:\xbb\xbf|\xbf[\xb0-\xbb])|\xf0(?:\x93\x90'
b'[\xb0-\xbf]|\x9b\xb2[\xa0-\xa3]|\x9d\x85[\xb3-\xba])|\xf3\xa0(?:\x80['
b'\x80-\x9f]|[\x82\x83\x88-\xbf][\x80-\xbf]|\x87[\xb0-\xbf]))|(?:\xd8[\x80'
b'-\x85]|\xdb\x9d|\xdc\x8f|\xe0(?:\xa2[\x90\x91]|\xa3\xa2|\xb5\x8e)|\xf0'
b'\x91(?:\x82\xbd|\x83\x8d|\x87[\x82\x83]|\xa4\xbf|\xa5\x81|\xa8\xba|\xaa['
b'\x84-\x89]|\xb5\x86|\xbc\x82))*(?:(?:(?:\xe1(?:\x84[\x80-\xbf]|\x85[\x80'
b'-\x9f])|\xea\xa5[\xa0-\xbc])*(?:(?:\xe1(?:\x85[\xa0-\xbf]|\x86[\x80-\xa7'
@RocketRace
RocketRace / elfcpu.py
Created December 15, 2022 22:22
the implementation of an animated elf cpu
import argparse, time
# Instruction format:
# 1xxxxxxx noop
# 0xxxxxxx add xxxxxxx to x register as a 7-bit signed integer
parser = argparse.ArgumentParser()
parser.add_argument('subcommand', choices=['run', 'assemble', 'compile'])
parser.add_argument('input')
parser.add_argument('--out', required=False)
@RocketRace
RocketRace / badapple.elfasm
Created December 10, 2022 17:35
A program to play Bad Apple on the Advent of Code 2022 day 10 machine — Assumes 16 cycles of VBlank between screens
This file has been truncated, but you can view the full file.
addx 1
addx 2
addx 2
addx 2
addx 2
addx 2
addx 2
addx 2
addx 2
addx 2
@RocketRace
RocketRace / advent-of-code-2022.dyalog
Last active December 6, 2022 19:15
Showing off my 2022 Advent of Code submissions written using Dyalog APL. Not all days will necessarily be implemented.
⎕IO ← 0
⍝ Day 1
⍝ Input: a nested vector of numbers
d1p1 ← ⌈/+/¨
d1p2 ← {+/ 3↑ {⍵[⍒⍵]} +/¨⍵}
⍝ Day 2
⍝ Input: a `n 2`-shaped character matrix
d2p1a ← {+/ 1 {⍵ + 1 + 3 × 3 | 1 + ⍵ - ⍺}¨ ⍥ ((⍉ (3∘| 'ABCXYZ'∘⍳)¨ ⍵)∘(↑⍨)) ¯1}
d2p2a ← {+/ 1 {(3 × ⍵) + 1 + 3 | ⍵ + ⍺ - 1}¨ ⍥ ((⍉ (3∘| 'ABCXYZ'∘⍳)¨ ⍵)∘(↑⍨)) ¯1}
⍝ Alternate input: two equal-length character vectors
@RocketRace
RocketRace / minesweeper2.js
Last active July 25, 2023 08:49
Minesweeper 2.0 (written for a "code guessing" competition; poor quality intentional) [run with node]
// Minesweeper 2.0
var readline = require("readline")
var crypto = require("crypto")
var readline = require("readline")
readline.emitKeypressEvents(process.stdin);
var stdin = process.stdin
var stdout = process.stdout
stdin.setRawMode(true);
var width = 35
var height = 15
@RocketRace
RocketRace / pep8.py
Created November 4, 2020 09:28
No context
content = "\n".join([f"**{x.get('name')}** : {', '.join([f'{k}: `{v[0]},{v[1]}`' if isinstance(v, list) else f'{k}: `{v}`' for k, v in sorted(x.items(), key=lambda λ: λ[0]) if k not in ['name', 'tags']])}" if not isinstance(x, str) else x for x in [matches[0]] + sorted(matches[1:], key=lambda λ: (λ[sort_by], λ[secondary_sort_by]), reverse=reverse)[first_result:last_result + 1]])
@RocketRace
RocketRace / bottles.baba
Created July 29, 2020 01:05
"99 bottles of beer on the wall" written in Babalang. Courtesy of FLeckami#3853 (@691193184251805774) on Discord!
// 99 bottles of beer in babalang
//define variables and create some sentences
// string numbers
0_str is you and move and more and move and more and more and more and more
1_str is 0_str and move
2_str is 1_str and move
@RocketRace
RocketRace / fibonacci.baba
Created July 29, 2020 01:00
Calculate Fibonacci numbers in Babalang
===Fibonacci===
// This function prints each digit of the digits of an input's ASCII representation.
// This is optional, but makes the result much tidier.
ord is level and has input
// No magic numbers! Every literal has to be constructed :/
// ASCII strings of each digit
0_str is you and move and more and move and more and more and more and more
1_str is 0_str and move