JDriven Blog

Groovy Goodness: For Loops With Index Variable

Posted on by  
Hubert Klein Ikkink

Groovy 5 adds support for using an index variable in a for-in loop. You must define an extra variable as first argument of the for loop. This variable will be used as index variable. For each iteration of the code in the for-in loop the value of this index variable is incremented by 1. You can use this value in the for loop.

Continue reading →

Groovy Goodness: Create Ascii Bar Charts

Posted on by  
Hubert Klein Ikkink

Groovy 5 adds a new utility method to create an ascii bar chart. You can use the bar method in the org.codehaus.groovy.util.StringUtil class. You can pass a value, a minimum and maximum value and optinally specify the width of the bar chart. The result is a String value consisting of a number of "blocks". A block could be whole, but also 1/8 eights of the block are used to get a nice looking bar chart. How many of these values are needed is based on the input arguments. With this method you have a nice way to format number values on a command-line.

Continue reading →

Kafka, Protobuf and Spring Boot gRPC

Posted on by  
Hugo Greyvenstein

Protobuf provides an easier and more performant approach to serialising and deserialising data. These performance capabilities and the ability to provide a common schema for data transfer objects, coupled with a performant message brokering service such as Kafka seems to be a match made in heaven.

Continue reading →

Groovy Goodness: Transform Iterable Into A Map

Posted on by  
Hubert Klein Ikkink

Groovy 5 introduced some extra overloaded methods for the collectEntries method, that can be used to transform an iterable object into a Map. You can now pass a closure or function as arguments to transform the original iterable element into the key and value for the resulting Map. It is now also possible to pass a so-called collector Map that will be used to extend with new key/value pairs.

Besides extra overloaded method signatures for collectEntries Groovy 5 also adds the new methods withCollectedKeys and withCollectedValues. With the method withCollectedKeys a closure or function can passed to create the keys for the new Map based on the elements from the iterable. The value of the key/value pair is the unchanged element. You use the method withCollectedValues to pass a closure or function to create the value for the new key/value pair in the resulting Map. The key will be the original element from the iterable.

Continue reading →

Nushell Niceties: Filtering Null And Empty Values

Posted on by  
Hubert Klein Ikkink

Nushell has very useful commands to filter lists and tables. When you have a list with null values, you can use the compact command to filter out the null values. With the option --empty you can also filter out empty items like empty strings, empty lists and empty records. If you want to filter out rows in a table where a column contains a null value, you can use the compact command followed by the name of the column.

Continue reading →

Nushell Niceties: Rolling Dice

Posted on by  
Hubert Klein Ikkink

Nushell has some nice built-in commands to get randomized data. The random command can be used to get random numbers, strings, and more. You can use the dice subcommand to get random numbers between 1 and 6. The command returns a list of integers. With the option --dice you can specify how many times to throw the dice. By default the dice has 6 sides, but you can use the option --sides to change that. You could roll a dice with 2 sides, like flipping a coin, or roll a dice with 10 sides.

Continue reading →

True programmers work in the command-line ;-)

Posted on by  
Ronald Koster

Some people think GUIs have replaced the command-line. But they have not, they are complementary. Some things can still be done better and easier in the command-line, for example scripting, and to servers one usually has access via an SSH terminal only. But there is more! This blog will describe a few very convenient commands for software developers. All of it works in the Bash shell (common on Linux), but most of it works in the Z shell (zsh) as well (common on Mac).

Continue reading →

shadow-left