rust
pub enum Node {
    File { name: String, size: u64 },
    Dir { name: String, children: Vec<Node> },
}

impl Node {

Modeling a Filesystem Tree in Rust with Recursive Enums and Total Size

rust recursion enums
by codesnips 3 tabs
php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Optimistic Locking With a Version Column in Laravel Eloquent

laravel eloquent optimistic-locking
by codesnips 4 tabs
ruby
class CreateIdempotencyKeys < ActiveRecord::Migration[7.1]
  def change
    create_table :idempotency_keys do |t|
      t.string :key, null: false
      t.string :request_path, null: false
      t.datetime :locked_at

Idempotent Form Submissions in Rails with an Idempotency-Key Column and before_action Guard

rails idempotency postgres
by codesnips 4 tabs
typescript
import jwt, { JwtPayload, SignOptions } from 'jsonwebtoken';

const SECRET = process.env.JWT_SECRET as string;
const ISSUER = 'auth.example.com';
const AUDIENCE = 'api.example.com';

Signing and Verifying JWT Access Tokens with Express Middleware

jwt express authentication
by codesnips 3 tabs
java
package com.example.caching.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.ShallowEtagHeaderFilter;

Conditional GET with ETag ShallowEtagHeaderFilter and Cache-Control in Spring Boot

spring-boot http-caching etag
by codesnips 3 tabs
python
from sqlalchemy import Column, Integer, BigInteger, String
from sqlalchemy.orm import declarative_base

Base = declarative_base()

Optimistic Locking With a Version Column and Bounded Retries in SQLAlchemy

sqlalchemy postgres optimistic-locking
by codesnips 3 tabs
rust
use std::str::FromStr;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Frequency {
    Daily,
    Weekly,

Parse iCalendar RRULE and Recurrence Data into Typed Rust Enums

rust parsing icalendar
by codesnips 3 tabs
php
<?php

namespace App\Correlation;

final class CorrelationIdStorage
{

Propagate a Correlation ID Through Symfony Requests and Monolog Logs

symfony monolog logging
by codesnips 4 tabs
php
<?php

namespace App\Http\Controllers;

use App\Jobs\SendNewsletterChunk;
use App\Models\NewsletterSend;

Chunk-Process a Large Newsletter Send with Laravel Job Batching and Progress Tracking

laravel queues job-batching
by codesnips 3 tabs
rust
const CONSECUTIVE_BONUS: f64 = 8.0;
const WORD_START_BONUS: f64 = 10.0;
const MATCH_BASE: f64 = 4.0;
const LEADING_PENALTY: f64 = 0.5;

#[derive(Debug, Clone, Copy)]

Fuzzy Search Ranker with Subsequence Matching and Score-Based Sorting in Rust

fuzzy-search ranking algorithms
by codesnips 3 tabs
ruby
module HealthCheckable
  extend ActiveSupport::Concern

  CheckResult = Struct.new(:name, :ok, :message, keyword_init: true)

  private

Rails Health-Check Endpoint With a Controller Concern and Database Ping

rails health-check monitoring
by codesnips 3 tabs
java
package com.example.http;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;

Attaching Bearer Tokens to Spring RestClient Calls with a ClientHttpRequestInterceptor

spring-boot restclient interceptor
by codesnips 3 tabs