Skip to content

Instantly share code, notes, and snippets.

View nberlette's full-sized avatar
🧱
rusting away

Nick Berlette nberlette

🧱
rusting away
View GitHub Profile
@nberlette
nberlette / basic.ts
Last active March 14, 2025 21:12
typescript runtime type validation
// deno-lint-ignore-file no-explicit-any no-namespace
import { inspect, type InspectOptions } from "node:util";
// #region Validation Types
export type Err<T = never> = {
success: false;
error: string | ValidationError<T>;
};
@nberlette
nberlette / ease.ts
Created March 14, 2025 09:16
TypeScript Easing / Tween API
export interface EasingMethods {
in(t: number): number;
out(t: number): number;
inOut(t: number): number;
}
interface EasingDef<K extends string = string> extends EasingMethods {
readonly name: K;
}
@nberlette
nberlette / atob_btoa.wat
Created March 14, 2025 09:14
WebAssembly (WAT) implementation of atob / btoa
(module
;; Memory: 1 page = 64 KiB
(memory $memory 1)
;; Exported error flag (0 = no error, 1 = error)
(global $error_flag (mut i32) (i32.const 0))
;; Base64 encoding table
(data (i32.const 0) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
@nberlette
nberlette / option.ts
Created March 14, 2025 09:10
Option<T>
const _tag: unique symbol = Symbol("Option.#tag");
type _tag = typeof _tag;
export interface Some<T> extends Option<T> {
readonly [_tag]: "Some";
readonly value: T;
}
export interface None extends Option<never> {
@nberlette
nberlette / LICENSE
Last active June 24, 2025 00:27
Virtual File System API (mostly compatible with `node:fs`)
The MIT License (MIT)
Copyright (c) 2025+ Nicholas Berlette (https://github.com/nberlette)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@nberlette
nberlette / ansi_reference.md
Last active September 29, 2025 07:09
ANSI Escape Sequences Reference (VT100 et al)
@nberlette
nberlette / LICENSE
Last active March 18, 2025 21:16
Advanced Unicode Table Rendering
The MIT License (MIT)
Copyright (c) 2024-2025 Nicholas Berlette. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@nberlette
nberlette / workers_ai_playground_prompts.md
Created March 4, 2025 10:59
Workers AI Playground Prompts

Deno Code Generator

System Prompt

You are a friendly expert software engineer. If the user requests you generate code, assume 
they want it written in TypeScript for Deno, and follow these rules to the letter: The code
should avoid using any external dependencies, unless absolutely necessary or specifically
@nberlette
nberlette / index.html
Last active December 6, 2024 00:15
Window Mangement Web Component Library
<div class="editor">
<n-window id="window1" class="window">
<n-view slot="views">
<n-tab slot="tabs" part="primary">Explorer</n-tab>
<n-tab slot="tabs" part="primary">Search</n-tab>
<n-tab slot="tabs" part="primary">Extensions</n-tab>
<div slot="content" name="panel-0">
<n-view>
<n-tab slot="tabs" active>File 1</n-tab>
@nberlette
nberlette / impl_wrapper_with_trait.rs
Last active November 13, 2024 00:35
[rust macro] impl_wrapper_with_trait
#[macro_export]
macro_rules! impl_wrapper_with_trait {
// Match multiple wrapper types with external type and default implementation (no custom tt)
(
$(
$(#[$meta:meta])*
$(unsafe)? $($vis:vis,? )? $wrapper:ident$(<$($lifetime:lifetime),+>)?$( : $ty:ty)? => $path:path $(,)? $({
$($body:block)+
})? $(,)?
$(,)?)+