Skip to content

Instantly share code, notes, and snippets.

Turn a Linux Machine into a Wi-Fi Access Point (AP) with NetworkManager

If you’re running a modern Linux distro like Debian 12 “Bookworm,” NetworkManager is the default way to manage networking. Below is a simple, copy-paste friendly guide to turn your device (e.g., a Raspberry Pi or small PC with a supported Wi-Fi adapter) into a wireless access point. We’ll cover WPA2, WPA3, and a mixed “transition” mode.

In the commands below, we assume you already created an AP connection profile named rpi-ap. Replace it with your own profile name if different.


Prerequisites

Reading from stdin with asyncio (and writing to stderr)

This short Python script shows how to use asyncio to read a single line from standard input (stdin) asynchronously and report what was read to standard error (stderr). It’s a compact example of wiring low-level OS pipes into asyncio’s high-level stream APIs.

What the code does

  1. Creates an asynchronous reader from a file-like object make_reader(fp) takes a binary file object (like sys.stdin.buffer) and:
  • Gets the current event loop.

Automate Your Git User Setup with a Post-Checkout Hook

When you work across multiple repositories—or switch between personal and work projects—it’s easy to forget which Git identity (name and email) a repo should use. This simple Git hook helps by prompting you to pick a past author identity whenever you check out a branch, then automatically sets user.name and user.email for that repository.

What This Hook Does

  • Runs after every git checkout.
  • If the repository already has a local user.name and user.email, it does nothing.
  • Otherwise, it scans the repo’s history for author names/emails, shows them in an interactive picker (fzf), and lets you choose.
  • It then writes the chosen identity to the repo’s local config.

How to Create a Custom Git Command Like git hoge

Git allows developers to extend its functionality by creating their own custom commands. This is a simple and powerful way to automate tasks or integrate new workflows directly into Git. For example, if you create a command named git-hoge, you can call it simply by typing git hoge in the terminal.

How It Works

When you run a command like git hoge, Git automatically looks for an executable file named git-hoge in your system’s PATH. If it finds it, Git runs that file as if it were a built-in Git command.

Steps to Create Your Own Command

Making sudo Safer for Shutdown: Defaults!/usr/sbin/shutdown timestamp_timeout=0

If you manage a Linux system, you may sometimes allow users to run specific administrative commands with sudo. One common example is letting trusted users execute the shutdown command: /usr/sbin/shutdown. But there’s a subtle security detail to consider—how long sudo remembers (or “caches”) a user’s password after they authenticate.

What the line means

Defaults!/usr/sbin/shutdown timestamp_timeout=0

Using Wayland on Linux in Hyper-V: How to Disable hyperv_fb on Ubuntu and Rocky Linux

When running a Linux virtual machine on Microsoft Hyper-V, you may want to use the Wayland display server for better performance and smoother graphics compared to X11. However, Wayland cannot function correctly if the Hyper-V framebuffer driver (hyperv_fb) is loaded, because it interferes with the kernel’s native framebuffer setup. To enable Wayland, you need to disable (blacklist) the hyperv_fb module. Below are two methods to do this for Ubuntu and Rocky Linux.


1. Disabling hyperv_fb via GRUB Kernel Arguments

This method edits the GRUB configuration to prevent hyperv_fb from loading at boot time.

A Simple Tool for Splitting and Rejoining Data with External Commands

This Python script provides a small command-line utility that can split a stream of bytes (from standard input) into many chunk files, and concatenate those chunk files back to a single stream (written to standard output). It’s designed to be flexible by letting you define how files are created, saved, and read using your own shell commands.

What the Program Does

  • split: reads data from stdin in fixed-size pieces and writes each piece to a new file. It can group files into numbered directories.
  • concat: reads those files back in order and writes their contents to stdout.

Both operations delegate the actual filesystem work (mkdir, write, read) to external commands you specify. This makes the tool adaptable to many environments (local disk, special devices, custom commands, etc.).

Access a Windows block device from WSL2 using NBD

If you have a directly attached SD-card reader (or other removable media that is not USB) and wsl --mount or usbip won’t work, exporting the raw Windows device over the network with nbd (via nbdkit) is a handy workaround. nbdkit can run on Windows and serve \\.\PHYSICALDRIVEx to your WSL2 instance, where you can attach it as /dev/nbd0. The nbdkit project and docs explain the server/plugin model nicely. ([libguestfs.org][1])

Below is a short, practical recipe.

References / useful links (keep these): https://rwmj.wordpress.com/2024/01/24/nbdkit-binaries-for-windows/ ([Richard WM Jones][2]) https://koji.fedoraproject.org/koji/userinfo?userID=458 https://koji.fedoraproject.org/koji/buildinfo?buildID=2835676

Waydroid audio fix (WSLg)

Waydroid expects a Pulse socket at /run/user/<UID>/pulse/native. WSLg provides /mnt/wslg/PulseServer. Create a symlink so Android clients talk to the Windows audio server:

ln -sf /mnt/wslg/PulseServer /run/user/$(id -u)/pulse/native

Getting sound working (ALSA → Pulse/ PipeWire) — quick notes and what each step does

If you want legacy ALSA clients and modern Pulse/PipeWire clients to play through the same audio server — for example inside WSL2 or a minimal Linux environment — these commands form a compact recipe. Below I’ll walk through what each line does and why it’s useful.


1) Install the tools

apt install -y alsa-utils pulseaudio-utils pipewire-bin libasound2-plugins