Code Explainers

Code explainers tagged #hashing

ruby
class LogAggregator
  BUCKET_FORMAT = "%Y-%m-%dT%H:%M"
 
  def initialize(entries)

Bucketing log entries by the minute in Ruby

aggregation hashing enumerable
Intermediate 5 steps
ruby
class ApplicationController < ActionController::Base
  EXPERIMENTS = {
    checkout_button_color: %w[control blue green],
    onboarding_flow: %w[control streamlined]

How A/B test cohorts are assigned in Rails

a-b-testing cookies hashing
Intermediate 8 steps
javascript
const crypto = require('crypto');
 
function idempotency({ store, ttlMs = 24 * 60 * 60 * 1000 }) {
  return async function idempotencyMiddleware(req, res, next) {

Idempotent POST requests in Express

idempotency middleware caching
Advanced 8 steps
rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{request::Parts, StatusCode},

A proof-of-work extractor in Axum

proof-of-work extractors hashing
Advanced 9 steps
java
@Component
public class ApiKeyRotationFilter extends OncePerRequestFilter {
 
    private static final String API_KEY_HEADER = "X-Api-Key";

Building an API key rotation filter in Spring

servlet-filter authentication caching
Intermediate 10 steps
go
package middleware
 
import (
	"hash/fnv"

A percentage feature-rollout middleware in Gin

feature-flags middleware hashing
Intermediate 6 steps
go
package dedup
 
import (
	"crypto/sha256"

Finding duplicate files by content hash in Go

hashing filesystem deduplication
Intermediate 8 steps
rust
use axum::body::Bytes;
use axum::http::{header, HeaderValue, StatusCode};
use axum::response::{IntoResponse, Response};
use serde::Serialize;

Custom Axum responses with per-user ETags

etag trait-implementation generics
Intermediate 7 steps
python
import hashlib
from collections import defaultdict
from pathlib import Path
 

Finding duplicate files by size then hash

hashing file-io deduplication
Intermediate 7 steps
php
<?php
 
namespace App\FeatureFlags;
 

How a feature flag evaluator decides

feature-flags rollout hashing
Intermediate 8 steps
php
<?php
 
namespace App\Queue;
 

Deduplicating a job queue with Redis

deduplication redis atomicity
Advanced 8 steps
ruby
class UserColor
  GOLDEN_RATIO_CONJUGATE = 0.618033988749895
 
  def initialize(username)

Deriving a stable color from a username

hashing color-theory deterministic-mapping
Intermediate 7 steps
python
import hashlib
import json
from fastapi import APIRouter, Request, Response, Depends, HTTPException, status
 

HTTP ETag caching in a FastAPI route

http-caching etag conditional-requests
Intermediate 9 steps
java
public class DuplicateFinder {
 
    public Map<String, List<Path>> findDuplicates(Path root) throws IOException {
        Map<String, List<Path>> byHash = new HashMap<>();

Finding duplicate files by content hash

hashing file-io streams
Intermediate 8 steps
rust
use std::fs::File;
use std::io::{self, Read};
use std::path::Path;
 

Streaming a SHA-256 hash of a file in Rust

hashing buffered-io streaming
Intermediate 5 steps
go
package checksum
 
import (
	"crypto/sha256"

Computing SHA-256 checksums in Go

hashing io-streaming filesystem-walk
Intermediate 7 steps
php
<?php
 
namespace App\Services;
 

Phone verification codes in Laravel

rate-limiting caching hashing
Intermediate 7 steps
ruby
require "digest"
 
class UploadDeduplicator
  CHUNK_SIZE = 64 * 1024

Deduplicating uploads by content hash

hashing deduplication streaming-io
Intermediate 7 steps