Code Explainers

Browse the library

rust
use axum::{
    async_trait,
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},

Idempotent payments with an Axum extractor

idempotency extractors shared-state
Intermediate 8 steps
go
package middleware
 
import (
	"bytes"

Building a response cache middleware in Gin

middleware caching concurrency
Intermediate 8 steps
java
public final class AesGcmCipher {
 
    private static final String TRANSFORMATION = "AES/GCM/NoPadding";
    private static final int GCM_TAG_BITS = 128;

Authenticated encryption with AES-GCM in Java

cryptography aes-gcm authenticated-encryption
Intermediate 7 steps
typescript
import {
  Injectable,
  NestInterceptor,
  ExecutionContext,

A per-route timeout interceptor in NestJS

interceptors metadata reflection rxjs
Intermediate 8 steps
javascript
class TokenBucket {
  constructor({ capacity, refillPerSecond }) {
    this.capacity = capacity;
    this.refillPerSecond = refillPerSecond;

How token-bucket rate limiting works in Express

rate-limiting token-bucket middleware
Intermediate 7 steps
ruby
class DigestMailer < ApplicationMailer
  default from: "notifications@example.com"
 
  def weekly_digest(user)

Building a weekly digest email in Rails

mailers active-record query-scopes
Intermediate 6 steps
python
from pathlib import Path
 
import chardet
 

Reading text files of unknown encoding in Python

encoding byte-order-mark fallback
Intermediate 8 steps
php
<?php
 
namespace App\Support;
 

How TOTP codes are generated in PHP

totp hmac two-factor-auth
Advanced 7 steps
rust
use std::time::Duration;
 
use axum::{
    extract::State,

Rate-limiting an expensive Axum route with tower

middleware concurrency-limiting shared-state
Intermediate 9 steps
go
package archive
 
import (
	"bytes"

Gzip round-trip compression in Go

compression io error-handling
Intermediate 5 steps
java
@RestController
@RequestMapping("/api/notifications")
public class NotificationStreamController {
 

Server-Sent Events per user in Spring

server-sent-events concurrency event-driven
Advanced 8 steps
typescript
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import {
  Observable,

A city autocomplete service in Angular

rxjs observables debouncing
Intermediate 7 steps
rust
use axum::{
    extract::State,
    http::{header, HeaderMap, StatusCode},
    response::{IntoResponse, Response},

Conditional GET caching in Axum

http-caching conditional-requests extractors
Intermediate 7 steps
go
package handlers
 
import (
	"encoding/json"

Hardening JSON decoding in Go HTTP handlers

json error-handling http
Intermediate 8 steps
php
<?php
 
namespace App\Http\Middleware;
 

ETag caching and gzip in Laravel middleware

middleware http-caching etag
Intermediate 8 steps
ruby
class OrdersController < ApplicationController
  rescue_from ActiveRecord::RecordNotUnique, with: :handle_duplicate_submission
 
  def create

Idempotent order creation in Rails

idempotency database-constraints error-handling
Intermediate 8 steps
java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

Compressing byte arrays with GZIP in Java

compression streams try-with-resources
Intermediate 6 steps
python
from flask import Blueprint, jsonify, request, abort
from flask_caching import Cache
 
cache = Cache(config={"CACHE_TYPE": "RedisCache", "CACHE_REDIS_URL": "redis://localhost:6379/0"})

Custom cache keys for Flask endpoints

caching redis cache-invalidation
Intermediate 7 steps