Mawson's Hut

Jeremy Mawson

Jenkins Git-plugin on Windows pauses when cloning.

If you have Jenkins & Msysgit on Windows, and you find that the git-plugin is pausing at the cloning stage, it is likely that the ssh child process is blocking for input.

Ensure that sure your ssh keys are in the correct location and that they don't require a password.

To find the correct location, in Process Explorer switch to tree view, and locate the stalled ssh.exe child process of Jenkins. Drill into it and confirm the HOME environment setting. This is where your .ssh folder should be located. For me it was c:\documents and settings\{username}\

Option's hidden gem

Did many people know about Option.apply before a few days ago? If my twitter stream is any indicator, it was a hidden gem waiting to be uncovered.

It was (welcome) news to me.

When integrating Scala with Java I often need to bridge a null to an Option type. It's important to convert nulls to Options because having nulls littering your logic means you can't trust your variables to be of the type declared; they might be null, and you have to check them with boilerplate if (x == null) checks at every turn.

Previously I was implementing this boilerplate pattern at every join between Scala and Java code where the latter might inject nulls into my logic.

The buzz that went around twitter was that this pattern already exists on the Option object.

Filed under  //   option   scala  

SBT plugin updates

How, oh how could I have forgotten SBT-GH-Issues? It allows management of github issues via SBT. This is the plugin that initially got me thinking ‘what other wonderful jewels are out there’?.

Since I wrote my last post, the Jenkins CI plugin has diverged from the Hudson version. (It’s been updated by @uzi_landsmann)

And then there’s a newly emerged code coverage plugin “name_pending”. It’s in beta and there has been at least one report of it not working well. But it’s early days yet, and I have hope in it.

Filed under  //   sbt   scala  

Plugins for SBT

SBT, the Simple Build Tool, has excellent plugin support. The official list of SBT plugins is on the SBT Wiki. I suspect it is not entirely up-to-date.

Here’s a list of plugins currently available. Some I have used personally, most I have not.

IDE/Tooling Support

Testing

  • Execute Cucumber features via cuke4duke Cuke4Duke SBT plugin by @rubbish (Don’t forget SBT already has testing support built in Specs, ScalaTest and ScalaCheck if these suit your needs better).

Build Artefacts

Code Metrics

Deploying

Polyglot

Continuous Integration

  • Still using Hudson? Hudson SBT Plugin
  • ^HudsonJenkins Jenkins SBT Plugin (I’m not sure if these differ at all currently, but I’d not be surprised if they diverged over time).

I’m sure to have missed a few. If so, let me know. Or better still, head over to the SBT Wiki and update it.

To keep up with new plugins (and libraries) as they are published, I recommend a subscription to implicit.ly

Filed under  //   sbt   scala  

Checking if your Brisbane property is flooded

I'm not in Brisbane, so I can't see how my property is doing right now. It's in a flood affected area, so I sought a way to see if it was flooded.

There is this useful local council facility for generating any properties flood report: http://flood.brisbane.qld.gov.au/floodwise_property_report/. Here's an example.

Flood_report

According to the Brisbane Times the flood peaked at 4.46 metres. The generated reports shows the range of heights above sea level for the given property. It also shows the minimum habitable level, which is where living areas must be constructed above.

In lieu of any other information this should be enough to determine the likelihood of your property being damaged.

My Scala submission to ai-contest.com for 2010

Bot name: Synesso
Unoficial rank: 500-600
Language: Scala
Source: https://github.com/Synesso/ai-contest-scala-impl

Whilst my bot is not a top performer (it's ranking about the top 11-12%), I thought it may be interesting to some to see idiomatic Scala with higher-order functions, method lifting, immutable types and specification tests (most of my bot was written using BDD).

I completely re-wrote the app entry-point from the Java starter pack and it is much more succinct. (I made this pack available to other contestants via the forums).

The specifications are here. Here's a good example of one. It deals with the behaviour of planets to project their future state given the incoming fleets.

The bot logic is here. Distinct operations were separated into different methods. These were lifted to functions and tested as closures in the specs.

Not having done any AI or game logic before I took a naive approach. I aimed for simplicity and treated each move independently. I did not differentiate between enemy targets and neutral targets. If it is a good deal (distance, regen and population wise) I take it. I sought to expand my collection of planets as a group rather than jumping to make distant colonies.

I would have loved to work with someone else during this project. Next year my local Scala user group will submit a collective bot. I can't wait.

I spent a long time trying to implement the same type of bot in Java, rewriting it maybe 5 times. It just got too messy for my liking. As soon as I could no longer make changes without side-effects I had to start again with a slightly revised algorithm. Using Scala made the task far simpler.

Filed under  //   ai   scala  

For comprehensions or higher order methods?

Scala's for-comprehensions are syntactical sugar for underlying higher order methods. The following two lines produce identical results. Which do you prefer, and why?

Filed under  //   scala  

Pascal's Triangle Kata

Here is my solution to James Carr's recent Kata - Pascal's Triangle. Implemented in Scala.

This recursive loop terminates on line 3 when the length of the List of Lists of Longs meets the required length.

On line 4 it adds a zero to the start and end of the latest list and forms a new list where each neighbour cell is added together. This new list is appended to the cumulative total and the function is called again.

Comments on the approach are appreciated.

Filed under  //   kata   scala  

Getting total size of files

I needed to quickly obtain the cumulative size of all log files in the current path. Here's how I did it:

  du logs*|sort -n|cut -f 1|awk '{tot=tot+$1} END {print tot}'

I'm sure there is an easier way. Please let me know so I can kick myself.

Filed under  //   bash