attachment_fu on Edge Rails

February 26th, 2008

Speaking of Edge Rails… attachment_fu will break because Edge has extracted callbacks out into a separate module.

To prevent unnecessary pain and suffering, see http://blog.methodmissing.com/2008/1/19/edge-callback-refactorings-attachment_fu/

Just paste that whole blob at the bottom of your attachment_fu.rb file and you’re good to go.


check_box broken in Rails 2.0.2?

February 26th, 2008

I was having an awful time submitting a form with a check_box. No matter what I did, it would only return “0” or “false”, never “1” or “true”, no matter how hard I mashed the mouse button on the check box.


  <%= check_box :fund, :tax_deductible %> <%= f.label :tax_deductible %>

I finally tried moving to edge Rails (from Rails 2.0.2), and the problem went away. Anyone else experience this?


Date Parsing Strangeness

February 22nd, 2008

Calculating dates is arguably one of the most complicated parts of programming. Ruby eases the stress with some great tools to help parse and calculate dates.

But lately I’ve run into some really strange behavior, and I’m kind of at a loss. I’m posting it here in the hopes that somebody can shed some light on why this is happening.

Basically I’m getting inconsistent results with the different parsing libraries. I’d like to be able to pass dates like “2/22”, “2/22/08”. Parsing a date like “2/22/08” should return February 2, 2008. But here’s what happens in the different parsing libraries:

>> Time.parse("2/22/08").to_date
=> Fri, 22 Feb 2008

>> Chronic.parse("2/22/08").to_date
=> Fri, 22 Feb 2008

>> Date.parse("2/22/08")
=> Wed, 22 Feb 0008

But as you can see, passing “2/22/08” to Date.parse we get the Year of our Lord, uh… 8. That’s obviously not right.

What about a date with no year, like “2/22”? I’d like it to return the date in the current year.

>> Date.parse("2/22")
=> Fri, 22 Feb 2008

>> Time.parse("2/22").to_date
=> Fri, 22 Feb 2008

>> Chronic.parse("2/22", :context => :past).to_date
=> Tue, 15 Feb 2022

Date and Time do pretty well, but even with :context => :past Chronic returns the year 2022.

What’s going on here? I’ll keep playing with it, but any insight would be appreciated.


I'm Beginning to Get Git

February 15th, 2008

I saw a great presentation about Git by Rein Henrichs at Austin on Rails the other night. I’ve heard a lot about Git, but based on what Rein said, I finally and decided to give Git a try. So far I have been extremely impressed. So impressed, in fact, that I’ve migrated the Donor Tools repository to Git, and I haven’t looked back since.

One of the best little benefits is the fact that Git only puts one .git folder at the top-level of your project, unlike Subversion, which litters every folder in your project with a .svn directory. Nice. I’m also loving the ability to branch and merge without tearing a whole in the space-time continuum.

Git takes a little getting used to. It was created by some extremely smart people (namely Linus Torvalds, who also created Linux), so the inner workings are completely beyond the scope of my comprehension. (Thanks for trying to explain it though Rein.) One of the toughest things to wrap my mind around is how to push and pull branches from remote repositories. But even baby steps with Git are more powerful than Subversion, so I’m really looking forward to becoming more experienced with Git.


The cost of freedom

February 1st, 2008

The cost of freedom is always high.

Most of the republican candidates in the race today are in favor of maintaining the war in Iraq. One of them even said that he’d keep it going for 100 years if necessary!

Now, I once heard that The War is costing us about $100,000,000,000 ($100 billion) per year. In sheer morbid curiosity, I was wondering how much that would end up costing us after 100 years. So I fired up Numbers and ran a quick, very simple calculation. Using an inflation rate of 3%, 100 years of war with Iraq would cost us…

$60,728,773,269,521

That’s 60 trillion dollars.

Please correct my math. I was wondering, maybe you can explain this to me… how would we come up with $60 trillion and still lower taxes?