Code Explainers

Browse the library

go
package textutil
 
import "strings"
 

Extracting delimited text with strings.Cut

string-parsing delimiters standard-library
Beginner 7 steps
javascript
const form = document.querySelector('#profile-form');
let isDirty = false;
 
form.addEventListener('input', () => {

Warn before leaving a form with unsaved edits

event-listeners dom state-tracking
Beginner 5 steps
ruby
class SyncInventoryJob < ApplicationJob
  queue_as :integrations
 
  retry_on Faraday::TimeoutError,

Resilient background jobs with retry_on in Rails

background-jobs error-handling retries
Intermediate 8 steps
rust
use std::sync::Mutex;
use std::time::{Duration, Instant};
 
#[derive(Debug, Clone, Copy, PartialEq)]

Building a circuit breaker in Rust

circuit-breaker state-machine concurrency
Advanced 8 steps
python
import fnmatch
from collections import defaultdict
from typing import Any, Callable
 

A pattern-matching event bus in Python

pub-sub decorators pattern-matching
Intermediate 8 steps
ruby
class Pluralizer
  IRREGULARS = {
    "person" => "people",
    "child" => "children",

Building an English pluralizer in Ruby

regular-expressions lookup-tables string-manipulation
Intermediate 8 steps
javascript
import type { MetadataRoute } from 'next'
 
const BASE_URL = process.env.NEXT_PUBLIC_SITE_URL ?? 'https://example.com'
 

Environment-aware robots.txt in Next.js

seo environment-config web-crawlers
Intermediate 6 steps
php
<?php
 
namespace App\Support;
 

Detecting file types by MIME in PHP

file-validation mime-detection whitelist
Intermediate 7 steps
python
from typing import Iterable
 
 
def jaccard_similarity(tags_a: Iterable[str], tags_b: Iterable[str]) -> float:

Ranking tag sets by Jaccard similarity

set-operations similarity-metric generators
Intermediate 5 steps
java
@Configuration
public class ValidationConfig implements WebMvcConfigurer {
 
    @Bean

Localized bean validation messages in Spring

internationalization bean-validation configuration
Intermediate 6 steps
typescript
interface ContentRange {
  unit: string;
  start: number;
  end: number;

Parsing HTTP Content-Range headers in TypeScript

regex parsing validation
Intermediate 8 steps
rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{header::HeaderValue, request::Parts, HeaderName},

Propagating trace context in Axum extractors

extractors distributed-tracing http-headers
Intermediate 8 steps
ruby
require 'set'
 
class CronSchedule
  FIELDS = %i[minute hour day month wday].freeze

Parsing and matching cron expressions in Ruby

parsing time-arithmetic sets
Intermediate 10 steps
javascript
const fs = require('fs');
const path = require('path');
const express = require('express');
 

Streaming video with HTTP range requests in Express

http-range-requests streaming path-traversal
Intermediate 8 steps
php
<?php
 
namespace App\Http\Controllers;
 

Serving cached translations from a Laravel controller

http-caching etag localization
Intermediate 8 steps
python
from django import forms
from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from formtools.wizard.views import SessionWizardView

Building a multi-step form with Django wizards

form-wizard multi-step-forms session-state
Intermediate 8 steps
java
public final class ChunkSorter {
 
    private static final int MAX_LINES_PER_CHUNK = 100_000;
 

External merge sort in Java

external-sort merge-sort priority-queue
Advanced 10 steps
go
package flatten
 
import (
	"encoding/json"

Flattening nested JSON into dotted keys

recursion json type-switch
Intermediate 7 steps