vaulter vaulter

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.

Coding

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:

  • Make all integer operations checked. Do this with the compile flag /checked: Go to project properties/build. Hit "advanced" button in lower right. Select "check for arithmetic overflow/underflow". A great debugging tool, but will slow your code down a bit.
  • Use a checked block of code. Just be aware that normal scoping rules apply (ie, if you call a method in the checked block, the arithmetic calculations in that method obviously won't be checked.

Top

Windows

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.

Top

Math

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.

Top