python
from enum import Enum
from typing import Optional

from fastapi import Query
from pydantic import BaseModel, Field, field_validator

Validate and Normalize Query Filters With a Pydantic Dependency in FastAPI

fastapi pydantic validation
by codesnips 3 tabs
php
<?php

namespace App\Tenancy;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

Enforce Multi-Tenant Isolation in Laravel with a Global Scope Bound to the Current User

laravel multi-tenancy eloquent
by codesnips 4 tabs
go
package web

import (
	"embed"
	"io/fs"
)

Serve Embedded Static Assets with embed.FS and Cache Headers in Go

go embed static-assets
by codesnips 3 tabs
javascript
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';

export const RouterContext = createContext(null);

export function RouterProvider({ children }) {
  const [path, setPath] = useState(() => window.location.pathname);

Client-Side Router with useRoute Hook and History API in React

react router hooks
by codesnips 3 tabs
go
package apiclient

import (
	"context"
	"fmt"
	"io"

Sharing a golang.org/x/time/rate Limiter Across Goroutines for Outbound API Calls

go rate-limiting concurrency
by codesnips 3 tabs
javascript
const { pool } = require('./db');

async function recordEvent(client, { eventId, type, payload }) {
  const { rows } = await client.query(
    `INSERT INTO webhook_events (event_id, type, payload, status)
     VALUES ($1, $2, $3, 'received')

Idempotent Stripe Webhook Processing With an Express Event-Store Middleware

express webhooks idempotency
by codesnips 3 tabs
python
import functools
import threading
import time
from collections import OrderedDict

Custom TTL + LRU Cache Decorator for Expensive Python Computations

python caching lru
by codesnips 2 tabs
rust
mod chunker;mod parallel_hash;

use parallel_hash::{hash_buffer, root_hash};

const CHUNK_SIZE: usize = 64 * 1024;

Content-Defined Chunking With Parallel BLAKE3 Hashing Using Rayon

rust rayon parallelism
by codesnips 3 tabs
javascript
import { useEffect, useState } from "react";

export function useDebounce(value, delay = 300) {
  const [debounced, setDebounced] = useState(value);

  useEffect(() => {

Debounced Search Box With Live Autocomplete in React

react hooks debounce
by codesnips 3 tabs
java
import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Predicate;

public final class RetryPolicy {
    private final int maxAttempts;

Async Retry With Exponential Backoff and Full Jitter Using ScheduledExecutorService

java retry backoff
by codesnips 3 tabs
typescript
export interface Todo {
  id: string;
  title: string;
  completed: boolean;
}

Optimistic UI Updates with Rollback Using React Query useMutation

react react-query optimistic-ui
by codesnips 3 tabs
go
package fetch

import (
	"context"
	"net/http"

Bounded Fan-Out With Worker Pool, errgroup, and Result Collection in Go

go concurrency goroutines
by codesnips 3 tabs