Clarence's Coding Journal

My software development experiences.

Learning Clojure

The land of Clojure goodness

A couple of weeks ago I rolled off from my previous client and I joined an existing project at a new client. My new project has already been active for about a year now. The interesting thing from a technology point of view is that the core language used on this project is Clojure. The prospect of learning and using a functional programming language like Clojure is very exciting for me as I spent the last several months on a project where the main language used was good old boring Java.

Most of my career I’ve been doing imperative-style programming, usually in the form of Object-Oriented programming. Earlier this year I tried my hand at Scala by following along in the excellent Coursera course Functional Programming Principles in Scala. This course taught me a few of the fundamental Functional Programming concepts so I wasn’t completely new going into Clojure.

What is Clojure?

Briefly, Clojure is a general purpose, functional, dynamic programming language which targets the Java Virtual Machine (JVM). Clojure is a dialect of Lisp. I remember learning Lisp when I was at University and I remember all the peculiar nested parentheses that confused me at times. Luckily, Clojure makes some trade-offs in favour of wider adoption and accessibility to mainstream developers over being a pure Lisp clone. This means that you’ll see syntactic sugar and other data structures – not everything is a list.

Where did I start my learning?

Luckily, I had a couple of days before starting on my new project to get some exposure to Clojure. I started with the awesome Clojure Koans. The Koans are mini exercises where you fix failing tests by writing code and you follow a learning path through the main parts of Clojure. Next, I started looking at 4Clojure.com where you solve progressively harder problems by filling in code snippets and submitting your solution – this is entirely web based so no extra tools are required though you should have some basic Clojure knowledge first.

How is going so far?

I’m lucky in that I am in an awesome, supportive team that practices pair programming on all user stories. This means that in the two short weeks that I have been on my project I have picked up a fair amount of Clojure and learnt some useful tips from experienced Clojure developers. Clojure is mostly used in the backed services on my project and the front-end makes use of AngularJS. This means that I am dividing my time between learning Clojure and AngularJS (which is also new for me).

So far I’m finding Clojure to be a very powerful and productive language. It reminds me of the “wow” moment I experienced when I first started learning Ruby after having spent a lot of time in C# and Java. The first thing I noticed was how little code was required to implement a feature and without excessive ceremony and boilerplate code.

Tooling

I am using Leiningen from the commandline for most build and testing tasks but using IntelliJ IDEA with the La Clojure plugin for code editing, navigation and refactoring. IntelliJ was chosen by the team I joined so I am just sticking with that for now. Another team using Clojure at my current client develops in Emacs. I’m keen to try out Emacs when I am a bit more confident with Clojure as I don’t want to introduce too many new things at once!

What’s next?

I’m currently going through the book Programming Clojure (2nd edition) by Stuart Halloway and Aaron Bedra to gain a bit more depth and breadth in Clojure. However, I expect to get better at it through practice and pairing on a real production codebase (i.e. my client project described earlier).

Viewing Git History in Summary Form

I use this one all the time for getting a nice summary of git commits:

1
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short

Here’s what the output looks like (used on the Homebrew git repo):

1
2
3
4
5
6
7
8
9
10
11
12
13
* d66c9f3 2011-03-16 | Boost version bump to 1.46.1 [Clint Shryock]
* 43019ac 2011-03-16 | Update JRuby to 1.6.0. [Aku Kotkavuo]
* 8ffc126 2011-03-16 | Erlang R14B02 [Yurii Rashkovskii]
* 24f4ad5 2011-03-16 | Gearman 0.18 [Clint Shryock]
* ec6521e 2011-03-15 | Fix keg-only, non-system dupes [Adam Vandenberg]
* fa2f638 2011-03-15 | Document keg-only system duplicates. [Adam Vandenberg]
* 3338b14 2011-03-15 | install - change keg-only warning [Adam Vandenberg]
* 9eb7c19 2011-03-15 | keg-only: provide more info about system dupes [Adam Vandenberg]
* d600846 2011-03-15 | scantailor: add libtiff dependency [Adam Vandenberg]
* 309ae6b 2011-03-15 | keg - use proper inheritance style [Adam Vandenberg]
* 3b25f34 2011-03-15 | Add new fontforge git repo as HEAD [codingisacopingstrategy]
* ac95e5c 2011-03-15 | New formula: mpg321 [Luca Spiller]
* 48c0ab0 2011-03-15 | Fix homepage audit warnings [Adam Vandenberg]

The output will also show any tags and visually show branches and merges.

You can then add it to your git config as an alias:

1
2
[alias]
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

And use it like so:

1
git hist

I got this tip from the following git tutorial site: http://gitimmersion.com

Getting Wireless Internet Working on Centos 6 on Your MacBook Pro

At home I have been setting up CentOS 6.2 on a spare MacBook Pro (thanks to my IS friend at work) for learning about RHEL 6. Since I use a wireless router, I wanted to get a wireless connection setup on the laptop. The MacBook Pros use a Broadcom wireless NIC:

1
2
$ lspci | grep Broadcom
04:00.0 Network controller: Broadcom Corporation BCM43224 802.11a/b/g/n Wireless LAN Controller (rev 01)

I initially tried compiling and installing the Broadcom driver following the (roughly similar) steps described here and here but with no luck (#sadtrombone).

Later, I saw a note at the top of the second page (referenced above) which linked to a source RPM called wl-kmod on ELRepo.org. I thought I’d give it one more try so I followed the relatively short and simple instructions on the wl-kmod page and it worked without a hitch!

The steps involve you installing some development tool packages, downloading a SRPM for wl-kmod, downloading the source for the Broadcom driver (64-bit in my case), building and installing the final RPM for wl-kmod. Once you either reboot or manually add the Linux kernal modules from the command line you see a new “Wireless Networks” section appear under the already existing “Wired Networks” section on the top right of your desktop (if you are running one that is).

You can then proceed to select one of the wireless networks that are detected (or manually add one yourself) and enter the wireless security details.

From the command line you will see the new wireless interface:

1
2
3
4
$ ifconfig eth1
eth1    Link encap:Ethernet HWaddr:xxxxxxxxxxxx
        inet addr:xxxxxxxxxx
        ...etc...

From then onwards it should just work!

AWS Summit, Melbourne

Yesterday (15th May 2012), I attended the AWS Summit in Melbourne. This was a single day event covering the future of the AWS Cloud and incorporating some deeper dive sessions. In the middle of the day there were three (3) breakout tracks. I attended the AWS “Ninja” Training track (the other two were Executive and Architecture tracks).

Most of the sessions were by Amazon AWS speakers; except for a couple by ThoughtWorks and one by TrendMicro. I particularly liked the “Continuous Delivery in the Cloud, The Devops Warrior Workshop” session by Nigel Fernandes and Fabio Lessa of ThoughtWorks; mostly because it was a bit deeper than the other sessions and showed some real-world application of Continuous Delivery on the AWS cloud.

The presentations and supplemental materials will be available in about a week’s time at the following URL: http://aws.amazon.com/awssummit. Nigel and Fabio’s code for the presentation are on Github and will be referenced in the slides that are published.

The event is being repeated tomorrow in Sydney. To follow along on Twitter, see the hashtag: #awssummit.

Some useful topics/resources mentioned in various talk were:

  • Guidance for designing different types of applications in the cloud at AWS Reference Architectures
  • Automating the provisioning of AWS resources with CloudFormation and building CloudFormation templates with CloudFormer from an existing set of resources
  • Taking advantage of Auto Scaling to automatically scale your fleet of servers up or down; particularly Scaling by Policy
  • Using ElasticCache for storing user session data in memory externally from your web tier to allow scaling up/down and deploys to happen more easily
  • Using IAM credentials in EC2 AMIs rather than your AWS credentials to limit potential damage if credentials are compromised
  • Bootstrapping launched AMIs via User Data scripts (e.g. passing in credentials)
  • Taking advantage of metadata Tags on AWS resources to more easily manage them
  • Using DynamoDB to support Big Data scenarios and have a fully managed and scalable database

There was also mention of the AWS re:Invent conference later in the year in Las Vegas. I’ll see if I can use my training budget for this :)

Checking Your GitHub SSH Key Fingerprints

Regular GitHub users are probably aware of the recent GitHub security vulnerability that was exploited by this fellow. You’ve also probably just received instructions via email to audit your SSH keys. An easy way to do this is to run following command on your SSH key(s) stored on your computer:

1
ssh-keygen -lf <path_to_your_public_ssh_key>

This will then display the fingerprint of your public key which you can then compare to fingerprint displayed next to your public key on GitHub.

Example:

1
ssh-keygen -lf dummy.pub  2048 d3:c7:8d:73:b4:6e:00:5d:ce:c6:85:04:9e:6c:67:51 dummy.pub (RSA)

In this case, the fingerprint is the part:

1
d3:c7:8d:73:b4:6e:00:5d:ce:c6:85:04:9e:6c:67:51