javascript
const crypto = require('crypto');

function computeSignature(secret, timestamp, payload) {
  return crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${payload}`, 'utf8')

Verify Stripe-Style Webhook Signatures With HMAC in Express Before Processing

webhooks hmac security
by codesnips 2 tabs
typescript
export interface UploadHandle {
  promise: Promise<{ status: number; body: string }>;
  xhr: XMLHttpRequest;
}

export function uploadFile(

React File Upload with Live Progress Bar Using XMLHttpRequest

react file-upload xmlhttprequest
by codesnips 3 tabs
java
@Component
public class SalesRollupScheduler {

    private static final Logger log = LoggerFactory.getLogger(SalesRollupScheduler.class);
    private static final int ROLLUP_WINDOW_DAYS = 3;

Roll Up Daily Sales Totals With a Scheduled Spring Batch Upsert via JdbcTemplate

spring-boot jdbctemplate postgres
by codesnips 3 tabs
rust
use std::collections::HashMap;
use std::hash::Hash;

const NIL: usize = usize::MAX;

struct Node<K, V> {

Build an O(1) LRU Cache in Rust With a HashMap and Intrusive Doubly Linked List

rust lru cache
by codesnips 3 tabs
ruby
class CreateStripeEvents < ActiveRecord::Migration[7.1]
  def change
    create_table :stripe_events do |t|
      t.string :stripe_event_id, null: false
      t.string :event_type, null: false
      t.string :status, null: false, default: "received"

Idempotent Stripe Webhook Processing in Rails with a Durable Event Log

rails stripe webhooks
by codesnips 4 tabs
python
from typing import Any, Optional

from fastapi.responses import JSONResponse
from pydantic import BaseModel

Consistent JSON Error Responses in FastAPI With a Custom Exception Handler

fastapi error-handling exceptions
by codesnips 3 tabs
typescript
export type EventMap = Record<string, unknown[]>;

type Listener<Args extends unknown[]> = (...args: Args) => void;

export class TypedEmitter<Events extends EventMap> {
  private listeners = new Map<keyof Events, Set<Listener<any>>>();

Type-Safe Event Emitter With Strongly-Typed Listener Payloads in TypeScript

typescript events event-emitter
by codesnips 3 tabs
python
import time
import threading
from collections import deque, defaultdict


class SlidingWindowLimiter:

Sliding-Window Rate Limiting in Flask With a Custom Decorator and In-Memory Buckets

flask rate-limiting decorators
by codesnips 3 tabs
ruby
class RevenueStat
  DEFAULT_RANGE = 30.days

  def initialize(account, range: DEFAULT_RANGE)
    @account = account
    @range = range

Memoized Query Object for a Cached Dashboard Stat in Rails

rails activerecord query-object
by codesnips 3 tabs
java
package com.example.security;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

Method-Level Role Authorization with a Custom @RequireRole Annotation and Spring AOP

spring spring-boot aop
by codesnips 4 tabs
java
package com.shop.inventory;

import jakarta.persistence.*;

@Entity
@Table(name = "inventory_item")

Optimistic Locking on Inventory Updates with @Version and a Retrying Conflict Handler in Spring Boot

spring-boot jpa hibernate
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