Archive for January, 2008

Javascript prototypes

Thursday, January 31st, 2008

I’m really beginning to groove dynamic languages these days.

DailyCalorieNeed.prototype.getKgPerWeek = function() {
	return (((this.tee.value - this.value) * 7) / 7800).round();
}

Number.prototype.round = function() {
	return Math.round(this * 100) / 100;
}

Now I’m sure there are libraries out there that will give me better rounding, that’s not the point. The point is that you can just change anything you like to extend your environment so it is more expressive.

The prototype library provides an instance method version of Math.round() too.

3 things I didn’t know about Javascript until tonight

Thursday, January 31st, 2008

1.

Arrays and associative arrays as literals in Javascript:

	var activityLevels = {
		sedentary:[1.15, 1.15],
		light:[1.4, 1.35],
		moderate:[1.5, 1.45],
		very:[1.85, 1.7],
		exceptional:[2.1, 2]
	}

	alert(activityLevels["light"][0]);  // => 1.4

2.

Apparently you should use Object rather than Array if you’re creating an associative array:

	var hash = new Object();
	hash["key"] = “value”;
	hash["foo"] = “bar”;

I am aware of the mitigating factors — hell, I just enumerated them — but complaining that Prototype “breaks” your ability to use Array as a hash is like complaining that Prototype “breaks” your ability to use String as a hash. It is not Prototype’s fault that JavaScript does not deter this improper use, and it certainly does not mean that Prototype does not “play well with others.” You are free to reject Prototype and keep using Array improperly, but then you give up your right to bitch and moan.

Thanks Mr. Dupont

3.

Date handling made super-badass-awesome in Javascript:

	// Convert text into Date
	Date.parse('today');
	Date.parse('t + 5 d'); // today + 5 days
	Date.parse('next thursday');
	Date.parse('February 20th 1973');
	Date.parse('Thu, 1 July 2004 22:30:00');

http://www.datejs.com/

Souad Massi’s album Deb is damn fine

Monday, January 28th, 2008
iTunes.jpg

Picked up the album Deb by Souad Massi from the library, quite a random selection but I can’t recommend it highly enough. She’s singing in Algerian Arabic and French so I don’t understand a word she’s saying but the music and singing is beautiful.

I’m a particular fan of the Spanish influenced guitar on Houria.

This is pretty much singer/songwriter acoustic style music with strong pop sensibilities when she gets the band involved but you will find her under “World” music instead of “Pop” because record shops can’t cope with people singing in funny foreign languages.

In other music news…

I picked up LCD Soundsystem’s Sound of Silver on the iTunes Music Store the other day (they’re on EMI so DRM free) and it totally rocks. It took a couple of plays through though, kinda like when I first heard Fat Freddy’s Drop.

Link to her Wikipedia entry.

Yay, my parents on flickr

Saturday, January 26th, 2008
St Heliers Boardwalk on Flickr - Photo Sharing!.jpg

I’ve been gently nudging (repeatedly harassing) my parents towards taking more photos and putting those up on flickr.

After getting them a new camera for Christmas and dad buying an iMac I think we’re finally there.

Finally, photos from home! I might even get to see some photos of their new house if they read this and take the hint!

Link

Ed Hillary RIP

Friday, January 11th, 2008
Remembering Sir Edmund Hillary - The New York Times

“The whole world around us lay spread out like a giant relief map,” he told one interviewer. “I am a lucky man. I have had a dream and it has come true, and that is not a thing that happens often to men.”

The NYT has a good obit. and slideshow.

Link to obit.

Link to slideshow.

Scrabble…

Tuesday, January 8th, 2008

Nothing says excitement like a good game of Scrabble…

Monica won but I am getting better!

Monica wins Scrabble

Shiny new camera!

Sunday, January 6th, 2008

I got a lovely new camera for Christmas, thank you M. I’ve been eyeing this camera since early last year. My sister has one and I was impressed.

Canon SD800 IS

The camera is small and fits in my jeans pocket. The battery hasn’t run out yet. I love the wide angle lens, the equivalent of a 28mm lens on a 35mm camera, that makes it as wide as M’s new 17mm wide angle lens on her Canon 400D/Rebel XTi.

One flaw, the LCD shows bad flares around bright lights and while these flares don’t show in the actual photo, it is distracting. The flares do show on video captures though, be warned and maybe check out the newly updated version.

Canon Powershot SD800IS

Stationary dork

Sunday, January 6th, 2008

I’m a bit of a stationary dork…

Stationary dork

I got a lovely Retro 51 pencil and a 2008 Moleskine page-a-day diary from M for Christmas.

I like Moleskine diaries but Moleskine is too expensive for jotting notes and brainstorming so I was pleased to come across the nice exercise books at Muji, stylish and cheap.

SMS + Calling gone from Leopard’s Address Book

Sunday, January 6th, 2008

Ugh… I used that a lot.

Link

First toast!

Saturday, January 5th, 2008

Mmm…

My lovely toasty Christmas present

Thank you Monica.