Code Explainers
Intermediate code explainers
go
func (h *TransactionHandler) ExportCSV(c *gin.Context) { ctx := c.Request.Context() filters := parseTransactionFilters(c)
Streaming a CSV export in Gin
streaming
csv-export
database-cursor
Intermediate
8 steps
php
<?php namespace App\Rules;
How a custom phone validation rule works in Laravel
validation
custom-rules
dependency
Intermediate
6 steps
ruby
class Comment < ApplicationRecord belongs_to :commentable, polymorphic: true, counter_cache: true belongs_to :author, class_name: "User"
How polymorphic comments work in Rails
polymorphic-association
concerns
counter-cache
Intermediate
8 steps
python
import json import logging import stripe
Handling Stripe webhooks in Django
webhooks
signature-verification
idempotency
Intermediate
7 steps
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
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