Skip to content

Instantly share code, notes, and snippets.

View nberlette's full-sized avatar
😍
Stage 3 decorators, meet Deno 🦖

Nicholas Berlette nberlette

😍
Stage 3 decorators, meet Deno 🦖
View GitHub Profile
@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
*/
@nberlette
nberlette / dbc.wip.pegjs
Created July 11, 2023 05:40
[WIP] DBC Language Grammar
/*!
* DBC Language Grammar, for PEG.js
* ---------------------------------------------------------------------------
* Copyright (c) 2021-2023+ Nicholas Berlette. All rights reserved.
* ---------------------------------------------------------------------------
* More info: [DBC Language Documentation](https://canbus-org.github.io/dbc)
*/
// #region Internal Parser Functions
{
const TYPES_TO_PROPERTY_NAMES = {
@nberlette
nberlette / dbc.pegjs
Last active July 11, 2023 07:09
DBC Language Grammar - PEG.js
/*!
* DBC Language Grammar, for PEG.js
* ---------------------------------------------------------------------------
* Copyright (c) 2021-2023+ Nicholas Berlette. All rights reserved.
* ---------------------------------------------------------------------------
* More info: [DBC Language Documentation](https://canbus-org.github.io/dbc)
*/
// #region Internal Parser Functions
{
const TYPES_TO_PROPERTY_NAMES = {
@nberlette
nberlette / math.ts
Last active June 25, 2023 11:28
TypeScript: type-level arithmetic operations
//
// Type-Level Arithmetic Operations in TypeScript
//
// Implemented by Nicholas Berlette (@nberlette)
// Inspired by the work of many others :)
//
export type ADD<A extends number, B extends number> =
| Internal.ADD<A, B> extends infer R extends number
? [R] extends [never] ? number : R : number;
@nberlette
nberlette / deserialize.ts
Last active July 1, 2023 19:51
🥣 dessert · deserialize and serialize, with type-safety.
import {
assert,
type SerializedValue,
TypedArray,
TypedArrayTypes,
} from "./helpers.ts";
import { StructuredReader, StructuredSyncReader } from "./reader.ts";
const binaryInputTypes = [ArrayBuffer, Uint8Array] as const;
const streamInputTypes = [ReadableStream, ...binaryInputTypes] as const;
@nberlette
nberlette / murmur128.ts
Created June 23, 2023 17:31
[TS] murmur128
/**
* MurmurHash3 128-bit implementation in TypeScript. Supports a custom seed for
* its first parameter. For another variant that assumes a default seed of 0,
* see {@link murmur128} instead.
*
* @param seed The seed to use for this hash.
* @param keys The keys to hash.
* @returns 128-bit hash as a `bigint`.
*
* Based on bryc's JavaScript hash functions:
@nberlette
nberlette / long.ts
Last active June 28, 2023 05:52
Math.long - based on bryc's implementation
declare interface LongStatic {
readonly prototype: Long;
new (low: number, high: number): Long;
fromInt(value: number): Long;
fromBigInt(value: bigint): Long;
fromString(value: string, radix?: number): Long;
fromNumber(value: number): Long;
fromBits(lowBits: number, highBits: number): Long;
@nberlette
nberlette / deno_install.sh
Created June 5, 2023 04:30 — forked from LukeChannings/deno_install.sh
Deno installation script
#!/bin/sh
# A modification of the standard Deno installation script (https://deno.land/install.sh)
# updated to support downloading a Linux arm64 binary from LukeChannings/deno-arm64
set -e
if ! command -v unzip >/dev/null; then
echo "Error: unzip is required to install Deno (see: https://github.com/denoland/deno_install#unzip-is-required)." 1>&2
exit 1
fi