<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Husband, father, designer &amp; developer, photographer, fly-fisherman, secret admirer of interior design, and proprietor of a silly, and sometimes awkwardly juvenile, monicker.

Twitter: @mrpunkin | Flickr: mrpunkin | Dribbble mrpunkin</description><title>MrPunkin</title><generator>Tumblr (3.0; @mrpunkin)</generator><link>http://mrpunkin.com/</link><item><title>Conditionally precompile assets with Rails 3 &amp; Capistrano</title><description>&lt;p&gt;We recently started testing &lt;a href="http://www.capify.org" target="_blank"&gt;Capistrano&lt;/a&gt; again for deployment of our Rails app. One of the first things I set out to find was a way to use Capistrano without the versioned folder structure, since &lt;a href="http://git-scm.com/" target="_blank"&gt;Git&lt;/a&gt; is in control of all our versioning.&lt;/p&gt;

&lt;p&gt;I found this &lt;a href="http://github.com/blog/470-deployment-script-spring-cleaning" target="_blank"&gt;great article&lt;/a&gt; about how achieve a Git-based Capistrano strategy, where he references an older &lt;a href="http://github.com/blog/470-deployment-script-spring-cleaning" target="_blank"&gt;blog post&lt;/a&gt; on the Git that describes the speed benefits, and the added advantages of splitting up your deploy.rb file into numerous smaller files.&lt;/p&gt;

&lt;p&gt;I was able to get all that up and working just fine, with a few minor changes to be able to use the provided Bundler and asset pipeline Capistrano tasks to install my required gems, and precompile assets. The first thing I noticed, however, was how frustrating it was to precompile assets every time I ran my deploy task. There had to be a better way!&lt;/p&gt;

&lt;p&gt;Well, I&amp;#8217;m proud to say I figured something out that I think will work well. We&amp;#8217;ll see over time, as I try it in production.&lt;/p&gt;

&lt;p&gt;My solution relies on checking the modified date of all non Git files nested under app/assets and finding those which have been modified in the last N minutes. If that list is empty it skips the asset precompiling by removing the &lt;code&gt;:after&lt;/code&gt; callback that triggers it.&lt;/p&gt;

&lt;script src="https://gist.github.com/2784462.js"&gt; &lt;/script&gt;&lt;p&gt;As you can see, I have created a few asset tasks that I place in an deploy/assets.rb file, which is included by my Capfile. The two tasks are described below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;determine_modified_assets&lt;/code&gt;:&lt;/strong&gt; Sets the variable &lt;code&gt;updated_assets&lt;/code&gt; to be an array of all assets that have been updated in the last N minutes. The amount of minutes is defined above by the &lt;code&gt;max_asset_age&lt;/code&gt; variable I have set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;conditionally_precompile&lt;/code&gt;:&lt;/strong&gt; Tests the &lt;code&gt;updated_assets&lt;/code&gt; variable to see if any assets were updated. If not, it removes the :after callback that runs &lt;code&gt;deploy:assets:precompile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I also set an after chain that hooks into &lt;code&gt;deploy:finalize_update&lt;/code&gt;, which runs well before the &lt;code&gt;deploy:update_code&lt;/code&gt; task that the asset precompile task runs after by default. This gives us time to unset the callback.&lt;/p&gt;</description><link>http://mrpunkin.com/post/23695354940</link><guid>http://mrpunkin.com/post/23695354940</guid><pubDate>Thu, 24 May 2012 15:32:50 -0700</pubDate><category>code</category><category>rails</category><category>ruby on rails</category><category>ruby</category><category>capistrano</category><category>web development</category></item><item><title>Using Arel for SQL functions</title><description>&lt;p&gt;If you are anything like me you understand that sometimes there are things you want to do a certain way, simply because you want to understand how to accomplish the task in a specific manner. I came across one of those instances today while trying to convert an old SQL-laden  ActiveRecord method to a new Rails 3 ActiveRecord::Relation chain.&lt;/p&gt;

&lt;p&gt;I wanted to know if there was a way to do a &lt;code&gt;GROUP BY&lt;/code&gt; in MySQL on a &lt;code&gt;DATE()&lt;/code&gt; converted value of a column without having to write the raw SQL statement. Before I show anything I want to acknowledge that I &lt;strong&gt;do&lt;/strong&gt; understand that it would be cleaner to read, and easier to accomplish, if I had just written the SQL into the &lt;code&gt;group()&lt;/code&gt; portion of the chain. My concern was finding a way to achieve this same effect using Arel, just incase you wanted to write database-agnostic code.&lt;/p&gt;

&lt;p&gt;Now let&amp;#8217;s suppose you wanted to grab the &lt;code&gt;DATE()&lt;/code&gt; conversion of a &lt;code&gt;DATETIME&lt;/code&gt; column, and that you already understand Arel and are using it to start building a join&amp;#8230;&lt;/p&gt;

&lt;script src="https://gist.github.com/1996454.js?file=sql_based.rb"&gt;&lt;/script&gt;&lt;p&gt;You can see we aren&amp;#8217;t using SQL strings to build our join, so why should we have to in order to get our date conversion, or other undefined Arel methods? As it turns out, we don&amp;#8217;t! Arel has a little class called NamedFunction that will give us exactly what we want&amp;#8230;&lt;/p&gt;

&lt;script src="https://gist.github.com/1996454.js?file=arel_based.rb"&gt;&lt;/script&gt;&lt;p&gt;You can see by my printing of the generated SQL when running &lt;code&gt;.to_sql&lt;/code&gt; that we were able to build the same result without writing any raw SQL, short of the function name. The second argument passed to a new &lt;code&gt;NamedFunction&lt;/code&gt; instance needs to be an array, which you can utilize if your SQL function requires multiple arguments.&lt;/p&gt;

&lt;p&gt;With a little knowledge of how Arel builds the SQL strings you can even get a bit tricky with   &lt;code&gt;Arel::Attributes::Attribute&lt;/code&gt; objects and start using Arel to do things such as build a  &lt;code&gt;CAST()&lt;/code&gt; function&amp;#8230;&lt;/p&gt;

&lt;script src="https://gist.github.com/1996454.js?file=cast.rb"&gt;&lt;/script&gt;&lt;p&gt;Anyways, mess around with it. Even if you don&amp;#8217;t deem it clean enough to be of use, at least you know to do it.&lt;/p&gt;</description><link>http://mrpunkin.com/post/18919379925</link><guid>http://mrpunkin.com/post/18919379925</guid><pubDate>Wed, 07 Mar 2012 14:22:00 -0800</pubDate><category>ruby on rails</category><category>rails</category><category>ruby</category><category>arel</category><category>web development</category><category>ActiveRecord</category></item><item><title>Backlit</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lvtlm2oqKU1qz4e10o1_250.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;a href="http://www.flickr.com/photos/mrpunkin/6460491147/" target="_blank"&gt;Backlit&lt;/a&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/13864084102</link><guid>http://mrpunkin.com/post/13864084102</guid><pubDate>Tue, 06 Dec 2011 22:20:27 -0800</pubDate></item><item><title>Morning Grass</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_lvkkgg5WUB1qz4e10o1_250.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;a href="http://www.flickr.com/photos/mrpunkin/6439907469/" target="_blank"&gt;Morning Grass&lt;/a&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/13628901762</link><guid>http://mrpunkin.com/post/13628901762</guid><pubDate>Fri, 02 Dec 2011 05:17:04 -0800</pubDate></item><item><title>In the Box</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lvfquoDwr11qz4e10o1_250.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;a href="http://www.flickr.com/photos/mrpunkin/6423550851/" target="_blank"&gt;In the Box&lt;/a&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/13506820202</link><guid>http://mrpunkin.com/post/13506820202</guid><pubDate>Tue, 29 Nov 2011 14:47:13 -0800</pubDate></item><item><title>Nest | The Learning Thermostat | Home</title><description>&lt;a href="http://www.nest.com/index.html"&gt;Nest | The Learning Thermostat | Home&lt;/a&gt;</description><link>http://mrpunkin.com/post/13299174776</link><guid>http://mrpunkin.com/post/13299174776</guid><pubDate>Fri, 25 Nov 2011 10:46:12 -0800</pubDate></item><item><title>Drawsgood Illustration and Design Portfolio - The artwork of Michael B. Myers Jr.</title><description>&lt;a href="http://www.drawsgood.com/9923/gallery"&gt;Drawsgood Illustration and Design Portfolio - The artwork of Michael B. Myers Jr.&lt;/a&gt;</description><link>http://mrpunkin.com/post/13250523059</link><guid>http://mrpunkin.com/post/13250523059</guid><pubDate>Thu, 24 Nov 2011 08:34:12 -0800</pubDate></item><item><title>Sunrise</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_ltrazfO0cG1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Sunrise&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/12019832848</link><guid>http://mrpunkin.com/post/12019832848</guid><pubDate>Fri, 28 Oct 2011 00:28:29 -0700</pubDate></item><item><title>Cafe</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_ltlz3dlZKW1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Cafe&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/11899726272</link><guid>http://mrpunkin.com/post/11899726272</guid><pubDate>Tue, 25 Oct 2011 03:23:39 -0700</pubDate></item><item><title>Road Trippin’</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_ltiwb7Js9r1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Road Trippin’&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/11817890450</link><guid>http://mrpunkin.com/post/11817890450</guid><pubDate>Sun, 23 Oct 2011 11:30:45 -0700</pubDate></item><item><title>DC*B</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lsyab1cveS1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;DC*B&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/11350835271</link><guid>http://mrpunkin.com/post/11350835271</guid><pubDate>Wed, 12 Oct 2011 08:23:27 -0700</pubDate></item><item><title>NeedToBreathe – Oohs and Ahhs</title><description>&lt;a href="http://www.last.fm/music/NeedToBreathe/_/Oohs+and+Ahhs"&gt;NeedToBreathe – Oohs and Ahhs&lt;/a&gt;: &lt;p&gt;&lt;a href="http://www.last.fm/music/NeedToBreathe" target="_blank"&gt;http://www.last.fm/music/NeedToBreathe&lt;/a&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/10491431005</link><guid>http://mrpunkin.com/post/10491431005</guid><pubDate>Wed, 21 Sep 2011 17:59:11 -0700</pubDate></item><item><title>Elastislide - A Responsive jQuery Carousel Plugin</title><description>&lt;a href="http://tympanus.net/Development/Elastislide/index5.html"&gt;Elastislide - A Responsive jQuery Carousel Plugin&lt;/a&gt;</description><link>http://mrpunkin.com/post/10209678447</link><guid>http://mrpunkin.com/post/10209678447</guid><pubDate>Wed, 14 Sep 2011 16:38:40 -0700</pubDate></item><item><title>Sunbreak</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lra7qh1iWI1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Sunbreak&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/10015348362</link><guid>http://mrpunkin.com/post/10015348362</guid><pubDate>Fri, 09 Sep 2011 21:51:55 -0700</pubDate></item><item><title>Morning Group</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lpr31vYtOs1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Morning Group&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/8769476196</link><guid>http://mrpunkin.com/post/8769476196</guid><pubDate>Thu, 11 Aug 2011 03:22:45 -0700</pubDate></item><item><title>Jar light</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_lp7ob9x55J1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Jar light&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/8305508598</link><guid>http://mrpunkin.com/post/8305508598</guid><pubDate>Sun, 31 Jul 2011 15:49:59 -0700</pubDate></item><item><title>Morning Fog</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lp3vxmsScN1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Morning Fog&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/8221263918</link><guid>http://mrpunkin.com/post/8221263918</guid><pubDate>Fri, 29 Jul 2011 14:44:12 -0700</pubDate></item><item><title>Clouds</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_lo4d99jImk1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Clouds&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/7453670451</link><guid>http://mrpunkin.com/post/7453670451</guid><pubDate>Sun, 10 Jul 2011 10:24:47 -0700</pubDate></item><item><title>Sea Nettles</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lo36dq2HCM1qz4e10o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;Sea Nettles&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/7431263768</link><guid>http://mrpunkin.com/post/7431263768</guid><pubDate>Sat, 09 Jul 2011 18:58:40 -0700</pubDate></item><item><title>The Drive Home</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_llps4ag3xB1qz4e10o1_250.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;b&gt;The Drive Home&lt;/b&gt;&lt;/p&gt;</description><link>http://mrpunkin.com/post/5806530713</link><guid>http://mrpunkin.com/post/5806530713</guid><pubDate>Tue, 24 May 2011 16:14:35 -0700</pubDate></item></channel></rss>

