Skip to content

Instantly share code, notes, and snippets.

View jjhiggz's full-sized avatar
🎯
Focusing

Jonathan Higger jjhiggz

🎯
Focusing
View GitHub Profile
import { z } from "zod";
// Zod schemas with branding
export const DollarsSchema = z.number().nonnegative().brand("dollars");
export const CentsSchema = z.number().int().nonnegative().brand("cents");
export type Dollars = z.infer<typeof DollarsSchema>;
export type Cents = z.infer<typeof CentsSchema>;
type DollarVal = Dollars | null | undefined;
@jjhiggz
jjhiggz / how-to-use.md
Last active August 6, 2025 13:22
Prisma Effect Generator

Prisma Effect Generator

  1. Put the above prisma-effect-generator.ts in your root of your project.

  2. Install "@prisma/generator-helper" and "@prisma/internals" as dev dependecies.

  3. Add this to your schema.prisma file

generator sqlSchema {
@jjhiggz
jjhiggz / sync-promise.ts
Created July 16, 2025 12:09
sync-promise
type SyncPromiseState<T, E = unknown> =
| { status: 'ok'; value: T }
| { status: 'error'; error: E };
class SyncPromise<T, E = unknown> {
private state: SyncPromiseState<T, E>;
private constructor(state: SyncPromiseState<T, E>) {
this.state = state;
}
@jjhiggz
jjhiggz / superpipe.ts
Last active July 16, 2025 11:54
superpipe
/**
* Perform left-to-right function composition.
* @param value The initial value.
* @param operations the list of operations to apply.
* @signature R.pipe(data, op1, op2, op3)
* @example
* superpipe(
* [1, 2, 3, 4],
* R.map(x => x * 2),
* arr => [arr[0] + arr[1], arr[2] + arr[3]],
@jjhiggz
jjhiggz / fetch-options.ts
Last active July 12, 2025 11:57
A simple function fetching pattern
export const getAuthHeaders = (
// Whatever inputs you need
) => {
return {
// whatever object you need
["ContentType"]: "application/json"
}
}
@jjhiggz
jjhiggz / ts-pattern-jsx.tsx
Created May 27, 2025 12:55
A great ts-pattern + JSX example
import { match } from 'ts-pattern';
// Define a discriminated union for sub-task states
type SubTaskState =
| { type: 'loading'; subTaskId: number }
| { type: 'completed'; subTaskId: number; result: string }
| { type: 'error'; subTaskId: number; error: string };
// Define a tuple union for task states
type TaskState =
@jjhiggz
jjhiggz / composition.ts
Last active April 14, 2025 16:57
Composition vs Inheritance
// Define individual animal types
type Dog = {
type: "dog";
name: string;
sound: "bark";
};
type Cat = {
type: "cat";
name: string;
@jjhiggz
jjhiggz / graph.ts
Created January 23, 2025 21:01
Useful Data Structures
import { uniqueBy } from "remeda";
import { SuperMap } from "./SuperMap.ts";
export class Graph<T> {
adjacencyList: SuperMap<T, T[]>;
private serialize: (input: T) => string;
private deserialize: (input: string) => T;
private printVal: (input: T) => any;
constructor(
@jjhiggz
jjhiggz / advent.ts
Last active December 9, 2024 06:49
import { piped } from "remeda";
import z from "zod";
const getBlocks = piped(
(a: string) => a.split(""),
(a) =>
a.map((char, index) => {
const isEven = index % 2 === 0;
const charValue = z.number().parse(+char);
@jjhiggz
jjhiggz / build-matrix.test.ts
Created September 9, 2024 16:05
Multi Item Alignment Stuff
import { buildMatrix } from "./build-matrix";
describe("Build Matrix", () => {
it("Should turn my shit into matrix of rows", () => {
expect(
buildMatrix({
// prettier-ignore
elements: [
1/1,
1/3, 2/3,