Archive: 2020

Gradle Goodness: Replace Files In Archives

Posted on by  
Hubert Klein Ikkink

Sometimes we might need to replace one or more files in an existing archive file. The archive file could be a zip, jar, war or other archive. Without Gradle we would unpack the archive file, copy our new file into the destination directory of the unpacked archive and archive the directory again. To achieve this with Gradle we can simply create a single task of type Zip. To get the content of the original archive we can use the project.zipTree method. We leave out the file we want to replace and define the new file as replacement. As extra safeguard we can let the tsak fail if duplicate files are in the archive, because of our replacement.

The following code shows an example of a task to replace a README file in an archive sample.zip using Groovy and Kotlin DSL. First the Groovy DSL:

Continue reading →

Github CLI

Posted on by  
Christophe Hesters

At my current customer we use Github a lot. Everything requires a review via a Pull Request. It is sometimes tedious to switch from your IDE or terminal to the browser while creating a PR. Github has a command line utility called gh which you can use to automatically create a PR from the command line. It has lots of extra stuff as well, such as downloading releases, viewing issues, creating gists, cloning repo’s and code completion.

Start by following the installation steps in https://github.com/cli/cli to install the gh binary. There are packages for all operating systems.

Continue reading →

How to stay connected during disconnected times

Posted on by  
Erik Pronk

Great to be the one kicking off our yearly blog festival Blogtober! This first blog is not particularly technical, but this subject has been the most prominent thing on my mind during the last 6 months. Connection with colleagues and sharing knowledge is part of our DNA at JDriven, better yet, it is part of our vision as a company. Throughout the years we gathered lots of experience in how we share our knowledge with the community. But this was always in a world without social distancing and other connection limitations.

Continue reading →

Replication of a single Avro serialized Kafka topic from one cluster to another

Posted on by  
Tim te Beek

As more and more teams and companies adopt Apache Kafka, you can find yourself wanting to share data via replication of one or more topics from one cluster to another. While replication of an entire cluster with all of it’s topics as a means of failover can be achieved with tools such as Mirror Maker and Confluent Replicator, for replication of a single topic there are fewer examples. Even more so when the source topic is serialized with Avro, with the schema stored in Confluent Schema Registry.

Here we present a minimal consumer that replicates a single Avro serialized Kafka topic from one cluster to another, while ensuring (only) the necessary Avro schema is registered in the target cluster Schema Registry.

Continue reading →

Clojure Goodness: Taking Or Dropping Elements From A Collection Based On Predicate

Posted on by  
Hubert Klein Ikkink

In Clojure we can take or drop elements from a collection based on a predicate using the functions take-while and drop-while. With the function take-while we take elements as long as the predicate returns true. Once the predicate returns false the function stops returning elements. Using the function drop-while we skip elements in the collection if the predicate returns true. If the predicate returns false the remaining elements in the collection are returned.

In the following example we use take-while and drop-while with different collection types:

Continue reading →

Clojure Goodness: Turn Java Object To Map With bean Function

Posted on by  
Hubert Klein Ikkink

The map data structure is used a lot in Clojure. When we want to use Java objects in our Clojure code we can convert the Java object to a map with the bean function. This function will use reflection to get all the properties of the Java object and converts each property with the property value to a key with value in the resulting map. The bean function will not recursively convert nested objects to a map, only the top-level properties are turned into key value pairs.

We see several examples of using the bean function in the following code snippet:

Continue reading →

Clojure Goodness: Create And Initialize Object Based On Java Class With doto

Posted on by  
Hubert Klein Ikkink

It is very easy to work with Java classes in Clojure. If we want to create a new object based on a Java class and invoke methods to initialize the object directly we can use the doto macro. The first argument is an expression to create a new object and the rest of the arguments are functions to invoke methods on the newly created object. The object returned from the first argument is passed as first argument to the method invocations. The doto function returns the object that is created with the first argument.

In the following example code we use the doto function in several cases:

Continue reading →

Clojure Goodness: Replacing Characters In A String With escape Function

Posted on by  
Hubert Klein Ikkink

The clojure.string namespace contains a lot of useful functions to work with string values. The escape function can be used to replace characters in a string with another character. The function accepts as first argument the string value and the second argument is a map. The map has characters as key that need to be replaced followed by the value it is replaced with. For example the map {\a 1 \b 2} replaces the character a with 1 and the character b with 2.

In the following example code we use the escape function in several cases:

Continue reading →

Clojure Goodness: Concatenation Of Map Function Results With mapcat

Posted on by  
Hubert Klein Ikkink

When we use a function as argument for the map function that returns a collection we would get nested collections. If we want to turn the result into a single collection we can concatenate the elements from the collections by applying the concat function, but we can do this directly with the function mapcat. The function mapcat takes as first argument a function (that returns a collection) and one or more collections as next arguments.

In the following examples we see several uses of mapcat:

Continue reading →

Starting a new job in times of the new normal

Posted on by  
Melissa Koppeschaar

Excitement

"It’s official! In April I will be starting an amazing new job!", I thought excitedly as I laid down my pen. I had just signed my contract with JCore during a nice lunch with a soon-to-be colleague. It was December 23st and signing the contract felt like an early Christmas present. Not only would JCore offer me plenty of opportunity to develop my technical and personal skills, they also offered a fun social environment. During the interviews I was told about pub quizzes, board game nights, Friday afternoon drinks, people playing videogames together…​ It seemed so much fun! I joined two of these events even before I officially started working for JCore. I had a great time and I was really looking forward for this to become my new normal. Little did I know that my actual new normal would be vastly different due to the corona crisis.

Continue reading →

Expanding the Java Bean Validations

Posted on by  
Jacob van Lingen

Since beginning of time mankind has been looking for a way to separate right from wrong. Where the primeval man judged righteousness by the contributions of the tribe, the current day programmer judges right by the wishes of the customer. For many years the average programmer wrote a bunch of logic to check if the boundaries defined by the client where uphold. As time went on and programming languages involved, metadata could be added to enrich functions, methods, classes and the like.

Of course for Java, these metadata are called annotations. Very soon they were used for a lot of things. Surpressing warnings, managing transactions, building XML/JSON structures and injecting dependencies. And, as you might have guessed by now, validating objects by a set of specific rules. One of the most commonly used frameworks would be the Jakarta Bean Validation framework. But what if I told you the provided annotations of that framework could be very easily expanded.

Continue reading →

shadow-left