Code Explainers

Browse the library

java
@Configuration
@EnableKafka
public class KafkaErrorHandlingConfig {
 

Kafka retry and dead-letter handling in Spring

kafka error-handling retry
Intermediate 7 steps
php
<?php
 
namespace App\Http\Controllers\Api;
 

Building a cursor-paginated feed in Laravel

cursor-pagination eager-loading validation
Intermediate 8 steps
typescript
import { useCallback, useEffect, useRef, useState } from "react";
 
interface Page<T> {
  items: T[];

A cursor-based infinite scroll hook in React

custom-hooks pagination intersection-observer
Intermediate 9 steps
go
package config
 
import "time"
 

The functional options pattern in Go

functional-options closures immutability
Intermediate 7 steps
ruby
class DateRangeMerger
  def initialize(ranges)
    @ranges = ranges
  end

Merging overlapping date ranges in Ruby

sorting interval-merging enumerable
Intermediate 5 steps
javascript
const form = document.querySelector('#signup-form');
const password = form.querySelector('#password');
const confirm = form.querySelector('#confirm-password');
const submit = form.querySelector('button[type="submit"]');

Live password-match validation in the DOM

form-validation dom-events accessibility
Intermediate 6 steps
python
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
from starlette.status import HTTP_413_REQUEST_ENTITY_TOO_LARGE

Enforcing a max request body size in FastAPI

middleware streaming request-limits
Advanced 6 steps
rust
use axum::{
    extract::FromRequestParts,
    http::{request::Parts, StatusCode, header::ACCEPT_LANGUAGE},
};

A locale extractor for Axum handlers

content-negotiation http-headers custom-extractor
Intermediate 7 steps
java
@Controller
@RequestMapping("/employees")
public class EmployeeController {
 

Customizing form binding in a Spring MVC controller

data-binding validation type-conversion
Intermediate 9 steps
php
<?php
 
namespace App\Services;
 

Caching per-tenant settings in Laravel

caching multi-tenancy dependency-injection
Intermediate 7 steps
typescript
type NestedValue = string | NestedValue[] | { [key: string]: NestedValue };
 
function parseFieldPath(name: string): string[] {
  const match = name.match(/^([^\[\]]+)((?:\[[^\[\]]*\])*)$/);

Parsing bracketed form field names into nested objects

parsing recursive-types regex
Intermediate 8 steps
go
package admin
 
import (
	"net/http"

Building a protected admin area in Gin

routing middleware authentication
Intermediate 6 steps
ruby
module SlowQueryLogger
  SLOW_QUERY_THRESHOLD_MS = 200.0
  IGNORED_PAYLOAD_NAMES = %w[SCHEMA TRANSACTION].freeze
 

Logging slow SQL queries in Rails

instrumentation logging pub-sub
Intermediate 7 steps
rust
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::Duration;

Graceful thread shutdown with an atomic flag

concurrency atomics memory-ordering
Advanced 7 steps
python
import logging
import uuid
from contextvars import ContextVar
 

Request ID tracing in FastAPI middleware

middleware context-variables request-tracing
Intermediate 7 steps
ruby
require "phonelib"
 
class PhoneNumber
  class InvalidNumber < StandardError; end

Wrapping phone parsing in a Ruby value object

value-object memoization validation
Intermediate 7 steps
java
package com.example.config.condition;
 
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;

A custom @Conditional feature flag in Spring

conditional beans feature flags annotations
Intermediate 7 steps
javascript
const express = require('express');
const EventEmitter = require('events');
 
const router = express.Router();

Server-Sent Events with Express

server-sent-events streaming event-emitter
Advanced 8 steps