Skip to content

Instantly share code, notes, and snippets.

View acquitelol's full-sized avatar
🌷
Often the most beautiful experiences are the unexpected ones ‹𝟹

Rosie acquitelol

🌷
Often the most beautiful experiences are the unexpected ones ‹𝟹
  • Meow LTD
  • In your walls
View GitHub Profile
@acquitelol
acquitelol / fractionalIndices.js
Created October 8, 2025 22:46
Proxies arrays allowing for inserting elements by indexing with fractional indices (ie x[0.5] = 1 inserts between 0 and 1)
function arrWithFractionalIndices<T>(arr: T[]) {
return new Proxy(arr, {
get(target, prop: string, receiver) {
if (!isNaN(+prop)) {
return (Reflect.get(target, String(Math.ceil(+prop)), receiver) * (1 - +prop))
+ (Reflect.get(target, String(Math.floor(+prop)), receiver) * +prop);
}
return Reflect.get(target, prop, receiver);
},
@acquitelol
acquitelol / pipe.js
Last active October 8, 2025 23:59
Implements piping in vanilla JS.
// @ts-nocheck
globalThis.rax = null;
// for when you need the return value of the expr
function pipe(_) { return globalThis.rax; };
function _(v) { return +(globalThis.rax = v); }
Object.defineProperty(Function.prototype, Symbol.toPrimitive, {
value: function() {
globalThis.rax = this(globalThis.rax);
@acquitelol
acquitelol / Makefile
Last active November 25, 2025 23:03
A Node V8 module in Elle without an `extern "C"` wrapper. Note: only works on aarch64.
main.node: main.o
cc -shared -fPIC main.o -L$(HOME)/.local/lib -lelle -Wl,-undefined,dynamic_lookup -o main.node
main.o: main.s
echo ".section __DATA,__mod_init_func,mod_init_funcs" >> main.s
echo ".p2align 3" >> main.s
echo ".quad _register_test" >> main.s
cc main.s -c -o main.o
main.s:
@acquitelol
acquitelol / Eval.ts
Last active July 31, 2025 10:59
A mathematical expression evaluator for natural numbers purely in the TypeScript type system
type Succ<T extends number, acc extends number[] = []> = acc['length'] extends T
? [...acc, 0]['length']
: Succ<T, [...acc, 0]>;
type Add<T extends number, U extends number, acc extends number[] = []> = acc['length'] extends U
? T
: Add<Succ<T>, U, [...acc, 0]>;
type Mul<T extends number, U extends number, Res extends number = 0, acc extends number[] = []> = acc['length'] extends U
? Res
@acquitelol
acquitelol / functionalDiv.js
Last active April 22, 2025 01:58
An implementation of division in pure-functional style but in JavaScript
const succ = n => f => x => f (n (f) (x))
const pred = n => f => x => n (g => h => h (g (f))) (u => x) (u => u)
const sub = m => n => n (pred) (m)
// these functions are using js primitives so theyre not pure anyway
// which means i can use js features like binops and ternaries
const churchToJs = n => n (x => x + 1) (0)
const jsToChurch = n => n === 0 ? False : succ (jsToChurch (n - 1))
const True = x => y => x
@acquitelol
acquitelol / fizzBuzz.js
Created April 21, 2025 02:00
Fizzbuzz but in purely functional JavaScript
const pair = a => b => f => f (a) (b)
const head = p => p (a => b => a)
const tail = p => p (a => b => b)
const range = low => high =>
low > high ? null :
pair (low) (range (low + 1) (high))
const map = f => xs =>
xs === null ? null :
@acquitelol
acquitelol / rosieWith.ts
Created April 8, 2025 18:45
A reimplementation of the `with` feature which was recently removed from TypeScript.
function rosieWith<T>(arg: T, callback: Function) {
const descriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(arg));
for (const [key, descriptor] of Object.entries(descriptors)) {
typeof descriptor.value === "function" && ((globalThis as any)[key] = descriptor.value.bind(arg));
}
callback();
for (const [key, descriptor] of Object.entries(descriptors)) {
@acquitelol
acquitelol / useStorageValue.ts
Created April 5, 2025 20:20
A hook which acts exactly like useState but also syncs a value in `localStorage`.
import { useState, useLayoutEffect } from "react";
export const useStorageValue = <T>(
key: string,
def: string | null = null,
replacer: (x: string) => T,
reviver?: (x: T) => string,
) => {
const [value, setValue] = useState<T>(
replacer(localStorage.getItem(key) ?? def!),
@acquitelol
acquitelol / stylesheet.ts
Created April 5, 2025 20:18
An extremely minimal StyleSheet module for use in React-style projects
type StyleSheet = Record<string, React.CSSProperties>;
export const mergeStyles = (...styles: React.CSSProperties[]) => styles.reduce((pre, cur) => ({ ...pre, ...cur }), {});
export const createStyleSheet = <T extends StyleSheet>(sheet: T) => ({
styles: sheet,
merge: (callback: (sheet: T) => React.CSSProperties[]) => mergeStyles(...callback(sheet))
});
export const commonStyles = createStyleSheet({
flex: {
@acquitelol
acquitelol / enu_m.ts
Last active April 4, 2025 15:41
An enum implementation which creates real TypeScript objects with number literals out of an enum string.
type EnumToObject<Keys extends string[], Acc extends string[] = []> =
Keys extends [infer First extends string, ...infer Rest extends string[]]
? { [K in First]: Acc["length"] } & EnumToObject<Rest, [...Acc, First]>
: {};
type Split<T extends string, D extends string, Acc extends string[] = []> =
Trim<T> extends `${infer First}${D}${infer Rest}`
? Split<Trim<Rest>, D, [...Acc, Trim<First>]>
: [...Acc, Trim<T>]