Friday, September 21, 2007

Ruby, ActiveRecord and Database Functions

Here's a neat little trick you might not know.  Rails (well, ActiveRecord) tends to do all of your SQL for you, right?  So you don't have to write a bunch of selects and joins to get at your data.  Fair enough.  Well, what happens when you need to do a manipulation on that data?  I have a case right now where I need to get the date_of_birth field of out my model.  The only problem is that it is stored encrypted, and I need to call my companies internal decrypt() method on it. 

The find method actually has what you need already built in, by passing a :select param into it.  Normally you'd be selecting *, but what you want to do here is change it for your specific purpose.  So in my Document class I have this:


def dob

  Document.find(id, :select=>'decrypt(date_of_birth) as dob').dob



Done!  Now once I have  Document object, the dob property appears just like any other. 

I realize that this trick only goes half way in that it makes a find() call whenever you access the parameter.  In reality I should figure out a way to make this trick integrate directly with the main instantiation of the object so there's not a second call involved.  But for this project I'm working with a small number of documents, and the extra database hit won't hurt me.  Anybody else want to chime in with a better way to integrate it?


Technorati tags: , , ,

Wednesday, September 19, 2007

Know What I Hate?

I hate financial sites that track your login by IP address, and then forget who you are whenever you login from a new machine.  I appreciate the concept -- new machine could mean new person off on a stolen card number someplace.  But in reality I've got a laptop that I cart back and forth between work and home, and if I check the bank account from work, and I last checked it from home, I have to dig out my bank card again and re-enter my information.  It's a small pain, but it's still a pain.  I'd rather they just didn't claim to remember it at all and made me re-enter it every time, instead of every visit being a potential unpleasant surprise. 

Tuesday, September 18, 2007 vs : How Blatant Can A Ripoff Get?

If you haven't seen it yet, be prepared for the onslaught of "" (no link for them, screw em) invitations to start swarming all your favorite blogs and social networks.  It's basically -- one day, one deal -- only, with an affiliate program.

The problem with it is that it is an exact copy of Woot!, as if the only thinking they put into it at all was "How can we steal this?" and "How can we get the users to do our marketing for us?"  They copied the look and feel.  They copied the colors and the fonts.  They even copied the questions on the FAQ, and the answers!  Even the email addresses are copied.  Of course, all things are copied with just enough of a change to stifle the obvious copyright infringement charges:

  • Woot has Today's Woot, The Blog, The Community, Write Us, Your Account, What Is Woot.
  • The other guy has Today's Deal, Our Blog, Make Money, Talk to Us, Your Account, What Is This.
    • (Note the irony of how the bad guys have no community, only a place for people interested in making easy money....)
  • Woot's FAQ on privacy policy:
  • The other guy's FAQ on privacy policy:
  • The Woot Write To Us form asks "What have you got to say", "Who Are You" and "Got an email address so we can write to you?"
  • The other guy's form asks "What have you got got to say", "Who Are You" and "Got an email address so we can write to you?"
    • (Looks like somebody forgot to tweak the copy on that page! Bad scammers!  No cookie for you.)


  • Get the picture?

Seriously, people, this thing has bad karma written all over it.  Don't reward people who do nothing but steal the original ideas of others and add no value.  There are plenty of affiliate programs out there for businesses that actually put a little effort into it and aren't just trying to ride the other guy's coat tails.

I can't wait until they copy Woot's legendary "Bag of Crap."  I wonder what they'll call it so they can claim to be original? 


Saturday, September 08, 2007

I Am The Cool Nerd King says I'm a Cool Nerd King.  What are you?  Click here!

I love a good "What are you...." test. This one, "What *kind* of nerd are you", certainly caught my attention. I guess I'm glad I scored so low on the "dork" scale - should have taken it back in high school!:)

Wednesday, September 05, 2007

You Know You've Been Hacking Too Long

When your brain is so tired that you go through a particular piece of your XML code, changing all particular instances of < to &lt; and all accompanying instances of > to &rt; ... and then wondering why it doesn't work.

Because "lt" is not short for "left", thus "rt" for "right" makes no sense to the poor compiler.

It's lt for "less than", thus the other one is "gt", or "greater than".


I crashed XMLSpy half a dozen times on that one, actually.


P.S. - I've been dreaming in code, lately.  That hasn't happened since college, and it's pretty messed up.  I'm sitting there on the couch, trying to keep my eyes open while watching some television show, and suddenly my brain starts fitting the characters' actions into IF-THEN-ELSE structures and other things and visions of angle brackets begin dancing in my head.  I find it quite fascinating, almost like lucid dreaming.


Technorati tags: , ,