Code Explainers
Browse the library
java
public class DuplicateFinder { public Map<String, List<Path>> findDuplicates(Path root) throws IOException { Map<String, List<Path>> byHash = new HashMap<>();
Finding duplicate files by content hash
hashing
file-io
streams
Intermediate
8 steps
php
<?php namespace App\Support;
Normalizing phone numbers to E.164 in PHP
input-validation
normalization
regular-expressions
Intermediate
8 steps
ruby
class QueryProxy ALLOWED = %i[where limit offset order includes distinct].freeze def initialize(relation, operations = [])
Building a lazy query proxy in Ruby
metaprogramming
method_missing
lazy-evaluation
Advanced
7 steps
javascript
class InfiniteScroll { constructor(sentinel, { loadMore, root = null, rootMargin = '200px' } = {}) { this.sentinel = sentinel; this.loadMore = loadMore;
Infinite scroll with IntersectionObserver
intersectionobserver
pagination
async
Intermediate
10 steps
java
@Component public class OrderRecoveryHandler { private final RabbitTemplate rabbitTemplate;
Dead-letter recovery with Spring AMQP
dead-letter-queue
retry
exponential-backoff
Advanced
9 steps
ruby
class Debouncer def initialize(delay:) @delay = delay @mutex = Mutex.new
A thread-safe debouncer in Ruby
concurrency
debouncing
mutex
Advanced
5 steps
go
package storage import ( "context"
A SQLite-backed order store in Go
database/sql
sqlite
error-wrapping
Intermediate
7 steps
php
final class Route { private string $regex; private array $paramNames = [];
Compiling route patterns into regex in PHP
routing
regex
parsing
Intermediate
8 steps
javascript
import { forwardRef, useImperativeHandle, useRef, useState } from 'react'; const TextField = forwardRef(function TextField( { label, error, onChange, ...props },
Exposing an imperative handle in React
forwardref
useimperativehandle
refs
Advanced
8 steps
typescript
import { CanActivate, ExecutionContext, Injectable,
How guards chain auth in NestJS
guards
authentication
authorization
Intermediate
8 steps
python
from fastapi import APIRouter, Depends, HTTPException, status from fastapi.security import OAuth2PasswordBearer from jose import JWTError, jwt from sqlalchemy.orm import Session
Chaining auth dependencies in FastAPI
dependency-injection
jwt-authentication
authorization
Intermediate
8 steps
java
@Component public class CorrelationIdWebFilter implements WebFilter, Ordered { public static final String CORRELATION_ID_HEADER = "X-Correlation-Id";
Correlation IDs in a Spring WebFlux filter
reactive
web filter
correlation id
Advanced
7 steps
ruby
require "net/http" require "json" class UrlFetcher
A thread-pool URL fetcher in Ruby
concurrency
thread-pool
queues
Intermediate
8 steps
rust
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::thread;
A round-robin worker pool in Rust
concurrency
thread-pool
channels
Intermediate
7 steps
go
package auth import ( "errors"
Hashing and verifying passwords with bcrypt in Go
password-hashing
bcrypt
error-handling
Intermediate
7 steps
php
public function customerTotals(Request $request): Collection { return DB::table('orders') ->join('customers', 'customers.id', '=', 'orders.customer_id')
Building an aggregate report with Laravel's query builder
query builder
aggregation
conditional queries
Intermediate
8 steps
typescript
import { useState, useCallback } from 'react'; type Todo = { id: string;
Optimistic UI updates in a React hook
optimistic-updates
custom-hooks
error-handling
Intermediate
8 steps
python
from flask import Blueprint, request, url_for, jsonify, abort from flask.views import MethodView from .models import Article, db
Building a paginated JSON API with Flask MethodView
rest-api
pagination
class-based-views
Intermediate
10 steps