php
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\PostResource;

Cursor Pagination for Eloquent Queries Exposed as a JSON API in Laravel

laravel eloquent pagination
by codesnips 3 tabs
python
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from .models import EmailOutbox

Sending Welcome Emails via a Django post_save Signal and Outbox Worker

django signals email
by codesnips 4 tabs
go
package feed

import "time"

type Event struct {
	ID        string    `json:"id"`

Stream and Decode Newline-Delimited JSON (NDJSON) from an HTTP Response Body in Go

go ndjson streaming
by codesnips 3 tabs
ruby
class Current < ActiveSupport::CurrentAttributes
  attribute :tenant, :request_id

  def tenant=(tenant)
    super
    Rails.logger.tagged("tenant=#{tenant&.id}") if tenant

Tenant Isolation in Rails with CurrentAttributes and an around_action

rails multi-tenancy current-attributes
by codesnips 4 tabs
javascript
import { useCallback, useEffect, useRef, useState } from 'react';

export function usePaginatedFetch(fetchPage, { pageSize = 20 } = {}) {
  const [items, setItems] = useState([]);
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState(null);

Infinite Scroll in React with IntersectionObserver and a Paginated Fetch Hook

react hooks infinite-scroll
by codesnips 3 tabs
java
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Time-Based Caffeine Cache for Expensive Currency Rate Lookups in Spring

caffeine caching spring
by codesnips 3 tabs
python
import base64
import json
from datetime import datetime
from typing import Optional, Tuple

Opaque Cursor Pagination for FastAPI Endpoints with SQLAlchemy

fastapi sqlalchemy pagination
by codesnips 3 tabs
ruby
class CreateAuditLogs < ActiveRecord::Migration[7.1]
  def change
    create_table :audit_logs do |t|
      t.references :auditable, polymorphic: true, null: false
      t.references :user, null: true, foreign_key: true
      t.string :action, null: false

Rails Audit Log for Model Changes Using ActiveRecord Callbacks

rails activerecord callbacks
by codesnips 4 tabs
php
<?php

namespace App\Services;

use App\Models\Order;
use Illuminate\Support\Facades\Cache;

Cache Expensive Dashboard Aggregates and Bust Them on Write in Laravel

laravel caching redis
by codesnips 4 tabs
rust
use serde::{Deserialize, Deserializer};
use time::OffsetDateTime;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserProfile {

Deserializing Optional and Renamed JSON API Fields with Serde in Rust

rust serde serde-json
by codesnips 2 tabs
python
import csv


class _LineBuffer:
    def __init__(self):
        self._data = ""

Stream a Large CSV Export in Chunks from a Flask Endpoint

flask streaming csv
by codesnips 3 tabs
java
package com.example.signup.validation;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

Custom @UniqueEmail Bean Validation Constraint in Spring Boot Signup

spring-boot bean-validation jsr380
by codesnips 4 tabs