09
Feb 13

pandora-tray

I keep telling myself that I’ll get around to releasing some of the little applications and utilities that I write, but never actually followed through.

Until now.

Meet ‘pandora-tray‘, a sweet and simple Windows application that sits in your system tray, and allows you to use your keyboard’s fancy multimedia keys to control playback through Pandora’s ‘PandoraOne’ desktop application.  It was mostly an application born out of my own laziness, but it was also an opportunity to play around with pinvokes and see how easy it is to write a system tray application.

Feel free to go download it and let me know how it works for you, or doesn’t work if that’s the case.


30
Apr 12

wcf rest interface with proper validation status code

I’ve been working on a self-hosted WCF REST service that supports HTTP authentication. I worked my way through all the fun bits, but near the end I ran into an issue with WCF’s handling of SecurityTokenExceptions in my custom UserNamePasswordValidatior. Instead of returning the expected 401 Unauthorized response code, I ended up with a 403 Forbidden response. Not all at what I wanted, nor within HTTP spec.

After searching around, and around, it turns out this was a known issue that Microsoft decided to hotfix with an interesting workaround. To fix the problem, all I needed to do was add an item to the exception I was throwing’s data dictionary, indicating what HTTP response code I really wanted it to return.


public override void Validate(string userName, string password)
{
 if (string.IsNullOrEmpty(userName) | string.IsNullOrEmpty(password))
 throw new ArgumentNullException();

if (string.Compare(userName, "testuser1") != 0 || string.Compare(password, "testpassword1") != 0)
 {
 SecurityTokenException ex = new SecurityTokenException();
 ex.Data["HttpStatusCode"] = HttpStatusCode.Unauthorized;
 throw ex;
 }
 else
 {
 SecurityTokenException ex = new SecurityTokenException();
 ex.Data["HttpStatusCode"] = HttpStatusCode.Unauthorized;
 throw ex;
 }
}

Not the most elegant solution in the world, but it at least gets the job done.


18
Apr 12

on coding

There’s been a minor flurry of activity on the interwebs about coding, specifically about reading code.  Jeff Atwood made a off-hand comment that set some people a-buzz:

“The idea that you’d settle down in a deep leather chair with your smoking jacket and a snifter of brandy for a fine evening of reading through someone else’s code is absurd.”
Jeff Atwood

And we had Scott Hanselman retort with:

“Absurd? Hardly. Nearly every programmer I’ve ever spoken to enjoys reading and discovering new code.”
Scott Hanselman

Jeff’s comment was taken a bit out of context since his post was in fact proclaiming the virtues of “reading the source”, but I can’t help but side with Mr. Hanselman.  You really have to be able to read to write, and if you’re going to do it well you have to want to.  That doesn’t mean that you can’t get away with living in isolation, but you’ll suffer the consequences accordingly.  People grow in response to external stimuli, which means you need to get out there and expose yourself to as much of your intended subject material as possible.  So cruise through SourceForge, Github, CodeProject, and all the rest, it’s the biggest benefit of the open source movement and there’s absolutely no reason not to take advantage of it.

If I had to sum up my own personal take on code slinging, it’s essentially the same as my view on more traditional writing which I think Stephen King put it best in his book On Writing:

“If you don’t have time to read, you don’t have the time (or the tools) to write. Simple as that.”
– Stephen King


13
Apr 12

mbunit dynamic and static test factories

I’ve been a big MbUnit fan for a while now, even going so far as to leverage it as the test framework for a lot of the automated integration tests that I write. So when I started re-writing a suite of automated tests, I reached into my toolbelt and pulled out MbUnit.

What I wanted to do was consume some XML, that defined what my test suite and tests cases, and use that drive my tests through MbUnit. So I started hunting around and came accross the built support for external data sources but it didn’t really look that appealing to me. The data I was trying to consume was XML, but I didn’t want to have to deal with XPath, so I kept digging.

Then I came across a blog entry from way back in 2008 announcing a new build of MbUnit that introduced Static and Dynamic Test Factories (also known in a previous life as Test Suites). I took one look and realized that it was exactly what I needed. All I had to do was write a single method that returned an IEnumerable collection of Test objects. Those test objects can be TestCases or TestSuites, so I could build an entire set of data driven tests in one fell swoop.

All I needed to do next was decided on a dynamic or static test factory. The biggest difference is that the tests are explored at run-time for a dynamic test factory and at load-time for a static test factory.

This means that with a static test factory the tests are all generated and displayed individually in the UI (Gallio) and can be selected to run individually (if so desired). With the dynamic test factory is displayed as a single test method and all tests have to be run at once, but it also supports parameterized input where the static test factory doesn’t.

Here’s a simple example that calls into a method to get a list of the text files in a given path and for each file validates that it contains words (not a grandiose test I know but it’ll suffice).


/// <summary>
/// Example test method for creating dynamic MBUnit tests
/// </summary>
/// <returns></returns>
[DynamicTestFactory]
public IEnumerable<Test> ExampleDynamicTests()
{
 TestSuite testSuite = new TestSuite("Dynamic Tests");
 foreach (string testfile in GetFileNames())
 {
 TestSuite ts = new TestSuite(string.Format("Testdata: {0}", Path.GetFileName(testfile)));
 string testdata = File.ReadAllText(testfile);
 ts.Children.Add(TestWordCount(testdata));
 testSuite.Children.Add(ts);
 }
 return new List<Test>() { testSuite };
}

/// <summary>
/// Example test method for creating static MBUnit tests
/// </summary>
/// <returns></returns>
[StaticTestFactory]
public static IEnumerable<Test> ExampleStaticTests()
{
 TestSuite testSuite = new TestSuite("Static Tests");
 foreach (string testfile in GetFileNames())
 {
 TestSuite ts = new TestSuite(string.Format("Testdata: {0}", Path.GetFileName(testfile)));
 string testdata = File.ReadAllText(testfile);
 ts.Children.Add(TestWordCount(testdata));
 testSuite.Children.Add(ts);
 }
 return new List<Test>() { testSuite };
}

/// <summary>
/// Tests the word count.
/// </summary>
/// <param name="testdata">The testdata.</param>
/// <returns></returns>
private static TestCase TestWordCount(string testdata)
{
 return new TestCase("Test Word Count", () => Assert.IsTrue(testdata.Split(' ').Length > 0));
}

The code inside each factory is identical, but the end result in the UI is different as seen here:

Gallio Screenshot

The end result will be the same number of tests run, with essentially the same test report created. I ended up going with the static test factory for the added UI benefit of being able to run tests individually.

So there we go, yet another reason to use MbUnit for all your testing needs.


28
Mar 12

customizing my desktop

It’s been quite a while since I went about customizing my desktop, but after seeing my wife’s results after integrating an OSX-style dock in Windows I decided to give it a whirl. When I started poking around I was blown away with the tools, widgets, gadgets and docks available for Windows now, and jumped in headfirst.

I started out with XWindowsDock, which I really liked, but it didn’t seem to have active development going on anymore which is a shame because the project seemed fairly promising.  I ended up going with RocketDock instead, which runs like a champ aside from one annoying bug with minimized windows.  Some applications don’t respect the “Minimize Windows to the Dock” setting and still end up in my taskbar which I have hidden away.  I hunted around it  apparently only affects Windows 7, so here’s to hoping that one’ll get fixed.

After that it was just a matter of searching through all the awesome icons and skins on DeviantArt and picking the ones that appealed the most to me.  Big kudos out to leechiahan for his awesome icon set.

Here’s what it looks like now, all put together:

And all the nitty-gritty details:

Dock

Desktop Widgets

Background


26
Mar 12

fun with baretail

I’m having to read and monitor log files a lot more than I used to, and really needed a utility like tail (but on windows).  After hunting around for a while I settled on BareTail because it seemed dead simple to use.  The only problem I had was the lack of explorer level integration, I really wanted to be able to right-click and immediately start watching the log file.

I poked around a bit and it turns out that it’s actually not that hard, with a bit of registry-fu, to add context menu commands to Windows Explorer:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\BareTail...]

[HKEY_CLASSES_ROOT\*\shell\BareTail...\command]
@="C:\\Tools\\baretail\\baretail.exe \"%L\""

Save that as a ‘.reg’ file (change the path to where you have baretail installed), import, and BAM, context menu goodness.


24
Mar 12

it’s all about me

At some point in the past I had the brilliant idea of registering a domain name and starting up a blog about my misadventures on the interwebs. I made a valiant attempt at it but like many of my other projects, or so my wife says, it fell victim to fatal neglect. So just the other day I browsed over to my domain and noticed the poor thing in all it’s splendor (and by splendor I mean PHP errors spewing everywhere) and decided that after 4.5 years it’s about time to start again.

I decided color was so 2007 and went with as minimalistic of a theme that I could; so here it is, new and minty fresh, the new old blog.