About mrhaki

My name is Hubert A. Klein Ikkink also known as mrhaki. I work at the great IT company JDriven. Here I work on projects with Java, Groovy, Gradle, Asciidoctor and more. At JDriven we focus on enterprise technologies. All colleagues support craftsmanship and are very eager to learn new technologies. This is truly a great environment to work in.

Follow mrhaki on Mastodon Follow mrhaki on Bluesky

Posts by mrhaki

Awesome AssertJ: Use isEqualToNormalizingNewlines To Assert With Text Block

Posted on by  
Hubert Klein Ikkink

A Java text block is an easy way to have a multiline string value. But there is a catch if we want to use a text block with the assertion method isEqualTo. Suppose you have written a piece of code that create a new string value where the line endings are defined using System.lineSeparator(). The string value would have the line ending \n on Linux and MacOS systems, and the line ending \r\n on Windows system. But a Java text block will always use the line ending \n on every platform, including the Windows platform. If you would run your tests on a Windows platform then the assertion using isEqualTo will fail, but the test will pass on Linux or MacOS systems. This is a problem if you are working with developers using different operating systems. Therefore it is better to use the method isEqualToNormalizingNewlines for these type of assertions. AssertJ will make sure the line endings are the same and the tests will pass independent of the operating system the tests are run on.

Continue reading →

Nushell Niceties: Calculating The Average Of Numeric Values

Posted on by  
Hubert Klein Ikkink

In order to calculate an average for a list of numbers, file sizes, durations, or range of numbers, or a table with columns containing numeric values you can use the math avg command. This command is part of the math module of Nushell. When the input is a list then the result is a single value with the average of all values in the list. If you use a table as input the result is a record where the key is the column name and the value the average of all values in that column. Finally it is possible to have a single value as input and the result is the same value obviously.

Continue reading →

Nushell Niceties: Calculating The Sum Of Numeric Values

Posted on by  
Hubert Klein Ikkink

The math module in Nushell has a lot of useful commands to work with numeric values. You can use the math sum command to calculate the sum of a multiple numeric values. The input of the command can be a list of numbers, durations, file sizes, or a range or table with columns containing numeric values. The result is a single numeric value with the sum of all values in the input. The math sum command can also be used on a table with multiple numeric columns. It will return a record with the sum of all values for each column.

Continue reading →

Nushell Niceties: Checking String Starts Or Ends With Given String

Posted on by  
Hubert Klein Ikkink

To check if a string value starts or ends with a given string you can use the str starts-with and str ends-with commands. The command returns a boolean value: true if the string starts or ends with the given string and false otherwise. The commands are case sensitive by default. You can use the --ignore-case (or the shorthand -i) to ignore casing while checking if a the string starts or ends with a given string.
To input can be a string value and then that string value is checked. If the input is an array of string values, then each element is checked. It is also possible to check values in a record or table. You need to pass the names of the field(s) or column(s) that you want to check the string values of.

Continue reading →

Nushell Niceties: Tables With Different Themes

Posted on by  
Hubert Klein Ikkink

A lot of commands have output displayed as table. It is possible to use different themes for tables. If you run the command table --list you get all available themes. At the moment the following themes are available: basic, compact, compact_double, default, heavy, light, none, reinforced, rounded, thin, with_love, psql, markdown, dots, restructured, ascii_rounded, basic_compact, single, double. You can use a theme with the table command by using the --theme option and the name of the theme. For example to have a different table theme for the ls command you can use ls | table --theme light.
If you want to change the theme for all table output you can set the configuration option $env.config.table.mode. To make this configuration setting permanent you can add it to config.nu file.

Continue reading →

Nushell Niceties: Summon Ellie The Nushell Mascot

Posted on by  
Hubert Klein Ikkink

When you start Nushell you can see a nice ASCII art elephant. That is Ellie a cute and friendly elephant mascot for Nushell. Elephants are popular as you can see them in other products like Mastodon and Gradle. It is possible to summon Ellie in your Nushell environment by running the ellie command. This command is part of the std library and you need to run use std ellie or std use * first.

Continue reading →

Groovy Goodness: Accessing Regular Expression Named Groups By Name

Posted on by  
Hubert Klein Ikkink

Groovy (and Java) support using names for groups in regular expressions. The name of the group is defined using the syntax ?<name> where name must be replaced with the actual group name. This is very useful, because you can use the group name to access the value that is captured by the defined regular expression in a java.util.regex.Matcher object. Groovy supports for a long time accessing a group using the index operator. Since Groovy 5 you can use the name of the group to access the value as well. You can specify the name between square brackets ([<name>]) or use the name as property.

Continue reading →

Nushell Niceties: Create Query Parameters For URL

Posted on by  
Hubert Klein Ikkink

The build-in HTTP client in Nushell can be used to interact with REST APIs and websites. If the URL you want to invoke has query parameters than you can use the url build-query command. The url build-query command transforms a record or table to URL encoded key/value pairs joined with an ampersand (&). Each key and value is separated by an equal sign (=). The command can expand a key with a list value to separate key/value pairs with the same key if the key is defined in a record.

Continue reading →

Nushell Niceties: Joining Values Into String

Posted on by  
Hubert Klein Ikkink

The string module contains a lot of useful commands to work with strings. If you want to join several values from a list into a single string you can use the str join command. The command accepts as argument the character(s) to use for joining the values. If you don’t specify the character(s) as argument the default value '' (empty string) is used.

Continue reading →

shadow-left