

Google Friend Connect
Friday December 5, 2008
I installed Google Friend Connect for my site, which took 10 minutes, and spent another few hours or so thinking up some creative ways of displaying it on the site. It problem is that its minimum width is 200 pixels, but my right navigation bar on my blog is 160 pixels. So I tried to float it and have some animations for it to pop out onmouseover, and blahblah, those didn't go so well, so I settled for the immediate effect and that works quite well. What's surprising is that I didn't have to tweak it for IE at all.
Anyway, in the past week, I've been to Momo's three times, been busy at work doing menu and UI coding, played a pretty good amount of DotA and generally slacked off with that secret website that I am working on.
There's two more weeks until I leave for Auckland. It's going to be an awesome Christmas time \o/
Shameful
Monday December 1, 2008
As shameful as it is, I spent a while trying to help Mike with his C++ programs, attempting to read a particular format of characters from stdin.
The problem is that if this program is fed character data, it loops continuously:
bool valid = false;
int num;
while (!valid)
{
int num_reads = scanf("%02d", &num);
if (num_reads == 1)
{
valid = true;
}
}
Why? num_reads is 0 and upon reaching scanf for the second time, the buffer is still attempting to read something, but it can't and returns 0.. and so on and so forth.
So what's the solution? Simple. Use sscanf!
int num;
char buffer[1024];
bool valid = false;
while (!valid)
{
std::cin >> buffer;
int num_reads = sscanf(buffer,"%d",&num);
if (num_reads == 1)
{
valid = true;
}
}
November News
Sunday November 23, 2008
Okay I haven't died yet, it's just been pretty boring on the news front for the blog.
Let's see, I've spent the last two weeks practically home alone: two flatmates in the South Island, one in Australia for a week, means one Jeremy at home cooking delicious food for himself, and playing absurd amounts of DotA. Not that either of these things are bad. I brought DotA to work on my iPod in the hope I could attract some interest and get my workmates to play as well.
I had a flatwarming for three of my workmates last night too. They live about 20 minutes up the road from me, so maybe I'll see them on the bus or walking home or something. But it was a pretty cool party, got to hang out with people and socialise and stuff. Woo~. Got caught by the rain as I went home, but luckily the bus was on time and I managed to minimise the wetness.
I've been doing a lot of web development lately. I fixed some spam bot problem with my Shoutbox a few minutes ago, and I thought I'd blog about something that's been infuriating me for the past few weeks.
The majority of the world have this program installed on their machines and actively use this malicious application. I do not know the exact numbers, but whatever the statistics are, it is far too much for people to being using such filth every day.
I am, of course, talking about Internet Explorer.
Who the hell at Microsoft decided to make a substandard browser with so many security flaws and a blatant disregard for web coding standards just to piss developers off? Morons. Absolute bloody morons.
In this site I've been working on (You know the one, Stephen :O), I have this search box that appears onmouseover, and it disappears when you click outside the box, but should remain visible when clicking inside the box. The easiest way to implement this was to cancel the bubbling effect that events have, that is, clicking inside a table will trigger its onclick, its parents onclick and continue up the chain until there are no more onclick handlers.
So, if the table onclick is specified and the event.returnValue parameter is set to false, I can use this value to prevent subsequent calls to the onclick handler. Thus, when it gets to the body onclick, inside the handler, I just return prematurely if event.returnValue is false.
Yup, that's all great. Works wonderfully on Firefox. This behaviour also works on Internet Explorer too...oh, wait. Hold on a second. By specifying that the event's returnValue is now false in Internet Explorer, all onclick handlers no longer work. That means onclicks for anchor tags and submit buttons. What kind of stupid system is that?
I resorted to using the following code:
<script type="text/javascript">
var eventHandled = new Array();
function myFunction(event) {
if (eventHandled[event.type])
return;
eventHandled[event.type] = true;
}
</script>
<body onclick="myFunction(event); eventStates = new Array();">
<table onclick="myFunction(event);">
<tr>
<td>No Click</td>
<td><div onclick="myFunction(event);">Click</div></td>
</tr>
</table>
Clicking on the innermost <div> with "Click" calls myFunction. myFunction sets eventHandled["onclick"] to be true, and prevents bubbling up by halting execution of the onclick in the <table> and <body> tags. Finally at the <body> tag, the states are reset to ensure that the next onclick can be processed. Phew!
Stupid Internet Explorer.
(PS: I should look at getting some syntax highlighting...)
The Air of Change
Saturday November 8, 2008
As history unfolded three days ago as America watched its first African-American President be elected, so too the winds of change have swept over New Zealand as John Key, leader of the National Party, becomes our Prime Minister-elect. Gracious in defeat was Helen Clark, who highlighted the good nine years of Labour government, and announced her resignation as leader.
But I must say.
The changes don't stop there. We are watching the face of New Zealand politics change like never before, as New Zealand First fail to meet the 5% party vote threshold, and both Winston Peters and Ron Mark fail to win their electorate seats, sealing the fate of the party as it no longer has any seats in Parliament.
I can say only one thing.


