javascript
const express = require('express');
const webhookRouter = require('./webhookRouter');
const apiRouter = require('./apiRouter');

const app = express();

Verify Stripe Webhook Signatures with a Raw-Body Express Route

express stripe webhooks
by codesnips 3 tabs
javascript
function escapeCell(value) {
  if (value === null || value === undefined) return '';
  const str = String(value);
  if (/[",\n\r]/.test(str)) {
    return '"' + str.replace(/"/g, '""') + '"';
  }

Stream a Large CSV Export in Express with Backpressure and an Async Row Generator

express streaming csv
by codesnips 3 tabs
go
package httpretry

import (
	"math/rand"
	"time"
)

Exponential Backoff With Full Jitter for Flaky HTTP Calls in Go

go http retry
by codesnips 3 tabs
python
from alembic import op
import sqlalchemy as sa

revision = "20240612_add_status"
down_revision = "20240515_create_orders"
branch_labels = None

Zero-Downtime NOT NULL Column Backfill with Alembic and SQLAlchemy

alembic sqlalchemy migrations
by codesnips 2 tabs
java
package com.example.reference;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

Seed Reference Data at Boot with a Spring Boot ApplicationRunner

spring-boot seeding reference-data
by codesnips 4 tabs
typescript
import { EventEmitter } from "events";

export interface Job<T> {
  id: string;
  payload: T;
  attempts: number;

Typed In-Memory Job Queue With a Concurrency-Limited Worker Pool

typescript job-queue concurrency
by codesnips 3 tabs
ruby
require 'sinatra/base'
require_relative 'upload_store'

class UploadApp < Sinatra::Base
  MAX_BYTES = 50 * 1024 * 1024

Streaming Multipart File Uploads to Disk in Sinatra Without Buffering

sinatra rack file-upload
by codesnips 3 tabs
go
package api

import (
	"encoding/json"
	"net/http"
)

Field-Level JSON Validation Errors in Go net/http Handlers

go net-http validation
by codesnips 3 tabs
typescript
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { TenantService } from './tenant.service';

@Injectable()
export class TenantContextMiddleware implements NestMiddleware {

Bind Tenant Context Per Request in NestJS With a Custom @TenantId() Decorator

nestjs multi-tenancy decorators
by codesnips 4 tabs
ruby
class PriceBreakdown < Struct.new(:subtotal_cents, :discount_cents, :tax_cents, keyword_init: true)
  def initialize(*)
    super
    freeze
  end

Memoizing a Pricing Breakdown as an Immutable Value Object in Rails

rails memoization value-object
by codesnips 3 tabs
rust
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderState {
    Pending,
    Paid,

Type-State Order Lifecycle Machine With Compile-Time Transition Safety in Rust

state-machine enums type-state
by codesnips 3 tabs
python
from datetime import datetime, timedelta, timezone

from jose import jwt, JWTError
from jose.exceptions import ExpiredSignatureError

SECRET_KEY = "change-me-in-production"

FastAPI JWT Authentication with Access/Refresh Tokens and a Verification Dependency

fastapi jwt authentication
by codesnips 3 tabs