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

<channel>
	<title>Shep Agile Development LLC</title>
	<atom:link href="http://shep-dev.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://shep-dev.com</link>
	<description>Linux, Web Development, and other geek stuff</description>
	<lastBuildDate>Thu, 16 Dec 2010 23:55:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>EventMachine Asynchronous HTTP Client &#8211; Custom Headers (User-Agent)</title>
		<link>http://shep-dev.com/?p=173</link>
		<comments>http://shep-dev.com/?p=173#comments</comments>
		<pubDate>Thu, 16 Dec 2010 23:54:31 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[EventMachine]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=173</guid>
		<description><![CDATA[If you have a need to set custom request headers like User-Agent or Host, here is how you do so via the EM client http = EventMachine::HttpRequest.new&#40;url&#41; .get&#40;:head =&#62; &#123;&#34;User-Agent&#34; =&#62; &#34;Custom Agent&#34;&#125;&#41;]]></description>
			<content:encoded><![CDATA[<p>If you have a need to set custom request headers like User-Agent or Host, here is how you do so via the EM client</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">http = <span style="color:#6666ff; font-weight:bold;">EventMachine::HttpRequest</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
  .<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:head</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;User-Agent&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Custom Agent&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=173</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone 3g Jailbreak 4.2.1 SpringBoard crash and Linux mount</title>
		<link>http://shep-dev.com/?p=168</link>
		<comments>http://shep-dev.com/?p=168#comments</comments>
		<pubDate>Thu, 09 Dec 2010 20:40:13 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=168</guid>
		<description><![CDATA[After updating to 4.2.1 and untethered jailbreak via redsn0w on my iPhone 3g, I had two major issues. The first issue has to do with multitasking. The springboard would crash when using the fast switching. This was fixed by changing the following lines in /System/Library/CoreServices/SpringBoard.app/N82AP.plist &#60;key&#62;opengles-1&#60;/key&#62; to &#60;key&#62;opengles-2&#60;/key&#62; The next problem was mounting my iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>After updating to 4.2.1 and untethered jailbreak via redsn0w on my iPhone 3g, I had two major issues. The first issue has to do with multitasking.  The springboard would crash when using the fast switching.   This was fixed by changing the following lines in /System/Library/CoreServices/SpringBoard.app/N82AP.plist</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;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>opengles-1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>to</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;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>opengles-2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The next problem was mounting my iPhone in Ubuntu Linux.  The error message will contain something about a timeout. If this is happening you probably need to re-pair the device by doing the following via the libimobledevice utils:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">idevicepair unpair
idevicepair pair
idevicepair validate</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=168</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Apache Phusion Passenger: Apache 2 not found</title>
		<link>http://shep-dev.com/?p=165</link>
		<comments>http://shep-dev.com/?p=165#comments</comments>
		<pubDate>Mon, 06 Dec 2010 18:47:43 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Phusion Passenger]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=165</guid>
		<description><![CDATA[This may be pretty basic, but figured it may be useful to others. According to the passenger docs, it will look for Apache in the $PATH environment variable. So to fix the Apache 2 not found error, you first need to find the install location. A very helpful command is &#8220;whereis&#8221; that comes standard on [...]]]></description>
			<content:encoded><![CDATA[<p>This may be pretty basic, but figured it may be useful to others.  According to the passenger docs, it will look for Apache in the $PATH environment variable.  So to fix the Apache 2 not found error, you first need to find the install location.  A very helpful command is &#8220;whereis&#8221; that comes standard on most *NIX systems.  If you have whereis installed copy/paste the following into the command line</p>

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

<p>That will set APACHE_PATH to the path returned from whereis.  Before you continue, please make sure the path was set properly.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$APACHE_PATH</span></pre></div></div>

<p>If everything looks good, update the $PATH environment variable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$APACHE_PATH</span><span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span></pre></div></div>

<p>Then check path to ensure it was updated</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PATH</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=165</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby 1.9 CSV undefined method map for String</title>
		<link>http://shep-dev.com/?p=158</link>
		<comments>http://shep-dev.com/?p=158#comments</comments>
		<pubDate>Fri, 12 Nov 2010 23:43:54 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=158</guid>
		<description><![CDATA[I&#8217;m in the process of upgrading an app running Ruby EE 1.8.7 to Ruby 1.9.2. Since FasterCSV is no longer available, I had to convert the code to use the internal CSV lib.  In doing so, I ran into the above error.  Looking at the source for FasterCSV &#60;&#60;, there was a catchall else statement [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m in the process of upgrading an app running Ruby EE 1.8.7 to Ruby 1.9.2.  Since <a href="http://fastercsv.rubyforge.org/">FasterCSV</a> is no longer available, I had to convert the code to use the internal CSV lib.  In doing so, I ran into the above error.  Looking at the source for FasterCSV &lt;&lt;, there was a catchall else statement that would handle passing a string and convert it to an array to become a row.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span><span style="color:#006600; font-weight:bold;">&#40;</span>arg<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> arg.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">and</span> arg.<span style="color:#9900CC;">size</span> == <span style="color:#006666;">2</span>  <span style="color:#008000; font-style:italic;"># appending a header and name</span>
        <span style="color:#0066ff; font-weight:bold;">@row</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> arg
      <span style="color:#9966CC; font-weight:bold;">elsif</span> arg.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#41;</span>                  <span style="color:#008000; font-style:italic;"># append header and name pairs</span>
        arg.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>pair<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#0066ff; font-weight:bold;">@row</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> pair <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>                                   <span style="color:#008000; font-style:italic;"># append field value</span>
        <span style="color:#0066ff; font-weight:bold;">@row</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, arg<span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#0000FF; font-weight:bold;">self</span>  <span style="color:#008000; font-style:italic;"># for chaining</span>
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In Ruby 1.9 the CSV &lt;&lt; method is expecting an Array or CSV::Row.  Easiest fix for me as to just make my string an Array.  Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=158</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu 10.10 Thunderbird 3.1.6 LastPass addon disables password manager</title>
		<link>http://shep-dev.com/?p=155</link>
		<comments>http://shep-dev.com/?p=155#comments</comments>
		<pubDate>Fri, 05 Nov 2010 20:24:41 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[LastPass]]></category>
		<category><![CDATA[Thunderbird]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=155</guid>
		<description><![CDATA[In my quest to find a good password solution, I tried LastPass. This was a very intrusive password manager on both Firefox and Thunderbird. I promptly removed it after about a day of use. However, removal of the addon left traces of itself throughout my settings. It completely disabled Thunderbird&#8217;s integrated password manager. I was [...]]]></description>
			<content:encoded><![CDATA[<p>In my quest to find a good password solution, I tried <a href="http://lastpass.com/">LastPass</a>.  This was a very intrusive password manager on both Firefox and Thunderbird.  I promptly removed it after about a day of use.  However, removal of the addon left traces of itself throughout my settings.  It completely disabled Thunderbird&#8217;s integrated password manager. I was lucky enough to find an article at <a href="http://kb.mozillazine.org/Password_not_remembered_%28Thunderbird%29">mozillaZine</a> with details on how to re-enable this feature.  </p>
<p>Here are the details from their site:</p>
<blockquote><p>
No checkbox to remember passwords</p>
<p>It can happen that you will find no checkbox in Thunderbird to remember passwords. To change this, you will need to edit the prefs.js file, located in the Thunderbird profile folder.</p>
<p>   1. Close Thunderbird and open the prefs.js file in Notepad or another editor (make a backup copy of prefs.js first, as a precaution).<br />
   2. Find the following line: user_pref(&#8220;signon.rememberSignons&#8221;, false);<br />
   3. Change the value from false to true.<br />
   4. Close the Notepad or editor window and save changes.<br />
   5. On the next startup of Thunderbird you should find the checkbox for remembering the password in the password manager. </p>
<p>Instead of editing prefs.js, you can change the same setting via about:config. </p></blockquote>
<p>While editing prefs.js, I found lots of settings that LastPass left behind.  Also, in Firefox &#8220;about:config&#8221; shows the same situation.  All in all, LastPass was a horrible solution.  I changed to using FF and Thunderbirds built in password manager with a master password.</p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=155</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Prototype JS default function arguments</title>
		<link>http://shep-dev.com/?p=148</link>
		<comments>http://shep-dev.com/?p=148#comments</comments>
		<pubDate>Tue, 03 Aug 2010 22:25:17 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=148</guid>
		<description><![CDATA[$H() is just one more reason to use Prototype. Coming from a Ruby background, I&#8217;ve become very fond of using hashes. I often use them in handling optional arguments to methods, and setting default values for those arguments. I was creating a function in JS, and realized using such methodology would allow for a much [...]]]></description>
			<content:encoded><![CDATA[<p><strong>$H()</strong> is just one more reason to use Prototype.  Coming from a Ruby background, I&#8217;ve become very fond of using hashes.  I often use them in handling optional arguments to methods, and setting default values for those arguments.  I was creating a function in JS, and realized using such methodology would allow for a much more descriptive function.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> handle_notice<span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> default_options <span style="color: #339933;">=</span> $H<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>show_notice<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> show_ignore<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
  options <span style="color: #339933;">=</span> default_options.<span style="color: #660066;">merge</span><span style="color: #009900;">&#40;</span>$H<span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  ...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above sets up a hash of default options, then merges or updates the default_options with the options hash passed to the function.  This allows me to use any combination of arguments, or pass none to use the default.  </p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=148</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Handy ActiveRecord Migration Methods</title>
		<link>http://shep-dev.com/?p=119</link>
		<comments>http://shep-dev.com/?p=119#comments</comments>
		<pubDate>Fri, 23 Apr 2010 22:35:11 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Migrations]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=119</guid>
		<description><![CDATA[We are undergoing a massive DB schema redesign. Much of the work is just tightening up the schema through optimizing indexes, setting default boolean and integer fields, and updating NULL allowed fields. Here is a little module I wrote to save massive amounts of code. module MigrationHelper def index_exists?&#40;table, lookup&#41; lookup = Hash&#91;:columns, Array&#40;lookup&#41;&#93; unless [...]]]></description>
			<content:encoded><![CDATA[<p>We are undergoing a massive DB schema redesign.  Much of the work is just tightening up the schema through optimizing indexes, setting default boolean and integer fields, and updating NULL allowed fields.  Here is a little module I wrote to save massive amounts of code.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> MigrationHelper
  <span style="color:#9966CC; font-weight:bold;">def</span> index_exists?<span style="color:#006600; font-weight:bold;">&#40;</span>table, lookup<span style="color:#006600; font-weight:bold;">&#41;</span>
    lookup = <span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:columns</span>, <span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#40;</span>lookup<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> lookup.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    lookup.<span style="color:#9900CC;">symbolize_keys</span>!
    lookup.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>key,value<span style="color:#006600; font-weight:bold;">|</span>lookup<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#006600; font-weight:bold;">&#40;</span>value.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>value.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>v<span style="color:#006600; font-weight:bold;">|</span>v.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>:<span style="color:#006600; font-weight:bold;">&#40;</span>value.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    indexes<span style="color:#006600; font-weight:bold;">&#40;</span>table<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>lookup.<span style="color:#9900CC;">keys</span>.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>lookup.<span style="color:#9900CC;">values</span>.<span style="color:#9900CC;">first</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> change_column_nulls<span style="color:#006600; font-weight:bold;">&#40;</span>table_name, nullable, <span style="color:#006600; font-weight:bold;">*</span>column_names<span style="color:#006600; font-weight:bold;">&#41;</span>
    column_names.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>column_name<span style="color:#006600; font-weight:bold;">|</span>
      table_columns = columns<span style="color:#006600; font-weight:bold;">&#40;</span>table_name<span style="color:#006600; font-weight:bold;">&#41;</span> 
      column_def = table_columns.<span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span>c.<span style="color:#9900CC;">name</span> == column_name.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;Unknown column name #{column_name} for #{table_name}<span style="color:#000099;">\n</span>Available columns: #{table_columns.collect(&amp;:name).to_sentence}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> column_def.<span style="color:#9900CC;">empty</span>?
      change_column table_name, column_name, column_def.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">type</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> nullable
    <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> change_column_defaults<span style="color:#006600; font-weight:bold;">&#40;</span>table_name, default, <span style="color:#006600; font-weight:bold;">*</span>column_names<span style="color:#006600; font-weight:bold;">&#41;</span>
    column_names.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>column_name<span style="color:#006600; font-weight:bold;">|</span>
      change_column_default table_name, column_name, default
    <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>I fond it necessary to have the index_exists? method mainly for my development purposes.  When I&#8217;m optimizing tables by doing complex indexes, I often do them right on the DB first before throwing them into a migration.  By having this check I can easily skip over it if it already exists.  It takes the same options as add_index.  You can pass table and column names, or just table and index name.  Here are some usage examples:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">add_index <span style="color:#ff3333; font-weight:bold;">:table</span>, <span style="color:#ff3333; font-weight:bold;">:column</span> <span style="color:#9966CC; font-weight:bold;">unless</span> index_exists?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:table</span>, <span style="color:#ff3333; font-weight:bold;">:column</span><span style="color:#006600; font-weight:bold;">&#41;</span>
add_index <span style="color:#ff3333; font-weight:bold;">:table</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:column1</span>, <span style="color:#ff3333; font-weight:bold;">:column2</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> index_exists?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:table</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:column1</span>, <span style="color:#ff3333; font-weight:bold;">:column2</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
add_index <span style="color:#ff3333; font-weight:bold;">:table</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:column1</span>, <span style="color:#ff3333; font-weight:bold;">:column2</span>, <span style="color:#ff3333; font-weight:bold;">:column3</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;some_index_name&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> index_exists?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:table</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;some_index_name&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>The method change_column_nulls is used to mass change the NULL allowed columns for a given table.  Really not much to it, but saves a lot of code over doing change_table or change_column.  Here is the usage:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">change_column_nulls <span style="color:#ff3333; font-weight:bold;">:table</span>, <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:column1</span>, <span style="color:#ff3333; font-weight:bold;">:column2</span></pre></div></div>

<p>And lastly change_column_defaults is just a wrapper around change_column_default for mass assignment.  Usage is the same as change_column_nulls passing the default values as the second argument.  I thought about combining the two, but it didn&#8217;t offer very much savings.  </p>
<p>These were tested using MySql 5.  I&#8217;m not sure about the compatibility with other servers.</p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=119</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails ActiveRecord MySql varbinary</title>
		<link>http://shep-dev.com/?p=115</link>
		<comments>http://shep-dev.com/?p=115#comments</comments>
		<pubDate>Fri, 26 Mar 2010 22:22:23 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=115</guid>
		<description><![CDATA[Although ActiveRecord has the following warning about database specific column types: &#8220;You may use a type not in this list as long as it is supported by your database (for example, &#8220;polygon&#8221; in MySQL), but this will not be database agnostic and should usually be avoided. ActiveRecord&#8221; You may have optimizations specific to a database [...]]]></description>
			<content:encoded><![CDATA[<p>Although ActiveRecord has the following warning about database specific column types: &#8220;<em>You may use a type not in this list as long as it is supported by your database (for example, &#8220;polygon&#8221; in MySQL), but this will not be database agnostic and should usually be avoided.  <a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#M001983">ActiveRecord</a></em>&#8221;  You may have optimizations specific to a database server like MySql&#8217;s varbinary.  Here is how to create the a table with a varbinary(1000) column.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">create_table <span style="color:#ff3333; font-weight:bold;">:page_error_sources</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
  t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:source</span>, <span style="color:#996600;">'varbinary(1000)'</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  t.<span style="color:#9900CC;">timestamps</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solr 1.4 Upgrade P2 &#8211; Out with Rsync CollectionDistribution in with JavaReplication</title>
		<link>http://shep-dev.com/?p=108</link>
		<comments>http://shep-dev.com/?p=108#comments</comments>
		<pubDate>Wed, 03 Mar 2010 22:11:22 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Cores]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Rsync]]></category>
		<category><![CDATA[Solr]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=108</guid>
		<description><![CDATA[Solr 1.4 made replication from Master to Slave servers a whole lot easier.  Before solr1.4 we were using rsync via the snapshooter and snappuller scripts As seen here.  This method worked OK, but intermittently we would see the snapshooter or puller fail for various Java reasons (Memory usually). Please see Solr Java-Based Replication for setup [...]]]></description>
			<content:encoded><![CDATA[<p>Solr 1.4 made replication from Master to Slave servers a whole lot easier.  Before solr1.4 we were using rsync via the snapshooter and snappuller scripts <a title="Solr CollectionDistribution" href="http://wiki.apache.org/solr/CollectionDistribution" target="_blank">As seen here</a>.  This method worked OK, but intermittently we would see the snapshooter or puller fail for various Java reasons (Memory usually).</p>
<p>Please see <a title="Solr Java-Based Replication" href="http://wiki.apache.org/solr/SolrReplication" target="_blank">Solr Java-Based Replication</a> for setup overview.  I will cover specific modification I had to make compared to what is in their documentation.  In my solrconfig.xml on my Master server, I have the following:</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;requestHandler</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/replication&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;solr.ReplicationHandler&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lst</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;master&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #808080; font-style: italic;">&lt;!--Replicate on 'startup' and 'commit'. 'optimize' is also a valid value for replicateAfter. --&gt;</span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;str</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replicateAfter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>startup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/str<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;str</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replicateAfter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>commit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/str<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lst<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/requestHandler<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then on the slave servers, I have:</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;requestHandler</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/replication&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;solr.ReplicationHandler&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lst</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;slave&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #808080; font-style: italic;">&lt;!--fully qualified url for the replication handler of master . It is possible to pass on this as a request param for the fetchindex command--&gt;</span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;str</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;masterUrl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://{solr_host}:{solr_port}/solr/${solr.core.name}/replication<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/str<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #808080; font-style: italic;">&lt;!--Interval in which the slave should poll master .Format is HH:mm:ss . If this is absent slave does not poll automatically. </span>
<span style="color: #808080; font-style: italic;">           But a fetchindex can be triggered from the admin or the http API --&gt;</span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;str</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pollInterval&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>00:00:30<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/str<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;str</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;httpReadTimeout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>10000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/str<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>--&gt;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lst<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/requestHandler<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Substitute {solr_host} and {solr_port} with your specific settings.  IMPORTANT: Note the ${solr.core.name} variable.  This makes it so the slaves will poll from the correct MultiCore path on the Master server.</p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=108</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Solr 1.4 Upgrade &#8211; Out with Faceting, In with MultiCore</title>
		<link>http://shep-dev.com/?p=86</link>
		<comments>http://shep-dev.com/?p=86#comments</comments>
		<pubDate>Mon, 01 Feb 2010 21:37:13 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Cores]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Solr]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=86</guid>
		<description><![CDATA[I finally found some time, though it was a bit forced, to look into the new CoreAdmin functionality released in Solr 1.4.  Our app was using the same index for multiple apps distinguished through Faceting.  This worked fine for a while, but the larger our indexed data got, the slower the queries were returned.  The [...]]]></description>
			<content:encoded><![CDATA[<p>I finally found some time, though it was a bit forced, to look into the new <a href="http://wiki.apache.org/solr/CoreAdmin" target="_blank">CoreAdmin</a> functionality released in<a href="http://wiki.apache.org/solr/Solr1.4" target="_blank"> Solr 1.4</a>.  Our app was using the same index for multiple apps distinguished through <a href="http://wiki.apache.org/solr/SolrFacetingOverview" target="_blank">Faceting</a>.  This worked fine for a while, but the larger our indexed data got, the slower the queries were returned.  The responsiveness of every app was now dependent on the total indexed size.  This was not ideal, so we upgraded to 1.4 to see how using multiple cores could help.</p>
<p>Upgrading was quite easy.  See http://wiki.apache.org/solr/Solr1.4 for upgrading notes.  What I will focus on are the details of using and automating the MultiCore functionality.  To enable the dynamic SolrCore functionality, you just need to put the following XML in <strong>solr.xml</strong> inside your solr_home directory.</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;solr</span> <span style="color: #000066;">persistent</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">sharedLib</span>=<span style="color: #ff0000;">&quot;lib&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cores</span> <span style="color: #000066;">adminPath</span>=<span style="color: #ff0000;">&quot;/admin/cores&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cores<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/solr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Don&#8217;t worry about creating any cores at this time.  The next thing I did was create a directory called &#8220;default&#8221; in my solr_home directory to store all of my shared configs for each core.  I then copied the conf/ directory from my solr_home into the newly created default dir.</p>
<p>The final step is to create the cores needed.  You can automate this by posting the following request and checking the XML response, or by just pasting this into your browser.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>host<span style="color: #7a0874; font-weight: bold;">&#125;</span>:<span style="color: #7a0874; font-weight: bold;">&#123;</span>port<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>solr_home<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>admin<span style="color: #000000; font-weight: bold;">/</span>cores?<span style="color: #007800;">action</span>=CREATE<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">name</span>=<span style="color: #7a0874; font-weight: bold;">&#123;</span>core_name<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">instanceDir</span>=default<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">dataDir</span>=<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">/</span>full<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>solr<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>core_name<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Here is how you automate the request using xml-simple and ruby</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#set the url string equal to the above command</span>
response = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">get_response</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">body</span>
xml = <span style="color:#CC00FF; font-weight:bold;">XmlSimple</span>.<span style="color:#9900CC;">xml_in</span><span style="color:#006600; font-weight:bold;">&#40;</span>response, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">'VarAttr'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'name'</span>, <span style="color:#996600;">'ContentKey'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'-content'</span>, <span style="color:#996600;">'KeyAttr'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'name'</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;Failed to create solr core&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> xml<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;lst&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;responseHeader&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;int&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;status&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> != <span style="color:#006666;">0</span></pre></div></div>

<div id="attachment_105" class="wp-caption alignnone" style="width: 597px"><a href="http://shep-dev.com/wp-content/uploads/2010/02/master-average_request.png"><img src="http://shep-dev.com/wp-content/uploads/2010/02/master-average_request.png" alt="" title="master average_request" width="587" height="205" class="size-full wp-image-105" /></a><p class="wp-caption-text">Master Solr server after upgrade to 1.4 and multi-core</p></div><br />
<div id="attachment_106" class="wp-caption alignnone" style="width: 613px"><a href="http://shep-dev.com/wp-content/uploads/2010/02/Slave-longer-CPU.png"><img src="http://shep-dev.com/wp-content/uploads/2010/02/Slave-longer-CPU.png" alt="" title="Slave longer CPU" width="603" height="289" class="size-full wp-image-106" /></a><p class="wp-caption-text">Solr slave server after upgrade to 1.4 and multi-core</p></div>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&#038;p=86</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
