Code Explainers
Code explainers tagged #streaming
python
import random from typing import Iterator, List
How reservoir sampling picks k items
reservoir-sampling
streaming
randomness
Intermediate
5 steps
javascript
const express = require('express'); const router = express.Router(); router.get('/exports/orders', async (req, res) => {
Streaming a large JSON export in Express
streaming
backpressure
cursors
Advanced
9 steps
javascript
const fs = require('fs'); const path = require('path'); const express = require('express');
Streaming video with HTTP range requests in Express
http-range-requests
streaming
path-traversal
Intermediate
8 steps
java
public final class ChunkSorter { private static final int MAX_LINES_PER_CHUNK = 100_000;
External merge sort in Java
external-sort
merge-sort
priority-queue
Advanced
10 steps
go
func StreamLogs(c *gin.Context) { path := c.Query("file") if path == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "missing file parameter"})
Streaming a live log tail with SSE in Gin
server-sent-events
streaming
channels
Advanced
10 steps
php
<?php function streamFileWithRanges(string $path, ?string $rangeHeader): void {
How HTTP range requests stream files in PHP
http-range-requests
streaming
partial-content
Intermediate
10 steps
python
import os import re from flask import Blueprint, request, Response, abort
HTTP range requests for video streaming in Flask
http-range-requests
streaming
generators
Intermediate
8 steps
go
func ServeThumbnail(c *gin.Context) { raw := c.Param("token") sig := c.Query("sig")
A signed thumbnail endpoint in Gin
signed-urls
image-processing
http-handler
Intermediate
9 steps
javascript
import OpenAI from 'openai'; const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
Streaming OpenAI tokens from a Next.js edge route
streaming
edge-runtime
readablestream
Advanced
9 steps
go
func (h *ReportHandler) ExportTransactions(w http.ResponseWriter, r *http.Request) { ctx := r.Context() from, to, err := parseDateRange(r.URL.Query())
Streaming a CSV export in Go
streaming
http
csv
Intermediate
8 steps
rust
use axum::{ body::Body, extract::State, http::{header, StatusCode},
Streaming a DB migration with Axum
streaming
keyset-pagination
backpressure
Advanced
8 steps
python
import heapq class MovingMedian:
Running median with two heaps
heaps
streaming
invariants
Advanced
8 steps
typescript
interface RunningStats { count: number; total: number; average: number;
Streaming running averages in TypeScript
generators
streaming
incremental-aggregation
Intermediate
6 steps
go
package logparse import ( "bufio"
Splitting multi-line logs with a Scanner
parsing
streaming
bufio
Intermediate
9 steps
python
import hashlib from collections import defaultdict from pathlib import Path
Finding duplicate files by size then hash
hashing
file-io
deduplication
Intermediate
7 steps
javascript
import { NextResponse } from 'next/server'; import { db } from '@/lib/db'; function csvCell(value) {
Streaming a CSV export in a Next.js route
streaming
csv
readablestream
Advanced
9 steps
javascript
class MovingAverage { constructor(windowSize) { if (!Number.isInteger(windowSize) || windowSize <= 0) { throw new RangeError('windowSize must be a positive integer');
A rolling average over a fixed window
circular-buffer
streaming
async-generators
Intermediate
7 steps
javascript
import { Suspense } from 'react'; import { searchProducts } from '@/lib/products'; import SearchInput from './search-input';
Streaming search results in a Next.js Server Component
server-components
suspense
streaming
Intermediate
8 steps