Skip to content

Instantly share code, notes, and snippets.

Bootstrap a Rocky root — no root required (uses unshare + dnf)

The snippet below bootstraps a minimal Rocky Linux root filesystem at "$HOME/path/to/rocky/root" while making it explicit that you do not need real root privileges on the host. It relies on Linux user namespaces so the process is mapped to root inside the namespace but runs as your unprivileged user on the host.

TARGET="$HOME/path/to/rocky/root"

# Create new userns / mount ns / pid ns and run the command inside (no real root required)
unshare --user --map-root-user --mount --pid --fork \
 dnf -y --installroot="$TARGET" \

Creating the same Windows .exe CLI launchers that pip makes — using distlib

English

When you pip install a package that exposes console entry points on Windows, pip (via its bundled distlib) produces small native .exe launcher files in the Scripts (or Scripts\) directory. Those .exe files are merely launchers that invoke the target Python interpreter and run your package’s entry point. You can reproduce that same functionality directly from Python by calling distlib.scripts.ScriptMaker — in other words, the .exe-creation logic is available as a callable library.

Below is a compact guide and example code you can drop into a script to generate the same Windows EXE wrappers pip would create.


Lightweight Namespace Shell: unshare --user --map-root-user --mount --pid --fork bash

unshare --user --map-root-user --mount --pid --fork bash is a compact one-liner that starts a new interactive shell with several Linux namespaces isolated. It’s a handy way to get a “root” shell that’s isolated from the rest of the system — useful for experimenting, testing, and lightweight container-like isolation without full container tooling.

The command

unshare --user --map-root-user --mount --pid --fork bash

Quick guide: mac.yml — Open a macOS tmate debug session in GitHub Actions

This tiny GitHub Actions workflow lets you start an interactive remote debugging session on a macOS runner using tmate. It’s handy when a job fails only on macOS and you want to hop into the running environment to inspect files, processes, or reproduce the problem live.

What the workflow does

name: Mac Debug (tmate)
on: workflow_dispatch           # manual trigger
jobs:

How to Squash Past Commits with Git Rebase

Squashing commits with Git’s rebase command is useful when you want to clean up your commit history. Here’s a step-by-step guide.


1. Check Which Commits to Squash

First, review the commit log to decide which commits you want to combine:

Creating a Git Branch from HEAD^

When working with Git, sometimes you may want to create a new branch based on the commit before the current HEAD. In Git notation, HEAD^ refers to the parent of the current commit.

Command

To create a branch from HEAD^, run:

git checkout -b  HEAD^

Tracing Function Calls in C++ with GDB and Python

When debugging recursive functions in C++, it can be helpful to trace every entry and exit of a function. With GDB (GNU Debugger) and a custom Python script, we can automate this process.


Step 1: Compile with Debug Information

We first compile our program with debugging symbols enabled and without optimization:

Automating Function Instrumentation in C++ with Clang and Python

When dealing with large C++ projects, adding debugging or tracing code to every function manually can be time-consuming. By combining Python with Clang’s parsing library (libclang), this process can be automated.

Preprocessing and Parsing with Clang

The workflow begins with preprocessing the C++ source file using g++ -E. Preprocessing expands macros and resolves includes, producing a file that is easier to analyze with Clang.

Next, the Python script uses clang.cindex to create an AST (Abstract Syntax Tree). It walks through all nodes and collects functions such as:

Route Only a Specific IP Range from Windows via WSL2 (Alpine) with openfortivpn

If you want Windows to reach only a particular IP range through your corporate VPN—while everything else stays on your normal Internet—one clean approach is to use WSL2 (Alpine Linux) as a tiny VPN router. Windows sends just the target routes to the WSL VM; Alpine dials the VPN with openfortivpn and NATs the traffic. Here’s a concise walkthrough.


What you’ll build

  • A lightweight Alpine Linux distro inside WSL2.
  • openfortivpn to connect to a FortiGate VPN without auto-installed routes.

Copy branch branch-b state into branch-a as a new commit

Summary: A short, simple guide to take the file state from branch-b (for example the tree at commit commit-b) and make that state a new commit on branch branch-a — without creating a merge commit or linking histories.


When to use this

Use this when you want branch-a to contain the same file contents as branch-b (the working tree of commit-b) but you do not want to perform a git merge or record branch-b as a parent in history. This produces a normal commit on branch-a whose snapshot equals commit-b.