Monday, August 10, 2015

David Hasselhoff Screensaver

It's good sense to lock your computer when you're away. My co-workers have a habit of punishing those who don't by changing their desktop background to a picture of David Hasselhoff (usually the one where he's naked holding a puppy), a practice known as "Hoffing". I decided to go one further and create a screensaver that displays mister Hasselhoff in all his glory.

This is the result. Extract the file on your victim's computer, right-click the .scr file and choose "Install". And here is the source code in case you're worried about malicious code (or just want to see how it works). I leaned heavily on the code from Frank McCown at

Update 2015-09-17 - I found that the previous version was crashing when trying to move the image. I've uploaded new versions of the .scr and source code (same links) to resolve the issue.

Sunday, September 14, 2014

Star Wars: Commander

I've Meanwhile, the non-optional PvP element is basically just stealing the hard-earned resources of other players. he real goal of these games though is to get you to buy whatever points they're selling in order to speed things up. This goal results in gameplay that just isn't fun.

Don't get me wrong, they're totally addicting. That's the whole point. Each stage opens up a new thing that makes you a little bit more powerful so you keep thinking "now I can do This", but each stage of the game takes longer and longer and ultimately, nothing really changes. You're still do the same thing over and over again. It's addicting, but I get no joy in the experience. It's just hard to stop.

Meanwhile, the non-optional PvP element is basically just stealing the hard-earned resources of other players. You log into the game to find another player has stolen resources it took you hours or even days to gather. Sure, you can attack them back, but them you lose the temporary protection obtained by having your base destroyed. And what's the point? Now they've lost time and resources.

This experience could be totally turned around by adding some additional strategy or RTS elements. As is, your attack units are completely mindless. After dropping them on the battlefield, you have no control over their behavior. They'll attack random (and strategically worthless) walls while being fired upon (and destroyed) by enemy units. Your defenses seem woefully underpowered (at least that's my experience) at repelling invading players. A single enemy unit was capable of taking down both shield generators and three turrets before being reinforced by the rest of the army for wiping out the rest of the base.

OK, rant over. And so is my time with this game.

Monday, September 8, 2014

Dynamically Changing the Color of SVG Using an ASP.NET HttpHandler

I have an SVG file that I'm using as the background image of elements on the page (using sprites). I wanted to dynamically update the color of the shapes and paths when theming the application, but I could not find a way to do this using CSS when the SVG is loaded as a background image (I have heard that inline <svg> elements will inherit style rules).

The way I solved the issue was to use a custom HttpHandler in my ASP.NET application that allows me to replace parts of the SVG with other content. Here's the code I used:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;

namespace MyNamespace
 public class DynamicSVGHandler : IHttpHandler
  public bool IsReusable
    return true;

  public void ProcessRequest( HttpContext context )
   var request = context.Request;
   var response = context.Response;

   var file = context.Server.MapPath( Path.ChangeExtension( request.Url.LocalPath, ".svg" ) );

   if( File.Exists( file ) )
    var lastWrite = File.GetLastWriteTimeUtc( file );
    response.ContentType = "image/svg+xml";
    response.Cache.SetExpires( DateTime.Now.AddMinutes( 5d ) );
    response.Cache.SetCacheability( HttpCacheability.Public );

    List<KeyValuePair<string, string>> replacements = new List<KeyValuePair<string, string>>();

    string value;

    foreach( string key in request.QueryString )
     if( key.Length > 3 && !string.IsNullOrEmpty( value = request.QueryString[key] ) && value.Length > 3 )//Implement any custom validation here.
      replacements.Add( new List<KeyValuePair<string, string>>( key, value ) );

    if( replacements.Count > 0 )
     string line;
     using( StreamReader reader = new StreamReader( File.OpenRead( file ) ) )
      while( (line = reader.ReadLine()) != null )
       foreach( var replacement in replacements )
        line = line.Replace( replacement.Key, replacement.Value );

       response.Output.WriteLine( line );
     response.WriteFile( file );
    response.StatusCode = 404;

Make sure to register your handler in your web.config (This example is for IIS 7+, integrated mode and I used the extension .dsvg):

   <add name="*.dsvg" path="*.dsvg" preCondition="integratedMode" verb="*" type="MyNamespace.DynamicSVGHandler, MyAssembly"/>

You can now reference any svg file in your application with the extension .dsvg instead of .svg and specify replacements in the URL (e.g. mysvg.dsvg?white=red to change "white" to "red").

In my SVG, I found it easiest to define the color using a style section rather than setting the fill of each shape, then add the class="svg-shape" to all the shapes.

Thursday, March 13, 2014

Changing the Color of Table and Column Names in SQL Server Management Studio 2012

If you've upgraded to SQL Server 2012 and used the new Management Studio, you've probably noticed that your table and column names are now a teal color that looks exactly like the color of your comments. Previous versions of Management Studio would use the color specified for "Plain Text", but the new version uses a new setting.

To change the color, open the Tools menu and choose Options.... In the Environment settings click Fonts and Colors. Locate and click "Identifier" in the Display Items list box then change the Item foreground to something other than Default. That should do the trick.

Monday, February 24, 2014

How to Restore Files from a Restore Point

In my last post, I mentioned how I had used Windows System Restore, only to find out that JavaScript (*.js) files are considered to be "system files" and are restored back to the state they existed when the restore point was created. I tried restoring back to the previous state, but no-go. System Restore failed with every other restore point.

I thought all was lost, until I found this article by the How-to Geek that has a batch file letting you mount the latest VSS (Volume Shadow Copy) volume and view the files contained there-in (when you create a Restore Point, Windows creates a VSS volume containing your files at that point in time). I didn't want the most recent volume, but I looked at the batch file and figured out how to list the available volumes and mount the one I wanted. I figured I'd document the steps in case this helps anyone else.

  1. First off, you need to open a command prompt as an administrator (Right-click the "Command Prompt" and choose "Run as Administrator").
  2. At the prompt, type
    VSSAdmin List Shadows
    This will list the available VSS volumes on your system. This can be confusing, but each one displays a creation time. What you're looking for is the the "Shadow Copy Volume" (e.g. \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1).
  3. Once you find out the name of the shadow copy volumne, you can mount the volume using MKLINK just as you would any other folder (if you haven't used MKLINK, I'd recommend you check it out - it's a pretty useful tool). For example:
    MKLINK /D C:\ShadowBackup \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1
    In this example, you'll see a new folder named ShadowBackup on your C: drive, containing the contents of the VSS volume.

Now you can view the contents of the VSS volume and view/copy any of the files within. This can also be useful if you accidentally delete a file or want to see what changes you've made.

To "unmount" the volume, you can simply delete the folder in Windows Explorer. This won't delete the volume, just the link to view the files.

Warning: System Restore will Modify/Delete JavaScript Files!

I discovered too late that Windows System Restore considers JavaScript (*.js) files to be system files. Apparently, the way System Restore works is it uses the Volume Shadow Copy service to back up your files, then during the restore process, it restores "system" files to their state at the time the restore point was created.

As a developer, this is bad for me, since I regularly create and edit JS files. After restoring my system, I opened up my code and found, to my surprise that all my JS changes had been reverted. If this happens to you, in my next post, I'll detail how I managed to restore the files.

Tuesday, January 14, 2014

Munchkin Rules Removed by Request.

The page of Munchkin rules has been removed by request. No hard feelings on this end.