Code Explainers

Browse the library

php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Admin\ReportController;

How nested route groups compose in Laravel

routing middleware authorization
Intermediate 8 steps
ruby
class ParamCoercer
  TYPES = {
    integer: ->(v) { Integer(v) },
    float:   ->(v) { Float(v) },

Coercing request params by schema in Ruby

lambdas type-coercion lookup-table
Intermediate 7 steps
python
from datetime import datetime
from zoneinfo import ZoneInfo
 
 

Timezone-safe datetime handling in Python

timezones datetime normalization
Intermediate 4 steps
rust
use std::env;
use std::time::Duration;
 
#[derive(Debug, Clone)]

Loading typed config from environment variables in Rust

configuration error-handling generics
Intermediate 7 steps
typescript
type AsyncFn<A extends unknown[], R> = (...args: A) => Promise<R>;
 
interface MemoizeOptions<A extends unknown[]> {
  keyFn?: (...args: A) => string;

Memoizing async functions with TTL in TypeScript

memoization generics promises
Advanced 8 steps
java
public class EventBus {
 
    private final Map<Class<?>, List<Subscriber>> subscribers = new ConcurrentHashMap<>();
    private final Executor executor;

Building an annotation-driven EventBus in Java

publish-subscribe reflection annotations
Intermediate 7 steps
javascript
import { useRef, useCallback, useEffect, useState } from "react";
 
function useThrottle(callback, delay) {
  const lastRun = useRef(0);

Building a throttle hook in React

throttling custom-hooks refs
Intermediate 8 steps
go
package middleware
 
import (
	"bytes"

Verifying webhook HMAC signatures in Gin

hmac middleware webhooks
Intermediate 7 steps
php
final class TokenBucketLimiter
{
    private float $tokens;
    private float $lastRefill;

How a token bucket rate limiter works

rate-limiting token-bucket throttling
Intermediate 7 steps
ruby
module Api
  module V2
    class ArticlesController < Api::BaseController
      before_action :set_article, only: %i[show update destroy]

Building a versioned JSON API controller in Rails

rest-api serialization pagination
Intermediate 10 steps
python
import shutil
import uuid
from pathlib import Path
 

Safe avatar uploads in FastAPI

file-upload validation streaming
Intermediate 8 steps
typescript
import { Injectable, Scope, Inject } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { Request } from 'express';
 

Request-scoped context service in NestJS

dependency-injection request-scope immutability
Intermediate 8 steps
java
public class OrderSerializer {
 
    private final ObjectMapper mapper;
 

Configuring a reusable Jackson ObjectMapper

serialization json builder-pattern
Intermediate 8 steps
javascript
async function copyToClipboard(text) {
  if (navigator.clipboard && window.isSecureContext) {
    try {
      await navigator.clipboard.writeText(text);

Copying to the clipboard with a fallback

clipboard progressive-enhancement dom
Intermediate 8 steps
rust
use std::time::Duration;
use tokio::time::sleep;
 
#[derive(Debug)]

Async retry with exponential backoff in Rust

retry exponential-backoff async
Intermediate 8 steps
ruby
class ArticlesController < ApplicationController
  before_action :set_article, only: %i[show edit update destroy publish]
 
  def edit

Policy-based authorization in a Rails controller

authorization policy-object before-action
Intermediate 9 steps
java
package com.example.maintenance;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

How a scheduled cleanup job runs in Spring

scheduling cron transactions
Intermediate 6 steps
go
package handlers
 
import (
	"fmt"

Handling secure file uploads in Gin

file-upload validation security
Intermediate 7 steps