Wednesday 31 October 2007

Ignorance

For the past 3 years or so, I have been ignorant of something that I can do in C#. That is, use the a ?? b operator. This doesn't exist in C++ or C, but it is nice if you don't know about it. What is return a if it is not null, otherwise it returns b. Therefore, what was previously

return var == null ? default : var;

can now be written as

return var ?? default;

Which is nice and small. They both could also be written as

if(var == null) return default; return var;

or more verbosely as

if(var == null) {
  return default;
}
return var;

Of course, I should have discovered this 3 years ago, but I didn't, oops. Never mind, that's why, I suppose I should look at open source code, because then I would see things I didn't know about and be forced to learn them, instead of just stumbling across them. Well, I'd still be stumbling across them, just a lot faster than I am now.

Tuesday 30 October 2007

Antivirus, VS2008

Today I have just installed Visual Studio 2008 v9 Beta 2. The first two times I tried installing it it didn't work. Then I realised it was probably not installing because of the new antivirus product I had just switched to, called Comodo Antivirus, so aptly named because it was made by Comodo. Anyway, I just temporarily disabled the "On Access Scanner", and the "HIPS Application Control" and then it installed fine.

I haven't yet played around much with VS8, having just installed it, but I have had a bit of a look at the Comodo antivirus product, and it looks very nice. The user interface for the most part is quite pretty, except for a few things that go away after an initial safe-list making scan. It also asks me if I should allow a programme to run, every time I start one, so it's quite paranoid, which is good. An antivirus product should be paranoid, and so should all computer users.

Anyway, there is a cute software project I made a while back, a few years now, but due to backup incompetence I have lost the original source (as well as the compiled examples). Never mind, I will be making it soon enough. Basically it is a hierarchical view control that behaves like a treeview control, and looks like a family tree. Anyway, the original implementation I made was quite neat. There was also I nice side tab control I made once, which has also disappeared of the face of the Earth.

Thinking down that path, there is also a little photography programme I made, which basically loads in a list of students from a school database, and then divides everything into classes, and allows the names to be added into a caption underneath it. The names are dynamic, and the list of students could be printed as barcodes and scanned in. This is useful, because it means for the most part that the students names are spelt properly (as long as they are in the school database). But now I have to make that again as well. Never mind.

Thursday 10 May 2007

The Mythical 1.44MB floppy

Well, the days of 3 1/2" floppies have long since passed (for most of us), although I'm sure 5 1/4" floppies are still being used... somewhere. Anyway, now is as good a time as any to explain why 1.44MB floppies never have been that size, and never can be.

To start off, a 1.44MB floppy has a capacity of exactly 1,474,560B. Wait a minute! Isn't that 1.47MB? Well, yes, if you use SI units (1 megabyte = 10^6 bytes). Isn't that 1.41MB? Think those of you to whom a megabyte is 2^20 bytes. But hey! Under neither definition of a MB does the 3 1/2" floppy fit!

Why?

Whoever called it the 1.44MB floppy decided that a kB was 1024 bytes, while a MB was 1000kB (1,024,000 Bytes). Multiply by 1.44, and behold! 1,474,560 bytes.

Isn't that crazy?

Monday 7 May 2007

Timezone Information on Windows

I was trying to find out how to grab the current timezone settings from the Windows registry, so I searched on the Internet, and eventually found where it was stored

(HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation)

, but most sites that showed the data structure were wrong. Only with one thing, that was which 16 bit integer represented the day of the week. Most sites said it was the 3rd Integer, but actually, it is the 8th (or last) Integer in the keys "StandardStart" and "DaylightStart". Eventually I found a site that said the right thing, so I'm going to list it here anyway.

 

Path: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation
Keys: StandardStart and DaylightStart
All integers are two byte big endian
Integer IndexRepresents
0Year: 0 = 1900
1Month: 1 = January ... 12 = December
2Week: 1 = First week ... 5 = Last Week
3Hour: 0 = Midnight, 23 = 11pm
4Minute: 0 - 59
5Second: 0 - 59
6Millisecond: 0 - 999
7Day of week: 0 = Sunday ... 6 = Saturday

 

So, there you have it.