Code Explainers
Browse the library
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
java
import java.time.Duration; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture;
A safe recurring heartbeat scheduler in Java
concurrency
scheduling
thread-safety
Intermediate
6 steps
javascript
function initLazyLoad(root = document) { const images = root.querySelectorAll('img[data-src]'); if (!('IntersectionObserver' in window)) {
How lazy image loading works
lazy-loading
intersectionobserver
progressive-enhancement
Intermediate
8 steps
go
package main import ( "bufio"
Counting matching lines in Go with bufio
file-io
buffered-scanning
error-handling
Intermediate
4 steps
ruby
class EventEmitter def initialize @listeners = Hash.new { |hash, key| hash[key] = [] } end
Building an EventEmitter in Ruby
pub-sub
closures
callbacks
Intermediate
7 steps
python
from flask import Blueprint, render_template, request, abort from sqlalchemy import select from .models import Article
Paginating articles in a Flask Blueprint
pagination
blueprints
input-validation
Intermediate
6 steps
javascript
import { notFound } from 'next/navigation'; const PER_PAGE = 24; const SORT_OPTIONS = ['relevance', 'price-asc', 'price-desc', 'newest'];
Parsing search params in a Next.js page
input-validation
query-params
pagination
Intermediate
10 steps
go
package collection func Deduplicate[T comparable](items []T) []T { seen := make(map[T]struct{}, len(items))
Generic deduplication in Go
generics
deduplication
maps
Intermediate
5 steps
ruby
require 'optparse' require 'ostruct' def parse_options(argv)
Parsing CLI options with OptionParser
cli
argument-parsing
validation
Intermediate
8 steps
rust
use axum::{extract::Form, http::StatusCode, response::{IntoResponse, Response}, Json}; use serde::Deserialize; use serde_json::json; use std::collections::HashMap;
Validating a signup form in Axum
form-validation
deserialization
error-handling
Intermediate
8 steps