Skip to content

Instantly share code, notes, and snippets.

@monotykamary
monotykamary / request_analysis.sql
Created May 9, 2026 13:41
DuckDB SQL queries for analyzing pi coding agent sessions from JSONL logs
-- Pi HTTP Request Analysis
-- Counts all outbound HTTP requests: assistant API calls + tool calls
INSTALL json;
LOAD json;
-- Create a table from all JSONL session files
CREATE OR REPLACE TABLE events AS
SELECT * FROM read_json_auto('agent/sessions/*/*.jsonl', format='newline_delimited', ignore_errors=true, maximum_object_size=134217728);

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

  • LRUCache(capacity int) Initialize the cache with positive size capacity.
  • int get(int key) Return the value of the key if it exists, otherwise return -1.
  • void put(int key, value int) Update the value of the key if it exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity, evict the least recently used key.
  • Both get and put must run in O(1) average time complexity.
type LRUCache struct {
    // TODO: design your structs
}
@monotykamary
monotykamary / test.sh
Created April 18, 2026 20:11
wafer thinking test
echo "=== WITHOUT tools ==="
curl -s --max-time 30 "https://pass.wafer.ai/v1/chat/completions" \
-H "Authorization: Bearer $WAFER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "GLM-5.1",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Read the file /tmp/test.txt"}
],

Concurrent Data Pipeline with Backpressure

Implement a high-throughput data processor in Go that simulates the FireGroup analytics workload:

// ProcessData ingests items from a source channel, transforms them via a CPU-intensive 
// operation (simulate with time.Sleep), and sends to a sink. Requirements:
// 1. Process up to N items concurrently (worker pool), but limit total concurrent processing 
//    to prevent OOM under load (backpressure)
// 2. Implement graceful shutdown on context cancellation: finish in-flight items, 

Thread-Safe LRU Cache with TTL

Implement an in-memory LRUCache class in Ruby. It must support O(1) get and put operations. You need to handle production realities:

Requirements:

  1. get(key) → Returns value or nil if key doesn't exist or is expired.
  2. put(key, value, ttl_seconds) → Inserts/updates. Evicts least recently used if capacity exceeded. TTL is per-key expiration.
  3. Thread-safe: Multiple threads can safely call get/put concurrently.
  4. Expiration happens lazily (on access) or proactively (bonus points).
@monotykamary
monotykamary / bin_tree.md
Created April 7, 2026 08:07
Golang binary tree traversal

Given the root of a binary tree, return the level order traversal of its nodes' values (i.e., from left to right, level by level). [1, 2]

Example 1:

  • Input: root = [3,9,20,null,null,15,7]
  • Output: [[3],[9,20],[15,7]] [1, 3, 4, 5, 6]

Example 2:

  • Input: root = [1]
@monotykamary
monotykamary / reward_aggregator.md
Last active April 7, 2026 06:59
Reward Aggregator
# frozen_string_literal: true

# Reward Aggregator
# Partners return inconsistent key types: some JSON APIs return strings,
# internal services return symbols. Result must unify them.

GRAB_PARTNER = {
  'reward_a' => { 'points' => 5000, 'key' => 'gr-a', 'tier' => 'silver' },
  'reward_b' => { 'points' => 7500, 'key' => 'gr-b' },
@monotykamary
monotykamary / letta-code-memory-architecture.md
Last active December 18, 2025 15:43
Letta Code Memory Architecture Deep Dive - Comprehensive technical breakdown of how memory works in Letta Code
@monotykamary
monotykamary / CONTEXT_OPTIMIZATION_GUIDE.md
Last active December 10, 2025 08:45
Playwright MCP Context Optimization Guide - Reduce action tool responses by 86-100% with real measurements

Playwright MCP Context Optimization Guide

This document describes how to reduce context overflow when using Playwright MCP with LLMs. A single tool call can produce 400k+ tokens due to ads, trackers, cookie banners, and verbose page snapshots. These optimizations can reduce that by 80-90%.

Problem Statement

Playwright MCP returns full page snapshots (accessibility tree in YAML format) after every action. This causes:

  • Token overflow: 400k+ tokens per tool call on complex pages
  • Wasted context: Ads, trackers, cookie banners inflate content
  • Unnecessary data: Most actions don't need the resulting snapshot
@monotykamary
monotykamary / centroids.md
Last active November 25, 2025 12:22
Semantic centroids

Formal Definition: Hybrid Semantic-Dimensional Similarity

1. Preliminaries: The Embedding Space

Let $\mathcal{T}$ be the set of all possible text inputs. We define a pre-trained embedding function $E$ that maps text to a $d$-dimensional vector space $\mathbb{R}^d$.

$$ E: \mathcal{T} \to \mathbb{R}^d $$

For any text input $x \in \mathcal{T}$, its vector representation is $\mathbf{v}_x = E(x)$. We assume the standard measure of semantic distance in this space is Cosine Similarity.