Skip to content

Instantly share code, notes, and snippets.

View chris-kruining's full-sized avatar

Chris Kruining chris-kruining

  • 4DotNet
  • Nederland
View GitHub Profile
@chris-kruining
chris-kruining / my-lib.nix
Last active December 3, 2025 14:17
A quick and dirty implementation of a url parser and switch expression (I run this with `nix eval --json --file ./url.nix | jq .`)
let
inherit (import <nixpkgs> {system = builtins.currentSystem;}) lib;
inherit (lib) isFunction isString isInt isAttrs attrsToList any all isList imap0 length elemAt;
P = {
# Wildcard
_ = {
__type = "pattern";
__kind = "any wildcard";
__functor = _: value: value != null;
@chris-kruining
chris-kruining / binary.ts
Created February 8, 2024 09:08
Zod binary serialization/encoding POC
import { z, ZodDate, ZodNumber, ZodBoolean, ZodString, ZodObject, ZodDiscriminatedUnion, ZodEnum, ZodArray, ZodTypeAny, ZodLiteral } from "zod";
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
export async function serialize<T extends ZodTypeAny>(schema: T, data: z.infer<T>): Promise<ArrayBuffer> {
let accumulation = new Uint8Array();
for await (const k of _serialize(schema, data, '')) {
accumulation = concatTypedArrays(accumulation, k);