Code Explainers

Intermediate code explainers

ruby
require "yaml"
require "pathname"
 
class AppConfig

A typed config loader in Ruby

yaml configuration recursion
Intermediate 8 steps
javascript
function splitFullName(fullName) {
  const cleaned = (fullName || '').trim().replace(/\s+/g, ' ');
 
  if (!cleaned) {

Parsing full names into first and last

string-parsing regex edge-cases
Intermediate 8 steps
php
<?php
 
namespace App\Providers;
 

Defining rate limiters in Laravel

rate limiting service provider closures
Intermediate 7 steps
go
package checksum
 
import (
	"crypto/sha256"

Computing SHA-256 checksums in Go

hashing io-streaming filesystem-walk
Intermediate 7 steps
python
import click
 
 
@click.command()

Building a typed CLI with Click

cli decorators validation
Intermediate 7 steps
java
public final class AccessLogParser {
 
    private static final Pattern LINE = Pattern.compile(
        "^(?<ip>\\S+) \\S+ \\S+ \\[(?<time>[^\\]]+)\\] "

Parsing Apache access logs in Java

regex named-groups parsing
Intermediate 7 steps
ruby
module ProductsHelper
  def cached_product_row(product)
    cache [product, current_user.role] do
      render partial: "products/row", locals: { product: product }

Russian doll caching that busts itself in Rails

fragment-caching cache-invalidation associations
Intermediate 4 steps
go
package dateutil
 
import (
	"fmt"

Parsing and formatting dates in Go

date parsing layouts timezones
Intermediate 7 steps
java
public class KeysetPaginationRepository {
 
    private final DataSource dataSource;
 

How keyset pagination works in Java

pagination sql jdbc
Intermediate 8 steps
typescript
import { IsInt, IsOptional, Max, Min } from 'class-validator';
import { Type } from 'class-transformer';
 
export class PaginationQueryDto {

Type-safe pagination queries in NestJS

pagination validation dto
Intermediate 7 steps
javascript
import { db } from '@/lib/db'
 
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL ?? 'https://example.com'
 

Generating a dynamic sitemap in Next.js

sitemap seo database-query
Intermediate 5 steps
ruby
def build_pivot_table(sales)
  pivot = sales.each_with_object(Hash.new { |h, k| h[k] = Hash.new(0.0) }) do |record, table|
    region = record.fetch(:region)
    quarter = record.fetch(:quarter)

Building a pivot table in Ruby

aggregation nested-hashes default-values
Intermediate 9 steps
python
import csv
 
from django.http import StreamingHttpResponse
from django.utils.timezone import now

Streaming a CSV export in Django

streaming csv-export generators
Intermediate 7 steps
rust
use axum::{
    async_trait,
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},

Idempotent payments with an Axum extractor

idempotency extractors shared-state
Intermediate 8 steps
go
package middleware
 
import (
	"bytes"

Building a response cache middleware in Gin

middleware caching concurrency
Intermediate 8 steps
java
public final class AesGcmCipher {
 
    private static final String TRANSFORMATION = "AES/GCM/NoPadding";
    private static final int GCM_TAG_BITS = 128;

Authenticated encryption with AES-GCM in Java

cryptography aes-gcm authenticated-encryption
Intermediate 7 steps
typescript
import {
  Injectable,
  NestInterceptor,
  ExecutionContext,

A per-route timeout interceptor in NestJS

interceptors metadata reflection rxjs
Intermediate 8 steps
javascript
class TokenBucket {
  constructor({ capacity, refillPerSecond }) {
    this.capacity = capacity;
    this.refillPerSecond = refillPerSecond;

How token-bucket rate limiting works in Express

rate-limiting token-bucket middleware
Intermediate 7 steps