ruby
module Authorizable
  extend ActiveSupport::Concern

  class NotAuthorized < StandardError; end

  included do

Rails Policy Authorization with a before_action Concern and 403 Rendering

rails authorization controllers
by codesnips 3 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
php
<?php

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

Soft-Delete and Restore Blog Posts with a Trash View in Laravel

laravel eloquent soft-deletes
by codesnips 4 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
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
rust
use std::collections::HashMap;
use std::sync::Mutex;

pub type AccountId = u64;
pub type Cents = i64;

Atomic Double-Entry Ledger Transfers With Rust Locking and Poison Recovery

ledger concurrency double-entry
by codesnips 3 tabs
typescript
export interface Page<T> {
  items: T[];
  nextCursor: string | null;
}

export interface Post {

Infinite-Scroll List in React with IntersectionObserver and Cursor Pagination

react hooks infinite-scroll
by codesnips 3 tabs
javascript
const express = require('express');
const webhookRouter = require('./webhookRouter');
const apiRouter = require('./apiRouter');

const app = express();

Verify Stripe Webhook Signatures with a Raw-Body Express Route

express stripe webhooks
by codesnips 3 tabs
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

Apply and Validate Coupon Codes with a Cart Totals Service in Laravel

laravel eloquent service-layer
by codesnips 4 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
rust
use serde::Serialize;
use serde_json::Value;

#[derive(Debug, Clone, Serialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum ChangeKind {

Diffing Two Config Snapshots Into a Typed Change List in Rust

rust serde config
by codesnips 3 tabs
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