Month: December 2007

  • Rails 2.0: Validations Without Extending ActiveRecord::Base

    In more “enterprisey” web stacks (such as Java with Hibernate and Spring MVC), it’s straightforward to design a validatable form whose contents do not correspond directly — if at all — to a persistent OR/M class: such as may happen in an ecommerce site where you’re collecting payment information but can only store some of it in the database for legal reasons. Just create a MVC-level view object using your framework-specific validation mechanism, and translate to/from the relevant OR/M classes as necessary in the controller.

    This scenario isn’t always straightforward to handle in Rails since the stack layers are smooshed together. In Rails 1.2.x, you could use (some) validations in your non-persistent PORO objects by extending ActiveRecord::Base and overriding the initializer to skip the databases-related stuff. Alas, this hack does not seem to work in Rails 2.0, but I have a solution which, in my brief testing, seems to work better than the aforementioned Rails 1.2 hack.

    Here’s how I used ActiveRecord::Validations in one of my view-only classes in a Rails 2.0.2 application without needing a dummy table in the database or ActiveRecord::Base.


    require 'active_record/validations'

    class Card

    # Define your arbitrary PORO attributes.
    attr_accessor :number
    attr_accessor :expiration_month
    attr_accessor :expiration_year
    attr_accessor :verification_value

    # For the ActiveRecord::Errors object.
    attr_accessor :errors

    def initialize(opts = {})

    # Create an Errors object, which is required by validations and to use some view methods.
    @errors = ActiveRecord::Errors.new(self)

    end

    # Dummy stub to make validtions happy.
    def save
    end

    # Dummy stub to make validtions happy.
    def save!
    end

    # Dummy stub to make validtions happy.
    def new_record?

    false

    end

    # Dummy stub to make validtions happy.
    def update_attribute
    end

    # Mix in that validation goodness!
    include ActiveRecord::Validations

    # Use validations.
    validates_presence_of :number
    validates_presence_of :expiration_month
    validates_presence_of :expiration_year
    validates_presence_of :verification_value

    end

  • Rails 2.0: HTTP Basic Authentication

    lock.pngHTTP Basic authentication support comes bundled with Rails 2.0, alleviating the need for external plugins we used with Rails 1.x. Here’s how you can use (and test) this new Rails 2.0 feature. (more…)

  • Mass Effect: Holy Freaking Crap

    picture-7.pngI figured I’d have some “me” time this weekend, so I picked up a copy of the highly praised Mass Effect. Saying it’s good is obvious; awesome is an understatement. Groin-grabbingly enthralling, genre-shattering entertainment is somewhere in the neighborhood. We’re talking a contender for best video game ever here. So if you’re last minute Christmas shopping for a 360 owner (possibly yourself), I can’t recommend Mass Effect highly enough.

    The gameplay itself is difficult to describe. Take the fun parts of leveling, storyline, voice acting and small squad combat RPG elements from Baldur’s Gate, the pace, feel and vehicle action of a FPS squad combat shooter, and drop that into an incredibly rich sci-fi backdrop of a Star Trek episode. Awesome sauce!

  • Penguin Pimp

    picture-5.pngI Celebrated my friend Gilraen’s birthday by molding figurines out of Sculpey, which turned out to be an excellent party activity. Karen started off with a cute penguin body, but somehow we ended up with a pimp: complete with hat, cane and technicolor dream coat. There are.. hmm.. “other” complementary figurines, but I’ll refrain from sharing those pictures in the name of cleanliness. Maybe the wine had something to do with it? Whatever.. good times 🙂

  • Rails 2.0: Testing For Well-Formed XML With assert_well_formed

    Here’s an easy way to validate that you’re always rendering well-formed HTML in an ordinary Rails application. I’ve written and verified this on Rails 2.0.1…

    (more…)

  • Xserve w/Leopard Server (Mac OS X 10.5), First Impressions

    picture-4.pngWe just picked up a refurbished 2.66GHz quad-core Xeon from Apple, which we’ll be using for internal infrastructure. (We’re in the process of migrating from a mix of Solaris and Linux). After about 8 hours of learning the ins and outs of Leopard Server over the weekend, we had the box running Open Directory (Kerberos and OpenLDAP), DNS, AFP, SMB, FTP, domain account and machine management, mobile home directories, MySQL, Software Update, Xgrid controller, Wikis, Blogs, iCal and VPN services, all tightly integrated with single sign-on (via Kerberos) into a sexy 1U package.

    • Xserve (refurbished discount, direct from Apple): ~$3K
    • 3 x 750GB Disks (Newegg): ~$450
    • 2 x Apple Drive Module (direct from Apple): ~$380
    • 2 x 2GB FB-DIMM RAM (Crucial): ~$300
    • Infrastructural sanity: priceless. (…or ~$4.5K after tax and random small stuff)

    That’s some serious value considering how much of a PITA setting all this up can be in Linux (or whatever) without vendor support, and far cheaper than paying a Systems Administrator in the long run. The Server Admin and Workgroup Manager tools are pretty freakin’ usable, too, relative to the internal complexity of the system. I’m a happy camper for now… let’s see if it lasts.

  • Invited To The Pentagon

    tides.png
    Mugr.com was recently invited to the Pentagon to demo our facial recognition voodoo as a potential biometric component to TIDES: Transportable Infrastructures for Development and Emergency Support. It was a very last minute trip with very little instruction and direction regarding what to prepare, so we packed up our Mactops and hopped on a plane.

    The subway ride at 5-something AM local time (3AM at home) after an all-nighter came cold and early, and shuttled a variety of more well-rested military types, who periodically would share a silent glance as if to say “OMG U N00B.” (Yes, in all capital letters with no exclamation point.) The guest check-in process was straightforward, and we soon found ourselves inside a small tent-like shelter booting our Macs if for no other reason than to warm our hands.

    The event itself brought in a diverse mix of (mostly) military, many of whom were happy to engage in our biometrics demo and subsequent discussion. I had many wonderful conversations with Dr. John Francis of the U.N. and many DoD personnel over at least a half pot of coffee. A fabulous experience, this goes to show how huge opportunities can spring up whenever, wherever.

    Would you risk your time, reputation and money for the opportunity? I know I’m game.

  • What's Better Than Windows Balloon Help?…

    Twice as much balloon help!

    picture-3.png

    My current testing environment for JumpBox development uses two Windows XP virtual machines on OS X under Parallels coherence mode: one with IE6 (gold taskbar on the bottom), the other IE7 (blue taskbar on the right). While they perform sufficiently with 4GB physical RAM, the constant nurturing required to keep these retards up to date and complaint free is ridiculous, given I only boot them once every couple weeks. Dyslexia also arises when each instance periodically “forgets” I’m using a Dvorak layout and reverts to QWERTY, even when sitting idle.

    picture-1x.png

    It’s the little things that drive one nuts. Office 2004 for OS X, for example, sets the bar really low for usability, quality and elegance. Full-screen mode?

    full_screen.png

    ..I guess not. And I won’t be inserting any cells into this table, either…

    insert_cells.png

    Given a choice between A and A, I think I’ll choose A.

    spell_check.png

    Waaaaay too much of this stupidity plagues Office. Not that Microsoft has much motivation to fix it, but it’s still sad to see such crappy software in wide-spread use.

    preston.rant_mode = false

  • 6 Things I'm Thankful For

    Bread BowlAn awesome first business year for OpenRain. The constant stress of context switching between software projects has become more managable, making weekend relaxation slightly more frequent. Marc has been a geeky Asian version of Superman, and our part-time office manager Gracie has been a godsend. Business has been great, and 2008 should be an exciting growth period.

    Bread bowls. Especially the kind filled with Cream of Broccoli soup.

    Not being poor. It’s easy to forget all the small luxuries afforded by a modest middle-class suburban family. Indoor plumbing, internet access, telephones, health care, shelter, affordable schooling… these aren’t common in many parts of the world.

    Loads of opportunities. One of the most motivating and simultaneously scary realities of running your own software company today is knowing you hold all the keys to your own future. There are so few barriers (especially economic) to today’s start-up that there is little excuse for not taking the risks and giving it your all. This year alone I’ve gotten to go to L.A., Washington D.C., England, San Francisco, Mendocino (California), Amsterdam, Austin, Baja and Portland off the top of my head. (Note to self: redeem those frequent flier miles!)

    Cheese. I’m a huge sucker for bree and havarti.

    The awesome people around me. Support structure is fundamental to success, and I’ve been fortunate enough to have a great one. Y’all know who you are!

    It’s been a superb 2007. Cheers to an even better 2008!