I got published!

Oct 21

Well, quoted at least, in CIO.com’s article “6 Scripting Languages Your Developers Wish You’d Let Them Use.” I just talked Groovy and its Java integration up a bit.

The article itself is okay, the title is a bit misleading, most of the languages that the article visits aren’t really scripting languages as such, but it’s good to see languages like Groovy getting more exposure to the business types.

Anyway, enough self-promotion, back to study. Expect a blog post soon on OpenSearch and Firefox goodness.

The origins of "w00t"

Oct 21

My good friend Yi Long on the topic of “w00t”:

The synendochal substitution of “00” for the “oo” of “woot” references the binary coding system of digital technology, thus highlighting the materiality and non-symbolising symbolism of sign systems; the relationship between signs and their significations are arbitrary (de saussure), neither presenting something real nor substantial.

He’s doing an Arts degree.

Groovy threads

Aug 06

Note: I think I’ll re-write this post, it’s a little confusing, but I’m in a rush.

I was just mucking about with threading in Groovy, it really is very simple. You pass Thread.start() a Closure. You could do something as simple as this:

Thread.start {
  //# do expensive operation
}

Here’s the sample code I ended up with. There are a few semi-advanced Groovy concepts here.

ReentrantLock.metaClass.withLock allows us to give all ReentrantLock instances a new method called withLock. All this does is wrap a closure (which is called by it() in the middle) with the lock.

We then define a closure called worker, that prints out some spacing depending on which thread is working (the thread number is passed in as a parameter), and some dots, and the relative time (from when we started the program).

After this definition, we actually start 5 threads off, and print “ROCK!”. The curry method is very interesting, if you don’t know what it means, you should read more about currying.

The output of the code is below the sample code.

import java.util.concurrent.locks.ReentrantLock

def startTime = System.currentTimeMillis()

ReentrantLock.metaClass.withLock = {
  lock()
  try {
    it()
  }
  finally {
      unlock()
  }
}

def lock = new ReentrantLock()

def worker = { threadNum ->
  4.times { count ->
    lock.withLock {
      print " " * threadNum
      print "." * (count + 1)
      println " ${System.currentTimeMillis() - startTime}"
    }
    Thread.sleep(100);
  }
}

5.times {
  Thread.start worker.curry(it)
}

println "ROCK!"

Output:

ROCK!
 . 6
  . 6
. 6
   . 7
    . 8
 .. 107
  .. 107
   .. 108
.. 108
    .. 109
 ... 208
   ... 208
  ... 209
    ... 209
... 210
 .... 311
  .... 311
    .... 312
   .... 312
.... 313

Groovy snippets

Jul 20

I like the simplicity of languages like Ruby and JavaScript. In both of these languages, you can do something similar to:

foo = bar || "default"

This actually assigns either bar (if it is truthy), or "default" to foo.

Sadly, with Java and Groovy, foo will actually have either true or false as a value. Behold, there is a way to do the same thing with Groovy:

foo = bar ?: "default"

It’s kind of a play on the ternary operator.

This means I can reduce this code

User currentUser = User.findByName(user)

if (!currentUser) {
    currentUser = new User(name: user)
    currentUser.save()
}

session.user = currentUser

to the one liner:

session.user = User.findByName(user) ?: new User(name: user).save()

Many-to-many relationship mapping with GORM/Grails

Jul 19

I’ve been working on a pet project in my spare time – a sort of twitter clone that authenticates against Atlassian Crowd. I’m using the awesome Grails/Crowd plugin, which is pretty seamless (but needs a bit of internal polishing).

I’ve only scratched the surface of Grails, but here are a few things I’ve run into as a Grails newb.

Leveraging Twitter's API and Google's JS Library API

May 28

So, in the past half hour I’ve been working on getting the widget at the top-right working. I like it better than the badges twitter provides.

It makes use of the Twitter API, and Google’s recently launched JS Library API.

Here’s the code (or you can look at the bottom of the page source):

If you want to re-use it, replace twitterUsername with your twitter username.


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
  var twitterUsername = 'broady';

  $(document).ready(function() {
    $.ajax({
      dataType: 'jsonp',
      url: "http://twitter.com/statuses/user_timeline/" + twitterUsername + ".json?callback=twitterCallback"
    });
  });

  function twitterCallback(data) {
    var found = false;
    $.each(data, function(){
      if (this["text"].indexOf('@') != 0 && !found) {
        $('#twitter').text(this["text"]);
        found = true;
      }
    });
  }
</script>

Storm Clouds

May 28

Lightning has started, if I have time I’m going to try to get some shots of it.

Storm Clouds 2

Storm Clouds 3

Storm Clouds

Nightclub photography

May 25

On Thursday night, after uni, I headed down to Skygarden (in the Sydney CBD) to have a go at taking photos at the UNSW Commerce society/Law society dance party.

Here are some of the shots I got out:

You can see more over on the facebook page.

If you went to the party and want a print quality shot of any of the photos, get in contact with me, either through facebook, or through the contact page.

For the photography geeks out there, the settings I sat on through the night were pretty much:

  • Focal length: 17mm — (35mm equiv. = 27mm)
  • Aperture: f4—f6.3
  • Shutter speed: 0.8s—1.5s
  • ISO: ISO100—ISO400

Flash was used in a variety of ways (but still on-camera). I’m gonna have to get an off camera set-up soon!

Hit by spam

Apr 21

I woke up this morning, and for some reason decided to look at my blog. I found ~500 new comments, all spam. Naturally, I went to delete them, but due to lack of consciousness deleted all comments.

Anyway, the point is – I need to move to another blogging platform. Here are some options:

  • WordPress – I hate the templating
  • Enki
  • Mephisto
  • MovableType
  • Tumblr

Any thoughts?

Sydney Skyline

Mar 27

Sydney Skyline

Got off the bus stop today just at the right time to catch this rather nice sunset. Need better clouds though, next time

Older posts: 1 2