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

type Broker struct {
	subscribers map[chan []byte]struct{}
	subscribe   chan chan []byte
	unsubscribe chan chan []byte

Server-Sent Events in Go with http.Flusher and Context Cancellation

sse streaming http
by codesnips 3 tabs
php
<?php

namespace App\Report;

use App\Repository\OrderRepository;
use Symfony\Contracts\Cache\ItemInterface;

Cache an Expensive Sales Report in Symfony With a Stamped Key and Invalidation Subscriber

symfony caching psr-6
by codesnips 3 tabs
rust
use axum::{
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},
    response::{IntoResponse, Response},
    Json,
};

Axum Bearer Token Extractor with Shared Auth State and Typed Claims

axum authentication middleware
by codesnips 3 tabs
ruby
class DownloadsController < ApplicationController
  before_action :authenticate_user!, only: :create
  skip_before_action :verify_authenticity_token, only: :show

  def create
    document = current_user.documents.find(params[:document_id])

Signed, Expiring Download URLs With HMAC Verification in Rails

rails hmac security
by codesnips 3 tabs
typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  // rawBody: true preserves the exact bytes Stripe signed
  const app = await NestFactory.create(AppModule, { rawBody: true });

Verify Stripe Webhook Signatures in a NestJS Guard Before the Handler

nestjs webhooks stripe
by codesnips 4 tabs
go
package config

import (
	"fmt"
	"os"
	"strconv"

Load Go Configuration From Environment Variables With Typed Defaults

go configuration environment-variables
by codesnips 3 tabs
php
<?php

namespace App\Controller;

use App\Message\ProcessStripeEvent;
use App\Webhook\StripeSignatureVerifier;

Verifying and Processing Stripe-Style Webhooks Idempotently in Symfony

symfony webhooks stripe
by codesnips 3 tabs
php
<?php

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

Throttled Last-Seen Tracking with Laravel Middleware and Redis Cache

laravel middleware redis
by codesnips 4 tabs
ruby
class ExportWriter
  def initialize(export)
    @export = export
  end

  def append(rows)

Chaining Dependent GoodJob Jobs with a Callback-Scheduled Continuation

rails good-job background-jobs
by codesnips 3 tabs
typescript
export interface AnalyticsEvent {
  name: string;
  props?: Record<string, unknown>;
  ts: number;
}

Batching Analytics Events With Interval Flush and Backpressure in TypeScript

analytics batching queue
by codesnips 3 tabs