Code Explainers
Browse the library
rust
use std::sync::Arc; use std::collections::HashMap; use axum::{ extract::State,
Hot-reloadable config with shared state in Axum
shared-state
concurrency
rwlock
Intermediate
7 steps
php
<?php namespace App\Rules;
How a custom coupon rule validates in Laravel
validation
eloquent
business-rules
Intermediate
7 steps
python
from xml.etree import ElementTree as ET from xml.dom import minidom
Converting nested dicts to XML in Python
recursion
serialization
xml
Intermediate
9 steps
javascript
function sparkline(values, { width = 200, height = 40, stroke = '#2563eb', fill = 'rgba(37,99,235,0.12)' } = {}) { if (!Array.isArray(values) || values.length < 2) { throw new RangeError('sparkline requires at least two data points'); }
Rendering a sparkline as SVG
svg
data-visualization
coordinate-mapping
Intermediate
8 steps
typescript
import { Directive, ElementRef, HostListener, Input, OnDestroy, TemplateRef, ViewContainerRef } from '@angular/core'; import { Overlay, OverlayRef } from '@angular/cdk/overlay'; import { TemplatePortal } from '@angular/cdk/portal';
Building a tooltip directive in Angular
directives
cdk-overlay
hover-interaction
Intermediate
7 steps
go
func (h *ReportHandler) ExportTransactions(w http.ResponseWriter, r *http.Request) { ctx := r.Context() from, to, err := parseDateRange(r.URL.Query())
Streaming a CSV export in Go
streaming
http
csv
Intermediate
8 steps
java
public final class SensitiveDataMasker { private static final Pattern CARD_NUMBER = Pattern.compile("\\b(?:\\d[ -]*?){13,19}\\b"); private static final Pattern EMAIL = Pattern.compile("[A-Za-z0-9._%+-]+@([A-Za-z0-9.-]+\\.[A-Za-z]{2,})");
Masking sensitive data with regex in Java
regex
data-masking
luhn-algorithm
Intermediate
8 steps
rust
use chrono::{DateTime, Duration, Utc}; #[derive(Debug, Clone)] pub struct Sample {
Forward-filling a time series in Rust
time-series
forward-fill
btreemap
Intermediate
7 steps
ruby
class ApplicationController < ActionController::Base INACTIVITY_TIMEOUT = 30.minutes before_action :expire_stale_session
Idle session timeout in a Rails controller
authentication
session-management
before-action
Intermediate
6 steps
python
from django.db import transaction from django.db.models import F from django.http import JsonResponse from django.views.decorators.http import require_POST
Safely reordering tasks with a Django action
transactions
row-locking
validation
Advanced
8 steps
javascript
import { NextResponse } from 'next/server'; import { revalidatePath } from 'next/cache'; import crypto from 'node:crypto';
A GitHub webhook that revalidates Next.js docs
webhooks
hmac-verification
cache-revalidation
Intermediate
8 steps
java
public final class UserAgentParser { private static final Pattern OS_PATTERN = Pattern.compile( "(Windows NT [0-9.]+|Mac OS X [0-9_]+|Android [0-9.]+|iPhone OS [0-9_]+|Linux)");
Parsing user-agent strings with regex in Java
regex
parsing
pattern-matching
Intermediate
9 steps
ruby
module Dotenv LINE = /\A\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*\z/ module_function
Parsing a .env file in Ruby
parsing
regular-expressions
environment-variables
Intermediate
8 steps
php
<?php namespace App\Mail;
Building a queued digest email in Laravel
mailable
queueing
localization
Intermediate
6 steps
go
package config import ( "bufio"
Parsing INI files in Go
parsing
state-machine
error-handling
Intermediate
7 steps
typescript
import { Component, computed, input, model, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; interface Product {
Reactive filtering with Angular signals
signals
computed
two-way-binding
Intermediate
9 steps
javascript
import { after } from "next/server"; import { NextResponse } from "next/server"; import { z } from "zod"; import { resend } from "@/lib/resend";
Deferring work with after() in Next.js
validation
background-tasks
route-handlers
Intermediate
8 steps
python
import os from uuid import uuid4 from flask import Blueprint, current_app, jsonify, request, url_for
How a Flask image upload endpoint works
file-upload
validation
image-processing
Intermediate
9 steps