<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Chris Finne - Bay Area Ruby on Rails Developer for Startups</title>
  <id>http://127.0.0.1</id>
  <updated>2010-01-17T00:00:00Z</updated>
  <author>
    <name></name>
  </author>
  <entry>
    <title>freeze - I can Modify CONSTANTS in Ruby</title>
    <link href="http://127.0.0.1/2012/03/25/freeze---i-can-modify-constants-in-ruby/" rel="alternate"/>
    <id>http://127.0.0.1/2012/03/25/freeze---i-can-modify-constants-in-ruby/</id>
    <published>2012-03-25T00:00:00Z</published>
    <updated>2012-03-25T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;h1&gt;STOP THE PRESSES!&lt;/h1&gt;

&lt;p&gt;I can modify a CONSTANT!&lt;/p&gt;

&lt;p&gt;Whoa, that&amp;rsquo;s a bit scary. I&amp;rsquo;ve been coding in Ruby for 5 or 6 years now. I probably knew this before and forgot. After all, when I was first learning Ruby, I read &lt;a href="http://www.ruby-doc.org/docs/ProgrammingRuby/"&gt;Programming Ruby&lt;/a&gt; and this concept is likely in there (but i&amp;rsquo;m too lazy to confirm it right now). I know I&amp;rsquo;m making myself look like an idiot for going this long without fully internalizing (or forgetting) this, but oh well. I&amp;rsquo;m writing this for my own benefit. I won&amp;rsquo;t forget this concept after spending a while explaining this important Ruby concept&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;h1&gt;STOP THE PRESSES!&lt;/h1&gt;

&lt;p&gt;I can modify a CONSTANT!&lt;/p&gt;

&lt;p&gt;Whoa, that&amp;rsquo;s a bit scary. I&amp;rsquo;ve been coding in Ruby for 5 or 6 years now. I probably knew this before and forgot. After all, when I was first learning Ruby, I read &lt;a href="http://www.ruby-doc.org/docs/ProgrammingRuby/"&gt;Programming Ruby&lt;/a&gt; and this concept is likely in there (but i&amp;rsquo;m too lazy to confirm it right now). I know I&amp;rsquo;m making myself look like an idiot for going this long without fully internalizing (or forgetting) this, but oh well. I&amp;rsquo;m writing this for my own benefit. I won&amp;rsquo;t forget this concept after spending a while explaining this important Ruby concept.&lt;/p&gt;

&lt;p&gt;At least recently, I&amp;rsquo;ve been mentally assuming that I&amp;rsquo;d get an ugly warning when I&amp;rsquo;d &lt;strong&gt;modify&lt;/strong&gt; a constant:&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; FOO='bar'
=&gt; "bar"
&gt;&gt; FOO &lt;&lt; '-more-bar'
=&gt; "bar-more-bar"
&lt;/pre&gt;


&lt;p&gt;The warning I was expecting was this when I try to &lt;strong&gt;redefine&lt;/strong&gt; a constant:&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; FOO='bar'
=&gt; "bar"
&gt;&gt; FOO='not bar'
(irb):2: warning: already initialized constant FOO
=&gt; "not bar"
&lt;/pre&gt;


&lt;p&gt;But technically the first example isn&amp;rsquo;t &lt;strong&gt;redefining&lt;/strong&gt; it is &lt;strong&gt;modifying&lt;/strong&gt; the CONSTANT. Let&amp;rsquo;s look at this again using object_id:&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; FOO='bar'
=&gt; "bar"
&gt;&gt; FOO.object_id
&lt;strong&gt;=&gt; 2157596880&lt;/strong&gt;
&gt;&gt; # Modify it
&gt;&gt; FOO &lt;&lt; '-more-bar'
=&gt; "bar-more-bar"
&gt;&gt; FOO.object_id
&lt;strong&gt;=&gt; 2157596880&lt;/strong&gt;
&gt;&gt; # Redefine it
&gt;&gt; FOO='not bar'
(irb):5: warning: already initialized constant FOO
=&gt; "not bar"
&gt;&gt; FOO.object_id
&lt;strong style="color:red"&gt;=&gt; 2157574820&lt;/strong&gt;
&lt;/pre&gt;


&lt;p&gt;Note that the object_id&amp;rsquo;s changed when we &lt;strong&gt;redefined&lt;/strong&gt; but not when we modified. &lt;strong&gt;Redefining&lt;/strong&gt; is what triggers the CONSTANT warning.&lt;/p&gt;

&lt;p&gt;But I recently did something like this:&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; ARR=[1,2,3,4,5]
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; qwer=ARR
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; qwer.delete(3)
=&gt; 3
&lt;/pre&gt;


&lt;p&gt;Then later on I used ARR again, and lo and behold it was missing the 3. &lt;strong&gt;YIKES!!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s look at this again using &lt;code&gt;object_id&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; ARR=[1,2,3,4,5]
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; ARR.object_id
&lt;strong&gt;=&gt; 2157583000&lt;/strong&gt;
&gt;&gt; qwer=ARR
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; qwer.object_id
&lt;strong&gt;=&gt; 2157583000&lt;/strong&gt;
&gt;&gt; qwer.delete(3)
=&gt; 3
&lt;/pre&gt;


&lt;p&gt;Ok, that makes sense. qwer is just another pointer to the same object.&lt;/p&gt;

&lt;h1&gt;So what now?&lt;/h1&gt;

&lt;p&gt;How about both an offensive and defensive strategy. First the defense:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you don&amp;rsquo;t want it modified, then &lt;strong&gt;freeze&lt;/strong&gt; it&lt;/em&gt;&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; ARR=[1,2,3,4,5].freeze
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; qwer=ARR
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; qwer.delete(3)
TypeError: can't modify frozen array
    from (irb):10:in `delete'
    from (irb):10
&lt;/pre&gt;


&lt;p&gt;And for the offense use &lt;strong&gt;dup&lt;/strong&gt; to create a duplicate object of the CONSTANT:&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; ARR=[1,2,3,4,5].freeze
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; ARR.object_id
=&gt; 2157590400
&gt;&gt; qwer=ARR.dup
=&gt; [1, 2, 3, 4, 5]
&gt;&gt; qwer.object_id
=&gt; 2157575680
&gt;&gt; qwer.delete(3)
=&gt; 3
&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;dup&lt;/strong&gt; creates a duplicate object&lt;/p&gt;

&lt;h1&gt;Great, but&amp;hellip;&lt;/h1&gt;

&lt;pre&gt;
&gt;&gt; FOO=42
=&gt; 42
&gt;&gt; bar=FOO
=&gt; 42
&gt;&gt; FOO.object_id
=&gt; 85
&gt;&gt; bar.object_id
=&gt; 85
&gt;&gt; bar += 99
=&gt; 141
&gt;&gt; bar.object_id
=&gt; 283
&lt;/pre&gt;


&lt;p&gt;Oh yeah, in Ruby, &lt;strong&gt;Fixnum&lt;/strong&gt; and &lt;strong&gt;Float&lt;/strong&gt; aren&amp;rsquo;t ever modified, they are immutable. When you do operations on them you are just reassigning another &lt;strong&gt;Fixnum&lt;/strong&gt; or &lt;strong&gt;Float&lt;/strong&gt; to your variable, so &lt;strong&gt;dup&lt;/strong&gt; and &lt;strong&gt;freeze&lt;/strong&gt; are not needed.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Ruby - Is a Phone Number Valid for SMS?</title>
    <link href="http://127.0.0.1/2011/12/05/ruby---is-a-phone-number-valid-for-sms/" rel="alternate"/>
    <id>http://127.0.0.1/2011/12/05/ruby---is-a-phone-number-valid-for-sms/</id>
    <published>2011-12-05T00:00:00Z</published>
    <updated>2011-12-05T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;div style="clear:both"&gt;
I've used an algorithm like this in a few projects, so thought I'd post it for posterity...

&lt;script src="https://gist.github.com/1446662.js?file=gistfile1.rb"&gt;&lt;/script&gt;

</summary>
    <content type="html">&lt;div style="clear:both"&gt;
I've used an algorithm like this in a few projects, so thought I'd post it for posterity...

&lt;script src="https://gist.github.com/1446662.js?file=gistfile1.rb"&gt;&lt;/script&gt;

&lt;/div&gt;


&lt;p&gt;I&amp;rsquo;ve used it for integrating with &lt;a href="http://www.aerialink.com/"&gt;SMS Solutions on Aerialink&lt;/a&gt; and &lt;a href="http://aerialink.com/"&gt;Twilio&amp;rsquo;s API&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Parse American Dates with Ruby 1.9 (in Rails)</title>
    <link href="http://127.0.0.1/2011/10/15/parse-american-dates-with-ruby-19-in-rails/" rel="alternate"/>
    <id>http://127.0.0.1/2011/10/15/parse-american-dates-with-ruby-19-in-rails/</id>
    <published>2011-10-15T00:00:00Z</published>
    <updated>2011-10-15T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: This method no longer works as of Ruby 1.9.3. Try Jeremy Evans' GEM &lt;a href="https://github.com/jeremyevans/ruby-american_date"&gt;ruby american date&lt;/a&gt; that works with all 1.9.x versions&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: This method no longer works as of Ruby 1.9.3. Try Jeremy Evans' GEM &lt;a href="https://github.com/jeremyevans/ruby-american_date"&gt;ruby american date&lt;/a&gt; that works with all 1.9.x versions.&lt;/p&gt;

&lt;p&gt;I probably spent days peeling the onion back to this solution, so had to share to avoid others from suffering the pain.&lt;/p&gt;

&lt;p&gt;Ruby 1.8 happily parses American dates, but Ruby 1.9 refuses. When it comes to software, I&amp;rsquo;m not an ideologue. I just want to get the job done, so I won&amp;rsquo;t pontificate, bloviate, opine or ramble on this topic. I&amp;rsquo;ll find the workaround and move on with my life.&lt;/p&gt;

&lt;p&gt;In a Rails project running on Ruby 1.9, I need to parse date and date/time strings that have the American format of month/day/year. I needed to do this in pure Ruby cases as well as assigning Date and Date/Time strings to ActiveRecord fields.&lt;/p&gt;

&lt;p&gt;I tried parsing the strings before they got to ActiveRecord with stuff like:&lt;/p&gt;

&lt;pre&gt;
  Time.strptime(params[:start_at],"%m/%d/%Y %I:%M %p")
&lt;/pre&gt;


&lt;p&gt;But there are too many places to put this and this is a fragile and error-prone approach. I then found some monkey-patching solutions to work with just date strings &lt;a href="http://blog.mustmodify.com/2011/03/get-ruby-1-9-date-parse-to-assume-american-date-format.html"&gt;here&lt;/a&gt; and &lt;a href="https://gist.github.com/779859"&gt;here&lt;/a&gt;, but this still didn&amp;rsquo;t solve the Date/Time strings.&lt;/p&gt;

&lt;p&gt;I tried attacking the Date/Time string conversion in &lt;code&gt;ActiveRecord::ConnectionAdapters::Column&lt;/code&gt; similar to &lt;a href="http://blog.nominet.org.uk/tech/2007/06/14/date-and-time-formating-issues-in-ruby-on-rails/"&gt;here&lt;/a&gt; by overriding &lt;code&gt;string_to_time&lt;/code&gt; and &lt;code&gt;fast_string_to_time&lt;/code&gt;, but still had weird and inconsistent results when assigning a Date/Time string to an ActiveRecord attribute.&lt;/p&gt;

&lt;p&gt;The final solution is of course a fraction of the code I cycled through and oh so simple, just swap the month and day if the string you are parsing looks like xx/xx/xxxx. I&amp;rsquo;m hooking in a a VERY low level, Ruby&amp;rsquo;s &lt;code&gt;Date._parse()&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;
  class Date
    class &lt;&lt; self
      def _parse_with_american(str, comp=true)
        hash = _parse_without_american(str, comp)
        if str=~/\A(\d{1,2})\/(\d{1,2})\/(\d{4})/
          tmp = hash[:mon]
          hash[:mon] = hash[:mday]
          hash[:mday] = tmp
        end
        hash
      end
      alias_method_chain :_parse, :american
    end
  end
&lt;/pre&gt;


&lt;p&gt;I&amp;rsquo;m using &lt;a href="https://github.com/rails/rails/blob/13e00ce6064fd1ce143071e3531e65f64047b013/activesupport/lib/active_support/core_ext/module/aliasing.rb#L23"&gt;alias_method_chain&lt;/a&gt; from Rails, but if you are not using Rails, well, you&amp;rsquo;ll figure it out.&lt;/p&gt;

&lt;p&gt;I have no idea why there is a &lt;code&gt;Date.parse&lt;/code&gt; and a &lt;code&gt;Date._parse&lt;/code&gt;, nor do I care at this point. I&amp;rsquo;m just glad to move on to solving real problems rather than wrestling with date/time strings.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Rails 3 to_s(:db) when database time is NOT UTC</title>
    <link href="http://127.0.0.1/2011/09/23/rails-3-tosdb-when-database-time-is-not-utc/" rel="alternate"/>
    <id>http://127.0.0.1/2011/09/23/rails-3-tosdb-when-database-time-is-not-utc/</id>
    <published>2011-09-23T00:00:00Z</published>
    <updated>2011-09-23T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;I&amp;rsquo;m upgrading a Rails application from v2.x to v3.1 and the application stores its dates in MySQL in Pacific timezone rather than UTC.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ve set my config/application.rb with the following settings&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;I&amp;rsquo;m upgrading a Rails application from v2.x to v3.1 and the application stores its dates in MySQL in Pacific timezone rather than UTC.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ve set my config/application.rb with the following settings&lt;/p&gt;

&lt;pre&gt;
config.time_zone = 'Pacific Time (US &amp; Canada)'
config.active_record.default_timezone = :local
&lt;/pre&gt;


&lt;p&gt;However, I just discovered that ActiveSupport time extensions don&amp;rsquo;t really care about ActiveRecord&amp;rsquo;s default_timezone setting.&lt;/p&gt;

&lt;pre&gt;
rails31&gt;&gt; Time.now.to_s(:db)
=&gt; "2011-09-23 03:02:52"
rails31&gt;&gt; 1.second.ago.to_s(:db)
=&gt; "2011-09-23 10:02:59"
&lt;/pre&gt;


&lt;p&gt;WHAT??? I know that these are 2 different classes:&lt;/p&gt;

&lt;pre&gt;
rails31&gt;&gt; Time.now.class
=&gt; Time
rails31&gt;&gt; 1.second.ago.class
=&gt; ActiveSupport::TimeWithZone
&lt;/pre&gt;


&lt;p&gt;This is because ActiveSupport sets to UTC before doing the &amp;ldquo;to_s&amp;rdquo; which makes sense with the default Rails configuration where all dates are stored in the DB as UTC.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rails/rails/blob/master/activesupport/lib/active_support/time_with_zone.rb"&gt;https://github.com/rails/rails/blob/master/activesupport/lib/active_support/time_with_zone.rb&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;
# &lt;tt&gt;:db&lt;/tt&gt; format outputs time in UTC; all others output time in local.
# Uses TimeWithZone's +strftime+, so &lt;tt&gt;%Z&lt;/tt&gt; and &lt;tt&gt;%z&lt;/tt&gt; work correctly.
def to_s(format = :default)
  if format == :db
    utc.to_s(format)
  elsif formatter = ::Time::DATE_FORMATS[format]
    formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
  else
    "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby 1.9 Time#to_s format
  end
end
alias_method :to_formatted_s, :to_s
&lt;/pre&gt;


&lt;p&gt;I guess I understand this because I&amp;rsquo;m dealing with 2 different libraries: ActiveRecord vs ActiveSupport, but it sure threw me for a loop in some of my tests where I would sometimes create values with Time.now and other times with 1.day.ago and the time-zone conversion would fail the test.&lt;/p&gt;

&lt;p&gt;My solution to this issue is to start using .to_s(:localdb) rather than .to_s(:db)&lt;/p&gt;

&lt;pre&gt;
Time::DATE_FORMATS.merge!(:localdb=&gt;"%Y-%m-%d %H:%M:%S")
&lt;/pre&gt;




&lt;pre&gt;
rails31&gt;&gt; Time.now.to_s(:db)
=&gt; "2011-09-23 02:56:34"
rails31&gt;&gt; Time.now.to_s(:localdb)
=&gt; "2011-09-23 02:56:38"
rails31&gt;&gt; 1.second.ago.to_s(:db)
=&gt; "2011-09-23 10:02:59"
rails31&gt;&gt; 1.second.ago.to_s(:localdb)
=&gt; "2011-09-23 03:02:59"
&lt;/pre&gt;

</content>
  </entry>
  <entry>
    <title>Ruby Rails Initialize BigDecimal with commas in the String</title>
    <link href="http://127.0.0.1/2011/07/22/ruby-rails-initialize-bigdecimal-with-commas-in-the-string/" rel="alternate"/>
    <id>http://127.0.0.1/2011/07/22/ruby-rails-initialize-bigdecimal-with-commas-in-the-string/</id>
    <published>2011-07-22T00:00:00Z</published>
    <updated>2011-07-22T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;Came across a bug in the app while helping out on &lt;a href="http://www.getspotme.com/"&gt;SpotMe&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When you create a BigDecimal, it takes a String as the argument (not a Float or Fixnum)&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;Came across a bug in the app while helping out on &lt;a href="http://www.getspotme.com/"&gt;SpotMe&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When you create a BigDecimal, it takes a String as the argument (not a Float or Fixnum)&lt;/p&gt;

&lt;pre&gt;
BigDecimal.new('99')
BigDecimal.new('44.23')
&lt;/pre&gt;


&lt;p&gt;In &lt;a href="http://www.getspotme.com/"&gt;SpotMe&lt;/a&gt; when someone was entering an amount for a bill or a payment, the amount might have a comma in it. The problem is that BigDecimal ignores everything to the right of the first comma it encounters&lt;/p&gt;

&lt;pre&gt;
&gt;&gt; BigDecimal.new('1,200') == BigDecimal.new('1200')
=&gt; false

&gt;&gt; BigDecimal.new('1,200') == BigDecimal.new('1')
=&gt; true

&lt;/pre&gt;


&lt;p&gt;Monkey Patch to the rescue!&lt;/p&gt;

&lt;script src="https://gist.github.com/1099504.js?file=gistfile1.rb"&gt;&lt;/script&gt;




&lt;pre&gt;
&gt;&gt; BigDecimal.new('1,200') == BigDecimal.new('1200')
=&gt; true

&gt;&gt; BigDecimal.new('1,200') == BigDecimal.new('1')
=&gt; false

&lt;/pre&gt;


&lt;p&gt;While this concept can work for just Ruby, I used Rails' &lt;a href="http://weblog.rubyonrails.org/2006/4/26/new-in-rails-module-alias_method_chain"&gt;alias_method_chain&lt;/a&gt;. I&amp;rsquo;ve read some &lt;a href="http://yehudakatz.com/2009/03/06/alias_method_chain-in-models/"&gt;arguments&lt;/a&gt; against this &lt;a href="http://stackoverflow.com/questions/3689736/rails-3-alias-method-chain-still-used"&gt;approach&lt;/a&gt;, but in the Startup world, I&amp;rsquo;m often just trying to get the job done fast, so I like to use it.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Screen Free Day</title>
    <link href="http://127.0.0.1/2010/10/19/screen-free-day/" rel="alternate"/>
    <id>http://127.0.0.1/2010/10/19/screen-free-day/</id>
    <published>2010-10-19T00:00:00Z</published>
    <updated>2010-10-19T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;A letter came home from my son&amp;rsquo;s 2nd grade class advocating a &amp;ldquo;Wellness Week&amp;rdquo; where physical activity, nutrition, etc. are emphasized. No problems there, except that they implicitly single out technology as an enemy of health&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;A letter came home from my son&amp;rsquo;s 2nd grade class advocating a &amp;ldquo;Wellness Week&amp;rdquo; where physical activity, nutrition, etc. are emphasized. No problems there, except that they implicitly single out technology as an enemy of health.&lt;/p&gt;

&lt;p&gt;Following is my response on the class&amp;rsquo;s Shutterfly forum:&lt;/p&gt;

&lt;blockquote&gt;
I'll freely admit that we failed this miserably yesterday. While I understand promoting physical activity to improve health, I'm a vocal advocate against anti-technology campaigns like this. We live in the capital of technology where our local economy is driven by media, video games and computers. My own career in software was sparked as a kid when I re-programmed my video games.
&lt;/blockquote&gt;




&lt;blockquote&gt;
Our kids should have a healthy passion for these technologies as they make learning easier, more engaging and more accessible. It is hard to get my 2 year old to play a board game, but there are many educational games on the iPad that have enough flash to keep her attention and an interface simple enough for a toddler.
&lt;/blockquote&gt;




&lt;blockquote&gt;
I'd rather see a "handwriting-free day" where all homework and drawing is done on a computer. Handwriting is a skill that is no longer relevant in most careers and in most of life. A "book-free day" where all reading is done on a piece of technology would also be helpful. By the time our kids enter college or the workforce, there will be very few printed periodicals no more printed newspapers. The sooner our kids get used to reading and learning on devices like the iPad, Kindle and computers, the better prepared they will be for future education and employment.

&lt;/blockquote&gt;


&lt;p&gt;It also reminds me of a great Onion post about &lt;a href="http://www.theonion.com/articles/report-90-of-waking-hours-spent-staring-at-glowing,2747/"&gt;Glowing Rectangles&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Top FAILS from Apples Mac OSX</title>
    <link href="http://127.0.0.1/2010/09/23/top-fails-from-apples-mac-osx/" rel="alternate"/>
    <id>http://127.0.0.1/2010/09/23/top-fails-from-apples-mac-osx/</id>
    <published>2010-09-23T00:00:00Z</published>
    <updated>2010-09-23T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;

&lt;div style="float:right"&gt;&lt;img src="/images/imac.png" width="200"&gt;&lt;/img&gt;&lt;/div&gt;


&lt;p&gt;Just a running list of simple concepts that Microsoft had nailed years ago, but Apple still FAILS to get&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;

&lt;div style="float:right"&gt;&lt;img src="/images/imac.png" width="200"&gt;&lt;/img&gt;&lt;/div&gt;


&lt;p&gt;Just a running list of simple concepts that Microsoft had nailed years ago, but Apple still FAILS to get.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Close Window (CMD-W) and Quit Application (CMD-Q) keys are adjacent. How many times have I mis-typed and lost all my windows in TextMate? Thank god Chrome finally implemented a feature to avoid this problem.&lt;/li&gt;
&lt;li&gt;Can only resize a window from a single corner. Did the other 3 sides cost too much to implement?&lt;/li&gt;
&lt;li&gt;Apple hates the keyboard &amp;ndash; inconsistent short-cut keys and menu navigation.&lt;/li&gt;
&lt;li&gt;the &amp;ldquo;Green circle of confusion&amp;rdquo;. I want to maximize or unmaximize a window. When I click that green circle, it seems that someone is rolling the dice to decide what should happen. This seems to have gotten better with Snow Leopard, but still&amp;hellip;&lt;/li&gt;
&lt;li&gt;Going from Tiger to Leopard was ok, but Leopard to Snow Leopard? What&amp;rsquo;s next? Striped Snow Leopard? (Update: ok, they release Lion. Next one better not be Snow Lion, or Desert Lion)&lt;/li&gt;
&lt;li&gt;Snappy. I still think my old Windows XP systems had a more &amp;ldquo;snappy&amp;rdquo; / &amp;ldquo;quick&amp;rdquo; feel to the windowing environment, e.g. opening, closing, moving windows, etc.&lt;/li&gt;
&lt;/ol&gt;

</content>
  </entry>
  <entry>
    <title>Apple Showdown Magic Mouse vs Magic Trackpad</title>
    <link href="http://127.0.0.1/2010/09/04/apple-showdown-magic-mouse-vs-magic-trackpad/" rel="alternate"/>
    <id>http://127.0.0.1/2010/09/04/apple-showdown-magic-mouse-vs-magic-trackpad/</id>
    <published>2010-09-04T00:00:00Z</published>
    <updated>2010-09-04T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;

&lt;h3&gt;Apple Mice&lt;/h3&gt;

&lt;div style="float:right"&gt;&lt;img src="/images/magic-mouse.jpg" width="200"&gt;&lt;/img&gt;&lt;/div&gt;


&lt;p&gt;I&amp;rsquo;ve never liked Apple&amp;rsquo;s Mice (Mouses? Meeces?). They typically take an act of god to &amp;ldquo;click&amp;rdquo; and the Magic Mouse is no different. They are also usually a lot heavier than the popular models in the PC world. But the Magic Mouse came with my Mac Pro I got a few months ago and I decided to give it a shot; afterall, Apple does so many things right (with a few glaring exceptions), they always deserve a chance&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;

&lt;h3&gt;Apple Mice&lt;/h3&gt;

&lt;div style="float:right"&gt;&lt;img src="/images/magic-mouse.jpg" width="200"&gt;&lt;/img&gt;&lt;/div&gt;


&lt;p&gt;I&amp;rsquo;ve never liked Apple&amp;rsquo;s Mice (Mouses? Meeces?). They typically take an act of god to &amp;ldquo;click&amp;rdquo; and the Magic Mouse is no different. They are also usually a lot heavier than the popular models in the PC world. But the Magic Mouse came with my Mac Pro I got a few months ago and I decided to give it a shot; afterall, Apple does so many things right (with a few glaring exceptions), they always deserve a chance.&lt;/p&gt;

&lt;p&gt;The Magic Mouse weighs in at around 100 grams with the 2 AA batteries (about 94 grams if the batteries aren&amp;rsquo;t fully charged) which I was surprised is about the same weight as one of my standard single AA battery mice from the PC world. It feels twice the weight, but scales don&amp;rsquo;t lie. There must be some Steve Jobs Faerie Dust going on here.&lt;/p&gt;

&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;

&lt;h3&gt;Apple Laptop Trackpads&lt;/h3&gt;

&lt;div style="float:right"&gt;&lt;img src="/images/macbook-pro.png" width="200"&gt;&lt;/img&gt;&lt;/div&gt;


&lt;p&gt;I&amp;rsquo;ve had numerous Macbook Pro&amp;rsquo;s and Airs since I converted 3 years ago. I&amp;rsquo;ve loved all the trackpads and they have improved them with every model. I&amp;rsquo;ve always found laptop trackpads to be the most productive as your hand doesn&amp;rsquo;t have to leave the keyboard for many operations. So I was extremely excited when I saw the &lt;a href="http://twitter.com/#search?q=%23magic%20%23trackpad"&gt;Trackpad mentions on Twitter&lt;/a&gt;, so I hardly looked at the price before ordering in &lt;a href="http://theoatmeal.com/blog/apps"&gt;classic Oatmeal psychology&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;

&lt;h3&gt;Apple Magic Trackpads&lt;/h3&gt;

&lt;div style="float:right"&gt;&lt;img src="/images/trackpad.png" width="200"&gt;&lt;/img&gt;&lt;/div&gt;


&lt;p&gt;My first impression if the Magic Trackpad is that the area is a lot larger than I expected as I was used to the laptop-sized surfaces, but after using, the size wasn&amp;rsquo;t much of an issue.&lt;/p&gt;

&lt;p&gt;What I did find challenging is that I had to lift my had so far to use it. Granted, it was the same distance as moving my hand to the mouse, but I was subconsciously expecting it to be as easy as the movement to the laptop trackpad.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/keyboard.png" width="200"&gt;&lt;/img&gt; Although I&amp;rsquo;m right handed, I mouse left-handed which is an advantage as the Apple keyboard extra keys extend pretty far to the right, which would make hand movements much farther.&lt;/p&gt;

&lt;p&gt;So I tried aligning the Trackpad in between my hands, just below the keyboard, but the Trackpad is too big, would occasionally get brushed and its angled elevation got in the way.&lt;/p&gt;

&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;

&lt;h3&gt;The Winner &amp;ndash; Better Touch Tool + Magic Mouse&lt;/h3&gt;

&lt;div style="float:right;margin-top:10px"&gt;&lt;img src="/images/better-touch-tool.png" width="200"&gt;&lt;/img&gt;&lt;/div&gt;


&lt;p&gt;Although it worked well on its own, I gave up on the Trackpad because it the ergonomics just didn&amp;rsquo;t fit for me. I&amp;rsquo;m using the Magic Mouse with the &lt;a href="http://blog.boastr.net/"&gt;Better Touch Tool&lt;/a&gt;. This tool allows you to make the surface of the Magic Mouse behave like the Trackpad, i.e. touch-clicks. It is VERY customizable, allowing you to define what areas on the Magic Mouse correspond to what actions, e.g. left-click right-click or dead zone.&lt;/p&gt;

&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
</content>
  </entry>
  <entry>
    <title>Rails Fixture Name Starts With Test</title>
    <link href="http://127.0.0.1/2010/08/16/rails-fixture-name-starts-with-test/" rel="alternate"/>
    <id>http://127.0.0.1/2010/08/16/rails-fixture-name-starts-with-test/</id>
    <published>2010-08-16T00:00:00Z</published>
    <updated>2010-08-16T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;I&amp;rsquo;m using Rails 2.3.5 and I have a Rails model called &amp;ldquo;Testimonial&amp;rdquo;. Whenever I run my tests, I get a funky error about ActionView::TestCase.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
desktop:~/code/project chrisfinne $ ruby -Ilib:test test/unit/business_test.rb&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;I&amp;rsquo;m using Rails 2.3.5 and I have a Rails model called &amp;ldquo;Testimonial&amp;rdquo;. Whenever I run my tests, I get a funky error about ActionView::TestCase.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
desktop:~/code/project chrisfinne $ ruby -Ilib:test test/unit/business_test.rb
Loaded suite test/unit/business_test
Started
&amp;hellip;E&amp;hellip;.
Finished in 0.311574 seconds.&lt;/p&gt;

&lt;p&gt;  1) Error:
testimonials(ActionView::TestCase):
TypeError: wrong argument type Class (expected Module)
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I found this &lt;a href="https://rails.lighthouseapp.com/projects/8994/tickets/261-argumenterror-using-fixtures-named-test"&gt;Lighthouse ticket&lt;/a&gt; that tells me that I can&amp;rsquo;t have models called Test (which I already knew) and I cannot have any fixture files that &lt;em&gt;START with&lt;/em&gt; &amp;ldquo;test&amp;rdquo;, e.g. &amp;ldquo;&lt;strong&gt;test&lt;/strong&gt;imonials.yml&amp;rdquo;. I didn&amp;rsquo;t know that when I chose the name for my class. The fix is pretty easy&amp;hellip;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rename the fixture file from &amp;ldquo;test/fixtures/testimonials.yml&amp;rdquo; to something else like &amp;ldquo;test/fixtures/&lt;strong&gt;a&lt;/strong&gt;testimonials.yml&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Associate the fixture with the proper class in test/test_helper.rb&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;&lt;code&gt;
  class ActiveSupport::TestCase&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;...
set_fixture_class :atestimonials =&amp;gt; Testimonial
...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  end
&lt;/code&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Indexing Sphinx on Amazon AWS EC2 With MySQL RDS and Compression</title>
    <link href="http://127.0.0.1/2010/06/03/indexing-sphinx-on-amazon-aws-ec2-with-mysql-rds-and-compression/" rel="alternate"/>
    <id>http://127.0.0.1/2010/06/03/indexing-sphinx-on-amazon-aws-ec2-with-mysql-rds-and-compression/</id>
    <published>2010-06-03T00:00:00Z</published>
    <updated>2010-06-03T00:00:00Z</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;I&amp;rsquo;m using &lt;a href="http://aws.amazon.com/rds/"&gt;Amazon&amp;rsquo;s Relational Database Service&lt;/a&gt; which runs MySQL 5.1 on a Large EC2 instance for me.&lt;/p&gt;

&lt;p&gt;I have over 2 million records in a Rails application that I index with Sphinx&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;I&amp;rsquo;m using &lt;a href="http://aws.amazon.com/rds/"&gt;Amazon&amp;rsquo;s Relational Database Service&lt;/a&gt; which runs MySQL 5.1 on a Large EC2 instance for me.&lt;/p&gt;

&lt;p&gt;I have over 2 million records in a Rails application that I index with Sphinx.&lt;/p&gt;

&lt;p&gt;Now I&amp;rsquo;m looking at MySQL Compression.
Sphinx can use it with this switch from the &lt;a href="http://sphinxsearch.com/docs/current.html"&gt;Sphinx Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
mysql_connect_flags = 32 # enable compression
&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;Sphinx Indexing (to a RAM disk) w/o compression&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;
real    15m17.159s&lt;br/&gt;
user    14m20.330s&lt;br/&gt;
sys 0m28.630s
&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;Sphinx Indexing (to a RAM disk) w/ MySQL Compression:&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;
real    15m45.433s&lt;br/&gt;
user    14m58.080s&lt;br/&gt;
sys 0m13.310s
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So no material difference between the two.&lt;/p&gt;

&lt;p&gt;As an aside:&lt;/p&gt;

&lt;h3&gt;Sphinx Indexing (to an EBS boot disk) w/ MySQL Compression:&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;
real    16m0.305s&lt;br/&gt;
user    14m56.730s&lt;br/&gt;
sys 0m16.230s
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;so it looks like using the RAM disk on EC2 doesn&amp;rsquo;t affect indexing performance all that much.&lt;/p&gt;

&lt;h3&gt;MySQL Compression for Rails&lt;/h3&gt;

&lt;p&gt;In parallel I was also looking up &lt;a href="/2010/06/03/how-to-enable-mysql-compression-with-rails-and-the-mysql-gem/"&gt;how to enable MySQL compression in a Rails app using the MySQL gem&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
</feed>

