Coding

This is where I keep my snippets

  • C# Set CommandTimeout manually when using auto-generated typed datasets

    I couldn’t find a way to increase the default command timeout quickly without having to do something complicated so I had to open up my .Designer.cs file (maintained by Visual Studio IDE), find the Fill method I was looking for and look for this line: this.Adapter.SelectCommand = this.CommandCollection[0]; Then I manually set my command timeout

    read more

  • WordPress Google Cache poisoning

    If you see garbage showing up in your sites google cache, you might want to have a look at your wp-includes/general-template.php file. Specifically the section that contains this line: if(!(strpos($sUserAgent, ‘google’) === false)) It should probably not be there, and will have been deposited there without your knowledge. Remove it and wait for your site

    read more

  • C# create a new GUID

    If you need a new GUID (not in code) and have MS Windows SDK installed, you can type this in the cmd prompt: uuidgen which will give you something like this: C:\>uuidgen ff9ddb07-bf8e-4f90-9475-8715c061231c If you need to do this at runtime in .Net, see System.Guid. System.Guid guid=System.Guid.NewGuid(); Console.WriteLine(guid.ToString);

    read more

  • Gacutil location in Windows Vista

    Weird, the Vista UAC prevents you from running gacutil, and on my machine this location was not PATHed. Figures. You’d have to fire up a CMD window (as Administrator) and find gacutil here: C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

    read more

  • C# Timers

    There are three kinds of timers in .Net but it’s not always obvious when to use which one.  Here’s some sample code of each, and then later on a table from the MSDN website that summarizes the differences. // Runs on the UI thread // Will not raise events if UI is unable to process

    read more

  • C# Suspend and Wakeup

    If you need to suspend a device running on battery power programmatically and wake it back up SO THAT THE MONITOR TURNS ON you need to use the basic Suspend if the device AND the SetThreadExecutionState function. If you don’t, the device will assume there is no user activity and since no thread has signalled

    read more

  • C# Using XMLParserContext to parse XML fragments

    This is useful if you don’t want all the file IO overhead if you are using XML as a protocol:

    read more