Code Explainers

Browse the library

php
<?php
 
namespace App\Providers;
 

Defining feature flags with Laravel Pennant

feature-flags service-provider config-driven
Intermediate 6 steps
typescript
import { Directive, EventEmitter, HostListener, Input, Output } from '@angular/core';
 
interface Shortcut {
  key: string;

A keyboard shortcut directive in Angular

directives event-handling keyboard-shortcuts
Intermediate 9 steps
go
package handler
 
import (
	"net/http"

Custom time validation in Gin

validation request-binding struct-tags
Intermediate 8 steps
python
from pathlib import Path
 
from django.contrib.auth.decorators import login_required
from django.http import FileResponse, Http404, HttpResponseForbidden

Serving files with access checks in Django

authorization http-caching file-serving
Intermediate 7 steps
rust
use once_cell::sync::Lazy;
use regex::Regex;
 
static LOG_LINE: Lazy<Regex> = Lazy::new(|| {

Parsing access logs with a lazy regex in Rust

regex lazy-initialization parsing
Intermediate 7 steps
java
public class RequestCoalescer<K, V> {
 
    private final ConcurrentHashMap<K, CompletableFuture<V>> inFlight = new ConcurrentHashMap<>();
    private final Function<K, V> loader;

Coalescing duplicate requests in Java

concurrency caching completablefuture
Advanced 6 steps
javascript
import { useState, useRef, useCallback } from "react";
 
export function MultiSelect({ options, value, onChange, placeholder = "Select…" }) {
  const [open, setOpen] = useState(false);

Building a keyboard-accessible MultiSelect in React

controlled-component accessibility keyboard-navigation
Intermediate 10 steps
java
public final class NaturalOrderComparator implements Comparator<String> {
 
    public static final NaturalOrderComparator INSTANCE = new NaturalOrderComparator();
 

Natural-order string sorting in Java

comparator natural-sort string-parsing
Intermediate 9 steps
rust
use axum::{
    extract::State,
    response::sse::{Event, KeepAlive, Sse},
    Json,

Proxying an SSE chat stream in Axum

server-sent-events streaming async-generators
Advanced 10 steps
go
package middleware
 
import (
	"net/http"

Localized validation errors in Gin

middleware internationalization validation
Intermediate 8 steps
php
<?php
 
namespace App\Http\Controllers;
 

Email confirmation with signed URLs in Laravel

signed-urls email-verification middleware
Intermediate 6 steps
typescript
import { Component, computed, signal } from '@angular/core';
import { CdkTableModule } from '@angular/cdk/table';
import { CdkScrollableModule } from '@angular/cdk/scrolling';
 

Paginating a CDK table with Angular signals

signals computed-state pagination
Intermediate 9 steps
ruby
require "csv"
 
class CsvExporter
  def initialize(records, columns: nil)

Turning records into CSV in Ruby

csv data-export serialization
Intermediate 7 steps
javascript
async function uploadInBatches(records, uploadFn, { batchSize = 100, concurrency = 3 } = {}) {
  const batches = [];
  for (let i = 0; i < records.length; i += batchSize) {
    batches.push(records.slice(i, i + batchSize));

Uploading records with bounded concurrency

concurrency worker-pool async-await
Advanced 8 steps
python
from copy import deepcopy
 
 
class CowSnapshot:

Copy-on-write attribute snapshots in Python

copy-on-write descriptors attribute-interception
Advanced 7 steps
java
package com.example.validation;
 
import java.util.List;
import java.util.stream.Collectors;

Validating JSON payloads against a schema in Java

json-schema validation recursion
Intermediate 8 steps
rust
use std::collections::HashMap;
 
fn decode_component(input: &str) -> String {
    let bytes = input.as_bytes();

Parsing a URL query string in Rust

url-encoding byte-parsing iterators
Intermediate 8 steps
go
func ListProducts(c *gin.Context) {
	allowed := map[string]string{
		"category": "category",
		"brand":    "brand",

Safe query filtering in a Gin handler

input-validation whitelisting query-building
Intermediate 7 steps