I spent a good chunk of the last few months of 2009 completely immersed in Haml, and having spent time using both ERb and the templating language that ships with ASP.NET MVC, I have no intentions of ever turning back.  That being said, Sass seems like the next logical choice for cleaning up my html/css, and while I was a bit confused as to the point of Compass (other than being a Sass compiler – which I already get for free through the Haml gem), Chris Eppstein finally gives up the goods about 15 or 16 minutes into his Compass screencast (the first 15 minutes are great too, but if you already have a grasp on Sass, they’re a bit redundant).

Long story short: I’m tired of sucking at CSS, and short of completely immersing myself in the spec, learning the idiosyncrasies of which browser supports which feature, and then somehow retaining all of that information, Compass with Sass seems very appealing.

Related Technologies: Blueprint, YUI


While I’m still not quite a ninja in Test::Unit, I finally feel at least proficient in it, and though I’d like nothing more than to proclaim my love for Shoulda from the highest peak of the highest mountains, I feel that I at least owe it to myself to check out RSpec before I consider the book closed on testing frameworks in Rails.

Related Technologies: Cucumber, Factory Girl, Mocha


I spent the first three or so years of my professional life completely immersed in the .NET world (ignoring that first year spent looking at COBOL mainframe code), and in that world, CruiseControl .NET is king of the continuous integration castle.  So, when I came into the Rails fold, I naturally turned to cruisecontrol.rb for my continuous integration needs.  Unfortunately, either I haven’t yet fully grasped the extensibility of cruisecontrol.rb or the community simply hasn’t yet matured to the level of CC.NET, but I am so far underwhelmed by the Ruby version of this popular continuous integration solution.  Luckily, while first learning Rails, my initial confusion over cruisecontrol.rb led me to stackoverflow where someone suggested checking out Hudson … six months later, I think I just might give it a try.


Runners Up

GitGit is an incredibly popular SCM solution in the Rails world, so I will eventually need to learn it.  For now, I think I’ll wait and hope that the tooling matures a bit more.

E-TextEditor – If it weren’t for the need to drop down into Cygwin to run rails apps, this would have been a no brainer.  Unfortunately for e, Netbeans still has a much, much shallower learning curve.  Unfortunately for Netbeans, it can be very, very slow, so e is something else that I will eventually need to learn.


Additional Resources

This list is still (by far) the best resource I have found for identifying new technology avenues to pursue.

Comments 6 Comments »

If you happen to live in the Baltimore/DC area and develop software, are interested in software, or read a lot about software, feel free to join on Sunday, July 12th at la Madeleine in Columbia, Maryland for the next Baltimore Software Book Club Meetup.

Even if you’re not an avid book reader, the discussion is always enjoyable, and I think everyone usually walks away having learned something (I hope!).

If you already have an account on, feel free to join the group and RSVP.  If you don’t have an account and don’t want to sign up, you’re still more than welcome to come.

Last time we had two new members show up, giving us four people total.  If we can get just one more person to show up, we’ll finally break our attendance record.  :)

Hope to see you there!

Comments No Comments »

If you’re anything like me, you probably have at least one (if not two or three) ‘temp’ directories scattered throughout your hard drive.  These directories were surely created with the best of intentions (‘OK, this temp directory is really going to be for temporary files.  I promise!’), but unless you’re incredibly religious about it, by now each one is filled with its own collection of random downloads, files, pictures, and other assorted junk.  To make things worse, you don’t feel safe deleting any of it, because well, you can’t remember why you put it there in the first place.

Fed up with never really knowing what files were temporary and therefore safe to delete in my collection of ‘temp’ directories, I finally came up with a simple solution that works for me.  I thought I’d share it here in the hopes that someone else might find it useful.


  1. Create a directory named ‘SafeToDelete’ somewhere on your hard drive.  (I like to use C:\SafeToDelete)
  2. Create a batch file to delete the directory (and it’s contents) and recreate it.  (I named mine SafeToDelete.bat and put it in C:\)
  3. Schedule the batch file to either run daily or at boot-up

That’s it.  The batch file I use for step 2 consists of two lines:

rmdir SafeToDelete /s /q
mkdir SafeToDelete

And, I just use the built-in windows scheduler for step 3.  This way, when I’m saving files, I have to make a conscious decision, “Is this really a temporary file?”. If so, throw it in SafeToDelete knowing that it will get deleted soon.  If not, put it in its rightful place.

Hope that helps.  This method has certainly made my hard drive much cleaner.

Comments No Comments »

If you happen to live in the Baltimore/DC area and write software, are interested in software, or read a lot about software, feel free to join on next Sunday (June 21st) at la Madeleine in Columbia, Maryland for the next Baltimore Software Book Club Meetup.

Even if you’re not an avid book reader, the discussion is always enjoyable, and I think everyone usually walks away having learned something.

If you already have an account on, feel free to join the group and RSVP.  If you don’t have an account and don’t want to sign up, you’re still more than welcome to show up.

Hope to see you there!

Comments No Comments »

So, I’ve had this problem for a while now that whenever I attempt to stream video through my computer to the Xbox it takes three attempts before I can finally start the video.  Basically, I fire up the Xbox, go to Videos, navigate to my TV folder, and then wait 30 seconds for whatever is throwing an error to time out before I get the No videos screen.  After about 60 seconds, I’m finally able to get back in to the Videos/TV folder and navigate through the TV subfolders.  I click on one and 30 seconds later I’m again staring at No videos.  One more try, and I’m finally watching some Flight of the Conchords (seriously, if you’re not already watching this show, buy the first season on DVD!).  To be fair, it’s a minor annoyance.  I am eventually able to watch my videos, but every new day requires another three attempts so definitely not ideal.  Aha!  A challenge!

So, where to begin?  Well, let’s start with Event Viewer.  I fire up the run command and type in eventvwr.  I scroll through the Application view, but nothing really jumps out.  When I switch to System, however, I find my answer:


Namely: The Windows Media Player Network Sharing Service service terminated unexpectedly.  It has done this 1 time(s).  The following corrective action will be taken in 30000 milliseconds: Restart the service.

My first instinct is to open up Google and find other people with similar problems.  Unfortunately, I wasn’t able to find much information.  A few people recommended clearing out the Cache folder under the Windows DRM folder, but all this did was to stop sharing from working altogether and to render my Zune subscription useless.  Don’t try this!

Thankfully I backed up my Cache folder and restoring it seemed to put everything back where it was before — complete with the three tries and I’ll play videos on my Xbox.

What’s next?  Well, I’ve always been dying for an excuse to fire up and play with WinDbg, so I start looking for how to debug Windows Services and stumble across this great article.  A few minutes of reading, and I’ve managed to attach WinDbg to the Windows Media Player Network Sharing Service.  I turn on the Command window, turn on the Xbox, navigate to Videos/TV and bam!, I see this:

(f94.f4c): Illegal instruction – code c000001d (first chance)
ModLoad: 04da0000 0566a000   C:\WINDOWS\system32\
ModLoad: 05670000 05ed9000   C:\WINDOWS\system32\xvid.dll
(f94.ab4): Access violation – code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=3d454ab4 ebx=00000000 ecx=0417fe60 edx=0417fe50 esi=0417fe60 edi=68578b48
eip=0568d554 esp=0417fd70 ebp=028f1f20 iopl=0         nv up ei pl nz na pe cy
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010207
*** WARNING: Unable to verify checksum for C:\WINDOWS\system32\xvid.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\system32\xvid.dll –
0568d554 8b0cbdd8d76a05  mov     ecx,dword ptr xvid_5670000!encore+0×46e8 (056ad7d8)[edi*4] ds:0023:a6c904f8=????????
*** WARNING: Unable to verify checksum for C:\WINDOWS\system32\
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\system32\ -

Now, I’ll be honest, I don’t understand what half of that means, but these two lines stand out like a sore thumb:

ModLoad: 04da0000 0566a000   C:\WINDOWS\system32\
ModLoad: 05670000 05ed9000   C:\WINDOWS\system32\xvid.dll

My first thought is that my Xvid driver is simply out of date, has a bug, or is just tired and needs a refresh.  Either way, I navigate to the Xvid site, download and install the latest codec, restart the laptop and the Xbox and Videos/TV/Flight of the Conchords works on the first try!  Sweet!

Comments No Comments »

I don’t think I’ve ever written about it, but for the last year or so I’ve been trying to learn to play the guitar. This endeavor actually started when my sister asked for and received an acoustic guitar for Christmas several years ago. Her interest in learning to play didn’t last long, and I eventually bought the guitar from her for about $100 (if I remember correctly).

Fast forward a few years, and I’ve now been taking guitar lessons locally for about four months using that same acoustic guitar. I’m still not very good (basic scales still elude me), but after receiving a gift card to Guitar Center for Christmas (early, I know), I decided it was finally time to go electric.

So, without further ado, here is my new Ibanez RG120 along with the Line 6 Spider III amp that I picked up along with it:

I know this post isn’t programming related (don’t worry — the focus of this blog is still programming), but I stopped writing posts when I took up guitar lessons and feel it’s only fitting that I post about the fruition of those lessons.

Comments No Comments »

Time again to dig into the next question on Scott Hanselman’s list of ASP.NET interview questions.  This question focuses on PostBacks; specifically, this question is posed:

"Explain how PostBacks work, on both the client-side and server-side. How do I chain my own JavaScript into the client side without losing PostBack functionality?"

Lets start with what a simple definition: A PostBack happens when the contents of a web page is sent back to the server for processing.

From the definition, it would seem that most (if not all) PostBacks happen on the server side.  Indeed, server-side PostBacks are the type you’re probably most familiar with.  For example, any time a component is declared with runat=server, it is taking advantage of the server-side handling of PostBacks.  When a PostBack happens, the information entered into a form is sent back to the same page for processing.  Newer versions of ASP.NET allow for cross-page PostBacks, but the vast majority of pages still post back to themselves.  That being said, there are a few things to remember when working with PostBacks:

  • The PostBack request contains the current value of every control within your form declared with runat=server.  The data is commonly referred to as the Post Data
  • The Post Data will also contain the content of the page’s ViewState.  In this case (unless specified otherwise), the ViewState will contain the original value of these same controls before their values were changed
  • Finally, the Post Data will contain the ID of the control that initiated the PostBack (for example, if you clicked a ‘Submit’ button, the ID of that button will be part of the Post Data

There is some additional information on ViewState and server-side PostBacks on MSDN, but that should get you started.

Regarding client-side PostBacks, and despite my best efforts to fully research the topic, without being able to directly talk to a potential interviewer posing this question, I’m not exactly certain what kind of answer Mr. Hanselman is looking for.  Almost every article I’ve found online seems to suggest that a client-side PostBack is little more than having an ASP.NET button, link button, or image button call a bit of JavaScript either before doing a server-side PostBack (i.e. displaying a confirmation dialog or doing some form validation) or in lieu of doing a server-side PostBack at all.  If that is indeed the case, this can be accomplished a few different ways.

For example, assume you have an ASP.NET button declared with ID = "btnSubmit"

<asp:button id="btnSubmit" runat="server" text="Do Something Potentially Destructive?"/>

And you want to add a confirmation dialog before the server-side PostBack occurs.  One way is to add an attribute to the control on PageLoad:

void Page_Load(object sender, EventArgs e)
btnSubmit.Attributes.Add("onclick", "return confirm(‘Are you want to do something potentially destructive?’);");

Starting with .NET 2.0, you can also take advantage of the OnClientClick property to accomplish the same goal:

<asp:button id="btnSubmit" runat="server" OnClientClick="return confirm(‘Are you sure you want to do something potentially destructive?’);" text="Do Something Potentially Destructive?" />

Assuming I’ve correctly interpreted the question, I believe that should set you on your way.  If not, please let me know in the comments.  This blog is as much a learning experience for me as it is for any potential readers, so don’t be shy. :)

Now, there is one lingering branch of this question that still needs answered.  Specifically, how do we chain our own JavaScript without losing PostBack functionality?  Well, again, to really answer this question, it would be best to get some more information as to exactly what is being asked.  That is, if you use one of the two methods above to add a confirmation dialog to a button, you won’t lost PostBack functionality.  In fact, I had to dig a bit deeper to really find a good example of how to answer this question.  Surprisingly (or maybe not-so-surprisingly), the answer came from Scott’s site.

What I think is being asked here is better understood when thinking about an ASP.NET LinkButton as opposed to your everyday Button.  If you’ve ever noticed, ASP.NET achieves the functionality of LinkButtons by creating and then calling a JavaScript function called __doPostBack that takes in two arguments — an EventTarget (the server-side function to be called) and an EventArgument (any arguments to that function).  This is important to note because if you now wanted to create your own JavaScript function that did some client-side processing and then called the appropriate server-side method, you would need to know the signature of this __doPostBack method.  It turns out you can get this method signature by calling Page.GetPostBackEventReference.  Tying this altogether, assume we have a LinkButton with ID = "lnkSubmit" and you want to set the NavigateUrl on PageLoad to your own JavaScript function that calls __doPostBack when it is finished.  You could do this in the following manner:

string PostBackReference = Page.GetPostBackEventReference(lnkSubmit);
lnkSubmit.NavigateUrl = BuildMyJavaScriptFunction("My first parameter", PostBackReference);

That should wrap it up.  If you have any questions, leave them in the comments!

Comments 5 Comments »

So, it’s time to tackle the next question in the original list of Scott Hanselman’s ASP.NET interview questions.  This time, the question asks to describe what events are fired when binding data to a data grid and what they could be used for.  If you are looking for a very technical overview, MSDN has the scoop on all of the data grid binding events.  Since this is a blog (and therefore not meant to be a technical document), I’ll try to approach the topic with a bit more of a pragmatic eye and give some example code usages.

On the the events!

The easiest way to figure out what events you have at your disposal is to create a DataGrid on your .aspx page and browse through the different intellisense options that pop-up beginning with "On".


As you can see in the image above, DataGrids in ASP.NET can do much more than display data.  However, in this case, we are only interested in the events that get fired as part of the process that binds the data to the DataGrid.  It turns out, out of the myriad of events that can be utilized, only two of them happen as part of the data binding process.  These two events are the ItemCreated event and the ItemDataBound event.



The ItemCreated event is fired when an item in a DataGrid control is created.  This means that at the time the event is fired, the DataGrid does not yet know about the data that will be bound to it.  So, if the logic of your method depends on this data being available to the control, you’re better off using the ItemDataBound event.  Other than that, the ItemCreate event differentiates itself in one other way from the ItemDataBound event: the ItemCreated event is raised when data is bound to the control and during round-trips (postbacks).  These qualities make the event especially well-suited to add custom attributes to a DataRow (such as onmouseover or other javascript events) or to control the appearance in ways that do not depend on the data within the DataRow (such as making every 10th row a different color).



The ItemDataBound event is fired after after an item in a DataGrid control is bound.  This means that (unlike the ItemCreated event) you can add special formatting to a DataRow that is dependent upon the data contained within that row.  Since ItemDataBound is fired after the ItemCreated event, it is within this event that you are presented with the final opportunity to access the data before it is rendered to the client.  These qualities make the event well-suited for changing the appearance of a row or cell based on the data within that row or cell (such as highlighting outliers or other important information).



Assume we have the following DataGrid declared on our .aspx page:

<asp:DataGrid ID="MainDataGrid"
="MainDataGrid_ItemCreated" />

On the code behind page then, we can create the following two methods to handle adding titles to header row, to specify more descriptive headers, and to change the row background color based on an employee’s salary:

protected void MainDataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
//If the item is in the header
    if (e.Item.ItemType == ListItemType.Header)
//Iterate through each cell
        foreach(TableCell item in e.Item.Cells)
//Add the title attribute — we could just as easily
            //add a javascript onmouseover event here
            item.Attributes.Add("title", item.Text);

        //Since the header values are set before we have access
        //to the data, we can modify the third column header to
        //be a bit more descriptive
        e.Item.Cells[2].Text = "Salary (in US$)";

protected void MainDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
//Since DataGrid differentiates between Items and AlternatingItems, you sometimes have to check
    //for one *or* the other
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
//Here we will modify the row color based on the salary
        //We can only do this within ItemDataBound since it relies
        //on the data being available from the data source
        if (Convert.ToInt32(e.Item.Cells[2].Text) < 10000)
e.Item.BackColor = System.Drawing.Color.LightPink;
else if (Convert.ToInt32(e.Item.Cells[2].Text) < 1000000)
e.Item.BackColor = System.Drawing.Color.LightBlue;
e.Item.BackColor = System.Drawing.Color.LightGreen;


I created a sample DataTable that I have bound to.  Using the two methods above, I get the following output in the browser:


If it helps, I have include a sample project that you can use to get started with your project.  You can download it here.

Hopefully that gives you a good idea of how best to take advantage of the events fired as part of binding data to a DataGrid.  If you have any questions or comments, please feel free to add them to the comment section.  I find these blog entries to be a great learning experience for me, so I’d love to know if they’ve been helpful to anyone else.

Comments 1 Comment »

Welcome to the third entry in my series of posted dedicated to answering Scott Hanselman’s ASP.NET interview questions.  In this entry, we will tackle using custom extensions (Scott uses *.jsp as an example to preserve backwards compatibility) to serve up ASP.NET pages.  By custom extensions, I mean that if you go to http://localhost/default.jsp you can actually direct the webserver to process the request using the ASP.NET worker process.

As it turns out, custom extensions are not all that difficult in ASP.NET assuming you have no aversions to getting under the hood and making some changes to IIS.  It also ties back nicely to the last post I did in this series that covered ASHX files and HttpHandlers.

To start out, lets first instruct IIS to send any request ending in a *.jsp extension to be passed on to the ASP.NET worker process.  To do this, open up Internet Information Services and find the website on your machine that you want to configure:


Next, select "Configuration" on the Properties page:


Here, you will be able to add the custom *.jsp extension.  For ease of use, I just copied the configuration values from the *.aspx extension.



Click "OK" until you are back to the main IIS screen and then exit.  At this point, IIS knows that when it receives a request with a *.jsp extension to pass the request along to the ASP.NET worker process.  Next, we need to instruct our application to process these incoming requests using the PageHandlerFactory HttpHandler.  To do this, open up the web.config file and add the following lines to the httpHandlers section in the system.web node:

<add path="*.jsp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true" />

Also, you’ll need to add the following lines to the compilation node (again in the system.web node):

<add extension=".jsp" type="System.Web.Compilation.PageBuildProvider" />

Visual Studio 2005 automatically creates the compilation node as self-closing, so here is what it should look like after you’ve added the lines above:

<compilation debug="true" strict="false" explicit="true">
<add extension=".jsp" type="System.Web.Compilation.PageBuildProvider" />

Now, IIS knows how to pass the request along and your application knows how to process any request with a *.jsp extension.  At this point, we’re basically finished.  If you already have an *.aspx page that you’d like to serve up with a *.jsp extension, all that’s left is to rename it and rebuild your application.  Otherwise, I’ve found it easier to create your pages uses the *.aspx extension and then change it to *.jsp once you’re finished making your code changes.

Here is a screenshot from an application that I configured on my machine before the Page PostBack:


And after the PostBack:


If you’d like, I also zipped up the solution which can be downloaded here.  If you have any additional questions, please feel free to leave them in the comments!

Comments 1 Comment »

I recently wanted to set up log4net on a project I’ve been working on and found the documentation somewhat lacking when trying to find a quick and easy setup guide.  So, once I had everything set up and working, I resolved to create one myself.

So, in less time than it takes to get a pizza delivered, here is how to quickly get log4net setup on your project.

What you’ll need:

  • The log4net dll (you can find the most recent version here)
  • A .Net project/solution that you’d like to add logging to (you’re on your own here)
  • Access to the Assembly.cs file for said project
  • Access to the app.config or web.config file for said project
  • A place to store your logging files (I will be using C:\ in this example, but this is one area in which the documentation actually excels)


  1. Place the log4net dll somewhere that you can reference it easily.  I like to keep a Libraries folder around in most of my projects to hold any 3rd party dlls, but the choice is up to you.
  2. Add a reference to the dll in your project solution:
    • References
  3. Add the following code to the Assembly.cs file.  More documentation here:
    • // Configure log4net using the .config file
      [assembly: log4net.Config.XmlConfigurator(Watch = true)]
      // This will cause log4net to look for a configuration file
      // called TestApp.exe.config in the application base
      // directory (i.e. the directory containing TestApp.exe)
      // The config file will be watched for changes.
  4. Add the following section to the web/app.config file in the <configuration> node:
    • <configSections>
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  5. Create a new section in the web/app.config using log4net as the node name:
    • <log4net>
      <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="C:\logfile.txt" />
      appendToFile value="true" />
      layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" />
      <level value="DEBUG" />
      appender-ref ref="FileAppender" />
  6. At the top of the class in which you want to implement logging, add the using log4net; directive.
  7. Define a static logger variable at the top of your class.  Something like this will work:
    • private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  8. Start adding logging statements to your code, for example:
    • log.Info("Entering application.");
  9. Altogether then, your class might look something like this:
    • using System;
      using System.Collections.Generic;
      using System.Text;
      using log4net;

      namespace log4netDemo
      class Program
      // Define a static logger variable so that it references the name of your class
              private static readonly ILog log = LogManager.GetLogger(typeof(Program));

              static void Main(string[] args)
      log.Info("Entering application.");

                  for (int i = 0; i < 10; i++)
      log.DebugFormat("Inside of the loop (i = {0})", i);

                  log.Info("Exiting application.");

  10. Which would produce this output when run:
    • 2008-05-12 19:53:28,059 [11] INFO  log4netDemo.Program [(null)] – Entering application.
      2008-05-12 19:53:28,260 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 0)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 1)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 2)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 3)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 4)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 5)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 6)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 7)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 8)
      2008-05-12 19:53:28,280 [11] DEBUG log4netDemo.Program [(null)] – Inside of the loop (i = 9)
      2008-05-12 19:53:28,280 [11] INFO  log4netDemo.Program [(null)] – Exiting application.


That really should be all there is to it.  Although I did find the lack of a simple, quickstart guide daunting, there is actually a lot of good documentation on the log4net site.  Particularly, if you want to use a different appender or read a more general introduction.

If you’re interested, I’ve zipped up a sample solution using the code above.  You can download it here.

Comments 14 Comments »