Skip to content

Instantly share code, notes, and snippets.

@harryscholes
harryscholes / main.rs
Created June 3, 2026 13:28
mini-jsongrep
//! # mini-jsongrep — a teaching implementation of the jsongrep pipeline
//!
//! This single file is a deliberately tiny, dependency-free re-implementation
//! of how `jsongrep` matches a path-query against a JSON document. It exists
//! to teach the five-stage pipeline that the real crate uses:
//!
//! 1. **Parse JSON into a tree.** (Here we hand-build a `Json` enum. The real
//! crate uses `serde_json_borrow` to parse text *zero-copy*.)
//! 2. **Parse the query string into an AST** (`parse` -> `Query`).
//! 3. **Compile the AST into an NFA** via *Glushkov's construction*
@harryscholes
harryscholes / main.sh
Created April 23, 2026 10:17
git worktree helpers
wt() {
# branch name
local name="$1"
# base branch for new worktrees
local base="${2:-main}"
# branch name with / replaced by - for use in directory name
local safe_name="${name//\//-}"
# current directory name; strip existing worktree suffix to get base repo name (uses _ as delimiter)
local repo_name="${PWD##*/}"
repo_name="${repo_name%%_*}"
@harryscholes
harryscholes / main.sh
Created February 17, 2026 21:15
agent git worktree functions
wt() {
# branch name
local name="$1"
# base branch for new worktrees
local base="${2:-main}"
# branch name with / replaced by - for use in directory name
local safe_name="${name//\//-}"
# current directory name; strip existing worktree suffix to get base repo name (uses _ as delimiter)
local repo_name="${PWD##*/}"
repo_name="${repo_name%%_*}"
@harryscholes
harryscholes / lib.rs
Last active February 12, 2026 23:21
Rust ontology
pub trait Ontology {
type Parent;
}
pub trait IsA<T> {}
/// Recursive blanket impl: `T` `is_a` `U` if `T`'s parent `is_a` `U`
impl<T, U> IsA<U> for T
where
T: Ontology,
@harryscholes
harryscholes / main.rs
Created January 8, 2026 11:57
FTS search recall using qrels
struct Qrel {
doc_id: String,
score: u32,
}
fn parse_queries_jsonl(
opt: SearchOptions,
) -> (Vec<VectorType>, Vec<Option<Struct>>, Vec<HashSet<KeyBytes>>) {
let queries_file = File::open(&opt.queries).expect("Cannot open queries file");
let queries_reader = BufReader::new(queries_file);
@harryscholes
harryscholes / main.rs
Created November 27, 2025 16:58
first experiments with vortex
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let session = VortexSession::empty()
.with::<ArraySession>()
.with::<VortexMetrics>()
.with::<LayoutSession>()
.with::<RuntimeSession>();
vortex::file::register_default_encodings(&session);
@harryscholes
harryscholes / docker-compose.yml
Created November 6, 2025 11:54
OpenSearch quickstart guide
services:
opensearch:
image: opensearchproject/opensearch:3
container_name: opensearch-node
environment:
- discovery.type=single-node
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
- DISABLE_INSTALL_DEMO_CONFIG=true
- DISABLE_SECURITY_PLUGIN=true
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=correct-horse-battery-staple
@harryscholes
harryscholes / bench.rs
Last active September 15, 2025 05:25
Roaring bitmap iteration benchmarks
use std::{hint::black_box, time::Duration};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use roaring::RoaringBitmap;
fn bench(c: &mut Criterion) {
for size in [1_000, 10_000, 100_000, 1_000_000] {
for sparsity in [0.001, 0.01, 0.1, 0.5, 1.0] {
let mut group = c.benchmark_group(format!("size={size}, sparsity={sparsity}"));
@harryscholes
harryscholes / bench.rs
Created August 18, 2025 12:58
Benchmark HashMap, BTreeMap and AHashMap for UUID keys
use std::{
collections::{BTreeMap, HashMap},
hint::black_box,
time::Duration,
};
use ahash::AHashMap;
use criterion::{BatchSize, Criterion, Throughput, criterion_group, criterion_main};
use uuid::Uuid;
@harryscholes
harryscholes / consistent_hash_ring.rs
Last active July 18, 2025 13:53
Consistent hash ring in Rust
use std::{
collections::HashMap,
hash::{DefaultHasher, Hash, Hasher},
};
const DEFAULT_VNODE_COUNT: usize = 1024;
struct VNode {
vnode_id: u64,
inode_id: usize,