Skip to content

Instantly share code, notes, and snippets.

View fzakaria's full-sized avatar

Farid Zakaria fzakaria

View GitHub Profile
@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 = ""
package hw5
import chisel3._
import chisel3.util._
case class CacheParams(capacity: Int, blockSize: Int, associativity: Int, addrLen: Int = 8, bitsPerWord: Int = 8) {
require((1 << addrLen) >= capacity)
require(capacity > blockSize)
require(isPow2(capacity) && isPow2(blockSize) && isPow2(associativity) && isPow2(bitsPerWord))
// inputs capacity & blockSize are in units of words
@fzakaria
fzakaria / Makefile
Created January 12, 2022 23:52
musl soname cache discrepancy
all: exe
# This library depends libx.so soname and calls f() from it
b/liby.so: c/libx.so
@mkdir -p $(dir $@)
echo 'int g() { h(); }' | $(CC) -o $@ -include dlfcn.h -shared -Wl,--no-as-needed -x c - -Lc -lx
# This library has both file and soname libx.so
c/libx.so:
@mkdir -p $(dir $@)
@fzakaria
fzakaria / compute-outputs.nix
Created January 6, 2022 03:25
Compute output path of all attributes in nixpkgs
let
pkgs = import <nixpkgs> {
config.allowBroken = true;
config.allowUnfree = true;
};
lib = import <nixpkgs/lib>;
tryEval = builtins.tryEval;
in
lib.mapAttrs (k: v:
let name = (tryEval v.name or "");
@fzakaria
fzakaria / glibc-debug.nix
Created January 2, 2022 01:40
Build a version of glibc with debug symbols in Nixpkgs
with import <nixpkgs> { };
enableDebugging (glibc.overrideAttrs (o: {
preConfigure = o.preConfigure + ''
export CFLAGS="-Wno-error=maybe-uninitialized $CFLAGS"
'';
}))