Skip to content

Instantly share code, notes, and snippets.

View porglezomp's full-sized avatar
💖
GITHUB DROP ICE

Cassie Jones porglezomp

💖
GITHUB DROP ICE
View GitHub Profile
@porglezomp
porglezomp / README.md
Last active March 19, 2024 16:00
Serializing Binary Data in Rust

Serializing Binary Data in Rust

The way I like to serialize data in Rust into binary formats is to let a data structure blit itself into a mutable buffer. This is a relatively composable, low level way to work that lends itself to having other abstractions built on top of it. I recently was serializing network packets, so let's make up a small packet format that illustrates how we can do this.

+-------------+-------------+
|  Tag (u16)  | Count (u16) |
+-------------+-------------+
|                           |
~        Entry (u32)        ~
@porglezomp
porglezomp / caption-screenshots.lua
Last active January 25, 2024 00:50
Captioned screenshots for MPV
require "mp"
local msg = require "mp.msg"
local utils = require "mp.utils"
-- Currently, I use webp quality=90
-- In the future: Use jxl quality=80
-- It might be nice to adjust the quality on a show-by-show basis
-- The format_json consults metatables to distinguish between empty arrays and lists
local json_object_metatable = { type = "MAP" }
function json_object(obj)
@porglezomp
porglezomp / Leftpad.idr
Last active October 7, 2023 23:25
Taking on Hillel's challenge to formally verify leftpad (https://twitter.com/Hillelogram/status/987432181889994759)
import Data.Vect
-- `minus` is saturating subtraction, so this works like we want it to
eq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k
eq_max n Z = rewrite minusZeroRight n in rewrite plusZeroRightNeutral n in Refl
eq_max Z (S _) = Refl
eq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in rewrite eq_max n k in Refl
-- The type here says "the result is" padded to (maximum k n), and is padding plus the original
leftPad : (x : a) -> (n : Nat) -> (xs : Vect k a)
@porglezomp
porglezomp / toggle-player-controls.user.js
Last active November 28, 2022 08:59
Toggle the controls on a video player for easier screenshots.
// ==UserScript==
// @name Toggle Video Controls (f1)
// @version 1
// @include https://archive.org/*
// @include https://www.youtube.com/*
// @grant none
// ==/UserScript==
// LICENSE: CC0 1.0
// Comments with support for more video players are encouraged, if you want to help out
@porglezomp
porglezomp / exception.c
Last active May 26, 2022 20:43
Exception handling in C with setjmp and longjmp!
#include <iso646.h>
#include <setjmp.h>
#include <stdio.h>
// Exception Macros
int _exn_handler_idx = 0;
jmp_buf _exn_handlers[1024];
@porglezomp
porglezomp / dracula.py
Last active May 14, 2022 20:28
Tell you what pages of dracula happen on a given day.
#!/usr/bin/env python3
from __future__ import annotations
import abc
import argparse
import datetime
import enum
import re
import sys
@porglezomp
porglezomp / twitter-alt-to-title.user.js
Last active March 16, 2022 15:43
Copy the alt text in tweets into the title text, so that you can see it on hover.
// ==UserScript==
// @name Twitter Alt-Text to Title-Text
// @description Copy the alt attribute of twitter images into the title attribute, so that I can see the alt text on hover.
// @version 1
// @grant none
// @include https://twitter.com/*
// ==/UserScript==
const SELECTORS = `.tweet .AdaptiveMedia-photoContainer img
, .Gallery-media img
@porglezomp
porglezomp / README.md
Last active March 3, 2022 09:26
Creating a Rust hello world in 0x a presses.

This is a Rust "Hello World" program in 0x A presses.

$ vim hello.rs
$ rustc --test hello.rs
$ ./hello --quiet
Hello, World!

If you don't know, [the A Button Challenge] is a Mario 64 speedrun category in which runners attempt to use the A button (the jump button!) as few times as possible. Make sure you watch the classic [Watch for Rolling Rocks - 0.5x A Presses][A Button Challenge] video linked above in order to understand.

@porglezomp
porglezomp / twitter-pinned-lists.user.js
Last active November 15, 2021 02:46
Show your pinned lists in your twitter top bar.
// ==UserScript==
// @name Twitter Pinned Lists
// @description Show your pinned lists in your twitter top bar.
// @version 1.1
// @grant none
// @include https://twitter.com/*
// @include https://mobile.twitter.com/*
// ==/UserScript==
// USAGE: Visit your lists page for a few seconds, and this will learn your pinned lists.
// ==UserScript==
// @name Animal Crossing Twitter Rating
// @description Display the rating of tweets using the Animal Crossing letter rating system
// @version 1
// @grant none
// @include https://twitter.com/*
// ==/UserScript==
// Notes via https://twitter.com/jamchamb_/status/1025977659522789376