java
@RestController
@RequestMapping("/api/notifications")
public class NotificationController {

    private final SseEmitterRegistry registry;
    private final NotificationService service;

Push Live Notifications with Server-Sent Events in Spring Boot

spring-boot sse server-sent-events
by codesnips 3 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
yaml
framework:
    workflows:
        order:
            type: state_machine
            marking_store:
                type: method

Guarding an Order State Transition with Symfony's Workflow Component and a Guard Listener

symfony workflow state-machine
by codesnips 4 tabs
java
@Entity
@Table(name = "idempotency_records",
       uniqueConstraints = @UniqueConstraint(columnNames = "idempotency_key"))
public class IdempotencyRecord {

    public enum Status { IN_PROGRESS, COMPLETED }

Idempotent POST Handling in Spring Boot with a Stored Idempotency-Key

spring-boot idempotency rest-api
by codesnips 3 tabs
typescript
import { useEffect, useState } from 'react';

export function useLocalStorage<T>(
  key: string,
  initialValue: T
): [T, (value: T) => void] {

Persisting a Dark-Mode Theme Toggle with a React ThemeProvider and localStorage

react context hooks
by codesnips 4 tabs
ruby
class Article < ApplicationRecord
  has_many :taggings, dependent: :destroy
  has_many :tags, through: :taggings

  scope :published, -> { where.not(published_at: nil) }

Filtering a Listing by Tags with a has_many :through Scope and a Query Object

rails activerecord has-many-through
by codesnips 3 tabs
php
<?php

namespace App\Jobs;

use App\Models\Invoice;
use App\Services\StripeGateway;

Preventing Double-Charges in Laravel with WithoutOverlapping Job Middleware

laravel queues background-jobs
by codesnips 3 tabs
javascript
import { useState, useEffect, useCallback } from 'react';

export function useLocalStorage(key, initialValue) {
  const readValue = useCallback(() => {
    if (typeof window === 'undefined') return initialValue;
    try {

Persist a React Shopping Cart to localStorage with a Context Provider

javascript react context
by codesnips 3 tabs
php
<?php

declare(strict_types=1);

namespace App\Security;

PHP Login Rate Limiting with a Sliding-Window Throttle Middleware

php rate-limiting middleware
by codesnips 3 tabs
go
package upload

import (
	"errors"
	"io"
	"log"

Streaming Multipart File Uploads to Disk in Go net/http

go net-http multipart
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

namespace App\Models;

use App\Support\TransientUrl;
use Illuminate\Database\Eloquent\Model;

Generate Temporary Signed S3 Download URLs for Private Files in Laravel

laravel s3 storage
by codesnips 4 tabs