Skip to content

Instantly share code, notes, and snippets.

View btoo's full-sized avatar
🅱️
2️⃣

btoo

🅱️
2️⃣
View GitHub Profile
@btoo
btoo / ~|.claude|agents|coder.md
Last active March 22, 2026 17:50
Claude and Codex agent backups

You are an elite full-stack software engineer with deep expertise in TypeScript, Python, FastAPI, Next.js, React, SQLAlchemy, and PostgreSQL. You write code that is type-safe, functional, and production-ready on the first pass.

Core Principles

1. Understand Before You Code

  • Read the requirements thoroughly before writing a single line. If requirements are ambiguous, use request_user_input in Plan mode when a recommended structured choice fits the decision; otherwise ask one concise plain-text question.
  • Explore the codebase to understand existing patterns, types, and conventions before implementing. Read adjacent files, existing implementations of similar features, and relevant type definitions.
  • Identify all affected layers — if adding a backend endpoint, consider: route, service, DAO, migrations, type generation, and frontend consumption.

2. Type Safety Is Non-Negotiable

@btoo
btoo / effect-react-component-di.ts
Created April 30, 2024 17:40
effect-ts react component dependency injection demo
import { Context, Effect } from "effect";
import { jest } from '@jest/globals';
import React, { useEffect, useState } from "react";
interface Ad {
id: string
trackingEvent: string
}
export class FireTrackingEvent extends Context.Tag("FireTrackingEvent")<
@btoo
btoo / useEvent.ts
Last active January 17, 2026 07:32
typescript type-safe version of the approximate implementation of react's (~no longer~ EDIT: it's been released under a new name https://react.dev/reference/react/useEffectEvent) proposed useEvent hook
import { useCallback, useLayoutEffect, useRef } from 'react';
/** typescript type-safe version of [the approximate implementation of react's (no longer) proposed `useEvent` hook](https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md#internal-implementation) */
export function useEvent<Args extends Array<unknown>, Return>(
handler: (...args: Args) => Return,
): typeof handler {
const handlerRef = useRef(handler);
useLayoutEffect(() => {
handlerRef.current = handler;

Here is a simple flow chart:

graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;
@btoo
btoo / replace-replaceAll.ts
Last active March 7, 2023 20:49
TypeScript type-safe string replace and replaceAll (doesn't support regex) using template literal types (note: this is just a proof of concept and shouldnt be taken seriously)
type Replace<
T extends string,
Match extends string,
Replacement extends string
> = T extends `${infer Prefix}${Match}${infer Postfix}`
? `${Prefix}${Replacement}${Postfix}`
: never;
type ReplaceAll<
T extends string,
@btoo
btoo / proto2ts.sh
Last active August 26, 2022 02:12
i stole this protobuf-to-typescript converter from a really smart friend of mine
#!/usr/bin/env bash
DIR=$(dirname "${BASH_SOURCE[0]}")
DIR=$(cd "$DIR" || exit; pwd -P)
if ! type protoc &> /dev/null; then
echo "Dependency 'protoc' is not installed."
echo
echo " If you are on macOS, you can use 'brew install protobuf'."
echo
@btoo
btoo / useKeyboardHeight.ts
Last active June 12, 2024 04:43
react native keyboard height hook
import { useEffect } from "react";
import { Keyboard } from "react-native";
import { useState } from "./mounted";
export function useKeyboardHeight() {
const [keyboardHeight, setKeyboardHeight] = useState(0);
useEffect(() => {
const showSubscription = Keyboard.addListener('keyboardDidShow', e => setKeyboardHeight(e.endCoordinates.height));
const hideSubscription = Keyboard.addListener('keyboardWillHide', () => setKeyboardHeight(0));
@btoo
btoo / mounted-utility-hooks.ts
Last active October 16, 2023 16:20
Tired of seeing the `Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.` error?
// Tired of seeing the
// `Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.`
// error?
// Then use these utility hooks to make sure things don't happen in unmounted components!
import { useCallback, useEffect, useRef, useState } from "react";
import type { Dispatch, SetStateAction, DependencyList } from 'react'
export function useMountedRef() {
const mountedRef = useRef(true);
@btoo
btoo / .eslintignore
Last active May 9, 2020 15:13
husky pre-commit hook to `eslint --fix` and `prettier --write` files staged in git
*dist*
*.json
yarn.lock
*.proto
*.md
Makefile
.eslintignore
@btoo
btoo / ‎.gif
Last active August 8, 2025 09:10
‎.gif