rust
use serde::Deserialize;
use std::fmt;

#[derive(Debug, Deserialize)]
pub struct UserRecord {
    pub name: String,

Row-by-Row CSV Import Validation With Line-Numbered Errors in Rust

csv serde validation
by codesnips 3 tabs
python
import hashlib
from functools import wraps

from flask import request, make_response
from redis import Redis

Flask ETag Caching for an Expensive Endpoint with Conditional 304 Handling

flask http-caching etag
by codesnips 2 tabs
ruby
require 'sinatra/base'
require_relative 'cart'
require_relative 'cart_helpers'

class StoreApp < Sinatra::Base
  enable :sessions

Session-Backed Shopping Cart with Sinatra Helpers and a Cart Value Object

sinatra sessions shopping-cart
by codesnips 3 tabs
typescript
export interface CronFields {
  minute: Set<number>;
  hour: Set<number>;
  dayOfMonth: Set<number>;
  month: Set<number>;
  dayOfWeek: Set<number>;

Cron-Expression Scheduler with Field Parser and a Tick Loop in TypeScript

cron scheduler parser
by codesnips 3 tabs
yaml
framework:
    workflows:
        order:
            type: state_machine
            marking_store:
                type: method

Guarding an Order State Transition with Symfony's Workflow Component and a Guard Listener

symfony workflow state-machine
by codesnips 4 tabs
java
package com.example.notifications;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;

Live Browser Notifications with Spring Boot SseEmitter and a Broadcaster Service

spring-boot sse server-sent-events
by codesnips 3 tabs
javascript
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';

export const RouterContext = createContext(null);

export function RouterProvider({ children }) {
  const [path, setPath] = useState(() => window.location.pathname);

Client-Side Router with useRoute Hook and History API in React

react router hooks
by codesnips 3 tabs
rust
#[derive(Debug, Clone, Copy)]
pub struct ByteRange {
    pub start: u64,
    pub end: u64, // inclusive
}

Serving HTTP Range Requests in Axum with Partial Content Responses

axum http range-requests
by codesnips 3 tabs
python
import contextvars
import uuid

_correlation_id: contextvars.ContextVar[str] = contextvars.ContextVar(
    "correlation_id", default="-"
)

Propagating a Correlation ID Through contextvars in FastAPI

fastapi contextvars middleware
by codesnips 4 tabs
java
@Entity
@Table(name = "invoices")
@FilterDef(
    name = "tenantFilter",
    parameters = @ParamDef(name = "tenantId", type = String.class)
)

Per-Tenant Row Filtering with Hibernate @Filter Enabled Per Request

hibernate jpa multi-tenancy
by codesnips 4 tabs
javascript
const express = require('express');
const controller = require('../controllers/userController');

const router = express.Router();

router.use((req, res, next) => {

Versioning an Express API with Router-per-Version Mounts and a Shared Controller Module

express api-versioning rest
by codesnips 4 tabs
typescript
export interface CartItem {
  id: string;
  name: string;
  price: number;
  quantity: number;
}

Type-Safe Shopping Cart with useReducer, Context, and a useCart Hook

react context usereducer
by codesnips 4 tabs