Code Explainers

Browse the library

java
@Component
public class InventoryReconciliationJob {
 
    private static final Logger log = LoggerFactory.getLogger(InventoryReconciliationJob.class);

Distributed scheduled jobs with Spring locks

distributed-locking scheduling concurrency
Advanced 8 steps
python
from flask import Blueprint, render_template, request, redirect, url_for, flash
from werkzeug.security import check_password_hash
 
from .models import User, db

A change-email route in Flask

blueprints form-validation password-hashing
Intermediate 8 steps
ruby
class DatasetImportJob < ApplicationJob
  queue_as :default
 
  def perform(import)

Streaming import progress with a Rails job

background-jobs turbo-streams progress-tracking
Intermediate 9 steps
rust
use bytes::{Buf, BufMut, BytesMut};
use tokio_util::codec::{Decoder, Encoder};
 
const MAX_FRAME: usize = 8 * 1024 * 1024;

A length-prefixed frame codec in Tokio

framing codecs buffers
Intermediate 8 steps
php
namespace App\Http\Filters;
 
use Closure;
use Illuminate\Database\Eloquent\Builder;

Composable query filters with Laravel's Pipeline

pipeline query-builder single-responsibility
Intermediate 7 steps
go
package render
 
import (
	"net/http"

How Gin renders MsgPack responses

serialization content-type interface-implementation
Intermediate 5 steps
typescript
import {
  Controller,
  Get,
  Query,

Validating paginated queries in NestJS

pagination validation pipes
Intermediate 7 steps
rust
use axum::{
    body::{Body, Bytes},
    extract::Request,
    http::StatusCode,

Logging request bodies in Axum middleware

middleware streaming-body logging
Intermediate 8 steps
java
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;

Ranking the most frequent words in Java

streams regex grouping
Intermediate 7 steps
ruby
class Booking < ApplicationRecord
  belongs_to :room
  belongs_to :guest
 

Guarding booking dates in a Rails model

validations associations scopes
Intermediate 5 steps
python
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

Testing FastAPI routes with dependency overrides

testing fixtures dependency-injection
Intermediate 7 steps
javascript
import { createContext, useContext, useState, useId } from "react";
 
const AccordionContext = createContext(null);
const ItemContext = createContext(null);

Building a compound Accordion in React

context compound-components state-management
Intermediate 8 steps
php
namespace App\Providers;
 
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;

Adding a whereActive macro in Laravel

macros service-provider query-builder
Intermediate 5 steps
go
package proxy
 
import (
	"log"

Building a hardened Go reverse proxy

reverse-proxy http timeouts
Intermediate 7 steps
typescript
import { AsyncLocalStorage } from 'node:async_hooks';
import { randomUUID } from 'node:crypto';
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

Request correlation IDs in NestJS with AsyncLocalStorage

async-local-storage middleware logging
Advanced 8 steps
rust
use std::time::Duration;
 
use axum::{
    body::Body,

Turning Axum timeouts into 504 JSON

middleware timeouts error-handling
Intermediate 7 steps
java
public final class HttpHeaders {
 
    private final NavigableMap<String, List<String>> values =
            new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

A case-insensitive HTTP headers map in Java

case-insensitivity multimap immutability
Intermediate 7 steps
ruby
class DashboardMetrics
  CACHE_TTL = 15.minutes
 
  def initialize(account)

Caching dashboard metrics in Rails

caching service-object query-optimization
Intermediate 5 steps