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
typescript
import { createContext, useContext, useEffect, useMemo, useState, ReactNode } from 'react';
import { authApi, User } from './authApi';

type Status = 'loading' | 'authenticated' | 'anonymous';

interface AuthValue {

Protect React Routes with an Auth Context and a RequireAuth Wrapper

react react-router authentication
by codesnips 4 tabs
php
<?php

namespace App\Services;

use App\Mail\VerifyEmail;
use App\Models\ContactEmail;

Signed URL Email Verification in Laravel Without the Built-in MustVerifyEmail Contract

laravel php signed-urls
by codesnips 4 tabs
rust
use serde::Serialize;
use serde_json::Value;

#[derive(Debug, Clone, Serialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum ChangeKind {

Diffing Two Config Snapshots Into a Typed Change List in Rust

rust serde config
by codesnips 3 tabs
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

Apply and Validate Coupon Codes with a Cart Totals Service in Laravel

laravel eloquent service-layer
by codesnips 4 tabs
javascript
const { pool } = require('./db');

async function recordEvent(client, { eventId, type, payload }) {
  const { rows } = await client.query(
    `INSERT INTO webhook_events (event_id, type, payload, status)
     VALUES ($1, $2, $3, 'received')

Idempotent Stripe Webhook Processing With an Express Event-Store Middleware

express webhooks idempotency
by codesnips 3 tabs
typescript
import { useCallback, useEffect, useRef, useState } from "react";

export function useIntersectionObserver(options?: IntersectionObserverInit) {
  const [isIntersecting, setIsIntersecting] = useState(false);
  const nodeRef = useRef<Element | null>(null);
  const optionsKey = JSON.stringify(options ?? {});

Infinite-Scroll Feed with a React IntersectionObserver Hook and Cursor Pagination

react hooks intersection-observer
by codesnips 3 tabs