rust
use std::error::Error;
use std::fmt;
use std::io;
use std::num::ParseIntError;

#[derive(Debug)]

Custom Error Enum With From Conversions for the ? Operator in Rust

rust error-handling traits
by codesnips 3 tabs
go
package proxy

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

Building a Reverse Proxy in Go with httputil.ReverseProxy and Header Rewriting

go reverse-proxy httputil
by codesnips 3 tabs
lua
-- KEYS[1] = bucket key
-- ARGV[1] = capacity, ARGV[2] = refill_rate (tokens/sec)
-- ARGV[3] = now_ms, ARGV[4] = requested tokens
local capacity    = tonumber(ARGV[1])
local refill_rate = tonumber(ARGV[2])
local now_ms      = tonumber(ARGV[3])

Token Bucket Rate Limiting in a Servlet Filter with Redis and Lua

rate-limiting token-bucket servlet
by codesnips 3 tabs
go
package webhook

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

Verifying and Dispatching Stripe-Style Webhooks by Event Type in Go

webhooks go hmac
by codesnips 3 tabs
java
package com.example.health;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

Custom Spring Boot HealthIndicator for Queue Depth on /actuator/health

spring-boot actuator health-check
by codesnips 4 tabs
javascript
const withTimeout = (promise, timeoutMs, name) => {
  let timer;
  const timeout = new Promise((_, reject) => {
    timer = setTimeout(
      () => reject(new Error(`check '${name}' timed out after ${timeoutMs}ms`)),
      timeoutMs

Express Health-Check Router With a Pluggable Dependency Checks Registry

express health-check observability
by codesnips 3 tabs
typescript
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

Global ValidationPipe with class-validator DTOs and Transform in NestJS

nestjs validation dto
by codesnips 3 tabs
python
import time
from collections import namedtuple

from sqlalchemy import text

CheckResult = namedtuple("CheckResult", ["name", "healthy", "latency_ms", "detail"])

Flask Health-Check Blueprint Reporting Database and Redis Status as JSON

flask health-check observability
by codesnips 3 tabs
ruby
class DebouncedReindexJob
  include Sidekiq::Job

  sidekiq_options queue: :indexing, retry: 5

  DEBOUNCE_DELAY = 5 # seconds

Debouncing Sidekiq Jobs Per-Record With Redis So Rapid Updates Coalesce Into One Run

rails sidekiq redis
by codesnips 3 tabs
python
import hmac
import hashlib
import time
from fastapi import Request, HTTPException, status

Verifying Stripe Webhook Signatures With a Reusable FastAPI Dependency

fastapi webhooks security
by codesnips 3 tabs
typescript
const RETRYABLE_STATUS = new Set([408, 429, 500, 502, 503, 504]);

export function isRetryable(error: unknown, response?: Response): boolean {
  if (response) {
    return RETRYABLE_STATUS.has(response.status);
  }

Retrying Fetch With Exponential Backoff and Full Jitter in TypeScript

retry backoff jitter
by codesnips 3 tabs
ruby
require 'sinatra/base'
require_relative 'cart'
require_relative 'cart_helpers'

class StoreApp < Sinatra::Base
  enable :sessions

Session-Backed Shopping Cart with Sinatra Helpers and a Cart Value Object

sinatra sessions shopping-cart
by codesnips 3 tabs