Skip to content

Instantly share code, notes, and snippets.

View t3dotgg's full-sized avatar

Theo Browne t3dotgg

View GitHub Profile
@t3dotgg
t3dotgg / try-catch.ts
Last active March 3, 2025 06:52
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
{
"description": "Caps Lock to Hyper, Hyper + u/o to pageup/pagedown, IJKL to arrows, Hyper + A to Ctrl+A",
"manipulators": [
{
"from": {
"key_code": "caps_lock",
"modifiers": { "optional": ["any"] }
},
"to": [
{
@t3dotgg
t3dotgg / claude-allowed-filetypes.txt
Created February 4, 2025 02:45
This is a list of all the file types Claude allows on their web app. Posting it so others have it
.pdf
.doc
.docx
.rtf
.epub
.odt
.odp
.pptx
.txt
.py
@t3dotgg
t3dotgg / page.tsx
Created February 26, 2024 21:21
Example of a page refreshing content using unstable_cache in Next.js App Router
import { revalidateTag, unstable_cache } from "next/cache";
import { db } from "~/server/db";
import { todoItems } from "~/server/db/schema";
const getTodos = unstable_cache(
async () => {
return await db.query.todoItems.findMany();
},
["todoItems"],
{
import { useQuery } from "@tanstack/react-query";
type Action<TActionInput = unknown, TActionReturn = unknown> = (
input: TActionInput,
) => Promise<TActionReturn>;
export type BundledAction<TAction extends Action> = {
key: string[];
result: Awaited<ReturnType<TAction>>;
action: TAction;
@t3dotgg
t3dotgg / day25.ts
Created December 25, 2022 05:27
typescript aoc day 25 solution
const input = await Deno.readTextFile("./input.txt");
const lines = input.split("\n");
const dv = {
"2": 2,
"1": 1,
"0": 0,
"-": -1, // === -1
"=": -2, // === -2
export const options: QualityOption[] = [
{
tag: "480p_30",
name: "480p 30fps",
configuration: {
width: 640,
height: 480,
frameRate: 30,
bitrateMin: 750,
@t3dotgg
t3dotgg / .env
Created November 25, 2021 06:59
Recommended .env for PScale local dev
DATABASE_URL="mysql://[email protected]:3309/roundest-mon"
SHADOW_URL="mysql://[email protected]:3310/roundest-mon"
export const useGetUserProfile = (userId: string) => {
return useQuery(["user-profile", userId], async () => {
return await fetch("/user/"+userId);
});
}
@t3dotgg
t3dotgg / proposal.jsx
Created July 12, 2021 00:25
A proposal for a `useBackend` React hook that is compiled out into an API route. Inspired by Vercel and Next.js
// /pages/index.tsx
function ExamplePage() {
const { data } = useBackend(
"get-user-info",
async () => {
const data = await getProfileFromDB();
return data; // {name: string}
},
{ prefetch: true }