erb
{% load cache %}
<section class="dashboard">
  <h1>{{ team.name }} — Overview</h1>

  {% cache 3600 team_order_stats team.id stats_version %}
    <div class="stat-grid">

Cache an Expensive Dashboard Fragment with Django's Template Cache Tag and Signal-Based Invalidation

django caching template-cache
by codesnips 3 tabs
java
package com.shop.orders;

import jakarta.persistence.*;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.ArrayList;

Mapping a JPA Entity to a Response DTO with MapStruct in Spring Boot

spring-boot jpa mapstruct
by codesnips 4 tabs
python
from datetime import datetime

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

Register a Custom Flask CLI Command to Seed the Database with Faker

flask cli click
by codesnips 3 tabs
java
package com.example.caching.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.ShallowEtagHeaderFilter;

Conditional GET with ETag ShallowEtagHeaderFilter and Cache-Control in Spring Boot

spring-boot http-caching etag
by codesnips 3 tabs
python
import abc
from typing import IO


class Exporter(abc.ABC):
    name: str = ""

Plugin Registry with Class Decorators and setuptools Entry-Point Discovery

python plugins decorators
by codesnips 4 tabs
python
import asyncio
import time
from dataclasses import dataclass
from typing import Any, Dict

In-Memory TTL Cache for FastAPI Endpoints With a Cache-Key Builder Dependency

fastapi caching ttl
by codesnips 3 tabs
ruby
require 'sinatra/base'
require 'json'

class HealthApp < Sinatra::Base
  configure do
    set :dump_errors, true

Mounting Modular Sinatra Apps Under Route Prefixes with Rack::URLMap

sinatra rack urlmap
by codesnips 3 tabs
rust
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::Mutex;
use tokio::time::sleep;

#[derive(Debug)]

Rate-Limiting Outbound HTTP with a Token Bucket in Rust (Tokio)

rust tokio rate-limiting
by codesnips 3 tabs
ruby
class RegistrationsController < ApplicationController
  def new
    @user = User.new
  end

  def create

Send a Welcome Email After Signup Using a Sidekiq Background Job in Rails

ruby rails sidekiq
by codesnips 4 tabs
rust
use clap::{Args, Parser, Subcommand, ValueEnum};

#[derive(Parser, Debug)]
#[command(name = "tasks", version, about = "A tiny task manager")]
pub struct Cli {
    #[arg(short, long, global = true)]

Building a clap Subcommand Dispatcher With a Command Trait in Rust

rust clap cli
by codesnips 3 tabs
php
<?php

namespace App\Http\Controllers;

use App\Models\Wallet;
use App\Services\WalletService;

Debit a Wallet Balance Safely with Row Locking in Laravel

laravel eloquent transactions
by codesnips 4 tabs
python
from flask import jsonify
from marshmallow import ValidationError as MarshmallowValidationError
from werkzeug.exceptions import HTTPException


class ApiError(Exception):

Structured JSON Error Handling for Flask API Validation Failures

flask rest-api error-handling
by codesnips 3 tabs