Parse European Date Formats in Ruby 1.8.6 and 1.8.7

The parse method in Ruby favours US mm-dd-yyyy date formats over European style dd-mm-yyyy formats. Ruby on rails uses the parse method to process Dates from String to Date objects, particularly in form processing. As a result, you need a heavy weight library or some pretty ugly string bashing to parse European formats by default.

Here's code I put together for Ruby 1.8.6 and 1.8.7 that will allow you to parse European dates by default. Throw this code in config/initializers/time_parsing.rb

mDate::Format::EuropeanDates
  def self.included(base)
    base.class_eval do
      class << self
        if RUBY_VERSION == '1.8.6'
          # From here: http://fatvegan.com/2008/05/27/european-dates-in-ruby-on-rails/
          alias_method :_parse_sla_us, :_parse_sla_eu
        else
          # Rewrite Ruby's _parse_sla method.
          def _parse_sla(str, e) # :nodoc:
            if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
              s3e(e, $3, $2, $1)
              true
            end
          end
        end
      end
    end
  end
end
 
Date.send(:include, Date::Format::EuropeanDate
module Date::Format::EuropeanDates
  def self.included(base)
    base.class_eval do
      class << self
        if RUBY_VERSION == '1.8.6'
          # From here: http://fatvegan.com/2008/05/27/european-dates-in-ruby-on-rails/
          alias_method :_parse_sla_us, :_parse_sla_eu
        else
          # Rewrite Ruby's _parse_sla method.
          def _parse_sla(str, e) # :nodoc:
            if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|n, ' ') # '
              s3e(e, $3, $2, $1)
              true
            end
          end
        end
      end
    end
  end
end

Date.send(:include, Date::Format::EuropeanDates)

Analytical Vs. Creative

Having worked closely with a couple of creative guys over the last year and a half, I've started looking more at the concept of design and creativity. As an (arguably) analytical guy with an open mind, I find discussion and literature on design and creativity, fresh and enlightening. It's simple a perspective I've largely ignored until now. Here's a snapshot of where my head is at right now with regards to creativity in business. This brown circle is what we know. Note that it's defined by a definite border. The fuzzy brown bit is what we don't know. The fuzzy brown bit disappears randomly because we don't know what we don't know. In order to process information within these two worlds we need two different sets of tools... We need analytical tools to process what we know and creative tools to process what we don't know. How do you process what you don't know? This might be a hint... Inference is the process of logical deduction. Extrapolation is the process of exploration. Everyone is familiar with processing what we know. The world is heavily biased to this concept. School is heavily biased in this direction. It's quantitative, easy to measure, and provable based on prior measurements. Creativity is based in that part of the world that we don't know. Creative territory requires imagination to reach. There is a clear change in paradigm between wading in the analytical pool, and floating in the creative abyss. Unfortunately in our world, creativity plays second to the analytical. Creativity is hard to measure, prove, and teach. People fear the unknown. Creativity is harder to translate in to Return On Investment. Here's the truth... Analytics and creativity are symbiotic. One doesn't survive without the other. Analytics processes what we know, and creativity finds stuff to know. Part of this idea is illustrated here... The truth finder represented by the circle is simply "some process" that finds truth from ideas. This is only part of the story though, knowledge spurs creativity... Creativity depends on knowledge, and vice versa. Analytics and creativity are just tools to process the known and unknown. A business that ignores creativity will become obsolete, stale, broke. A company that ignores analytics will never gain traction, floating, useless. All very well, and maybe even correct. But, how does this help you? Creatives: Spend more time grounded. Perhaps, take time to look at your market, your finances, your place within this world. Drop your pretensions. Analyticals: Take time to dream. Drop your assumptions, ignore your fears of the unknown, leave your ego behind. Embrace what you don't know.

Cleaning My Whiteboard

Hello world! I have a whiteboard in my office that I use as a semi-permanent scratch pad. When I have important miscellaneous information I usually write it on the edge of my whiteboard, leaving the middle of the board for working stuff out. Anyway, over the years I've had "whiteboard creep" where the edges have filled up and I've had to encroach on the middle of the board. It's time to take back control, so I'm going to transfer stuff from the edge of my whiteboard to this blog and then wipe the board clean. (what a random post...) Writing Copy Marketing copy should describe why your product/service/offer is...
  • Ultra specific
  • Urgent
  • Unique
  • Useful
Dynamic Keywords In Adwords You can use {keyword: default} to pull in the searched keyword in to your adword ads. You can change keyword to Keyword or KeyWord to capitalise the first word, or each word of the dynamic component. eCPM On an experiment site I was receiving $3.5 eCPM. The site was receiving 3,000 page views / month. Typical Mac Site PDFpen is a typical Mac software website and if I were to build Mac software then my website would look something like that one.