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
java
package com.example.feed;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

Cursor-Paginated Feed With Keyset Query and Spring Data Slice

spring-boot spring-data-jpa pagination
by codesnips 4 tabs
ruby
class OrderCreationService
  Result = Struct.new(:success?, :order, :error, keyword_init: true)

  def initialize(customer:, line_params:)
    @customer = customer
    @line_params = line_params

Transactional Order Creation With Nested Savepoints in Rails

rails activerecord postgres
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
javascript
export const MAX_VISIBLE = 4;

const DEFAULTS = {
  variant: "info",
  duration: 4000,
};

Toast Notification Queue in React with Context and useReducer

react context-api usereducer
by codesnips 3 tabs
python
import re

EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")


class SignupValidator:

Validate a Flask Signup Form and Collect Per-Field Errors

flask validation forms
by codesnips 4 tabs
java
package com.example.orders.dto;

import com.example.orders.validation.ValidationGroups.Create;
import com.example.orders.validation.ValidationGroups.Update;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;

Cascading @Valid on Nested DTOs with Validation Groups in Spring Boot

spring-boot validation bean-validation
by codesnips 4 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
go
package store

import (
	"context"
	"database/sql"
)

Propagating a Context Deadline for Per-Request Timeouts in Go HTTP Handlers

go context http
by codesnips 3 tabs
java
@RestController
@RequestMapping("/api/products")
public class ProductController {

    private final ProductRepository repository;
    private final JsonMergePatchService patchService;

Spring Boot PATCH Endpoint With JSON Merge Patch (RFC 7386)

spring-boot rest-api json-merge-patch
by codesnips 4 tabs
java
@Configuration
@EnableAsync
public class AsyncConfig {

    @Bean(name = "downstreamExecutor")
    public ThreadPoolTaskExecutor downstreamExecutor() {

Aggregating Parallel Downstream Calls With CompletableFuture in a Spring @Async Service

spring-boot completablefuture async
by codesnips 4 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