go
package pqueue

type Job struct {
	ID       string
	Payload  interface{}
	Priority int

Priority Job Queue in Go Backed by container/heap

go container-heap priority-queue
by codesnips 3 tabs
ruby
module Paginatable
  extend ActiveSupport::Concern

  Page = Struct.new(:records, :next_cursor, keyword_init: true)

  DEFAULT_LIMIT = 25

Cursor-Paginated Rails API with ETag and Conditional GET Caching

rails api http-caching
by codesnips 3 tabs
php
<?php

namespace App\Controller;

use App\Entity\Tenant;
use App\Repository\InvoiceRepository;

Resolve the Current Tenant from the Request Host with a Symfony Argument Resolver

symfony multi-tenancy value-resolver
by codesnips 4 tabs
java
package com.example.audit.config;

import java.util.Optional;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;

Automatic JPA Auditing in Spring Boot with @CreatedDate and @LastModifiedBy

spring-boot spring-data-jpa auditing
by codesnips 4 tabs
plaintext
model User {
  id        String    @id @default(uuid())
  email     String    @unique
  name      String
  posts     Post[]
  deletedAt DateTime?

Soft-Delete and Restore in TypeScript with a Prisma Repository and Migration

prisma postgres soft-delete
by codesnips 4 tabs
ruby
class AddSlugToArticles < ActiveRecord::Migration[7.1]
  def change
    add_column :articles, :slug, :string, null: false, default: ""
    add_index :articles, :slug, unique: true

    # Backfill existing rows before the unique index is relied upon in code.

Generate Unique URL Slugs in Rails with before_validation and a friendly Controller Lookup

rails activerecord slugs
by codesnips 3 tabs
javascript
import React, { createContext, useCallback, useMemo, useRef, useState } from 'react';
import { ToastViewport } from './ToastViewport';

export const ToastContext = createContext(undefined);

let counter = 0;

Build a React Toast Notification System with Context Provider, Hook, and Portal

react toast context-api
by codesnips 4 tabs
java
package com.example.orders.event;

import java.math.BigDecimal;
import java.time.Instant;

public final class OrderPlacedEvent {

Publishing Domain Events After Commit with @TransactionalEventListener in Spring Boot

spring-boot spring-events transactions
by codesnips 4 tabs
rust
use std::cmp::{Ordering, Reverse};

#[derive(Debug, Clone)]
pub struct ScheduledTask<T> {
    pub priority: u8,
    pub seq: u64,

Priority Task Scheduler in Rust with BinaryHeap and Reverse Ordering

rust binary-heap scheduler
by codesnips 3 tabs
python
from __future__ import annotations

from dataclasses import dataclass, field
from decimal import Decimal, ROUND_HALF_UP
from typing import Optional, Protocol

Composable Order Discount Pipeline With Rule Objects in Python

pipeline strategy-pattern discounts
by codesnips 3 tabs
php
<?php

namespace App\Events;

use App\Models\Order;
use Illuminate\Broadcasting\PrivateChannel;

Broadcasting Order Status Updates to a Private Channel with Laravel Echo

laravel broadcasting websockets
by codesnips 4 tabs
go
package store

import (
	"errors"
	"fmt"
	"time"

Wrapping Errors with Context and Inspecting Them via errors.Is and errors.As in Go

errors error-handling error-wrapping
by codesnips 3 tabs