typescript

typescript
import type { RequestHandler } from 'express';

type Bucket = { count: number; resetAt: number };
const buckets = new Map<string, Bucket>();

export function rateLimit(opts: { windowMs: number; max: number; key: (req: any) => string }): RequestHandler {

Rate limiting by IP + user (Express)

node security reliability
by Mateo Rodriguez 1 tab
typescript
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

export async function withTxRetry<T>(fn: (tx: PrismaClient) => Promise<T>, attempts = 3): Promise<T> {
  for (let i = 0; i < attempts; i++) {

Prisma transaction with retries for serialization errors

prisma postgres concurrency
by Mateo Rodriguez 1 tab
typescript
import { z } from 'zod';
import type { RequestHandler } from 'express';

export function validateBody<T extends z.ZodTypeAny>(schema: T): RequestHandler {
  return (req, res, next) => {
    const parsed = schema.safeParse(req.body);

Runtime validation for request bodies (Zod)

typescript validation api
by Mateo Rodriguez 1 tab
typescript
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

export function middleware(req: NextRequest) {
  const { pathname } = req.nextUrl;
  const protectedRoute = pathname.startsWith('/dashboard');

Next.js middleware for auth gating

nextjs auth security
by Mateo Rodriguez 1 tab
typescript
export type PostId = string & { readonly brand: unique symbol }
export type UserId = string & { readonly brand: unique symbol }

export interface User {
  id: UserId
  name: string

TypeScript types from Rails serializers

typescript types rails
by Maya Patel 1 tab
typescript
import { useEffect, useRef, ReactNode } from 'react'
import { createPortal } from 'react-dom'

interface ModalProps {
  isOpen: boolean
  onClose: () => void

Modal dialogs with focus trapping and accessibility

react accessibility modal
by Maya Patel 1 tab
typescript
type Toast = { id: string; message: string; kind: 'success' | 'error' };
const listeners = new Set<(t: Toast) => void>();

export const toastBus = {
  on(fn: (t: Toast) => void) {
    listeners.add(fn);

Frontend: toast notifications via a small event bus

react frontend ux
by Mateo Rodriguez 1 tab
typescript
import { Helmet } from 'react-helmet-async'

interface SEOProps {
  title: string
  description: string
  image?: string

SEO optimization with React Helmet

react seo react-helmet
by Maya Patel 2 tabs
typescript
import React, { Component, ReactNode } from 'react'

interface Props {
  children: ReactNode
  fallback?: ReactNode
  onError?: (error: Error, errorInfo: React.ErrorInfo) => void

Error boundaries for graceful error handling

react error-handling typescript
by Maya Patel 2 tabs
typescript
import { useForm } from 'react-hook-form'
import { useState } from 'react'
import api from '@/services/api'

interface SignupFormData {
  email: string

React Hook Form with async validation

react forms validation
by Maya Patel 1 tab
typescript
import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { useDebounce } from '@/hooks/useDebounce'
import api from '@/services/api'

export function SearchInput() {

Debounced search with controlled inputs

react search debounce
by Maya Patel 1 tab
typescript
import { memo } from 'react'
import { Post } from '@/types'

interface PostListItemProps {
  post: Post
  onLike: (id: string) => void

React memo for component optimization

react performance optimization
by Maya Patel 2 tabs