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
go
package hub

type Hub struct {
	subscribers map[*Subscriber]struct{}
	broadcast   chan []byte
	register    chan registration

Concurrent Fan-Out Event Hub With Non-Blocking Broadcast in Go

go concurrency channels
by codesnips 3 tabs
php
<?php

namespace App\Http\Requests\Wizard;

use Illuminate\Foundation\Http\FormRequest;

Multi-Step Onboarding Wizard in Laravel with Per-Step Form Requests and Session Progress

laravel forms validation
by codesnips 4 tabs
php
<?php

use App\Models\Conversation;
use App\Models\User;
use Illuminate\Support\Facades\Broadcast;

Broadcasting a Chat Message with Laravel Echo and Blade Components

laravel broadcasting websockets
by codesnips 4 tabs
ruby
class Comment < ApplicationRecord
  belongs_to :post
  belongs_to :author, class_name: "User"

  validates :body, presence: true, length: { maximum: 2_000 }

Broadcast Live Comment Updates with Turbo Streams in Rails

rails turbo hotwire
by codesnips 4 tabs