Fakecracker: NetBSD as a Function Based MicroVM

In November 2018 AWS published an Open Source tool called Firecracker, mostly a virtual machine monitor relying on KVM, a small sized Linux kernel, and a stripped down version of Qemu. What baffled me was the speed at which the virtual machine would fire up and run the service. The whole process is to be compared to a container, but safer, as it does not share the kernel nor any resource, it is a separate and dedicated virtual machine.
If you want to learn more on Firecracker’s internals, here’s a very well put article.

Rofi Window Switcher With XFCE (updated, now with icons)

This bug forbids rofi window mode to give focus to a selected window when click to focus is disabled in XFCE. Using the same trick the first commenter used, I came up with this script which uses wmctrl to handle windows listing, selection and focus:

#!/bin/sh

clicktofocus="xfconf-query -c xfwm4 -p /general/click_to_focus -s "

$clicktofocus true
w=$(wmctrl -l|awk '{$1=$2=$3=""; sub(/^[ \t]+/, ""); print $0}' | \
	rofi -dmenu -i -p "Window Switcher")
wmctrl -a "$w"
$clicktofocus false

Not the prettiest method but it emulates rofi -show window pretty well.

Testing GPG Keys With Docker... and fail

As a password-store user, GPG is particularly important and sensitive, I use it for pretty much everything authentication / encryption related. Also, about a year ago I got myself a pair of Yubikeys, and they are now involved in all of the mentioned workflows.

Now on the topic, as my keys are a crucial part of my online life, I wanted to make sure I had those backuped safely, and moreover, that this backup is usable in an empty environment by simply importing the public and private keys. Among the various possibilities, I thought firing up a basic docker container with an interactive shell would be my fastest bet. How wrong I was.

Understanding Bitcoin LevelDB Format (and messing up with bytes)

I’ve contributed to a small project I found useful in my digging of Bitcoin’s LevelDB databases structure; leveldbctl is a CLI tool that permits to parse a LevelDB database rather simply. But it was missing a critical function for my use case, hexadecimal fields handling, which are heavily used by Bitcoin. Until now it was only capable of reading / writing strings.

It is now possible to use it to retrieve values from Bitcoin’s (and probably a lot more cryptocurrencies) block index keys, i.e.:

Gitlab Pages Simply Put

Yet another topic IMHO explained in the most possible complicated way in Gitlab documentation, Gitlab pages are in fact extremely powerful and simple to use.

In order to create a website with an URL of the form https://<username>.gitlab.io/<project>, there are a couple of steps to follow. First, write a Job to publish your pages, this job can be part of your project’s .gitlab-ci.yml but for some reason, official documentation gives the idea you are supposed to create a specific repository for that.

Generate All Boolean Array Combinations

While writing Go tests for goxplorer, I wanted to test all boolean flags combinations without having to cascade for loops.
This first method came to mind:

package main

import (
	"fmt"
)

func stob(bf []bool, s string) {
	for i, b := range s {
		if b == '0' {
			bf[i] = false
		} else {
			bf[i] = true
		}
	}
}

func main() {
	bf := []bool{false, false, false, false, false}

	for i := 0; i < 32; i++ {
		b := fmt.Sprintf("%b", i)
		stob(bf, b)
		fmt.Println(bf)
	}
}

Because the fastest way of generating every possible combination of 5 bits is to count from 0 to 31, i.e. 2^5, i.e. 32. The second trick here is to use fmt.Sprintf("%b") to generate a string representing the binary value.
It works, but I found the idea of using strings too heavy for a “binary” task.
A friend came to me with a barbaric bits field solution I found way too smart / complicated :), so I thought about another option but also using bits field, and thought about the following: how to tell if a field is a 1? One of the many options is the or binary operator; indeed, if a field is 0 and is “or’ed” with a 1, its value will become 1, if the initial value is 1, it will not change. Remember or truth table?

Publish Binary Releases on Gitlab

I switched to Gitlab when Github was bought by Microsoft. Call me extremist, stupid, and all the names you like, I personally felt the need to do it.
And quite honestly, I’m pretty happy with that choice, Gitlab is an incredibly useful suite, we use the community version at work and would never go back. But there’s one thing that’s pretty annoying with Gitlab, their documentation organization. Honestly it’s like they don’t want you to figure out how to do things. It’s often split into tens of various links and you end up reading issues discussions without really knowing if the feature you’d like is implemented or just an idea at that point.

Yubikey, Suspend and Restore

Another one of those quickies that can save you some time. When my Linux laptop resumed from sleep, I was annoyed that DrDuh’s perfect Yubikey setup would throw me the following when I tried to SSH:

sign_and_send_pubkey: signing failed: agent refused operation

Seems like the key doesn’t like being put to sleep and woken up. Another annoyance, for some reason, also when waking up, laptop’s touchpad was disabled. So I put this little script in /lib/systemd/system-sleep:

Alpine, tmux and UTF-8

A quicky in case anybody has the same issue. I use pine / alpine as a mail client since my firsts steps on the UNIX/Linux world, it always served me well.
Nevertheless, since a couple of weeks, I had this weird behavior where the mail content pager would not display accents (éàü…) while the mail list would! Worse, this inconsistent behavior only happened in tmux.
I suspected something involving locales but no, everything was fine on this side.
So it turns out alpine’s mail content pager doesn’t know how to cope with a value of screen-256color in the TERM variable. Changing it to xterm-256color fixed accents display.

Push Motion Image Capture to Telegram

I use the fantastic motion project to monitor my apartment activity when I’m not home (not happening until God knows when these days…). I wanted it to warn me when there’s movement more interactively than with a basic email. Telegram and its very well documented bot API is really perfect for this task, so I came up with the following motion configuration:

on_picture_save /bin/sh /home/imil/bin/on_picture_save.sh %f

and more importantly, the following script:

#!/bin/sh

. ${HOME}/.tg

ffile=${HOME}/tmp/motion_capture

f=${1%?????????}

mplayer ${HOME}/Music/42899__freqman__canon-dos-d30-no-focus.wav

[ -e ${ffile} ] && [ "$(cat $ffile)" = "$f" ] && exit 0

curl -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendPhoto" \
 -F chat_id=${CHATID} -F photo="@$1"

echo $f > $ffile

the ~/.tg file has the following content: