Code Explainers

Browse the library

rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{header::HeaderName, request::Parts, StatusCode},

A custom tenant extractor in Axum

extractors middleware error-handling
Intermediate 7 steps
java
public class Views {
    public interface Public {}
    public interface Internal extends Public {}
}

Filtering JSON fields with @JsonView in Spring

serialization json-view access-control
Intermediate 6 steps
ruby
class ChatChannel < ApplicationCable::Channel
  periodically :sweep_stale_typists, every: 3.seconds
 
  def subscribed

How a typing indicator works in Rails ActionCable

websockets presence cache-expiry
Intermediate 9 steps
php
<?php
 
namespace App\Http\Controllers;
 

How a soft-delete restore endpoint works in Laravel

soft-deletes authorization single-action-controller
Intermediate 5 steps
go
package logtail
 
import (
	"bufio"

How a tail -f follower works in Go

io context channels
Intermediate 10 steps
typescript
type QueryValue = string | number | boolean | null | undefined;
type QueryInput = QueryValue | QueryValue[] | { [key: string]: QueryInput };
 
function buildQueryString(params: Record<string, QueryInput>): string {

Building nested query strings recursively

recursion url-encoding serialization
Intermediate 8 steps
python
from flask import g, session
 
from .extensions import cache
from .models import User

Injecting the current user in Flask templates

context-processor caching authentication
Intermediate 6 steps
rust
#[derive(Debug, Deserialize)]
pub struct SearchParams {
    #[serde(default)]
    q: String,

Building a safe search query in Axum

query parameters deserialization sql-building
Intermediate 10 steps
java
import java.util.Arrays;
import java.util.List;
 
public final class LatencyStats {

Computing latency percentiles in Java

percentiles interpolation immutability
Intermediate 9 steps
ruby
class Author < ApplicationRecord
  has_many :posts
 
  scope :with_post_stats, -> {

Aggregating post stats in a Rails scope

scopes sql-aggregation left-join
Intermediate 8 steps
php
<?php
 
namespace App\Models;
 

Auto-pruning old records with Laravel's Prunable

pruning eloquent cleanup
Intermediate 5 steps
typescript
type RGB = { r: number; g: number; b: number };
 
function parseHex(hex: string): RGB {
  const normalized = hex.replace(/^#/, "").trim();

Lightening and darkening hex colors in TypeScript

bitwise color-manipulation parsing
Intermediate 9 steps
rust
use axum::{
    body::Body,
    extract::State,
    http::{header, StatusCode},

Streaming a DB migration with Axum

streaming keyset-pagination backpressure
Advanced 8 steps
java
@Configuration
public class WebConfig {
 
    @Bean

HTTP caching with ETags in Spring

http-caching etag servlet-filters
Intermediate 6 steps
ruby
require "securerandom"
require "time"
 
class ICalEvent

Building an iCalendar file in Ruby

serialization string-formatting file-formats
Intermediate 10 steps
javascript
const legacyRedirects = [
  { from: '/blog/:slug', to: '/articles/:slug' },
  { from: '/shop/product/:id', to: '/store/items/:id' },
  { from: '/about-us', to: '/about' },

How redirects work in Next.js config

redirects routing configuration
Intermediate 7 steps
python
import heapq
 
 
class MovingMedian:

Running median with two heaps

heaps streaming invariants
Advanced 8 steps
go
package middleware
 
import (
	"crypto/hmac"

Verifying signed URLs with Gin middleware

hmac middleware authentication
Intermediate 8 steps