Code Explainers

Browse the library

python
import re
from datetime import datetime
from dataclasses import dataclass
 

Parsing access logs with named regex groups

regex named-groups dataclasses
Intermediate 6 steps
php
<?php
 
final class ProductRepository
{

Safe SQL pagination with PDO in PHP

pagination input-validation prepared-statements
Intermediate 7 steps
rust
use axum::{
    extract::State,
    http::StatusCode,
    response::IntoResponse,

An async job queue handler in Axum

background-jobs async http-202
Intermediate 9 steps
ruby
module TextAnalysis
  module_function
 
  WORD_PATTERN = /[\p{Alpha}']+/

Building a word-frequency analyzer in Ruby

text processing regex enumerable
Intermediate 8 steps
go
package debounce
 
import (
	"sync"

Building a debouncer in Go

concurrency debounce timers
Intermediate 6 steps
typescript
import { useState, useEffect, useRef, useCallback } from "react";
 
interface SearchResult {
  id: string;

A debounced search hook in React

debounce custom-hooks abortcontroller
Intermediate 7 steps
java
@WebMvcTest(OrderController.class)
class OrderControllerTest {
 
    @Autowired

Slice testing a controller with @WebMvcTest in Spring

testing mocking http
Intermediate 8 steps
python
import gzip
from pathlib import Path
from typing import Iterator
 

Streaming TSV records with Python generators

generators lazy-evaluation file-io
Intermediate 5 steps
php
<?php
 
namespace App\Http\Requests;
 

How a Laravel FormRequest validates input

validation form-request input-sanitization
Intermediate 6 steps
rust
use axum::{
    extract::FromRequestParts,
    http::{request::Parts, StatusCode, header::AUTHORIZATION},
};

How a JWT extractor works in Axum

authentication jwt extractors
Intermediate 8 steps
javascript
import { useMemo, useState } from 'react';
 
function ProductList({ products }) {
  const [query, setQuery] = useState('');

Memoizing a filtered list in React

memoization derived-state filtering
Intermediate 8 steps
ruby
module Fibonacci
  CACHE = Hash.new do |cache, n|
    cache[n] = cache[n - 1] + cache[n - 2]
  end

Memoizing Fibonacci with a Hash default block

memoization recursion hash-default
Intermediate 5 steps
go
package retry
 
import (
	"context"

Retry with exponential backoff in Go

retry exponential-backoff jitter
Intermediate 8 steps
typescript
type SignupInput = {
  email: string;
  password: string;
  confirmPassword: string;

How a typed signup validator collects errors

form-validation type-safety regex
Intermediate 9 steps
java
public final class BusinessDays {
 
    private BusinessDays() {
    }

Counting business days between two dates in Java

date arithmetic utility class streams
Intermediate 7 steps
python
import hashlib
import hmac
import os
 

Verifying signed payment webhooks in Flask

hmac webhooks signature verification
Intermediate 7 steps
php
<?php
 
final class CsrfGuard
{

Building a per-form CSRF guard in PHP

csrf security sessions
Intermediate 8 steps
php
<?php
 
namespace App\Models;
 

Polymorphic comments in Laravel with morphTo

polymorphism eloquent relationships
Intermediate 5 steps