hashing

typescript
import { createHash } from "crypto";
import { readFileSync } from "fs";

export function sha256(query: string): string {
  return createHash("sha256").update(query, "utf8").digest("hex");
}

GraphQL persisted queries (hash allowlist)

graphql security performance
by codesnips 3 tabs
ruby
class FeatureFlag < ApplicationRecord
  validates :key, presence: true, uniqueness: true
  validates :percentage,
            numericality: { only_integer: true,
                            greater_than_or_equal_to: 0,
                            less_than_or_equal_to: 100 }

Percentage-Based Feature Flag Rollout With a Stable Bucketing Gate in Rails

rails feature-flags rollout
by codesnips 4 tabs
rust
use std::collections::HashMap;
use std::path::PathBuf;

use walkdir::WalkDir;

pub fn group_by_size(root: &str) -> HashMap<u64, Vec<PathBuf>> {

Detect Duplicate Files with Parallel Blake3 Checksums in Rust

rust checksums blake3
by codesnips 4 tabs
rust
use crate::hashing::double_hash;

pub struct BloomFilter {
    bits: Vec<u64>,
    m: usize, // number of bits
    k: u32,   // number of hash probes

Bloom Filter for Deduplicating Seen URLs in a Web Crawler

bloom-filter probabilistic hashing
by codesnips 3 tabs
go
package mailer

import (
	"crypto/sha256"
	"encoding/hex"
	"strings"

Idempotent Email Sending with a Redis Fingerprint Set in Go

redis idempotency email
by codesnips 3 tabs
sql
CREATE TABLE password_reset_tokens (
  id          BIGSERIAL PRIMARY KEY,
  user_id     BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  token_hash  TEXT NOT NULL,
  expires_at  TIMESTAMPTZ NOT NULL,
  used_at     TIMESTAMPTZ,

Password reset tokens: hash + expiry

security express authentication
by codesnips 3 tabs
rust
mod chunker;mod parallel_hash;

use parallel_hash::{hash_buffer, root_hash};

const CHUNK_SIZE: usize = 64 * 1024;

Content-Defined Chunking With Parallel BLAKE3 Hashing Using Rayon

rust rayon parallelism
by codesnips 3 tabs