java
package com.example.health;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;

Custom Spring Boot Actuator Health Indicators for Database and Disk

spring-boot actuator health-check
by codesnips 3 tabs
rust
use std::fs;
use std::path::Path;

#[derive(Debug, Clone)]
pub struct Migration {
    pub version: i64,

Sequential Schema Migrations With Version Tracking in Rust and Postgres

migrations postgres sql
by codesnips 3 tabs
typescript
import { Injectable, computed, signal } from '@angular/core';

@Injectable({ providedIn: 'root' })
export class LoadingService {
  private readonly activeRequests = signal(0);

Global Loading Spinner via In-Flight Request Tracking in an Angular HttpInterceptor

angular http-interceptor rxjs
by codesnips 4 tabs
php
<?php

use App\Http\Controllers\CommentController;
use Illuminate\Support\Facades\Route;

// The ->scoped() call forces {comment} to resolve through $post->comments,

Scoped Route-Model Binding for Nested Resources in Laravel

laravel routing route-model-binding
by codesnips 3 tabs
go
package limiter

import (
	"context"
	"errors"
)

Leaky-Bucket Concurrency Limiter with a Buffered Semaphore Channel in Go

go concurrency rate-limiting
by codesnips 3 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
ruby
require "csv"

class ProductImporter
  BATCH_SIZE = 500

  attr_reader :errors, :inserted

Bulk-Insert a Product CSV in Rails with a Service Object and upsert_all

rails csv bulk-insert
by codesnips 3 tabs
typescript
type Loader<T> = () => Promise<T>;

interface Entry<T> {
  value: T;
  expiresAt: number;
}

TTL Cache With In-Flight Request Deduplication for Async Calls

caching async deduplication
by codesnips 4 tabs
go
package feed

import "time"

type Post struct {
	ID        int64

Batch-Load Related Rows with a Single IN Query to Avoid N+1

go sql postgres
by codesnips 3 tabs
php
<?php

namespace App\Http\Controllers;

use App\Models\Order;
use App\Services\InvoicePdfService;

Stream a PDF Invoice from an Order with Dompdf in Laravel

laravel php dompdf
by codesnips 3 tabs
ruby
class Current < ActiveSupport::CurrentAttributes
  attribute :user, :request_id

  def permissions
    @permissions ||= PermissionSet.new(user)
  end

Memoizing Computed User Permissions Per Request with Current Attributes in Rails

rails authorization caching
by codesnips 4 tabs
typescript
export const PERMISSIONS = {
  READ_POSTS: 'posts:read',
  WRITE_POSTS: 'posts:write',
  DELETE_POSTS: 'posts:delete',
  MANAGE_USERS: 'users:manage',
} as const;

Typed Role-Based Route Guards with Permission Middleware in Express

express authorization rbac
by codesnips 3 tabs