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 feed

import (
	"encoding/base64"
	"encoding/json"
	"time"

Cursor-Based Keyset Pagination for a Postgres Feed API in Go

go postgres pagination
by codesnips 3 tabs
rust
use dashmap::DashMap;
use std::time::Instant;

pub struct TokenBucket {
    tokens: f64,
    last_refill: Instant,

Token-Bucket Rate Limiter Middleware for Axum Using DashMap

axum rust rate-limiting
by codesnips 3 tabs
typescript
export interface Todo {
  id: string;
  title: string;
  completed: boolean;
}

Optimistic UI Updates with Rollback Using React Query useMutation

react react-query optimistic-ui
by codesnips 3 tabs
typescript
export type EventMap = Record<string, unknown[]>;

type Listener<Args extends unknown[]> = (...args: Args) => void;

export class TypedEmitter<Events extends EventMap> {
  private listeners = new Map<keyof Events, Set<Listener<any>>>();

Type-Safe Event Emitter With Strongly-Typed Listener Payloads in TypeScript

typescript events event-emitter
by codesnips 3 tabs
javascript
const MAX_LIMIT = 100;
const DEFAULT_LIMIT = 20;
const ALLOWED_ORDER = new Set(['asc', 'desc']);

function decodeCursor(raw) {
  const json = Buffer.from(raw, 'base64').toString('utf8');

Cursor-Based Pagination in Express With Query-Parsing Middleware

express pagination cursor-pagination
by codesnips 3 tabs
java
package com.example.catalog.web;

import com.example.catalog.domain.Product;
import java.math.BigDecimal;

public record ProductResponse(

Paginated Product Search Endpoint with Spring Data JPA Specifications

spring-boot spring-data-jpa pagination
by codesnips 4 tabs
lua
-- KEYS[1] = bucket key
-- ARGV[1] = capacity, ARGV[2] = refill_per_sec, ARGV[3] = now (float seconds)
local capacity = tonumber(ARGV[1])
local rate = tonumber(ARGV[2])
local now = tonumber(ARGV[3])

Redis-Backed Token Bucket Rate Limiter as FastAPI Middleware

fastapi redis rate-limiting
by codesnips 4 tabs
ruby
require 'sinatra/base'
require_relative 'upload_store'

class UploadApp < Sinatra::Base
  MAX_BYTES = 50 * 1024 * 1024

Streaming Multipart File Uploads to Disk in Sinatra Without Buffering

sinatra rack file-upload
by codesnips 3 tabs
php
<?php

namespace App\Event;

use Symfony\Contracts\EventDispatcher\Event;

Symfony: Send a Welcome Email Asynchronously with Messenger and an Event Subscriber

symfony messenger async
by codesnips 4 tabs
go
package watch

import (
	"sync"
	"time"
)

Debounce Filesystem Change Events Before Triggering a Rebuild in Go

fsnotify debounce filewatcher
by codesnips 3 tabs
rust
use std::collections::HashMap;

#[derive(Debug, PartialEq)]
pub enum LogLevel {
    Info,
    Warn,

Streaming Log File Aggregation With Buffered Line Iteration in Rust

rust streaming file-io
by codesnips 3 tabs