"Blog" misspelled!!?

I have Firefox 2.0 installed, with its built-in spell-checker. Now apparently when I say 'blog', it thinks I must've meant one of log, bog, slog, clog or flog. I've added it to my dictionary (which is "English (Australian)", by the way). I also have American and British installed, just like I have the English keyboard layout installed as a spare, so I can easily switch and type £ quite easily. 🙂

Javascript's getYear() function, and other IE headaches

Someone I know came across this gem. I guess it's well publicised, but if you haven't come across it before, it could easily catch you out.

The interesting thing is that IE will give you 2006 for getYear(). That's wrong. It should give 106 (as per http://www.w3schools.com/jsref/jsref_getYear.asp). The correct function to use is getFullYear(). But of course, if you develop for IE primarily, you'll find this and think that other browsers are wrong. Then you'll put stuff in place to detect which browser you're working on, so that the 'buggy' other browsers handle the JavaScript correctly. Then some future version of IE will fix it, and your code will break within IE.

I have come across a menu system a while back that doesn't like IE7 because they had an IE-specific version of their code. Personally, I prefer to write for Firefox first (I find that Firefox has tended in the past to be slightly closer to the W3C standard), and then work on any code that doesn't work properly in IE, so that it displays correctly in both browsers WITHOUT having to have browser-detection. It can be hard, but it's definitely doable. I think it's much safer to stick as close as possible to the standard (but I do appreciate that this is a nice 'theory', and shouldn't be an enforced rule).

Correction: That page gives you the value that the current browser will give. Seems here, Firefox is wrong, as per the description of the function 'it should return 4 digits'. I had browsed to the page which said "this will give you 106", and figured it was correct, when actually, that was a browser quirk. Oh joy!  (Thanks Alun)

Another correction: Seems that JavaScript 1.5 is supposed to give 106, and JavaScript 1.2 and earlier are supposed to give 2006 – http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Date:getYear – but either way, it's deprecated, and getFullYear() should be used instead.

The horror of daylight savings (sorry Perth)

I have friends in Perth, who I have always envied for the fact that they don't apply daylight savings there.

For anyone who somehow has no idea what I'm talking about… because the days are long in the summer, many countries in the world apply 'daylight savings', to effectively shift an hour of daylight from the morning (when people are typically still asleep) to the evening (when people are still able to work). When winter comes around again, they adjust back to 'normal', and have a day centred around noon again.

Personally, I wish the world would just say "Hey, it makes much more sense for us to be centred around 1pm. The working day (9am-5pm) is centred around 1pm, so let's make our timezone match that being the time that the sun is at its highest too." Then we could abolish daylight savings. It might make for winter mornings when the sun doesn't come up until after we're at work, but how is that much different to having the sun go down at 4pm? Much easier if you live near the equator and have days that much more consistent in length. I have a cousin who lives in the Shetland Islands, where at Christmas the sun doesn't quite come up even at noon.

And now Western Australia (the state that contains Perth) is looking to introduce daylight savings. Of course, much of the population is rejoicing. They want to have the hour of daylight shifted from the morning to the evening. They don't want to be woken up by the sun streaming through their windows at 5am – they'd much rather have it stay up until 8pm in the evening.

But pity all the people who ever use computers, and have no idea of the luxury they've always had by not having a timezone adjustment.

Oh I know… Windows is really good this way and will adjust your timezone for you twice a year. Microsoft even bring out patches to fix up Australian computers when the government decides to change the system for the Olympics or Commonwealth games. I'm sure Microsoft will roll its collective all-seeing eyes and produce a patch for Perthites. If not, Michael Kleef will write one himself!

But what does this mean for all the code that was written without considering daylight savings? Surely the fact that you never hear whinges from developers in the rest of the world about daylight savings?

Well, you actually do. It's one of those things that people just live with. But the nightmares caused by daylight savings are many.

So, consider the situation where your server changes timezones. You might have a 2-minute-long event which started at 00:59 and ended 02:01. Or which started at 01:59 and ended at 01:01. Does your code handle that? Do your clients mind if you're working around the clock on something but the timeline suggests you all took an hour off in the middle of a crisis?

Or, consider the situation where your server doesn't change timezones. People start whinging that 'current time' is displayed wrong on the web server. So you translate everything into the user's timezone, but now when they look for that event that occurred at 5pm on a particular day 6 months ago, they can't find it, because they've changed timezone since then and the history figures it must've happened at 4pm.

What happens to the overnight staff who work for that extra hour in Autumn/Fall, or work an hour less in Spring? Do you pay them for that time? The system says they clocked in at 10pm and left at 8am, same as always… Or else they actually have worked an extra hour and break various industrial relation laws. Not to mention the disgruntled person who feels that they've been forced to work an hour less…

People typically make the decision one way or another and just live with it. But poor Perth – they had the luxury of avoiding daylight savings, and may find it forced on them.

Faster binary converter – where do your solutions come from?

Mitch Wheat is a great guy. He really is. And he's clearly a mathematician.

I mean, I did a half-major as part of my BSc, doing a handful of 3rd year Pure Maths subjects (which I got HDs in too – I wasn't just sleeping during class), but Mitch… he thinks like a mathematician. You can tell when he comes up with a solution like this for converting numbers to binary. Makes me wonder if this is something he came up with, or something he read in a book. Knowing Mitch, he came up with it himself. I'm in a bit of awe here. I feel like it's the kind of solution that I could've come up with once upon a time, and hopefully could still given the right colleagues and a whiteboard. 🙂

Let's come back to the 'solution read in a book' thing.

I remember sitting in a user-group meeting in Redmond in March. Itzik was speaking. He was talking about the use of CLR in SQL, and came across the Product aggregate function. There is no product() in T-SQL, and a lot of people have considered that it's a good candidate for CLR, since you can make a user-defined aggregate function this way. Itzik's lines were something like "And I was sure there was a good way of doing this without having to use CLR, so I got reading my maths books." He mentioned some of the names that I have a vague recollection of from my university days (which I have forgotten again so won't write here), and then said that he came across log(a*b) = log(a) + log(b). And of course, almost everyone in the room had light-bulbs appear.

I wasn't so much inspired by the fact that "here's this great way of solving the product question", but rather "here's a way of solving some miscellaneous thing, where the answer comes out of a maths book." And now I've found Mitch providing me with the same hunger to academise (that's not a word, but you know what I mean).

I nearly got into academia. Having done uni, I had offers to do a PhD. But I had a good job offer, and studying didn't seem like it was going to pay the bills. A large part of me would've liked to have done. I remember being a research assistant for Professor John Crossley at Monash, helping to write code (in CAM/L, using a Tcl/Tk interface) to try to convert mathematical proofs into computer programs (the idea being that if you can prove – using really fundamental principles – that for all x, there exists a number y that has particular properties, then that proof should be able to be converted 'automatically' into a program which will find that y). I found that fascinating. I don't know whether the theory ever got really proven, but I found academia really interesting.

And of course, in the 'real' world, the uses of academia are somewhat doubted. It was good to see a locknote session at Tech.Ed (AU) this year about some of the image processing stuff that Microsoft Research Labs are working on. But I'm also really curious to know about algorithms for solving interesting problems.


Simple recursive CTE

I like CTEs. Mostly because it lets me have a derived table that I can refer to multiple times. I don't often use the recursive features of it. But when I do, I repeatedly feel amazed at the power available.

Today I had a challenge to produce a nice SQL way of converting integers to binary

So I pulled out the CTE. 🙂

with ctebins as
(select num as num_orig, num as working_level, cast('' as varchar(max)) as binval
from nums_bin
union all
select c.num_orig, c.working_level / 2, cast(c.working_level % 2 as varchar(max)) + c.binval
from ctebins c
where c.working_level > 0
select num_orig, binval
from ctebins
where working_level = 0

What this is doing is to populate the top level of the CTE with a bunch of numbers from nums_bin, along with a blank string. I know I don't have to use varchar(max) – it's not going to get that big after all…

Then it fills the CTE with rows using recursion. I keep the original number (to use later), and keep cutting it in half to get the binary number out. Then I query the full CTE for the last level of recursion – when my working number got down to zero.

It works nicely, and it's very fast on a big set of numbers. 


ActiveSync to a new Exchange Server

This week we had a few hassles with our Exchange Server. I don't know the details, but I know that we moved to a new Exchange Server. From an Outlook perspective, this was fine. From a Windows Mobile perspective, it wasn't so great.

The new Exchange Server is in a different domain, so I had to use a different set of credentials to sync with it. I installed the root certificate, did all the right things to get it working, but got an error saying:

Synchronization failed due to a device software error. Contact your network administrator. 0x80004005

Not good. Did some googling, and saw some stuff about getting an End User Update, and other stuff about a hard reset. I tried searching through the registry for something that might've helped… no luck there either. Luckily, I store all my useful data on an SD card, and have a folder with all my app's install stuff. I did a backup to keep the rest of the data safe, and then did the nasty hard reset.

Ten minutes later, I had successfully synced with the server. Half an hour later, I was fully restored. I'm sure there will be the odd configuration setting I've forgotten to make on some application (like the font size in Egress), but on the whole, I'm very happy. Most of all, because I actually have very little fear of hard resets. I know that whenever I have some error that I just can't solve, I can always fall back to "let's try a hard reset" if I need to.


ACS SA Branch Committee

I've been nominated for the ACS SA Branch Committee. I've been a member of the ACS for a few months now – a Senior Member even. But it hasn't really meant a lot so far. As I want to be an influencer, particularly in regards to promoting IT in Adelaide (it's where I live, and I figure that if I can help develop IT as an industry here, then that's good for both me and anyone else who lives here), I had toyed with the idea of joining the committee. Nominations close this Friday, and after checking with Roslyn about the extra night out per month (my time feels quite limited already, but I think this is worth the investment), I agreed to let myself be nominated.

It doesn't mean I'm on the committee yet though. There may be more people putting their hands up than there are spots available, in which case it will come down to a vote. I'll keep you posted.

Developing presenters with an open mic night

In August I ran a tag-team user-group meeting. The idea was that people within the group would get up and give a really short presentation about something which they thought was cool. I had a few people put their hands up, and I prompted a few more people as well. All in all, the meeting was really good. Numbers were down, but I think this comes down to people not really knowing what to expect (but let's face it, numbers are down when I'm listed as the speaker – I think it's the familiarity thing).

Since then, I've noticed some other groups doing similar things. And some of those people have asked me about the whys, and hows of it.

The Why is easy for me.

Firstly, it lets me know who in the audience is willing to present (and who has a knack for it). More than that though, it tells me who I could potentially help develop as a speaker.

Secondly, it gives me an idea about the things that people are interested in. The section of the evaluation form that says "What should we have presentations on in the future?" is almost always blank.

Thirdly, it saves me having to find a speaker that month. Actually, this is a really big thing. Getting speakers to come to Adelaide can be awkward – we're a bit isolated from the rest of the world.

The How is a bit more complicated. I have a list here, and these are in no particular order.

First, you need to give people a lot of warning. Tell them a good two or three months in advance, and also tell them that you'll be prompting people.

Second, you need to prompt people. You didn't get that from the first point? Hmm… You will get people who just volunteer, but you'll also find that a lot of people won't. So just ask them. Especially those people who you think would do a good job.

Third, It helps to have a prize for the best talk. If nothing else, you'll find that some people really like the prize and want to pursue it. Greed can help. 🙂

Fourth, give people ideas. I don't just list them, but I tell people I have some ideas, and then when I prompt people, if their excuse is that they can't think of anything to speak on, give them a couple of topics to choose from.

Fifth, warn people that you might not get through them – and have these people as the seasoned presenters who really don't need the practice. The newbies will go overtime, almost guaranteed.

Sixth, don't stop those people that go overtime. Be really encouraging to them. Actually, be really encouraging whatever happens.

Seventh, get people's notes in advance and prepare good questions. If someone's struggling, you can turn their talk around with a couple of well-placed questions. This can really help.

Eighth (wow, there's a few), have a bunch of tips yourself that you don't need slides for. You can give these tips while people swap machines – just a way of filling in time between presentations. Keeping it flowing will really help.

Ninth, offer to have an interview-style presentation if you know someone has something
good to say but will be nervous about presenting. For many people, the problem is just standing in front of other people. But if you get them to just have a conversation in front of everyone else, then that could be the break-through they need.

There are more, of course. But I can't think of them right now. I guess that's where 'comments' come in. 🙂 I'd like to hear feedback from anyone else who has run similar meetings, to hear how they went.