Eric Milford :: Web Developer & Food Advocate

Happy Halloween!

Posted by Eric Milford on October 22, 2009

Tagged with just for a laugh

Romancing Your Soul

Posted by Eric Milford on October 21, 2009

Tagged with worth thinking about

"Being with me is like a bubble bath..."

Posted by Eric Milford on October 18, 2009

Tagged with site updates, in my life

As promised, the picture albums are up. Quite faster than I had expected, honestly. You can access the most recent albums by clicking the thumbnail images at right (if you're reading this on the homepage) or by clicking the "Pictures" link in the top navigation. The current albums aren't exactly recent; I'll post new ones soon.

I spent the afternoon at the DC Improv watching the raddest new performer to hit the DC comedy scene. "She's short but she's funny", the MC said as she stepped onto the stage. Her stage name...Juicy JBro, emphasis on the Juicy. I've always enjoyed watching her in her comedic element. I was definitely proud to see her up there. Not in a father towards his son becoming a young man kind of way, but in that way that simply says I'm glad to see her doing something she wants to and working hard to achieve it.

It was a blast seeing a talented bunch of junior improvisationalists' culminate a mere 6 weeks of improv training with their graduating show. Being on stage in front of a crowd would be hard for many. Being on stage in front of a crowd and making them laugh would be hard for most. Being on stage in front of a crowd and making them laugh, while spontaneously responding to audience input is just damn impressive.

Lastly, I hate cold weather!

Read Full Post »

Ordinalized Dates w/ Ruby on Rails

Posted by Eric Milford on October 16, 2009

Tagged with ruby on rails

December 31st, 1980. It's a common enough date format that I'm surprised a "%o" format placeholder or similar isn't available for Ruby's strftime method.

1 >> d = DateTime.now
2 => Fri, 16 Oct 2009 15:11:49 -0400
3 
4 >> date.strftime('%B %o, %Y')
5 => "October o, 2009" # Uh oh
6 
7 >> date.strftime('%B %o, %Y')
8 => "October 16th, 2009" # I wish

The following line of code is what I've seen most often referenced as a solution. It's quick and effective, but the double call to date feels unnatural and not very Rails-like.

1 date.strftime("%B #{date.day.ordinalize}, %Y")

For the Ruby-only crowd, you might very well be stuck. As I mentioned above, Ruby's standard method for date formatting does not support an ordinal date. In Rails, however, the convention is to place the DATE_FORMATS inside of an initializer, config/initializer/time_formats.rb.

 1 ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
 2    :datetime_military   => '%Y-%m-%d %H:%M',
 3    :datetime            => '%Y-%m-%d %I:%M%P',
 4    :ordinalize      => lambda { |time| time.strftime("%a %b #{time.day.ordinalize}") }
 5 )
 6 
 7 >> d = DateTime.now
 8 => Fri, 16 Oct 2009 15:11:49 -0400
 9 
10 >> d.to_s(:ordinalize)
11 => "Fri Oct 16th"

Read Full Post »