javascript
const { Pool } = require('pg');
const Cursor = require('pg-cursor');

const pool = new Pool();

async function* streamUsers({ since, batchSize = 500 }) {

Stream a Large JSON Array Response in Node.js Without Buffering

nodejs streams transform-stream
by codesnips 3 tabs
javascript
const Busboy = require('busboy');
const { storeFile } = require('./storage');

function parseMultipart(req, { maxFileSize = 20 * 1024 * 1024 } = {}) {
  return new Promise((resolve, reject) => {
    const busboy = Busboy({

Streaming Multipart Form Upload Parser Using Busboy in Node.js

nodejs multipart streaming
by codesnips 3 tabs
java
package com.example.github;

import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

Declarative Typed HTTP Client With Retrofit and an OkHttp Auth Interceptor

retrofit okhttp http-client
by codesnips 3 tabs
javascript
const sharp = require('sharp');

const DEFAULTS = {
  maxWidth: 1600,
  maxHeight: 1600,
  format: 'webp',

Resize and Compress Uploaded Images with Sharp Before Saving to Disk

nodejs express sharp
by codesnips 3 tabs
java
@RestController
@RequestMapping("/users")
public class UserPatchController {

    private final UserRepository users;
    private final JsonPatchService patchService;

Applying RFC 6902 JSON Patch with Optimistic Locking in Spring Boot

spring-boot rest-api json-patch
by codesnips 3 tabs
go
package appconfig

import (
	"flag"
	"io"
	"os"

Parsing and Validating CLI Flags into a Typed Config Struct in Go

cli flags configuration
by codesnips 3 tabs
typescript
import { Type } from 'class-transformer';
import { IsInt, IsOptional, IsString, Max, Min } from 'class-validator';

export class CursorPaginationQuery {
  @IsOptional()
  @IsString()

Cursor-Based Pagination for a TypeORM Repository in NestJS

nestjs typeorm pagination
by codesnips 4 tabs
python
from typing import Optional
from pydantic import BaseModel, EmailStr, Field, field_validator, model_validator


class CreateUserRequest(BaseModel):
    model_config = {"extra": "forbid"}

Validating JSON Payloads with Pydantic v2 and Returning Field-Level Errors in FastAPI

fastapi pydantic validation
by codesnips 3 tabs
sql
CREATE TABLE outbox_deliveries (
    id              BIGSERIAL PRIMARY KEY,
    dedupe_key      TEXT        NOT NULL,
    target_url      TEXT        NOT NULL,
    payload         JSONB       NOT NULL,
    status          TEXT        NOT NULL DEFAULT 'PENDING',

Reliable Webhook Delivery with a Transactional Outbox and Dedupe Key in Spring Boot

spring-boot webhooks outbox-pattern
by codesnips 3 tabs
java
package com.example.orders;

public final class Order {

    public static final Order POISON_PILL = new Order(-1L, 0.0);

Producer/Consumer Order Processing With a Bounded BlockingQueue in Java

java concurrency blockingqueue
by codesnips 3 tabs
typescript
import React, { useMemo } from 'react';
import { VirtualList } from './VirtualList';

interface LogEntry {
  id: number;
  level: 'info' | 'warn' | 'error';

Virtualized List in React: Render Only Visible Rows on Scroll

react virtualization windowing
by codesnips 3 tabs
ruby
require "sinatra/base"
require "rack/utils"

class AdminApp < Sinatra::Base
  before do
    protected!

Protecting Namespaced Admin Routes in Sinatra with an HTTP Basic Auth before Filter

sinatra http-basic-auth authentication
by codesnips 3 tabs