Category: Coding & Scripting

This category contains all posts about coding and scripting. It combines topics like programming and scripting languages, best practices for coding styles and documentation, and others.

  • Dart: Zufallszahl in einem Bereich erstellen

    Dart: Zufallszahl in einem Bereich erstellen

    Written by

    in

    Analog zum Artikel über Java Zufallszahlen bietet auch Dart Möglichkeiten, um eine Zufallszahl zu erstellen. Hierzu kann beispielsweise die Klasse Random aus dem Paket dart:math verwendet werden. In der Dokumentation heißt es: Generiert eine nicht-negative Zufallszahl gleichmäßig verteilt im Bereich von 0 (einschließlich) bis max (ausschließlich). https://api.dart.dev/stable/3.3.3/dart-math/Random/nextInt.html In nachfolgendem Beispiel wird eine Zufallszahl zwischen einem Minimum und…

    Read more

  • WordPress: how to remove the ‘link rel=shortlink’ tag from your site

    WordPress: how to remove the ‘link rel=shortlink’ tag from your site

    Written by

    in ,

    By default, WordPress adds <link rel=”shortlink”> meta tag to the <head> of a website and uses the short url like https://mixable.blog/?p=12345 for this. When you already use nice slugs as permalink structure, such a tag is not necessary, because you already have unique urls. To remove the shortlink tag, you can use an additional plugin…

    Read more

  • How to delete a single element from an array in PHP

    How to delete a single element from an array in PHP

    Written by

    in

    There are multiple ways to remove an element from an array in PHP. The simplest one is the method unset(). unset() The method unset() can be used to remove a single element of the array: The output of print_r() is: array_splice() This function can be used to remove a portion of an array and replace…

    Read more

  • PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given

    PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given

    Written by

    in ,

    After moving a WordPress installation to another server, the following error showed up: The new server had a different linux distribution and a newer PHP version. In my case, the environment changed from PHP 7.4 to PHP 8.2. I already added some missing PHP extensions and updated the configuration to match the old one, but…

    Read more

  • JavaScript: how to check if a string variable is an integer value

    JavaScript: how to check if a string variable is an integer value

    Written by

    in

    In JavaScript, one way to check if a variable is of type integer, Number.isInteger() can be used: But this solution has the disadvantage, that a string with integer value like ’22’ will result in false. Use parseInt You can use the parseInt function to parse a string and convert it into an integer. If the…

    Read more

  • How to decode the exception backtrace of an ESP32

    How to decode the exception backtrace of an ESP32

    Written by

    in

    When the execution of code on an ESP32 throws an exception, the output might look like this: The Espressif tools contain a binary called xtensa-esp32-elf-addr2line which will decode the backtrace addresses and return details about the source files, lines and function names, etc. To run the tool, call: In the command above, simply…

    Read more

  • FutureBuilder: handle multiple futures in a single widget

    FutureBuilder: handle multiple futures in a single widget

    Written by

    in

    By default, FutureBuilder provides a single future parameter that handles a single Future. For multiple Futures, we can combine them into a single Future using Future.wait. Here’s a step-by-step guide on how to do this: Create a list of Future objects Create a list of Future objects that represent the asynchronous operations you want to…

    Read more

  • mysqldump: how to use a specific port

    mysqldump: how to use a specific port

    Written by

    in

    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…

    Read more

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

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

    Written by

    in

    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,…

    Read more

  • ESP32: Stack canary watchpoint triggered (loopTask)

    ESP32: Stack canary watchpoint triggered (loopTask)

    Written by

    in ,

    Recently, I stumble upon the following error on an ESP32: 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): Foto von Vishnu Mohanan auf Unsplash

    Read more

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

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

    Written by

    in

    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…

    Read more

  • PHP: when to use ‘self’ and when to use ‘$this’?

    PHP: when to use ‘self’ and when to use ‘$this’?

    Written by

    in

    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…

    Read more

  • PHP: How to check if a string contains a specific word?

    PHP: How to check if a string contains a specific word?

    Written by

    in

    When working with strings in PHP, you can already use many handy functions to manipulate the string contents. Sometimes you only want to check for the string contents before doing an action. You can check if a string contains a specific word in PHP by using the strpos(), preg_match() or str_contains(). Using strpos() The strpos()…

    Read more

  • Dart: What is the difference between the “const” and “final” keywords?

    Dart: What is the difference between the “const” and “final” keywords?

    Written by

    in

    In Dart, both const and final are used to declare variables that can’t be reassigned after they’re initialized. However, there are some differences between them: In general, use const when you have a value that will never change and you want to ensure that only one instance of it exists, and use final when you…

    Read more

  • Flutter: How to Create a Color from a Hexadecimal Color String

    Flutter: How to Create a Color from a Hexadecimal Color String

    Written by

    in

    In Flutter, you can create a color from a hexadecimal color string value using the Color class. The Color class takes a 32-bit integer value as an argument, where the first 8 bits represent the alpha channel (transparency) and the remaining 24 bits represent the red, green, and blue channels. To create a color object…

    Read more

  • Pecl: fixing “fatal error: ‘pcre2.h’ file not found”

    Pecl: fixing “fatal error: ‘pcre2.h’ file not found”

    Written by

    in

    When using pecl to install a PHP extension, I always got a “fatal error: ‘pcre2.h’ file not found” after PHP has been updated. The update was done using brew upgrade php. In my case, this happens when I try to install pcov using: The output was: To fix the issue, make sure you have pcre2…

    Read more

  • jQuery methods in plain JavaScript

    jQuery methods in plain JavaScript

    Written by

    in ,

    Life is already very complex, so let’s simplify your projects by removing all the jQuery code. Plain JavaScript provides the same functionalities and it does not require any additional frameworks. And it’s supported by most of the modern browsers out of the box. This is a list of replacements for your daily used jQuery methods.…

    Read more

  • PHP: Function utf8_decode() and utf8_encode() have been deprecated

    PHP: Function utf8_decode() and utf8_encode() have been deprecated

    Written by

    in

    The utf8_encode() and utf8_decode() functions in PHP are used for encoding and decoding strings between ISO-8859-1 (Latin-1) encoding and UTF-8 encoding. While PHP’s standard library does include utf8_encode and utf8_decode functions, they are limited to converting between ISO-8859-1 (Latin-1) and UTF-8 encodings. It is important to note that these functions cannot be relied upon to…

    Read more

  • Flutter: How to remove the debug banner during development

    Flutter: How to remove the debug banner during development

    Written by

    in ,

    By default, Flutter shows a debug banner on the top right corner of an app, that indicates that the app was build in debug mode. This banner… … is intended to deter people from complaining that your app is slow when it’s in debug mode. In debug mode, Flutter enables a large number of expensive…

    Read more

  • HTML: how to vertically center an object with CSS?

    HTML: how to vertically center an object with CSS?

    Written by

    in

    There are several ways to vertically center an object with CSS: Flexbox This method uses the CSS flexbox layout to center the child element vertically within the parent container. The align-items property set to center aligns the child element along the cross axis. Grid Layout This method uses the CSS grid layout to center the…

    Read more