Code Explainers

Intermediate code explainers

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
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
php
<?php
 
namespace App\Models;
 

How Eloquent scopes model order status in Laravel

query scopes state machine eloquent
Intermediate 7 steps
java
@RestController
@RequestMapping("/api/reports")
public class OrderReportController {
 

Streaming a CSV export in Spring

streaming csv-export backpressure
Intermediate 9 steps
ruby
class Article < ApplicationRecord
  belongs_to :author, class_name: "User"
  has_many :taggings, dependent: :destroy
  has_many :tags, through: :taggings

How scopes compose in Rails

scopes activerecord query-composition
Intermediate 8 steps
typescript
type QueuedRequest = {
  id: string;
  url: string;
  method: string;

A retry queue with exponential backoff

retry exponential-backoff persistence
Intermediate 10 steps
ruby
class Order
  class InvalidTransition < StandardError; end
 
  TRANSITIONS = {

A state machine for order transitions in Ruby

state-machine data-driven error-handling
Intermediate 8 steps
python
from flask import Blueprint, jsonify, request, abort
 
v1 = Blueprint("users_v1", __name__)
v2 = Blueprint("users_v2", __name__)

Versioning a Flask API with Blueprints

api versioning blueprints rest
Intermediate 7 steps