This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>] | |
NewerOlder