python
import asyncio
import uuid
from dataclasses import dataclass, field
from typing import Any, Dict, Optional

Long-Polling a Background Job's Status with a Shared Result Registry in FastAPI

fastapi asyncio long-polling
by codesnips 3 tabs
javascript
const crypto = require('crypto');

function parseSignatureHeader(header) {
  const parts = {};
  for (const segment of String(header || '').split(',')) {
    const [key, value] = segment.split('=');

Verify Stripe-Style Webhook HMAC Signatures with a Timestamped Scheme in Express

express webhooks hmac
by codesnips 3 tabs
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

Queued Saved-Search Digest Emails for New Listings in Laravel

laravel queues eloquent
by codesnips 3 tabs
ruby
class ImportResult
  RowError = Struct.new(:line, :messages)

  attr_reader :imported, :row_errors

  def initialize

Streaming CSV Product Import With Per-Row Validation and Error Reporting in Rails

rails csv service-object
by codesnips 3 tabs
typescript
import { Controller, Sse, Headers } from '@nestjs/common';
import { interval, Observable } from 'rxjs';
import { map } from 'rxjs/operators';

interface FeedPayload {
  id: number;

Streaming Server-Sent Events into a Live React List with an EventSource Hook

react sse eventsource
by codesnips 3 tabs
go
package listing

import "encoding/base64"

func Encode(name string) string {
	return base64.RawURLEncoding.EncodeToString([]byte(name))

Cursor-Based Directory Listing API in Go with net/http

go pagination cursor
by codesnips 3 tabs
java
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import java.time.Instant;

@MappedSuperclass
public abstract class SoftDeletable {

Soft-Delete JPA Entities with Hibernate @Where and a Restore-Capable Repository

spring spring-data hibernate
by codesnips 4 tabs
python
import uuid
from django.db import models
from django.utils import timezone


class OutboxManager(models.Manager):

Transactional Outbox with Timer-Based Flushing and Exponential Backoff in Django

django outbox postgres
by codesnips 3 tabs
javascript
const crypto = require('crypto');

function computeStrongEtag(body) {
  const buf = Buffer.isBuffer(body) ? body : Buffer.from(String(body));
  const digest = crypto.createHash('sha1').update(buf).digest('base64');
  return '"' + digest + '"';

ETag-Based HTTP Caching in Express With 304 Not Modified Handling

express http-caching etag
by codesnips 3 tabs
ruby
class Coupon < ApplicationRecord
  before_validation :normalize_code

  validates :code,
            coupon_code: { min_length: 6 },
            uniqueness: { case_sensitive: false }

Validating Coupon Codes with a Custom EachValidator in Rails

rails validations activerecord
by codesnips 3 tabs
java
@RestController
@RequestMapping("/api/products")
public class ProductController {

    private final ProductRepository repository;
    private final JsonMergePatchService patchService;

Spring Boot PATCH Endpoint With JSON Merge Patch (RFC 7386)

spring-boot rest-api json-merge-patch
by codesnips 4 tabs
javascript
const SHUTDOWN_TIMEOUT_MS = 10_000;

function registerFatalHandlers({ logger, onFatal, exitCode = 1 }) {
  let shuttingDown = false;

  async function handleFatal(kind, error) {

Graceful Node.js Shutdown on uncaughtException and unhandledRejection

node reliability graceful-shutdown
by codesnips 3 tabs