rust
use std::collections::HashMap;
use std::sync::Mutex;

pub type AccountId = u64;
pub type Cents = i64;

Atomic Double-Entry Ledger Transfers With Rust Locking and Poison Recovery

ledger concurrency double-entry
by codesnips 3 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
java
@Entity
@Table(name = "stored_files")
public class StoredFile {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)

Spring Boot Multipart File Upload with Metadata Persistence and Validation

spring-boot multipart file-upload
by codesnips 3 tabs
php
<?php

namespace App\Payment;

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

Collect Tagged Payment Gateways with a Symfony Compiler Pass and Service Locator

symfony dependency-injection compiler-pass
by codesnips 4 tabs
python
import threading


class MinuteRingBuffer:
    def __init__(self, window_minutes=15):
        if window_minutes < 1:

Rolling Per-Minute Log Aggregation with a Ring Buffer

logging metrics observability
by codesnips 3 tabs
ruby
class DashboardMetrics
  include ActiveModel::Model

  attr_reader :account

  def initialize(account)

Expiring Dashboard Fragment Caches with a Versioned Composite Cache Key in Rails

rails caching fragment-caching
by codesnips 3 tabs
javascript
export class QueryCache {
  constructor() {
    this.entries = new Map();
  }

  getEntry(key) {

Building a Minimal useQuery Hook with a Shared Cache Provider in React

react hooks caching
by codesnips 4 tabs
rust
use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade};
use axum::extract::State;
use axum::response::Response;
use axum::routing::get;
use axum::Router;

Fan-Out Domain Events to WebSocket Clients With a Tokio Broadcast Channel

tokio async broadcast
by codesnips 3 tabs
typescript
import { useEffect, useState } from "react";

export function useDebouncedValue<T>(value: T, delay = 300): T {
  const [debounced, setDebounced] = useState<T>(value);

  useEffect(() => {

Build a Debounced Search Box in React with a Reusable useDebouncedValue Hook

react hooks typescript
by codesnips 3 tabs
javascript
export const initialCart = { items: {} };

export function cartReducer(state, action) {
  switch (action.type) {
    case 'ADD_ITEM': {
      const { product, qty = 1 } = action;

Persist and Hydrate a Shopping Cart with useReducer and localStorage

react hooks usereducer
by codesnips 3 tabs
rust
use std::any::Any;

pub trait CommandHandler {
    fn name(&self) -> &str;

    fn handle(&self, input: &dyn Any) -> Box<dyn Any>;

Type-Erased Command Handler Registry With Trait Objects in Rust

rust trait-objects dispatch
by codesnips 3 tabs
java
package com.example.api.error;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.time.Instant;
import java.util.List;

Structured Error Responses with @RestControllerAdvice in Spring Boot

spring-boot rest-api exception-handling
by codesnips 3 tabs