streaming

rust
use std::collections::VecDeque;

pub struct RollingAverage {
    buf: VecDeque<f64>,
    capacity: usize,
    sum: f64,

Rolling Average Over a Sliding Window of Sensor Readings in Rust

rust sliding-window streaming
by codesnips 2 tabs
rust
use std::time::{Duration, Instant};

pub struct LeakyBucket {
    level: f64,
    capacity: f64,
    rate_per_sec: f64,

Leaky-Bucket Rate Shaper for a Tokio Message Consumer

rate-limiting leaky-bucket backpressure
by codesnips 3 tabs
python
from sqlalchemy import select

from .models import Order, db


def stream_orders(batch_size=1000):

Stream a Large CSV Export in Flask With a Generator Response

flask streaming csv
by codesnips 3 tabs
rust
use std::path::{Component, Path, PathBuf};

#[derive(Debug)]
pub enum ResolveError {
    Traversal,
    NotFound,

Safely Serving Static Files with Path Traversal Protection in Rust

rust axum tokio
by codesnips 3 tabs
ruby
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user

ActionCable channel that streams Turbo updates safely

rails hotwire turbo
by codesnips 4 tabs
python
import os
import uuid

from flask import Blueprint, current_app, jsonify, request
from werkzeug.exceptions import RequestEntityTooLarge

Streaming Large Multipart File Uploads to Disk in Flask Without Buffering

flask werkzeug streaming
by codesnips 3 tabs
go
package feed

import "time"

type Event struct {
	ID        string    `json:"id"`

Stream and Decode Newline-Delimited JSON (NDJSON) from an HTTP Response Body in Go

go ndjson streaming
by codesnips 3 tabs
java
@RestController
@RequestMapping("/api/transactions")
public class TransactionExportController {

    private final CsvExportService exportService;

Stream a Large CSV Export to the HTTP Response with StreamingResponseBody in Spring Boot

spring-boot streaming csv
by codesnips 3 tabs
javascript
function parseRange(header, size) {
  if (!header || !header.startsWith('bytes=')) return null;

  const [rawStart, rawEnd] = header.replace('bytes=', '').split('-');
  let start;
  let end;

HTTP Range Requests for Video Streaming in Node.js With fs.createReadStream

nodejs http streaming
by codesnips 3 tabs
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

Serve Purchased Downloads Behind Signed Temporary URLs in Laravel

laravel eloquent signed-urls
by codesnips 4 tabs
python
import csv


class _LineBuffer:
    def __init__(self):
        self._data = ""

Stream a Large CSV Export in Chunks from a Flask Endpoint

flask streaming csv
by codesnips 3 tabs
go
package metrics

import "time"

type bucket struct {
	start time.Time

Time-Bucketed Metric Aggregation With a Concurrent Ring of Windows in Go

go metrics time-series
by codesnips 3 tabs