javascript
const BASE_URL = "/api/search";

export async function searchProducts(query, { signal } = {}) {
  const params = new URLSearchParams({ q: query, limit: "10" });
  const res = await fetch(`${BASE_URL}?${params}`, {
    signal,

Cancel Stale Autocomplete Requests with AbortController in a React Hook

react hooks abortcontroller
by codesnips 3 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
java
public class ProductAggregator implements AutoCloseable {

    private final RemoteServices services;
    private final ExecutorService pool = Executors.newFixedThreadPool(8);

    public ProductAggregator(RemoteServices services) {

Coordinate Parallel Remote Lookups With CompletableFuture in Java

java completablefuture concurrency
by codesnips 3 tabs
java
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.Instant;

Nightly Cleanup of Expired Refresh Tokens with Spring @Scheduled and a Bulk Delete Query

spring-boot scheduling cron
by codesnips 4 tabs
ruby
class ProjectPresenter
  def initialize(project, include_tasks: true)
    @project = project
    @include_tasks = include_tasks
  end

Building Nested JSON Presenters in Rails Without ActiveModel::Serializer

rails presenter json
by codesnips 3 tabs
ruby
class OrderPresenter < SimpleDelegator
  attr_reader :current_user

  def initialize(order, current_user:)
    super(order)
    @current_user = current_user

Presenter + fast_jsonapi Serializer for Clean JSON:API Responses in Rails

rails json-api serialization
by codesnips 3 tabs
php
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

Resize and Store User Avatars with Intervention Image in Laravel

laravel file-upload image-processing
by codesnips 3 tabs
typescript
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bull';
import { ScheduleModule } from '@nestjs/schedule';
import { DigestProducer } from './digest.producer';
import { DigestProcessor } from './digest.processor';

Scheduling and Processing Email Digests with a Bull Queue in NestJS

nestjs bull redis
by codesnips 3 tabs
javascript
const express = require('express');
const { enqueueEmail } = require('./emailQueue');

const router = express.Router();

router.post('/users/:id/welcome-email', async (req, res, next) => {

Reliable Background Email Jobs With BullMQ, Redis, and a Worker Process

bullmq redis background-jobs
by codesnips 3 tabs
typescript
import { AsyncLocalStorage } from 'node:async_hooks';

interface Store {
  requestId: string;
}

Propagate a Request ID Through NestJS Logs with AsyncLocalStorage

nestjs logging middleware
by codesnips 4 tabs
javascript
const { z } = require('zod');

const signupSchema = z
  .object({
    email: z
      .string()

Reusable Zod Schema Validation Middleware for Express Signup Routes

express zod validation
by codesnips 3 tabs
php
<?php

use App\Http\Controllers\DocumentsController;
use Illuminate\Support\Facades\Route;

Route::middleware('auth')->group(function () {

Soft Deletes with a Trash View and Restore Route in Laravel

laravel eloquent soft-deletes
by codesnips 4 tabs