Compdigitec Labs

Local build in npm

By admin | May 24, 2021

npm install # Install dependencies
npm run build # Needs a like like "build": "tsc" in package.json. For TypeScript, just run tsc directly if missing
npm install -g # Installed compiled result to global packages

Topics: Code | No Comments »

Python classes, metaclasses, and instances at a glance

By admin | February 16, 2021

For more details:

Topics: Code | 1 Comment »


By admin | February 15, 2021

git format-patch $1..HEAD -o wip && git reset --hard $1

Topics: Code | 1 Comment »

Getting files from sources in Scala

By admin | February 14, 2021

// Java-based ways

// Scala-native way

Topics: Code | 3 Comments »

Epson DS-30 on Ubuntu Linux

By admin | February 13, 2021

Use the attached ds-30-bundle, download from

Install the deb packages with ./ –dry-run

Use simple-scan to run the scan. Insert paper face down above/next to
the little scan marker and press the button

Topics: Linux | No Comments »

Running a GUI application in Docker

By admin | January 30, 2021

apt-get update && apt-get install -y openssh-server vim xpra

# Allow container to connect to GUI?
xhost +
docker run --rm -v /tmp/.X11-unix:/tmp/.X11-unix -p 2222:2222 -e DISPLAY --security-opt seccomp:unconfined -it <image> bash

sudo mkdir -p /run/user/1000
sudo chown ubuntu:ubuntu /run/user/1000

xpra start ssh:ubuntu@localhost:2222 --exit-with-children --start-child="xfce4-terminal"

Topics: Linux | No Comments »

Creating a service to run a systemd-nspawn server

By admin | January 28, 2021

debootstrap –include=systemd-container –components=main,universe focal myContainer

Edit /usr/lib/systemd/system/systemd-nspawn@.service

ExecStart= -> remove -U

sudo systemctl daemon-reload
sudo systemctl restart systemd-nspawn@myContainer

Topics: Linux | 1 Comment »

Git refuses to discover new remote branches

By admin | January 23, 2021

In addition to the excellent suggestions at, take a look in .git/config and make sure fetch is specified to only fetch the master branch:

[remote "origin"]
  url =
  fetch = +refs/heads/master:refs/remotes/origin/master # bad

You’ll want to change the fetch line to fetch all branches instead:

[remote "origin"]
  url =
  fetch = +refs/heads/*:refs/remotes/origin/*

Topics: Linux | 2 Comments »

ImageMagick snippet: batch crop, dither, and guillotine

By admin | November 12, 2020

# Create output dirs
mkdir -p cropped dithered output
rm cropped/*.png dithered/*.png output/*.png

# Crop (3000x2000 at position 200, 200)
mogrify -crop 3000x2000+200+200 -path ./cropped *.png

# Dither (to indexed colours)
mogrify +dither -colors 4 -path ./dithered cropped/*.png

# Guillotine
mogrify -crop 2x1@ +repage -path ./output dithered/*.png

Topics: Linux, Uncategorized | No Comments »

Concatenating PDFs while padding/extending odd-length PDFs

By admin | October 10, 2020

When concatenating PDFs to consolidate print jobs, it is nice to have single-page or PDFs with odd numbers of pages to not have to share sides with another unrelated document.

There is a short script available at ; however, it does not appear to be updated for PyPDF2. So here is an update for Python3 and PyPDF2.


sudo apt install python3-pypdf2

#!/usr/bin/env python3
# Inspired from

import copy
import sys
from PyPDF2 import PdfFileWriter, PdfFileReader

def main():
    if len(sys.argv) < 2:
        print("No input PDFs specified", file=sys.stderr)
        return 1

    pdf_writer = PdfFileWriter()
    output_page_number = 0
    alignment = 2           # to align on even pages

    # So we can close the file objects later.
    file_objects = []

    for filename in sys.argv[1:]:
        # Store the file object for closing
        f = open(filename, 'rb')

        # Open the input PDF
        pdf_reader = PdfFileReader(f)

        # Add input pages
        for page in pdf_reader.pages:
            output_page_number += 1

        # Add filler pages
        while output_page_number % alignment != 0:
            output_page_number += 1

    # Write output PDF while input files are still open.

    # Close open files.
    while len(file_objects) > 0:

    return 0


Topics: Linux | No Comments »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! « Older Entries