Code Explainers
Browse the library
typescript
import { Controller, Get, Param, Post, Body, Version, VERSION_NEUTRAL } from '@nestjs/common'; import { UsersService } from './users.service'; import { CreateUserDto } from './dto/create-user.dto';
How API versioning works in NestJS
api-versioning
routing
dependency-injection
Intermediate
9 steps
javascript
import { useState, useRef, useCallback, useLayoutEffect } from "react"; export function useResizeObserver({ debounce = 0 } = {}) { const [size, setSize] = useState({ width: 0, height: 0 });
A resize-observing hook in React
custom-hook
resizeobserver
callback-ref
Advanced
8 steps
rust
use std::io::{BufRead, BufReader}; use std::process::{Command, Stdio}; #[derive(Debug)]
Parsing ps output into structs in Rust
subprocess
parsing
iterators
Intermediate
8 steps
go
package handlers import ( "net/http"
Validating query params with Gin binding tags
validation
struct-tags
pagination
Intermediate
8 steps
php
<?php namespace App\Http\Resources;
Shaping API JSON with a Laravel Resource
api
serialization
data transformation
Intermediate
7 steps
ruby
class InventoryItem < ApplicationRecord belongs_to :warehouse validates :quantity, numericality: { greater_than_or_equal_to: 0 }
Safe inventory updates in Rails
concurrency
pessimistic-locking
optimistic-locking
Advanced
7 steps
java
package com.example.inventory; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser;
Reading and writing CSV with Commons CSV
csv-parsing
file-io
try-with-resources
Intermediate
7 steps
python
from fastapi import APIRouter, FastAPI, HTTPException from pydantic import BaseModel
Versioning a FastAPI API with mounted sub-apps
api-versioning
response-models
sub-applications
Intermediate
6 steps
typescript
import { HttpService } from '@nestjs/axios'; import { Injectable, Logger, ServiceUnavailableException } from '@nestjs/common'; import { AxiosError } from 'axios'; import { catchError, firstValueFrom, retry, timer } from 'rxjs';
Resilient payment retries in NestJS
retry
exponential-backoff
rxjs
Advanced
8 steps
javascript
import { useState } from "react"; const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Building a validated signup form in React
form-validation
controlled-components
state-management
Intermediate
10 steps
go
package api import ( "encoding/json"
Building reusable JSON helpers in Go HTTP handlers
http
json
error-handling
Intermediate
9 steps
java
package com.example.security; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec;
Salted password hashing with PBKDF2 in Java
password-hashing
pbkdf2
salting
Intermediate
7 steps
typescript
interface PaginationParams { totalItems: number; pageSize: number; currentPage: number;
Building safe pagination metadata in TypeScript
pagination
input-validation
pure-functions
Intermediate
7 steps
php
final class DebouncedSessionStore { private array $pending = []; private array $timers = [];
Debouncing session writes with an event loop
debounce
event-loop
atomic-write
Advanced
9 steps
ruby
require "forwardable" class ShoppingCart extend Forwardable
Delegation in Ruby with Forwardable
delegation
composition
enumerable
Intermediate
9 steps
javascript
import { useRef, useState, useCallback, useMemo } from 'react'; export function VirtualList({ items, rowHeight = 40, height = 600, overscan = 5, renderRow }) { const [scrollTop, setScrollTop] = useState(0);
How a virtualized list works in React
virtualization
performance
memoization
Intermediate
8 steps
rust
use axum::{ routing::get, Json, Router, };
Response compression in Axum with tower-http
middleware
compression
http
Intermediate
6 steps
go
package server import ( "net/http"
Serving cached static assets in Gin
caching
static-files
middleware
Intermediate
7 steps