SmugMug Rocks

Posted in Random on November 5th, 2009 by James – Comments Off

After not having my photo gallery online for about a year, I finally got around to getting it back.  I was previously self-hosting the gallery with Gallery2, but that software turned out to really just be a pain in the neck for my gallery and all the other galleries I host.

SmugMug came to the rescue!  Allison has been using SmugMug for her portrait photography lately, and it’s proven itself to be nothing short of awesome.  The site is very fast and responsive, the upload tools are great, slideshows work (fancy that), and the cost is reasonable.  If you want an account and want $5 off, use this referral code: sJz9wIbaT3urU

Check out my pictures at http://bensie.smugmug.com.

jQuery: Focus the first input of a text field

Posted in Random on June 11th, 2009 by James – Comments Off

If you have forms around your site (logins, registrations, etc), you might want to automatically focus those fields so the user has less clicking around to do.  We want to do this unobtrusively, and don’t want to focus it if the field already has data in it (editing existing forms).  Here’s the jQuery code to pull it off:

Developing For The iPhone: Part I

Posted in Random on April 22nd, 2009 by James – Comments Off

Ever since Apple started up the App Store, I’ve been dying to dig in to Objective-C and write an application for the iPhone (no, I don’t own an iPhone yet).  I’m certainly not alone, as there are now like 100,000 apps available on the store.  I bought a book, read through a lot of the developer documentation, but finally something even better came along — Stanford is posting the lectures and slides on iTunes U for iPhone Application Programming.  While the lecturers are not the best speakers, the content of the class is fantastic so far.  I’ve watched 4 episodes and have grasped more by watching those than all of the prior reading I have done.

This isn’t the first time I’ve “taken classes” while not actually in school.  If you’re ever interested in taking a class on something that you didn’t want to take a grade on in undergrad, check out iTunes U and Academic Earth.

My first iPhone app will no doubt be very simple and probably not all that useful, but it’ll be an accomplishment.

Rails 2.3: default_scope

Posted in Tech on March 13th, 2009 by James – Comments Off

Rails 2.3 includes a new method called default_scope which provides an easy way to set default attributes on a model as it calls on records from the database.  After playing around with it a bit, I am certain that I’m going to avoid using this method for a few reasons.

Before I get to that, here’s the syntax:

You could set a default_scope for any number of conditions, but :o rder is really the only thing that makes sense to me (red flag number one) because nothing else would have fixed conditions for all database queries.

With this default_scope in place, we’re going to get an ORDER_BY ‘name’ ASC added to our SQL query when calling Person.all, Person.old, or Person.young. That’s all well and good until the query gets a little complex–what happens if we specify a different :o rder in the named scope or in the controller? As you might guess, the default_scope loses out to specifying a different :o rder in other methods.

Once your query gets complicated with includes and joins, you’ll find that suddenly the defaulted :o rder option does not show up in your query and all your people are completely out of order.  At that point, you’re back to square one needing to manually specify the order in a separate named_scope or in the controller logic.

The inconsistency here is intolerable, and the code also loses a lot of clarity when it is implemented since it will not work under all circumstances.  Personally, I like :o rder options visible in the controller (I put just about everything else in named_scopes) because the code stays clear.  Just seems to me that it’s better to leave this method out all together.