Skip to content

Instantly share code, notes, and snippets.

@jaens
jaens / zod-strict.ts
Last active October 7, 2024 10:41
Zod deep strict and map utility
import { z, type ZodDiscriminatedUnionOption } from "zod";
const RESOLVING = Symbol("mapOnSchema/resolving");
export function mapOnSchema<T extends z.ZodTypeAny, TResult extends z.ZodTypeAny>(
schema: T,
fn: (schema: z.ZodTypeAny) => TResult,
): TResult;
export function mapOnSchema(schema: z.ZodTypeAny, fn: (schema: z.ZodTypeAny) => z.ZodTypeAny): z.ZodTypeAny {
@jaens
jaens / storyBookRouter.tsx
Created February 18, 2024 00:01
Storybook fake Tanstack router
/* eslint-disable react-refresh/only-export-components */
import {
createMemoryHistory,
createRootRoute,
createRoute,
createRouter,
useRouterState,
type NotFoundRouteProps,
} from "@tanstack/react-router";
import { createContext, useContext, type ReactNode } from "react";
{
"log": {
"version": "1.2",
"creator": {
"name": "Firefox",
"version": "117.0"
},
"browser": {
"name": "Firefox",
"version": "117.0"
@jaens
jaens / parser.ts
Last active January 10, 2021 16:41
Quick example of an LL(1) incremental parser in TypeScript
type RuleName = string;
type TokenName = string;
type Ast = { type: string; args: Ast[] };
// Stack frame for executing grammar rules
type Frame = {
/** Current rule being executed */
rule: RuleName;
/** Position within instruction array */
#!/usr/sbin/dtrace -C -s
#pragma D option quiet
#pragma D option switchrate=10hz
inline int af_inet = 2; /* AF_INET defined in bsd/sys/socket.h */
inline int af_inet6 = 30; /* AF_INET6 defined in bsd/sys/socket.h */
#define HEADER "%-6s %-16s %-8s %-30s %-5s %8s %s\n"
#define HEADERD "%-6d %-16s %-8s %-30s %-5d %8d %s\n"
#!/usr/sbin/dtrace -w -C -s
#pragma D option quiet
inline int af_inet6 = 30; /* AF_INET6 defined in bsd/sys/socket.h */
inline string CHARLES = "Charles";
syscall::connect*:entry
{