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
java
package com.shop.orders;

import jakarta.persistence.*;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.ArrayList;

Mapping a JPA Entity to a Response DTO with MapStruct in Spring Boot

spring-boot jpa mapstruct
by codesnips 4 tabs
php
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

Resize and Store User Avatars with Intervention Image in Laravel

laravel file-upload image-processing
by codesnips 3 tabs
python
import functools
import threading


def debounce(wait):
    def decorator(func):

Debounce Repeated Function Calls With a Thread-Safe Python Decorator

python decorators debounce
by codesnips 2 tabs
ruby
class AddressForm
  include ActiveModel::Model
  include ActiveModel::Attributes

  attribute :line1, :string
  attribute :line2, :string

Rails Nested Address Form Object With Aggregated ActiveModel Errors

rails activemodel form-object
by codesnips 3 tabs
javascript
class TokenBucket {
  constructor(capacity, refillPerSecond) {
    this.capacity = capacity;
    this.refillPerMs = refillPerSecond / 1000;
    this.tokens = capacity;
    this.lastRefill = Date.now();

Token Bucket Rate Limiter Middleware for Express with Per-Key Buckets

nodejs express rate-limiting
by codesnips 4 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
rust
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]

Cursor-Paginated Streaming REST Endpoint in Axum with Keyset Pagination

axum rust pagination
by codesnips 3 tabs
go
package health

import (
	"context"
	"sync"
	"time"

Concurrent Readiness Health Check Endpoint in Go with Timeouts

go health-check readiness
by codesnips 3 tabs
ruby
class RegistrationsController < ApplicationController
  def new
    @user = User.new
  end

  def create

Send a Welcome Email After Signup Using a Sidekiq Background Job in Rails

ruby rails sidekiq
by codesnips 4 tabs
go
package pricecache

import (
	"context"
	"sync"

Collapse Concurrent Identical Requests in Go with singleflight

go singleflight concurrency
by codesnips 3 tabs
python
import functools
import threading
import time
from collections import OrderedDict

Custom TTL + LRU Cache Decorator for Expensive Python Computations

python caching lru
by codesnips 2 tabs