Code Explainers
Browse the library
typescript
export function chunk<T>(items: readonly T[], size: number): T[][] { if (size <= 0 || !Number.isInteger(size)) { throw new RangeError(`chunk size must be a positive integer, got ${size}`); }
Splitting work into sequential batches in TypeScript
generics
async-await
batching
Intermediate
5 steps
go
package handlers import ( "net/http"
Cookie-based sessions in Gin
authentication
cookies
middleware
Intermediate
7 steps
python
from pathlib import Path def print_tree(root, prefix="", show_hidden=False):
Printing a directory tree with recursion
recursion
filesystem
sorting
Intermediate
6 steps
php
<?php namespace App\Http\Controllers\Auth;
How a Laravel registration endpoint works
validation
database-transactions
events
Intermediate
8 steps
ruby
module LogParser class AccessLogStreamer SEVERITY_PATTERN = /\b(ERROR|WARN|FATAL)\b/
Streaming log lines with a Ruby enumerator
enumerators
lazy-iteration
regex-matching
Intermediate
6 steps
java
@RestController @RequestMapping("/webhooks/stripe") public class StripeWebhookController {
How a Stripe webhook controller works in Spring
webhooks
signature-verification
event-handling
Intermediate
7 steps
typescript
import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, throwError, timer } from 'rxjs'; import { mergeMap, retryWhen } from 'rxjs/operators';
Exponential backoff retries in Angular
retry
exponential-backoff
rxjs
Advanced
7 steps
javascript
import Papa from 'papaparse'; const MAX_SIZE = 5 * 1024 * 1024;
Validating and parsing CSV uploads in the browser
promises
csv-parsing
validation
Intermediate
8 steps
go
package validators import ( "regexp"
Custom validators in Gin
validation
sync.once
regexp
Intermediate
5 steps
python
from dataclasses import dataclass, fields, MISSING from typing import get_type_hints, get_origin, get_args, Union
Type-checking dataclasses at runtime
dataclasses
type-hints
runtime-validation
Advanced
8 steps
rust
use axum::{ body::Body, extract::Request, http::{header::HeaderValue, HeaderName},
Request ID middleware in Axum
middleware
tracing
request-extensions
Intermediate
7 steps
php
<?php namespace App\Http\Controllers;
Handling avatar uploads in Laravel
file-upload
image-processing
validation
Intermediate
8 steps
ruby
class HostnameValidator < ActiveModel::EachValidator MAX_LENGTH = 253 LABEL = /\A(?!-)[a-z0-9-]{1,63}(?<!-)\z/i
Writing a custom hostname validator in Rails
validation
custom validator
regex
Intermediate
8 steps
ruby
class PaymentsController < ApplicationController before_action :require_idempotency_key def create
Idempotent payment creation in Rails
idempotency
transactions
race-conditions
Advanced
10 steps
ruby
class Survey < ApplicationRecord has_many :questions, dependent: :destroy has_many :respondents, dependent: :nullify
Nested survey forms in Rails
nested-attributes
validations
associations
Intermediate
9 steps
php
<?php namespace App\Security;
Secure password hashing with Argon2id in PHP
password-hashing
argon2id
timing-attacks
Intermediate
8 steps
python
import time import threading
How a thread-safe token bucket rate limiter works
rate-limiting
concurrency
locking
Intermediate
6 steps
go
package logfmt import ( "bytes"
Pooling buffers for logfmt encoding in Go
object-pooling
memory-reuse
serialization
Intermediate
8 steps