Code Explainers

Browse the library

php
<?php
 
declare(strict_types=1);
 

Validating registration input with filter_var

validation sanitization filter_var
Intermediate 8 steps
typescript
interface Order {
  id: number;
  customerId: string;
  total: number;

A type-safe groupBy in TypeScript

generics reduce type-inference
Intermediate 6 steps
python
import time
from dataclasses import dataclass, field
 
from fastapi import Depends, FastAPI, HTTPException, Request, status

Token-bucket rate limiting in FastAPI

rate-limiting token-bucket dependency-injection
Advanced 10 steps
rust
use axum::{
    http::StatusCode,
    response::{IntoResponse, Response},
    Json,

How a custom error type maps to HTTP in Axum

error-handling enums trait-implementation
Intermediate 7 steps
java
@Service
public class GitHubClient {
 
    private final WebClient webClient;

Calling the GitHub API with Spring WebClient

reactive http-client dependency-injection
Intermediate 7 steps
javascript
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';
import { SignJWT, jwtVerify } from 'jose';
 

JWT session cookies in a Next.js Route Handler

authentication jwt cookies
Intermediate 8 steps
ruby
class Money
  include Comparable
 
  CURRENCY_SYMBOLS = { usd: "$", eur: "€", gbp: "£" }.freeze

Building an immutable Money value object in Ruby

value-object immutability comparable
Intermediate 8 steps
php
function memoize(callable $fn): callable
{
    $cache = [];
 

How memoization works in PHP closures

memoization closures higher-order-functions
Intermediate 8 steps
typescript
import { Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, LessThan } from 'typeorm';

Scheduled session cleanup in NestJS

cron-scheduling background-jobs repository-pattern
Intermediate 7 steps
typescript
import {
  CallHandler,
  ExecutionContext,
  Injectable,

Wrapping responses in a NestJS interceptor

interceptors rxjs response-shaping
Intermediate 7 steps
rust
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::thread;
 

Aggregating metrics across threads in Rust

concurrency shared-state mutex
Intermediate 7 steps
python
import argparse
import sys
from pathlib import Path
 

Building a subcommand CLI with argparse

cli argparse subcommands
Intermediate 6 steps
go
package main
 
import (
	"errors"

Parsing and validating CLI flags in Go

cli-parsing validation error-handling
Intermediate 8 steps
ruby
require "csv"
 
class SalesReport
  def initialize(path)

Aggregating CSV sales data in Ruby

data-aggregation memoization group_by
Intermediate 6 steps
javascript
'use server'
 
import { revalidatePath } from 'next/cache'
import { redirect } from 'next/navigation'

How a Next.js Server Action updates a post

server-actions authorization validation
Intermediate 7 steps
java
public class ThumbnailProcessor {
 
    private static final int MAX_CONCURRENCY = 4;
 

Bounded parallel thumbnail rendering in Java

concurrency thread-pool futures
Intermediate 7 steps
php
<?php
 
namespace App\Support;
 

Locale-aware formatting with PHP's intl extension

internationalization encapsulation constructor-injection
Intermediate 7 steps
typescript
type RetryOptions = {
  retries?: number;
  timeoutMs?: number;
  baseDelayMs?: number;

Retry with timeout and backoff in TypeScript

promises retry exponential-backoff
Intermediate 10 steps