Code Explainers

Browse the library

php
<?php
 
namespace App\Console\Commands;
 

How a database backup command works in Laravel

artisan-command shell-process error-handling
Intermediate 8 steps
ruby
class WelcomeSequenceOrchestrator
  STEPS = [
    { mailer: :welcome_email,      delay: 0.hours },
    { mailer: :getting_started,    delay: 1.day },

Scheduling a drip email sequence in Rails

mailers background jobs scheduling
Intermediate 6 steps
typescript
import { Controller } from '@nestjs/common';
import {
  MessagePattern,
  Payload,

Manual RabbitMQ acks in a NestJS controller

microservices message-queue acknowledgement
Intermediate 8 steps
rust
use std::convert::TryFrom;
 
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HttpStatus {

Converting HTTP codes with TryFrom in Rust

enums error-handling trait-implementation
Intermediate 8 steps
python
import random
 
import click
from faker import Faker

Building a Flask seed command with Click

cli database seeding orm
Intermediate 7 steps
typescript
type LazyImageOptions = {
  rootMargin?: string;
  loadedClass?: string;
};

Lazy-loading images with IntersectionObserver

intersectionobserver lazy-loading performance
Intermediate 7 steps
rust
use axum::{
    extract::{Request, State},
    http::{HeaderValue, StatusCode},
    middleware::Next,

API version headers with Axum middleware

middleware http-headers versioning
Intermediate 8 steps
javascript
import { useState, useRef } from "react";
 
export function TagInput({ initialTags = [], onChange }) {
  const [tags, setTags] = useState(initialTags);

Building a tag input in React

controlled-inputs state-management keyboard-handling
Intermediate 8 steps
python
import smtplib
from email.message import EmailMessage
from threading import Thread
 

Sending welcome emails off the request thread in Flask

background-threads app-context email
Intermediate 8 steps
typescript
type DeepPartial<T> = T extends object
  ? { [K in keyof T]?: DeepPartial<T[K]> }
  : T;
 

Type-safe deep merge in TypeScript

recursion conditional-types mapped-types
Advanced 7 steps
rust
use axum::{
    extract::Path,
    http::StatusCode,
    routing::{get, post},

Building a REST resource in Axum

rest-api routing serialization
Intermediate 9 steps
javascript
import { NavLink, useLocation } from 'react-router-dom';
 
const NAV_ITEMS = [
  { to: '/', label: 'Dashboard', end: true },

Building an accessible Sidebar in React

routing accessibility declarative-ui
Intermediate 6 steps
php
function fuzzySearch(string $query, array $items, int $limit = 10): array
{
    $query = mb_strtolower(trim($query));
 

Building a ranked fuzzy search in PHP

fuzzy-search string-matching ranking
Intermediate 7 steps
python
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.shortcuts import get_object_or_404
from django.views.generic import DetailView
 

Team membership access control in Django

access-control mixins class-based-views
Intermediate 7 steps
typescript
type CurrencyFormatOptions = {
  locale?: string;
  currency: string;
  showDecimals?: boolean;

Caching Intl.NumberFormat for currency

memoization internationalization caching
Intermediate 9 steps
rust
use chrono::NaiveDate;
use serde::{Deserialize, Deserializer};
 
#[derive(Debug, Deserialize)]

Custom date parsing with serde in Rust

serde deserialization csv-parsing
Intermediate 7 steps
javascript
function escapeHtml(str) {
  return str.replace(/[&<>"']/g, (ch) => ({
    '&': '&amp;',
    '<': '&lt;',

Safely highlighting search matches in text

html-escaping regex search-highlighting
Intermediate 7 steps
php
<?php
 
namespace App\Models;
 

Debouncing Eloquent jobs in Laravel

debounce model-events queued-jobs
Advanced 7 steps