Code Explainers

Intermediate code explainers

javascript
import { NextResponse } from 'next/server';
import { readFile, stat } from 'node:fs/promises';
import { join, extname, normalize } from 'node:path';
import { createHash } from 'node:crypto';

Serving private assets from a Next.js route

path-traversal http-caching etag
Intermediate 6 steps
ruby
module WifiQrCode
  ESCAPE_CHARS = /([\\;,:"])/.freeze
 
  AUTH_TYPES = {

Building a Wi-Fi QR code payload in Ruby

string-formatting validation escaping
Intermediate 9 steps
java
public final class IniParser {
 
    private static final Pattern SECTION = Pattern.compile("\\[(.+?)\\]");
 

Parsing INI files in Java

parsing regex state-machine
Intermediate 10 steps
php
<?php
 
namespace App\Models;
 

Auto-generating unique slugs in Laravel

eloquent model-events slugs
Intermediate 8 steps
typescript
type CompactOptions = {
  locale?: string;
  maximumFractionDigits?: number;
};

Caching Intl.NumberFormat for compact numbers

memoization internationalization caching
Intermediate 7 steps
rust
use rand::Rng;
 
#[derive(Debug)]
pub struct WeightedChoice<T> {

Weighted random sampling in Rust

weighted-sampling generics binary-search
Intermediate 7 steps
javascript
export default function DashboardLayout({ children, analytics, notifications }) {
  return (
    <div className="flex h-screen overflow-hidden">
      <Sidebar />

Parallel routes in a Next.js layout

parallel-routes layouts app-router
Intermediate 8 steps
go
package middleware
 
import (
	"crypto/subtle"

Timing-safe API key auth in Gin

middleware authentication constant-time-compare
Intermediate 8 steps
ruby
require "nokogiri"
require "open-uri"
require "set"
 

Extracting and normalizing links in Ruby

web-scraping url-parsing html-parsing
Intermediate 8 steps
java
@Component
public class ApiKeyRotationFilter extends OncePerRequestFilter {
 
    private static final String API_KEY_HEADER = "X-Api-Key";

Building an API key rotation filter in Spring

servlet-filter authentication caching
Intermediate 10 steps
go
package handlers
 
import (
	"context"

A custom Gin validator backed by Redis

validation redis struct-tags
Intermediate 8 steps
python
class TrieNode:
    __slots__ = ("children", "is_word")
 
    def __init__(self):

Building a prefix trie in Python

trie tree-traversal recursion
Intermediate 7 steps
javascript
function flatten(obj, prefix = '', result = {}) {
  for (const [key, value] of Object.entries(obj)) {
    const path = prefix ? `${prefix}.${key}` : key;
 

Flattening nested objects into dotted paths

recursion object-traversal accumulator
Intermediate 6 steps
php
namespace App\Console\Commands;
 
use App\Models\Region;
use App\Services\ReportBuilder;

How a Laravel command warms report caches

caching cache-warming artisan-command
Intermediate 5 steps
ruby
require "yaml"
require "date"
 
class Money

Custom YAML serialization in Ruby

serialization yaml custom-encoding
Intermediate 7 steps
java
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
public class AuditingConfig {
 

Automatic audit trails with Spring Data JPA

jpa-auditing security-context entity-listeners
Intermediate 7 steps
rust
use std::collections::BTreeSet;
 
#[derive(Debug)]
pub enum FieldError {

Parsing a cron field in Rust

parsing error-handling enums
Intermediate 7 steps
go
package trie
 
import "sort"
 

Building a frequency-ranked autocomplete trie in Go

trie autocomplete recursion
Intermediate 9 steps