<?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>Doug McInnes &#187; Coding</title>
	<atom:link href="http://dougmcinnes.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://dougmcinnes.com</link>
	<description>Chuckle and Chortle</description>
	<lastBuildDate>Wed, 24 Aug 2011 05:51:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>HTML 5 Asteroids on the iPad</title>
		<link>http://dougmcinnes.com/2010/05/24/html-5-asteroids-on-the-ipad/</link>
		<comments>http://dougmcinnes.com/2010/05/24/html-5-asteroids-on-the-ipad/#comments</comments>
		<pubDate>Tue, 25 May 2010 07:29:44 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[asteroids]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=168</guid>
		<description><![CDATA[I&#8217;ve added touch controls to the HTML 5 Asteroids game that will only appear when you&#8217;re running it on an iPad.  The game will expand to fill the whole screen for maximum asteroid blasting action.  Orient your iPad in landscape &#8230; <a href="http://dougmcinnes.com/2010/05/24/html-5-asteroids-on-the-ipad/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added touch controls to the HTML 5 Asteroids game that will only appear when you&#8217;re running it on an iPad.  The game will expand to fill the whole screen for maximum asteroid blasting action.  Orient your iPad in landscape fashion!</p>
<h1 style="text-align: center;"><a href="http://dougmcinnes.com/html-5-asteroids/">Play It!</a></h1>
<p> </p>
<p>There are a couple caveats (warning some nerdy content ahead):</p>
<h4>Tunneling Effect</h4>
<p>On the iPad the game runs at around 22 frames per second at its peak, not nearly as good as around 40 on a laptop, though it is enough for gameplay even if it can get choppy at times when there&#8217;s a lot of stuff whizzing around.</p>
<p>Unfortunately I&#8217;m only testing for collisions when the objects are rendered so it&#8217;s quite possible with lower framerates to have a bullet flying out of your ship first get rendered on one side of the asteroid you&#8217;re trying to pulverize and in the next frame get rendered on the other side letting it sail undamaged into your ship.  This is called the tunneling effect.  This is not a problem on a laptop or desktop because the framerates are high.  Since we&#8217;re sampling less per second (~22 verses ~40) a moving object is drawn less times though it&#8217;s traveling the same distance.  In other words if an asteroid travels from the top of the screen to the bottom of the screen in one second, on your computer it will most likely get drawn 40 times during that trip and on an iPad it will get drawn only 22 times leaving larger gaps between the drawings.  These larger gaps leave more of a chance for things to slip through and not collide when your eyes say they should have.</p>
<p>I&#8217;m considering augmenting the collision detection to remove the tunneling effect but it will need extra math which means slower framerates, at least initially.  It might be a better use of my time to pump framerates up.</p>
<h4>Buggy Touch Events</h4>
<p>There&#8217;s a bug with the iPad&#8217;s implementation of touch events in Javascript: if you have two fingers on the screen and raise one of them, a &#8220;touchend&#8221; event gets fired containing a reference to both fingers even though the second one hasn&#8217;t been raised.  If you then raise the second one, a &#8220;touchend&#8221; event is not fired.</p>
<p>It drove me nuts trying to figure this out and I haven&#8217;t been able to  work around it.</p>
<p>What this means for the game is that using two fingers at the same time will get frustrating fast as the control you&#8217;re holding down will stop working periodically.  I suggest tapping for the best experience instead of holding.</p>
<p>Oh, this does not happen on the iPhone in case you were wondering, it works as expected! I have sent a bug report to apple (with a <a href="/wp-content/uploads/2010/05/test.html">sample html page</a>) and hopefully they already have a fix that&#8217;s not available yet or they will fix it for a future release.</p>
<p>On a side note, why aren&#8217;t Apple&#8217;s bug lists searchable by the public?  They must get reams of dupes.</p>
<ol> </ol>
<p>In any case, let me know how it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2010/05/24/html-5-asteroids-on-the-ipad/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTML 5 Asteroids</title>
		<link>http://dougmcinnes.com/2010/05/12/html-5-asteroids/</link>
		<comments>http://dougmcinnes.com/2010/05/12/html-5-asteroids/#comments</comments>
		<pubDate>Thu, 13 May 2010 06:42:31 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[asteroids]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=126</guid>
		<description><![CDATA[For some months I&#8217;ve been playing around with HTML 5&#8242;s Canvas element because I was curious about it, especially after seeing it run Flash.  I hacked at it for a while then realized I had produced an Asteroids game. Play &#8230; <a href="http://dougmcinnes.com/2010/05/12/html-5-asteroids/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">For some  months I&#8217;ve been playing around with HTML 5&#8242;s Canvas element because I was curious about it, especially after <a href="http://wiki.github.com/tobeytailor/gordon/">seeing it run Flash</a>.  I hacked at it for a  while then realized I had produced an Asteroids game.<img class="size-full wp-image-132 alignright" title="asteriods" src="http://dougmcinnes.com/wp-content/uploads/2010/05/asteriods.png" alt="" width="171" height="134" /></p>
<h1 style="text-align: center;"><a title="Play It!" href="/html-5-asteroids/">Play It!</a></h1>
<p style="text-align: left;"> </p>
<p style="text-align: left;">The source code is <a href="http://github.com/dmcinnes/HTML5-Asteroids">up on GitHub</a>!</p>
<p style="text-align: left;">The <a href="https://developer.mozilla.org/en/Canvas_tutorial">Canvas</a> element is super cool.  Basically all of the sprites in the game are simple paths defined by an array of points.  These points are translated, rotated and scaled based on their state at any given point in the game using the standard Canvas transformations.  Plus it gives it a nice retro feel.</p>
<p style="text-align: left;">Let me know what you think!</p>
<p style="text-align: left;">Here&#8217;s some cool links to things that helped me out with the game:</p>
<ul style="text-align: left;">
<li><a href="http://www.alienryderflex.com/polygon/">Determining Whether A Point Is Inside A Complex Polygon</a>.  Firefox does the wrong thing when it comes to isPointInPath(), the main Canvas method I used for collision detection; It doesn&#8217;t apply the current transformations before determining if there&#8217;s been a collision (and <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=405300">they won&#8217;t fix it</a> for some reason).  I implemented this method to get around the problem but it works fast enough it could be used on all browsers.</li>
<li><a href="http://www.metanetsoftware.com/">Metanet Software</a>, the makers of the awesome flash game <a href="http://www.thewayoftheninja.org/n.html">N</a>, have made a couple of extremely useful <a href="http://www.metanetsoftware.com/technique.html">tutorials on collision detection</a>.  These describe some of the techniques I used in the game, in particular the grid based broad-phase they describe in their second tutorial.</li>
<li>I used <a href="http://typeface.neocracy.org/">typeface.js</a> &#8216;s <a href="http://typeface.neocracy.org/fonts.html">convert tool</a> to convert the awesome <a href="http://www.dafont.com/vector-battle.font">Vector Battle</a> font into some JSON point data that could be easily used in the canvas.  Typeface.js is a neat library for easily embedding arbitrary fonts in the page.  On supported browsers it creates small canvas elements and renders the font inside based on the CSS.  I borrowed bits from the library to get the font rendering.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2010/05/12/html-5-asteroids/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
		<item>
		<title>Ruby Vim Fu</title>
		<link>http://dougmcinnes.com/2010/04/11/ruby-vim-fu/</link>
		<comments>http://dougmcinnes.com/2010/04/11/ruby-vim-fu/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 06:18:19 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[LA Ruby]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=81</guid>
		<description><![CDATA[This last Thursday Alf and I gave a talk at LA Ruby on Vim, in particular how we use Vim to edit Ruby code.  Giles asked us to present on Vim months ago and we finally got around to doing &#8230; <a href="http://dougmcinnes.com/2010/04/11/ruby-vim-fu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This last Thursday <a href="http://alfmikula.blogspot.com/">Alf</a> and I gave a talk at <a href="http://www.laruby.com/">LA Ruby</a> on <a href="http://www.vim.org/">Vim</a>, in particular how we use Vim to edit Ruby code.  <a href="http://gilesbowkett.blogspot.com/">Giles</a> asked us to present on Vim months ago and we finally got around to doing it.</p>
<p>I think it went well considering we probably spent more time figuring out the background color scheme on our slides than preparing what we were going to say.  I wasn&#8217;t worried, I&#8217;ve been using Vim for 15 years now so it was my favorite kind of speech: one where I felt completely at ease with the subject matter.</p>
<p>In any case here are the slides in a <a href="http://amikula.github.com/vim_fu/">viewable form</a> on Github, as well as the <a href="http://github.com/amikula/vim_fu">source</a>.  We used the <a href="http://slideshow.rubyforge.org/">Slideshow gem</a> to set them up.</p>
<p>The slides probably will not be of any particular use to you since they&#8217;re rather sparse.  We however added a bunch of links on the end to blogs/screencasts/cool sites we like as well as all of the plugins we mentioned during the talk.</p>
<p>So you don&#8217;t have to hunt through the slides here are those links in all their glory:</p>
<h1>Links</h1>
<p><a href="http://www.vim.org/">http://www.vim.org/</a></p>
<p><strong>MacVim</strong> – <a href="http://code.google.com/p/macvim/">http://code.google.com/p/macvim/</a></p>
<p><a href="http://vim.wikia.com/wiki/Best_Vim_Tips">http://vim.wikia.com/wiki/Best_Vim_Tips</a></p>
<p><strong>Cheat Sheet!</strong> –  <a href="http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html">http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html</a></p>
<p><a href="http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html"></a><a href="http://items.sjbach.com/319/configuring-vim-right">http://items.sjbach.com/319/configuring-vim-right</a></p>
<p><strong>Screencasts on Vim</strong> – <a href="http://vimcasts.org/">http://vimcasts.org/</a></p>
<p><strong>Vim Tip a Day on Twitter</strong> – <a href="http://twitter.com/vimtips">http://twitter.com/vimtips</a></p>
<p><a href="http://durdn.com/blog/2008/11/26/vim-mind-share-soaring-roundup-of-10-vim-articles-recent-and-older-gems/">http://durdn.com/blog/2008/11/26/vim-mind-share-soaring-roundup-of-10-vim-articles-recent-and-older-gems/</a></p>
<p><a href="http://durdn.com/blog/2008/11/26/vim-mind-share-soaring-roundup-of-10-vim-articles-recent-and-older-gems/"></a><strong>Vim Recipies</strong> – <a href="http://vim.runpaint.org/toc/">http://vim.runpaint.org/toc/</a></p>
<p><a href="http://biodegradablegeek.com/2007/12/using-vim-as-a-complete-ruby-on-rails-ide/">http://biodegradablegeek.com/2007/12/using-vim-as-a-complete-ruby-on-rails-ide/</a></p>
<h1>Plugins</h1>
<p><strong>The Rails Plugin</strong> – <a href="http://rails.vim.tpope.net/">http://rails.vim.tpope.net/</a></p>
<p><strong>NERD Tree</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=1658">http://www.vim.org/scripts/script.php?script_id=1658</a></p>
<p><strong>Command-T</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=3025">http://www.vim.org/scripts/script.php?script_id=3025</a></p>
<p><strong>BufExplorer</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=42">http://www.vim.org/scripts/script.php?script_id=42</a></p>
<p><strong>AutoTag</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=1343">http://www.vim.org/scripts/script.php?script_id=1343</a></p>
<p><a href="http://www.vim.org/scripts/script.php?script_id=1343"></a><strong>Vimball</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=1502">http://www.vim.org/scripts/script.php?script_id=1502</a></p>
<p><strong>NERDCommenter</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=1218">http://www.vim.org/scripts/script.php?script_id=1218</a></p>
<p><strong>NERDSnippets</strong> – <a href="http://github.com/scrooloose/nerdsnippets">http://github.com/scrooloose/nerdsnippets</a></p>
<p><strong>Align</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=294">http://www.vim.org/scripts/script.php?script_id=294</a></p>
<p><strong>RubySingleTest</strong> – <a href="http://www.vim.org/scripts/script.php?script_id=2869">http://www.vim.org/scripts/script.php?script_id=2869</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2010/04/11/ruby-vim-fu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Single Test</title>
		<link>http://dougmcinnes.com/2009/02/16/ruby-single-test/</link>
		<comments>http://dougmcinnes.com/2009/02/16/ruby-single-test/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 15:59:11 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=73</guid>
		<description><![CDATA[I, like many developers, do my best to follow the practice of Test Driven Development (TDD). In practical terms this means you write a test to test your code before you write the code itself. This approach forces your mindset &#8230; <a href="http://dougmcinnes.com/2009/02/16/ruby-single-test/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I, like many developers, do my best to follow the practice of <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a> (TDD).  In practical terms this means you write a test to test your code before you write the code itself.  This approach forces your mindset into having a clearer sense of how the code will be used since you&#8217;re writing code to use the code first.  Got it?   Increased test coverage also means more robust and maintainable code.</p>
<p>My first formal introduction to TDD was a <a href="http://pragmaticstudio.com/testing-rails/">three-day TDD workshop</a> put on by <a href="http://onestepback.org/">Jim Weirich</a> and <a href="http://objo.com/">Joe O&#8217;Brien</a> while I was at the Los Angeles Times.  Jim, an expert EMACS user, had his system setup to run tests quickly from within the editor, even showing a red or green notice indicating the pass/fail status of the test.</p>
<p>This may not seem like a big deal to people using any number of IDEs but personally, I&#8217;m a <a href="http://www.vim.org/">Vim</a> user (specifically <a href="http://code.google.com/p/macvim/">MacVim</a>, it&#8217;s an extremely well done port of Vim using Cocoa).  I love it.  I&#8217;m way faster editing inside of Vim; my brain has mapped around all of the commands because I&#8217;ve been editing with it for so long.  I&#8217;ve been using vi variants in one form or another since my Freshman year of college when my Computer Science 101 professor forced us all to code with it for our programming projects on the school&#8217;s Sun server.  While doing Java work two or so years ago, I developed mostly on Eclipse and eventually broke down and purchased a license for the Eclipse vi keybinding plugin.  Now that I&#8217;m employed for Ruby work I&#8217;ve switched back to Vim full-time (after a 1/2 hour dabbling with Textmate).</p>
<p>Jim&#8217;s EMACS setup made me jealous.  During the class I figured out how to set the make program to use ruby (or spec for rspec tests) and <a href="http://www.vim.org/htmldoc/quickfix.html">Quickfix</a> will run the tests for the file.  Here&#8217;s the command:</p>
<blockquote><p>:set makeprg=ruby\ %</p></blockquote>
<p>The <strong>\</strong> escapes the space and the <strong>%</strong> gets expanded to the current buffer&#8217;s filename when Quickfix is activated.  Quickfix was originally used for a &#8220;quick&#8221; way of compiling your program to see if there&#8217;s any errors.  Vim will even move your cursor to the file and line number of the first error if there are any.  This works for ruby tests too!  Another Vim setting, <strong>errorformat</strong>, is how Vim parses errors from running <strong>makeprg</strong>.</p>
<p>OK, so this is all great, but what if my test file is huge?  What if it takes 10+ seconds to run?  What if I&#8217;m only interested in a single test because I&#8217;m being a good developer and practicing TDD?</p>
<p>This is where the <a href="http://github.com/dmcinnes/ruby_single_test/tree/master">Ruby Single Test plugin</a> comes in.  The plugin is an extraction of some functions I&#8217;ve been playing with in my .vimrc file for the past couple of weeks.  All it does is provide a command for running the test block your cursor is hovering over in your test file (<strong>&lt;leader&gt;.</strong> by default.  <strong>&lt;leader&gt;</strong> is usually comma or backslash).  Most of the time you&#8217;re only interested in a single test while you&#8217;re editing code so turn-around time is vastly improved.  No more jumping back to the console to run a test.</p>
<p>To install just drop the <a href="http://github.com/dmcinnes/ruby_single_test/tree/master">ruby_single_test.vim</a> file in your <strong>.vim/plugin</strong> directory.</p>
<p>Currently it works for Test::Unit as well as Rspec tests.  I&#8217;ve been using this quite a bit recently and I think I&#8217;ve worked out most of the bugs.  My setup isn&#8217;t necessarily the same any everyone&#8217;s so please let me know if you have any problems with it!  The code is up on <a href="http://github.com">Github</a>, so feel free to play with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2009/02/16/ruby-single-test/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Javascript Love</title>
		<link>http://dougmcinnes.com/2008/11/13/javascript-love/</link>
		<comments>http://dougmcinnes.com/2008/11/13/javascript-love/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 07:17:55 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Los Angeles Times]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[InplaceEditor]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[preview]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[scriptaculous]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=23</guid>
		<description><![CDATA[I&#8217;ve been a busy bee releasing stuff into the wild lately. Most of them have been Ruby on Rails plugins but I&#8217;ve also been doing some Javascript work. Here&#8217;s two tidbits that I developed at the Los Angeles Times. Inplace_preview &#8230; <a href="http://dougmcinnes.com/2008/11/13/javascript-love/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><script src="/wp-content/uploads/2008/11/prototype.js"></script> <script src="/wp-content/uploads/2008/11/effects.js"></script><br />
<script src="/wp-content/uploads/2008/11/controls.js"></script> <script src="/wp-content/uploads/2008/11/inplace_preview.js"></script><br />
<script src="/wp-content/uploads/2008/11/gallery_scroller.js"></script> I&#8217;ve been a busy bee releasing stuff into the wild lately.  Most of them have been Ruby on Rails plugins but I&#8217;ve also been doing some Javascript work.  Here&#8217;s two tidbits that I developed at the <a href="http://www.latimes.com/">Los Angeles Times</a>.</p>
<h4>Inplace_preview</h4>
<p><a href="http://github.com/latimes/inplace_preview/tree/master">Inplace_preview</a> is the first.  It monkeypatches <a href="http://script.aculo.us/">Scriptaculous</a>&#8216; <a href="http://github.com/madrobby/scriptaculous/wikis/ajax-inplaceeditor">InPlaceEditor</a> to give it a preview mode.  It also includes an ability to do an ajax call for rendering the preview.  It comes in handy when using an InPlaceEditor for editing HTML but with the ajax rendering anything would be possible.  </p>
<p>Here&#8217;s an example (if you save you&#8217;ll get a big-ol error since we don&#8217;t actually save here):</p>
<p><span id="preview-test" style="margin-left:15px;" title="Click to edit"><strong>Click Here to Edit&#8230;</strong></span> <script type="text/javascript"><!--
new Ajax.InPlaceEditor('preview-test', '/update', { rows: 15, previewLink: true, cols: 35, okText: 'Save', cancelText: ' Cancel'} )
// --></script></p>
<h4>Gallery_scroller</h4>
<p><a href="http://github.com/latimes/gallery_scroller/tree/master">Gallery_scroller</a> is small Javascript library for creating a scrolling gallery that we&#8217;re using on more projects then I expected.  It requires <a href="http://www.prototypejs.org/">Prototype</a> and <a href="http://script.aculo.us/">Scriptaculous</a> <a href="http://github.com/madrobby/scriptaculous/wikis/effects">effects.js</a> libraries.</p>
<p>Here&#8217;s an example:</p>
<div id="gst">
<style>
#gst div.gallery { height: 150px; padding-right:16px; text-align:left; float:left; margin-right:10px; }
#gst div.gallery img, li.highlight img { border:2px solid #d0d0c4; }
#gst div.gallery div { width: 140px; }
#gst #gallery_container { position:relative; padding:10px; height:150px; width:540px; }
#gst a.gallery_textlink { font-weight:bold; font-size:110%; }
#gst #gallery_mask { position:relative; height:180px; width:540px; overflow:hidden; clear:left; border:2px black solid; margin-top:10px;}
#gst #gallery_buttons { width:39px; margin-top:2ex; }
#gst #gallery_previous { width: 19px; height: 19px; float:left; background:url(/wp-content/uploads/2008/11/arrow-left-disabled.gif); border-right: 1px #ddd solid; }
#gst #gallery_next { width: 19px; height: 19px; float:right; background:url(/wp-content/uploads/2008/11/arrow-right-disabled.gif); }
#gst #gallery_previous.active { cursor:pointer; background:url(/wp-content/uploads/2008/11/arrow-left.gif); }
#gst #gallery_next.active { cursor:pointer; background:url(/wp-content/uploads/2008/11/arrow-right.gif); }
</style>
<div id="gallery_buttons">
  <span id="gallery_previous"></span><br />
  <span id="gallery_next"></span>
</div>
<div id="gallery_mask">
<div id="gallery_container">
<div id="gallery_2178" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=3041243&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/1037874128.jpg" alt="10-18 (AP) Democratic presidential nominee Sen. Barack Obama says his Republican opponent Sen. John McCain will give tax breaks to the wealthy, a group he says already make out like 'bandits,' some literally on Wall Street." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=3041243&amp;topVideoCatNo=71782">Barack Obama says John McCain will&#8230;</a></div>
</div>
<div id="gallery_2183" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=3042708&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/114494528.jpg" alt="10-19 (AP) Speaking in Fayetteville, North Carolina Sunday, Democratic presidential candidate Barack Obama said he was honored to hear the news that former Secretary of State Colin Powell was endorsing him for president." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=3042708&amp;topVideoCatNo=71782">Barack Obama praises Colin Powell</a></div>
</div>
<div id="gallery_1868" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2854101&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/138133817.jpg" alt="2854101_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2854101&amp;topVideoCatNo=71782">Barack Obama accepts the&#8230;</a></div>
</div>
<div id="gallery_1546" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2649745&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/199373581.jpg" alt="7-2 (CNN) Barack Obama is trying to prove that faith-based politics isn't reserved for Republicans. In fact, the Democrat now is taking a page from President Bush's playbook. Jessica Yellin has more on Obama's version of the president's faith-based initiative." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2649745&amp;topVideoCatNo=71782">Barack Obama&#8217;s faith-based&#8230;</a></div>
</div>
<div id="gallery_1817" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2837083&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/219916731.jpg" alt="8-25 (AP) Democratic presidential candidate Barack Obama was campaigning in Wisconsin Sunday, one day after announcing Delaware Senator Joseph Biden as his running-mate." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2837083&amp;topVideoCatNo=71782">Barack Obama campaigns in Wisconsin</a></div>
</div>
<div id="gallery_1321" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2560121&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/315428173.jpg" alt="6-5 (CNN) If you look at where the poll numbers were just last fall, Barack Obama's success is nothing short of amazing. So how did he beat the Clintons' formidable political machine? Brian Todd has the answer. " height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2560121&amp;topVideoCatNo=71782">What went right for Barack Obama</a></div>
</div>
<div id="gallery_1578" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2681117&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/404079547.jpg" alt="7-11 (CNN) Senator Barack Obama did something that critics say puts him closer to President Bush. It involves Obama's vote on legislation meant to help protect Americans, but that some people say puts Americans' telephone and e-mail privacy at risk. Now, some liberals are not happy with Obama. Ed Henry has details." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2681117&amp;topVideoCatNo=71782">Barack Obama criticized for&#8230;</a></div>
</div>
<div id="gallery_1845" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2849055&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/412984206.jpg" alt="2849055_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2849055&amp;topVideoCatNo=71782">Barack Obama officially becomes&#8230;</a></div>
</div>
<div id="gallery_1849" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2850109&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/436474808.jpg" alt="2850109_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2850109&amp;topVideoCatNo=71782">Barack Obama joins Joe Biden at&#8230;</a></div>
</div>
<div id="gallery_1850" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2848786&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/551163595.jpg" alt="8-27 (DNC) Barack Obama's name will appear on ballots across the nation in November. Delegates attending the Democratic National Convention in Denver have nominated Obama for president, the first black American to bare the presidential nomination of a major party." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2848786&amp;topVideoCatNo=71782">Democrats nominate Barack Obama</a></div>
</div>
<div id="gallery_1596" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2693319&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/621738199.jpg" alt="7-15 (CNN) Barack Obama tells the NAACP African Americans must take more responsibility for their own lives. Sabrina Fang has more from the White House." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2693319&amp;topVideoCatNo=71782">Barack Obama addresses the NAACP</a></div>
</div>
<div id="gallery_1597" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2692745&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/696565248.jpg" alt="7-15 (CNN) Senator Barack Obama continues his message of personal responsibility. The Democratic presidential candidate addressed the NAACP in Cincinnati." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2692745&amp;topVideoCatNo=71782">Barack Obama on personal&#8230;</a></div>
</div>
<div id="gallery_1860" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2852390&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/731932852.jpg" alt="2852390_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2852390&amp;topVideoCatNo=71782">Preparations underway for Barack&#8230;</a></div>
</div>
<div id="gallery_1871" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2854549&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/865386836.jpg" alt="2854549_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2854549&amp;topVideoCatNo=71782">Barack Obama promises tax cut if&#8230;</a></div>
</div>
<div id="gallery_1873" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2854526&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/107196.jpg" alt="2854526_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2854526&amp;topVideoCatNo=71782">Barack Obama accepts Democratic&#8230;</a></div>
</div>
<div id="gallery_1886" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2863331&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/34994920-31172605.jpg" alt="2863331_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2863331&amp;topVideoCatNo=71782">Barack Obama condemns rumors&#8230;</a></div>
</div>
<div id="gallery_1887" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2863387&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/35059740-31144425.jpg" alt="2863387_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2863387&amp;topVideoCatNo=71782">Barack Obama and John McCain urge&#8230;</a></div>
</div>
<div id="gallery_1680" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2742638&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/35256668-05135124.jpg" alt="7-29 (CNN) Breaking up is hard to do, especially if it's a presidential candidate you're breaking up with. They love him, they love him not. We're talking about the media and Barack Obama. Jeanne Moos reports that those in the press who follow him most closely aren't feeling all that close these days." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2742638&amp;topVideoCatNo=71782">Barack Obama&#8217;s relationship with&#8230;</a></div>
</div>
<div id="gallery_1175" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2477916&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/384707563.jpg" alt="2477916_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2477916&amp;topVideoCatNo=71782">Barack Obama</a></div>
</div>
<div id="gallery_1451" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/news/politics/la-ca-0622-presidents-pg,0,3704732.photogallery?track=rss"><img src="/wp-content/uploads/2008/11/40099116-17162042.jpg" alt="Barack Obama Photos" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/news/politics/la-ca-0622-presidents-pg,0,3704732.photogallery?track=rss">Before Barack Obama: Alternative&#8230;</a></div>
</div>
<div id="gallery_1470" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2615428&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/45171987.jpg" alt="2615428_vk" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2615428&amp;topVideoCatNo=71782">Barack Obama&#8217;s funding advantage&#8230;</a></div>
</div>
<div id="gallery_1486" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2621995&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/460582403.jpg" alt="6-24 (CNN) One of Senator Barack Obama's latest P.R. moves involves a look-alike presidential seal that definitely didn't get the official seal of approval. Jeanne Moos takes a look." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2621995&amp;topVideoCatNo=71782">Barack Obama&#8217;s seal controversy</a></div>
</div>
<div id="gallery_1487" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2621983&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/507846466.jpg" alt="6-24 (CNN) Once enemies, they're now joining forces. Democrats Barack Obama and Hillary Clinton are preparing for a rally in the aptly named Unity, New Hampshire. Candy Crowley has more." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2621983&amp;topVideoCatNo=71782">Barack Obama and Hillary Clinton&#8230;</a></div>
</div>
<div id="gallery_1490" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2622008&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/580571534.jpg" alt="6-24 (CNN) One of Senator Barack Obama's latest public relations moves involves a look-alike presidential seal that definitely didn't get the official seal of approval. Jeanne Moos takes a look." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2622008&amp;topVideoCatNo=71782">Barack Obama and Muslim voters</a></div>
</div>
<div id="gallery_1495" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2626176&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/795300114.jpg" alt="6/25 (CNN) Friday, two former primary rivals will come together for one cause, putting Senator Obama in the White House. Hillary Clinton and Barack Obama make their first joint campaign appearance Friday in Unity, New Hampshire. Today, Obama praised Senator Clinton and talked about what their hard-fought primary did to her political status." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2626176&amp;topVideoCatNo=71782">Barack Obama on Hillary Clinton</a></div>
</div>
<div id="gallery_1514" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/video/?clipId=2634673&amp;topVideoCatNo=71782"><img src="/wp-content/uploads/2008/11/861529769.jpg" alt="6-27 (CNN) Barack Obama says contrary to what some comedians are saying, he and actress Scarlett Johansson hardly know each other -- which makes their so-called &quot;break up&quot; most unusual. Jeanne Moos reports." height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/video/?clipId=2634673&amp;topVideoCatNo=71782">Barack Obama and Scarlett Johansson</a></div>
</div>
<div id="gallery_515" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/entertainment/news/la-et-popcandidates-pg,1,3609591.photogallery?track=rss"><img src="/wp-content/uploads/2008/11/867966830.jpg" alt="Barack Obama Photos" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/entertainment/news/la-et-popcandidates-pg,1,3609591.photogallery?track=rss">Pop culture candidates</a></div>
</div>
<div id="gallery_519" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/la-na-demdebate-pg,0,9946.photogallery?track=rss"><img src="/wp-content/uploads/2008/11/899943488.jpg" alt="Barack Obama Photos" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/la-na-demdebate-pg,0,9946.photogallery?track=rss">Democratic debate</a></div>
</div>
<div id="gallery_534" class="gallery_scroll_unit gallery"><a href="http://www.latimes.com/la-super_tuesday08_nation-pg,0,4952159.photogallery?track=rss"><img src="/wp-content/uploads/2008/11/906115334.jpg" alt="Barack Obama Photos" height="110" /></a> </p>
<div><a class="gallery_textlink" href="http://www.latimes.com/la-super_tuesday08_nation-pg,0,4952159.photogallery?track=rss">Super Tuesday: Nation</a></div>
</div>
</div>
</div>
<p><script type="text/javascript"><!--
  //<![CDATA[
new GalleryScroller('gallery_container', 'gallery_previous', 'gallery_next')
// --></script></div>
<p>The documentation on both of these goes into detail on how they work, so check out their <a href="http://github.com/latimes/inplace_preview/tree/master">github</a> <a href="http://github.com/latimes/gallery_scroller/tree/master">sites</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2008/11/13/javascript-love/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Couple of Railsy Tidbits</title>
		<link>http://dougmcinnes.com/2008/11/10/couple-of-railsy-tidbits/</link>
		<comments>http://dougmcinnes.com/2008/11/10/couple-of-railsy-tidbits/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 19:30:43 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Los Angeles Times]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[HTTP Auth]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[subselection]]></category>
		<category><![CDATA[YAML]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=19</guid>
		<description><![CDATA[I made a post on the Gem Install That blog detailing the simple_admin plugin which adds a simple authentication scheme to your Ruby on Rails application.  It stores usernames and passwords in a YAML file to make it extra easy. &#8230; <a href="http://dougmcinnes.com/2008/11/10/couple-of-railsy-tidbits/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I made a post on the <a href="http://geminstallthat.wordpress.com/">Gem Install That</a> blog detailing the <a href="http://geminstallthat.wordpress.com/2008/11/07/simple_admin-met-a-pieman/">simple_admin plugin</a> which adds a simple authentication scheme to your Ruby on Rails application.  It stores usernames and passwords in a <a href="http://www.yaml.org/">YAML</a> file to make it extra easy.</p>
<p><a href="http://geminstallthat.wordpress.com/author/reidmix/">Reid</a> also posted on Gem Install That about another plugin we worked on, <a href="http://geminstallthat.wordpress.com/2008/11/01/subselector-moneypenny/">Subselector</a>, which extends ActiveRecord to give it subselection capibilities.</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2008/11/10/couple-of-railsy-tidbits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cached_resource</title>
		<link>http://dougmcinnes.com/2008/10/30/cached_resource/</link>
		<comments>http://dougmcinnes.com/2008/10/30/cached_resource/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 21:13:06 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Los Angeles Times]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=16</guid>
		<description><![CDATA[Another Ruby on Rails plugin that I&#8217;ve developed at the Los Angeles Times is cached_resource. In a nutshell cached_resource automagically caches ActiveResource response objects in a memcached instance.  The plugin requires cache_fu for memcached configuration goodness.  See also: Kickin&#8217; ass &#8230; <a href="http://dougmcinnes.com/2008/10/30/cached_resource/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Another Ruby on Rails plugin that I&#8217;ve developed at the <a href="http://latimes.com/">Los Angeles Times</a> is <a href="http://github.com/latimes/cached_resource/tree/master">cached_resource</a>.</p>
<p>In a nutshell cached_resource automagically caches <a href="http://api.rubyonrails.org/classes/ActiveResource/Base.html">ActiveResource</a> response objects in a <a href="http://www.danga.com/memcached/">memcached</a> instance.  The plugin requires <a href="http://github.com/defunkt/cache_fu/tree/master">cache_fu</a> for memcached configuration goodness.  See also: <a href="http://errtheblog.com/posts/57-kickin-ass-w-cachefu">Kickin&#8217; ass with cache-fu</a>.</p>
<p>The code for cached_resource is also up on <a href="http://github.com/">GitHub</a> along with a many other Los Angeles Times plugins and other tidbits.  You can find it here: <a href="http://github.com/latimes/cached_resource/tree/master">http://github.com/latimes/cached_resource/tree/master</a></p>
<p>So, how do you get it to work?  After dropping the plugins in <strong>vendor/plugins</strong>, set up your cache_fu configuration then drop this single line in any of your ActiveResource models:</p>
<pre>class MyClass &lt; ActiveResource::Base
  <strong>cached_resource</strong>
end</pre>
<p>The cached_resource call also takes normal cache_fu options:</p>
<pre>class MyClass &lt; ActiveResource::Base
  <strong>cached_resource :ttl =&gt; 15.minutes</strong>
end</pre>
<p>So now every time you run a <strong>.find()</strong> on <strong>MyClass</strong> the results will be cached for the next time you do the same kind of find.  The cache key is the URI of the ActiveRecord generated REST query.</p>
<p>In addition, if you do <strong>MyClass.find(:all)</strong> or the like to get a list of resources, individual instances in the returned list will be cached separately and the list itself will be distilled down to IDs before it&#8217;s stuffed in its own cache bucket.  When pulled from the cache the list will be reconstituted by pulling the individual objects from the cache by ID or making additional ActiveResource queries to get objects that have fallen out for one reason or another. The upshot of this is you&#8217;ll have less of a chance of stale data between mixed finds.</p>
<p>The cached_resource plugin makes some assumptions about how your REST service is set up.  If the REST service you&#8217;re pointing to with ActiveResource are wacky, i.e. not conforming to exactly what ActiveResource expects its URLs to be, this plugin will probably not work for you.  That said, if you can do normal finds with IDs, like <strong>MyClass.find(123)</strong>, you&#8217;ll probably be fine.</p>
<p>This plugin was written before <a href="http://thewebfellas.com/blog/2008/6/9/rails-2-1-now-with-better-integrated-caching">memcached support was baked into Rails 2.1</a> so if anyone wants to fork and get it working please be my guest!  I&#8217;ll be happy to pull it back in <img src='http://dougmcinnes.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Credit where credit is due: <a href="http://kleinptr.wordpress.com/">Josh Kleinpeter</a> originally came up with the cached_resource concept and Subba Rao helped to lay the groundwork.</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2008/10/30/cached_resource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Craken</title>
		<link>http://dougmcinnes.com/2008/07/14/craken/</link>
		<comments>http://dougmcinnes.com/2008/07/14/craken/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 18:53:09 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Los Angeles Times]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[craken]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://dougmcinnes.com/?p=14</guid>
		<description><![CDATA[This is the first of hopefully many (a few?) Ruby on Rails plugins I&#8217;ve created as a developer for the Los Angeles Times. This one is called Craken.  In a nutshell it manages and installs rake-centric cron jobs.  Coupled with &#8230; <a href="http://dougmcinnes.com/2008/07/14/craken/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is the first of hopefully many (a few?) Ruby on Rails plugins I&#8217;ve created as a developer for the <a href="http://latimes.com">Los Angeles Times</a>.</p>
<p>This one is called Craken.  In a nutshell it manages and installs <a title="Simple ruby build program with capabilities similar to make. " href="http://rake.rubyforge.org/">rake</a>-centric <a title="Time-based scheduling service in Unix-like computer operating systems." href="http://en.wikipedia.org/wiki/Cron">cron</a> jobs.  Coupled with <a title="Tool for automating tasks on one or more remote servers." href="http://www.capify.org/">Capistrano</a> goodness it is the answer to your recurring task needs in Rails.</p>
<p>It&#8217;s up on <a title="new hotness" href="http://github.com/">GitHub</a>: <a href="http://github.com/latimes/craken/tree/master">http://github.com/latimes/craken/tree/master</a></p>
<p>Here&#8217;s the deal: with many web applications comes the need to do recurring tasks on the servers the application runs on.  These sorts of tasks can range from running backups, clearing caches, emailing notices and other such maintenance-y things.</p>
<p>Who manages these tasks?  Ideally the task code as well as configuration and timing should be kept with the source code of the application itself and not as part of some further set of scripts that reside in a dubious location in your source control.  This is what Craken does.</p>
<p>The tasks are defined as rake tasks within the application.  Craken itself is a rake task that sets up a crontab for defined tasks based on your current application configuration.  The plugin also includes a Capistrano recipe that runs the Craken rake task on remote servers making deployment a breeze.</p>
<p>Craken, by default, looks for recurring task definitions here:</p>
<pre>RAILS_ROOT/config/craken/crontab</pre>
<p>You can also define tasks for a particular machine by prefixing the machine name (separated with an underscore):</p>
<pre>RAILS_ROOT/config/craken/MyMachineName_crontab</pre>
<p>The file format is modeled after crontab:</p>
<pre>30 1 * * * thing:to_do</pre>
<p>In this case <em>thing:to_do</em> is a rake task.  It will run at 1:30 AM every morning (take a look at the <a href="http://unixnotes.wordpress.com/2006/04/14/cron-format-crontab/">crontab format</a> if this makes no sense).</p>
<p>The command to install the cron job locally:</p>
<pre>% rake craken:install</pre>
<p>If you&#8217;re using Capistrano for deployment (and you really should) a recipe is provided to run <em>craken:install</em> on remote machines.  Your Capistrano configuration needs to define a <strong>:cron</strong> role so the recipe knows which machines it should run the command on.</p>
<pre>% cap craken:install</pre>
<p>Ideally you can make craken:install part of your deployment configuration, <strong>:after_deploy</strong> would be a good place to put it.  Craken overwrites the existing configuration for the application on the machine so running it multiple times is not a problem.  Running multiple apps on the same machine or cron jobs placed by hand?  No worries, Craken delimits the lines it generates in crontab with comments and doesn&#8217;t disturb existing entries.</p>
<p>For more information about the plugin, peruse the <a href="http://github.com/latimes/craken/tree/master/README">README</a> file.</p>
<p>If you have any questions/comments/suggestions about Craken please leave a comment!</p>
<p>The name &#8220;Craken&#8221; generously suggested by <a href="http://gilesbowkett.blogspot.com/">Giles Bowkett</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dougmcinnes.com/2008/07/14/craken/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

