Code Explainers

Browse the library

python
import uuid
from pathlib import Path
 
from fastapi import APIRouter, File, Form, HTTPException, UploadFile

Handling multipart file uploads in FastAPI

file-upload validation multipart-form
Intermediate 6 steps
typescript
import { Component, ChangeDetectionStrategy } from '@angular/core';
 
@Component({
  selector: 'app-card',

Multi-slot content projection in Angular

content-projection components templates
Intermediate 7 steps
rust
use axum::{extract::State, http::StatusCode, Json};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use uuid::Uuid;

An atomic money transfer handler in Axum

database-transactions atomicity error-handling
Intermediate 9 steps
go
package security
 
import (
	"crypto/hmac"

Signing and verifying payloads with HMAC in Go

hmac cryptography authentication
Intermediate 5 steps
typescript
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, DeepPartial } from 'typeorm';
import { User } from './entities/user.entity';

Building a CRUD service in NestJS

crud dependency-injection repository-pattern
Intermediate 7 steps
python
from copy import deepcopy
from typing import Any, Mapping
 
 

How a recursive deep merge works in Python

recursion immutability dictionaries
Intermediate 6 steps
rust
use std::sync::Arc;
use std::time::Duration;
 
use axum::{

Long-polling with Axum and Tokio Notify

long-polling concurrency shared-state
Advanced 8 steps
php
<?php
 
namespace App\Http\Controllers\Api;
 

Cursor pagination in a Laravel API

pagination cursor keyset
Intermediate 9 steps
javascript
import { useEffect, useRef } from "react";
import { useBlocker } from "react-router-dom";
 
export function useUnsavedChangesPrompt(isDirty, message = "You have unsaved changes. Leave anyway?") {

Guarding unsaved changes with a React hook

custom-hooks navigation-guard event-listeners
Intermediate 7 steps
go
package handlers
 
import (
	"context"

Liveness vs readiness health checks in Gin

health-checks dependency-injection context-timeout
Intermediate 7 steps
typescript
type AsyncMethod = (...args: any[]) => Promise<any>;
 
function LogExecutionTime(thresholdMs = 0) {
  return function <T extends AsyncMethod>(

A method decorator that times async calls

decorators higher-order-functions async
Advanced 9 steps
python
from difflib import SequenceMatcher
from bisect import bisect_left, bisect_right
 
 

Building a fuzzy autocomplete matcher

fuzzy-matching binary-search ranking
Intermediate 9 steps
rust
use axum::{
    body::Body,
    http::{header, HeaderValue, StatusCode, Uri},
    response::{IntoResponse, Response},

Serving embedded static files in Axum

static-assets embedding http-headers
Intermediate 7 steps
php
<?php
 
namespace App\Queue;
 

A stable priority job queue in PHP

priority-queue data-structures closures
Intermediate 8 steps
javascript
function deepFreeze(obj) {
  const propNames = Reflect.ownKeys(obj);
 
  for (const name of propNames) {

Recursively freezing a nested object

recursion immutability object-freezing
Intermediate 6 steps
go
package handlers
 
import (
	"net/http"

Custom query validation in Gin

validation query-binding deduplication
Intermediate 8 steps
typescript
import { Controller, Get, Param, Query, Redirect, NotFoundException } from '@nestjs/common';
import { LinksService } from './links.service';
 
@Controller('links')

Handling HTTP redirects in NestJS

redirects routing decorators
Intermediate 7 steps
python
import secrets
from datetime import datetime, timedelta, timezone
 
from fastapi import APIRouter, Cookie, Depends, HTTPException, Response, status

Cookie session auth in FastAPI

session-authentication cookies dependency-injection
Intermediate 8 steps