Skip to content

Instantly share code, notes, and snippets.

@elazarl
elazarl / minimal-bootable-kernel-mac-arm64.md
Created June 7, 2026 20:17
Minimal bootable Linux kernel on Apple Silicon Mac (arm64) via Podman + QEMU/HVF

Minimal Bootable Linux Kernel on a Mac (Apple Silicon, arm64)

Build a tiny custom Linux kernel inside a Podman container and boot it against an Ubuntu cloud image with QEMU — entirely on an Apple Silicon Mac, no sudo required.

The whole point is a fast edit‑compile‑run cycle: boot to a userspace shell in well under a second thanks to hardware acceleration (HVF).

This is the arm64 variant. Because the Mac is itself arm64, the kernel is built natively (no cross‑compiler) and QEMU runs the guest with the hvf accelerator at

@elazarl
elazarl / jc-lsusb.py
Last active August 12, 2024 07:19
just the lsub portion of jc from https://github.com/kellyjonbrazil/jc
# from utils.py
"""jc - JSON Convert utils"""
import sys
import re
import locale
import shutil
from itertools import islice
from collections import namedtuple
@elazarl
elazarl / fastapi-posgresql.py
Last active June 15, 2024 20:00
An example how to combine async fastapi server with async psycopg
#!/usr/bin/env python3
# to run use:
# $ fastapi dev fastapi-posgresql.py
from contextlib import asynccontextmanager
from typing import Annotated, AsyncGenerator
import psycopg
from psycopg_pool import AsyncConnectionPool
@elazarl
elazarl / sprint_int.c
Last active May 9, 2023 08:20
Small standalone stupid function to convert integer value to string, for code with zero library support
#include <stdint.h>
#include <stdio.h>
char *sprint_int_(char *out, uint64_t a, uint64_t base) {
char itoc[] = "0123456789abcdef";
char *orig_out = out;
uint64_t a_ = a;
int i = 0;
while (a_ >= base) {
a_ /= base;
i++;
@elazarl
elazarl / stack_size.c
Last active April 12, 2020 13:27
This is a demonstration showing how to print stack size of a certain function
// We demonstrate how to get the stack usage of a function
// using the __builtin_frame_address function of GCC and clang.
//
// This function returns:
// The frame is the area on the stack that holds local variables and saved registers.
// The frame address is normally the address of the first word pushed on to
// the stack by the function.
//
// by saving its value and comparing it to a callee, we get the stack usage of this
// function.
@elazarl
elazarl / simple_transform_before_zstd.c
Created January 30, 2020 15:35
Check if a simple transform before applying zstd reduce file size
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
char buf[1024*1024];
@elazarl
elazarl / bench_comp_decomp.py
Last active January 29, 2020 14:57
Measures compression and decompression speed and size ratio on many files
#!/usr/bin/python3
import argparse
from collections import namedtuple
import csv
import os
import shutil
import subprocess
import statistics
import re
@elazarl
elazarl / test_vec_to_c.py
Last active January 26, 2020 21:59
NIST test vector to C format
# This converts test vectors from
# https://csrc.nist.gov/Projects/cryptographic-algorithm-validation-program/CAVP-TESTING-BLOCK-CIPHER-MODES
# to a C-struct format.
# For example to initialize
# struct test_case {
# int count;
# int data_unit_len;
# std::string key;
# std::string index;
# std::string plaintext;
@elazarl
elazarl / uuid4sym.py
Last active May 16, 2019 05:12
replace UUID with distinguishable emojis
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""uuid4sym - replace UUID version 4 to an easily distinguishable symbol
When looking at a long log file with some UUID4 uuids, you'll have a hard time
distinguishing between two UUIDs.
Both 26cb1b84-7748-11e9-9437-2bf0efaa1b2e and 2725e8de-7748-11e9-a9c8-f3e5d10ab3d6
looks similar to the human eye.
@elazarl
elazarl / dir2img.py
Created April 30, 2019 14:11
Create an image with filesystem, copies a local directory content to it
#!/usr/bin/python3
"""Create image from a directory
This script creates image whose contents are a given directoy on the filesystem.
Example usage:
$ mkdir mydir
$ echo A > mydir/a
$ ./dir2img.py -d mydir -i myimage.img