Skip to content

Instantly share code, notes, and snippets.

View reececomo's full-sized avatar
🍊
Working on something cool

Reece Como reececomo

🍊
Working on something cool
View GitHub Profile
@reececomo
reececomo / bfloat16.d.ts
Created April 15, 2025 10:17
BFloat16s in TypeScript
This file has been truncated, but you can view the full file.
export type brain = bfloat16;
export type bf16 = bfloat16;
export type bf16 = bfloat16;
export type bfloat16 =
| -Infinity | -3.3895313892515355e+38 | -3.3762391092936863e+38 | -3.362946829335837e+38 | -3.349654549377988e+38 | -3.336362269420139e+38 | -3.3230699894622897e+38 | -3.3097777095044405e+38 | -3.2964854295465914e+38 | -3.2831931495887422e+38 | -3.269900869630893e+38 | -3.256608589673044e+38 | -3.2433163097151947e+38 | -3.2300240297573456e+38 | -3.2167317497994964e+38 | -3.2034394698416473e+38
| -3.190147189883798e+38 | -3.176854909925949e+38 | -3.1635626299680998e+38 | -3.1502703500102506e+38 | -3.1369780700524015e+38 | -3.1236857900945523e+38 | -3.110393510136703e+38 | -3.097101230178854e+38 | -3.083808950221005e+38 | -3.0705166702631557e+38 | -3.0572243903053065e+38 | -3.0439321103474573e+38 | -3.0306398303896082e+38 | -3.017347550431759e+38 | -3.00405527047391e+38 | -2.9907629905160607e+38
| -2.9774707105582116e+38 | -2.964178430
@reececomo
reececomo / float16.d.ts
Created April 15, 2025 10:13
Float 16s in TypeScript
This file has been truncated, but you can view the full file.
export type f16 = float16;
export type half = float16;
export type float16 =
| -Infinity | -65504 | -65472 | -65440 | -65408 | -65376 | -65344 | -65312 | -65280 | -65248 | -65216 | -65184 | -65152 | -65120 | -65088 | -65056
| -65024 | -64992 | -64960 | -64928 | -64896 | -64864 | -64832 | -64800 | -64768 | -64736 | -64704 | -64672 | -64640 | -64608 | -64576 | -64544
| -64512 | -64480 | -64448 | -64416 | -64384 | -64352 | -64320 | -64288 | -64256 | -64224 | -64192 | -64160 | -64128 | -64096 | -64064 | -64032
| -64000 | -63968 | -63936 | -63904 | -63872 | -63840 | -63808 | -63776 | -63744 | -63712 | -63680 | -63648 | -63616 | -63584 | -63552 | -63520
| -63488 | -63456 | -63424 | -63392 | -63360 | -63328 | -63296 | -63264 | -63232 | -63200 | -63168 | -63136 | -63104 | -63072 | -63040 | -63008
| -62976 | -62944 | -62912 | -62880 | -62848 | -6281
@reececomo
reececomo / bitmask-enums.js
Last active April 10, 2025 08:22
ESLint rule for consistent bit masks (as inlineable const enums)
/**
bitmask-enums.js
Custom rule for eslint-plugin-rulesdir
@see https://www.npmjs.com/package/eslint-plugin-rulesdir
Treats any enum with "mask" or "flag" in the name as a bit mask.
Converts to an inlineable const enum.
@reececomo
reececomo / logWebAudioStats.js
Last active August 2, 2025 15:04
Get the uncompressed size of WebAudio
async function logWebAudioStats( url )
{
const response = await fetch(url);
const responseBytes = await response.arrayBuffer();
// decode audio
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const audioBuffer = await audioContext.decodeAudioData(responseBytes);
// get statistics
checkout_new_branch() {
local adjectives=(
ancientest boldest bravest brightest calmest cleverest coldest coolest craziest darkest
dustiest eagrest fanciest fastest fiercest flattest freshest funniest gentlest giantest
grandest greenest grimmest happiest harshest heaviest hottest iciest jolliest kindest largest
laziest lightest littlest loneliest loudest luckiest magicalest mightiest modernest narrowest
newest noblest oldest orangest palest perfectest pinkest plainest poorest proudest quickest
quietest rapidest rarest richest roundest roughest saddest sharpest shiniest shortest shyest
silentest simplest sleekest slowest smallest smartest smoothest softest solidest sourest
@reececomo
reececomo / pluck.sh
Created November 11, 2024 09:01
zsh command to replace a file with the one from the default branch (or some other branch)
pluck() {
INFO="Description: Replace a single file's contents with the value from remote branch"
local filename branch matches file_choice
filename=$1
pluckbranch=${2:-origin/$(git symbolic-ref refs/remotes/origin/HEAD | sed 's|^refs/remotes/origin/||' 2> /dev/null)}
currentbranch=$(git branch --show-current 2> /dev/null)
# Define color codes
RED='\033[31m'
@reececomo
reececomo / git-force.sh
Last active November 8, 2024 01:32
protect git push -f
git() {
WARN='\033[0;33m'
RESET='\033[0m'
if [[ "$1" == "push" && "$2" == "-f" ]]; then # idiot safety net
echo -e "${WARN}note: running with --force-with-lease. run with \"--force\" to override.${RESET}"
command git push --force-with-lease "${@:3}"
else
command git "$@"
fi
@reececomo
reececomo / .zshrc
Last active November 5, 2024 03:01
zsh git aliases/functions: fin, rebase
alias reload="source ~/.zshrc"
alias editzsh="code ~/.zshrc"
alias editbash="code ~/.zshrc" # legacy
# git:
branch() {
git branch --show-current 2> /dev/null
}
defaultbranch() {
@reececomo
reececomo / example.ts
Created November 3, 2024 02:34
file uploads with r2
// ----- 2. -----
// (scroll down for 1.)
import { z } from "zod";
import { UploadConfig, uploadFile } from "@/utils/upload-client";
import { uploadsTable } from "@/server/db/schema";
import { userProcedure } from "@/server/api/procedures";
import { db } from "@/server/db";
@reececomo
reececomo / utility-types.ts
Last active September 25, 2024 02:37
AllowExcess<T>, InexactOptionals<T>, Untrusted<T>, etc.
/* eslint-disable @typescript-eslint/ban-types */
/**
* Allow object literals to include additional unchecked properties.
* @see https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks
*/
// prettier-ignore
export type AllowExcess<T> = T extends object
? T extends Array<infer U> ? AllowExcess<U>[]
: {[K in keyof T]: AllowExcess<T[K]>} & {[key: string]: unknown}