Posts

  • Share Bluetooth adapter and devices between VMs

    I virtualize Windows on Linux via QEMU-KVM and VFIO. A Bluetooth adapter populates one of the USB ports of the Host. When I start a Windows VM, I have libvirt take over control of the USB device and pass it through to the client.

    All fine, device detected. The only issue that I run into, is that I need to re-pair my Bluetooth devices after switching (and after switching back again).

    To solve this issue: copy the Bluetooth link key from the paired OS to the other OS. Assuming the device is paired in Windows, and you want to share it with a Linux OS:

  • Copy container images from one host to another

    Copy an image from one host to another, without using a Docker registry:

    # stream `image-name` from `host-a` gzipped over the network, use `pv` to show progress
    ssh user@host-a docker save image-name \| gzip | zcat | pv | docker load 
    
    # Note how the first pipe is escaped, because it's supposed to be executed on the remote host
    # Use podman, docker, or whatever container engine you like to use
    
    # Alternatively, stream `image-name` from `host-a`, use ssh compression and don't show progress
    ssh +C user@host-a docker save image-name | docker load 
    
  • Setting up LVM on a RAID array with mdadm

    License: CC BY 4.0

    Recently, one of my favourite YouTube channels decided to cease their presence on YouTube and remove their channel. I stumbled across some old pictures which I overly compressed to fit to 600 megabytes - CD-ROM sized - faces barely recognizable. When visiting some bookmark from 2010, I found out that it was not served through that link anymore. The time for me is now, to become a datahoarder. 🕸️

    Disclaimer: I’m not an expert in this field and merely want to record and share my experience, that’s why I chose to license this text with the formidable CC BY 4.0.

    What does that practically entail for me? Setting up some long-term reliable storage on my Linux desktop in the form of a RAID-1 array. As I found existing tutorials a bit confusing and I wanted to retain the steps that I undertook for future reference, I decided to make them publicly available here.

  • Re-binding XHCI driver to make USB responsive again after resume

    After updating my Ubuntu 20.04 LTS installation’s Linux Kernel to 5.8 from 5.4, I started experiencing irregular problems with unresponsive USB devices after resuming from sleep. Once in every few wakeups, the USB mouse and Bluetooth transciever would ‘freeze’ and the devices vanish from the lsusb list. After some playing around, I found that unbinding and rebinding the XHCI driver resolved the issue for me.

    When all works fine, the output of the lsusb command would look something like this:

  • Test codeblocks in markdown documents

    I enjoy a quick-start when I try out some new software. The sooner I see something blinking, the better. Straight-forward documentation and clear examples improve the experience of trying out new things. The simplest and most fun examples typically find their way into the readme of my project as that’s the place where new users are most likely to stumble upon first. In one project, I realised that I wanted to test the code that I wrote in the readme.md too. This post is about how I did just that.

    Markdown is strong in its simplicity. Text-markup finds it way into the document via semantic textual decorations.

    Hello world, it's a glorious day
    ====
    Less is more.
    
    Lorem Ipsum
    ---
    Dolor C++:
    
    ```cpp
    std::min(1.0, 3);
    ```
    
  • CORS on Apache: Cross-Origin Resource Sharing

    The Cross-Origin Resource Sharing or CORS policies of a webhost indicate whether a browser should allow a script to access their resources.

    Traditionally, the browser do not allow scripts loaded from an origin to interact with resources from another origin. This behaviour is the same-origin policy. CORS allows hosts to relax those constraints by instructing which external origins are allowed to interact with it. The host communicates this intent via a specific set of headers.

    Note that the same-origin policy is client-enforced and as such does not restrict access to the resource with any other method than XHR.

    As webservers can typically modify response headers, they allow you to set up a CORS policy. In this example, Apache acts as a proxy for Jenkins, an automation server. Jenkins provides API access to its information but does not allow the administrator to modify the CORS settings easily. The goal is to allow external origins to access the Jenkins API information that Apache proxies.

  • Trigger build for all jobs in Jenkins organization

    Learn how to trigger all builds in a Jenkins organization or folder through the Groovy script console.

    Jenkins is the automation server of choice for thousands of organizations. Though it is a bit quirky at times, it offer the features, flexibility and community that projects require. Central to Jenkins is the scripting language Groovy which allows for automating configuration and management.

  • distcc as a Docker system service

    Distcc allows you to distribute the compilation of C, C++ and Obj-C. It wraps your typical compiler executable and offloads the compilation to remote and local compiler instances with the help of the distcc service. This reduces the compile-time of projects with many compilation units.

    For distcc to work properly, it should run the same compiler version on all compilation servers. This is typically not a big issue when running the same Linux distribution on both client and servers. But what if your use Arch while the server runs CentOS, or you run Ubuntu Bionic while the server runs Eoan? Or what if you have upgraded your local compiler while the server is still on the previous version of a compiler?

    Yes, containers.

  • Get PhpDoc @params of a method

    A well-written PhpDoc is a goldmine of information. It may feel redundant, however, to document values that you use in your code too. Why not parse the PhpDoc itself and use that value? Reflection is the way to go.

    Consider an Api class that requests users by ID from the Api’s user endpoint. We like to document the name of this endpoint in the PhpDoc for documentation purposes.

    class Api {
        /**
         * @param int $id
         * @return User
         * @endpoint users
         */
        public function user(int $id) : User {
            $this->request('users', $id);
        }
    }
    
  • Chunk an Iterator into Arrays in PHP

    PHP's iterators can take the heat out of memory consumption when processing big datasets. Typical for such datasets is that workers process them in manageable chunks of a limited size. As these workers typically are independent of each other, it might be necessary to pack chunks of the source in arrays that can be sent with the job metadata to the worker. This is when you might want to chunk an iterator into arrays.

    A Generator function is useful to achieve this purpose. As opposed to a normal function, a generator function yields return values as the caller asks for them. Take this dice roller:

    function dice() {
        return rand() % 6 + 1;
    }
    

subscribe via RSS