<?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>Relentless Simplicity :: Bill Harding&#039;s Tech Blog</title>
	<atom:link href="http://www.williambharding.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.williambharding.com/blog</link>
	<description>Rails programming with a blog aftertaste</description>
	<lastBuildDate>Sat, 11 May 2013 23:23:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Ruby slice to end of an array</title>
		<link>http://www.williambharding.com/blog/rails/ruby-slice-to-end-of-an-array/</link>
		<comments>http://www.williambharding.com/blog/rails/ruby-slice-to-end-of-an-array/#comments</comments>
		<pubDate>Sat, 11 May 2013 23:23:47 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=654</guid>
		<description><![CDATA[It&#8217;s popular enough to be a Google-suggested search, but not popular enough to have a good result yet. If you want to slice to the end of a Ruby array, and/or get the end of a Ruby array, what you want is arr[1, -1] # -1 means all the rest of the array]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s popular enough to be a Google-suggested search, but not popular enough to have a good result yet.</p>
<p>If you want to slice to the end of a Ruby array, and/or get the end of a Ruby array, what you want is</p>
<pre code="ruby">
arr[1, -1] # -1 means all the rest of the array
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/rails/ruby-slice-to-end-of-an-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Balsamiq (and Air) on Ubuntu/Linux Pangolin 64 bit</title>
		<link>http://www.williambharding.com/blog/technology/install-balsamiq-on-ubuntulinux-pangolin-64-bit/</link>
		<comments>http://www.williambharding.com/blog/technology/install-balsamiq-on-ubuntulinux-pangolin-64-bit/#comments</comments>
		<pubDate>Mon, 29 Apr 2013 00:18:34 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=646</guid>
		<description><![CDATA[In my continued effort to ween myself off VMware (slow start speed, many gigs to copy every time I get a new computer) I decided to invest some time this afternoon toward getting one of my essential tools, Balsamiq Mockups, to work on 64-bit Precise Pangolin. I had assumed this would be impossible, so was [...]]]></description>
			<content:encoded><![CDATA[<p>In my continued effort to ween myself off VMware (slow start speed, many gigs to copy every time I get a new computer) I decided to invest some time this afternoon toward getting one of my essential tools, Balsamiq Mockups, to work on 64-bit Precise Pangolin. I had assumed this would be impossible, so was stunned to find that it&#8217;s not only possible, but pretty darned easy. Here are the steps that I cobbled together from a few sources to get it working fast:</p>
<h3>Install Adobe Air</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>airdownload.adobe.com<span style="color: #000000; font-weight: bold;">/</span>air<span style="color: #000000; font-weight: bold;">/</span>lin<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>latest<span style="color: #000000; font-weight: bold;">/</span>AdobeAIRInstaller.bin
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x AdobeAIRInstaller.bin
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>x86_64-linux-gnu<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>x86_64-linux-gnu<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0.2.0 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0.2.0
<span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>AdobeAIRInstaller.bin</pre></div></div>

<p>The middle bit makes some symlinks so that Adobe Air can access gnome keyring (required for install). If you&#8217;re running 32-bit Pangolin, those two steps are slightly different:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>i386-linux-gnu<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>i386-linux-gnu<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0.2.0 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libgnome-keyring.so.0.2.0</pre></div></div>

<h3>Install Balsamiq</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>builds.balsamiq.com<span style="color: #000000; font-weight: bold;">/</span>b<span style="color: #000000; font-weight: bold;">/</span>mockups-desktop<span style="color: #000000; font-weight: bold;">/</span>MockupsForDesktop64bit.deb
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> MockupsForDesktop64bit.deb</pre></div></div>

<p>Or if you&#8217;re running 32-bit:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>builds.balsamiq.com<span style="color: #000000; font-weight: bold;">/</span>b<span style="color: #000000; font-weight: bold;">/</span>mockups-desktop<span style="color: #000000; font-weight: bold;">/</span>MockupsForDesktop32bit.deb
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> MockupsForDesktop32bit.deb</pre></div></div>

<h3>Yay For Easy</h3>
<p>Thanks to <a href="http://www.linux.org/article/view/install-adobe-flash-reader-air-in-ubuntu-12-04-precise-pangolin-">Linux.org</a> for the guidance on installing Adobe Air. The steps on Adobe&#8217;s own site are an awful mess.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/technology/install-balsamiq-on-ubuntulinux-pangolin-64-bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplest means for AJAX upload with Rails Carrierwave and jQuery</title>
		<link>http://www.williambharding.com/blog/rails/the-simplest-means-for-ajax-uploading-with-rails-carrierwave-and-jquery/</link>
		<comments>http://www.williambharding.com/blog/rails/the-simplest-means-for-ajax-uploading-with-rails-carrierwave-and-jquery/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 07:15:37 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=630</guid>
		<description><![CDATA[The time has finally come for a follow-up to my post from a couple years ago on using jQuery, attachment_fu, and Rails 2.3 to upload an asset to my blog. I wanted to share the updated version of my attempt to determine the absolute minimal code necessary to implement AJAX uploads on Rails 3 with [...]]]></description>
			<content:encoded><![CDATA[<p>The time has finally come for a follow-up to my <a href="http://www.williambharding.com/blog/rails/rails-ajax-image-uploading-made-simple-with-jquery/">post from a couple years ago</a> on using jQuery, attachment_fu, and Rails 2.3 to upload an asset to my blog. I wanted to share the updated version of my attempt to determine the absolute minimal code necessary to implement AJAX uploads on Rails 3 with Carrierwave.  As was the case a few years ago, the Google results still tend to suck when searching for a<em> simple</em> means to accomplish an AJAX upload with Rails &#8212; the most popular result I could find this evening was a <a href="http://stackoverflow.com/questions/8363698/rails-carrier-wave-with-jquery-uploader">Stackoverflow post</a> that detailed <strong>9</strong> (ick) steps, including adding a gem to the project and creating new middleware.  No thanks!</p>
<p>The Javascript from my previous example is essentially unchanged.  It uses <a href="http://www.jquery.com">jQuery</a> and the <a href="http://plugins.jquery.com/project/form" target="_blank">jQuery-form</a> plugin. The main challenge in getting a AJAX uploading working is that form_for :remote doesn&#8217;t understand multipart form submission, so it&#8217;s not going to send the file data Rails seeks back with the AJAX request. That&#8217;s where the jQuery form plugin comes into play. Following is the Rails code that goes in your html.erb.  Remember that in my case I am creating an image that will be associated with a model &#8220;BlogPost&#8221; that resides in the BlogPostsController.  Adapt for your models/controllers accordingly:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= form_for<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:image_form</span>, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:controller <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:blog_posts</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create_asset</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:remote</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:method <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'upload_form'</span>, <span style="color:#ff3333; font-weight:bold;">:multipart</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> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 Upload a file: <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:uploaded_data</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Here&#8217;s the associated Javascript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#upload_form input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxSubmit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  beforeSubmit<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>f<span style="color: #339933;">,</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   o.<span style="color: #660066;">dataType</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  complete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>XMLHttpRequest<span style="color: #339933;">,</span> textStatus<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">// XMLHttpRequest.responseText will contain the URL of the uploaded image.</span>
   <span style="color: #006600; font-style: italic;">// Put it in an image element you create, or do with it what you will.</span>
   <span style="color: #006600; font-style: italic;">// For example, if you have an image elemtn with id &quot;my_image&quot;, then</span>
   <span style="color: #006600; font-style: italic;">//  $('#my_image').attr('src', XMLHttpRequest.responseText);</span>
   <span style="color: #006600; font-style: italic;">// Will set that image tag to display the uploaded image.</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now, chances are you&#8217;re uploading this asset from a #new action, which means that the resource (here, the BlogPost) that will be associated with the image has yet to be created.  That means we&#8217;re going to need a model that we can stick the AJAX-created image in until such time that the main resource has been created.  We can do this if we create a migration for a new BlogImage model like so:</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:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
  create_table <span style="color:#ff3333; font-weight:bold;">:blog_images</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:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:image</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  add_column <span style="color:#ff3333; font-weight:bold;">:blog_posts</span>, <span style="color:#ff3333; font-weight:bold;">:blog_image_id</span>, <span style="color:#ff3333; font-weight:bold;">:integer</span> <span style="color:#008000; font-style:italic;"># once created, we'll want to reference the BlogImage we created beforehand via AJAX</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The corresponding BlogImage model would then be:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> BlogImage <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  mount_uploader <span style="color:#ff3333; font-weight:bold;">:image</span>, BlogImageUploader
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Of course, if your resource already exists at the time the AJAX upload will happen, then you&#8217;re on easy street.  In that case, you don&#8217;t have to create a separate model like BlogImage, you can just add a column to your main resource (BlogPost) and mount the uploader directly to BlogPost.  In either case, the BlogImageUploader class would be setup with whatever options you want, per the <a href="https://github.com/jnicklas/carrierwave">Carrierwave documentation</a>.</p>
<p>Continuing under the assumption that you will separate your model from the main resource (in this case, the BlogImage, which is separate from the BlogPost), we can create this image before the BlogPost exists, and stash the BlogPost id however you see fit.  Thus, your controller&#8217;s #create_asset method will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> create_asset
  blog_image = BlogImage.<span style="color:#9900CC;">new</span>
  blog_image.<span style="color:#9900CC;">image</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:image_data</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:uploaded_data</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  blog_image.<span style="color:#9900CC;">save</span>!
&nbsp;
  <span style="color:#008000; font-style:italic;"># TODO: store blog_image.id in session OR pass ID back to form for storage in a hidden field</span>
  <span style="color:#008000; font-style:italic;"># OR if your main resource already exists, mount the uploader to it directly and go sip on a </span>
  <span style="color:#008000; font-style:italic;"># pina colada instead of worrying about this</span>
&nbsp;
  render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> blog_image.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And that&#8217;s it.  No new gems, plus low-fat Javascript and controller additions.  </p>
<h3>Bonus section:  How to embed this AJAX upload form in the form for its parent resource</h3>
<p>One of the more common questions from my last post was how to display this AJAX image upload amongst the form for another resource.  There are many ways to accomplish this (see <a href="www.williambharding.com/blog/rails/rails-ajax-image-uploading-made-simple-with-jquery#comments">comments from last post if you&#8217;ve got time to kill</a>), but in keeping with the spirit of simplicity in this post, one fast hack I&#8217;ve used:</p>
<ol>
<li>After all the form fields for the main resource, close the form without a submit button</li>
<li>Insert the AJAX form</li>
<li>Add a link below the AJAX form that is styled to look like a button.  Have this link call Javascript to submit your main form</li>
</ol>
<p>Not going to win any beauty contests, but easy to setup and gets the job done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/rails/the-simplest-means-for-ajax-uploading-with-rails-carrierwave-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One approach to fixing Mysql Alter Table hang</title>
		<link>http://www.williambharding.com/blog/mysql-2/one-approach-to-fixing-mysql-alter-table-hang/</link>
		<comments>http://www.williambharding.com/blog/mysql-2/one-approach-to-fixing-mysql-alter-table-hang/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 22:12:19 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Mysql]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=622</guid>
		<description><![CDATA[Many of the Google results you&#8217;ll get for searching along the lines of &#8220;mysql alter table hang&#8221; or &#8220;mysql alter table frozen&#8221; or &#8220;mysql alter table stuck&#8221; will correctly point out that it often takes a long time for an alter table to finish.  They will also point out that killing an alter table is [...]]]></description>
			<content:encoded><![CDATA[<p>Many of the Google results you&#8217;ll get for searching along the lines of &#8220;mysql alter table hang&#8221; or &#8220;mysql alter table frozen&#8221; or &#8220;mysql alter table stuck&#8221; will correctly point out that it often takes a long time for an alter table to finish.  They will also point out that killing an alter table <a href="http://www.dbasquare.com/2012/05/15/why-do-threads-sometimes-stay-in-killed-state-in-mysql/">is not an instant operation</a>, it takes time for the kill to delete the temporary table.  But none of these morsels of advice covers the situation we recently found ourselves in, so I will share some details.</p>
<p>We had a write-intensive database table with small row size and a moderately big size (~700mb).  After waiting about 30 minutes for the alter table to complete, I finally got fed up and attempted to kill the alter table&#8217;s thread.  The thread did indeed change to a &#8220;killed&#8221; state rather than a query, but that killed state was still there 30..60..90 minutes later (all the while claiming that it was &#8220;renaming results table&#8221;).  Moreover, about 1800 threads that had become stuck waiting on the alter were sitting around on our Mysql process list.</p>
<p>I tried various remedies, from looking for deadlocks in &#8220;SHOW INNODB STATUS\G&#8221; (no deadlocks, just 1800 patiently waiting threads), to looking for the temp table that had supposedly been getting built to see if it was progressing (it wasn&#8217;t).  About three hours into the event, I decided we might as well kill the 1800 stuck processes in case it would take a DB restart to finally clear this alter table.  I followed <a href="http://www.mysqlperformanceblog.com/2009/05/21/mass-killing-of-mysql-connections/">these instructions on how to kill Mysql threads en mass</a>, and got us down to just the alter thread along with a couple waiting threads that hadn&#8217;t been in my list of threads to kill.</p>
<p>Then, about two minutes later, something mysterious happened.  The alter command finished.</p>
<p>All of the Googling and Mysql info delving I could manage would not reveal what it was that had left the ALTER command stuck so much longer than it typically takes for a table of its size.  But whatever was keeping the alter command from finishing seems clearly to have been related to the 1800 threads that were sitting around waiting on the alter to complete.  Once we purged these, the alter finished within a couple minutes.</p>
<p>Hopefully this is a helpful alternate idea to try if you should find yourself with an ALTER TABLE that refuses to die no matter what steps you take.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/mysql-2/one-approach-to-fixing-mysql-alter-table-hang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What happens if two Google Adwords auto targets have the same bid?</title>
		<link>http://www.williambharding.com/blog/uncategorized/what-happens-if-two-google-adwords-auto-targets-have-the-same-bid/</link>
		<comments>http://www.williambharding.com/blog/uncategorized/what-happens-if-two-google-adwords-auto-targets-have-the-same-bid/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 17:40:54 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=620</guid>
		<description><![CDATA[The title of this blog came up recently as we continue to optimize our Google Shopping Adwords bidding tool, and I wanted to share my learnings with future web searchers.    Our situation is that we use Google Shopping PLAs to drive traffic to Bonanza, and our bid amounts are specified via Adwords labels that [...]]]></description>
			<content:encoded><![CDATA[<p>The title of this blog came up recently as we continue to optimize our Google Shopping Adwords bidding tool, and I wanted to share my learnings with future web searchers.    Our situation is that we use Google Shopping PLAs to drive traffic to Bonanza, and our bid amounts are specified via Adwords labels that we apply to each item.  Most items will have multiple Adwords labels, where each Adwords label corresponds to an Adwords auto target.  My question to Google was:  when there is one product that has multiple Adwords labels, and those labels correspond to auto targets that have the same bid, which auto target gets credit for the impression (and subsequent click/conversion)?</p>
<p>The answer, straight from Google, makes a lot of sense:</p>
<blockquote><p>So the one that enters the auction will be attributed with the clicks and impressions and this is dependent on the performance history associated with that auto target. The one with the stronger performance history &#8211; clicks and CTR attributed to it, will enter the auction and hence get the impressions.</p>
<p>Additionally if they are from different ad groups &#8211; the past ad group performance history and ad group level CTR would also matter.</p></blockquote>
<p>Thus the answer:  whichever auto target performs best has the best chance of being shown in Google&#8217;s Adwords &#8220;auction&#8221; (the name they give to the process of choosing which Adword or GS products to show).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/uncategorized/what-happens-if-two-google-adwords-auto-targets-have-the-same-bid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Early Signs of a Coder</title>
		<link>http://www.williambharding.com/blog/rants/early-signs-of-a-coder/</link>
		<comments>http://www.williambharding.com/blog/rants/early-signs-of-a-coder/#comments</comments>
		<pubDate>Tue, 23 Oct 2012 06:39:00 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=604</guid>
		<description><![CDATA[What is the single question that is most predictive of dev ability?   The best coders come from a very disparate set of backgrounds, so it&#8217;s hard to group them on a single criteria. However, one characteristic that I have seen be consistently predictive:  starting at a young age.  Gates, Woz, and even Jordan did [...]]]></description>
			<content:encoded><![CDATA[<p>What is the single question that is most predictive of dev ability?   The best coders come from a very disparate set of backgrounds, so it&#8217;s hard to group them on a single criteria.</p>
<p>However, one characteristic that I have seen be consistently predictive:  starting at a young age.  Gates, Woz, and even Jordan did it.</p>
<p>I am not in position to say whether I make for a good, great, or gruesome coder (1).  But I know that my history with computers is epic:</p>
<ul>
<li>1993: Age 13. Get our first computer, a Packard Bell 486SX/33 with 4MB of RAM.  It came with a San Diego Zoo App, an encyclopedia, and a really lame racing app of some sort (not to mention all the Win 3.1 niceties).  (2)</li>
<li>1993: Learn how to use DOS, configure games to use extended memory, figure out how windows system config files work</li>
<li>1993: Discover QBasic.  Disappointed to learn that it doesn&#8217;t compile to exes.  Decide to write a choose-your-own-adventure game with it anyway, complete with ASCII graphics.</li>
<li>1994: Start a <a href="http://bbslist.textfiles.com/360/">BBS</a> (search for &#8220;Bill Harding&#8221; in the list), get the most calls in Poulsbo/Bremerton/Silverdale area (not saying much)</li>
<li>1994: Enroll in the first of two computer programming courses at local community college (4.0).</li>
<li>1995: Wrote VBBS scripts to emulate about five most popular BBS flavors (PCBoard, OBV/2, Renegade, etc).  To my knowledge, no one else accomplished this.  It was like carving a pumpkin with a butter knife.</li>
<li>1995: Finish the community college computer programming courses with 3.9 average</li>
<li>1996: Discover I prefer girls to computers</li>
</ul>
<p>From 1996 until late-college were the dark ages of Bill programming, wherein I spent the better part of my teens having forgotten about that whole computer thing. (3)</p>
<p>But the reasons coding was so magnetic to me are the reasons it still is:   a chance for me to dream up whatever I could think of, and then make it become real to feel the rush of creation.</p>
<p>It&#8217;s like what businesses are supposed to be:  you decide what&#8217;s important to you, and then go make that vision into reality.  But in business, there is constant compromise and pragmaticism that ultimately rules the day, unless you&#8217;re Steve Jobs.  For a competent coder, they can at any time create the best program (of a certain type) across all human history.  It could be used by thousands or millions of people.  If it&#8217;s important enough to spend years on.</p>
<p>Even in the more pragmatic here and now, I know of few other jobs with a comparable opportunity to build something that matters with one&#8217;s own two hands.  This is why I latched onto programming so tightly &amp; immediately at age 13.</p>
<p>Most of these characteristics are present by early teens:  the desire to build things, the capacity to solve problems, the joy of seeing a project completed&#8230; I think of them as &#8220;born qualities;&#8221; thus, my hunch is that if the teenager has access to a computer, they&#8217;ll probably figure out pretty quickly if they&#8217;re a programmer or not.</p>
<p>Update:  interviewed about 50 UW CS students today. The earliest coder of the bunch started in his late teens. The vast majority started when they entered the program (??!!).  So perhaps this theory is bunk, or these kids all suck.</p>
<p>(1) I suppose that having built Bonz is strong circumstantial evidence that I&#8217;m not gruesome</p>
<p>(2) Note how I remember the software that came with my first computer in as much detail as my first kiss</p>
<p>(3) Not entirely true; I did still fix old people&#8217;s computers at exorbitant prices (consistent with what other computer fixers charged). But mostly the cute girls beat the computers in this round.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/rants/early-signs-of-a-coder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Exception Handling and Notification with Errbit</title>
		<link>http://www.williambharding.com/blog/rails/rails-exception-handling-and-notification-with-errbit/</link>
		<comments>http://www.williambharding.com/blog/rails/rails-exception-handling-and-notification-with-errbit/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 18:37:31 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=596</guid>
		<description><![CDATA[Bonanza has travelled a long road when it comes to trying out exception handling solutions. In the dark &#38; early days we went simple with the Exception Notification plugin. The drawbacks of it were many, starting with the spam that it would spew forth when our site went into an error state and we&#8217;d end [...]]]></description>
			<content:encoded><![CDATA[<p>Bonanza has travelled a long road when it comes to trying out exception handling solutions. In the dark &amp; early days we went simple with the Exception Notification plugin. The drawbacks of it were many, starting with the spam that it would spew forth when our site went into an error state and we&#8217;d end up with thousands of emails. There was also no tracking of exceptions, which made it very difficult to get a sense for which exception was happening how often.</p>
<p>Eventually we moved to HopToad (now Airbrake). It was better, but lacked key functionality like being able to close exceptions en masse or leave comments on an exception.</p>
<p>From there we moved to <a href="http://exceptional.io">Exceptional</a>, which we ended up using for the past year.  It was alright, when it worked.  The problem was, for us, it frequently didn&#8217;t work.  Most recently, we spent the last week having received two exceptions reported by Exceptional, when New Relic clearly showed that hundreds of exceptions had happened over that time period.  Also damning was the presentation of backtraces, which were hard to read (when present), as well as an error index page that made it difficult to discern what the errors were until they were clicked through.</p>
<p>Enter <a href="https://github.com/errbit/errbit">Errbit</a>.  Jordan found this yesterday as we evaluated what to do about the lack of exceptions we were receiving from Exceptional.  Within a couple hours, he had gotten Errbit setup for us, and suddenly we were treated to hundreds of new exceptions that Exceptional had silently swallowed from our app over the past year.</p>
<p>But it&#8217;s not just that Errbit does what it is supposed to &#8212; it&#8217;s the bells and whistles it does it with.</p>
<p><a href="http://www.williambharding.com/blog/wp-content/uploads/2012/10/errbit.png"><img class="alignnone size-large wp-image-597" title="errbit" src="http://www.williambharding.com/blog/wp-content/uploads/2012/10/errbit-1024x606.png" alt="" width="540" height="319" /></a></p>
<p>Specifically, a handful of the features that make Errbit such a great solution:</p>
<ul>
<li>Can set it up to email at intervals (e.g., 1st exception, 100th exception) so you hear about an exception when it first happens, and get reminded about it again later if it continues to be a repeat offender</li>
<li>Allows exceptions to be merged (or batch merged) when similar</li>
<li>Allows comments by developers on exceptions, and shows those comments from the main index page so you can quickly see if an exception is being worked on without needing to click through to it</li>
<li>Easy to read backtrace, <strong>plus </strong>automagic tie-in to Github, where you can actually click on the backtrace and see the offending code from within Github (holy jeez!)</li>
<li>Liberal use of spacing and HTML/CSS to make it much easier to read session, backtrace, etc relative to Exceptional and other solutions we&#8217;ve used</li>
<li>Open source, so you can add whatever functionality you desire rather than waiting for a third party to get around to it (a fact we&#8217;ve already made use of repeatedly in our first two days)</li>
<li>Open source, so the price is right (free)</li>
</ul>
<p>Simply put, if you&#8217;re running a medium-to-large Rails app and you&#8217;re not using Errbit, you&#8217;re probably using the wrong solution.  <a href="https://github.com/errbit/errbit">Detailed installation instructions exist on the project&#8217;s Github home</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/rails/rails-exception-handling-and-notification-with-errbit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fix: IRB pasting is super slow, typing in ruby debugger has lag</title>
		<link>http://www.williambharding.com/blog/rails/fix-irb-pasting-is-super-slow-typing-in-ruby-debugger-has-lag/</link>
		<comments>http://www.williambharding.com/blog/rails/fix-irb-pasting-is-super-slow-typing-in-ruby-debugger-has-lag/#comments</comments>
		<pubDate>Wed, 30 May 2012 01:17:15 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[lag]]></category>
		<category><![CDATA[paste]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[slow]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=589</guid>
		<description><![CDATA[After numerous hours spent trying unsuccessfully to fix this problem by following the instructions outlined on a few StackOverflow posts, Jordan presented a recipe for fixing this problem (that actually fixed the problem) today. The essence of the issue is that the readline package that gets installed with REE is by default some bastard version [...]]]></description>
			<content:encoded><![CDATA[<p>After numerous hours spent trying unsuccessfully to fix this problem by following the instructions outlined on a few StackOverflow posts, Jordan presented a recipe for fixing this problem (that actually fixed the problem) today.</p>
<p>The essence of the issue is that the readline package that gets installed with REE is by default some bastard version that lags, at least on our Ubuntu and Mint installations. Installing the rvm readline package did not fix it for either of us, nor did an assortment of experiments on compiling REE with different options. Here&#8217;s what did:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$<span style="color:#006600; font-weight:bold;">&gt;</span> sudo apt<span style="color:#006600; font-weight:bold;">-</span>get remove libreadline6<span style="color:#006600; font-weight:bold;">-</span>dev
$<span style="color:#006600; font-weight:bold;">&gt;</span> sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install libreadline<span style="color:#006600; font-weight:bold;">-</span>gplv2<span style="color:#006600; font-weight:bold;">-</span>dev
$<span style="color:#006600; font-weight:bold;">&gt;</span> rvm remove ree
$<span style="color:#006600; font-weight:bold;">&gt;</span> rvm install ree</pre></div></div>

<p>One problem you may encounter is that if you&#8217;re avoiding newer versions of Ubuntu until admit defeat about Unity, the &#8220;libreadline-gplv2-dev&#8221; package is by default only present in Oneiric and above.  Here&#8217;s where I found the package versions that worked with Maverick:  <a href="https://launchpad.net/~dns/+archive/test0/+sourcepub/2252776/+listing-archive-extra" title="https://launchpad.net/~dns/+archive/test0/+sourcepub/2252776/+listing-archive-extra">https://launchpad.net/~dns/+archive/test0/+sourcepub/2252776/+listing-archive-extra</a>.  After downloading the packages from this link, the install sequence became</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$<span style="color:#006600; font-weight:bold;">&gt;</span> sudo apt<span style="color:#006600; font-weight:bold;">-</span>get remove libreadline6<span style="color:#006600; font-weight:bold;">-</span>dev libreadline5
$<span style="color:#006600; font-weight:bold;">&gt;</span> sudo dpkg <span style="color:#006600; font-weight:bold;">-</span>i libreadline5_5.2<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span>~maverick0_amd64.<span style="color:#9900CC;">deb</span>
$<span style="color:#006600; font-weight:bold;">&gt;</span> sudo dpkg <span style="color:#006600; font-weight:bold;">-</span>i libreadline<span style="color:#006600; font-weight:bold;">-</span>gplv2<span style="color:#006600; font-weight:bold;">-</span>dev_5.2<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span>~maverick0_amd64.<span style="color:#9900CC;">deb</span>
$<span style="color:#006600; font-weight:bold;">&gt;</span> rvm remove ree
$<span style="color:#006600; font-weight:bold;">&gt;</span> rvm install ree</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/rails/fix-irb-pasting-is-super-slow-typing-in-ruby-debugger-has-lag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a Custom Thumbnail Processor in Carrierwave</title>
		<link>http://www.williambharding.com/blog/rails/howto-create-a-custom-thumbnail-processor-in-carrierwave/</link>
		<comments>http://www.williambharding.com/blog/rails/howto-create-a-custom-thumbnail-processor-in-carrierwave/#comments</comments>
		<pubDate>Thu, 10 May 2012 00:21:45 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[carrierwave]]></category>
		<category><![CDATA[custom processing]]></category>
		<category><![CDATA[image processing]]></category>
		<category><![CDATA[thumbnail]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=577</guid>
		<description><![CDATA[The latest in my of &#8220;shouldn&#8217;t this be better covered in Google and docs if people really use CarrierWave?&#8221;-series. Creating a custom thumbnail processor in Carrierwave is pretty straightforward, but not from any search query I could construct. The gist: class MyUploader &#38;lt; CarrierWave::Uploader::Base version :custom_thumbnail do process :some_fancy_processing end &#160; def some_fancy_processing # Here [...]]]></description>
			<content:encoded><![CDATA[<p>The latest in my of &#8220;shouldn&#8217;t this be better covered in Google and docs if people really use CarrierWave?&#8221;-series.  Creating a custom thumbnail processor in Carrierwave is pretty straightforward, but not from any search query I could construct.  The gist:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MyUploader <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">CarrierWave::Uploader::Base</span>
  version <span style="color:#ff3333; font-weight:bold;">:custom_thumbnail</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    process <span style="color:#ff3333; font-weight:bold;">:some_fancy_processing</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> some_fancy_processing
    <span style="color:#008000; font-style:italic;"># Here our context is the CarrierWave::Uploader object, so we have its full</span>
    <span style="color:#008000; font-style:italic;"># assortment of methods at our disposal.  Let's say we want to open an image with</span>
    <span style="color:#008000; font-style:italic;"># openCV and smooth it out.  That would look something like:</span>
    cv_image = <span style="color:#6666ff; font-weight:bold;">OpenCV::CvMat</span>.<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">full_cache_path</span> <span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># See past blog post on the origins of full_cache_path</span>
    cv_image.<span style="color:#9900CC;">smooth</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span>,<span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># The key to telling CW what data this thumb should use is to save our output to</span>
    <span style="color:#008000; font-style:italic;"># the current_path of the Uploader, a la</span>
    cv_image.<span style="color:#9900CC;">save_image</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">current_path</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Just call #custom_thumbnail.url on your Uploader instance, and you should get the path to the custom result you created.</p>
<p>Using this framework you should be able to get CW to perform whatever sort of custom image processing you want.   Thanks to <a href="http://www.freezzo.com/2010/12/23/create-ffmpeg-processor-for-carrierwave-in-rails-3/">these fellows</a> for helping me decode the #current_path magic here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/rails/howto-create-a-custom-thumbnail-processor-in-carrierwave/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto: Store a CarrierWave File Locally After Uploading to S3</title>
		<link>http://www.williambharding.com/blog/rails/howto-store-a-carrierwave-file-locally-after-uploading-to-s3/</link>
		<comments>http://www.williambharding.com/blog/rails/howto-store-a-carrierwave-file-locally-after-uploading-to-s3/#comments</comments>
		<pubDate>Wed, 09 May 2012 23:45:15 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[carrierwave]]></category>
		<category><![CDATA[retrieve_from_cache]]></category>
		<category><![CDATA[retrieve_from_store]]></category>
		<category><![CDATA[storage]]></category>

		<guid isPermaLink="false">http://www.williambharding.com/blog/?p=571</guid>
		<description><![CDATA[Have now needed to do this twice, and both times have required about an hour of sifting through Google morass to figure out how to pull this off. The situation we&#8217;re assuming here is that you have some CarrierWave file that you&#8217;ve stored to a remote location, and you want to get a copy of [...]]]></description>
			<content:encoded><![CDATA[<p>Have now needed to do this twice, and both times have required about an hour of sifting through Google morass to figure out how to pull this off.   The situation we&#8217;re assuming here is that you have some CarrierWave file that you&#8217;ve stored to a remote location, and you want to get a copy of that file locally to manipulate it.  With promising method names like &#8220;retrieve_from_cache!&#8221; and &#8220;cache!&#8221; and &#8220;move_to_cache&#8221; you too may become entangled in the maze of what the hell you&#8217;re supposed to be calling to accomplish this.  Here&#8217;s what.</p>
<p><strong>Step 1</strong>:   Retrieve from your store (the external place your file exists) to cache (your local machine).</p>

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

<p>After running that, if you call</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">my_cw_uploader.<span style="color:#9900CC;">cached</span>?</pre></div></div>

<p>You should get a long string that is the filename for the file that got cached.  Note that the cache status of a file is only saved on a per-object basis, so if you try something like</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Image.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">my_cw_uploader</span>.<span style="color:#9900CC;">cache_stored_file</span>!</pre></div></div>

<p>&#8230; you will never again see the object that did the caching, and you will never be able to use that cache.   Only call #cache_stored_file! on an object you are keeping around.</p>
<p><strong>Step 2</strong>: Go access the file that you cached.  Not quite as easy as it sounds.  For this, I mixed in the following into my uploader class</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#6666ff; font-weight:bold;">CarrierWave::Uploader::Cache</span>
	<span style="color:#9966CC; font-weight:bold;">def</span> full_cache_path
		<span style="color:#996600;">&quot;#{::Rails.root}/public/#{cache_dir}/#{cache_name}&quot;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So now when you call</p>

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

<p>You&#8217;ll get the full pathname to the file you downloaded.  </p>
<p>Hope this helps save someone else from an hour of Google hell.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.williambharding.com/blog/rails/howto-store-a-carrierwave-file-locally-after-uploading-to-s3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
