On Scala (or: Why Static Typing Doesn’t Have To Suck)

November 29th, 2009

Last week Michael Neale and I gave a presentation at the 2009 Open Source Developer’s Conference. The topic was effectively a quick and dirty intro to the Scala language, along with some comparisons between Scala and other languages. I’m no Scala expert or even a day-to-day user but I’m a massive fan of what it stands for, which is in Mike’s words “a better Java than Java”. Hopefully that came across in the presentation.

The conference was a lot of fun and there were a lot of familiar faces from last year. I’ll no doubt be back again next time around!

Anyway, now that the presentation is out of the way, you can see our original paper here: On Scala (or: Why Static Typing Doesn’t Have to Suck). The presentation itself was recorded and is due to be put up on the Internet somewhere at some point in time. Will update this post if/when the video becomes available.

Categories: Software Development | No Comments

Clojure and MessageDigest

June 22nd, 2009

Last night I needed a quick and dirty SHA function for a clojure-based web application. MessageDigest to the rescue!


(ns com.deskchecked.utils
  (:use clojure.contrib.str-utils)
  (:import [java.security MessageDigest]))

(defn sha
  "Generates a SHA-256 hash of the given input plaintext."
  [input]
  (let [md (MessageDigest/getInstance "SHA-256")]
    (. md update (.getBytes input))
    (let [digest (.digest md)]
      (str-join "" (map #(Integer/toHexString (bit-and % 0xff)) digest)))))

There’s obviously a dependency on clojure-contrib here which you can do away with if you don’t need it. And of course, you can pick a hashing algorithm to suit your needs.

Nothing exciting, but I figure I can’t be the only person in need of this sort of stuff. :)

Categories: Functional Programming, Software Development | No Comments

HTML 5 Canvas Stroke Coordinates

June 1st, 2009

So HTML 5 has been getting a lot of attention recently — in no small part thanks to Google and others. Indeed, reading some of the features planned for HTML 5 are very exciting from a web developer’s perspective. The video and audio elements for standardized web page multimedia, worker threads and of course the canvas element and API.

Since getting excited about HTML 5, it’s been the canvas element that has most immediately grabbed my attention — both for the possibility it opens for a standardized way to render custom user interface components in HTML and for the fact it’s already quite well supported in the more popular alternative browsers (Firefox, Opera, Safari). So instead of studying maths like I should be doing (exams in less than two weeks!), I’ve been tinkering. Nothing exciting except to say that it’s fantastic to be able to render arbitrary graphics without waiting for an applet or Flash to load up.

However, I’ve been bitten by my first quirk in the API — a difference between how coordinates are used for strokes vs fills. Let me explain.

To draw a line using the HTML 5 canvas element, you use code that looks something like this:

  var context = $("canvas").getContext("2d");
  context.strokeStyle = "#a00";
  context.beginPath();
  context.moveTo(5, 5);
  context.lineTo(100, 5);
  context.stroke();

The resulting line looks like this:

The line is too wide!

Hmm. The line appears to be two pixels wide. Why is that? I figure maybe it was presumptious of me to assume a default of 1 pixel for lines, so I checked the spec. Nope, the spec says the default is 1.0. I read a little about coordinate space vs. bitmap size, it still didn’t really explain the behaviour I was seeing. So I poked around on #whatwg, and was told this:

Philip`: thomaslee: Integer coordinates refer to the positions *between* pixels
Philip`: thomaslee: If you want to draw a line through just a single column of pixels, you have to shift the coordinates by 0.5
snip
thomaslee: Philip`: right, so that would explain why I’m still seeing two pixel lines when reducing line width. But why on earth do integer coordinates refer to the space in between pixels?
Philip`: thomaslee: It’s that way so that fills work like you would expect (with sharp edges), but it has the consequence that strokes don’t quite work like you expect (so you have to shift them by 0.5 to the centers of pixels)

So I adjusted my code:

  var context = $("canvas").getContext("2d");
  context.strokeStyle = "#a00";
  context.beginPath();
  context.moveTo(5, 5.5);
  context.lineTo(100, 5.5);
  context.stroke();

Sure enough, it fixed the issue:

Ah, that's better!

Philip` then went on to explain why this counter-intuitive behaviour is to keep other aspects of the API suffering from similar issues. If you change the stroke behaviour, it breaks fills and vice versa. Without knowing the API for more than the few hours I’ve spent with it, I can’t really comment on it much more than that.

My brain hurts already.

Despite this weird behaviour, the canvas API on the whole seems to be very easy to follow and logical. And HTML 5 is slowly restoring my faith in the future of web development. We’re finally starting to see a move away from the hacks, work-arounds and the mish-mash of technologies that are the norm for modern web applications. Here’s hoping we don’t have to wait too long.

Now, back to the maths …

Categories: Software Development | 2 Comments

ausroomies.com.au launched!

January 31st, 2009

Over the past month or so I’ve been working on a site to enable people to find share accommodation here in Australia. I was a big fan of Gumtree’s simplicity but didn’t like how little control I had as a room seeker to really narrow down and organize the listings I’m interested in. I think this is, in part, due to the fact Gumtree is a site for generic classifieds rather than specifically for room seekers — which is totally understandable. However, so far I’ve found other room mate finder services to be over-complicated either requiring me to sign up for a membership (which I hate doing) or to fill out a big scary form in order to find a room. No thanks!

The site was originally written using Merb but a nasty DataMapper bug combined with lacking documentation lead me back to PHP, which sucked. On the plus side, this is my first project using the Symfony framework which really is quite nice as far as PHP frameworks go. I’m a little dubious about the direction in which the framework is headed in the medium to long term, but for this little project it was great.

So that’s how ausroomies came to be. The site’s not perfect and I’m especially worried about whether people will actually stay long enough to play with the search engine to see what it can do. My logs from the first day are indicating the answer is a big, fat “no”. Somewhat predictable I guess. Maybe it’ll become more useful as we get more data. I think the dodgey programmer design currently leaves a lot to be desired, too. I hope to resolve that in a month or so. Outside of that, I can’t convey how much of a relief it is to finally get it live and to finally have something to show for it compared to all the usual throw-away experiments and prototypes I usually play around with.

Anyway, now that this has launched I should hopefully be able to return to a relatively normal sleeping pattern. :) I’m keen to hear the good and bad, so please drop me a line if you have any feedback regarding the site.

Categories: Life, Software Development | 2 Comments

Prepaid Three Mobile Broadband on Ubuntu Linux with Gnome NetworkManager

December 29th, 2008

I received my shiny new Huawei E160G USB modem from 3 and was desperately hoping that I was just enough behind the curve that it would magically work out of the box with Ubuntu 8.10.

Now, I’m on a prepaid plan because I think contracts are the devil. As you would expect (?), the configuration required for the prepaid accounts is ever so slightly different from the defaults used by Ubuntu. Instead of using 3netaccess as the APN, you’ve got to use 3services.

If you’re running Gnome/Ubuntu, you can set the APN via System » Preferences » Network Configuration » Mobile Broadband, then selecting your Three mobile broadband profile and clicking “Edit”. The field for changing your APN should be in the “Advanced” section. Aside from that, you shouldn’t need to change anything more to enjoy your prepad Three account.

I’ve just sent off a patch to the upstream provider of the service data included with Gnome. I hope this saves somebody out there the two hours I just lost! :P

UPDATE: This patch was applied upstream on the 19/01/2009.

Categories: Software Development | 1 Comment

What do you most dislike about PHP?

December 17th, 2008

The title of this post is probably a little bit flamebait-ish, but I’m actually genuinely interested to get the Internet’s opinion on the following:

Pick any three aspects of PHP that makes you feel dirty as a developer, and post them as a comment here.

For me it’s:

  • The standard library is a huge, monolithic mess. This has been covered before, so I won’t beat a dead horse. I’d love to see the standard library reorganized and some sanity introduced around the naming of certain aspects.
  • Superglobals because they behave weirdly in certain scenarios and make unit testing a pain in the ass.
  • omg\namespace\separator\is\Backslash, which has effectively killed this long-awaited feature for me.

Again, I don’t intend for this to be about hating on PHP or its developers (read: comments that don’t contribute anything meaningful to the discussion won’t see the light of day). Instead, I want to formalize what causes people pain when working with PHP today. Who knows — maybe somebody, somewhere will listen?

Categories: PHP, Software Development | 2 Comments

Python Language Internals: From Source to Execution

December 10th, 2008

Last week I gave a presentation in Sydney for the Open Source Developer’s Conference on the internals of the Python compiler. Now that the conference is over, I figure there’s no better place for the original paper than right here on my blog.

Thanks again to my employer, Shine for all their wonderful support with this. Thanks too to the folks who reviewed my paper before it was submitted and my colleagues at Shine who endured a painful test run that ran well over time! ;)

OSDC 2008 was a whole lot of fun. If you happened to miss the conference, I strongly recommend you make it along next year. It’s well worth the trip.

Download Python Language Internals: From Source to Execution, and a corresponding patch against Python 2.6 beta 3 implementing the “unless” statement. If you want to test the patch, you also be aware of the nasty little circular dependency that may cause you some grief — apply the latest (non-review) patch from the tracker before you start the build and you should be fine.

Categories: Compilers, Python, Software Development | 1 Comment

Updated Code Section

November 25th, 2008

The “code” section of the website has been updated to reference most of the code I’ve uploaded to this blog over the past year or so. Enjoy!

Categories: Software Development | No Comments

A new look (and a new domain!)

October 19th, 2008

As you may have noticed in the last week or two, the web site has undergone a bit of a rebranding process. deskchecked.com will still continue to work for at least another year, but I’ll slowly be moving everything over to this new domain: deskchecked.com.

It probably seems like a trivial issue, but I’ve longed to get rid of the hyphen in the deskchecked domain. However, every time I went looking for a new domain name I was never happy with the alternatives I came up with. At long last, I’ve finally settled on this one. Unfortunately, this decision has already taken its toll on my Google rank but I’m sure as new content rolls in I’ll see that pick up again over time.

Again, I must apologise for the lack of posts. In addition to the OSDC paper, I’ve been busy actually writing code rather than just writing about writing code. :)

Categories: Software Development | 5 Comments

Ubiquity Command for Google Code Search

September 10th, 2008

Apologies for the extended silence, I’ve been super busy writing my OSDC paper. The paper was submitted for review just a few days back, so hopefully I’ll have a bit more time for this blog now. :)

Over the past day or two I’ve started taking a look at Mozilla Ubiquity, and have been quite impressed. Mac heads might think of it as QuickSilver for the browser: a keyboard-driven interface to getting stuff done. However, the real power of Ubiquity lies in how easy it is to extend it with new commands. It’s a command-line geek’s dream.

Anyway — until I find the time to write a meaningful post, check out my Ubiquity command for Google Code Search. You will need to install the Ubiquity add-on in order to install this command, obviously :)

Categories: Software Development | 1 Comment