Skip to content

Instantly share code, notes, and snippets.

@mohashari
mohashari / snippet-1.txt
Created July 21, 2026 01:02
Building a High-Throughput Speculative Decoding Middleware in Rust for LLM Inference Gateways — code snippets
use std::sync::Arc;
use tokio::sync::Mutex;
use uuid::Uuid;
pub struct SpeculativeSession {
pub session_id: Uuid,
pub prompt_tokens: Vec<u32>,
pub generated_tokens: Vec<u32>,
pub draft_lookahead: usize,
pub temperature: f32,
@mohashari
mohashari / snippet-1.yaml
Created July 21, 2026 01:01
Automating Ephemeral TLS Session Resumption Key Rotation Across Multi-Region Envoy Proxies — code snippets
# Static Envoy configuration demonstrating inline, hardcoded session ticket keys.
# DO NOT USE THIS IN PRODUCTION: Rotating keys requires a full configuration reload or process restart.
static_resources:
listeners:
- name: ingress_edge
address:
socket_address:
address: 0.0.0.0
port_value: 443
filter_chains:
@mohashari
mohashari / snippet-1.sql
Created July 21, 2026 01:00
Scaling Distributed Task Scheduling via PostgreSQL Advisory Locks and Bounded Queue Workers — code snippets
-- Robust schema for high-throughput scheduled tasks
CREATE TABLE scheduled_tasks (
id BIGSERIAL PRIMARY KEY,
task_type VARCHAR(64) NOT NULL,
payload JSONB NOT NULL DEFAULT '{}',
run_at TIMESTAMPTZ NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'queued',
max_retries INT NOT NULL DEFAULT 3,
retry_count INT NOT NULL DEFAULT 0,
error_log TEXT,
@mohashari
mohashari / snippet-2.txt
Created July 20, 2026 01:02
Optimizing LLM Context Caching at the Gateway Level: Implementing Prefix-Based Prompt Caching in a Rust API Proxy — code snippets
use sha2::{Sha256, Digest};
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ChatMessage {
pub role: String,
pub content: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
@mohashari
mohashari / snippet-1.yaml
Created July 20, 2026 01:01
Debugging DNS Resolution Latency Spikes in Kubernetes: Profiling CoreDNS and UDP Packet Drops with eBPF — code snippets
apiVersion: apps/v1
kind: Deployment
metadata:
name: payment-service
namespace: production
spec:
replicas: 10
template:
spec:
containers:
@mohashari
mohashari / snippet-1.go
Created July 19, 2026 01:02
Designing a Distributed Rate Limiter in Go Using Sliding Window Logs and Redis Cluster — code snippets
package ratelimit
import (
"context"
"fmt"
"time"
"github.com/google/uuid"
"github.com/redis/go-redis/v9"
)
@mohashari
mohashari / snippet-1.go
Created July 19, 2026 01:02
Preventing Secret Exfiltration in Kubernetes: Restricting DNS Resolution inside Pods via CoreDNS Policies and Cilium — code snippets
package main
import (
"context"
"encoding/base32"
"fmt"
"net"
"os"
"strings"
"time"
@mohashari
mohashari / snippet-1.txt
Created July 19, 2026 01:01
Implementing Dynamic Batching for LLM Inference in Custom C++ Server Gateways — code snippets
#include <queue>
#include <mutex>
#include <condition_variable>
#include <chrono>
#include <vector>
#include <optional>
template <typename T>
class ConcurrentBatchQueue {
public:
@mohashari
mohashari / snippet-1.json
Created July 15, 2026 01:02
Architecting a Real-Time Hybrid Search System: Combining Dense Vectors and BM25 Indexes in Elasticsearch — code snippets
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 1,
"refresh_interval": "30s",
"codec": "best_compression"
}
},
"mappings": {
@mohashari
mohashari / snippet-1.yaml
Created July 15, 2026 01:02
Building a Zero-Trust Service Mesh: Enforcing Mutual TLS and Fine-Grained Authorization Policies with Istio and SPIFFE/SPIRE — code snippets
apiVersion: spire.spiffe.io/v1alpha1
kind: ClusterSPIFFEID
metadata:
name: payment-service-spiffeid
spec:
spiffeIdTemplate: "spiffe://prod.example.org/ns/{{ .PodMeta.Namespace }}/sa/{{ .PodSpec.ServiceAccountName }}"
podSelector:
matchLabels:
app: payment-service
workloadSelector: