Skip to content

Instantly share code, notes, and snippets.

View nberlette's full-sized avatar
🧱
make, break, patch, repeat ad infinitum

Nicholas Berlette nberlette

🧱
make, break, patch, repeat ad infinitum
View GitHub Profile
@nberlette
nberlette / dom.ts
Last active November 27, 2023 00:28
`DUM`: like a DOM implementation for Deno... but dumber.
/// <reference no-default-lib="true" />
// deno-lint-ignore-file no-unused-vars no-explicit-any
import {
inspect,
type InspectOptions,
type InspectOptionsStylized,
// highlight,
indexOf,
pop,
@nberlette
nberlette / list-all.ts
Last active April 13, 2025 03:56
Deno KV: list / search / sort huge batches of entries in database
export interface ListAllOptions<T> extends Deno.KvListOptions {
comparer?(a: Deno.KvEntry<T>, b: Deno.KvEntry<T>): number;
}
export interface ListEntry<T> extends Deno.KvEntry<T> {
readonly cursor: string;
}
export async function listAll<T>(
kv: Deno.Kv,
@nberlette
nberlette / .gitignore
Last active March 5, 2025 23:25
`PLimit`: TypeScript re-imagining of p-limit and yocto-queue. Friendly with Deno, Bun, and Node.
dist
node_module
*.env*
*.log
.*.log
*.lock*
*-lock.*
.DS_Store
Thumbs.db
.SpotlightV100
@nberlette
nberlette / outdent.ts
Last active February 2, 2024 09:48
`Outdent`: remove common indentation in TypeScript (on type-level and value-level)
// Copyright (c) 2024+ Nicholas Berlette (https://github.com/nberlette)
// Published under the MIT license. All rights reserved.
/**
* Removes common leading whitespace from each line in {@linkcode S}.
* This is the type-level counterpart to the {@linkcode outdent} function.
*
* @example
* ```ts
* type S = Outdent<`
@nberlette
nberlette / README.md
Last active October 31, 2023 05:20
[TS] DisposableStack + AsyncDisposableStack Implementation (explicit resource management)

Explicit Resource Management Polyfill

This is a bare-bones implementation of the interfaces AsyncDisposableStack and DisposableStack from the [Explicit Resource Management Proposal].

Usage

Note: see the examples below for more detailed usage examples.

DisposableStack and Disposable

@nberlette
nberlette / parser.mjs
Last active October 27, 2023 04:38
Peggy.js XML Grammar
// deno-lint-ignore-file
// Generated by Peggy 3.0.2.
// https://peggyjs.org/
export default (function () {
"use strict";
function add(obj, props) {
for (const [k, v] of Object.entries(props)) if (v) obj[k] = v;
return obj;
}
@nberlette
nberlette / README.md
Last active October 6, 2023 23:20
Using SVG <foreignObject /> to render an HTML document as an image

HTML documents inside SVG with <foreignObject />

HTMLImageElement

SVG foreignObject + HTML

HTMLObjectElement

<object type="image/svg+xml;charset=utf-8"

@nberlette
nberlette / examples.ts
Last active January 4, 2024 01:44
`tpl`: replace template string tokens (on type-level and value-level)
import { tpl } from "./tpl.ts";
// Examples:
// -----------------------------------------------------------------------------
// unfortunately, we can't infer string literal types from template strings.
// this is a design limitation of TypeScript, and the core team has no plans to
// change this behavior as it currently stands :(
const result1 = tpl`Hello {who}! Want to {what:party}?${{ who: "nberlette" }}`;
// runtime result: "Hello nberlette! Want to party?"
@nberlette
nberlette / RenewExpiredGPGkey.md
Created September 29, 2023 18:23 — forked from TheSherlockHomie/RenewExpiredGPGkey.md
Updating expired GPG keys and backing them up 🔑🔐💻

Updating expired GPG keys and their backup 🔑🔐💻

I use a GPG key to sign my git commits.

An error like this one might be a sign of an expired GPG key.

error: gpg failed to sign the data fatal: failed to write commit object
@nberlette
nberlette / index.html
Last active August 22, 2023 20:36
VIN Decoder App
<div id="app" class="wrapper !opacity-100">
<noscript>Please enable JavaScript to use this app.</noscript>
</div>
<script>
/**
* Unocss Runtime DOM options
* @see https://unocss.dev/integrations/runtime
* @see https://github.com/unocss/unocss/tree/main/packages/runtime#readme
*/