Author: Mathias Lipowski

Install and update GitLab Runner

I already wrote a summary on how to Setup GitLab Runner for Docker containers on Synology NAS. As this article has a lot of details for the Synology setup, I decided to write a short summary for this topic on a regular Linux server. So let’s go…

Before we start, we need to have Docker Engine installed on our system. Check out the Docker docs on how to install the Docker Engine on your system.

Install GitLab Runner

To install GitLab Runner, simply pull the container by using:

docker pull gitlab/gitlab-runner:latest

Now you can start the container as described in the section Start GitLab Runner below.

Update GitLab Runner

To update GitLab Runner, you also have to pull the container by using:

docker pull gitlab/gitlab-runner:latest

Then you have to stop and remove the current container image:

docker stop gitlab_runner
docker rm gitlab_runner

Now you can start the new container as described below.

Start GitLab Runner

docker run --detach \
  --name gitlab_runner \
  --restart always \
  --network host \
  -v /run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest

And finally you have to register the Runner in your GitLab instance. In the following commands, you need to set your own values for <host.example.com> and <registration_token>:

docker exec -it gitlab_runner gitlab-runner register \
  --url https://<host.example.com>/ \
  --registration-token <registration_token>

The registration will ask for some input. In my case, I used a docker executor with the alpine:latest image:

untime platform                                    arch=amd64 os=linux pid=16 revision=e95f89a0 version=13.4.1
Running in system-mode.                            
                                                   
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://<host.example.com>/
Please enter the gitlab-ci token for this runner:
<registration_token>
Please enter the gitlab-ci description for this runner:
[synology]: docker_alpine
Please enter the gitlab-ci tags for this runner (comma separated):

Registering runner... succeeded                     runner=sA4DKorC
Please enter the executor: docker-ssh, parallels, docker+machine, kubernetes, docker, shell, ssh, virtualbox, docker-ssh+machine, custom:
docker
Please enter the default Docker image (e.g. ruby:2.6):
alpine:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

 

mysqldump: how to use a specific port

To use a specific port with the mysqldump command, you can provide the --port (or -P) option followed by the port number you want to use. The --port option specifies the TCP/IP port number to use when connecting to the MySQL server.

When using -P remember to use an uppercase P, because the lowercase option -p refers to the password.

Here’s the general syntax of using mysqldump with a specific port:

mysqldump --port=PORT_NUMBER -u USERNAME -p DATABASE_NAME > dump.sql

Replace the following placeholders:

  • PORT_NUMBER: The specific port number you want to use (e.g., 3306).
  • USERNAME: Your MySQL username.
  • DATABASE_NAME: The name of the database you want to dump.
  • dump.sql: The name of the file where you want to save the database dump.

After executing this command, you’ll be prompted to enter your MySQL password. Once you provide the correct password, the mysqldump command will connect to the MySQL server using the specified port and create a dump of the specified database.

Foto von André Carvalho auf Unsplash

 

macOS: how to print a test page


To print a test page on a Mac, follow these steps:

  1. Open “System Preferences”.
  2. Click on “Printers & Scanners” (or “Print & Scan” depending on your macOS version).
  3. Select the printer you want to print a test page from.
  4. Click the “Open Print Queue”.
  5. A new window will open, showing the print queue for the selected printer.
  6. Look for the “Printer” menu at the top of the window and select “Print Test Page” or “Print Test Sheet.”
  7. Your printer will now print a test page.

Please note that the specific steps may vary slightly depending on your macOS version.

Foto von Andras Vas auf Unsplash

JavaScript: the differences between escape(), encodeURI(), and encodeURIComponent()

Foto von Markus Spiske auf Unsplash

In JavaScript, escape(), encodeURI(), and encodeURIComponent() are three functions used to encode strings for different purposes. Each function serves a distinct purpose, and it’s essential to understand their differences:

escape()

The escape() function is used to encode a string so that it can be safely included in a URL query string. It encodes special characters, except for alphanumeric characters and the following set of symbols: @*_+-./. The main drawback of escape() is that it does not encode all characters, and it’s considered deprecated in favor of encodeURIComponent().

Example:

const originalString = "Hello, World!";
const encodedString = escape(originalString);
console.log(encodedString); // "Hello%2C%20World%21"

encodeURI()

The encodeURI() function is used to encode a complete URI (Uniform Resource Identifier) but leaves the special characters used in the query string (?, &, =, etc.) untouched. It is primarily used to encode the main part of a URL, such as the protocol, domain, and path.

Example:

const originalURI = "https://www.example.com/my page.html?name=John Doe";
const encodedURI = encodeURI(originalURI);
console.log(encodedURI); // "https://www.example.com/my%20page.html?name=John%20Doe"

encodeURIComponent()

The encodeURIComponent() function is used to encode a component of a URI, such as a query parameter, fragment identifier, or any part that needs to be included in the query string. Unlike encodeURI(), this function encodes all special characters to ensure they are safely passed as parameters in a URL.

Example:

const originalParameter = "John Doe";
const encodedParameter = encodeURIComponent(originalParameter);
console.log(encodedParameter); // "John%20Doe"

In summary

Use escape() for encoding a string to be safely included in a query string, but it’s deprecated and not recommended for general use.

Use encodeURI() for encoding a complete URI (protocol, domain, path) but not the query string parameters.

Use encodeURIComponent() for encoding individual components (e.g., query parameters) of a URI to ensure all special characters are encoded properly. This is the most commonly used encoding function for URLs.

Foto von Markus Spiske auf Unsplash

ESP32: Stack canary watchpoint triggered (loopTask)

Recently, I stumble upon the following error on an ESP32:

Guru Meditation Error: Core  1 panic'ed (Unhandled debug exception)
Debug exception reason: Stack canary watchpoint triggered (loopTask) 
Core 1 register dump:
PC      : 0x40083774  PS      : 0x00060b36  A0      : 0x3ffb0120  A1      : 0x3ffb0060  
A2      : 0x68efa751  A3      : 0x3ffb0938  A4      : 0x3ffb0720  A5      : 0xfb879c5c  
A6      : 0x61b36b71  A7      : 0x0006970f  A8      : 0x01709af4  A9      : 0x01709af4  
A10     : 0xfaa5dfed  A11     : 0x01a3ff3b  A12     : 0x76651dec  A13     : 0x00000001  
A14     : 0x00000000  A15     : 0x04adbe74  SAR     : 0x0000001e  EXCCAUSE: 0x00000001  
EXCVADDR: 0x00000000  LBEG    : 0x400f1cc5  LEND    : 0x400f1cc9  LCOUNT  : 0x00000000  

ELF file SHA256: 0000000000000000

The reason for this was an infinite loop that was caused by two methods that where called from each other. So the execution of the first method never ended. The code looked something like this (extremly simplified):

void loop() {
  methodOne();
}

void methodOne() {
  // ... some other code and conditions
  methodTwo();
}
void methodTwo() {
  // ... some other code and conditions
  methodOne();
}

Foto von Vishnu Mohanan auf Unsplash

ESP32: how to read and write the partition table of an ESP device?

To communicate with an ESP32 the ESP-IDF (Espressif IoT Development Framework) can be used. This framework provides a collection of useful scripts to communicate with your ESP device. The framework is supported on Windows, Linux and macOS.

You can download the ESP-IDF repository and extract the contents into a folder.

Note that you need to have python 3 installed. For example by using brew install python on macOS. In addition, the esptool library is required by running pip install esptool in your terminal.

Reading the Partition Table

The partition table is located at 0x8000 (32768) on older, and on 0x9000 (36384) on newer systems. Its length is always 0xc00 (3072) bytes.

With the esptool.py, this can be read out, for example by the command

python $(IDF_PATH)/components/esptool_py/esptool/esptool.py read_flash 0x9000 0xc00 ptable.img

To create a “human” readable csv file, you can use the gen_esp32part.py tool:

python $(IDF_PATH)/components/partition_table/gen_esp32part.py ptable.img > ptable.csv

In my case, the partition table looks as follows:

Foto von Vishnu Mohanan auf Unsplash

Docker: how to build and push a Git repository to Docker Hub

To build and push a Git repository to Docker Hub, you can follow these steps:

Step 1 – Create a Dockerfile in the root directory of your Git repository. This file contains instructions for building your Docker image.

Step 2 – Build your Docker image using the docker build command. You will need to provide a name and tag for your image. For example:

codedocker build -t yourusername/yourimage:tag

This command will build an image with the tag yourusername/yourimage:tag.

Step 3 – Log in to Docker Hub using the docker login command. You will need to provide your Docker Hub username and password.

docker login

Step 4 – Push your Docker image to Docker Hub using the docker push command. For example:

docker push yourusername/yourimage:tag

This command will push your image to Docker Hub with the tag yourusername/yourimage:tag.

Once you have completed these steps, your Docker image will be available on Docker Hub for others to use and download.

PHP: when should I use ‘self’ and when should I use ‘$this’?

In PHP, the keyword $this is used to refer to the current instance of the class, while the keyword self is used to refer to the class itself.

You should use $this when referring to instance-level properties or methods within the same class, such as when accessing a property of the current object or calling a method of the current object.

For example:

class MyClass {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function sayHello() {
        echo "Hello, my name is " . $this->name;
    }
}

$obj = new MyClass("John");
$obj->sayHello(); // output: "Hello, my name is John"

On the other hand, you should use self when referring to static properties or methods within the same class, such as when accessing a static property or calling a static method of the class.

For example:

class MyClass {
    private static $count = 0;

    public function __construct() {
        self::$count++;
    }

    public static function getCount() {
        return self::$count;
    }
}

$obj1 = new MyClass();
$obj2 = new MyClass();
echo MyClass::getCount(); // output: 2

In summary, $this is used for instance-level properties and methods, while self is used for static properties and methods.