Code Explainers

Browse the library

go
package middleware
 
import (
	"errors"

Centralized error handling in Gin

middleware error-handling custom-errors
Intermediate 8 steps
typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, shareReplay } from 'rxjs';
 

Caching HTTP config in an Angular service

caching observables dependency-injection
Intermediate 6 steps
rust
use axum::{
    extract::{Path, State},
    routing::{get, post},
    Json, Router,

Building a nested REST API router in Axum

routing extractors shared-state
Intermediate 8 steps
python
import os
import tempfile
from pathlib import Path
from typing import Union

How atomic file writes work in Python

atomicity filesystem durability
Advanced 7 steps
php
<?php
 
namespace App\Console;
 

How task scheduling works in Laravel

scheduling cron fluent-api
Intermediate 7 steps
javascript
import { useState, useEffect } from "react";
 
export function useUser(userId) {
  const [user, setUser] = useState(null);

How a data-fetching hook works in React

custom-hooks data-fetching abortcontroller
Intermediate 8 steps
php
<?php
 
namespace App\Policies;
 

How authorization policies gate updates in Laravel

authorization policies access control
Intermediate 7 steps
typescript
import {
  CACHE_MANAGER,
  CacheInterceptor,
} from '@nestjs/cache-manager';

A tenant-aware HTTP cache in NestJS

caching interceptors multi-tenancy
Intermediate 7 steps
java
@RestController
@RequestMapping("/api/products")
public class ProductController {
 

How a paginated REST controller works in Spring

pagination dto-mapping dependency-injection
Intermediate 8 steps
python
import re
from datetime import datetime
from dataclasses import dataclass
 

Parsing access logs with named regex groups

regex named-groups dataclasses
Intermediate 6 steps
php
<?php
 
final class ProductRepository
{

Safe SQL pagination with PDO in PHP

pagination input-validation prepared-statements
Intermediate 7 steps
rust
use axum::{
    extract::State,
    http::StatusCode,
    response::IntoResponse,

An async job queue handler in Axum

background-jobs async http-202
Intermediate 9 steps
ruby
module TextAnalysis
  module_function
 
  WORD_PATTERN = /[\p{Alpha}']+/

Building a word-frequency analyzer in Ruby

text processing regex enumerable
Intermediate 8 steps
go
package debounce
 
import (
	"sync"

Building a debouncer in Go

concurrency debounce timers
Intermediate 6 steps
typescript
import { useState, useEffect, useRef, useCallback } from "react";
 
interface SearchResult {
  id: string;

A debounced search hook in React

debounce custom-hooks abortcontroller
Intermediate 7 steps
java
@WebMvcTest(OrderController.class)
class OrderControllerTest {
 
    @Autowired

Slice testing a controller with @WebMvcTest in Spring

testing mocking http
Intermediate 8 steps
python
import gzip
from pathlib import Path
from typing import Iterator
 

Streaming TSV records with Python generators

generators lazy-evaluation file-io
Intermediate 5 steps
php
<?php
 
namespace App\Http\Requests;
 

How a Laravel FormRequest validates input

validation form-request input-sanitization
Intermediate 6 steps