The namespace clojure.pprint
has some useful function to pretty print different data structures. The function print-table
is particularly useful for printing a collection of maps, where each map represents a row in the table, and the keys of the maps represent the column headers. The print-table
function accepts the collection as argument and prints the table to the console (or any writer that is bound to the *out*
var). We can also pass a vector with the keys we want to include in the table. Only the keys we specify are in the output. The order of the keys in the vector we pass as argument is also preserved in the generated output.
Continue reading →
As promised last time, in the third and final installment we would look at some actual code.
As it will turn out, our straightforward implementation will need a little rework in order to properly fire up the GPU.
Continue reading →
When we mock a method that returns a Stream
we need to make sure we return a fresh Stream
on each invocation to support multiple calls to the mocked method. If we don’t do that, the stream will be closed after the first call and subsequent calls will throw exceptions. We can chain multiple thenReturn
calls to return a fresh Stream
each time the mocked method is invoked. Or we can use multiple arguments with the thenReturn
method, where each argument is returned based on the number of times the mocked method is invoked. So on the first invocation the first argument is returned, on second invocation the second argument and so on. This works when we know the exact number of invocations in advance. But if we want to be more flexible and want to support any number of invocations, then we can use thenAnswer
method. This method needs an Answer
implementation that returns a value on each invocation. The Answer
interface is a functional interface with only one method that needs to be implemented. We can rely on a function call to implement the Answer
interface where the function gets a InvocationOnMock
object as parameter and returns a value. As the function is called each time the mocked method is invoked, we can return a Stream
that will be new each time.
Continue reading →
Sometimes the answer to your problems is right in front of you.
But somehow you just can’t grasp it until you’ve had a bit of an enlightenment experience.
This happened to me a couple of weeks ago.
Continue reading →
A Gradle build file describes what is needed to build our Java project. We apply one or more plugins, configure the plugins, declare dependencies and create and configure tasks. We have a lot of freedom to organize the build file as Gradle doesn’t really care. So to create maintainable Gradle build files we need to organize our build files and follow some conventions. In this post we focus on organizing the tasks and see if we can find a good way to do this.
It is good to have a single place where all the tasks are created and configured, instead of having all the logic scattered all over the build file. The TaskContainer
is a good place to put all the tasks. To access the TaskContainer
we can use the tasks
property on the Project
object. Within the scope of the tasks
block we can create and configure tasks. Now we have a single place where all the tasks are created and configured. This makes it easier to find the tasks in our project as we have a single place to look for the tasks.
Continue reading →
The IntelliJ HTTP Client is very useful for testing APIs. We can use Javascript to look at the response and write tests with assertions about the response. If an API returns a JSON Web Token (JWT), we can use a Javascript function to decode the token and extract information from it. For example we can then assert that fields of the token have the correct value. There is no built-in support in IntelliJ HTTP Client to decode a JWT, but we can write our own Javascript function to do it. We then use the function in our Javascript response handler to decode the token.
Continue reading →
Last week we had a quick glance of what GPU programming is and what kind of issues it can tackle.
Today, we will dive a bit under the hood and take a look at the logical architecture of modern chips, and show a basic strategy when to migrate part of our code over to the CUDA platform.
Continue reading →
It is good practice in Gradle to use lazy configuration. This makes builds faster as only configuration values are evaluated when needed. We should try to not let Gradle spend time on evaluating configuration values that will not be used. For example tasks that are not executed could still be configured by Gradle. If we make sure the configuration of these tasks is lazy we can save time.
Gradle gives us a lazy way to get the value of a Java system property. In our build script we can use the providers
property of type ProviderFactory
and the method systemProperty(String)
. This method returns a Provider<String>
instance that can be used to get the value of a system property in a lazy way. The method systemProperty
can also be used with a Provider<String>
argument.
Continue reading →
It is good practice in Gradle to use lazy configuration. This makes builds faster as only configuration values are evaluated when needed. We should try to not let Gradle spend time on evaluating configuration values that will not be used. For example tasks that are not executed could still be configured by Gradle. If we make sure the configuration of these tasks is lazy we can save time.
Gradle gives us a lazy way to get the value of an environment variable. In our build script we can use the providers
property of type ProviderFactory
and the method environmentVariable(String)
. This method returns a Provider<String>
instance that can be used to get the value of an environment variable in a lazy way.
Continue reading →
You never touched Groovy, nor did you jump on the Scala train.
Clojure never attracted you; and you heard about Ceylon long after the language had already died.
You are one of those old-fashioned Java folks!
But now, after all those years, you want to join the cool Kotlin kids.
So, where to start?
Let’s discover the language together by decompiling it to Java code.
Today: The things we tend to forget!
Continue reading →
When we use the IntelliJ HTTP Client we can write JavaScript for the pre-request and response handlers. If we want to access an environment variable in JavaScript we can use request.environment.get(string)
. The argument for the get
function is the name of the environment variable we want to get the value for. Environment variables can be defined in the file http-client.env.json
or in http-client.private.env.json
.
Continue reading →
The built-in IntelliJ HTTP Client is very useful for testing HTTP requests and responses. If we want to define a variable in our .http
file that is only used in this file and will not change per environment we can define it using the following syntax: @<variable name> = variable value
. The variable is an in-place variable and the scope of the variable in the current .http
file. The variable is immutable and can only be defined with a value once and cannot be overwritten. To refer to the variable we use the syntax {{}}
.
Continue reading →