Code Explainers

Intermediate code explainers

javascript
const legacyRedirects = [
  { from: '/blog/:slug', to: '/articles/:slug' },
  { from: '/shop/product/:id', to: '/store/items/:id' },
  { from: '/about-us', to: '/about' },

How redirects work in Next.js config

redirects routing configuration
Intermediate 7 steps
go
package middleware
 
import (
	"crypto/hmac"

Verifying signed URLs with Gin middleware

hmac middleware authentication
Intermediate 8 steps
php
<?php
 
namespace App\Http\Controllers;
 

Building a multi-step onboarding wizard in Laravel

session-state validation multi-step-forms
Intermediate 9 steps
typescript
interface RunningStats {
  count: number;
  total: number;
  average: number;

Streaming running averages in TypeScript

generators streaming incremental-aggregation
Intermediate 6 steps
java
package com.acme.catalog.persistence;
 
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;

Auditing timestamps with a JPA MappedSuperclass in Spring

jpa auditing lifecycle-callbacks
Intermediate 5 steps
javascript
import { createContext, useContext, useReducer, useCallback, useEffect } from 'react';
 
const AuthContext = createContext(null);
 

Building an auth context in React

context usereducer authentication
Intermediate 8 steps
python
import json
import logging
import threading
from pathlib import Path

A hot-reloading config file watcher

file-watching thread-safety hot-reload
Intermediate 7 steps
php
<?php
 
namespace App\Http;
 

HTTP content negotiation in PHP

http content-negotiation parsing
Intermediate 9 steps
typescript
import {
  IsEmail,
  IsNotEmpty,
  IsOptional,

How validation groups reuse one DTO in NestJS

validation dto decorators
Intermediate 9 steps
php
<?php
 
namespace App\Listeners;
 

Generating responsive images in a Laravel listener

queued jobs event listeners image processing
Intermediate 7 steps
python
class Parser:
    def __init__(self, text):
        self.tokens = self._tokenize(text)
        self.pos = 0

A recursive descent arithmetic parser

recursive-descent tokenizer operator-precedence
Intermediate 9 steps
javascript
import { useDeferredValue, useMemo, useState } from "react";
 
function ProductSearch({ products }) {
  const [query, setQuery] = useState("");

Keeping search input snappy with useDeferredValue in React

concurrent-rendering deferred-value memoization
Intermediate 7 steps
rust
use axum::{
    extract::{FromRef, FromRequestParts},
    http::{header, request::Parts, StatusCode},
    RequestPartsExt,

How a JWT extractor works in Axum

jwt authentication extractors
Intermediate 8 steps
typescript
import { InjectionToken, inject, Provider, isDevMode } from '@angular/core';
import { WINDOW } from './window.token';
 
export interface AnalyticsConfig {

Layered config with an Angular InjectionToken

dependency-injection configuration factory-provider
Intermediate 8 steps
ruby
class Admin::AccountsController < Admin::BaseController
  before_action :set_account, only: :destroy
 
  def destroy

A guarded destroy action in Rails

controllers callbacks transactions
Intermediate 8 steps
php
final class InvoiceCalculator
{
    private const SCALE = 4;
 

Precise money math with PHP's BCMath

bcmath arbitrary precision money
Intermediate 8 steps
python
import re
from dataclasses import dataclass, field
 
 

Building a table of contents from Markdown

regular-expressions parsing slugification
Intermediate 9 steps
javascript
const IBAN_LENGTHS = {
  DE: 22, FR: 27, GB: 22, ES: 24, IT: 27,
  NL: 18, BE: 16, CH: 21, AT: 20, PT: 25,
};

How IBAN validation works in JavaScript

validation checksum modular-arithmetic
Intermediate 8 steps