Skip to content

Instantly share code, notes, and snippets.

@mohashari
mohashari / snippet-1.txt
Created July 1, 2026 01:01
Automated Least-Privilege IAM Role Generation for AWS ECS Tasks Using eBPF Auditing — code snippets
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
char LICENSE[] SEC("license") = "GPL";
#define MAX_PAYLOAD_SIZE 128
struct ssl_event_t {
__u32 pid;
@mohashari
mohashari / snippet-1.go
Created July 1, 2026 01:00
Designing a Lock-Free Ring Buffer in Go for High-Throughput Memory-Mapped IPC — code snippets
package ipc
import (
"fmt"
"os"
"syscall"
)
// MmapSharedMemory opens or creates a file at the specified path,
// truncates it to the target size, and maps it into virtual memory.
@mohashari
mohashari / snippet-1.txt
Created June 30, 2026 01:02
Zero-Trust SPIRE-to-Envoy Integration for Dynamically Rotating Service-to-Service mTLS Credentials — code snippets
agent {
data_dir = "/run/spire/data"
log_level = "info"
server_address = "spire-server.spire.svc.cluster.local"
server_port = 8081
socket_path = "/run/spire/sockets/agent.sock"
trust_bundle_path = "/run/spire/bundle/bundle.crt"
trust_domain = "prod.muklis.dev"
}
@mohashari
mohashari / snippet-1.go
Created June 30, 2026 01:02
Implementing Raft Consensus Log Compaction via LSM-Tree SSTable Integration — code snippets
package storage
import (
"encoding/binary"
"fmt"
)
// KeyLayout defines the internal binary representation of a key in the LSM-tree.
// Keys are formatted as: [User Key (Variable)] [Raft Index (8 Bytes)] [Type (1 Byte)]
// Sorting by User Key ascending, and then Raft Index descending ensures that
@mohashari
mohashari / snippet-1.txt
Created June 30, 2026 01:01
Optimizing Vector Search Retrieval: Implementing HNSW Index Graphs with Custom Distance Metrics — code snippets
use std::alloc::{alloc, dealloc, Layout};
use std::ptr::NonNull;
pub struct VectorTable {
ptr: NonNull<f32>,
dimension: usize,
capacity: usize,
len: usize,
}
@mohashari
mohashari / snippet-1.txt
Created June 30, 2026 01:01
Building a Custom Prometheus Exporter for eBPF-based Disk I/O Latency Tracking in Go — code snippets
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
char LICENSE[] SEC("license") = "GPL";
struct hist_key {
u32 dev;
u32 bucket;
};
@mohashari
mohashari / snippet-1.yaml
Created June 29, 2026 01:03
Securing Kubernetes Ingress: Automating mTLS with Cert-Manager and SPIFFE/SPIRE — code snippets
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: spire-upstream-ca
namespace: spire
spec:
secretName: spire-upstream-ca-secret
duration: 2160h # 90 days
renewBefore: 360h # 15 days
commonName: spire-ca.prod.mycompany.internal
@mohashari
mohashari / snippet-1.txt
Created June 29, 2026 01:02
Building an In-Memory Semantic Cache for LLM Embeddings Using Rust and FAISS — code snippets
// Add these dependencies to your Cargo.toml for building the semantic cache
/*
[dependencies]
faiss = "0.12.0"
moka = { version = "0.12.0", features = ["future"] }
ort = "1.16.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.35", features = ["full"] }
tokenizers = "0.13.4"
@mohashari
mohashari / snippet-1.js
Created June 29, 2026 01:01
Real-Time Memory Leak Detection in Production Node.js Services Using V8 Heap Snapshots and Core Dumps — code snippets
const { PerformanceObserver } = require('perf_hooks');
const v8 = require('v8');
class MemoryAnomalyDetector {
constructor(thresholdPercentage = 0.85, sampleWindow = 5) {
this.thresholdPercentage = thresholdPercentage;
this.sampleWindow = sampleWindow;
this.postGcHeapHistory = [];
this.isDumping = false;
this.initGCListener();
@mohashari
mohashari / snippet-1.txt
Created June 29, 2026 01:01
Designing a High-Throughput Distributed Rate Limiter Using Redis Cell and Rust — code snippets
use bb8::Pool;
use bb8_redis::RedisConnectionManager;
/// Convenient type alias for the thread-safe connection pool.
pub type RedisPool = Pool<RedisConnectionManager>;
/// Initializes the asynchronous Redis connection pool with customizable limits.
pub async fn create_redis_pool(
redis_uri: &str,
max_pool_size: u32,