ruby
class ParamSchema
  def initialize(fields)
    @fields = fields
  end

  def coerce(params)

Typed Query Param Coercion in a Sinatra before Filter with Schema Defaults

sinatra rack params
by codesnips 2 tabs
python
import asyncio
from typing import Awaitable, Callable, Dict, TypeVar

T = TypeVar("T")

Coalesce Duplicate In-Flight Requests with an Asyncio Single-Flight Cache

asyncio concurrency caching
by codesnips 3 tabs
typescript
import { RequestHandler } from 'express';
import { ZodTypeAny, ZodError } from 'zod';

export class ValidationError extends Error {
  status = 422;
  constructor(public issues: unknown) {

Composable Express Request Validation with Zod Schema Middleware

express validation zod
by codesnips 3 tabs
rust
use pulldown_cmark::{html, Options, Parser};
use std::collections::HashSet;

pub struct SafeHtml(String);

impl SafeHtml {

Rendering Untrusted Markdown to Sanitized HTML with pulldown-cmark and ammonia

rust markdown html-sanitization
by codesnips 3 tabs
java
@Configuration
@EnableScheduling
@EnableConfigurationProperties(CleanupProperties.class)
public class SchedulingConfig {

    @Bean(destroyMethod = "shutdown")

Recurring Cleanup Job with Spring @Scheduled and a Shutdown-Aware Executor

spring spring-boot scheduling
by codesnips 3 tabs
typescript
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { FeatureFlagGuard } from './feature-flag.guard';
import { RequireFeature } from './feature-flag.decorator';

@Controller('experiments')
@UseGuards(FeatureFlagGuard)

Per-Request Feature Flags in NestJS with a Custom Decorator and Resolution Guard

nestjs feature-flags guards
by codesnips 4 tabs
php
<?php

namespace App\ValueObjects;

final readonly class NotificationSettings
{

Cast a JSON Column to an Immutable Value Object with a Custom Eloquent Cast in Laravel

laravel eloquent value-object
by codesnips 3 tabs
ruby
module Result
  def self.Success(value)
    Success.new(value)
  end

  def self.Failure(error)

Railway-Oriented Result Monad for Chaining Lead Enrichment Steps in Ruby

result-monad railway-oriented functional
by codesnips 3 tabs
java
package com.example.docs.domain;

import jakarta.persistence.*;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

Soft-Delete JPA Entities with Hibernate @SQLDelete and @Where Filtering

spring-boot hibernate jpa
by codesnips 3 tabs
rust
use std::collections::HashMap;
use std::fmt;

#[derive(Debug, Clone)]
pub struct Document {
    pub body: String,

Trait-Based Document Transform Pipeline With Ordered Plugins in Rust

rust trait-objects pipeline
by codesnips 3 tabs
javascript
'use strict';

const { Transform } = require('stream');

class LineSplitter extends Transform {
  constructor(options = {}) {

Split a Large Log File Into Date-Based Chunks With a Node.js Transform Stream

nodejs streams backpressure
by codesnips 3 tabs
python
from typing import Literal, Tuple, Type

from pydantic import BaseModel, PostgresDsn, RedisDsn
from pydantic_settings import (
    BaseSettings,
    PydanticBaseSettingsSource,

Layered Pydantic Settings: Env Vars Over a YAML Defaults File

pydantic configuration settings
by codesnips 4 tabs