Create directories corresponding to each alphabet using linux command-line

Today, I had to create twenty-six directories each corresponding to an English alphabet. I wrote a simple bash script that uses for loop with mkdir to do it as shown below.

for alphabet in {a..z}; do
   mkdir $alphabet

Working through sbt test deadlock

Today, I encountered an issue while running tests for one of my Scala SBT projects. Each time, ran sbt test command hang. After running jvisualvm, I discovered that it is due to thread deadlock. I couldn’t figure out why deadlock is happening. Test cases worked fine when ran individually. To work through this issue, I disabled parallel execution of tests.

From command-line, you can use following command to disable parallel execution of test:

$ sbt 'set parallelExecution in Test := false' test

You can also set this setting in your build.sbt to avoid setting this setting manually.In your build.sbt , add the following line.

parallelExecution := false

Python json object_hook

Today, I was building a REST client for one of the REST server applications using Python. I decided to use Python requests library for writing my REST API client. Requests is a very easy to use library that you can use to quickly bootstrap your REST API client. Writing REST client for REST endpoints was a matter of an hour. This REST API client will be used from our custom Jython(JVM implementation of Python) REPL. REST API has only two endpoints that return JSON objects. Response of first endpoint was fed to the second endpoint. I was returning the JSON response as Python dictionary. User can change values of the first response and pass it to the second API call. In Python, you work with dictionary as shown below. Continue reading “Python json object_hook”

Python Puzzle

Let me start with the confession that I am not an expert Python developer so this might not be a surprise for some of you. Yesterday, I was working on a Python REST API client using awesome requests library for one of my server application. To quickly hack my client, I created a Python virtual environment using virtualenv and installed required libraries using pip. I was ready to play with Python(again). I created a new file and added a method. For demonstration, let’s suppose our method is called hello, as shown below. Continue reading “Python Puzzle”

GSON tip: @JsonProperty equivalent

Jackson has a very useful annotation @JsonProperty that gives developer the option to provide a name that will be used to map data from JSON to the value object. This is very useful when REST API you are interacting with does not follow conventions like some fields are caps, some camel case, and other using underscore. Today, I had a similar need but I was working with GSON library instead of Jackson. The solution in Gson is a similar annotation called @SerializedName that you can use to provide names that match the source JSON. A simple example is shown below.

public class Message{
    private String id;
    private int fileDescriptors;

Gradle tip: Using gradle plugin from local maven repository

Today, I was trying to use a Gradle plugin that was currently not published to Bintray or any other public repository. I performed following actions to use that plugin in my project.

Step 1: Build the gradle plugin

Clone the gradle plugin to your local machine and run the following command to publish plugin to your local Maven repository.

$ ./gradlew clean build
$ ./gradlew publishToMavenLocal

Step 2: Add plugin to your project build.gradle

Once you have published your plugin to local Maven repository then you need to add the plugin to your project so that you can execute it. Add the following to your build.gradle.

apply plugin: 'my-demo-plugin'

  repositories {

        classpath 'io.shekhar.gradle.plugins:my-demo-plugin:0.1-SNAPSHOT'

In the build.gradle shown above we are applying our plugin my-demo-plugin using the apply plugin command. Then we used buildscript method to add our plugin to classpath. Also, we used local maven repo using mavenLocal() Gradle function.