Groovy with spice – curried closures

Groovy rocks!

I have used Groovy swing builder before to layout some basic Swing UIs, but recently I used it for the first time for some real scripting. It was a script to do some database maintenance, and I was amazed at how easy, fun and productive Groovy can be.

What surprised me most was how easy it was to refactor as I went along. I had assumed that it will be inherently more difficult to modify it without static typing and full IDE support. Not the case at all, although it was a single script, and so things might be different if it is a Groovy program spread over multiple scripts.

Incidentally, the Codehaus Groovy Closures page has the easiest to understand explanation of what curried functions are -

You can fix the values for one or more arguments to a closure instance using the curry() method from the Closure type. In fact, this action is often referred to as currying in functional programming circles, and the result is generally referred to as a Curried Closure. Curried closures are very useful for creating generic closure definitions, and then creating several curried versions of the original with differing parameters bound to them.

I had glanced over curried functions in past, and it always looked like something that I will have to sit down and write some code to fully understand. But this explanation just clicked instantly. Thanks to whoever wrote this; I am sure I will find a use for it again soon.

Intellij IDEA – Add unambiguous imports as you type

One of my favourite settings in IDEA is to turn on the ‘Add unambiguous imports on the fly’ option.
With this on, if you type a class name, and that class is unique in the project libraries, IDEA automatically adds an import for that class. No need to stop typing to press ALT – ENTER.

So, I updated to IDEA 7 and found this wasn’t working anymore. Even more annoying, I couldn’t find this option in the settings. Turns out this setting has a new home.
In IDEA 7, it is has been moved to Settings|Code style|Imports.

Ref – EAP 7087 Release Notes

WordPress blogs – Source code syntax highlighting

Say goodbye to the code tag.
Wordpress.com blogs have a new shortcode to post source code with syntax highlighting.
http://wordpress.com/blog/2007/09/03/posting-source-code/

If you find that you can’t get it to work, make sure that you have typed in the shortcode, and not copied the snippet from the FAQ entry.

When copied, the snippet contains invalid markup. See if you can spot the difference -

sourcecode language='css']...[/sourcecode
sourcecode language=’css’]...[/sourcecode

:)

Friendster hacked

(or how to use Firefox web developer to impress your wife :) )

Looks like Friendster is suffering from some kind of CSS attack.
So, if your Friendster profile page is showing up a blank page, go to this link – Friendster Hacked and follow the instructions there to fix it.

Now on to how Chris Pederick’s Web developer made me look like a hero (at least in my wife’s eyes) :) :-

Wifey comes home and tells me her Friendster site is not working. Being the good samaritan that I am, I immediately open up my browser to have a look. The page shows up all blank, so of course the first thing I do is View – Source.
All the page data is there in the source, it just isn’t showing up.
Hmmm…time to download and install Web Develoer and Firebug in her browser. That done the following few steps led to resolution of the problem :-

Using Web Developer extension -
1. Try Disable -> Javascript – no effect
2. Try CSS -> Disable Styles -> All Styles – Cool! The page shows up without all styles; time to narrow it down
3. Try CSS -> Disable Styles -> Embedded Styles – The page shows up
(CSS -> Disable Styles -> Inline Styles has no effect, so the problem is in an embedded style)
4. Do CSS -> View CSS – All the different styles are listed in a new tab. Luckily there are only two embedded styles, and one of them immediately seems like the problem -

Embedded Styles from http://www.friendster.com/user.php?uid=XYZ
body {background-color:#ffffff;
background-attachment:fixed}
.commonbox h2 {background-color:transparent; color:#ffffff}
.commonbox {border-color:transparent}

div{display:none}

Back to View – Source, and a search for div{display:none} brings up the offending code -
Friendster code

Ha! I actually LOL when I saw this.
It was easy to fix this after getting so far. Go to the Profile page, bring up the edit box for the shout out. For my wife’s account, it came up as this -
Friendster
Remove, reset and save, and the profile was back to the way it was.

After fixing it, I google for friendster hacked, and one of the first few links is the one mentioned above.
Darn! Could just have googled first, but then I would have missed out on having all this fun, and my wife wouldn’t have been as impressed he he.

BTW, anybody at Friendster looking for an exceptional software developer? ;)

P.S. If you use Firefox, go get the web developer extension. It is priceless for the web developers and the power users alike.

Some programming blog recommendations

First one up is Brian Oxley’s blog, which I have been reading for a while now. He writes only occasionally, but almost all his posts have solid, relevant content. Exactly the kind of technical blog I like to read.

Chris Ashton is the newest entry on my blogroll, informative and entertaining.
He mostly uses C++ C# when talking about programming, but all the posts I read were programming language neutral.
Here’s something from his post on brainstorming that made me laugh out -

Today I’m able to articulate exactly what bugged me about that meeting, namely: there were no customers in that room. Or outside of it, for that matter. All we had was a bunch of devs pulling shit out of their asses and trying to pretend that someday, somewhere a customer might want to have this hypothetical product with all these features, even so much as to pay real money for it. We had this illusion that we were super creative geniuses and coming up with all these new ideas, but really we were just wanking. Hell, the ideas weren’t all that novel anyways.

Spot on, mate.

And finally, recently rediscovered thanks to Brian, is Ivan Moore’s Programming in the small series. Short sweet nuggets of programming wisdom. Check it out!

Bloglines – claiming your wordpress.com blog feed

Bloglines allows you to claim the feed for your blog. Verifying a claim requires adding two Bloglines provided keys to your blog, one in a post, and the other one in the template of your blog.

Adding a key to a blog post is easy enough, but the free wordpress.com account does not allow you to edit your template. No problem…just add a text widget to your blog and add the second key there.

BTW, when adding the first key in a blog post, I was only able to get it to work by including it using the code tags.

(Suggested by Jack Whitsitt, via WordPress forums. Thanks, Jack.)

Freakonomics and Undercover Economist

I find my reading habits go through cycles.
Last year it was a lot of SF. This year, until now, it has been mostly non fiction on a variety of topics.
The next up, I think, will be a lot of technical reading, but only after I finish reading all the fantasy novels in my stack of already bought books -

book_stack.jpg

It was fun reading Freakonomics and Undercover Economist. I would definitely be recommending these to friends.

Freakonomics is the first book on economics that I have read in a long time.
A good read overall, but I found it getting boring at times. One reason is that the topics covered are a bit far away from everyday life in Malaysia. Also, the author often spends too much time describing the methods used and figures collected during his research.

The Undercover Economist, on the other hand, is a much more fun and lighter read. The case studies are shorter, and they are the kind of things you come across every day.
And, I am no longer embarrassed buying the cheapest drink on Starbucks menu.
Why should I, now that I understand differential pricing ;)

The link is out there – no more!

Remember the ‘Where would you like to go today’ slogan MS homepage used to have?

That’s what Erik’s Linkblog was like for me.
A few moments to spare and I used to head over to Erik’s Linkblog to see what good stuff I could find to read.

But no more! After many years of bringing us the best of the links (especially Java) every day, Eric is putting it to rest.

We will miss it Erik. Thanks for all the hard work.