Code Explainers
Browse the library
javascript
import { useState, useEffect, useCallback, useRef } from "react"; export function usePersistentForm(storageKey, initialValues) { const [values, setValues] = useState(() => {
A React hook that persists form state to localStorage
custom-hooks
localstorage
debounce
Intermediate
9 steps
rust
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; use serde::{Deserialize, Serialize}; use uuid::Uuid;
Building a typed create_user handler in Axum
serde
extractors
sqlx
Intermediate
7 steps
java
@Component public class JwtAuthenticationFilter extends OncePerRequestFilter { private final JwtTokenProvider tokenProvider;
How a JWT auth filter works in Spring
authentication
jwt
servlet-filter
Intermediate
8 steps
typescript
function throttle<T extends (...args: any[]) => void>( fn: T, limit: number ): (...args: Parameters<T>) => void {
Building a trailing-edge throttle in TypeScript
throttling
closures
generics
Intermediate
7 steps
go
package store import ( "database/sql"
Wrapping and inspecting errors in Go
error-handling
error-wrapping
sentinel-errors
Intermediate
8 steps
php
<?php namespace App\Support;
Building a URL slug from any title in PHP
regex
transliteration
string-processing
Intermediate
8 steps
python
from collections import deque class RollingAverage:
A rolling average over a fixed window
sliding-window
running-sum
deque
Intermediate
7 steps
javascript
function groupBy(items, keySelector) { const resolveKey = typeof keySelector === 'function' ? keySelector : (item) => item[keySelector];
Building a flexible groupBy in JavaScript
higher-order-functions
reduce
data-transformation
Intermediate
6 steps
rust
use axum::{ response::sse::{Event, KeepAlive, Sse}, routing::get, Router,
Streaming live price ticks with SSE in Axum
server-sent-events
broadcast-channel
streaming
Advanced
8 steps
java
@Entity @Table(name = "accounts") public class Account {
Optimistic locking with @Version in Spring
optimistic-locking
jpa
concurrency
Advanced
7 steps
typescript
interface TokenBucketOptions { capacity: number; refillPerSecond: number; }
How a token bucket rate limiter works
rate-limiting
token-bucket
lazy-evaluation
Intermediate
7 steps
go
package main import ( "context"
Graceful HTTP shutdown in Go
graceful-shutdown
signals
goroutines
Intermediate
8 steps
php
<?php declare(strict_types=1);
Streaming file lines with a PHP generator
generators
lazy-evaluation
file-io
Intermediate
7 steps
ruby
class SessionsController < ApplicationController MAX_ATTEMPTS = 5 THROTTLE_WINDOW = 15.minutes
Throttling failed logins in Rails
rate-limiting
authentication
caching
Intermediate
7 steps
python
from collections import OrderedDict from typing import Callable, Hashable, Iterable, Iterator, TypeVar T = TypeVar("T")
Two ways to dedupe while keeping order
deduplication
generators
ordered-data
Intermediate
7 steps
javascript
function makeReorderableList(listEl, onReorder) { let draggedItem = null; listEl.addEventListener('dragstart', (e) => {
Drag-to-reorder lists with the HTML5 drag API
drag-and-drop
event-delegation
dom-manipulation
Intermediate
8 steps
go
package handlers type SignupRequest struct { Email string `json:"email" binding:"required,email"`
Validated signup handler in Gin
request validation
error handling
http status codes
Intermediate
7 steps
python
from django.db.models import Sum, Count, F, DecimalField from django.db.models.functions import TruncMonth, Coalesce from .models import Order
Build a monthly revenue report in Django
aggregation
orm
group-by
Advanced
7 steps