java
@Component
public class SalesRollupScheduler {

    private static final Logger log = LoggerFactory.getLogger(SalesRollupScheduler.class);
    private static final int ROLLUP_WINDOW_DAYS = 3;

Roll Up Daily Sales Totals With a Scheduled Spring Batch Upsert via JdbcTemplate

spring-boot jdbctemplate postgres
by codesnips 3 tabs
javascript
const { Worker, MessageChannel } = require('node:worker_threads');
const path = require('node:path');

class WorkerPool {
  constructor(size) {
    this.workers = [];

Fan Out CPU Work to Node.js worker_threads and Merge Results via MessageChannel

nodejs worker-threads concurrency
by codesnips 3 tabs
javascript
const express = require('express');
const { toCsv } = require('./csvSerializer');
const { fetchOrders } = require('./orderRepository');

const router = express.Router();

Content Negotiation in Express: Serve JSON or CSV From One Route

express content-negotiation rest-api
by codesnips 3 tabs
typescript
export type Validator = (value: string) => string | null;

export const required = (message = 'This field is required'): Validator => {
  return (value) => (value.trim().length === 0 ? message : null);
};

Field-Level Form Validation with a Reusable useField Hook in React

react hooks forms
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
rust
use std::collections::HashMap;
use std::hash::Hash;

const NIL: usize = usize::MAX;

struct Node<K, V> {

Build an O(1) LRU Cache in Rust With a HashMap and Intrusive Doubly Linked List

rust lru cache
by codesnips 3 tabs
php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Validate an Unredeemed Coupon Code with a Custom Laravel Rule Object

laravel validation eloquent
by codesnips 4 tabs
ruby
class CreateStripeEvents < ActiveRecord::Migration[7.1]
  def change
    create_table :stripe_events do |t|
      t.string :stripe_event_id, null: false
      t.string :event_type, null: false
      t.string :status, null: false, default: "received"

Idempotent Stripe Webhook Processing in Rails with a Durable Event Log

rails stripe webhooks
by codesnips 4 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
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

Building Filterable, Sortable Product Listings with Laravel Query Scopes

laravel eloquent query-scopes
by codesnips 3 tabs
typescript
import { useEffect, useState } from "react";

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

  useEffect(() => {

Debounced Draft Autosave with React Query and a Saving-Status Indicator

react react-query autosave
by codesnips 4 tabs
java
package com.example.cache;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CompletionException;
import java.util.concurrent.atomic.AtomicBoolean;

Single-Flight Cache Loader: Coalesce Concurrent Identical Loads in Java

caching concurrency single-flight
by codesnips 3 tabs