java
package com.example.search;

import java.time.LocalDate;

@ValidDateRange
public class DateRangeSearch {

Bind and Validate a Date-Range Search with @ModelAttribute and a Custom PropertyEditor

spring-boot spring-mvc data-binding
by codesnips 4 tabs
typescript
import { useEffect, useState } from "react";

export function useDebouncedValue<T>(value: T, delay = 300): T {
  const [debounced, setDebounced] = useState<T>(value);

  useEffect(() => {

Build a Debounced Search Box in React with a Reusable useDebouncedValue Hook

react hooks typescript
by codesnips 3 tabs
rust
use serde::Deserialize;

#[derive(Debug, Deserialize)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum WebhookEvent {
    #[serde(rename = "payment.succeeded")]

Tagged Webhook Deserialization and Typed Handler Dispatch in Rust with Serde

webhooks serde axum
by codesnips 3 tabs
python
import hashlib
import json


def compute_etag(payload, weak=False):
    body = json.dumps(payload, sort_keys=True, separators=(",", ":"))

Conditional GET with ETag Generation and 304 Not Modified in Flask

flask http caching
by codesnips 3 tabs
ruby
require 'sinatra'
require 'json'
require_relative 'book'
require_relative 'helpers'

set :books, {

Sinatra Content Negotiation: Serve HTML or JSON by Accept Header

sinatra rack content-negotiation
by codesnips 4 tabs
ruby
class AddSlugToArticles < ActiveRecord::Migration[7.1]
  def change
    add_column :articles, :slug, :string
    add_index :articles, :slug, unique: true

    reversible do |dir|

Auto-Generating URL Slugs in Rails with a before_validation Callback and Friendly Finder

rails activerecord slugs
by codesnips 4 tabs
php
<?php

namespace App\Correlation;

final class CorrelationIdStorage
{

Propagate a Correlation ID Through Symfony Requests and Monolog Logs

symfony monolog logging
by codesnips 4 tabs
go
package main

import (
	"log"
	"net/http"
	"time"

Instrumenting Go HTTP Handlers with Prometheus Counters and Histograms

prometheus metrics observability
by codesnips 3 tabs
javascript
const multer = require('multer');

const ALLOWED_MIME = new Set(['image/jpeg', 'image/png', 'image/webp']);

function fileFilter(req, file, cb) {
  if (!ALLOWED_MIME.has(file.mimetype)) {

Upload and Resize User Avatars with Multer and Sharp in Express

express multer sharp
by codesnips 3 tabs
rust
use axum::{
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},
    response::{IntoResponse, Response},
    Json,
};

Axum Bearer Token Extractor with Shared Auth State and Typed Claims

axum authentication middleware
by codesnips 3 tabs
rust
use once_cell::sync::Lazy;
use regex::Regex;
use std::str::FromStr;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Severity {

Grouping Log Lines by Severity and Emitting a Summary Report in Rust

logging parsing cli
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