<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>flouri.sh - Blog</title>
  <id>tag:flouri.sh,2008:mephisto/</id>
  <generator version="0.7.2" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://flouri.sh/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://flouri.sh/" rel="alternate" type="text/html"/>
  <updated>2008-06-25T03:52:27Z</updated>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-06-25:47</id>
    <published>2008-06-25T03:50:00Z</published>
    <updated>2008-06-25T03:52:27Z</updated>
    <category term="Technology"/>
    <link href="http://flouri.sh/2008/6/25/queryreviewer-is-now-rails-2-1-safe" rel="alternate" type="text/html"/>
    <title>QueryReviewer is now rails 2.1 safe</title>
<content type="html">
            &lt;p&gt;Thanks to a nice suggestion by the community which I pretty much used verbatim.  
Still works with rails 2.0 and 1.2.3.  Check out the project homepage.
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://code.google.com/p/query-reviewer/&quot;&gt;http://code.google.com/p/query-reviewer/&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-04-30:45</id>
    <published>2008-04-30T16:05:00Z</published>
    <updated>2008-06-20T16:07:30Z</updated>
    <category term="Work"/>
    <link href="http://flouri.sh/2008/4/30/i-m-working-at-pivotal" rel="alternate" type="text/html"/>
    <title>I'm working at Pivotal</title>
<content type="html">
            After a 4 month interlude at &lt;a href=&quot;http://www.spongefish.com&quot;&gt;SpongeFish&lt;/a&gt;,
I'm now working at &lt;a href=&quot;http://www.pivotallabs.com&quot;&gt;Pivotal Labs&lt;/a&gt;.  Pivotal's
a really fun place to do agile rails consulting and I'm loving it so far...
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-04-10:43</id>
    <published>2008-04-10T21:05:00Z</published>
    <updated>2008-04-10T21:19:12Z</updated>
    <category term="Technology"/>
    <link href="http://flouri.sh/2008/4/10/mysql-query-reviewer-now-with-ajax-and-profiling" rel="alternate" type="text/html"/>
    <title>MySQL Query Reviewer - now with AJAX and Profiling</title>
<content type="html">
            &lt;p&gt;Kevin Hall and I have released a new version of the 
&lt;a href=&quot;http://code.google.com/p/query-reviewer/&quot;&gt;query_reviewer&lt;/a&gt;
plugin. You should start by looking at my 
&lt;a href=&quot;http://flouri.sh/2008/2/13/mysql-query_reviewer-plugin&quot;&gt;first post&lt;/a&gt;, 
to see what the basic premise is before reading this article.  The single largest improvment is the ability to 
analyze the database requests of AJAX requests, which is accomplished by piggy backing javascript or HTML
into the ends of AJAX responses.
Here's what it currently looks like, analyzing
my project on a page that does lots of database requests:&lt;/p&gt;
&lt;a href=&quot;http://flouri.sh/assets/2008/4/10/Picture_4.png&quot;&gt;
  &lt;img src=&quot;http://flouri.sh/assets/2008/4/10/Picture_4.png&quot; /&gt;
&lt;/a&gt;
&lt;p&gt;The improvements are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;View query analysis for &lt;strong&gt;AJAX requests&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Take into account the &lt;strong&gt;duration&lt;/strong&gt; of a query (if production data)&lt;/li&gt;
&lt;li&gt;Show &lt;strong&gt;PROFILE&lt;/strong&gt; information from mysql&lt;/li&gt;
&lt;li&gt;Warnings for &lt;strong&gt;long key&lt;/strong&gt; lengths (which can be bad even when you hit an index)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Lots of information is now available for a single slow query:&lt;/p&gt;
&lt;a href=&quot;http://flouri.sh/assets/2008/4/10/Picture_5.png&quot;&gt;
  &lt;img src=&quot;http://flouri.sh/assets/2008/4/10/Picture_5.png&quot; /&gt;
&lt;/a&gt;
&lt;p&gt;I'm really excited that this plugin is getting attention, and welcome feedback, suggestions, and bug reports
on the &lt;a href=&quot;http://code.google.com/p/query-reviewer/&quot;&gt;Google Code project homepage&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To install it, simply visit the &lt;a href=&quot;http://code.google.com/p/query-reviewer/&quot;&gt;project homepage&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-03-30:41</id>
    <published>2008-03-30T18:07:00Z</published>
    <updated>2008-03-30T18:08:33Z</updated>
    <category term="Personal"/>
    <link href="http://flouri.sh/2008/3/30/flourish-is-back-from-the-dead" rel="alternate" type="text/html"/>
    <title>Flourish is back from the dead</title>
<content type="html">
            &lt;p&gt;Things started going very badly for flouri.sh when my home server wouldn't boot up.
I removed almost all the hardware, but could not even get a POST screen or any beeps.  I even
reseated the RAM and CPU, but no luck.  Finally, I grabbed an old media PC shuttle cube and
attempted the craziest idea:&lt;/p&gt;

&lt;img src=&quot;http://flouri.sh/assets/2008/3/30/server_lifeboat.jpg?1206900468&quot; /&gt;

&lt;p&gt;The 4 x RAID5 disks are actually being powered by my old server, but the PCI raid card is 
inserted into my old media PC.  The shuttle doesn't have enough power or room to run all those disks
so I'm using the old server as a lifeboat with 4 IDE cables running between them!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-02-18:39</id>
    <published>2008-02-18T19:11:00Z</published>
    <updated>2008-02-18T19:59:50Z</updated>
    <category term="Technology"/>
    <link href="http://flouri.sh/2008/2/18/writing-data-migrations-in-rails" rel="alternate" type="text/html"/>
    <title>Writing data migrations in rails</title>
<content type="html">
            &lt;h3&gt;Using ActiveRecord can be tricky, here's how&lt;/h3&gt;
&lt;p&gt;
Data migrations are a major headache in every rails project I've worked on.  Developers typically write straight SQL migrations which take much
longer to create and test, or they use ActiveRecord and run into problems.  I recent wrote a data migration which took 7 existing tables and
compressed them into 4.  Some of the new 4 had the same names as the existing models, so I finally figured out how to do this safely with 
ActiveRecord.  Here's my advice:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When changing the schema of an existing set of tables, create new tables and then rename them.&lt;/li&gt;
&lt;li&gt;Include active record fragments &lt;b&gt;inside the migration class&lt;/b&gt; at the top of your migrations.&lt;/li&gt;
&lt;li&gt;Put your data migrations inside transactions.&lt;/li&gt;
&lt;li&gt;Make your data migrations completely reversible (which is a lot easier when you follow the first rule)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here's an example of an ActiveRecord class fragment at the top of a migration:&lt;/p&gt;
&lt;pre class=&quot;blackboard&quot;&gt;&lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;MarkPrimaryBits&lt;span class=&quot;Superclass&quot;&gt; &lt;span class=&quot;Superclass&quot;&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Migration&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;LessonVersion&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;Entity&quot;&gt;Base&lt;/span&gt;
    &lt;span class=&quot;Support&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;lesson&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;Lesson&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;Entity&quot;&gt;Base&lt;/span&gt;
    &lt;span class=&quot;Support&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;lesson_versions&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
 
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;self.up&lt;/span&gt;
    ...
&lt;/pre&gt;
&lt;p&gt;By putting the Lesson and LessonVersion classes at the top of the migration, I'm allowing myself to use those classes inside my migration
and be &lt;i&gt;completely independent of any changes made to the real model&lt;/i&gt; from then on (including the deletion of the class itself).  
Furthermore, I can have another migration which uses those same class names with completely different meanings and they won't conflict 
with each other.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-02-15:38</id>
    <published>2008-02-15T18:11:00Z</published>
    <updated>2008-02-15T18:25:04Z</updated>
    <category term="Technology"/>
    <link href="http://flouri.sh/2008/2/15/extending-has_many-associations-correctly" rel="alternate" type="text/html"/>
    <title>Extending has_many associations correctly</title>
<content type="html">
            &lt;h3&gt;How to build custom methods on associations that aren't slow&lt;/h3&gt;
&lt;p&gt;The &quot;has_many do&quot; syntax has been widely adopted in rails, but I often see it going wrong.  Consider the following association extension:&lt;/p&gt;
&lt;pre class=&quot;blackboard&quot;&gt;&lt;span class=&quot;Support&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;versions&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;primary&lt;/span&gt;
    &lt;span class=&quot;Entity&quot;&gt;find&lt;/span&gt;(&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;first&lt;/span&gt;, &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;conditions&lt;/span&gt; =&amp;gt; {&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;primary&lt;/span&gt; =&amp;gt; &lt;span class=&quot;Constant&quot;&gt;true&lt;/span&gt;})
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;What's wrong with this code is that the finder has to execute a database request every time it's invoked.  True, rails has a query cache, but it
results in more database requests then one should need.  We can make it better by caching the result in an instance variable attached to the
association:&lt;/p&gt;
&lt;pre class=&quot;blackboard&quot;&gt;&lt;span class=&quot;Support&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;versions&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;primary&lt;/span&gt;
    &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;@&lt;/span&gt;primary&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;||=&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;find&lt;/span&gt;(&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;first&lt;/span&gt;, &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;conditions&lt;/span&gt; =&amp;gt; {&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;primary&lt;/span&gt; =&amp;gt; &lt;span class=&quot;Constant&quot;&gt;true&lt;/span&gt;})
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;But what if you already have the association loaded?  Inside the block, you can access various methods of the AssociationCollection and
AssociationProxy classes.  Notable methods are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;proxy_owner - the module that contains the association&lt;/li&gt;
&lt;li&gt;proxy_reflection - the Reflection object that contains the association options (FK, :dependent, etc)&lt;/li&gt;
&lt;li&gt;proxy_target - the cached association data, if the association has been loaded&lt;/li&gt;
&lt;li&gt;loaded? - returns true if the association has been loaded&lt;/li&gt;
&lt;li&gt;reset - delete the cached association data and forget it has been loaded&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Using these methods, we can rewrite our method to be the most efficient possible, by making use of loaded association data when present:&lt;/p&gt;
&lt;pre class=&quot;blackboard&quot;&gt;&lt;span class=&quot;Support&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;versions&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;primary&lt;/span&gt;
    &lt;span class=&quot;Keyword&quot;&gt;if&lt;/span&gt; loaded?
      &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;@&lt;/span&gt;primary&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;||=&lt;/span&gt; proxy_target.&lt;span class=&quot;Entity&quot;&gt;detect&lt;/span&gt; { |&lt;span class=&quot;Variable&quot;&gt;ver&lt;/span&gt;| ver.&lt;span class=&quot;Entity&quot;&gt;primary?&lt;/span&gt; }
    &lt;span class=&quot;Keyword&quot;&gt;else&lt;/span&gt;
      &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;@&lt;/span&gt;primary&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;||=&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;find&lt;/span&gt;(&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;first&lt;/span&gt;, &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;conditions&lt;/span&gt; =&amp;gt; {&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;primary&lt;/span&gt; =&amp;gt; &lt;span class=&quot;Constant&quot;&gt;true&lt;/span&gt;})
    &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;Now our method is guarenteed to make only 1 database call, no matter how many times invoked.  It also will make zero database calls if the
entire association has already been loaded.  The only downside is that &quot;how to determine if primary&quot; logic has to be written once in rails_sql 
and once in pure ruby.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-02-13:37</id>
    <published>2008-02-13T18:46:00Z</published>
    <updated>2008-02-13T18:47:38Z</updated>
    <category term="Work"/>
    <link href="http://flouri.sh/2008/2/13/mysql-query_reviewer-plugin" rel="alternate" type="text/html"/>
    <title>MySQL query_reviewer plugin</title>
<content type="html">
            &lt;h3&gt;query_analyzer on steriods!&lt;/h3&gt;
&lt;h4&gt;Features&lt;/h4&gt;
&lt;p&gt;QueryReviewer is an advanced SQL query analyzer.  It accomplishes the following goals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;View all EXPLAIN output for all SELECT queries to generate a page&lt;/li&gt;
&lt;li&gt;Rate a page's SQL usage into one of three categories: OK, WARNING, CRITICAL&lt;/li&gt;
&lt;li&gt;Attach meaningful warnings to individual queries&lt;/li&gt;
&lt;li&gt;Find out where the query was executed with a stack trace&lt;/li&gt;
&lt;li&gt;Display advanced interactive summary on page&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It accomplishes this by injecting an absolutely positioned div into your HTML markup before it's sent out of rails.  View injection can be 
turned off, if necessary and replaced with &amp;lt;%= query_review_output %&amp;gt; somewhere in your view.&lt;/p&gt;

&lt;h4&gt;Screenshot&lt;/h4&gt;
&lt;img src=&quot;http://flouri.sh/assets/2008/2/13/Screenshot-stevend_on_SpongeFish_-_Mozilla_Firefox.png?1202927924&quot; width=&quot;&quot; /&gt;
&lt;a href=&quot;http://flouri.sh/assets/2008/2/13/Screenshot-stevend_on_SpongeFish_-_Mozilla_Firefox.png?1202927924&quot;&gt;View larger&lt;/a&gt;

&lt;h4&gt;Project homepage&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;http://code.google.com/p/query-reviewer/&quot;&gt;http://code.google.com/p/query-reviewer/&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;Installing&lt;/h4&gt;
&lt;p&gt;svn export http://query-reviewer.googlecode.com/svn/trunk/ vendor/plugins/query_reviewer&lt;/p&gt;
&lt;p&gt;Then optionally run &quot;rake query_reviewer:setup&quot; and edit config/query_reviewer.yml to change the default settings.&lt;p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2008-01-02:36</id>
    <published>2008-01-02T21:24:00Z</published>
    <updated>2008-01-02T23:43:57Z</updated>
    <category term="Technology"/>
    <link href="http://flouri.sh/2008/1/2/mephisto-mac-com-photo-feed" rel="alternate" type="text/html"/>
    <title>mac.com "Web Gallery" Photos in Mephisto</title>
<content type="html">
            &lt;h4&gt;All the flickr functionality with better iPhoto integration!&lt;/h4&gt;
&lt;p&gt;I just finished a conversion of my existing flickr ajax mephisto plugin to use mac.com web
galleries!  I finally ended up paying for mac.com, because of the awesome integration with everything.&lt;/p&gt;
&lt;p&gt;Features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pull photos from a specific album or your entire gallery&lt;/li&gt;
&lt;li&gt;Uses AJAX to pull feed data, so it won't bottleneck your main page rendering&lt;/li&gt;
&lt;li&gt;Randomly chooses X photos to display every time&lt;/li&gt;
&lt;li&gt;A variety of supported images sizes: square, small, medium, and large&lt;/li&gt;
&lt;li&gt;Images automatically link to Apple's awesome web gallery interface&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Issues (depending on size of gallery, mine has 400 images at the time):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The RSS feed takes between 2 and 10 seconds to deliver from apple.&lt;/li&gt;
&lt;li&gt;The downloaded XML file takes 2 to 5 seconds process.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Usage&lt;/h4&gt;
&lt;p&gt;How I used it in my site:&lt;/p&gt;
&lt;pre class=&quot;blackboard&quot;&gt;&lt;span class=&quot;MetaTag&quot;&gt;&lt;span class=&quot;MetaTag&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;MetaTag&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;MetaTag&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Pictures:&lt;span class=&quot;MetaTag&quot;&gt;&lt;span class=&quot;MetaTag&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;MetaTag&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;MetaTag&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
{% macgallery feed: http://gallery.mac.com/dsboulder/?webdav-method=truthget&amp;amp;feedfmt=photocastrss  count: 4  format: square  width: 75  height: 75 %} 
{% endmacgallery %}
&lt;/pre&gt;
&lt;p&gt;Supported options to the &quot;macgallery&quot; liquid tag:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;feed: REQUIRED.  The url of the RSS feed to your gallery, or to a specific album.&lt;/li&gt;
  &lt;li&gt;count: OPTIONAL (default: 6).  The number of images to display.&lt;/li&gt;
  &lt;li&gt;format: OPTIONAL (default: square).  Also valid are &quot;small&quot;, &quot;medium&quot;, and &quot;large&quot;.&lt;/li&gt;
  &lt;li&gt;width/height: OPTIONAL (default: none).  If specified, will add width and height attributes to the IMG tag.  Useful for resizing the square images from their 160x160 default size.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Where to get the plugin&lt;/h4&gt;
&lt;code&gt;
svn checkout http://mephisto-mac-gallery-ajax.googlecode.com/svn/trunk/ vendor/plugins/mephisto_mac_gallery_ajax
&lt;/code&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2007-12-03:29</id>
    <published>2007-12-03T16:05:00Z</published>
    <updated>2007-12-01T16:12:41Z</updated>
    <link href="http://flouri.sh/2007/12/3/mephisto-uv-syntax-highlighting-plugin" rel="alternate" type="text/html"/>
    <title>Mephisto UV Syntax Highlighting Plugin</title>
<content type="html">
            &lt;p&gt;
After I wrote the article on &lt;a href=&quot;http://flouri.sh/2007/11/3/ultraviolet-syntax-highlighting-in-mephisto&quot;&gt;
hacking UV into mephisto&lt;/a&gt;, I made it an actual plugin.  The only trick was inserting a fake
codepress.rb file since mephisto requires &quot;codepress&quot; in 2 places.&lt;/p&gt;
&lt;p&gt;To get up and running:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Delete the existing &lt;code&gt;filtered_column_code_macro&lt;/code&gt; plugin.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;./script/plugin install http://wush.net/svn/public/plugins/mephisto/uv_code_macro&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Copy over UV's xhtml theme CSS files.  See &lt;a href=&quot;http://ultraviolet.rubyforge.org/usage.xhtml&quot;&gt;using UV as a library&lt;/a&gt;.&lt;br /&gt;You'll have to run something like &lt;code&gt;Uv.copy_files &quot;xhtml&quot;, &quot;public/stylesheets&quot;&lt;/code&gt; from the console&lt;/li&gt;
&lt;li&gt;Include one or more of the new stylesheets in your layout.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;&amp;lt;filter:code lang=&quot;XXXX&quot; theme=&quot;XXXX&quot;&amp;gt;&lt;/code&gt; tags to highlight your code!&lt;/li&gt;
&lt;/ul&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2007-12-01:28</id>
    <published>2007-12-01T16:00:00Z</published>
    <updated>2007-12-09T23:02:44Z</updated>
    <category term="Work"/>
    <link href="http://flouri.sh/2007/12/1/mephisto-flickr-ajax-plugin" rel="alternate" type="text/html"/>
    <title>Mephisto Flickr AJAX Loader</title>
<content type="html">
            &lt;p&gt;I'm tired of waiting for my blog to load because of a slow flickr feed request!  I designed this
new plugin by copying the flickr photostream plugin, but making it actually load the pictures
and the feed through an immediate AJAX request.  This tremendously increased the performance
of my mephisto pages!&lt;/p&gt;
&lt;p&gt;The plugin defines a flickr controller, which accepts the AJAX request.  Unfortunately,
you can't change how the photos are laid out anymore (I'm not setting up a liquid context for
this ajax response).  Of course, if you don't like the result of the plugin, just change it to
match what you want:&lt;/p&gt;
&lt;pre class=&quot;blackboard&quot;&gt;&lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;FlickrController&lt;span class=&quot;Superclass&quot;&gt; &lt;span class=&quot;Superclass&quot;&gt;&amp;lt;&lt;/span&gt; ActionController::Base&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;index&lt;/span&gt;
    result &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
    pics &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; find_pictures
    pics.&lt;span class=&quot;Entity&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do &lt;/span&gt;|&lt;span class=&quot;Variable&quot;&gt;pic&lt;/span&gt;|
      result &lt;span class=&quot;Keyword&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&amp;lt;a href='&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;#{&lt;/span&gt;pic&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;link&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;}&lt;/span&gt;&lt;/span&gt;'&amp;gt;&amp;lt;img src='&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;#{&lt;/span&gt;pic&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;send&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;(&lt;/span&gt;params&lt;span class=&quot;String&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;format&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;to_sym&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;}&lt;/span&gt;&lt;/span&gt;' alt='&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;#{&lt;/span&gt;pic&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;title&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;}&lt;/span&gt;&lt;/span&gt;'&amp;gt;&amp;lt;/a&amp;gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;Support&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Constant&quot;&gt;:&lt;/span&gt;inline&lt;/span&gt; =&amp;gt; result
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;h4&gt;How to install and use&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Uninstall the flickr photostream plugin&lt;/li&gt;
&lt;li&gt;&lt;code&gt;./script/plugin install http://wush.net/svn/public/plugins/mephisto/mephisto_flickr_ajax&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Use the following tag in your liquid template:&lt;br /&gt;
 &lt;code&gt;
{{flickrajaxphotostream feed:&amp;lt;YOUR_FEED_URL&amp;gt; count:&amp;lt;NUMBER_IMAGES&amp;gt; format:&amp;lt;[square, small, etc]&amp;gt;}}&lt;br /&gt;
{{endflickrajaxphotostream}}
&lt;/code&gt;&lt;/li&gt;
&lt;a href=&quot;http://elctech.com/2007/12/1/mephisto-flickr-ajax-loader&quot;&gt;Originally posted on ELC's blog&lt;/a&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2007-11-14:27</id>
    <published>2007-11-14T04:01:00Z</published>
    <updated>2007-11-14T04:08:13Z</updated>
    <category term="Work"/>
    <link href="http://flouri.sh/2007/11/14/rendering-views-without-a-web-request-in-rails" rel="alternate" type="text/html"/>
    <title>Rendering views without a web request in rails</title>
<content type="html">
            &lt;h4&gt;Why the heck do you want to do that?&lt;/h4&gt;
&lt;p&gt;Views are very well integrated into the rails framework, but they're only typically rendered when an
http request comes in.  ActionMailer is the main exception, but what if you want to render a view for
use in another backend application?  These days, document fragments are being used everywhere, and
often times I'll need rendered HTML for a use other than just sending it back to the requesting user.
&lt;/p&gt;
&lt;h4&gt;A solution: instantiate a controller and view&lt;/h4&gt;
&lt;p&gt;Controllers are just objects, and so are views.  We can instantiate a controller, instantiate a
view, then point the view to the controller and we're ready to go.  The only think we're missing is
the session and the request objects, but not every view needs those.  I used this once for updating a
facebook profile using a backgroundrb worker:&lt;/p&gt;
&lt;pre class=&quot;cobalt&quot;&gt;&lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;FakeView&lt;span class=&quot;EntityInheritedClass&quot;&gt; &lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;&lt;/span&gt; ActionView::Base&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;SomeHelper&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;SomeOtherHelper&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;FakeController&lt;span class=&quot;EntityInheritedClass&quot;&gt; &lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;&lt;/span&gt; ActionController::Base&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;render_some_view&lt;/span&gt;
    action_view &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;FakeView&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Support&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;join&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Variable&quot;&gt;RAILS_ROOT&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;app&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;views&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    action_view&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;instance_variable_set&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;@controller&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;LangVariable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    markup &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; action_view&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;render&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;partial&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;facebook/your_profile&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;    
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;By subclasses &lt;code&gt;ActionView::Base&lt;/code&gt;, you can mix helpers into the view class, making their
methods available.&lt;/p&gt;
&lt;h4&gt;Another solution: use the test framework!&lt;/h4&gt;
&lt;p&gt;The rails TestProcess is the only place where views are rendered.  If you really want to simulate a
real experience when rendering a view, use the test process.  First, you'll need an actual controller
with an actual action you want to render in it, like this one:
&lt;/p&gt;
&lt;pre class=&quot;cobalt&quot;&gt;&lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;FacebookController&lt;/span&gt;
  &lt;span class=&quot;SupportFunction&quot;&gt;before_filter&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;login_required&lt;/span&gt;
  
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;your_profile&lt;/span&gt;    
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;Then, we create and instante a test as follows:&lt;/p&gt;
&lt;pre class=&quot;cobalt&quot;&gt;&lt;span class=&quot;Keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;FacebookTest&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;ActionController&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;TestProcess&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;attr_reader&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;response&lt;/span&gt;
  
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;initialize&lt;/span&gt;
    &lt;span class=&quot;SupportFunction&quot;&gt;require_dependency&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;application&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;defined?&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Variable&quot;&gt;ApplicationController&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;controller&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;UserScheduleEntryController&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;new&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;request&lt;/span&gt;    &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;ActionController&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;TestRequest&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;new&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;response&lt;/span&gt;   &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;ActionController&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;TestResponse&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;new&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
  
  &lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;render_your_profile&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Variable&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;controller&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;instance_variable_set&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;@user&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; user&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;Comment&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;#&lt;/span&gt; bypass login required&lt;/span&gt;
    get &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;your_profile&lt;/span&gt;
    &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;response&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;  
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;

test &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Support&quot;&gt;FacebookTest&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;new&lt;/span&gt;&lt;/span&gt;
test&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;render_your_profile&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
markup &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; test&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;response&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;body
&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;require_dependency&lt;/code&gt; was something I threw in because backgroundrb didn't 
have some of the
required classes loaded at that point, it may not be something you need in your application.&lt;/p&gt;
&lt;a href=&quot;http://www.elctech.com/2007/11/14/rendering-views-without-a-web-request-in-rails&quot;&gt;I originally
posted this article on ELC's blog&lt;/a&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2007-11-07:26</id>
    <published>2007-11-07T21:48:00Z</published>
    <updated>2007-11-07T21:50:24Z</updated>
    <category term="Personal"/>
    <link href="http://flouri.sh/2007/11/7/tremble-at-my-fast-internet-speeds" rel="alternate" type="text/html"/>
    <title>Tremble at my fast internet speeds</title>
<content type="html">
            &lt;p&gt;Ever since moving to San Francisco, I can't believe how fast internet access can be here! Check it out:&lt;/p&gt;
&lt;img src=&quot;http://flouri.sh/assets/2007/11/7/Picture_1.png&quot; alt=&quot;speedtest_results&quot; /&gt;
&lt;p&gt;The sample above was taken at my house... middle of the day... using a cable modem with Comcast over 802.11n wireless!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2007-11-07:24</id>
    <published>2007-11-07T04:37:00Z</published>
    <updated>2007-11-07T17:57:13Z</updated>
    <category term="Work"/>
    <link href="http://flouri.sh/2007/11/7/duplicate-migrations-in-rails" rel="alternate" type="text/html"/>
    <title>Duplicate Migrations in Rails</title>
<content type="html">
            &lt;h4&gt;Why we need duplicate migrations&lt;/h4&gt;
&lt;p&gt;Have you ever been working on a large project, and had people check in migrations with the same 
numbers? It's happened to me probably no less than 10 times in the last year.  In each case, the 
situation is recoverable, but sometimes requires a lot of manual rolling back of specific migrations
on possibly several machines. Then you have to renumber all the migrations after the conflict, of course.
&lt;/p&gt;
&lt;p&gt;An even worse situation is when a project is branched and remerged. For example, you might want to 
branch out several complicated features from trunk for a few weeks, then bring them back when complete.
Assuming you create 2 feature branches (for adding profiles and friends to your users), 
you could end up with something like this:&lt;/p&gt;
&lt;code&gt;
&lt;ul&gt;
  &lt;li&gt;036_modify_users_to_include_first_name.rb&lt;/li&gt;
  &lt;li&gt;037_create_profiles.rb&lt;/li&gt;
  &lt;li&gt;037_create_friendships.rb&lt;/li&gt;
  &lt;li&gt;037_fix_a_bug.rb&lt;/li&gt;
  &lt;li&gt;038_add_timestamps_to_friendships.rb&lt;/li&gt;
  &lt;li&gt;038_modify_accounts_to_limit_length.rb&lt;/li&gt;
  &lt;li&gt;039_modify_users_to_include_gender.rb&lt;/li&gt;
&lt;/ul&gt;
&lt;/code&gt;
&lt;p&gt;In the above situation, the person merging the two branches has a very difficult situation ahead.
Everyone working on the project is probably on revision 37 (profiles branch), 38 (friends branch), or
39 (trunk).  The safe way to proceed with traditional rails migrations is to force all machines be
migrated down to 36.  No new migrations can be added while the migrations are then renumbered so they
range from 036 to 042.  Finally, all users can update from trunk and run rake db:migrate.  Of course,
people often forget to migrate down, and end up stuck in the middle of a sequence of migrations that
has been renumbered (I am so tired of reversing migrations by hand).&lt;/p&gt;
&lt;h4&gt;Solution: Allowing duplicate migration version numbers&lt;/h4&gt;
&lt;p&gt;
In the above example, the 3 migrations numbered 37 are not dependent in any way.  Because they had to
be developed independently, duplicate version numbers are very rarely dependent.  For this reason,
we beleive that it is usually safe to create a &quot;partial ordering&quot; of migrations rather than an
exact ordering.  In this partial ordering (which can be represented as a lattice), 
migrations with the same version number will be run in an arbitrary order: 
&lt;/p&gt;
&lt;img class=&quot;center&quot; src=&quot;http://elctech.com/assets/2007/11/7/Duplicate_migrations_lattice.png&quot; alt=&quot;lattice&quot; /&gt;
&lt;p&gt;
Since all of the dependencies in the above lattice flow downward, we can satisfy the partial ordering
by running the migrations alphabetically by filename, alphabetizing them first by version number and
then by class name.  This will only work if we can make the assumption that when new migrations are
added, they can only be dependent on those with smaller version numbers.
&lt;/p&gt;
&lt;h4&gt;How the plugin works&lt;/h4&gt;
&lt;p&gt;Traditional rails &lt;code&gt;schema_info&lt;/code&gt; table cannot hold enough information to keep track of
which migrations have been run, so we need to adopt a new schema format, which we place in a new
&lt;code&gt;schema_infos&lt;/code&gt; table:&lt;/p&gt;
&lt;img src=&quot;http://elctech.com/assets/2007/11/7/Picture_11.png&quot; alt=&quot;schema_infos schema&quot; /&gt;
&lt;p&gt;
In this new schema, every record represents a migration that has been run.  By traversing this table,
we can get an accurate picture of the state of the system, and decide which migration to run next.&lt;/p&gt;
&lt;p&gt;
If we want to migrate to version 10, for example, we create an alphabetical listing of migrations up
to and including version 10(s).  Then we traverse that list in order, running &quot;up&quot; on 
migrations which have not been previously run, and inserting a record into &lt;code&gt;schema_infos&lt;/code&gt;.
Finally, we create a list of migrations with version numbers
larger than 10, and run &quot;down&quot; on those in &lt;em&gt;reverse alphabetical order&lt;/em&gt;, removing the entries
in &lt;code&gt;schema_info&lt;/code&gt;.
&lt;/p&gt;
&lt;h4&gt;A little under the hood&lt;/h4&gt;
&lt;p&gt;Below is the main migrate function.  It does exactly what is discussed in the previous section:&lt;/p&gt;
&lt;pre class=&quot;cobalt&quot;&gt;&lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;migrate_with_duplicates&lt;/span&gt;
  &lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Entity&quot;&gt;migration_classes_before&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;target_version&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;each&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do &lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;|&lt;/span&gt;(&lt;span class=&quot;Variable&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;migration_class&lt;/span&gt;)&lt;span class=&quot;Punctuation&quot;&gt;|&lt;/span&gt;    
    &lt;span class=&quot;Keyword&quot;&gt;next&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Entity&quot;&gt;schema_information_contains?&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;migration_class&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;Support&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;Base&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;logger&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;info&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;Migrating up &lt;span class=&quot;StringEmbeddedSource&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;#{&lt;/span&gt;migration_class&lt;span class=&quot;Punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;StringEmbeddedSource&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;#{&lt;/span&gt;version&lt;span class=&quot;Punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;)&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
    migration_class&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;migrate&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;up&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Entity&quot;&gt;insert_schema_information&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;migration_class&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
  
  &lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Entity&quot;&gt;migration_classes_after&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;target_version&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;each&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do &lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;|&lt;/span&gt;(&lt;span class=&quot;Variable&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;migration_class&lt;/span&gt;)&lt;span class=&quot;Punctuation&quot;&gt;|&lt;/span&gt;              
    &lt;span class=&quot;Keyword&quot;&gt;next&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Entity&quot;&gt;schema_information_contains?&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;migration_class&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;Support&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;Base&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;logger&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;info&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;Migrating down &lt;span class=&quot;StringEmbeddedSource&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;#{&lt;/span&gt;migration_class&lt;span class=&quot;Punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; (&lt;span class=&quot;StringEmbeddedSource&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;#{&lt;/span&gt;version&lt;span class=&quot;Punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;)&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
    migration_class&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;migrate&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;down&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Entity&quot;&gt;remove_schema_information&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;migration_class&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;h4&gt;What would be even better...&lt;/h4&gt;
&lt;p&gt;I've always wanted to write a migration system based on partial orderings where dependencies are
explicit, and version numbers are history.  Such a system would work nicely on top of the new &lt;code&gt;
schema_infos&lt;/code&gt; table format.  The tricky part would be how to state the dependencies without
forcing the migration author to work too hard.&lt;/p&gt;
&lt;h4&gt;Download&lt;/h4&gt;
&lt;p&gt;From the ELC plugin repository: &lt;a href=&quot;http://wush.net/svn/public/plugins/duplicate_migrations/&quot;&gt;
http://wush.net/svn/public/plugins/duplicate_migrations&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To install:&lt;br /&gt;&lt;strong&gt;&lt;code&gt;./script/plugin install -x http://wush.net/svn/public/plugins/duplicate_migrations&lt;/code&gt;&lt;/strong&gt;&lt;br /&gt;
(installing automatically creates the schema_infos table and populates it, but does NOT delete your old schema_info table... don't panic!)&lt;/p&gt;
&lt;p&gt;Originally posted on &lt;a href=&quot;http://elctech.com/2007/11/7/duplicate-migrations-in-rails&quot;&gt;ELC's blog&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2007-11-05:23</id>
    <published>2007-11-05T03:30:00Z</published>
    <updated>2008-04-29T00:28:52Z</updated>
    <category term="Projects"/>
    <link href="http://flouri.sh/2007/11/5/ruby-gems-and-plugins" rel="alternate" type="text/html"/>
    <title>Ruby gems and plugins</title>
<summary type="html">This is complete list with link to every open source ruby gem and rails plugin I've written (updated every time I write something new).</summary><content type="html">
            This is complete list with link to every open source ruby gem and rails plugin I've written (updated every time I write something new).
&lt;h4&gt;A complete listing of ruby gems and rails plugins I've written&lt;/h4&gt;
&lt;ul&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://code.google.com/p/acts-as-solr-system/&quot;&gt;acts_as_solr_system&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://code.google.com/p/query-reviewer/&quot;&gt;query_reviewer&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://flouri.sh/2007/12/1/mephisto-flickr-ajax-plugin&quot;&gt;Mephisto: Flickr AJAX photo feed&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://flouri.sh/2007/12/3/mephisto-uv-syntax-highlighting-plugin&quot;&gt;Mephisto: Ultraviolet code syntax highlighting&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://wush.net/svn/public/plugins/duplicate_migrations/&quot;&gt;duplicate_migrations&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;acts_as_runnable_code_on_rails&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/gem.gif&quot; alt=&quot;gem&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://runnable-code.rubyforge.org/&quot;&gt;acts_as_runnable_code&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/gem.gif&quot; alt=&quot;gem&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://wrapped-class.rubyforge.org/&quot;&gt;acts_as_wrapped_class&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://wush.net/svn/public/wizard_form_for&quot;&gt;wizard_form_for&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/gem.gif&quot; alt=&quot;&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://wush.net/svn/public/mongrel_upload_progress_db&quot;&gt;mongrel_upload_progress_db&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://wush.net/svn/public/preload_fixtures&quot;&gt;preload_fixtures&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img class=&quot;noborder tight&quot; src=&quot;http://flouri.sh/assets/2007/11/5/plugin.png&quot; alt=&quot;plugin&quot; /&gt;&amp;nbsp;&lt;a href=&quot;http://wush.net/svn/public/use_db/&quot;&gt;use_db&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
          </content>  </entry>
  <entry xml:base="http://flouri.sh/">
    <author>
      <name>admin</name>
    </author>
    <id>tag:flouri.sh,2007-11-04:18</id>
    <published>2007-11-04T22:44:00Z</published>
    <updated>2007-11-04T22:48:05Z</updated>
    <category term="Technology"/>
    <link href="http://flouri.sh/2007/11/4/syntax-highlighting-mephistro-admin-side" rel="alternate" type="text/html"/>
    <title>Syntax highlighting Mephistro admin side</title>
<content type="html">
            &lt;h4&gt;Using CodePress to make writing blog entries easier&lt;/h4&gt;
&lt;p&gt;After I got Metphisto working with Ultraviolet syntax highlighting, I decided to make writing blog
entries easier! I already had some experience with my &lt;a href=&quot;/2007/10/15/tictactoe&quot;&gt;TicTacToe&lt;/a&gt;
project using &lt;a href=&quot;http://codepress.org&quot;&gt;CodePress&lt;/a&gt; for real-time syntax highlighting.
From there, I was able to modify Mephisto to use syntax highlighting while I was writing my articles...
the goal being to make the HTML easier to read and easier to write:&lt;/p&gt;
&lt;div class=&quot;center&quot;&gt;
  &lt;img src=&quot;http://flouri.sh/assets/2007/11/4/Picture_6.png&quot; alt=&quot;screenshot&quot; /&gt;
&lt;/div&gt;
&lt;p&gt;The first step was to install CodePress from &lt;a href=&quot;http://codepress.org&quot;&gt;codepress.org&lt;/a&gt; into the
mephistro public directory.  I ended up putting the css in /stylesheets, and the javascript in
/javascripts... &lt;b&gt;big mistake!&lt;/b&gt;  Codepress likes to be kept all together (probably best in /public), and you shouldn't have to
rewrite any of the paths in codepress.html or codepress.js, like I did. 
&lt;/p&gt;
&lt;p&gt;The second step was to include &lt;code&gt;codepress.js&lt;/code&gt; in your layout.&lt;/p&gt;
&lt;p&gt;Then I made the following modifications to &lt;code&gt;/app/views/admin/articles/_form.rhtml&lt;/code&gt; replacing
only the dd tag that defines the &quot;body&quot; textarea:
&lt;pre class=&quot;cobalt&quot;&gt;&lt;span class=&quot;MetaTagA&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;MetaTagA&quot;&gt;dd&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;EmbeddedSource&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;%=&lt;/span&gt; form&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;text_area&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;class&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;fat codepress html linenumbers-off&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;rows&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;25&lt;/span&gt;  &lt;span class=&quot;Punctuation&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;MetaTagA&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;MetaTagA&quot;&gt;br&lt;/span&gt;/&lt;span class=&quot;Punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;EmbeddedSource&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;%=&lt;/span&gt; check_box_tag &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;enable_codepress&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;1&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;onchange&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;article_body.toggleEditor();&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;amp;&lt;/span&gt;nbsp&lt;span class=&quot;Punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;  Use codepress for syntax highlighting 
  &lt;span class=&quot;EmbeddedSource&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;%=&lt;/span&gt; hidden_field_tag &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;article[body_hidden]&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;@&lt;/span&gt;article&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;body&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;Constant&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;:&lt;/span&gt;id&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;article_body_hidden&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Punctuation&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;MetaTagA&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;MetaTagA&quot;&gt;dd&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;Just changing the class of the text_area is enough to active codepress... pretty cool huh?  The
checkbox is cool too, allowing you to turn codepress on/off on the fly.
Unfortunately, I had to do some craziness with a hidden field.  Codepress does not submit the edited
data with the form, like you'd expect.  Because it creates an design-mode iframe, the browser does not
submit your code the way you want it to.  However, it provides an object on which you can call a method
to get the unformatted code.  We can copy the code into the hidden field with an onsubmit 
in &lt;code&gt;/app/views/admin/articles/new.rhtml&lt;/code&gt; and
&lt;code&gt;/app/views/admin/articles/edit.rhtml&lt;/code&gt; by adding an :onsubmit option to the form like so:&lt;p&gt;
&lt;pre class=&quot;cobalt&quot;&gt;&lt;span class=&quot;EmbeddedSource&quot;&gt;{:id =&amp;gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;article-form&lt;span class=&quot;Punctuation&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, :multipart =&amp;gt; &lt;span class=&quot;Constant&quot;&gt;true&lt;/span&gt;, &lt;/span&gt;
&lt;span class=&quot;EmbeddedSource&quot;&gt;  :onsubmit =&amp;gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;document.getElementById('article_body_hidden').value = article_body.getCode();&lt;span class=&quot;Punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;Of course, we've now got a hidden field named &lt;code&gt;article[body_hidden]&lt;/code&gt; which contains
the actual body, rather than the regular field article[body], so we need to deal with that somewhere. 
I chose &lt;code&gt;/app/models/article.rb&lt;/code&gt;, adding the following public method:&lt;/p&gt;
&lt;pre class=&quot;cobalt&quot;&gt;&lt;span class=&quot;Keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Entity&quot;&gt;body_hidden=&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Variable&quot;&gt;newval&lt;/span&gt;&lt;span class=&quot;Punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;LangVariable&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;FunctionCall&quot;&gt;&lt;span class=&quot;Punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;Entity&quot;&gt;body&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;=&lt;/span&gt; newval
&lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;This is still mostly untested, but I'm really enjoying it so far.  Uploading an asset inline
might not submit the body of the article anymore, so you'll have to a similar piece of javascript to
copy the value from the codepress object or lose your changes when you upload an image.&lt;/p&gt;
          </content>  </entry>
</feed>
