Skip to content

Instantly share code, notes, and snippets.

@44100hertz
44100hertz / immutable.lua
Last active June 9, 2025 18:37
Immutable table library for Lua5.1 / LuaJIT
--------------- pairs/ipairs polyfill
-- modified from:
-- https://gist.github.com/creationix/b56de2dde4021673f24242258efdcc80
do
local function mm_exists(name, trig)
local triggered = false
trig(setmetatable({}, {[name] = function () triggered = true end}))
return triggered
@44100hertz
44100hertz / fiveRules.md
Last active May 31, 2025 05:53
Five Practices for Clean Lua

Five Practices for Clean Lua

Having written tens of thousands of lines of Lua as well as several other langs, I have created guidelines for readable, maintainable, and even portable code.

I'm striving for a sanity that is very rare in the field of programming, that of simplicity. If you're using Lua on purpose, that should be appealing. Even if you're not using Lua, these ideas translate to Javascript and on some level any other language. In fact, following this paradigm makes your code more portable to C, to Rust, and to purely functional languages.

Even if it is not easy to adapt to this paradigm, by using it many headaches disappear. Good code is a narrow path. I can guide you to that path, but you must still walk it.

This article is inspired in part by this Gleam blog post, All you need is data and functions.

@44100hertz
44100hertz / most_tactile.csv
Last active November 16, 2024 22:06
List of most tactile switches from database
Name Depth First half work (gfmm) Second half work (gfmm) Difference
Clickiez 40g Tactile deep 155.694 75.6585 80.0355
Clickiez 40g Tactile 3 medium 121.874 56.3675 65.5065
Clickiez 40g Tactile 2 medium 122.076 59.1035 62.9725
Clickiez 75g Tactile 2 medium 146.176 86.085 60.091
Clickiez 75g Tactile 3 deep 167.4465 107.4575 59.989
Clickiez 75g Tactile deep 169.1445 109.454 59.6905
Clickiez 40g Clicky 3 medium 91.5005 52.5485 38.952
Clickiez 40g Clicky 2 medium 84.8565 48.4355 36.421
Clickiez 75g Clicky 2 medium 119.916 84.3455 35.5705
@44100hertz
44100hertz / most_tactile.lua
Last active November 16, 2024 21:19
Find the most tactile switch within the database at https://github.com/ThereminGoat/force-curves
local basedir = "/tmp/analyze-forces/"
os.execute("mkdir -p " .. basedir)
local function list_dir(path)
local date = os.date()
local listing_path = basedir .. date .. ".txt"
os.execute(string.format('ls "%s" > "%s"', path, listing_path))
local out = {}
for line in io.lines(listing_path) do
out[#out + 1] = line
@44100hertz
44100hertz / parserModify.md
Created February 11, 2024 19:24
Modifying Parsers to work with structure editors

General

Conventional parsers must be modified to create an effective structure editor.

Most parsers create an AST (abstract syntax tree), but structure parsers create a CST (concrete syntax tree). This is because the parser must take note of things that affect the code appearance and not just the code output.

The parser should provide error feedback, but should NEVER give up when creating structure. Instead, it should use sane fallbacks as to always create an editable CST, within reason. Every CST should correspond almost 1:1 with corresponding code, whether that code is valid or invalid.

@44100hertz
44100hertz / Linear-GammaCorrect.glslp
Created November 10, 2023 22:17
Linear Gamma Correct Retroarch Shader
shaders = "2"
feedback_pass = "0"
shader0 = "shaders_glsl/linear/linearize.glsl"
filter_linear0 = "true"
wrap_mode0 = "clamp_to_border"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "false"
scale_type_x0 = "source"
@44100hertz
44100hertz / fir.ts
Created September 4, 2022 04:13
hand-rolled FIR sinc filter
const WINDOW_SIZE = 4; /* Determines how much of normalized sinc function is sampled
1 = Just the center spike (-Pi/2 thru Pi/2)
*/
const SAMPLE_POINTS = 63; // Determines quality of output
const MIN_FREQ = 20; // Determines buffer length
const MAX_FREQ = 20000; // Determines shutoff frequency
const coefficients = Array(SAMPLE_POINTS).fill(0).map((_,i) => {
const thru = i / (SAMPLE_POINTS-1);
const pos = thru * WINDOW_SIZE - WINDOW_SIZE / 2.0;
@44100hertz
44100hertz / shortNum.js
Created August 9, 2022 10:47
Number shortener
function shortNumber (num, desiredDigits) {
if (num < 0) {
// Negative
return '-' + shortNumber(-num, desiredDigits-1);
} else if (num === 0) {
// Zero is problematic
return '0';
}
function standardNotation (num, desiredDigits) {
scanr_rec :: (a -> b -> b) -> b -> [a] -> [b]
scanr_rec _ acc [] = [acc]
scanr_rec f acc (x:xs) = let next = scanr_rec f acc xs in f x (head next) : next
scanr_fold :: (a -> b -> b) -> b -> [a] -> [b]
scanr_fold f acc = foldr scanFold [acc]
where
scanFold x acc = f x (head acc) : acc
scanl_rec :: (b -> a -> b) -> b -> [a] -> [b]
@44100hertz
44100hertz / phoneticspell.lua
Created March 11, 2022 06:09
Takes espeak output, makes it into sort-of-readable phonetic language inspired by Sayspel
local input =
[==[
Put Your input text here.
]==]
local phonemes = {}
do
local h = io.popen('espeak -w /dev/null -x "' .. input .. '"')
phonemes = h:read('*a')
h:close()