All catalogs

Snippets

Code snippet library

Ready TS/Python boilerplate for auth, AI, web, data, web3, ops. Copy, paste, ask the AI to extend.

29 entries

Auth & session

5 entries

Clerk + Next.js middleware

Protect routes with Clerk's middleware in Next.js App Router.

Lucia session check (App Router)

Server-side session lookup with Lucia in a server component.

Verify a JWT (jose)

Verify an HS256/RS256 JWT and extract claims with jose.

Auth.js credentials provider

Email + password sign-in with Auth.js (NextAuth) v5.

Verify a webhook signature (HMAC-SHA256)

Constant-time HMAC verification for incoming webhooks.

AI & LLM

8 entries

Claude streaming chat

Stream tokens from Claude Sonnet 4.6 via the official SDK.

Claude tool use loop

Minimal loop: model picks a tool, you run it, feed the result back.

Anthropic prompt caching

Mark a long system prompt as cacheable to cut token cost on repeated calls.

OpenAI streaming completion

Stream a chat completion from GPT-4o with the official SDK.

Batch embeddings (OpenAI)

Embed many texts in one call. Cheaper + faster than one-at-a-time.

Tiny RAG retrieve (cosine)

Brute-force cosine search over an in-memory vector store. Works for ≤10k chunks.

Vercel AI SDK tool calling

Define a typed tool with Zod and let the model invoke it through generateText.

Strict JSON output (Anthropic)

Coerce the model to return parseable JSON. Wrap with jsonrepair fallback.

Web & frontend

6 entries

fetch with timeout + retry

Cancel slow requests, retry transient 5xx with exponential backoff.

useDebounce hook

Delay a value update until N ms after the last change. For search-as-you-type.

useInView hook (IntersectionObserver)

Trigger when an element enters the viewport. Lazy load + infinite scroll.

Server Action form (Next.js)

Form posts directly to a server function. No client state library.

Edge rate limit (Upstash)

Per-IP fixed window rate limit at the edge.

Presigned S3 upload URL

Server signs, browser PUTs directly to S3 — no payload through your server.

DB & cache

4 entries

Drizzle schema + relations

Typed Postgres schema with one-to-many relation. Drives migrations.

Prisma interactive transaction

Multi-step write that rolls back on any error.

Postgres advisory lock

App-level lock keyed by an int, useful for preventing duplicate cron runs.

Cache wrapper (read-through)

Wrap any async function to memoize its result in Redis with TTL.

Web3 & wallet

3 entries

wagmi: read an ERC-20 balance

Read balanceOf for the connected wallet. Type-safe via the ABI.

Solana: transfer SOL

Build, sign and send a SOL transfer with @solana/kit (web3.js v2).

Sign EIP-712 typed data (viem)

Sign structured data the user can preview in their wallet.

Deploy & ops

3 entries

Multi-stage Dockerfile (Node)

Build deps + cache deps separately, ship a minimal runtime image.

GitHub Action: deploy on tag

Build + deploy when you push a v* tag. Caches node_modules.

Healthcheck endpoint

Liveness + readiness probes that actually check downstream deps.