rust
use std::fmt;

#[derive(Debug)]
pub enum HashError {
    Backend(String),
    InvalidHash,

Pluggable Password Hasher Trait in Rust with Argon2 and Bcrypt Backends

rust argon2 bcrypt
by codesnips 3 tabs
javascript
const Busboy = require('busboy');
const { storeFile } = require('./storage');

function parseMultipart(req, { maxFileSize = 20 * 1024 * 1024 } = {}) {
  return new Promise((resolve, reject) => {
    const busboy = Busboy({

Streaming Multipart Form Upload Parser Using Busboy in Node.js

nodejs multipart streaming
by codesnips 3 tabs
python
import os
import uuid

from flask import Blueprint, current_app, jsonify, request
from werkzeug.exceptions import RequestEntityTooLarge

Streaming Large Multipart File Uploads to Disk in Flask Without Buffering

flask werkzeug streaming
by codesnips 3 tabs
ruby
class Product < ApplicationRecord
  scope :by_status, ->(status) {
    status.present? ? where(status: status) : all
  }

  scope :in_category, ->(category_id) {

Composable Query Filters with Rails Scopes and a Filter Object

rails activerecord scopes
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;

Resolve the Authenticated User into a Controller Argument in Spring Boot

spring-boot spring-mvc security
by codesnips 4 tabs
go
package optimistic

import (
	"errors"
	"sync"
)

Optimistic UI Rollback in Go With a Compensating Action Log

go concurrency optimistic-ui
by codesnips 3 tabs
typescript
import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
  VersionColumn,

Optimistic Locking in NestJS with a TypeORM Version Column and Conflict Exception Filter

nestjs typeorm optimistic-locking
by codesnips 4 tabs
javascript
const pino = require('pino');
const { AsyncLocalStorage } = require('async_hooks');

const als = new AsyncLocalStorage();

const logger = pino({

Request-Scoped Correlation ID Middleware and Child Logger in Express

express middleware logging
by codesnips 3 tabs
python
import datetime as dt

from sqlalchemy import Column, DateTime, Integer, String, UniqueConstraint
from sqlalchemy.orm import declarative_base

Base = declarative_base()

Idempotent Webhook Ingestion With a Postgres Dedupe Store in FastAPI

fastapi webhooks idempotency
by codesnips 3 tabs
javascript
const { WebSocketServer } = require('ws');
const crypto = require('crypto');

const wss = new WebSocketServer({ port: 8080 });

function broadcast(payload, except) {

Reconnecting WebSocket Chat Client with a Broadcasting Node Server

websocket realtime reconnection
by codesnips 3 tabs
ruby
class Cart < ApplicationRecord
  belongs_to :user, optional: true
  has_many :cart_items, dependent: :destroy

  scope :for_session, ->(token) { where(session_token: token) }
  scope :active, -> { where(merged_at: nil) }

Merge a Guest Cart Into a User's Cart on Login With a Rails Service Object

rails service-object devise
by codesnips 3 tabs
typescript
export const TOTAL_STEPS = 3;

export interface WizardData {
  email: string;
  password: string;
  fullName: string;

Typed Multi-Step Wizard Form With a useReducer State Machine in React

react typescript usereducer
by codesnips 4 tabs