[null, null, {"document_url": "http://madkingsmusings.blogspot.com/2011_07_01_archive.html", "unformatted_src": "http://2.bp.blogspot.com/-o0u2ZfC-nxA/TiGYMU5pHnI/AAAAAAAABA4/8W4Ev37DFbo/s1600/CommandMark.jpg", "src": "http://2.bp.blogspot.com/-o0u2ZfC-nxA/TiGYMU5pHnI/AAAAAAAABA4/8W4Ev37DFbo/s1600/CommandMark.jpg", "formatted_filename": "CommandMark"}, null, null, null, {"document_url": "http://madkingsmusings.blogspot.com/2011_07_01_archive.html", "unformatted_src": "http://i452.photobucket.com/albums/qq250/Demonic-Genius/stormtrooperarmy.jpg", "src": "http://i452.photobucket.com/albums/qq250/Demonic-Genius/stormtrooperarmy.jpg", "formatted_filename": "stormtrooperarmy", "rendered_width": 320, "rendered_height": 179}, null, null, {"document_url": "http://madkingsmusings.blogspot.com/2011_07_01_archive.html", "unformatted_src": "http://2.bp.blogspot.com/-eWthLQs-9_M/Tg_eInp6YVI/AAAAAAAAAuk/u-8Axu0QC18/s640/IMG_20110702_103255.jpg", "src": "http://2.bp.blogspot.com/-eWthLQs-9_M/Tg_eInp6YVI/AAAAAAAAAuk/u-8Axu0QC18/s640/IMG_20110702_103255.jpg", "formatted_filename": "IMG", "rendered_width": 640, "rendered_height": 476}, null, null, null, null, null, null, null, null, null, {"document_url": "http://madkingsmusings.blogspot.com/2011_07_01_archive.html", "unformatted_src": "http://photos1.blogger.com/x/blogger2/4022/698742561780572/259/532640/gse_multipart47467.jpg", "src": "http://photos1.blogger.com/x/blogger2/4022/698742561780572/259/532640/gse_multipart47467.jpg", "formatted_filename": "gse multipart", "alt_text": "<a href=\"http://www.jlab.org\">JLab</a> Hockey", "rendered_width": 150, "rendered_height": 173}, null, null, null, null]

Checking Web Application Health

There are certain things you want to know about your web application to make sure it has started correctly and to help diagnose problems.
The first question is easy to answer? But what about the others? You can obviously determine if the other dependencies are up by going to the appropriate place in your application, but it'd be nice to have a single location to check all of these. And what about server settings or code version? Ever had a bug reported that you know you fixed? It's nice to also be able to make sure that you really are running the version you think you are.

Here's how I've accomplished this on a Ruby on Rails project.

Single Location
First, I created a controller with a single page:
Here is the beginning of the controller class.
As you can see, I've protected it, so only administrative users can view this page. Here is the views/admin/index.html.haml where I show server state.

Dependency Tests
I've implemented each test as a separate Ajax call. In the view code above, this everything from "Site Tests" on down. This consists of the buttons (one for each test, just one here), a place to show the output, and the javascript to make this work. For each test, I just add a new button in the .test div. As you can see in the code above, the button makes an Ajax call (:remote=>true) and calls a javascript function to show that the result is loading. It is up to the controller to then update the testOutput div with output status.

In my admin_controller.rb I have a function for each button that looks like:
The helper function standard_test looks like:
All it does is executes the test code (via the yield statement) and catches any thrown exceptions. If there is no exception, it considers the test a success. Assuming it was called via an Ajax call, it then renders the javascript template test_output.js.haml which is simply:
As you can see, this merely replaces the testOutput div with what is rendered by the _test_output.html.haml partial:
Of course, don't forget to make sure your routes are in your config/routes.rb.
Including version information is going to be very specific to your environment. We use Mercurial for our version control, and since we have a number of Java project, we use ant for our deployment process. Here is how I connected these together.

In the ant deployment script, I added a target that looks like:
All that is left is to get the contents of this version.txt file into the @version variable that is displayed by index.html.haml. This is done by simply having the index method in admin_controller.rb read in the file.
This really wasn't too much work, and now I have a single page that I can go to and at a glance see what version of the code was deployed and which rails environment is being used. Adding new tests is just a simple matter of adding a new button to the view, which calls a new test method in the controller. By leveraging the standard_test method, new tests can consist of just the code they are intended to test.
Posted by Michael Haddox-Schatz at 9:00 AM 0 comments 

Windows Command Line Cut & Paste Rant

Just a quick rant this week. When selecting text in the windows command console, why does it do a "block" mark rather than a line based mark?!?! In every other text based environment I've used, including Windows Notepad and MS Word, if you start highlighting text in the middle of one line and move down to the middle of the next line it select the end of the first line and the beginning of the next line.  i.e. all the text that starts where you started the mark and ends where you ended the mark. For some reason the Windows Command shell only marks the text that is actually in the box, i.e. a couple characters in the middle of both lines. Is there a time that this behavior is useful? If you know, please share it with me.

For me, I often want to copy either a long command line I ran, or the output of a command, to put in an email, IM, a wiki, or even to paste into another terminal to run. But if the line is wrapped, then to make sure I get everything I want, I have to also copy the command prompt. This means I have to add an intermediate step of editing my selection before I can send it. What's even more bizzarre to me, is that in searching on the web, I can't even find any other comments about this behavior. Nor can I find a way to change this. Am I the only one who finds this annoying? More importantly, does anyone know how to change this behavior?

(I know, I know. I shouldn't be using Windows, and I shouldn't be cutting and pasting. Well, I have to admit that I sometimes do both, and I was doing a lot of both this past week.)
Posted by Michael Haddox-Schatz at 9:00 AM 4 comments 

Attack of the Clones 

GCJ 2011 T-Shirt

Due to the holiday weekend, I am just making a short post this week.

Last week I mentioned that I got knocked out of the TCO 2011 competition, and so will get no shirt for it. Well, a couple days later FedEx delivered my Google Code Jam 2011 t-shirt. It's not as cool as getting the trip to Japan for the finals, but I guess I'll take what I can get. Since a picture was requested, here it is. And, no Alan, programming contests don't completely eliminate the need to go clothes shopping, though I do have around two dozen t-shirts plus a nice winter coat and hat from various programming contests. JLab Hockey I don't just program