Skip to content

Instantly share code, notes, and snippets.

@mohashari
mohashari / snippet-1.txt
Created July 10, 2026 15:44
Optimizing Multi-LoRA Serving in Production: Dynamic Adapter Swapping with Triton Inference Server — code snippets
name: "ensemble_base_model"
backend: "vllm"
max_batch_size: 0
input [
{
name: "prompt"
data_type: TYPE_STRING
dims: [ 1 ]
},
@mohashari
mohashari / snippet-1.go
Created July 9, 2026 01:04
Implementing a Zero-Copy Message Broker in Go Using Linux splice(2) and TCP Zero-Copy — code snippets
package broker
import (
"fmt"
"sync"
"golang.org/x/sys/unix"
)
// Pipe represents a pair of kernel pipe file descriptors used for splicing.
type Pipe struct {
@mohashari
mohashari / snippet-1.sh
Created July 9, 2026 01:03
Hardening Kubernetes Control Planes against SSRF: Configuring Cilium Egress Gateways with SPIFFE Identities — code snippets
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set authentication.enabled=true \
--set authentication.mutual.spire.enabled=true \
--set authentication.mutual.spire.install.enabled=true \
--set authentication.mutual.spire.install.server.dataStorage.enabled=true \
--set egressGateway.enabled=true \
--set bpf.masquerade=true
@mohashari
mohashari / snippet-1.sql
Created July 9, 2026 01:01
Optimizing Retrieval-Augmented Generation (RAG) with Hierarchical Navigable Small World (HNSW) Index Quantization in pgvector — code snippets
-- Step 1: Add the half-precision vector column allowing NULLs initially
ALTER TABLE documents ADD COLUMN embedding_half halfvec(1536);
-- Step 2: Populate the new column in batches to prevent transaction log bloat
-- (For a live database, execute this in chunks of 50,000 rows using a background job)
UPDATE documents
SET embedding_half = embedding::halfvec(1536)
WHERE embedding_half IS NULL;
-- Step 3: Enforce the NOT NULL constraint after verification
@mohashari
mohashari / snippet-1.go
Created July 9, 2026 01:00
Tracing Distributed Transactions Across Async Queue Boundaries with OpenTelemetry Context Propagation — code snippets
package tracing
import (
"github.com/IBM/sarama"
"go.opentelemetry.io/otel/propagation"
)
// SaramaProducerCarrier injects trace context into Sarama producer message headers.
type SaramaProducerCarrier struct {
Headers *[]sarama.RecordHeader
@mohashari
mohashari / snippet-1.go
Created July 8, 2026 23:13
Designing a Conflict-Free Replicated Data Type (CRDT) for Collaborative Editing in Go — code snippets
package crdt
import (
"errors"
"sync"
)
// ID uniquely identifies an item in the CRDT space.
// Using compact numeric types minimizes heap allocation size and GC overhead.
type ID struct {
@mohashari
mohashari / snippet-1.sh
Created July 8, 2026 23:12
Dynamic Secret Rotation for Kafka Clients using Vault and Kubernetes CSI — code snippets
# Enable the PKI secrets engine at a specific path for Kafka client certs
vault secrets enable -path=kafka-pki pki
# Tune the secrets engine to support up to 30 days max TTL
vault secrets tune -max-lease-ttl=720h kafka-pki
# Generate the root CA certificate for Kafka clients
vault write -format=json kafka-pki/root/generate/internal \
common_name="Kafka Client Root CA" \
ttl=87600h > root_ca.json
@mohashari
mohashari / snippet-1.go
Created July 8, 2026 23:11
Building an Adaptive LLM Routing Gateway for Multi-Model Cost-Latency Tradeoffs — code snippets
package gateway
import "time"
// ModelConfig represents the static metadata and dynamic tracking of an LLM upstream.
type ModelConfig struct {
ID string `json:"id"`
Provider string `json:"provider"`
InputCostPerM float64 `json:"input_cost_per_m"` // USD per 1M input tokens
OutputCostPerM float64 `json:"output_cost_per_m"` // USD per 1M output tokens
@mohashari
mohashari / snippet-1.yaml
Created July 5, 2026 01:02
Securing Microservice-to-Microservice Communication via WireGuard Kernel-Level Encryption in Cilium CNI — code snippets
# Cilium CNI Helm values.yaml for enabling kernel-level WireGuard encryption
encryption:
enabled: true
type: wireguard
# Force the use of the native Linux kernel module instead of userspace BoringTun
wireguard:
userspace: false
# Port must be exposed and accessible between all cluster nodes
port: 51871
# Auto-calculate MTU based on physical link overhead
@mohashari
mohashari / snippet-1.go
Created July 5, 2026 01:01
Mitigating Memory Fragmentation in High-Throughput Go Services with Custom jemalloc Allocators — code snippets
package jemalloc
/*
#cgo LDFLAGS: -ljemalloc
#include <stdlib.h>
#include <jemalloc/jemalloc.h>
*/
import "C"
import (
"unsafe"