Code Explainers

Intermediate code explainers

python
from urllib.parse import urlparse, parse_qs
from dataclasses import dataclass, field
 
ALLOWED_SCHEMES = {"http", "https"}

Validating URLs into a safe endpoint in Python

input validation url parsing dataclasses
Intermediate 7 steps
php
final class BitmapGrid
{
    private SplFixedArray $cells;
 

A flat-array bitmap grid in PHP

data-structures row-major-order bitmap
Intermediate 7 steps
go
func handleUpload(w http.ResponseWriter, r *http.Request) {
	if err := r.ParseMultipartForm(32 << 20); err != nil {
		http.Error(w, "failed to parse form: "+err.Error(), http.StatusBadRequest)
		return

Handling multi-file uploads in Go

multipart file-upload http-handler
Intermediate 9 steps
typescript
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BullModule } from '@nestjs/bullmq';
 

How a NestJS feature module wires up

dependency-injection modularity orm
Intermediate 7 steps
python
from flask import Blueprint, render_template, request, redirect, url_for, flash
from werkzeug.security import check_password_hash
 
from .models import User, db

A change-email route in Flask

blueprints form-validation password-hashing
Intermediate 8 steps
ruby
class DatasetImportJob < ApplicationJob
  queue_as :default
 
  def perform(import)

Streaming import progress with a Rails job

background-jobs turbo-streams progress-tracking
Intermediate 9 steps
rust
use bytes::{Buf, BufMut, BytesMut};
use tokio_util::codec::{Decoder, Encoder};
 
const MAX_FRAME: usize = 8 * 1024 * 1024;

A length-prefixed frame codec in Tokio

framing codecs buffers
Intermediate 8 steps
php
namespace App\Http\Filters;
 
use Closure;
use Illuminate\Database\Eloquent\Builder;

Composable query filters with Laravel's Pipeline

pipeline query-builder single-responsibility
Intermediate 7 steps
go
package render
 
import (
	"net/http"

How Gin renders MsgPack responses

serialization content-type interface-implementation
Intermediate 5 steps
typescript
import {
  Controller,
  Get,
  Query,

Validating paginated queries in NestJS

pagination validation pipes
Intermediate 7 steps
rust
use axum::{
    body::{Body, Bytes},
    extract::Request,
    http::StatusCode,

Logging request bodies in Axum middleware

middleware streaming-body logging
Intermediate 8 steps
java
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;

Ranking the most frequent words in Java

streams regex grouping
Intermediate 7 steps
ruby
class Booking < ApplicationRecord
  belongs_to :room
  belongs_to :guest
 

Guarding booking dates in a Rails model

validations associations scopes
Intermediate 5 steps
python
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

Testing FastAPI routes with dependency overrides

testing fixtures dependency-injection
Intermediate 7 steps
javascript
import { createContext, useContext, useState, useId } from "react";
 
const AccordionContext = createContext(null);
const ItemContext = createContext(null);

Building a compound Accordion in React

context compound-components state-management
Intermediate 8 steps
php
namespace App\Providers;
 
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;

Adding a whereActive macro in Laravel

macros service-provider query-builder
Intermediate 5 steps
go
package proxy
 
import (
	"log"

Building a hardened Go reverse proxy

reverse-proxy http timeouts
Intermediate 7 steps
rust
use std::time::Duration;
 
use axum::{
    body::Body,

Turning Axum timeouts into 504 JSON

middleware timeouts error-handling
Intermediate 7 steps