Code Explainers

Browse the library

python
import hashlib
import os
from datetime import timedelta
 

Serving cacheable static assets in Flask

http-caching etag conditional-requests
Intermediate 8 steps
php
<?php
 
namespace App\Reminders;
 

Scheduling reminders across time zones in PHP

timezones datetime immutability
Intermediate 7 steps
go
package middleware
 
import (
	"net/http"

A per-IP rate limiter middleware in Gin

rate-limiting token-bucket middleware
Intermediate 8 steps
typescript
import {
  Controller,
  Post,
  UploadedFile,

Handling avatar uploads in NestJS

file-upload validation interceptors
Intermediate 7 steps
rust
use axum::{
    extract::State,
    response::sse::{Event, KeepAlive, Sse},
};

Broadcasting live prices over SSE in Axum

server-sent-events broadcast-channel streams
Advanced 9 steps
java
public record ServerConfig(
        String host,
        int port,
        Duration timeout,

Loading typed config into a Java record

records factory-methods parsing
Intermediate 7 steps
java
public final class IbanValidator {
 
    private static final Map<String, Integer> COUNTRY_LENGTHS = Map.ofEntries(
        Map.entry("DE", 22), Map.entry("FR", 27), Map.entry("GB", 22),

Validating IBANs with the mod-97 checksum

validation checksum modular-arithmetic
Intermediate 8 steps
ruby
class LRUCache
  def initialize(capacity)
    raise ArgumentError, "capacity must be positive" unless capacity.positive?
 

How an LRU cache works in Ruby

caching eviction hash-ordering
Intermediate 7 steps
python
import re
from collections import Counter
from pathlib import Path
 

Ranking the top words in a PDF

text-processing regex counting
Intermediate 6 steps
typescript
@Component({
  selector: 'app-article-editor',
  templateUrl: './article-editor.component.html',
})

Autosaving a form with RxJS in Angular

reactive-forms rxjs-operators debouncing
Advanced 8 steps
go
package tsvio
 
import (
	"bufio"

Reading and writing TSV records in Go

parsing io-streams error-handling
Intermediate 10 steps
rust
pub struct Fibonacci {
    current: u64,
    next: u64,
}

A Fibonacci iterator in Rust

iterators traits lazy-evaluation
Intermediate 6 steps
php
<?php
 
namespace App\Http\Middleware;
 

Verifying GitHub webhook signatures in Laravel

middleware hmac webhooks
Intermediate 5 steps
java
@Configuration
@EnableWebSecurity
public class OAuth2SecurityConfig {
 

How OIDC login works in Spring Security

oauth2 openid-connect authorization
Intermediate 8 steps
ruby
class QueryParser
  def self.parse(query_string)
    new(query_string).parse
  end

Parsing nested query strings in Ruby

parsing recursion tokenization
Intermediate 9 steps
python
import django_filters
from django import forms
from django.utils import timezone
 

Building a date-range FilterSet in Django

filtering querysets form-widgets
Intermediate 6 steps
typescript
type CountdownState = {
  deadline: number;
  onTick: (remaining: number) => void;
  onComplete: () => void;

A countdown timer that survives reloads

persistence timers localstorage
Intermediate 10 steps
go
package config
 
import (
	"fmt"

Loading and saving YAML config in Go

yaml struct-tags defaults
Intermediate 8 steps