<?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>Tue, 03 Aug 2010 22:26:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<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&amp;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&amp;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&amp;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&amp;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&amp;p=86</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone 3g 3.1.2 jailbreak update PwnageTool</title>
		<link>http://shep-dev.com/?p=83</link>
		<comments>http://shep-dev.com/?p=83#comments</comments>
		<pubDate>Thu, 15 Oct 2009 16:00:20 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[jailbreak]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=83</guid>
		<description><![CDATA[I updated my jailbroken iPhone to 3.1 when it first came out and had some major issues that required almost a daily hard reboot.  I successfully downgraded it to 3.0.1, but still had some baseband issues with the service (phone and sms) not working.  I was very excited to see the iPhone Dev Team came [...]]]></description>
			<content:encoded><![CDATA[<p>I updated my jailbroken iPhone to 3.1 when it first came out and had some major issues that required almost a daily hard reboot.  I successfully downgraded it to 3.0.1, but still had some baseband issues with the service (phone and sms) not working.  I was very excited to see the iPhone Dev Team came out with a 3.1.2 jailbreak using <a href="http://blog.iphone-dev.org/post/211802082/pwnage-pie">PwnageTool 3.1.4</a></a></p>
<p>Since I was already jailbroken, I simply built the custom IPSW, and clicked Option+Restore in iTunes.  Everything went as expected, and I finally have a stable phone again.</p>
<p>I&#8217;ve been jailbreaking my phone since I first got it over a year ago, and I&#8217;m so glad to see the process getting easier and smoother every time.  Big thanks to the <a href="http://blog.iphone-dev.org/">iPhone Dev Team</a> and all their hard work.</p>
<p>Here are the steps I took in case you are <strong>already jailbroken</strong> and just want the bug fixes and 3.1 update.</p>
<ul>Requirements</p>
<li>Mac OS X</li>
<li>iTunes 9.0.1</li>
<li>Already jailbroken iPhone 3G on 3.0 firmware</li>
<li>Backups!</li>
</ul>
<ul>Steps</p>
<li>Check for updates in iTunes</li>
<li>Choose to download only for the update</li>
<li>Download PwnageTool 3.1.4 <a href="http://xs1.iphwn.org/releases/PwnageTool_3.1.4.dmg.5122330.TPB.torrent">Torrent</a> <a href="http://downloads2.touch-mania.com/PwnageTool_3.1.4.dmg">Mirror</a></li>
<li>Launch PwnageTool and go walk through the steps to create your custom IPSW</li>
<li>Answer Yes to already jailbroken and exit the app when prompted</li>
<li>Launch iTunes and hold the Option key and click Restore</li>
<li>Select your custom IPSW file (probably on your destop)</li>
<li>Enjoy your new 3.1.2 jailbreak</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&amp;p=83</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aggregation with MySQL and ActiveRecord</title>
		<link>http://shep-dev.com/?p=81</link>
		<comments>http://shep-dev.com/?p=81#comments</comments>
		<pubDate>Fri, 31 Jul 2009 19:38:39 +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>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=81</guid>
		<description><![CDATA[I had some data that I wanted to aggregate by year for a flash graphing app called amCharts. Here was the SQL query I used to gather the data: SELECT AVG&#40;column1&#41; AS column1, AVG&#40;column2&#41; AS column2 FROM table1 t1 JOIN table2 t2 ON t2.id = t1.tabel2_id GROUP BY YEAR&#40;t2.datetime_field&#41; Rather than using this sql in [...]]]></description>
			<content:encoded><![CDATA[<p>I had some data that I wanted to aggregate by year for a flash graphing app called <a href="http://www.amcharts.com/">amCharts</a>.  Here was the SQL query I used to gather the data:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> AVG<span style="color: #66cc66;">&#40;</span>column1<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> column1<span style="color: #66cc66;">,</span> AVG<span style="color: #66cc66;">&#40;</span>column2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> column2 <span style="color: #993333; font-weight: bold;">FROM</span> table1 t1
<span style="color: #993333; font-weight: bold;">JOIN</span> table2 t2 <span style="color: #993333; font-weight: bold;">ON</span> t2<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> t1<span style="color: #66cc66;">.</span>tabel2_id
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> YEAR<span style="color: #66cc66;">&#40;</span>t2<span style="color: #66cc66;">.</span>datetime_field<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Rather than using this sql in ActiveRecord via find_by_sql, I figured I&#8217;d make it pretty and use the built in find method.  Here is what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Table1.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:select</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'t2_id, AVG(column1) as column1, AVG(column2) as column2'</span>, <span style="color:#ff3333; font-weight:bold;">:joins</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:t2</span>, <span style="color:#ff3333; font-weight:bold;">:group</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'YEAR(t2.datetime_field)'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>The :select option allows you to define the attributes you want returned with the AR object.  I&#8217;m using MySQL to do the averaging of the data via the AVG function.  I would normally use the :include option for joins, but I couldn&#8217;t get it to work with this query, so the :joins option seemed to work well by passing it the association definition from the model.  The :group option simply works the same as the SQL group by.  Just pass it a sql fragment, in my case just the year field portion of the datetime field.</p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&amp;p=81</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RJS redirect_to params contain &amp;</title>
		<link>http://shep-dev.com/?p=79</link>
		<comments>http://shep-dev.com/?p=79#comments</comments>
		<pubDate>Thu, 25 Jun 2009 19:29:41 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=79</guid>
		<description><![CDATA[I came across this today when I added a parameter to a RJS page.redirect_to call.  It appears that prototype or rails is not properly handling the parameters when there are more than 2.  I got around it by using a defined route in the routes.rb that looks like this: map.route_name 'controller_name/action_name/:foo_id', :controller =&#62; 'controller_name', :action [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this today when I added a parameter to a RJS page.redirect_to call.  It appears that prototype or rails is not properly handling the parameters when there are more than 2.  I got around it by using a defined route in the routes.rb that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">map.<span style="color:#9900CC;">route_name</span> <span style="color:#996600;">'controller_name/action_name/:foo_id'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'controller_name'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'action_name'</span></pre></div></div>

<p>I had to change the redirect_to in my RJS file from this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">page.<span style="color:#9900CC;">redirect_to</span> page_recrawl_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:foo_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@foo_id</span>, <span style="color:#ff3333; font-weight:bold;">:bar_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@bar_id</span>, <span style="color:#ff3333; font-weight:bold;">:bang</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>To this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">page.<span style="color:#9900CC;">redirect_to</span> page_recrawl_path<span style="color:#006600; font-weight:bold;">&#40;</span>@foo_id, <span style="color:#006600; font-weight:bold;">&#123;</span>:bar_id <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@bar_id</span>, <span style="color:#ff3333; font-weight:bold;">:bang</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</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&amp;p=79</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jailbroken iPhone 3g 3.0 firmware</title>
		<link>http://shep-dev.com/?p=72</link>
		<comments>http://shep-dev.com/?p=72#comments</comments>
		<pubDate>Sun, 21 Jun 2009 05:21:44 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[jailbreak]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=72</guid>
		<description><![CDATA[Thanks to the iPhone Dev-Team for releasing the Pwnage Tool 3.0, I was able to upgrade to the jailbroken 3.0 firmware. The install process went very smoothly. I followed a similar procedure to what they demo&#8217;d on their youtube video. Some of my favorite jailbroken apps don&#8217;t work with the new firmware. Here are my [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to the <a href="http://blog.iphone-dev.org">iPhone Dev-Team</a> for releasing the Pwnage Tool 3.0, I was able to upgrade to the jailbroken 3.0 firmware.  The install process went very smoothly.  I followed a similar procedure to what they demo&#8217;d on their <a href="http://www.youtube.com/quickpwn">youtube video</a>.  Some of my favorite jailbroken apps don&#8217;t work with the new firmware.  Here are my findings:</p>
<p><strong>Apps</strong></p>
<ul>
<li>Cycorder: Yes</li>
<li>OpenSSH: Yes</li>
<li>SBS Settings: Yes</li>
<li>Icy: Yes</li>
<li>Cydia: Stability issues</li>
<li>PdaNet: Yes, but possible stability issues</li>
<li>Winterboard: Mostly, some themes weren&#8217;t stable</li>
<li>Pwnplayer: no</li>
<li>Snapture: no</li>
<li>NES: no</li>
</ul>
<p>Overall the new 3.0 features were well worth upgrading.  The only app I will really miss is Pwn player and I hope there will be a similar replacement (it&#8217;s no longer maintained).  As for the other apps, I&#8217;m sure they&#8217;ll be getting updates soon.  Please let me know what apps you have working.</p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&amp;p=72</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails background process: MySQL server has gone away</title>
		<link>http://shep-dev.com/?p=67</link>
		<comments>http://shep-dev.com/?p=67#comments</comments>
		<pubDate>Tue, 02 Jun 2009 17:45:52 +0000</pubDate>
		<dc:creator>Shep</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shep-dev.com/?p=67</guid>
		<description><![CDATA[Using workling and starling to handle background tasks is very nice. Check out this link for info on setting it up.  However, I encountered the error: &#8220;Mysql::Error: MySQL server has gone away&#8221; when accessing an external DB tables like users and roles.  I found that someone recommended using verify_active_connections!, however the table the connection error [...]]]></description>
			<content:encoded><![CDATA[<p>Using <a href="http://rubyforge.org/projects/starling/">workling</a> and <a href="http://github.com/purzelrakete/workling/tree/master/Changes">starling</a> to handle background tasks is very nice.  Check out <a href="http://www.justinball.com/2008/08/18/using-starling-workling-with-ruby-on-rails/">this link</a> for info on setting it up.  However, I encountered the error: &#8220;Mysql::Error: MySQL server has gone away&#8221; when accessing an external DB tables like users and roles.  I found that someone recommended using verify_active_connections!, however the table the connection error occurred on was a HABTM table &#8216;user_roles&#8217;.  I found that verify_active_connections will use the scope of the model/object you invoke it on.  So the final solution was to do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">user.<span style="color:#9900CC;">roles</span>.<span style="color:#9900CC;">verify_active_connections</span>!</pre></div></div>

<p>This will make sure users, user_roles, and roles all have valid connections.  This error occurred using rails 2.0.1.  It may be fixed in newer versions of ActiveRecord.  </p>
]]></content:encoded>
			<wfw:commentRss>http://shep-dev.com/?feed=rss2&amp;p=67</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
