Sunday, December 4, 2011

hackqd -- 4 Quick and Dirty Hacking

This last week at work I ran into a problem where I needed to analyze some log files. Being a linux weenie I started off by firing up the shell and started grepping and bashing my way around the problem, all the while thinking... "sheeshz, I sure wish I could do this in Scala". 

After a bit of brief googling I ran across Tom Morris' great article about "hacking" with Scala, http://tommorris.org/wiki/Scala_for_Hackers  As you'll see if you read it, by "hacking" we're talking about the sort of thing that developers and system administrators do constantly, i.e. writing "as simple as possible" utilities to help them take something apart or put something together. And if you're in the business of building cloud based systems you know exactly what I mean there's lots of this sort of utility work that needs to be done.

However, when I set off to use Scala for this I quickly discovered that reading Tom's article was not enough. First off, I wanted to work with 2.9.1, the most recent Scala compiler. Next up, I wanted to use com.googlecode.charts4j which immediately adds dependency management etc. And of course... I just wanted something simple to run from the command line. 

In case you didn't realize it, sbt has a great solution for exactly these sorts of problems. The "console" command allows you to use the Scala REPL from the command line and include all the dependencies in your project. But setting this up and figuring out how to get something like an App like trait capability accessible from sbt's console mode took just more than the couple of minutes I had available at work. 

So... I decided to hack at it over the weekend. 

The result is posted on github at https://github.com/langley/hackqd I hope to continue to refine this and add notes and a github wiki page to explain some of the experiments and continue to provide a good starting point for people who want to:
  • hack up a scala based solution to something
  • use charts4j and other useful hacking libraries from scala
  • and who knows what else... 

Having nice "bite sized chunks of code" usable as a starting point for building out quick Scala based hacked solution seems a great tool for learning getting started with Scala. 

-- Langley

No comments:

Post a Comment