Skip to content

Instantly share code, notes, and snippets.

@mohashari
mohashari / snippet-1.txt
Created July 15, 2026 01:01
Designing a Lock-Free Ring Buffer for IPC with Shared Memory and POSIX Semaphores in C — code snippets
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <semaphore.h>
#include <sys/types.h>
#define RING_CAPACITY 4096 // Must be a power of two
#define MSG_PAYLOAD_SIZE 1024
@mohashari
mohashari / snippet-1.txt
Created July 15, 2026 01:00
Tracing Asynchronous Database Transactions Across Thread Pools with OpenTelemetry and Java Agent — code snippets
package com.example.observability;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ManualContextPropagator {
@mohashari
mohashari / snippet-1.py
Created July 14, 2026 01:04
Designing a Quantitative Metric for Microservice Coupling Using Graph Theory and Git History — code snippets
import os
import datetime
from collections import defaultdict
from git import Repo
import numpy as np
def analyze_git_temporal_coupling(repo_path, service_dirs, days=90):
repo = Repo(repo_path)
since_date = datetime.datetime.now() - datetime.timedelta(days=days)
@mohashari
mohashari / snippet-1.hcl
Created July 14, 2026 01:03
Automating Ephemeral SPIFFE/SPIRE ID Attestation for AWS Fargate Tasks via KMS and OIDC — code snippets
resource "aws_kms_key" "spiffe_attestation" {
description = "Asymmetric KMS Key for SPIFFE/SPIRE Fargate Attestation"
customer_master_key_spec = "RSA_2048"
key_usage = "SIGN_VERIFY"
deletion_window_in_days = 7
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
@mohashari
mohashari / snippet-1.go
Created July 14, 2026 01:02
Implementing a Lock-Free B-Link Tree in Go for Concurrent Indexing — code snippets
package blink
import (
"bytes"
"sync"
"sync/atomic"
"unsafe"
)
// Key represents the indexing key.
@mohashari
mohashari / snippet-1.txt
Created July 14, 2026 01:02
Building a Custom Guardrail Pipeline for LLM API Gateways Using Rust and WASM — code snippets
use log::{info, warn};
use proxy_wasm::traits::*;
use proxy_wasm::types::*;
proxy_wasm::main! {{
proxy_wasm::set_log_level(LogLevel::Info);
proxy_wasm::set_root_context(|_| -> Box<dyn RootContext> {
Box::new(GuardrailRootContext {
config: GuardrailConfig::default(),
})
@mohashari
mohashari / snippet-1.go
Created July 14, 2026 01:01
Detecting File Descriptor Exhaustion in gRPC Servers Using eBPF and OpenTelemetry Metrics — code snippets
package main
import (
"context"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "github.com/ashari/grpc-otel-ebpf/proto"
@mohashari
mohashari / snippet-1.go
Created July 12, 2026 01:02
Debugging gRPC Connection Leakage and HTTP/2 Stream Leaks Using eBPF and bpftrace — code snippets
package main
import (
"context"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
@mohashari
mohashari / snippet-1.py
Created July 12, 2026 01:02
Implementing Dynamic Chunking and Sparse Vector Search in Qdrant for Multi-Tenant RAG — code snippets
import re
from typing import List, Dict, Any
class MarkdownStructuralChunker:
def __init__(self, max_chunk_size: int = 1000):
self.max_chunk_size = max_chunk_size
self.header_regex = re.compile(r'^(#{1,6})\s+(.+)$', re.MULTILINE)
def chunk_document(self, text: str) -> List[Dict[str, Any]]:
lines = text.split('\n')
@mohashari
mohashari / snippet-1.go
Created July 12, 2026 01:01
Implementing a Lock-Free Consistent Hashing Ring with Bounded Loads in Go — code snippets
package main
import (
"sync/atomic"
)
// Node represents a physical backend server (e.g., a Redis or gRPC instance).
type Node struct {
ID string
Addr string