Category: Coding & Scripting

  • Flutter: how to create a better MaterialColor from Color

    Flutter: how to create a better MaterialColor from Color

    Written by

    in

    In Flutter, MaterialColor is a class that defines a color palette to be used within a Material Design app. It creates a set of shades for a given primary color, which can be used in various components of the UI, such as buttons, text fields, and navigation bars. MaterialColor objects can be created from a…

    Read more

  • Flutter: how to sort a list of objects by one of its properties

    Flutter: how to sort a list of objects by one of its properties

    Written by

    in

    In Flutter (Dart), there are different posibilities to sort a list of objects by one of its properties. Let’s asume you have a list of Person objects that have a property name on which you want to sort the array. Sort a list using the sort() method You can use the sort method of List…

    Read more

  • mysqldump: how to exclude or include tables

    mysqldump: how to exclude or include tables

    Written by

    in ,

    mysqldump is a command-line tool used for creating database backups in MySQL. By default, mysqldump includes all tables of the specified database when creating the dump. In some cases, it is useful to exclude some of the tables or even include only some of them. For me, this helped to exclude one of the biggest…

    Read more

  • JavaScript: simple code structure for libraries

    JavaScript: simple code structure for libraries

    Written by

    in

    The code of a JavaScript library might get very complex over time. This can be a problem for maintenance and expandability. When writing a library, you should address two main points: The following “template” provides a simple code structure that fulfills those points: You can use such a library the following way: Inspiration: https://stackoverflow.com/questions/13606188/writing-a-library-what-structure Photo…

    Read more

  • Flutter: red text and yellow lines in Text widget

    Flutter: red text and yellow lines in Text widget

    Written by

    in

    When using a text widget, there are some configurations where the text turns red and gets yellow lines. In my case, it looks like in the following image. The reason for this is a lack of style parameters from the parent widget. The red text shows that there is no color information available. The yellow…

    Read more

  • PHP: rounding a number and keeping the zeros after comma

    PHP: rounding a number and keeping the zeros after comma

    Written by

    in

    In PHP you can use the round() method to round a double. This methods accepts a precision value as second parameter. Some examples: When using round() on a value like 3.0000 the conversion to a string will result in just “3”: This is not wrong, but when you want to have a constant precision for…

    Read more

  • PHP: get version details from composer.json

    PHP: get version details from composer.json

    Written by

    in

    Composer is a tool for dependency management in PHP. It allows PHP developers to easily manage and install the libraries and packages their projects depend on. Composer simplifies the process of including external libraries into PHP projects and helps manage versioning and dependencies. The packages that are required for your project are located in a…

    Read more

  • GitLab CI + Flutter: pub: command not found

    GitLab CI + Flutter: pub: command not found

    Written by

    in ,

    In one of my projects, I used a GitLab environment to perform Flutter tests. For this, I setup my .gitlab-ci.yaml to use a Flutter docker image of cirrusci/flutter for code quality check or tests. The file looks like this: Up to version 2.10.* of the Flutter docker image, this worked fine. But starting with version…

    Read more

  • MySQL error: Cannot truncate a table referenced in a foreign key constraint

    MySQL error: Cannot truncate a table referenced in a foreign key constraint

    Written by

    in

    By default, you cannot TRUNCATE (empty) a table that has foreign key constraints applied on it. This is to keep the data consistent over multiple tables that are linked by constraints. Nevertheless, it might be necessary to truncate all data from a table. Here are a few options you can consider to resolve this issue: Solution 1…

    Read more

  • Markdown: how do I add a newline in a table?

    Markdown: how do I add a newline in a table?

    Written by

    in

    When creating tables in markdown, you use the vertical line | to split the columns. Each line of the document represents a row of the table. So adding a normal line break will result in a new row by default. Let’s assume you have a table with a large text and you want to split…

    Read more

  • Build and Release a Flutter App

    Build and Release a Flutter App

    Written by

    in ,

    Updating the app’s version number To update the version number, navigate to the pubspec.yaml file and update the following line with the current version string: After the change, run: Build and release the iOS app A detailled description of the whole process is described at docs.flutter.dev. To release the iOS app, you use Flutter to build a…

    Read more

  • Free and Easy Horizontal Stacked Bar Graphs with Google Colab / Jupyter (as well as Python and Pandas)

    Free and Easy Horizontal Stacked Bar Graphs with Google Colab / Jupyter (as well as Python and Pandas)

    Written by

    in ,

    Recently, my wife needed to create some stacked bar graphs for her publications. She wasn’t able to find a tool on the internet which allowed her to do this in an easy and shareable way. So I used this opportunity to look into Jupyter Notebooks. These notebooks allow you to document and run code and…

    Read more

  • Dart: code snippets for faster coding

    Dart: code snippets for faster coding

    Written by

    in

    There are different concepts that improve the data handling in Dart. The following list of snippets is a collection of the most handy once. Warning: this might simplify your code a lot! 😉 The Spread Operator Dart supports the spread operator, which allows to insert a collection (multiple elements) into a collection: Operators Dart supports different…

    Read more

  • brew: install Java on macOS

    brew: install Java on macOS

    Written by

    in ,

    The following steps will guide you through the installation of Java on macOS. First, check the available Java related formulas: Currently, there are two different version of Java: java and java11. To check the version of both, you can use the following commands: Depending on your requirements, you can install one of the above. For…

    Read more

  • Flutter: enable scroll-to-top for nested Scaffolds (e.g. in IndexedStack)

    Flutter: enable scroll-to-top for nested Scaffolds (e.g. in IndexedStack)

    Written by

    in

    When using nested Scaffolds (e.g. in combination with IndexedStack), the PrimaryScrollController is not usable by default. An IndexedStack will load all subviews so scroll-to-top will change all scrollable views at the same time, even if they are not visible or it simply does not work, because the PrimaryScrollController can only be attached to a single…

    Read more

  • Flutter: add drag handle to ReorderableListView

    Flutter: add drag handle to ReorderableListView

    Written by

    in

    By default, ReorderableListView only shows drag handles on desktop (GitHub). To enable a drag handle inside a ReorderableListView, it is possible to add the following code into the child’s subtree: A full example usage with a very simple list: This will result in the following output:

    Read more

  • Flutter: expand TextField height to match parent widget

    Flutter: expand TextField height to match parent widget

    Written by

    in

    To expand the height of TextField to match the parents widgets height, the following code can be used: The important thing is, that both minLines and maxLines need to be set to null. To set the height of the Container to match it’s parent or even the complete screen, height can be set to double.infinity.

    Read more

  • Enable debugging output in PHPUnit

    Written by

    in

    When running PHPunit there are only dots and letters for each test by default: To enable debug output and get some more details about the tests running, simply add the logging section to phpunit.xml.dist: This will create a debug output and helps to track the tests: In my case, this helped when my code reached…

    Read more

  • Xcode: how to disable an extension during app build

    Xcode: how to disable an extension during app build

    Written by

    in ,

    Sometimes the development version of an app includes multiple code e.g. an extension that should not be released yet. In this case, it’s possible to exclude the extension when building an app. This keeps all your code, but does not include the extension during the build phase. To achieve this, simply open the Build Phases…

    Read more

  • Create certificate for localhost domains on macOS

    Create certificate for localhost domains on macOS

    Written by

    in ,

    Step 1: create a self-signed root certificate First, let’s create a self-signed root certificate: The parameter -days 390 sets the number of days, this certificate is valid. Starting on September 1st (2020), SSL/TLS certificates cannot be issued for longer than 13 months (397 days), see https://stackoverflow.com/a/65239775. If this time is too long, you will receive…

    Read more