Skip to content

Instantly share code, notes, and snippets.

View alexanderson1993's full-sized avatar
🚀
Spaceshippin...

Alex Anderson alexanderson1993

🚀
Spaceshippin...
View GitHub Profile
import { ButtonHTMLAttributes, useRef, useEffect } from "react";
export function ClickAndHoldButton({
action,
delay = 500,
loopDuration = 100,
...rest
}: {
action: () => void;
delay?: number;
@alexanderson1993
alexanderson1993 / README.md
Created September 27, 2024 19:54
Turnkey Reverse Proxied Portainer Script

A script for installing Docker and Portainer CE on an Ubuntu box which you can use to start up all kinds of other apps on the same host.

Make sure you change the appropriate parts of the script, specifically the DEFAULT_EMAIL used for the acme-companion, and the hostnames for the Portainer container.

@alexanderson1993
alexanderson1993 / Debug.ts
Created July 17, 2024 23:58
TinyBase PartyKit Client
import { TinyBaseSynchronizedPartyKitServer } from "@/party/TinyBaseSynchronizedPartyKitServer.ts";
import type * as Party from "partykit/server";
export default class Server
extends TinyBaseSynchronizedPartyKitServer
implements Party.Server
{
constructor(readonly room: Party.Room) {
super(room);
}
@alexanderson1993
alexanderson1993 / README.md
Created May 30, 2024 13:02
Refactor this custom React Hook

React Hook Refactor

I can think of at least three ways this hook can be refactored which makes it easier to read and more performant. This can be done without adding new dependencies or changing the signature of the context provider or hook, so it only refactors the internal behavior.

I'd love to see how anyone else would refactor this.

@alexanderson1993
alexanderson1993 / makeEmailSender.ts
Created April 8, 2024 14:16
Fetch-based email sending using SES - perfect for Cloudflare and other non-Node.js runtimes
import { AwsClient } from "aws4fetch";
const sesEndpoint = "email.us-east-1.amazonaws.com";
export function makeEmailSender({
accessKeyId,
secretAccessKey,
defaultFromAddress,
}: {
accessKeyId: string;
@alexanderson1993
alexanderson1993 / createR2UploadHandler.ts
Created April 5, 2024 15:22
A Remix upload handler for R2 buckets
import type { UploadHandlerPart } from "@remix-run/cloudflare";
export class MaxPartSizeExceededError extends Error {
constructor(public field: string, public maxBytes: number) {
super(`Field "${field}" exceeded upload size of ${maxBytes} bytes.`);
}
}
export function createR2UploadHandler({
bucket,
@alexanderson1993
alexanderson1993 / README.md
Last active November 4, 2024 13:06
Prisma D1 Migration CLI
migrate.mov

A handy CLI for working with the new Cloudflare D1/Prisma integration. You can read about that here: https://blog.cloudflare.com/prisma-orm-and-d1

Getting Started

  • Install wrangler, Prisma, and the other dependencies
npm install prisma@latest @prisma/client@latest @prisma/adapter-d1
@alexanderson1993
alexanderson1993 / README.md
Last active January 25, 2025 15:13
Prisma-like Migrations and type safety with Kysely
@alexanderson1993
alexanderson1993 / AlertDialogProvider.tsx
Created April 2, 2023 19:07
A multi-purpose alert/confirm/prompt replacement built with shadcn/ui AlertDialog components.
"use client";
import * as React from "react";
import { Input } from "@/components/ui/Input";
import { Button } from "@/components/ui/Button";
import {
AlertDialog,
AlertDialogContent,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogDescription,
@alexanderson1993
alexanderson1993 / CurrencyInput.tsx
Created July 29, 2022 13:12
A currency input field built with Chakra-UI
function CurrencyInput({
value,
onChange,
max,
}: {
value: number;
max: number;
onChange: (val: number) => void;
}) {
const [error, setError] = useState('');