Skip to content

Instantly share code, notes, and snippets.

View fzakaria's full-sized avatar

Farid Zakaria fzakaria

View GitHub Profile
@fzakaria
fzakaria / jar_index.bzl
Created November 7, 2024 17:47
Bazel Starlark rule to create a JarIndex
def _jar_index_impl(ctx):
java_info = ctx.attr.src[JavaInfo]
java_runtime = ctx.attr._java_runtime[java_common.JavaRuntimeInfo]
java_home = java_runtime.java_home
jar_bin = "%s/bin/jar" % java_home
runtime_jars = " "
for jar in java_info.transitive_runtime_jars.to_list():
runtime_jars += jar.path + " "
@fzakaria
fzakaria / BUILD.bazel
Created October 4, 2024 02:59
Creating a JAR natively in Starlark
load("@bazel_skylib//rules:write_file.bzl", "write_file")
genrule(
name = "example",
outs = ["example.jar"],
cmd = """
OLD_CWD=$$(pwd) && cd $(RULEDIR) && \\
$$OLD_CWD/$(JAVABASE)/bin/jar cmfv $(rootpath :manifest) \\
$$OLD_CWD/$@ $(rootpath :main_class)
@fzakaria
fzakaria / index.html
Created August 8, 2024 16:02
A little web-page for my Raspberry Pi to show the local surf conditions at Steamer Lane, Santa Cruz, CA
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Santa Cruz Surf Watch</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
@fzakaria
fzakaria / github_webhook.malloy
Created June 13, 2024 16:56
Malloy for GitHub webhook data
# First we declare out source which is a single table.
# You can join other sources together and Malloy will take care of doing the
# correct join conditions.
# To see the github events you can look at:
# https://docs.github.com/en/webhooks/webhook-events-and-payloads
source: github_events is duckdb.table('./github_events.parquet') extend {
dimension:
is_pull_request is metadata.event = 'pull_request'
measure:
counts is count()
@fzakaria
fzakaria / graph_workflow.py
Created March 3, 2024 23:51
Graph a GitHub Workflow using plotnine
import pandas as pd
from plotnine import ggplot, aes, geom_line, theme, labs, scale_x_datetime, element_text, geom_point
import json
from datetime import datetime
# $ gh run list --workflow buildAndTestBazel.yml --repo openxla/stablehlo --json startedAt,updatedAt --status completed --branch main --limit 100 > json_data.json
# Assuming `json_data` is your JSON data loaded into a variable
# If your JSON is in a file, you can load it with:
with open('json_data.json', 'r') as f:
json_data = json.load(f)
@fzakaria
fzakaria / elf_loader.py
Created October 10, 2023 17:35
ELF Loader in python
import ctypes
import mmap
import struct
# Simplified ELF Header Structure
class Elf32_Ehdr(ctypes.Structure):
_fields_ = [
("e_ident", ctypes.c_char * 16),
("e_type", ctypes.c_uint16),
("e_machine", ctypes.c_uint16),
@fzakaria
fzakaria / Makefile
Created September 10, 2023 15:17
Playing with symbols
all: exe
# This library depends libx2.so soname and calls h() from it
y/liby.so: x/libx2.so
@mkdir -p $(dir $@)
echo 'extern int foo(); int g() { return foo(); }' | $(CC) -o $@ -shared -x c - -Lx -l:libx2.so '-Wl,--no-as-needed,--enable-new-dtags,-rpath,$$ORIGIN/../x'
# This library has both file and soname libx.so
x/libx.so:
@mkdir -p $(dir $@)
@fzakaria
fzakaria / Makefile
Created September 10, 2023 02:36
Order of linked libraries can affect symbol resolution
example: example.c liba.so libb.so
gcc -o example -lb -la -laltf -lf -x c -L. example.c
libf.so: f.c
gcc -shared -o libf.so -x c f.c
libaltf.so: alternative-f.c
gcc -shared -o libaltf.so -x c alternative-f.c
liba.so: a.c libf.so
from plotnine import *
import pandas as pd
import numpy as np
# Initialize list of lists
raw = [['PHP', 9, 70], ['Java', 8, np.nan], ['JavaScript', 10, 683], ['.NET', 3, np.nan], ['Python', 6, 19], ['Ruby', 9, 68]]
data = {
'Language': [],
'Type': [],
'Value': []
@fzakaria
fzakaria / rpath.rb
Created March 7, 2022 17:09
Largest RPATH in /nix/store/*/bin
#!/usr/bin/env ruby
require 'find'
require 'elftools'
STORE = "/nix/store/*/bin/*"
puts "Searching /nix/store for rpath entries."
seen = 0
current = ""