<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xml:lang="en" xml:base="http://derekdevries.com/wp-atom.php">
	<title type="text">Derek DeVries</title>
	<subtitle type="text" />

	<updated>2009-09-04T19:02:54Z</updated>
	<generator uri="http://wordpress.org/" version="2.7.1">WordPress</generator>

	<link rel="alternate" type="text/html" href="http://derekdevries.com" />
	<id>http://derekdevries.com/feed/atom/</id>
	

			<link rel="self" href="http://feeds.feedburner.com/devrieda" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Rails Seed Data]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2009/04/13/rails-seed-data/" />
		<id>http://derekdevries.com/?p=72</id>
		<updated>2009-09-04T19:02:54Z</updated>
		<published>2009-04-13T05:58:03Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" />		<summary type="html"><![CDATA[Seed data in Rails applications has been <a href="http://railspikes.com/2008/2/1/loading-seed-data">discussed</a> <a href="http://quotedprintable.com/2007/11/16/seed-data-in-rails">ad</a> <a href="http://stackoverflow.com/questions/62201/how-and-whether-to-populate-rails-application-with-initial-data">nauseum</a>, but I wanted to throw out another simple option that I use quite regularly. I've essentially found that seed data for my applications comes in three different flavors. ]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2009/04/13/rails-seed-data/"><![CDATA[<p>Seed data in Rails applications has been <a href="http://railspikes.com/2008/2/1/loading-seed-data">discussed</a> <a href="http://quotedprintable.com/2007/11/16/seed-data-in-rails">ad</a> <a href="http://stackoverflow.com/questions/62201/how-and-whether-to-populate-rails-application-with-initial-data">nauseum</a>, but I wanted to throw out another simple option that I use quite regularly. I&#8217;ve essentially found that seed data for my applications comes in three different flavors. </p>
<h3>1. Always seed</h3>
<p>We wipe out and reload this seed data multiple times in a application&#8217;s lifetime. A good example of this in <a href="http://sportspyder.com">SportSpyder</a> is the list of sports such as MLB, NFL, etc. This data is never modified by the application itself, and is essentially read-only. If we want to add a new sport, we can wipe out and reload the seed data for the table without repercussions. </p>
<h3>2. Seed once</h3>
<p>We seed this data to the table only once. A good example of this is inserting an application&#8217;s first Admin user. After seeding the initial data, the application takes over modification and maintenance of the data in that table. You would never want to reseed the table at a later time since this would wipe out additional data added by other means.</p>
<h3>3. Development/Dummy data</h3>
<p>This is dummy data that we throw into an application to check out how things look before we go live with real content in the application. </p>
<h3>Loading the data</h3>
<p>Lately I&#8217;ve tossed aside test fixtures in favor of using <a href="http://www.thoughtbot.com/projects/factory_girl">FactoryGirl</a> for testing, but I find yaml files work fine for most seed data (as long as there isn&#8217;t too much of it.) You could probably incorporate this idea into object based seeding options as well. </p>
<p>To handle the three different types of seed data, we create a few subdirectories within <code>db/</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> db<span style="color: #000000; font-weight: bold;">/</span>seed<span style="color: #000000; font-weight: bold;">/</span>always
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> db<span style="color: #000000; font-weight: bold;">/</span>seed<span style="color: #000000; font-weight: bold;">/</span>develop
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> db<span style="color: #000000; font-weight: bold;">/</span>seed<span style="color: #000000; font-weight: bold;">/</span>once</pre></div></div>

<p>In here we put YML based fixture files with the data we want to load. One thing to remember is that you probably want to manually specify the <code>id</code>s instead of relying on foxy fixtures. You don&#8217;t want your <code>id</code> column starting at numbers like <code>237252458</code>. </p>
<p>We then add a new file named <code>lib/tasks/db.rake</code> with the following tasks:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record/fixtures'</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Seed the database with once/ and always/ fixtures.&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:seed</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
    load_fixtures <span style="color:#996600;">&quot;seed/once&quot;</span>
    load_fixtures <span style="color:#996600;">&quot;seed/always&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:always</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Seed the database with develop/ fixtures.&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:develop</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
    load_fixtures <span style="color:#996600;">'seed/develop'</span>, <span style="color:#ff3333; font-weight:bold;">:always</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
  private
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> load_fixtures<span style="color:#006600; font-weight:bold;">&#40;</span>dir, always = <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'db'</span>, dir, <span style="color:#996600;">'*.yml'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>fixture_file<span style="color:#006600; font-weight:bold;">|</span>
      table_name = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>fixture_file, <span style="color:#996600;">'.yml'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">if</span> table_empty?<span style="color:#006600; font-weight:bold;">&#40;</span>table_name<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> always
        truncate_table<span style="color:#006600; font-weight:bold;">&#40;</span>table_name<span style="color:#006600; font-weight:bold;">&#41;</span>
        Fixtures.<span style="color:#9900CC;">create_fixtures</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'db/'</span>, dir<span style="color:#006600; font-weight:bold;">&#41;</span>, table_name<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> table_empty?<span style="color:#006600; font-weight:bold;">&#40;</span>table_name<span style="color:#006600; font-weight:bold;">&#41;</span>
    quoted = connection.<span style="color:#9900CC;">quote_table_name</span><span style="color:#006600; font-weight:bold;">&#40;</span>table_name<span style="color:#006600; font-weight:bold;">&#41;</span>
    connection.<span style="color:#9900CC;">select_value</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;SELECT COUNT(*) FROM #{quoted}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_i</span>.<span style="color:#9900CC;">zero</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> truncate_table<span style="color:#006600; font-weight:bold;">&#40;</span>table_name<span style="color:#006600; font-weight:bold;">&#41;</span>
    quoted = connection.<span style="color:#9900CC;">quote_table_name</span><span style="color:#006600; font-weight:bold;">&#40;</span>table_name<span style="color:#006600; font-weight:bold;">&#41;</span>
    connection.<span style="color:#9900CC;">execute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;DELETE FROM #{quoted}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> connection
    <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And that&#8217;s it. You can now seed your data by running:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rake db:seed</pre></div></div>

<p>And insert development/dummy data with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rake db:develop</pre></div></div>

]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2009/04/13/rails-seed-data/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2009/04/13/rails-seed-data/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Custom Buttons with CSS]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2009/04/02/custom-buttons-with-css/" />
		<id>http://derekdevries.com/?p=44</id>
		<updated>2009-04-02T06:57:19Z</updated>
		<published>2009-04-02T06:51:38Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" />		<summary type="html"><![CDATA[While localizing our <a href="http://maintainabletest.com/">Automated Test Database</a> software, we found the need for a better solution for styling buttons. This post covers using CSS to style buttons using  both the &#60;button&#62; and &#60;a&#62; tags across all major browsers.

]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2009/04/02/custom-buttons-with-css/"><![CDATA[<p>While localizing our <a href="http://maintainabletest.com/">Automated Test Database</a> software, we found the need for a better solution for styling buttons. Our requirements were: </p>
<ol>
<li>Consistent CSS based buttons for both <code>&lt;button&gt;</code> and <code>&lt;a&gt;</code> elements.</li>
<li>Active, hover, primary, and disabled button states.</li>
<li>Compatible and consistently in IE6, IE7, IE8, Firefox, Safari, and Chrome.</li>
<li>Semantic markup.</li>
</ol>
<p>I found a few blog posts that cover some (or most) of these requirements, but none of them seem to cover them all. Most concentrate on either the button or anchor tag, but not both. </p>
<p>I&#8217;ve created a GitHub project &#8212; <a href="http://github.com/devrieda/custom_buttons/tree/master">custom_buttons</a> that contains XHTML, CSS, and images for buttons to do it all. There are two different examples &#8212; a round button, and a more rectangular button. The code takes advantage of the <a href="http://alistapart.com/articles/slidingdoors/">sliding doors technique</a> so that the button expands to fit the size of the text. </p>
<p>The markup for styling a <code>&lt;button&gt;</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;button round_button&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Submit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;button round_button primary&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Submit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;button round_button disabled&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Submit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And the markup for styling an <code>&lt;a&gt;</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;button round_button&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Submit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;button round_button primary&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Submit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;button round_button disabled&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Submit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The result from both examples:<br />
<img src="http://derekdevries.com/wp-content/uploads/2009/04/buttons.gif" alt="buttons" title="buttons" width="228" height="52" class="alignnone size-full wp-image-19" /></p>
<p>In my examples I use the &#8220;round_button&#8221; and &#8220;rect_button&#8221; classes to differentiate between multiple button styles that use the same technique. If you only require a single button style, you can probably get away with simplifying the code to just use <code>class="button"</code>.</p>
<p>A lot of this code is based on content in the following articles (and their helpful comments):</p>
<p><a href="http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html">How to make sexy buttons with CSS</a><br />
<a href="http://stopdesign.com/archive/2009/02/04/recreating-the-button.html">Recreating the button</a><br />
<a href="http://particletree.com/features/rediscovering-the-button-element/">Rediscovering the button element</a><br />
<a href="http://www.filamentgroup.com/lab/styling_the_button_element_with_sliding_doors/">Styling the button element with sliding doors</a></p>
]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2009/04/02/custom-buttons-with-css/#comments" thr:count="10" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2009/04/02/custom-buttons-with-css/feed/atom/" thr:count="10" />
		<thr:total>10</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Auditing UX with Documentation]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2008/05/07/auditing-user-experience-with-documentation/" />
		<id>http://derekdevries.com/?p=17</id>
		<updated>2009-04-13T05:58:59Z</updated>
		<published>2008-05-08T00:16:10Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="ux" />		<summary type="html"><![CDATA[End-user documentation has always been a thorn for many developers. We'd much rather be writing working software than explaining how that software works. It is especially difficult working in an agile environment where things change so quickly that writing extensive end-user documentation just slows down application development. ]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2008/05/07/auditing-user-experience-with-documentation/"><![CDATA[<p>End-user documentation has always been a thorn for many developers. We&#8217;d much rather be writing working software than explaining how that software works. It is especially difficult working in an agile environment where things change so quickly that writing extensive end-user documentation just slows down application development. </p>
<p>One real benefit of end-user documentation is that it generally will help make your application better. When you&#8217;re explaining in depth how to use your application, it becomes immediately obvious where you&#8217;re application is deficient, confusing, or inconsistent. </p>
<p>Try writing a walk-through of your application. Write down what each element of your application does, and why. If you find areas that are confusing to write down, chances are you&#8217;ll be getting an e-mail from a client who is confused as well. </p>
]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2008/05/07/auditing-user-experience-with-documentation/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2008/05/07/auditing-user-experience-with-documentation/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Configuring Sphinx on Leopard]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2008/04/05/configuring-sphinx-on-os-x-leopard/" />
		<id>http://derekdevries.com/?p=14</id>
		<updated>2009-02-24T04:13:11Z</updated>
		<published>2008-04-05T21:55:25Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="sphinx osx" />		<summary type="html"><![CDATA[I ran into a few small errors when installing <a href="http://www.sphinxsearch.com/">Sphinx</a> on my Mac Book Pro. I'll share my install instructions along with a couple troubleshooting tips for others that may have the same problems. 

]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2008/04/05/configuring-sphinx-on-os-x-leopard/"><![CDATA[<p>I ran into a few small errors when installing <a href="http://www.sphinxsearch.com/">Sphinx</a> on my Mac Book Pro. I&#8217;ll share my install instructions along with a couple troubleshooting tips for others that may have the same problems. </p>
<p>Let&#8217;s start with the instructions for installing the latest version to <code>/usr/local</code>. If you&#8217;re not familiar with what this means, check out Dan&#8217;s article on <a href="http://hivelogic.com/articles/using_usr_local/">Using /usr/local</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.sphinxsearch.com<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>sphinx-0.9.8-rc2.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzf</span> sphinx-0.9.8-rc2.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> sphinx-0.9.8-rc2
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-fr</span> sphinx-0.9.8-rc2<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<h3>Troubleshooting</h3>
<p>If you&#8217;re installing Sphinx on Leopard on the 64 bit architecture you need to run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LDFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> .<span style="color: #000000; font-weight: bold;">/</span>configure</pre></div></div>

<p>If <code>make</code> is throwing you an error that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
<span style="color: #c20cb9; font-weight: bold;">make</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>sphinx.o<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #000000;">1</span>
<span style="color: #c20cb9; font-weight: bold;">make</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>all<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #000000;">2</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>: <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>all-recursive<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #000000;">1</span></pre></div></div>

<p>You may need to specify the path to mysql using the <inlinecode>&#8211;with-mysql</inlinecode> option to <inlinecode>./configure</inlinecode>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-mysql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>mysql</pre></div></div>

<p>If <code>make</code> is throwing you an error that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sphinx.cpp:<span style="color: #000000;">17343</span>: error: ‘XML_STATUS_ERROR’ was not declared <span style="color: #000000; font-weight: bold;">in</span> this scope
sphinx.cpp:<span style="color: #000000;">17367</span>: error: ‘XML_STATUS_OK’ was not declared <span style="color: #000000; font-weight: bold;">in</span> this scope
sphinx.cpp: In member <span style="color: #000000; font-weight: bold;">function</span> ‘bool CSphSource_XMLPipe2::ParseNextChunk<span style="color: #7a0874; font-weight: bold;">&#40;</span>int, CSphString<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>’:
sphinx.cpp:<span style="color: #000000;">17775</span>: error: ‘XML_STATUS_OK’ was not declared <span style="color: #000000; font-weight: bold;">in</span> this scope
<span style="color: #c20cb9; font-weight: bold;">make</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>sphinx.o<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #000000;">1</span>
<span style="color: #c20cb9; font-weight: bold;">make</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>all<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #000000;">2</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>: <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>all-recursive<span style="color: #7a0874; font-weight: bold;">&#93;</span> Error <span style="color: #000000;">1</span></pre></div></div>

<p>This is from having an incompatible version of <code>expat</code> installed. Here are instructions for installing the latest version of expat.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">-O</span> <span style="color: #660033;">-L</span> http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>expat<span style="color: #000000; font-weight: bold;">/</span>expat-2.0.1.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzf</span> expat-2.0.1.tar.gz 
<span style="color: #7a0874; font-weight: bold;">cd</span> expat-2.0.1
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> 
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-fr</span> expat-2.0.1<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2008/04/05/configuring-sphinx-on-os-x-leopard/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2008/04/05/configuring-sphinx-on-os-x-leopard/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Syncing to Time Capsule]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2008/04/05/syncing-to-time-capsule-from-terminal/" />
		<id>http://derekdevries.com/?p=13</id>
		<updated>2009-02-24T04:13:24Z</updated>
		<published>2008-04-05T21:29:36Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="osx terminal" />		<summary type="html"><![CDATA[I got really excited about the <a href="http://www.apple.com/timecapsule/">Apple Time Capsule</a> when it was released. I had two 500GB duplicate external hard drives chained off of my Mac Book Pro to backup my rather large collection of media. I typically use <a href="http://en.wikipedia.org/wiki/Rsync">rsync</a> to copy files to the drives and keep them in sync. ]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2008/04/05/syncing-to-time-capsule-from-terminal/"><![CDATA[<p>I got really excited about the <a href="http://www.apple.com/timecapsule/">Apple Time Capsule</a> when it was released. I had two 500GB duplicate external hard drives chained off of my Mac Book Pro to backup my rather large collection of media. I typically use <a href="http://en.wikipedia.org/wiki/Rsync">rsync</a> to copy files to the drives and keep them in sync. </p>
<p>The only problem with my setup was that it required me to connect these drives to my laptop and eject them as I move my computer around the house. Time Capsule solves this by making my setup wireless. </p>
<p>You can view the hard drive volumes mounted on your Mac from the terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes
.<span style="color: #000000; font-weight: bold;">/</span>                    Macintosh HD<span style="color: #000000; font-weight: bold;">@</span>
..<span style="color: #000000; font-weight: bold;">/</span>                   Derek<span style="color: #ff0000;">'s Time Capsule/</span></pre></div></div>

<p>When using a Time Capsule drive, it may not appear in <code>/Volumes</code> if it isn&#8217;t mounted. You can mount your drive with a simple bash script that uses <code>mount_afp</code>.</p>
<p>Save as mount_capsule.sh</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># configure - enter your capsule name, ip, and username:password</span>
<span style="color: #007800;">CAP_NAME</span>=<span style="color: #ff0000;">&quot;Derek's Time Capsule&quot;</span>
<span style="color: #007800;">CAP_IP</span>=<span style="color: #ff0000;">&quot;192.168.1.103&quot;</span>
<span style="color: #007800;">USER</span>=<span style="color: #ff0000;">&quot;username:password&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/Volumes/<span style="color: #007800;">$CAP_NAME</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[info] Mounting <span style="color: #007800;">$CAP_NAME</span>...&quot;</span>
&nbsp;
  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #ff0000;">&quot;/Volumes/<span style="color: #007800;">$CAP_NAME</span>&quot;</span>
  mount_afp <span style="color: #ff0000;">&quot;afp://<span style="color: #007800;">$USER</span>@<span style="color: #007800;">$CAP_IP</span>/<span style="color: #007800;">$CAP_NAME</span>&quot;</span> <span style="color: #ff0000;">&quot;/Volumes/<span style="color: #007800;">$CAP_NAME</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[info] <span style="color: #007800;">$CAP_NAME</span> mounted&quot;</span></pre></div></div>

<p>And now let&#8217;s make the script executable and run it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">744</span> mount_capsule.sh
$<span style="color: #000000; font-weight: bold;">&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>mount_capsule.sh
<span style="color: #7a0874; font-weight: bold;">&#91;</span>info<span style="color: #7a0874; font-weight: bold;">&#93;</span> Mounting Derek<span style="color: #ff0000;">'s Time Capsule...
[info] Derek'</span>s Time Capsule mounted</pre></div></div>

<p>Once we&#8217;ve mounted the drive, we can proceed to copy/move/rsync data to it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>derek<span style="color: #000000; font-weight: bold;">/</span>work <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>Derek<span style="color: #ff0000;">'s Time Capsule/backup</span></pre></div></div>

]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2008/04/05/syncing-to-time-capsule-from-terminal/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2008/04/05/syncing-to-time-capsule-from-terminal/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[The Upper Class]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2008/03/26/the-upper-class/" />
		<id>http://derekdevries.com/?p=12</id>
		<updated>2009-02-24T03:42:15Z</updated>
		<published>2008-03-26T23:27:33Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="ruby" />		<summary type="html"><![CDATA[Today I did a presentation on Ruby object inheritance for the <a href="http://www.techvalleyrb.org/">Tech Valley Ruby Brigade</a>. Here are <a href="http://assets.derekdevries.com/presentations/2008/the_upper_class.pdf">the slides</a>. ]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2008/03/26/the-upper-class/"><![CDATA[<p>Today I did a presentation on Ruby object inheritance for the <a href="http://www.techvalleyrb.org/">Tech Valley Ruby Brigade</a>. Here are <a href="http://assets.derekdevries.com/presentations/2008/the_upper_class.pdf">the slides</a>. Some of the presentation is based off material in the first chapter of <a href="http://www.amazon.com/gp/redirect.html%3FASIN=0596510322%26tag=sportspyder-20%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596510322%253FSubscriptionId=1RVMD8N7EVCFF8RR1CG2">Advanced Rails</a>. </p>
]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2008/03/26/the-upper-class/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2008/03/26/the-upper-class/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Rails for PHP Reference]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2008/03/21/rails-for-php-reference/" />
		<id>http://derekdevries.com/?p=11</id>
		<updated>2009-02-24T03:42:08Z</updated>
		<published>2008-03-21T22:49:16Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="php" /><category scheme="http://derekdevries.com" term="rails" />		<summary type="html"><![CDATA[<a href="http://mikenaberezny.com">Mike</a> and I have been diligently converting PHP methods to Ruby for our freshly released <a href="http://railsforphp.com/reference">Rails for PHP Reference</a>. This section is an extension of the reference found in our book -- <a href="http://www.pragprog.com/titles/ndphpr/">Rails for PHP Developers</a>. ]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2008/03/21/rails-for-php-reference/"><![CDATA[<p><a href="http://mikenaberezny.com">Mike</a> and I have been diligently converting PHP methods to Ruby for our freshly released <a href="http://railsforphp.com/reference">Rails for PHP Reference</a>. This section is an extension of the reference found in our book &#8212; <a href="http://www.pragprog.com/titles/ndphpr/">Rails for PHP Developers</a>. </p>
<p>The book covers the language reference, while this reference aims to translate as many of the PHP methods as possible. We&#8217;ve even put together an easy way of searching for your favorite PHP functions by typing them in the url like: <code>http://railsforphp.com/preg_match_all</code>. </p>
<p>Enjoy!</p>
]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2008/03/21/rails-for-php-reference/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2008/03/21/rails-for-php-reference/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Rails Asset Cache]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2007/12/13/rails-asset-cache/" />
		<id>http://derekdevries.com/?p=10</id>
		<updated>2009-02-24T03:42:03Z</updated>
		<published>2007-12-13T22:29:53Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="css" /><category scheme="http://derekdevries.com" term="javascript" /><category scheme="http://derekdevries.com" term="rails" />		<summary type="html"><![CDATA[Rails 2.0 uses asset cache to combine multiple Javascript or CSS libraries to a single Javascript and single CSS file. This improves performance by reducing the number of HTTP requests.]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2007/12/13/rails-asset-cache/"><![CDATA[<p>As a follow up to my article on Minifying Your Rails Javascript, let&#8217;s take a look at a new feature in Rails 2.0 that makes packaging your assets into a single file much easier.</p>
<h3>Enabling Cache</h3>
<p>We use asset helpers such as <code>javascript_include_tag</code> and <code>stylesheet_link_tag</code> in our layouts to include external Javascript and CSS files. One benefit of using these helpers is the ability to cache these resources. Asset cache is turned on when the <code>perform_caching</code> configuration option is set to <code>true</code>. </p>
<p>Rails applications default to having caching disabled during development, and enabled in production. We can change this in <code>config/environments/development.rb</code> to test out caching during development.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">perform_caching</span> = <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<h3>Caching Assets</h3>
<p>We enable asset caching in our applications using the <code>:cache</code> option in our helpers. We can cache Javascript files by doing the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;prototype&quot;</span>, <span style="color:#996600;">&quot;application&quot;</span>, <span style="color:#996600;">&quot;effects&quot;</span>,
                           <span style="color:#ff3333; font-weight:bold;">:cache</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;cache/all&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>When caching is disabled, Rails will generate the normal references to these resources.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;/javascripts/prototype.js?1197321216&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/application.js?1197321216&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/effects.js?1197321216&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>However when caching is enabled, Rails will generate a single external Javascript file in the location we specified. It will then reference this file instead of the original source files.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;/javascripts/cache/all.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>As you can see in the above example, we&#8217;re going to store our asset cache in subdirectories named <code>cache/</code>. This makes it easier to clear out the cache later on. Caching external CSS files works similar to the Javascript example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">&quot;typography&quot;</span>, <span style="color:#996600;">&quot;layout&quot;</span>, <span style="color:#996600;">&quot;color&quot;</span>,
                        <span style="color:#ff3333; font-weight:bold;">:cache</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;cache/all&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<h3>Clearing Cache</h3>
<p>Rails comes with some useful built-in tasks for clearing out temporary files under the <code>tmp:</code> rake namespace. Rails does not come with a built-in task for clearing out the asset cache. We&#8217;ll add this ourselves by adding a new rake task named rake <code>tmp:assets:clear</code>. Create a new file in your Rails application named at <code>lib/tasks/tmp.rake</code>, and add the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:tmp</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  namespace <span style="color:#ff3333; font-weight:bold;">:assets</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
    desc <span style="color:#996600;">&quot;Clears javascripts/cache and stylesheets/cache&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:clear</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>      
      <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">rm</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'public/javascripts/cache/[^.]*'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">rm</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'public/stylesheets/cache/[^.]*'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The custom <code>tmp:assets:clear</code> task we added removes all files from both the <code>javascripts/cache/</code> and <code>stylesheets/cache/</code> directories. Let&#8217;s give it a whirl:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$<span style="color: #000000; font-weight: bold;">&gt;</span> rake tmp:assets:<span style="color: #c20cb9; font-weight: bold;">clear</span></pre></div></div>

<h3>Wrap Up</h3>
<p>Using asset cache can significantly reduce the number of requests sent to the server for external CSS and Javascript files. Along with a good gzip strategy, this is an essential feature when working with large multi-file Javascript libraries. </p>
<p>For additional performance increases using asset helpers, check out Chad Fowler&#8217;s write-up of <a href="http://chadfowler.com/2007/2/18/edge-rails-goody-distributed-asset-hosts">Distributed Asset Hosts</a>.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2007/12/13/rails-asset-cache/#comments" thr:count="5" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2007/12/13/rails-asset-cache/feed/atom/" thr:count="5" />
		<thr:total>5</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Rails, IE, and Parallels]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2007/03/26/rails-ie-and-parallels/" />
		<id>http://derekdevries.com/?p=9</id>
		<updated>2009-02-24T03:42:00Z</updated>
		<published>2007-03-26T22:28:46Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="ie" /><category scheme="http://derekdevries.com" term="parallels" /><category scheme="http://derekdevries.com" term="rails" />		<summary type="html"><![CDATA[Testing your Rails applications in Internet Explorer is still a necessity these days, and Parallels Desktop for the Mac does a great job at making this as painless as possible.]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2007/03/26/rails-ie-and-parallels/"><![CDATA[<p>More and more web developers are using OS X as their development tool of choice these days. It&#8217;s hard not to with excellent tools like <a href="http://macromates.com">TextMate</a>, and the ability to run in a Unix style environment. As much as we&#8217;d like to give IE the boot, we know that the browser market share is still dominated by this browser. Web development professionals these days need to make sure their code at least works in Firefox, Safari, IE6, and IE7. This leaves us with two very important browsers which don&#8217;t natively run on the Mac. <a href="http://www.parallels.com/en/products/desktop/">Parallels Desktop for Mac</a> comes to the rescue here to make it just as easy to test the two versions of IE on a Mac as it is on a PC. </p>
<p>We&#8217;ll go over the basics needed to test your Rails applications in IE6/IE7 on Parallels in the most convenient way possible. </p>
<ul>
<li><a href="#getting-started">Getting Started</a></li>
<li><a href="#open-ports-on-the-network">Open Ports on the Network</a></li>
<li><a href="#browsing-in-ie">Browsing in IE</a></li>
<li><a href="#browse-by-name-with-bonjour">Browse By Name with Bonjour</a></li>
</ul>
<h3>Getting Started</h3>
<p>I&#8217;ll start out by saying that the first prerequisite for this setup is having an Intel powered Mac. This article is useless without one unless you&#8217;re just here to drool over neat tools. </p>
<p>Being able to use Parallels comes at a cost. You&#8217;ll need to shell out $79.99 for a copy of Parallels for Mac, and a couple hundred more for a copy of Windows. I believe this is a nominal business cost for what the software offers, and is much cheaper than having to buy and maintain a separate PC to run Windows. Both Parallels and Windows have a trial versions you can use to verify that this setup is worth your money. </p>
<p>Once you <a href="http://www.parallels.com/en/download/desktop/">download Parallels for Mac</a>, you can unpack and install the software as usual. Parallels has a great guide for getting started with the software. It will take you through Installing Parallels Desktop, Creating new Virtual Machines, and Installing Windows on the machine. I started out by installing a single Windows XP virtual machine and set it up with IE6 and all other default settings I use. I then just copied that setup to create a new VM on which I upgraded to IE7. </p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/vms.gif" />
</p>
<h3>Open Ports on the Network</h3>
<p>When developing Rails applications on the Mac, the typical setup is to develop everything on localhost, and serve the applications using mongrel.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> maintainable
$ mongrel_rails start <span style="color: #660033;">-d</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">3000</span></pre></div></div>

<p>We can of course access this directly in our native Mac browsers by navigating to <code>http://localhost:3000</code>. To make this application accessible from IE on our Windows VM, we&#8217;ll have to accept network traffic through our firewall on port 3000. Open up your Apple System Preferences and go to the sharing window.</p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/sharing.gif" />
</p>
<p>Navigate to the <strong>Firewall</strong> Tab in the Sharing pane, and click on the <strong>New</strong> button so that we can add an additional  port(s). </p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/new_port.gif" />
</p>
<p>Here is where we make our Rails ports available on the network. We&#8217;re going to open up ports 3000-3099 for any additional Rails applications we choose to bind to a port in that range. Enter</p>
<ul>
<li><strong>Port Name:</strong> Other</li>
<li><strong>TCP Port Number(s):</strong> 3000-3099</li>
<li><strong>Description:</strong> Rails Applications (30xx)</li>
</ul>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/add_port.gif" />
</p>
<h3>Browsing in IE</h3>
<p>Now we should be able to browse to this from IE in our Parallels machine by pointing to our internal IP Address. We can find out this internal address by taking a look at the Services tab on our Sharing pane. Near the bottom it will say something like &#8220;Other Macintosh Users can access your computer at afp://192.168.1.100&#8243;. </p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/internal_ip.gif" />
</p>
<p>This is the number we&#8217;re looking for, and we can alternately find it using this command from the terminal.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000;">192</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span></pre></div></div>

<p>Once we have our internal IP, let&#8217;s fire up our IE browser and check out our site. In IE, navigate to http://192.168.1.100:3000. </p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/rails_in_ie.gif" />
</p>
<h3>Browse By Name with Bonjour</h3>
<p>The problem with browsing by internal IP address is that it&#8217;s likely to change from day to day. A better approach is to install Bonjour for Windows so that we can simply refer to our computer by name instead of number. </p>
<p>We&#8217;ll first go back into our Services tab on the Sharing pane in Apple System Preferences. Here we&#8217;re going to shorten our name to be something easy to remember and type into the browser. Click on the <strong>Edit</strong> Button near the top. </p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/edit_name.gif" />
</p>
<p>I&#8217;m going to simply rename this to <strong>derek.local</strong>. Feel free to be more creative with your own. </p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/derek_local.gif" />
</p>
<p>To seamlessly network with our Windows VM without the hassle of dealing with network settings manually, we&#8217;re going to install <a href="http://developer.apple.com/networking/bonjour/download/">Bonjour for Windows</a>. Download <strong>BonjourSetup.exe</strong>, and choose the default settings for the installation. With Bonjour installed, we can now browse to our application at http://derek.local:3000. </p>
<p class="inline_figure">
  <img src="http://assets.derekdevries.com/images/articles/2007/03/rails_in_ie_by_name.gif" /></p>
]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2007/03/26/rails-ie-and-parallels/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2007/03/26/rails-ie-and-parallels/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>derek</name>
						<uri>http://derekdevries.com</uri>
					</author>
		<title type="html"><![CDATA[Minifying Your Rails Javascript]]></title>
		<link rel="alternate" type="text/html" href="http://derekdevries.com/2007/02/05/minifying-your-rails-javascript/" />
		<id>http://derekdevries.com/?p=8</id>
		<updated>2008-04-11T04:11:24Z</updated>
		<published>2007-02-05T22:27:43Z</published>
		<category scheme="http://derekdevries.com" term="Uncategorized" /><category scheme="http://derekdevries.com" term="javascript" /><category scheme="http://derekdevries.com" term="prototype" /><category scheme="http://derekdevries.com" term="rails" />		<summary type="html"><![CDATA[The Javascript libraries that ship with Rails are extremely useful, but have a significant filesize footprint. Writing a simple Rake task to minify our Javascript files using JSMin provides a way cut down the size of your Javascript code before deploying your Rails application.]]></summary>
		<content type="html" xml:base="http://derekdevries.com/2007/02/05/minifying-your-rails-javascript/"><![CDATA[<p>While Prototype and Scriptaculous prove to exceptionally useful, they both have a pretty substantial footprint. The current stable Prototype (v1.5) is 69K, and the Scriptaculous Effects library is 36K. This puts us at over 100K to include these Javascript libraries. </p>
<p>This number can be cut down a little bit with Douglas Crockford&#8217;s <a href="http://www.crockford.com/javascript/jsmin.html">JSMin</a> filter. This filter creates a smaller version of your Javascript source by stripping out extraneous code like whitespace and comments. The minified versions of Prototype is 52K, and Effects is 28K. This saves us around 25K off the bat. </p>
<p>Since we like to keep as much of our code as possible in the Ruby family, we use the Ruby version of the minifier. Copy The <a href="http://www.crockford.com/javascript/jsmin.rb">jsmin.rb</a> file to <span class="path">script/javscript/jsmin.rb</span> in your Rails application.</p>
<p>Now let&#8217;s add a handy Rake task to minify your javascript code using this script. The following task will combine <span class="path">prototype.js</span>, <span class="path">effects.js</span>, and <span class="path">application.js</span>. This will create our final minified file as <span class="path">all_min.js</span>. You can add additional javascript files to the <code>libs</code> array as needed, or adjust what you want the final file to be named. Then copy the code into a file named <span class="path">lib/tasks/js.rake</span>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:js</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Minify javascript src for production environment&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:min</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#008000; font-style:italic;"># list of files to minify</span>
    libs = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'public/javascripts/prototype.js'</span>, 
            <span style="color:#996600;">'public/javascripts/effects.js'</span>, 
            <span style="color:#996600;">'public/javascripts/application.js'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># paths to jsmin script and final minified file</span>
    jsmin = <span style="color:#996600;">'script/javascript/jsmin.rb'</span>
    final = <span style="color:#996600;">'public/javascripts/all_min.js'</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># create single tmp js file</span>
    tmp = <span style="color:#CC00FF; font-weight:bold;">Tempfile</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'all'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    libs.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>lib<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>lib<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> tmp.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>f.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    tmp.<span style="color:#9900CC;">rewind</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># minify file</span>
    <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#91;</span>ruby <span style="color:#008000; font-style:italic;">#{jsmin} &lt; #{tmp.path} &gt; #{final}]</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>#{final}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Before we run the task, there is a single point in Prototype version 1.5 stable that breaks the jsmin filter. There is a <a href="http://dev.rubyonrails.org/ticket/7301">patch</a> for this in the Rails trac, but we will need to manually add the single missing semi-colon until it is applied. You may want to also run your application code through <a href="http://www.jslint.com/">JSLint Verifier</a> and clean up any issues that may jam the jsmin filter. </p>
<p>Now we can minify our javascript by running this new task. It will create a new javascript file with the combined source. From the root of your rails application run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rake js:min
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>derek<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>sportspyder<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
created public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>all_min.js
<span style="color: #000000; font-weight: bold;">&lt;</span>pre<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
In our development environment we don<span style="color: #ff0000;">'t want to have to re-minify our javascript after every change. We'</span>ll still use our separate and easy to <span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #7a0874; font-weight: bold;">source</span> files. We can <span style="color: #000000; font-weight: bold;">do</span> this by putting a conditional <span style="color: #000000; font-weight: bold;">in</span> our layout to include the minified version <span style="color: #000000; font-weight: bold;">in</span> production mode, and the separate files during development.
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>pre <span style="color: #007800;">lang</span>=<span style="color: #ff0000;">&quot;ruby&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;%</span> <span style="color: #000000; font-weight: bold;">if</span> RAILS_ENV == <span style="color: #ff0000;">'production'</span> <span style="color: #000000; font-weight: bold;">%&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&lt;%</span>= javascript_include_tag <span style="color: #ff0000;">&quot;all_min&quot;</span> <span style="color: #000000; font-weight: bold;">%&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&lt;%</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">%&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&lt;%</span>= javascript_include_tag <span style="color: #ff0000;">&quot;prototype&quot;</span>, <span style="color: #ff0000;">&quot;effects&quot;</span>,
                           <span style="color: #ff0000;">&quot;application&quot;</span> <span style="color: #000000; font-weight: bold;">%&amp;</span>gt;
<span style="color: #000000; font-weight: bold;">&lt;%</span> end <span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>One of the added benefits of this approach is that you have a single Javascript source file for the client to download instead of multiple resources for the browser to pull. </p>
<p>You&#8217;ll have to make sure to run this rake task before you deploy, and may want to add it directly to your deployment script. </p>
<p>While minification provides a nice break in file size, it is secondary to sending your javascript compressed. Compression can cut your Javascript to nearly 1/4 of the original size, and is most commonly done using using  Apache&#8217;s mod_deflate module. There is more information on Apache settings on <a href="http://mongrel.rubyforge.org/docs/apache.html">the Mongrel website</a>.</p>
<h4>Update - 03/01/2007</h4>
<p>Prototype doesn&#8217;t actively support a specific packing strategy for various reasons, and patches submitted for making the code pass something like JSLint are likely to be ignored. Reasons for this, and some other strategies on reducing filesize of the library are discussed in <a href="http://www.andrewdupont.net/2007/02/26/packing-prototype/"> Packing Prototype</a>. </p>
<h4>Update - 12/14/2007</h4>
<p>Rails 2.0 includes a feature that makes much of what is described here obsolete. Check out our write-up of Rails Asset Cache.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://derekdevries.com/2007/02/05/minifying-your-rails-javascript/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://derekdevries.com/2007/02/05/minifying-your-rails-javascript/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
	</feed>
