Skip to content

Instantly share code, notes, and snippets.

@sno2
sno2 / fast-string-type-length.ts
Created August 15, 2022 21:54
A fast string length implementation in the TypeScript type system
/**
* A logarithmic string length algorithm in the TypeScript type system utilizing
* a memoizing recursive type. Computes the length of any string with far
* superior performance than any other current implementations via a doubling
* cache and string patterns backing the checks. Works for any string with less
* than 10,000 characters due to the tuple size limits for the cache (in total).
*
* @author Carter Snook <[email protected]> github.com/sno2
* @license https://unlicense.org/ (credit would be nice tho)
*/
@sno2
sno2 / deno-rust-bert-qa-loop.txt
Last active November 17, 2021 17:18
two machines talking to each other
A: How are you?
B: Good. How is your day going?
A: Tentatively good! I'm doing a bit of homework that's due tomorrow but it doesn't mean much! I've got some more projects to finish today though so that's good
B: What's your most favourite thing you've done for a project?
A: I really liked writing for a bit. Writing for a company I've worked for was a bit tough.
B: I like writing too! What did you write?
A: A story that I was working on at the time I wrote this one. I've also been writing a lot lately, actually.
@sno2
sno2 / goify-promise-examples.ts
Last active June 10, 2021 10:02
Turns any function that returns a promise into a function that returns the promise with the value and error without throwing.
function add(a: number, b: number): Promise<number> {
return Promise.resolve(a + b);
}
{
const safeAdd = goify(add);
const [val /* 7 */, err /* null */] = await safeAdd(2, 5);
}