Visual Studio Code – Auto Time Stamp

While organizing most of my information in Markdown files meanwhile, I like to have some metadata in each file to see e.g. when files have been created and/or updated.

The Auto Time Stamp extension is a small extension that doe exactly this for you. By adding Created: and/or Last modified: the extension will update these fields automatically when the file is saved.

// Created: 2018/02/04 12:24:41
// Last modified: 2018/02/09 11:41:41

This extension is going into my must-have toolbox for VS Code.

Link: (GitHub): https://github.com/lpubsppop01/vscode-auto-timestamp
Link (VS Marketplace): https://marketplace.visualstudio.com/items?itemName=lpubsppop01.vscode-auto-timestamp

Raspberry Pi – Setting a static IPv4 address

It run me mad, as I tried to change the IP address of my Raspberry to a static one. I changed literally everything in  /etc/network/interfaces and reloaded, restarted and reboot the device over and over.

iface eth0 inet static
address 192.168.0.207
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.

As the above configuration did not help a lot, I figured out that based on the Raspberry model, you need to change settings on various places.

First run

cat /proc/cpuinfo

to determine you model. While getting something like

pi@raspberrypi:~ $ cat /proc/cpuinfo
processor    : 0
model name    : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS    : 2.00
Features    : half thumb fastmult vfp edsp java tls
CPU implementer    : 0x41
CPU architecture: 7
CPU variant    : 0x0
CPU part    : 0xb76
CPU revision    : 7

Hardware    : BCM2708
Revision    : 0004
Serial        : 000000004715b608

you need to use the hardware revision and

Model and Pi Revision 256MB Hardware Revision Code from cpuinfo
Model B Revision 1.0 256MB 0002
Model B Revision 1.0 + ECN0001 (no fuses, D14 removed) 256MB 0003
Model B Revision 2.0
Mounting holes
256MB 0004
0005
0006
Model A
Mounting holes
256MB 0007
0008
0009
Model B Revision 2.0
Mounting holes
512MB 000d
000e
000f
Model B+ 512MB 0010
Compute Module 512MB 0011
Model A+ 256MB 0012
Pi 2 Model B 1GB a01041 (Sony, UK)
a21041 (Embest, China)
PiZero 512MB 900092

Based on this information you need

Model a

Static IP addresses in /etc/network/interfaces is not the “prefered” way,as it is an old way and DHCPCD5 is installed.

Model b

Static IP addresses are configured in the /etc/dhcpcd.conf and it is  required that /etc/network/interfaces is set to manually.

iface eth0 inet manual

That’s all…

Creating Tests – As long as they are automated

I have been often asked about testing, how something could be tested automatically, how something could be tested at all. Especially if there is/was no testing framework. My answer has been always the same:

It doesn’t matter. As long the tests are autmated.

Testing frameworks have been created over time. They have not been there from the beginning. Eventually, there is no test framework for your problem yet. However, this does not mean you can’t test.

An error was reported in my EIP-PlantUML side project. After some analysis, I figured out it was caused by a syntax issue within a string in a definition file. The problem here, you see the particular error only once the result has been rendered as an image. How to test this?

I simply wrote a Bash script checking the definitions instead. That’s all. It passes with the exit code 0 or 1 if the test fails. That way I will be able to integrate it in a test suite later one ,even if I don’t know how this will look right now.

The test script itself is rather simple using grep in a shell script.

#!/bin/bash
Red=$'\e[1;31m'
Green=$'\e[1;32m'
Clear=$'\e[0m'

count=$(grep 'r_label' -c ../EIP_Elements.puml)

if [ "$count" -eq "0" ] ; then
    echo "$Green PASSED:$Clear No issues detected."
    exit 0
else
    echo "$Red FAILED:$Clear Issues detected."
    grep 'r_label' -n ../EIP_Elements.puml
    exit 1
fi

Fixing Podlove Cron Jobs in WordPress Docker Containers

While we were publishing the first episode of our Podcast, I came across some issues with WordPress, though.

First of all: We are using the Podlove Publisher and therefore WordPress to host our Podcast.

Unfortunately, I encountered an issue with the required cron jobs. The Podlove WP Cron Diagnostics showed, that there was nothing set up.

PHP Constant
ALTERNATE_WP_CRON: not definde
DISABLE_WP_CRON: not defined

As a result, any attempt to connect to running cron jobs failed. After checking Google I found a helpful hint here. All you have to do is to add

define('ALTERNATE_WP_CRON', true);

in your wp-config.php.

And here the fun begins. I am using the official WordPress Docker container and Ansible to deploy it on my servers. So you need a way to add this line to a wp-config.php file on your server using an Ansible script… I think you get it. Some years ago, you would have simply logged into your server, changed the line in the file and eventually restart your webserver.

Now everything becomes more difficult. First of all I try such things manually. To do so (as well as to verify the changes on the server) I bash into the running WordPress container

docker exec -i -t {containerId} /bin/bash

just to realize there is neither vim or even vi on this container available. Also less did not work. At least I was able to read the file using more.

Again I looked for some hints and found a great hint on Stackoverflow:

You can make use of the WORDPRESS_CONFIG_EXTRA environment variable to define any other config values in the wp-config.php file.

With this environmental variable, you can literally add anything to your wp-config.php file in the prebuild WordPress image without fiddling with own containers and so on.

environment:      
  WORDPRESS_DB_HOST: db:1234
 WORDPRESS_DB_USER: wp
 WORDPRESS_DB_PASSWORD: topsecret
 WORDPRESS_CONFIG_EXTRA: |
   define('ALTERNATE_WP_CRON', true);
    define( 'DISABLE_WP_CRON', true );

Looking into your wp-config.php now should reveal the following line:

// WORDPRESS_CONFIG_EXTRA
 define('ALTERNATE_WP_CRON', true);
 define( 'DISABLE_WP_CRON', true );

Also running the diagnostics in the Podlove plugin now should come up with some better news:

Started the Podcast

A few weeks ago, I announced to start my personal educational project Hack-the-Planet.

I started the GitHub Project, the Twitch Stream and we already gathered a small community at Reddit and Discord.

Eventually, I wanted to start a podcast. However alone, it’s only half the fun. Said that I had a surprising phone call by an old friend who was willing to start the podcast with me. That’s not only a lot of fun but also a great honor to perform the Podcast with him.

Yesterday, we finally recorded episode 0 of the podcast and already published it. The Podcast is already available at Spotify and will be available soon at iTunes as well once the Apple site works again. More on this topic in episode 1. If you are using any other application I can also subscribe directly from our feed or head to the podcast site at https://podcast.hack-the-planet.tv.

We hope to publish an episode once a week. So stay tuned and feel free to subscribe to the podcast.

Visual Studio Code: Open in Browser

While I started using Visual Studio Code frequently for several Web development project, I got very annoyed by copying file paths and pasting them into my browser to view the file there.

The open-in-browser extension for Visual Studio Code is a small simple solution to exactly this problem. It lets you open a file directly in your default browser.

Open an html file, Windows and Linux keyboard shortcut is Ctrl+Alt+O, for MacOS is Cmd+Alt+O. If you want to preview html in your default browser directly, please type Ctrl+K D.

Visual Studio Code open-in-browser Extension
Visual Studio Code open-in-browser Extension

Links:
Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=coderfee.open-html-in-browser
GitHub: https://github.com/coderfe/vscode-open-in-browser