Skip to content

Instantly share code, notes, and snippets.

View fzakaria's full-sized avatar

Farid Zakaria fzakaria

View GitHub Profile
@fzakaria
fzakaria / qemu_aarch64_filter.bpf.c
Created July 4, 2026 21:04
eBPF binfmt qemu aarch64 example
// SPDX-License-Identifier: GPL-2.0
/*
* binfmt_misc 'B' (BPF) program: match aarch64 ELF binaries and choose the
* interpreter (qemu-aarch64) dynamically via bpf_binprm_set_interp().
*
* The program is given the BINPRM_BUF_SIZE file header as context. It inspects
* the ELF header and, on a match, sets the interpreter and returns 1. This
* makes the handler a superset of a traditional magic rule: the program both
* decides the match and computes the interpreter path (it could equally derive
* a path relative to the binary).
@fzakaria
fzakaria / build.go
Last active June 21, 2026 19:59
Nix build in under 100 lines
package main
import (
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
)
@fzakaria
fzakaria / README.md
Created June 8, 2026 15:12
Cache-aware struct benchmarks: pointer-chasing staircase & AoS vs SoA

Cache-Aware Struct Benchmarks

Benchmarks demonstrating how struct size and memory layout affect performance due to CPU cache behavior. Companion code for the blog post Every byte matters.

Benchmarks

1. Pointer-Chasing (cache staircase)

@fzakaria
fzakaria / def.bzl
Created June 12, 2025 23:40
Compile jar to source jar mapping
ClassPathInfo = provider(
"Provider for classpath information",
fields = {
"compile_jars": "A json fragment containing the mapping of the current jar to its source jar",
},
)
def _classpath_aspect_impl(target, ctx):
java_info = target[JavaInfo]
compile_jars = depset(
@fzakaria
fzakaria / flatbuffer.bzl
Created May 19, 2025 21:38
Creating Java libraries for flatbuffers with flatc
"""
FlatBuffer Java rule for Bazel
"""
FlatbufferInfo = provider(
doc = "A provider for FlatBuffer schema files.",
fields = {
"fbs_files": "The list of fbs files that were used as inputs",
},
)
@fzakaria
fzakaria / BUILD.bazel
Created May 14, 2025 21:29
Genrule to check Linux sandbox
genrule(
name = "check_cgroup",
outs = ["cgroup_output.txt"],
cmd = """
set -euo pipefail
echo "==== /proc/self/cgroup ====" > $@
cat /proc/self/cgroup >> $@
echo "" >> $@
@fzakaria
fzakaria / analyze_git_signatures.py
Created April 16, 2025 16:03
Find the number of git commits that have changed public signatures in Java code
#! /usr/bin/env python3
import subprocess
import re
import datetime
from collections import defaultdict, Counter
import argparse
import os
import sys
@fzakaria
fzakaria / generate_classpath.py
Created March 14, 2025 20:43
Generate a .classpath from a text file
import sys
import os
from xml.etree import ElementTree as ET
from xml.dom import minidom
# Usage: python gen_classpath.py jars.txt /path/to/bazel/workspace
def find_binary_jar(source_jar):
"""Replace '-sources.jar' or '-src.jar' with '.jar' or 'lib' prefix if necessary"""
dir_name, file_name = os.path.split(source_jar)
@fzakaria
fzakaria / count_dyn_syms.py
Created March 13, 2025 22:31
Count exported symbols from all shared objects in the dependency tree
#! /usr/bin/env nix
#! nix shell github:tomberek/-#python3With.pyelftools --command python3
import sys
import subprocess
import re
import os
from elftools.elf.elffile import ELFFile
from elftools.elf.constants import SHN_INDICES
@fzakaria
fzakaria / MODULE.bazel
Created January 14, 2025 19:58
Using Bazel Build Event Service (BES)
build_event_stream_repo = use_extension("//tools/build_defs:bes_repo.bzl", "build_event_service_repo")
build_event_stream_repo.settings(
name = "bazel_bes",
revision = "7.4.1",
sha256s = {
"build_event_stream.proto": "7388663cc11b0642ffce0e3a14bd4c4902b913fb5697e5cf47b7a4d7c8ba5640",
"command_line.proto": "a6fb6591aa50794431787169bc4fae16105ef5c401e7c30ecf0f775e0ab25c2c",
"invocation_policy.proto": "7a1f9074d64aaea2c5fc01df093a25fbbd68d84db63fbfb355f5aa15683a75cd",
"option_filters.proto": "bc1cc29e53e2856c3ae25149cc6661bb218737a9146e7417eb29f8caaa715821",