Advent of Code 2018

This year I was introduced to the Advent of Code by Julien and Hielke, who organized a local advent.

It is a great initiative, it is nice to be focused on coding and it adds to a festive atmosphere. Together with four other team members the challenge was accepted. We all took a different approach, as it also stimulates learning a bit about new stuff (e.g. using Kotlin vs Java).

Due to time constraints I have solved only the first half of the advent puzzles, and also by using ‘plain old Java’. But my personal challenge is to look back at the code and apply a better (more modern) alternative in the time to come.

My code can be found at https://github.com/martinkoel/adventofcode-2018 , be warned – it is ‘Hackathon style’ code – as you get more points the faster you finish..

Extending Android XML-RPC to support regular Java serialization

For my current Android project I wanted to have some communication with a server component. After spending some time on finding a decent solution I arrived at XML-RPC.

A client would use this code to ask the server the sum of two numbers:

int sum = (Integer) client.call(“Calculator.add”, 2, 4);

The server side would have a class “Calculator” with a method “add”, like so:

public int add(int i1, int i2) { 
    return i1 + i2; 
}

Nice and clean!

For the client (Android) I use Android XML-RPC and for the server side I use use Apache WS XML-RPC. It is not possible to use Apache WS XML-RPC on Android out of the box, as there are some issues relating to the core Java classes that are supported on Android. I am sure you could get it running with some effort, but then you still will add hundreds of kilobytes to your app because of the jar files that need to be included. Android XML RPC is around 50 kilobytes, which is much nicer from an end-user perspective.

By default there is a limited set of “data types” that can be used and I want to use my own “data types” (like “User”, “Project”, etc.). Apache XML RPC has a special mode “enabledForExtensions”, if you check that option it will give you access to the use of longs, shorts, bytes, floats, DOM nodes, instances of java.io.Serializable, or JAXB objects. This is only handy in a use case that has Apache XML RPC on both client and server. So not in my case!

Luckily, it is easy to extend Android XML RPC to allow other data types. You just have to add some code to the XMLRPCSerializer class. As I only wanted support for deserializing objects I added an extra if clause to the deserialize method:

} else if (typeNodeName.equals(“ex:serializable”)) { 
    obj = null; 
    String value = parser.nextText(); 
    BufferedReader reader = new BufferedReader(new StringReader(value)); 
    String line; 
    StringBuffer sb = new StringBuffer(); 
    while ((line = reader.readLine()) != null) { 
        sb.append(line); 
    }

    ByteArrayInputStream bais = new ByteArrayInputStream(Base64Coder.decode(sb.toString())); 
    ObjectInputStream ois = new ObjectInputStream(bais); 
    obj = ois.readObject(); 
    parser.nextTag(); 
    // parser.require(XmlPullParser.END_TAG, null, ..

    return obj;

} else {

Adding servlet support to the Maven webapp archetype

Today I wanted to create a servlet and used the m2eclipse plugin for Eclipse to create a web application based on the available Maven webapp archetype.

When using the archetype you will miss some essential jars and cannot create a Java 5 servlet. So I did the following:

1. adjust the pom: add dependency

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>servlet-api</artifactId> 
    <version>2.5</version> 
    <scope>provided</scope> 
</dependency>

2. adjust the web.xml: adjust the header

<?xml version=”1.0″ encoding=”UTF-8″?> 
<web-app xmlns=”http://java.sun.com/xml/ns/javaee” 
         xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”        xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” 
         version=”2.5″>

3. open the properties of the project and under Java Compiler change the compliance level to 1.5

Font, fonts, fonts

Currently I try to do some front end designing and am messing around with fonts. These two sites are very helpful: http://thinkclay.com/technology/cufon-sifr-flir

The first describes the techniques currently available for embedding fonts (so you get a 1:1 image of any font you want on any browser)

The second describes which fonts are browser safe and has example screen prints of these fonts being used in different browser on different platforms:

http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html

My first Flex application

The client I currently work for has many applications that are using Adobe Flex to generate a Flash front-end. As there is a chance that I have to participate in a Flex project it is about time to learn something about it and to create my first Flex app, so here you have it: hello world!

It was created using the trial Flex builder plugin for Eclipse and involved little more than a few clicks.

So far so good. I will play around with it a bit more and will dive into the subject of connecting with Java server side code later.

Update: a few lines of code later results in this: playing around with tabs

Spring Roo

Today I found out about the existence of Spring Roo. A really cool project that certainly fills a sweet spot between what IDE´s and build tools will do for you.

What is Spring Roo: as they say it “a little man that does all stuff you do not want to worry about”.

This translates to CODE GENERATION through a Spring Roo command shell environment.

Example goal: create a wedding RSVP application, including persistence using JPA and Hibernate. Take these steps:

1. create a directory named wedding

2. fire up Roo

3. type “create project” (Roo now creates a Maven 2 project)

4. type “persistence setup –provider HIBERNATE –database HYPERSONIC_PERSISTENT” (this creates all xml and properties files)

5. type the following to fill the database with something:

entity –name ~.domain.Rsvp

field string code –notNull –sizeMin 1 –sizeMax 30

field string email –sizeMax 30

field number attending –type java.lang.Integer

field string specialRequests –sizeMax 100

field date confirmed –type java.util.Date

6. Add a web tier: “controller scaffold ~.web.RsvpController”

7. See what we got! “mvn tomcat:run”

That´s (roughly) it, in just a few steps we have a working web application that conforms to the standards and includes unit tests!

Example taken from the Spring Roo site.

Jira, Confluence and Bamboo

For the last days I’ve been looking in to some products that a potential client is using and I have no experience with. There are three development process related products that nicely integrate together:

  • Jira – issue tracking and planning
  • Confluence – wiki
  • Bamboo – continuous build server

As they are commercial and all from the same company (Atlassian) it is no surprise that they integrate very well. Reports from Bamboo and Jira can be published via Confluence so that all essential information can be found in the same place – nice for both management and developers.

It is also possible to use Bamboo as a release management tool, somebody wrote a nice article about it and developed some plugins. This is about a year old, so maybe it is built in by now.

Progress on GPS parking pilot Amsterdam

After more testing and developing the GPS parking beta seems more viable than ever. Currently all major zones have been added and only the 10 cent and limited time parking areas have to be added.

This is the new main screen. As you can see there is an extra button that allows for selecting a zone by map.

This is the map screen. The screen is in ‘manual mode’ because the GPS is not turned on or available (e.g. indoors). The user can tap on the zone where he is parked and the application will retrieve the zone information.

In GPS mode this is done automatically.