All posts by Alistair Lattimore

About Alistair Lattimore

My name is Alistair Lattimore, I'm in my very early 30's and live on the sunny Gold Coast in Australia. I married my high school sweet heart & we've been together for longer than I can remember. Claire and I started our family in September 2008 when Hugo was born and added a gorgeous little girl named Evie in May 2010. You can find me online in the typical hangouts, Google+, Twitter & facebook. .

JavaScript ParseInt Cast Error

It would appear there is some sort of an auto-casting problem in JavaScript. I have an external JavaScript file included into a page which defines a set of arrays, a line from the file looks like this:

  1. var resortPAArray = new Array('("1 Bed","1 Bedroom","2","3")','("2 Bed","2 Bedroom","3","5")','("Penthouse","Penthouse","4","10")');

The two numbers in each inner array represent the minimum and maximum people allowed to stay in that room type, for instance a 2 Bed bedroom can sleep a minimum of three and a maximum of five. There is a line in the JavaScript file for each building and they are used to auto-populate a booking form (to save posting back to the server on every change). The scripts were executing without error, until we added a room type which allowed ten (10) or more people in it.

When you select the building, it uses the inner arrays to populate a dropdown box with the room types (1 Bedroom, 2 Bedroom, ..). Once you select the room type, it then populates the next dropdown with the corresponding min/max people for that room type. Out of interest, the min/max values are assigned as follows where tmpArray represents an inner array:

  1. minpax=tmpArray[2];
  2. maxpax=tmpArray[3];

From here, those values are used in a for loop as follows:

  1. for (var i=minpax; i<=maxpax; i++) {
  2. // code here
  3. }

Remember, at this point the script is executing without any problems. When the values are assigned to the minpax and maxpax variables, they are technically strings – since they are defined in the inner arrays with quotes around them. Conveniently, JavaScript auto-casts values for you – as such the strings are cast to a numeric internally and the mathematic comparison is done.

Unfortunately, when a string value of 10 was assigned to maxpax, the for loop never executed and the as such, you couldn’t select how many people you wanted in that room. Initially, it made no sense at all. The JavaScript file for this building was structurally sound, no missing quotes, brackets or commas. All the values were in place, no strange characters at all – it was, for all intensive purposes, just like all the others.

The solution was quite simple, explicitly cast the values for minpax/maxpax when they are initially assigned or during the for loop.

  1. for (var i=parseInt(minpax); i<=parseInt(maxpax); i++) {
  2. // code here
  3. }

The Uplate Game Show With Hotdogs

Not long after Hotdogs was evicted from the Big Brother house, he signed a deal with Network Ten for his own show. The show, “The Uplate Game Show” would take the place of “Big Brother Uplate” that was hosted by Mike Goldman.

While Big Brother was running, Uplate with Mike Goldman worked. He would talk about the day that just passed, show snippets of what happened during the day and live feeds from the house. While that was going on, there were also little brain teaser type games being played – an anagram game for instance.

This however, is in stark contrast to The Uplate Game Show. One of the primary reasons it worked with Mike Goldman, was the audience were watching to find out about the craze that is Big Brother. Unfortunately for Hotdogs, he doesn’t have any of that – which leaves him with pointless games and his lack luster hosting ability.

The last couple of times I’ve seen it before going to bed, he is calling people that have registered on his list. Problem is, the show is that boring that once they register they don’t watch it again. Last night again, he called three people who were in bed, the call went something like this (my emphasis and paraphrasing):

Hotdogs: HI!!!!, this is Hotdogs from the Uplate Game show!!!11one
Them: umm, heelllloo.. who is it again..?
Hotdogs: Its Hotdogs!!!!11one, did you register on the Uplate Game Show list????
Them: umm, sorry.. you’ll have to speak a little slower
Hotdogs: The Uplate Game Show, did you register???
Them: umm, no I didn’t.. maybe it was my daughter but she has been in bed for 3 hours already
Hotdogs: well I guess I don’t get to give away a prize tonight then
Them: nope, sorry.

If that isn’t bad enough, imagine the worst TV host you can. Now imagine them on TV for an hour and a half a night, with absolutely no content to discuss at all. It isn’t an entertainment show, he doesn’t discuss any current events at all – its just him, his Uplate list (that no one is awake for), the crap games and him babbling for the whole thing repeating himself over and over.

I can’t believe that the show is on TV, it is appalling.

ADO RecordSet GetRows

ActiveX Data Objects (ADO) enable you to access and manipulate data from a variety of different sources. Through ADO, you can connect to various databases such as Access, mySQL, PostgreSQL, MSSQL, Oracle and more. Once connected you can execute SQL against the database, as per normal.

ADO provides a series of objects, methods and properties to make your life as a developer easier. One such object is the RecordSet, which provides a GetRows method. GetRows purpose is to copy a series of records from a populated RecordSet object and place them into an array. You can specify the number of rows to copy, where to start copying from and what fields in the RecordSet you’d like copied. The general format is as follows:

myArray = myRecordSet.GetRows(<number of rows>, <starting position>, <fields>)

After consulting the documentation for the method on MSDN, it appears that calling the GetRows method actually advances the current cursor position in the RecordSet. As an example, consider a RecordSet with the cursor position pointing to the first item. After calling GetRows with a three (3) for the first parameter, the next time you read the RecordSet the cursor will be pointing at the fourth record.

Unfortunately, I was caught out by this feature. Without consulting any documentation on the method first, I expected that calling GetRows would copy an arbitrary number of records from any position in the RecordSet without altering the current cursor position. If it did need to move the cursor to access the rows, I expected that it would return the cursor to the original position.

This is really just a fine implementation issue. I felt that since it was a copy type method, that it wouldn’t have made any modification to the RecordSet object. If you hadn’t of read the documentation, would you expect that it would advance the cursor or leave it in its original position?

Brisbane Formal Wear/Suit Hire

With the wedding creeping up on us week by week, it was well and truly time to organise the suits for the groom and groomsmen.

It was suggested that we first port of call be Tony Barlow, as he apparently has a good range of formal wear for weddings, formals, balls and so forth. The suggestion was spot on, we didn’t need to go anywhere else for it – they had everything we needed. Our attendant, Sonya (from memory) was also fantastic, she knew what we should and shouldn’t be wearing, what looks good and what is considered a fashion faux pas. The whole experience was very simple and straight forward, no doubt helped along by a great attendant.

Strike one more from the list, September 24 here we come!

Espresso Porn

Last night, Natalie dropped a link to a site all about coffee porn (yes, the content is work safe – except for the domain name itself). The mental imagery was running rampant to start with, picturing people making espresso in the nude and who knows what else.

Once I clicked into the site, I was given a very pleasant surprise – its a coffee site, by coffee lovers for coffee lovers, of sorts. It shows a whole bunch of close up photos of coffee being made, ie the cradle with fresh coffee and crema filtering through it. There are some really awesome shots on there actually, I really like:

I think I’ve now seen one of the most beautiful things in the world, ohh how I love coffee.
:)