Skip to content

Instantly share code, notes, and snippets.

@mohashari
mohashari / snippet-1.txt
Created July 26, 2026 01:03
Designing a Lock-Free Read-Copy-Update (RCU) Cache in C++ for Ultra-Low Latency Routing Tables — code snippets
#include <atomic>
#include <vector>
#include <thread>
#include <mutex>
#include <algorithm>
#include <limits>
struct Node {
Node* next{nullptr};
virtual ~Node() = default;
@mohashari
mohashari / snippet-1.sh
Created July 26, 2026 01:02
Implementing Ephemeral WireGuard VPN Tunnels for Secure Cross-Cloud Database Replication — code snippets
#!/usr/bin/env bash
set -euo pipefail
# Enable IP forwarding and disable reverse path filtering hazards
echo "Optimizing network sysctl for WireGuard gateway..."
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv4.conf.all.forwarding=1
sudo sysctl -w net.ipv4.conf.all.rp_filter=2
sudo sysctl -w net.ipv4.conf.default.rp_filter=2
@mohashari
mohashari / snippet-1.txt
Created July 26, 2026 01:01
Debugging Socket Buffer Bloat and TCP Queueing Delay in High-Throughput Go Services with eBPF — code snippets
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_endian.h>
char LICENSE[] SEC("license") = "GPL";
struct event {
__u32 pid;
__u64 duration_ns;
@mohashari
mohashari / snippet-1.py
Created July 26, 2026 01:00
Implementing Custom KV Cache Eviction Policies in vLLM for Multi-Tenant Chatbots — code snippets
from fastapi import Request, HTTPException
from typing import Dict, Any
import jwt
# Secret key used for decoding JWT headers passed by the API Gateway
JWT_SECRET = "production_super_secret_key_rotation_99"
class TenantContextMiddleware:
async def __call__(self, request: Request, call_next):
# Extract JWT from Authorization header
@mohashari
mohashari / snippet-1.txt
Created July 25, 2026 01:05
Designing a Zero-Allocation Circular Buffer Log Writer in C++ Using Atomic Memory Operations and Memory-Mapped Files — code snippets
#include <atomic>
#include <cstdint>
struct alignas(64) LogSlot {
std::atomic<uint32_t> status; // 0 = Empty, 1 = Writing, 2 = Ready
uint32_t length;
char payload[248]; // 256 bytes total slot size (perfectly fits 4 cache lines)
};
struct alignas(64) LogControlBlock {
@mohashari
mohashari / snippet-1.yaml
Created July 25, 2026 01:04
Implementing Zero-Trust Service-to-Service Authorization Using Envoy Proxies and Open Policy Agent (OPA) — code snippets
# Envoy HTTP filter configuration for OPA external authorization
http_filters:
- name: envoy.filters.http.ext_authz
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz
grpc_service:
envoy_grpc:
cluster_name: ext-authz-opa
timeout: 0.15s
transport_api_version: V3
@mohashari
mohashari / snippet-1.txt
Created July 25, 2026 01:03
Implementing Pipeline Parallelism for Distributed Transformer Inference on Local Hardware Using Socket-Based IPC in Rust — code snippets
use std::convert::TryInto;
use std::slice;
#[repr(C, align(8))]
#[derive(Debug, Copy, Clone)]
pub struct FrameHeader {
pub magic: [u8; 4], // Must be b"TNSR"
pub msg_type: u8, // 1: Token IDs (prefill), 2: Activations, 3: Logits, 4: Error
pub shape_rank: u8,
pub padding: [u8; 2], // Structural padding to align to 8-byte boundary
@mohashari
mohashari / snippet-1.yaml
Created July 25, 2026 01:02
Debugging CPU Throttling and CFS Bandwidth Control Issues in High-Throughput Go Containers Running on Kubernetes — code snippets
apiVersion: apps/v1
kind: Deployment
metadata:
name: high-throughput-service
namespace: production
spec:
replicas: 10
template:
metadata:
labels:
@mohashari
mohashari / snippet-1.sh
Created July 24, 2026 01:03
Implementing Real-Time Tensor-Parallelism Communication Over RDMA (RoCEv2) for Distributed LLM Inference — code snippets
#!/usr/bin/env bash
# Production initialization script for configuring RoCEv2 lossless network interfaces (Mellanox ConnectX)
set -euo pipefail
INTERFACE="eth0"
# RoCEv2 uses DSCP value 26 (CS3) or 46 (EF) commonly. We will map traffic class to DSCP 26.
PRIORITY=3
DSCP=26
echo "=== Configuring sysctl parameters for high-performance RDMA ==="
@mohashari
mohashari / snippet-1.yaml
Created July 24, 2026 01:02
Preventing Privilege Escalation in Kubernetes via eBPF-Based Dynamic Seccomp Profile Generation and Enforcement — code snippets
apiVersion: security-profiles-operator.x-k8s.io/v1alpha1
kind: ProfileRecording
metadata:
name: payment-service-recorder
namespace: core-payments
spec:
kind: SeccompProfile
recorder: bpf
podSelector:
matchLabels: