Skip to content

Instantly share code, notes, and snippets.

View AlexGeb's full-sized avatar
🏠
Working from home

Alexandre Behaghel AlexGeb

🏠
Working from home
View GitHub Profile
#!/usr/bin/env bash
# benchmark-tsc.sh — Compare `tsc --build` times across two git branches.
#
# Usage:
# bash scripts/benchmark-tsc.sh
#
# Override defaults via env vars:
# N=5 bash scripts/benchmark-tsc.sh
# BRANCH_A=main BRANCH_B=feat/foo bash scripts/benchmark-tsc.sh
#
import path from "path";
import { Project, ts } from "ts-morph";
const packageName = "assistant";
const packageDir = `packages/${packageName}`;
const project = new Project({
tsConfigFilePath: path.resolve(`${packageDir}/tsconfig.json`),
});
@AlexGeb
AlexGeb / organize-imports.ts
Last active April 9, 2026 10:49
Organize imports using ts-morph
import path from "path";
import { type FormatCodeSettings, Project } from "ts-morph";
const packageName = "assistant";
const formatSettings: FormatCodeSettings = {
ensureNewLineAtEndOfFile: true,
indentSize: 2,
};
/* eslint-disable @typescript-eslint/no-explicit-any */
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
k: infer I,
) => void
? I
: never;
export type UnionToTuple<T, R extends any[] = []> = [T] extends [never]
? R
: UnionToIntersection<T extends any ? (t: T) => void : never> extends (
@AlexGeb
AlexGeb / useRenderCount.ts
Created July 21, 2025 07:35
Hook that logs the render count of the component where it is used
import { useEffect, useRef } from "react";
export const useRenderCount = (label: string) => {
const count = useRef(0);
useEffect(() => {
count.current += 1;
// eslint-disable-next-line no-console
console.log(`${label} render count:`, count.current);
});
};
@AlexGeb
AlexGeb / hasDefinedKey.ts
Created March 26, 2025 16:46
hasDefinedKey
export const hasDefinedKey =
<K extends PropertyKey>(key: K) =>
<T extends Partial<Record<K, unknown>>>(
obj: T,
): obj is T & Record<K, Exclude<T[K], undefined>> =>
key in obj && obj[key] !== undefined;
@AlexGeb
AlexGeb / split.ts
Created February 6, 2025 09:33
split.ts
type Split<
V extends string,
S extends string,
> = V extends `${infer Head}${S}${infer Rest}`
? [Head, ...Split<Rest, S>]
: Array<V>;
const split = <V extends string, S extends string>(
value: V,
separator: S,
@AlexGeb
AlexGeb / DiseaseAreaRepository.spec.ts
Last active October 23, 2024 13:09
This gist demonstrate the use of sql dataloaders in effect
import { Model } from '@effect/sql';
import { PgClient } from '@effect/sql-pg';
import { layer } from '@effect/vitest';
import {
Array,
Config,
Effect,
Exit,
Fiber,
flow,
@AlexGeb
AlexGeb / FormRenderer.ts
Created September 11, 2024 09:37
Renders a form given an Effect schema
import type { Schema } from '@effect/schema';
import { AST } from '@effect/schema';
import { effectTsResolver } from '@hookform/resolvers/effect-ts';
import { Button } from '@inato/ui';
import { Match, Option } from 'effect';
import type {
FieldValues,
SubmitErrorHandler,
SubmitHandler,
} from 'react-hook-form';
@AlexGeb
AlexGeb / FormReact19.tsx
Created August 25, 2024 22:38
React 19 form example, with custom hook and effect schema validation
import { ArrayFormatter, Schema } from '@effect/schema';
import { Effect, Either, flow, Record } from 'effect';
import { Suspense, use, useActionState } from 'react';
const updateName = async (name: string) => {
await Effect.runPromise(Effect.sleep(2000));
return name;
};
type State<T> =