Code Explainers

Browse the library

go
package handlers
 
import (
	"net/http"

Struct-level validation for partial updates in Gin

validation struct-tags partial-update
Intermediate 7 steps
python
from decimal import Decimal
 
from django.db import transaction
from django.core.exceptions import ValidationError

Placing an order atomically in Django

transactions row-locking concurrency
Advanced 9 steps
typescript
import {
  Controller,
  Post,
  Headers,

Verifying Stripe webhooks in NestJS

webhooks signature-verification event-handling
Intermediate 7 steps
javascript
function makeTableSorter(rows) {
  const state = { key: null, dir: 1 };
 
  const compareBy = (key) => (a, b) => {

Building a stateful table sorter in JavaScript

closures stable-sort comparators
Intermediate 7 steps
rust
use std::fmt;
 
#[derive(Debug)]
pub enum ConfigError {

Building a custom error type in Rust

error-handling enums trait-implementation
Intermediate 9 steps
java
@RestController
@RequestMapping("/api/products")
@RequiredArgsConstructor
public class ProductSearchController {

Binding paged search filters in Spring

data-binding validation pagination
Intermediate 7 steps
go
package fetcher
 
import (
	"context"

Bounded-concurrency HTTP fetching in Go

concurrency semaphore context-cancellation
Advanced 9 steps
python
import os
from dataclasses import dataclass
from functools import lru_cache
 

Loading typed config from environment variables

configuration environment-variables type-coercion
Intermediate 6 steps
javascript
function createAutocomplete(input, resultsList, { minChars = 2, delay = 300 } = {}) {
  let timer = null;
  let controller = null;
 

Building a debounced autocomplete widget

debouncing abortcontroller closures
Intermediate 9 steps
rust
use axum::{
    async_trait,
    extract::{rejection::JsonRejection, FromRequest, Request},
    http::StatusCode,

A validating JSON extractor in Axum

extractors validation error-handling
Intermediate 7 steps
java
@DataJpaTest
@Testcontainers
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class OrderRepositoryIT {

Testing a JPA repository against real Postgres in Spring

integration-testing testcontainers jpa
Intermediate 8 steps
go
package inventory
 
import (
	"encoding/csv"

Parsing CSV into typed structs in Go

csv-parsing error-wrapping type-conversion
Intermediate 8 steps
php
<?php
 
namespace App\Services;
 

Placing an order atomically in Laravel

transactions pessimistic-locking concurrency
Advanced 8 steps
python
import hashlib
from pathlib import Path
 
 

Streaming SHA-256 checksums in Python

hashing file-io streaming
Intermediate 6 steps
typescript
type JsonValue = Record<string, unknown> | unknown[];
 
export function parseJsonStream<T = JsonValue>(
  stream: ReadableStream<Uint8Array>,

Streaming JSON parsing with a depth counter

streams parsing state-machine
Advanced 9 steps
ruby
class ContactImporter
  def initialize(rows)
    @rows = rows
  end

Deduplicating contacts with Enumerable#uniq

deduplication normalization enumerable
Intermediate 4 steps
php
<?php
 
namespace App\Database;
 

Building a fluent SQL query builder in PHP

fluent-interface method-chaining sql
Intermediate 10 steps
java
@Aspect
@Component
public class IdempotencyAspect {
 

How an idempotency aspect works in Spring

aop idempotency caching
Advanced 9 steps