Code Explainers

Browse the library

rust
use std::fmt;
 
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Money {

Formatting money with Rust's Display trait

trait-implementation integer-arithmetic enums
Intermediate 10 steps
typescript
import { useEffect, useRef, useCallback } from "react";
 
type DraftPayload = Record<string, unknown>;
 

A debounced auto-save hook in React

debouncing request-cancellation refs
Advanced 7 steps
go
package search
 
import (
	"net/url"

Building a query URL from a Filter struct in Go

url-encoding struct-methods input-validation
Intermediate 8 steps
javascript
import Link from "next/link";
import { prisma } from "@/lib/prisma";
 
const PAGE_SIZE = 20;

A searchable, paginated table as a Next.js Server Component

server-components pagination search
Intermediate 6 steps
python
import ijson
from decimal import Decimal
 
 

Streaming JSON aggregation with ijson

streaming json-parsing generators
Intermediate 7 steps
ruby
module Instrumentation
  module Timing
    def self.[](*method_names)
      Module.new do

Timing methods with a prepended module in Ruby in Rails

metaprogramming prepend instrumentation
Advanced 7 steps
php
<?php
 
namespace App\Http\Controllers;
 

Time-limited signed download links in Laravel

signed urls authorization file streaming
Intermediate 6 steps
java
public final class ListPartitioner {
 
    private ListPartitioner() {
    }

Splitting a list into fixed-size chunks in Java

generics partitioning streams
Intermediate 8 steps
rust
use std::collections::HashSet;
use std::io::{self, BufRead, BufWriter, Write};
 
fn main() -> io::Result<()> {

Filtering duplicate lines in Rust

stdin hashset buffering
Beginner 5 steps
typescript
type Curried<A extends any[], R> = A extends [infer First, ...infer Rest]
  ? (arg: First) => Rest extends [] ? R : Curried<Rest, R>
  : R;
 

Type-safe currying in TypeScript

currying conditional-types recursion
Advanced 8 steps
go
package handlers
 
import (
	"net/http"

Content negotiation in Gin handlers

content-negotiation struct-tags rest-api
Intermediate 4 steps
javascript
import { Suspense } from 'react';
import { getProducts } from '@/lib/api/products';
import { formatPrice } from '@/lib/format';
 

Streaming a product list with Suspense in Next.js

server-components suspense streaming
Intermediate 8 steps
python
import os
import uuid
 
from flask import Blueprint, current_app, jsonify, request

Handling secure file uploads in Flask

file-upload validation blueprints
Intermediate 8 steps
php
<?php
 
namespace App\Http\Requests;
 

Normalizing input in a Laravel FormRequest

validation authorization input-normalization
Intermediate 6 steps
java
package com.example.orders.messaging;
 
import com.example.orders.dto.OrderEvent;
import com.example.orders.service.OrderProcessingService;

Manual RabbitMQ acks in a Spring listener

message-queue error-handling acknowledgement
Intermediate 6 steps
rust
use axum::{extract::{Query, State}, http::StatusCode, Json};
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;

Cursor pagination in an Axum handler

cursor-pagination keyset-pagination base64
Advanced 10 steps
php
<?php
 
namespace App\Http;
 

Building an onion middleware pipeline in PHP

middleware closures array-reduce
Advanced 9 steps
java
package com.example.shop.repository;
 
import com.example.shop.domain.Order;
import com.example.shop.domain.OrderStatus;

Deriving JPA queries from method names in Spring

query derivation repositories pagination
Intermediate 8 steps