For the countless hours that I spend sitting in front of a computer, I'm always amazed at how little I know about/remember how to use it. Here's my attempt at cataloging the useful tricks I'm sometimes forced to find.
Checking for overflow in C#
June 13, 2006
If you ever need to check for numerical over/under flow in C#, there's two ways to do it:
Nixing that blasted reboot reminder
June 14, 2007
Ever install auto updates, only to find that every ten minutes XP asks you if you you want to reboot your computer? Of course, "no" isn't a choice...the closest is "later", which is cleverly defined as "10 min" and feels like about "10 sec" when you're working on something. Fortunately, there's a nifty workaround. Here's what you do:
Start / Run / gpedit.msc / Local Computer Policy / Computer Configuration / Administrative Templates / Windows Components / Windows Update / Re-prompt for restart with scheduled installations. Counterintuitively, you click "enable" then specify the number of minutes. "disable" will make it default to 10 min.Leon goes on to point out that the following command will make it so you don't have to reboot for the changes to take effect:
>gpupdate.exe /force
Unfortunately, when I run it, I still have to logoff and backon. Sigh. At least next time it will work.
Fast Variance
June 13, 2007
I can never find a link telling me how to calculate variance/standard deviation in a single pass. It's not hard to work out, but then I always have to check myself. Here it is:
Var = [ss - (sum*sum/n)] / (n-1)
Where ss = sum of squares, and n is the sample size. Here's the derivation (note Sum is the summation operator, ss is Sum[x*x] and sum is Sum[x].
var = (1/n) Sum[(x - mean)^2]= (1/n) Sum[x*x - 2*x*mean + mean*mean]
= (1/n) [ss - 2*mean*sum + Sum[mean*mean]]
= (1/n) [ss - 2*(sum/n)*sum + mean*mean*n]
= (1/n) [ss - 2*sum*sum/n + sum*sum/n]
= (1/n) [ss - sum*sum/n]
And of course replace (1/n) with (1/(n-1)) for the unbiased variance.