javascript
const express = require('express');
const multer = require('multer');
const os = require('os');
const fs = require('fs/promises');
const { parseCsvStream } = require('./csvStreamParser');

Stream and Validate Large CSV Uploads Row-by-Row with Node Streams and Backpressure

nodejs streams csv
by codesnips 3 tabs
go
package authtransport

import (
	"errors"
	"net/http"
)

Injecting Auth Headers via a Custom http.RoundTripper Decorator in Go

go http middleware
by codesnips 3 tabs
ruby
require 'set'
require 'json'

class Broadcaster
  def initialize
    @mutex = Mutex.new

Stream Server-Sent Events from a Sinatra Route With Keep-Alive Pings

sinatra sse streaming
by codesnips 3 tabs
ruby
class Cart < ApplicationRecord
  belongs_to :user, optional: true
  has_many :cart_items, dependent: :destroy

  scope :for_session, ->(token) { where(session_token: token) }
  scope :active, -> { where(merged_at: nil) }

Merge a Guest Cart Into a User's Cart on Login With a Rails Service Object

rails service-object devise
by codesnips 3 tabs
python
import asyncio
from typing import Awaitable, Callable, Dict, TypeVar

T = TypeVar("T")

Coalesce Duplicate In-Flight Requests with an Asyncio Single-Flight Cache

asyncio concurrency caching
by codesnips 3 tabs
typescript
export interface CartItem {
  id: string;
  name: string;
  price: number;
  quantity: number;
}

Type-Safe Shopping Cart with useReducer, Context, and a useCart Hook

react context usereducer
by codesnips 4 tabs
javascript
const fs = require('fs');
const readline = require('readline');

async function* streamCsvRows(filePath) {
  const stream = fs.createReadStream(filePath, { encoding: 'utf8' });
  const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });

Stream and Import a Large CSV File Line-by-Line with Node.js readline

nodejs streams readline
by codesnips 3 tabs
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

Queued Saved-Search Digest Emails for New Listings in Laravel

laravel queues eloquent
by codesnips 3 tabs
python
from enum import Enum
from typing import Optional

from fastapi import Query
from pydantic import BaseModel, Field, field_validator

Validate and Normalize Query Filters With a Pydantic Dependency in FastAPI

fastapi pydantic validation
by codesnips 3 tabs
php
<?php

namespace App\Tenancy;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

Enforce Multi-Tenant Isolation in Laravel with a Global Scope Bound to the Current User

laravel multi-tenancy eloquent
by codesnips 4 tabs
go
package web

import (
	"embed"
	"io/fs"
)

Serve Embedded Static Assets with embed.FS and Cache Headers in Go

go embed static-assets
by codesnips 3 tabs
go
package main

import (
	"log"
	"net/http"
	"time"

Serving Partial Video Content with HTTP Range Requests in Go

go http range-requests
by codesnips 3 tabs