Tuesday, 20 January, 2009. Tagged with: software, rails, testing
I recently launched a Rails application that has a phone number field available to it. In the process of writing my spec tests, I allowed the phone field to be a certain number of characters and allowed it to be empty. The formatting test, however, I left pending. I searched for, but did not find a great solution past some very unreadable regular expressions.
In the course of watching a movie this evening, I had a solution. I created an array of acceptable formats, looped over the array and checked each entry against the phone number. If I had a match, the validation passes. Setting the string match to the beginning and I can allow for extensions without being too persnickety about formatting.
Here it is (via a handy gist):
def valid_phone
return true if phone.blank?
phone_formats = [
/^\(\d\d\d\) \d\d\d-\d\d\d\d/,
/^\d\d\d.\d\d\d.\d\d\d\d/,
/^\d\d\d-\d\d\d-\d\d\d\d/
]
valid = false
phone_formats.each do |format|
if phone.match( format )
valid = true
end
end
unless valid
errors.add(“Phone format isn’t recognized”)
end
end
Here are some spec test examples.
It doesn’t handle international formats, but, for right now, it fits my needs.
Tuesday, 20 January, 2009. Tagged with: photography

Festivities up the street from us today.
Tuesday, 20 January, 2009. Tagged with: photography

Inauguration Day snow in Raleigh. I have a few more over on Flickr. As of 9:45, North Raleigh was still getting big, fluffy flakes of snow. We’ve seen one SUV traverse the neighborhood and our up-the-street neighbors on quads. That’s been it.
It’s a pretty, nice gift, particularly since most times Raleigh gets forecast for snow, it’s a dusting. Enough to screw up traffic, but not enough to enjoy. Not today.
Monday, 19 January, 2009. Tagged with: business, testing, web development
My wife and I are launching a website in the near future. As part of the ongoing development process, we’d been talking about testing alternate browsers. We’re able to test Internet Explorer 6 on our machines using Darwine and ie4osx. Still, that left us without a great option to do IE7 testing.
As it happens, we have an older MacBook Pro 2.33 that fell off of Craigslist. We’d like to sell it, but Robin brought up using it as a Windows machine. I figured with Boot Camp and a Windows license, sure, we could be in business. However, with Windows XP or Vista licenses running between $120 and $300, I was eager to find an alternate solution. Bootstrapping a business means funneling money into product, not blowing the budget on something we’ll use infrequently. The tool can be essential, but infrequently used and thus, too expensive.
I remembered at work, one of our sysadmins set-up up some virtual machines to allow Linux and Mac OS X users to test on Windows XP. So, my thought was to use Amazon’s Elastic Computing Cloud (EC2) running Windows Server 2003. Handily, the machine images already use IE7. I fired up EC2 instances about four different times. At $0.125 per instance/hour and a little bit extra for Amazon S3 usage to load the image, our tests wound up at a whopping $0.52.
How I went about this:
There are other places I can take this, building a machine image with other browsers installed and storing the image on S3. In fact, that’ll probably making sense for us later this week.
There are other, largely unexplored options, mentioned here for future reference:
- Browsershots A service that screen shots a site in several browsers.
- litmus Free testing up to 50 times/month in FF2 and IE7. Or spend $24 for a day pass or get a month for $49. The tests give you screen shots and HTML and CSS validity reports. They do email testing, too.
- CrossBrowserTesting.com
Screen shot services aren’t as useful because while you see what the page renders as, you don’t get a sense of what quirks a user will run into if, say, a JavaScript action fires differently. That’s the situation we’re in. The pages look fine, but don’t act like they should.
Sunday, 18 January, 2009. Tagged with: links, technological failure
Tidbits from and related to US Airways Flight 1549.
News coverage, meanwhile, is abuzz over the apparent heroics of the US Airways pilots, and maybe you are wondering how pilots are trained when it comes to putting a plane down in water.
They aren’t, per se. There are procedures in the book, but ditchings, as they’re called, are not regularly rehearsed in simulators. Not only are they exceptionally unlikely, but more critical than the ditching itself is dealing with the emergency that causes it — multiple engine failures, a fire, or some other unfortunate scenario. As for hitting the water, the gist is to do so slowly and gently, with the nose at more or less the typical landing angle, wings level, and avoiding heavy swells.
In the event of a water landing, the pilot can manually activate the switch, which closes the outflow valve and avionic ventilation ports, which are the openings below the aircraft’s float line. All commercial airliners are required to have a ditch switch according to Federal Aviation Administration regulations.
The bird-strike testing is conducted in accordance with detailed FAA specifications to confirm that the engine can safely tolerate a bird strike, and the birds used have to be representative of the types of birds that pose a potential threat to aircraft engines in flight, GE says.
The dead-bird carcasses, obtained from a variety of sources, can weigh a pound or more. To certify the massive GE90 engine, for example, an 8-pound Canada goose was used for the first time.
One bird can really fuck up a fan blade. A whole flock of birds…