<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Xor News</title>
	<atom:link href="http://www.flester.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.flester.com/blog</link>
	<description>You can't have it both ways</description>
	<pubDate>Tue, 12 Aug 2008 13:30:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Aliasing a Ruby class</title>
		<link>http://www.flester.com/blog/2008/08/12/aliasing-a-ruby-class</link>
		<comments>http://www.flester.com/blog/2008/08/12/aliasing-a-ruby-class#comments</comments>
		<pubDate>Tue, 12 Aug 2008 13:27:43 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=63</guid>
		<description><![CDATA[In a Rails system with a pretty standard user model, views, and controller, I recently found that the users_controller was getting pretty large. There was a pretty significant amount of code that I wanted to add to deal with the users using a different set of views under some circumstances &#8212; and I didn&#8217;t want [...]]]></description>
			<content:encoded><![CDATA[<p>In a Rails system with a pretty standard user model, views, and controller, I recently found that the users_controller was getting pretty large. There was a pretty significant amount of code that I wanted to add to deal with the users using a different set of views under some circumstances &#8212; and I didn&#8217;t want to add all of that to the users_controller.rb.  What I wanted was to move these functions to a staff_controller.rb, use restful routing on it and just treat the user object differently.</p>
<p>This didn&#8217;t work out so well initially. Trying to use form_for in a view always reflects on the type of object you have and sends the results right back to the users_controller &#8212; not what I wanted. I tried a bunch of stuff to force the form_for to do what I wanted but no joy. What I wanted I thought was a way to alias the user model.</p>
<pre name="code" class="ruby">
class Staff < User
end
</pre>
<p>Problem solved.</p>
<p>The User model had some nice named scopes for finders, for example:</p>
</pre>
<pre name="code" class="ruby">
  named_scope
          :recent,
          :conditions => ["created_at > ?", 2.weeks.ago]
</pre>
<p>And now I can do all of the following</p>
<pre name="code" class="ruby">
  Staff.first
  Staff.recent
  Staff.find(params[:id])
  @staff = Staff.recent.find(:all,
              :conditions => ['name = ?',"jim"])
  @staff.last_login_at = Time.now
  @staff.save!
</pre>
<p>.. which since reflection now says they are staff objects, causes<br />
all the view helpers that reflect on stuff to work properly and doesn&#8217;t<br />
break any of the ActiveRecord stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/08/12/aliasing-a-ruby-class/feed</wfw:commentRss>
		</item>
		<item>
		<title>Canon A650 Panorama Mode</title>
		<link>http://www.flester.com/blog/2008/08/09/canon-a650-panorama-mode</link>
		<comments>http://www.flester.com/blog/2008/08/09/canon-a650-panorama-mode#comments</comments>
		<pubDate>Sat, 09 Aug 2008 19:50:17 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=60</guid>
		<description><![CDATA[I may write up a better review of the new Canon A650 that I got for my birthday once I figure out a little more about how to use all of the fine features and get a little more experience. I&#8217;ve been too busy to take very many pictures recently, but I did experiment with [...]]]></description>
			<content:encoded><![CDATA[<p>I may write up a better review of the new Canon A650 that I got for my birthday once I figure out a little more about how to use all of the fine features and get a little more experience. I&#8217;ve been too busy to take very many pictures recently, but I did experiment with the panorama stitching feature while on vacation in Waves, NC.<br />
<a href='http://www.flester.com/blog/wp-content/uploads//2008/08/beach-panorama.jpg'><img src="http://www.flester.com/blog/wp-content/uploads//2008/08/beach-panorama-thumb.jpg" alt="Outer Banks, Waves, NC" title="Outer Banks, Waves NC" width="500" height="46" class="aligncenter size-full wp-image-62" /></a></p>
<p>The image is large (9MB) so don&#8217;t click if you are on dial-up. Does dial-up still exist?</p>
<p>Upon putting the camera into panorama mode, the next step is to indicate whether you will shoot moving left or moving right. The camera then lets you take up to 26 pictures and keeps showing the last 1/3 of the previous picture on the large LCD screen as an aid to lining up the next shot.</p>
<p>Having taken all the pictures they should then be downloaded to a folder on the computer. This panorama comprises 13 images shot at 3 MP resolution (the camera does 12.1 MP) and then stitched using the Canon software on Mac OS X. The stitching process took about 4 seconds. I think it did a pretty reasonable job and I&#8217;m excited to try it out some more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/08/09/canon-a650-panorama-mode/feed</wfw:commentRss>
		</item>
		<item>
		<title>Using model objects in migrations is fragile</title>
		<link>http://www.flester.com/blog/2008/08/05/using-model-objects-in-migrations-is-fragile</link>
		<comments>http://www.flester.com/blog/2008/08/05/using-model-objects-in-migrations-is-fragile#comments</comments>
		<pubDate>Tue, 05 Aug 2008 02:07:37 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=59</guid>
		<description><![CDATA[I got sucked into a trap. In a Rails migration it&#8217;s so easy to use an ActiveRecord::Base model object to update some stuff, and it looks nice and DRY. But it is extremely fragile. For example suppose your domain has a user and sponsor model. Each user has a sponsor. You start out this way:

 [...]]]></description>
			<content:encoded><![CDATA[<p>I got sucked into a trap. In a Rails migration it&#8217;s so easy to use an ActiveRecord::Base model object to update some stuff, and it looks nice and DRY. But it is extremely fragile. For example suppose your domain has a user and sponsor model. Each user has a sponsor. You start out this way:</p>
<pre name="code" class="ruby">
   def self.up
      create table :users do |t|
         t.string :name
         t.string :password
         t.string :sponsor_name
         t.timestamps
      end
   end
</pre>
<p>Later you want to insist that every user in the system have a sponsor. You already have a bunch of test data that you are intellectually invested in, so you whip up a quick migration to make sure.</p>
<pre name="code" class="ruby">
  def self.up
     User.find(:all, :conditions => 'sponsor_name IS NULL').each do |u|
         u.sponsor_name = "The Default"
         u.save!
      end
  end
</pre>
<p>Cool. Works good. You can go up and down. But some time later you realize the supreme error of your ways. You should have had a sponsor model and the user should have a sponsor_id, not a sponsor_name. Doh! What was I thinking. Time for another migration:</p>
<pre name="code" class="ruby">
   def self.up
      add_column :users, :sponsor_id, :integer
      drop_column :users, :sponsor_name
   end
</pre>
<p>and the corresponding self.down method too, and the necessary belongs_to, has_one in the user and sponsor model classes. But now you can&#8217;t migrate the database up from bootstrap any more because your use of the the User model with u.sponsor_name above will not work. The user no longer has a sponsor_name.</p>
<p>The root of the issue is that the model objects are not versioned along with the database as it goes up and down. Since fixtures just use the same model objects that doesn&#8217;t help one bit.</p>
<p>The only reliable way we have come up with is to inject data using raw sql. So step two above<br />
could change to</p>
<pre name="code" class="ruby">
  def self.up
     execute 'update users set sponsor_name = "The Default" where sponsor_name IS NULL'
  end
</pre>
<p>That works, up and down the line, because the database sql IS in sync with the database at every step.</p>
<p>Have a better way to write less brittle migrations? Let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/08/05/using-model-objects-in-migrations-is-fragile/feed</wfw:commentRss>
		</item>
		<item>
		<title>Rails Flash with Ajax</title>
		<link>http://www.flester.com/blog/2008/08/01/rails-flash-with-ajax</link>
		<comments>http://www.flester.com/blog/2008/08/01/rails-flash-with-ajax#comments</comments>
		<pubDate>Fri, 01 Aug 2008 03:38:00 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=58</guid>
		<description><![CDATA[The typical Ruby on Rails flash area is only drawn when there is a message to flash. I think something like this is fairly common (this example is haml, but that&#8217;s not the point) usually done in a partial, something like app/views/shared/_flash.html.haml:

- %w(info notice error).each do &#124;type&#124;
  - if flash[type.to_sym]
    .warning.flash_message{:class [...]]]></description>
			<content:encoded><![CDATA[<p>The typical Ruby on Rails flash area is only drawn when there is a message to flash. I think something like this is fairly common (this example is haml, but that&#8217;s not the point) usually done in a partial, something like app/views/shared/_flash.html.haml:</p>
<pre name="code" class="ruby">
- %w(info notice error).each do |type|
  - if flash[type.to_sym]
    .warning.flash_message{:class => &#8220;#{type.to_s}&#8221;}
      %span= h(flash[type.to_sym])
      %small
        %a{:href=>&#8221;#&#8221;, :onclick=>&#8221;$$(&#8217;div.flash_message&#8217;)[0].hide();return false&#8221;} Close this message
 </pre>
<p>The problem with this is that if you are Ajaxing a bunch of stuff you could use the flash area for user interaction and highlighting messages, but if it isn&#8217;t there, that could be a problem. So how about doing this instead so that the flash area is always drawn, just not displayed:</p>
<pre name="code" class="ruby">
- %w(info notice error).each do |type|
  .warning.flash_message{ :class => "#{type}", :id => "flash_#{type}", :style => "display: #{flash[type.to_sym] ? &#8216;block&#8217; : &#8216;none&#8217;}&#8221; }
    %span
      - if flash[type.to_sym]
        = h(flash[type.to_sym])
    %small
      %a{:href=>&#8221;#&#8221;, :onclick=>&#8221;$$(&#8217;div.#{type.to_s}&#8217;)[0].hide();return false&#8221;} Close this message
</pre>
<p>The flash closer is still in there so we don&#8217;t have to worry about the complexity of building that again every time, and the message is in a separate span element so it is easy to fill in. So then we can add a little bitty application helper (app/helpers/application_helper.rb)</p>
<pre name="code" class="ruby">
  def flashnow(page,msg)
    page.select("#flash_notice span").first.replace("<span>#{msg}</span>&#8220;)
    page.select(&#8221;#flash_notice&#8221;).first.show
  end
</pre>
<p>You might need to change the replace method for replaceHtml<br />
depending on the version of prototype you are working with.<br />
and call it from any view that is building an rjs response:</p>
<pre name="code" class="ruby">
  flashnow(page,'Yeeha, cowboy, it worked!')
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/08/01/rails-flash-with-ajax/feed</wfw:commentRss>
		</item>
		<item>
		<title>Cold-filtered iced-coffee</title>
		<link>http://www.flester.com/blog/2008/07/15/cold-filtered-iced-coffee</link>
		<comments>http://www.flester.com/blog/2008/07/15/cold-filtered-iced-coffee#comments</comments>
		<pubDate>Tue, 15 Jul 2008 12:51:14 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Food]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=57</guid>
		<description><![CDATA[Here&#8217;s my summer-time recipe for cold-filtered iced-coffee. If you have had iced-coffee before but it was normal hot-brewed coffee, well, please be seated before taking your first sip. : - )

Measure 8 tbs ground coffee into a quart mason jar - a nice full-city roast would be good, or a good breakfast blend, or &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s my summer-time recipe for cold-filtered iced-coffee. If you have had iced-coffee before but it was normal hot-brewed coffee, well, please be seated before taking your first sip. : - )</p>
<ol>
<li>Measure 8 tbs ground coffee into a quart mason jar - a nice <a href="http://coffee.wikia.com/wiki/Full_city_(roast)">full-city roast</a> would be good, or a <a href="http://www.kaldiscoffee.com/shop/product_details.aspx?QProductID=52980&#038;QCategoryID=25">good breakfast blend</a>, or &#8230; oh just about any good fresh coffee will do because some coffee is better than no coffee.</li>
<li>Fill the jar with some nice water, give it a stir and put on the lid</li>
<li>Place the jar on your kitchen counter, not in direct sun, overnight or 8 hours</li>
<li>Strain. I use the gold-wire filter that came with the coffee maker, straining it through twice so that the coffee ends up back in the mason jar.</li>
<li>Refrigerate the black gold, elixir of life, uh, the coffee.</li>
<li>Put some crushed ice in a tall (or grande, or vente) cup, pour in some coffee until about 2/3 full</li>
<li>Top off with cold water</li>
<li>Add a little <a href="http://www.torani.com/">Torani</a> caramel or vanilla bean, perhaps a little cream. To taste</li>
<li>Sit back and enjoy</li>
</ol>
<p>The worst thing about it is, when you want a glass full, you will have had to make it yesterday. Which is hard to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/07/15/cold-filtered-iced-coffee/feed</wfw:commentRss>
		</item>
		<item>
		<title>Pocket Bible</title>
		<link>http://www.flester.com/blog/2008/07/02/pocket-bible</link>
		<comments>http://www.flester.com/blog/2008/07/02/pocket-bible#comments</comments>
		<pubDate>Wed, 02 Jul 2008 18:55:50 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Bible Wisdom]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=54</guid>
		<description><![CDATA[Pocket Bible, the html version.
King James Version
American Standard Version
update: fixed links
]]></description>
			<content:encoded><![CDATA[<p>Pocket Bible, the html version.</p>
<p><a href="/blog/wp-content/uploads/2008/07/kjv.html">King James Version</a></p>
<p><a href="/blog/wp-content/uploads/2008/07/asv.html">American Standard Version</a></p>
<p><strong>update:</strong> fixed links</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/07/02/pocket-bible/feed</wfw:commentRss>
		</item>
		<item>
		<title>Iñtërnâtiônàlizætiøn</title>
		<link>http://www.flester.com/blog/2008/07/01/internationaliz%c3%a6ti%c3%b8n</link>
		<comments>http://www.flester.com/blog/2008/07/01/internationaliz%c3%a6ti%c3%b8n#comments</comments>
		<pubDate>Tue, 01 Jul 2008 13:29:01 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Web Technologies]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=50</guid>
		<description><![CDATA[This is a test, thanks, Sam.
A lot has changed in four years since Sam wrote that article. But there is still a lot of borked UTF-8 i18n handling out there.
So there &#8212; Iñtërnâtiônàlizætiøn. 
I&#8217;ll leave the RTL test to someone braver.
]]></description>
			<content:encoded><![CDATA[<p>This is a test, thanks, <a href="http://www.intertwingly.net/stories/2004/04/14/i18n.html">Sam</a>.<br />
A lot has changed in four years since Sam wrote that article. But there is still a lot of borked UTF-8 i18n handling out there.</p>
<p>So there &#8212; Iñtërnâtiônàlizætiøn. </p>
<p>I&#8217;ll leave the<a href="http://en.wikipedia.org/wiki/Right_to_left#Directionality"> RTL </a>test to someone braver.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/07/01/internationaliz%c3%a6ti%c3%b8n/feed</wfw:commentRss>
		</item>
		<item>
		<title>Asynchronous Jackhammer and &#8230;</title>
		<link>http://www.flester.com/blog/2008/06/21/asynchronous-jackhammer-and</link>
		<comments>http://www.flester.com/blog/2008/06/21/asynchronous-jackhammer-and#comments</comments>
		<pubDate>Sat, 21 Jun 2008 13:09:15 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Computers]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=48</guid>
		<description><![CDATA[I guess this would be in the &#8220;You know you have a problem when&#8230;&#8221; category, but I don&#8217;t want to make one of those because, well, uh, too many things might end up there.
But when you first see one of these, a chisel bladed jack-hammer bit, and the first though is &#8220;Man, XML is even [...]]]></description>
			<content:encoded><![CDATA[<p>I guess this would be in the &#8220;You know you have a problem when&#8230;&#8221; category, but I don&#8217;t want to make one of those because, well, uh, too many things might end up there.</p>
<p>But when you first see one of these, a chisel bladed jack-hammer bit, and the first though is &#8220;Man, XML is even pervasive in *that* industry too!&#8221;, well, I don&#8217;t know what other category it could go in.<br />
<a href='http://www.flester.com/blog/wp-content/uploads//2008/06/00001.jpg'><img src="http://www.flester.com/blog/wp-content/uploads//2008/06/00001.jpg" alt="Asynchronous JackHammer and XML" title="Asynchronous JackHammer and XML" width="450" height="337" class="alignnone size-medium wp-image-49" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/06/21/asynchronous-jackhammer-and/feed</wfw:commentRss>
		</item>
		<item>
		<title>Cornus Kousa</title>
		<link>http://www.flester.com/blog/2008/06/21/cornus-kousa</link>
		<comments>http://www.flester.com/blog/2008/06/21/cornus-kousa#comments</comments>
		<pubDate>Sat, 21 Jun 2008 13:04:19 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Family]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=46</guid>
		<description><![CDATA[
Want Biscuit with that Cornus Kousa?
]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.flester.com/blog/wp-content/uploads//2008/06/00029.jpg'><img src="http://www.flester.com/blog/wp-content/uploads//2008/06/00029.jpg" alt="" title="Biscuit with C. Kousa" width="262" height="350" class="alignnone size-medium wp-image-47" /></a><br />
Want Biscuit with that Cornus Kousa?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/06/21/cornus-kousa/feed</wfw:commentRss>
		</item>
		<item>
		<title>Ages of Isaac, Jacob and Joseph</title>
		<link>http://www.flester.com/blog/2008/06/05/ages-of-isaac-jacob-and-joseph</link>
		<comments>http://www.flester.com/blog/2008/06/05/ages-of-isaac-jacob-and-joseph#comments</comments>
		<pubDate>Thu, 05 Jun 2008 18:45:52 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flester.com/blog/?p=44</guid>
		<description><![CDATA[Mr. Ryrie&#8217;s notes have it that when Jacob deceived Isaac, Isaac being old and thinking that he was preparing to die, that Isaac went on to live another 43 years. It&#8217;s not obvious how he gets this and so here is how it&#8217;s done, first in text, then with a picture.

Joseph was 39 when Jacob [...]]]></description>
			<content:encoded><![CDATA[<p>Mr. Ryrie&#8217;s notes have it that when Jacob deceived Isaac, Isaac being old and thinking that he was preparing to die, that Isaac went on to live another 43 years. It&#8217;s not obvious how he gets this and so here is how it&#8217;s done, first in text, then with a picture.</p>
<ol>
<li>Joseph was 39 when Jacob came to Egypt. Jacob was 130 (45:11 + 47:9)</li>
<li>Jacob was 91 when Joseph was born (subtract 39 from both sides)</li>
<li>Jacob had been in Padan Aram 14 years when Joseph was born (30:25 + 31:41)</li>
<li>Jacob was 77 when he stole the blessing and left home (subtract 14 from 91)</li>
<li>Isaac was 60 years old when Jacob was born (25:26)</li>
<li>Isaac was 137 when Jacob stole the blessing (60 + 77)</li>
<li>Isaac lived 43 more years to 180 (35:28)</li>
</ol>
<p>In the picture, (click to see a larger view) just use the red horizontal arrows to align the columns and work forward from Jacob&#8217;s birth and backwards from Joseph in Egypt. Simple.<br />
<a href='http://www.flester.com/blog/wp-content/uploads//2008/06/isaac-jacob-joseph.jpg'><img src="http://www.flester.com/blog/wp-content/uploads//2008/06/isaac-jacob-joseph.jpg" alt="" title="isaac-jacob-joseph" width="262" height="350" class="alignnone size-medium wp-image-45" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flester.com/blog/2008/06/05/ages-of-isaac-jacob-and-joseph/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
