eggfriedrice.com

And your bird can sing

July 25th, 2007

Well, she can if she can remember the lyrics to the song on TMF she’s singing over. Apparently Madonna sang about level crossings.

The big giant tidy up is complete! Just in time really as my Mum’s coming to stay for a couple of nights. If we don’t pass inspection after five days of solid cleaning I’m going to quite miffed. Now we’re just hoping it doesn’t piss down quite so much as it did last time she was here, we nearly drowned.

I don’t really have much to say but the threat of a fine is looming large so here’s a couple of things from the internet that amused me recently:
xkcd Goto
(You might need to be a bit geeky to get it but trust me, it’s hilarious)

YouTube comment of the day (Mika – you’re on a winner with comments like this):
“i think this video is good becoz i jst went to devon wid skool and we woz all singin it on da minibus”

Righto, that’s it. See you tomorrow, assuming I can get past security at the airport and get in and out…

Programming and the art of recycling

July 16th, 2007

I like recycling. It’s a pain in the arse but it gives you that nice warm saving-the-plant fuzzy feeling every time you crush a coke can and put it in the bag. Even this website is made from 100% recycled, post consumer, electrons. I grow my free range blog posts in a managed environment and they’re fully compostable (the best use for them really).

My favourite kind of recycling, though, is the code type. Tonight I reused some javascript that I wrote earlier in the year for something else entirely, it worked great for its new use and saved about an hour of faffing around. Some of the code I’m still using I originally wrote years ago. I have no idea how some of it actually works any more, I haven’t read through it properly for ages, but it still works. Some of it I should probably update but while it still works, why poke about?

I have two rules of programming:

  1. Don’t remember any details you don’t need to, just know where to find them
  2. Write stuff that works and then reuse it until you’re blue in the face

Very simple stuff, but it’s surprising how far a bit of cut and paste and a few books can take you.

Now I’m off to stack the dishwasher so we can reuse more stuff tomorrow!

A Kind of Magic

June 1st, 2007

Whoever thought Magic Quotes in PHP was a great idea should be banned from using a computer ever again.

I’ve only just started using PHP properly (enough to fall in love with Smarty, more later) and this slashes appearing in all my strings thing has been bugging me. I’m used to running strings through an escape function before shoving it into a database because that’s what we do. Having all get/post strings escaped is JUST ANNOYING AND STUPID. And you can’t just disable the ini setting in the PHP code because by the time it’s running your code it has already bastardised your data. Luckily though, you can disable it in a .htaccess really simply:

php_flag magic_quotes_gpc off

And now sensibility reigns supreme once again and all is well in the world of code.

Apparently Magic Quotes will be disabled by default in PHP 6, in the meantime I might suggest they rename them Moron Quotes.

<rant>
Talking of morons, Virgin Media is sucking badly at the moment, I can only reach my own blog by using an SSH tunnel into a box in Sussex and then out again. I can’t reach blogspot, some other Google sites, Youtube AND WORST OF ALL, I haven’t been able to read UserFriendly for THREE DAYS. In all seriousness, having called Virgin Mediocre/Telewest and spoken to four different phone monkeys who wouldn’t know an ethernet cable from a cheese sandwhich I can only assume that the system normally works because they’re not allowed to touch it.

Highlight was when I was telling monkey three about how traceroute was showing packet loss after a particular hop clearly labelled blueyonder he started to tell me how to disable pop up blocking in Internet Exploder. Upon being informed that I’m using Firefox he suggested I call the makers of Firefox to ask them for help. Excuse me while I open a new bug on bugzilla…

Apparently this issue is due to be fixed tomorrow. The Virgin Mediocre help page shows the estimated fix time as being seven hours ago, so it’s going really well.

Virgin Mediocre: fairly cheap, fairly fast, run by morons, fine for home use, not to be used anywhere near a business environment.
</rant>

In other news: I’ve done my exams, just need to go into college once more on Tuesday to tick some boxes and then that’s me educated! I need to work my arse off this weekend to finish off a website in time for it’s launch on Monday and then I can have a couple of days off. Which is good because I’m itching to solder anything to something else…

When is long not long?

February 4th, 2007

When it’s exactly the same length as something shorter!

For my Higher Computing C Programming assessment I’ve had to write a simple program, part of which calculates the file size of a video by multiplying the height, width, colour depth, number of frames per second and length. Simple? I thought so.

I’ve done a bit of C programming, but mostly for 8 bit microcontrollers, I’m used to thinking in terms of unsigned chars and this is my downfall here.

Using one of the example tests for the program gives a sum like this 270 * 340 * 16 * 25 * 189 = 6,940,080,000. That’s too big for an int. Luckily C has datatypes for bigger numbers, like “long” and “long long” (for even longer things). Great! So all I need to do is swap to longs or long longs and then it’ll work! Except this is stepping into a bit of a minefield.

It turns out that a long is exactly the same length as an int on 32 bit computers (like most of mine). On my Linux and Windows boxes an int is 32 bits long. So, a long long it is then! That’s 64 bits everywhere I’ve looked. Only as it’s quite uncommon I found it tricky to work out what to use at the format specifier. This is mostly because long longs seem to be a GCC addition to the C language, not part of the spec. That’s fine because I’m using GCC on Linux to develop this program and at college we’re using Bloodshed Dev-C++ under Windows XP.

Dev-C++ is a nice, lightweight and open source IDE for C and C++. I was quite impressed with Telford College for choosing something open source for their Windows boxes (I’m adding more OS software by running Firefox at Telford using the portableapps version from the student network share).

Anyway, back to the problem. %lld is the GCC printf specifier for a long long, nice and easy to remember, ll == long long. And luckily Dev-C++ uses the MinGW version of GCC so I can port my code straight over. Ha! No such luck. It turns out (I discovered after some really handy exchanges on the Edlug mailing list) that the MinGW GCC implementation of printf is actually made to use the Microsoft long long print specifier with is %I64d. Catchy. Unless you use %I64 you experience some sort of weird miscounting thing and printf prints out garbage. This page explains it.

So after all the faffing around and general irritation of this half hour job taking three days I finally have it working. Along the way I discovered that for a language that’s been around for a million years C isn’t all that well defined. Also, I found that the datatypes vary. I knew this was the case anyway but I didn’t realise how weirdly they vary.

I’ve complied and run this code on a few different computers here:

#include

int main(){
printf(" TYPE BYTES BITS\n");
printf(" char: %d %3d\n", sizeof(char), sizeof(char)*8);
printf(" short: %d %3d\n", sizeof(short), sizeof(short)*8);
printf(" int: %d %3d\n", sizeof(int), sizeof(int)*8);
printf(" long: %d %3d\n", sizeof(long), sizeof(long)*8);
printf("long long: %d %3d\n", sizeof(long long), sizeof(long long)*8);

return 0;
}

I expected the length of an int to be 32 bits on a 32 bit system and 64 bits on a 64bit system. Strangely it seems to be 32 bits everywhere but the long is 32 bits on a 32 bit system and 64 bits on a 64 bit system. That’s enough, I’m past caring, it’s all too weird! I’m almost beginning to wish they’d chosen to teach Java this year and that’s a really bad sign!

Apologies to the non-geeks who might read this entry but well done for getting this far! Apologies to the geeks who read this entry, but well done for getting this far without posting a comment pointing out a cockup or inaccuracy, you can post it now!