<?xml version="1.0" encoding="UTF-8"?>
<rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>pastbedti.me</title>
	
	<link>http://www.pastbedti.me</link>
	<description>About ruby, rails, postgresql and stuff....</description>
	<lastBuildDate>Wed, 13 Jan 2010 21:54:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/pastbedtime" /><feedburner:info uri="pastbedtime" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>It’s all about the bits and pieces</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/nDrtB-GJEOs/</link>
		<comments>http://www.pastbedti.me/2010/01/its-all-about-the-bits-and-pieces/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 01:41:50 +0000</pubDate>
		<dc:creator>Patrik Hedman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[lego]]></category>
		<category><![CDATA[lego-core]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=647</guid>
		<description><![CDATA[Introducing Lego
For a while now Mathias and I have been hacking away on our very own web framework called Lego.
But why? I hear you cry, why yet another one, what&#8217;s wrong with Rails, Merb, Ramaze, Sinatra, Camping, Rango, Waves, Mack, and so on and so on.
Well, they&#8217;re all great but we believe they aren&#8217;t dumb [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introducing Lego</strong></p>
<p>For a while now <a href="http://www.pastbedti.me/author/admin/">Mathias</a> and <a href="http://www.pastbedti.me/author/polly/">I</a> have been hacking away on our very own web framework called <a href="http://github.com/stjernstrom/lego-core/">Lego</a>.<br />
But why? I hear you cry, why yet another one, what&#8217;s wrong with Rails, Merb, Ramaze, Sinatra, Camping, Rango, Waves, Mack, and so on and so on.<br />
Well, they&#8217;re all great but we believe they aren&#8217;t dumb enough!<br />
Lego however is about as dumb as it gets, all it knows is how to handle the request/response cycle and leaves the rest up to plugins.<br />
The downside of this approach is that it takes a little bit more work to get it up and running the upside is that you get exactly what you want, nothing more, nothing less.</p>
<p><strong>I&#8217;m intrigued, tell me more</strong></p>
<p>So at it&#8217;s core there&#8217;s lego-core which contains only the bare essentials, a way to set up a controller that rack can run, and a way to extend the various parts of lego.</p>
<p>Future plans include a lego-more gem already setup with commonly used plugins so you easily can get up and running quickly and a central repository of available lego plugins.</p>
<p><strong>A simple application</strong></p>
<p>Provided that you have lego-core installed (gem install lego-core) put the following in a config.ru file:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'lego-core'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> MyApp <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Lego::Controller</span>; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
run MyApp</div></td></tr></tbody></table></div>
<p>Run it with rackup and point your browser to <a href="http://localhost:9292/">http://localhost:9292/</a> and you should be met by a plain old &#8216;404 &#8211; Not found&#8217;, not terribly exiting right? But that&#8217;s pretty much all lego-core gives you <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p><strong>So what about those plugins?</strong></p>
<p>The lego extension system allows you to hook into various parts of the execution chain, namely:</p>
<p>View &#8211; For action and view related stuff<br />
Controller &#8211; For defining controller dsl&#8217;s<br />
Router &#8211; Rules for how lego should match routes, must have a self.match_route method which takes a route and an env parameter and return either a two element array containing the env and a hash of match data (or an empty hash if no match data is available) or false</p>
<p>At it&#8217;s core, a plugin is a module that responds to register who&#8217;s responsibility is to register with lego, following is a simple plugin example:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">module</span> SamplePlugin<br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># Register is called by lego when plugin is loaded</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span>lego<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; lego.<span style="color:#9900CC;">add_plugin</span> <span style="color:#ff3333; font-weight:bold;">:view</span>, View<br />
&nbsp; &nbsp; lego.<span style="color:#9900CC;">add_plugin</span> <span style="color:#ff3333; font-weight:bold;">:router</span>, Matcher<br />
&nbsp; &nbsp; lego.<span style="color:#9900CC;">add_plugin</span> <span style="color:#ff3333; font-weight:bold;">:controller</span>, Routes<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># A plugin module we load as a view helper</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> View<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> h1<span style="color:#006600; font-weight:bold;">&#40;</span>content<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;&lt;h1&gt;#{content}&lt;/h1&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># A very simply route helper</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Routes<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> get<span style="color:#006600; font-weight:bold;">&#40;</span>path, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; add_route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:get</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> path, <span style="color:#ff3333; font-weight:bold;">:action_block</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> block<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># A very simple route matcher</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Matcher<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">match_route</span><span style="color:#006600; font-weight:bold;">&#40;</span>route, env<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>route<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:path</span><span style="color:#006600; font-weight:bold;">&#93;</span> == env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'PATH_INFO'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#006600; font-weight:bold;">&#91;</span>env, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span> : <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><strong>It&#8217;s about time for a real example!</strong></p>
<p>As we showed you earlier, lego-core gives you a way to set up an application but it don&#8217;t know how to map routes to action so let&#8217;s expand on the previous application with our newly gained knowledge of lego&#8217;s extension system:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'lego-core'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">module</span> Routes<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">register</span><span style="color:#006600; font-weight:bold;">&#40;</span>lego<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; lego.<span style="color:#9900CC;">add_plugin</span> <span style="color:#ff3333; font-weight:bold;">:controller</span>, SinatraController<br />
&nbsp; &nbsp; lego.<span style="color:#9900CC;">add_plugin</span> <span style="color:#ff3333; font-weight:bold;">:router</span>, &nbsp; &nbsp; SimpleRouter<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># implements a basic Sinatra inspiered dsl</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> SinatraController<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> get<span style="color:#006600; font-weight:bold;">&#40;</span>path, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; add_route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:get</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> path, <span style="color:#ff3333; font-weight:bold;">:action_block</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> block<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># Implements a very basic mather rule</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> SimpleRouter<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">match_route</span><span style="color:#006600; font-weight:bold;">&#40;</span>route, env<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>route<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:path</span><span style="color:#006600; font-weight:bold;">&#93;</span> == env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'PATH_INFO'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#0000FF; font-weight:bold;">true</span> : <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;"># define an application</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> MyApp <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Lego::Controller</span><br />
&nbsp; plugin Routes<br />
&nbsp; <br />
&nbsp; get <span style="color:#996600;">&quot;/&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#996600;">&quot;Hello from /&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
run MyApp</div></td></tr></tbody></table></div>
<p>As before, run it with rackup and point your browser to <a href="http://localhost:9292/">http://localhost:9292/</a> and this time you should be greeted by &#8220;Hello from /&#8221;.</p>
<p><strong>Don&#8217;t repeat yourself</strong></p>
<p>If you have a plugin you want to use in every application, then consider defining it globally:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; Lego.<span style="color:#9900CC;">plugin</span> MyPlugin<br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># or group multiple plugin calls in a config block</span><br />
<br />
&nbsp; Lego.<span style="color:#9900CC;">config</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; plugin MyViewPlugin<br />
&nbsp; &nbsp; plugin MyControllerPlugin<br />
&nbsp; &nbsp; plugin MyRouteMatcherPlugin<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><strong>Configuration options</strong></p>
<p>Lego also comes with a very simple configuration handler, it basically provides two methods, set and options, lets look at them in action:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> MyApp <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Lego::Controller</span><br />
&nbsp; plugin Routes<br />
<br />
&nbsp; set <span style="color:#ff3333; font-weight:bold;">:foo</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;bar&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:baz</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;quux&quot;</span><br />
<br />
&nbsp; get<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/foo&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> options <span style="color:#ff3333; font-weight:bold;">:foo</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <br />
&nbsp; get<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/bar&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> options <span style="color:#ff3333; font-weight:bold;">:bar</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>As with plugins you can use set globally:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; Lego.<span style="color:#9900CC;">set</span> <span style="color:#ff3333; font-weight:bold;">:foo</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;bar&quot;</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># or group multiple set calls in a config block</span><br />
<br />
&nbsp; Lego.<span style="color:#9900CC;">config</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; set <span style="color:#ff3333; font-weight:bold;">:foo</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;bar&quot;</span><br />
&nbsp; &nbsp; set <span style="color:#ff3333; font-weight:bold;">:baz</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;quux&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><strong>Wrapping up</strong></p>
<p>In conclusion Lego is a &#8216;Use what you want&#8217; framework that tries to stay out of your way as much as possible and thank&#8217;s to it’s modular design, you are free to use your favourite technologies and tools.</p>
<p><strong style="color: red;">Please note that it&#8217;s still in a highly experimental stage!</strong></p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/nDrtB-GJEOs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2010/01/its-all-about-the-bits-and-pieces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2010/01/its-all-about-the-bits-and-pieces/</feedburner:origLink></item>
		<item>
		<title>Deploying a Sinatra app with Apache and Phusion Passenger a.k.a. mod_rack</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/4s_5yQldT-E/</link>
		<comments>http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-a-k-a-mod_rack/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 22:01:30 +0000</pubDate>
		<dc:creator>Mathias Stjernström</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sinatra]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[webroot]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=610</guid>
		<description><![CDATA[My Sinatra + Apache + Passenger setup did not just run  
Deploying a simple Sinatra rack application under Apache and Phusion Passenger turned out not work out of the box for me. 
I already had a virtual host so I decided to deploy with passengers sub URI (sub URI documentation).
To make this work you&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<h3>My Sinatra + Apache + Passenger setup did not just run <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </h3>
<p>Deploying a simple Sinatra rack application under Apache and Phusion Passenger turned out not work out of the box for me. </p>
<p>I already had a virtual host so I decided to deploy with passengers sub URI (<a href="http://www.modrails.com/documentation/Users%20guide.html#deploying_rack_to_sub_uri" target="_blank">sub URI documentation</a>).</p>
<p>To make this work you&#8217;ll need Apache installed with Phusion Passenger setup (<a href="http://www.modrails.com/install.html" target="_blank">Passenger installation</a>)</p>
<p>
<h3>This is what I started with</h3>
<p>This is my folders for the already existing website.</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># Existing homedir</span><br />
<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>my_web<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #666666; font-style: italic;"># Current webroot</span><br />
<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>my_web<span style="color: #000000; font-weight: bold;">/</span>htdocs</div></td></tr></tbody></table></div>
<p>
<h3>Creating folders and files for Sinatra</h3>
<p>The first thing you want to do is to create folders and files for Sinatra.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mkdir /home/my_web/sinatra</div></td></tr></tbody></table></div>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cd /home/my_web/sinatra<br />
mkdir tmp<br />
mkdir logs<br />
mkdir public<br />
touch app.rb<br />
touch config.ru</div></td></tr></tbody></table></div>
<p>
<h3>Create symlink</h3>
<p>Create a symbolic link from our current webroot to the new Sinatra app so that apache/passenger can find it.</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>my_web<span style="color: #000000; font-weight: bold;">/</span>sinatra<span style="color: #000000; font-weight: bold;">/</span>public <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>my_web<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>app</div></td></tr></tbody></table></div>
<p>
<h3>Creating the application</h3>
<p>We also need a Sinatra application for this to work so lets fill those files.</p>
<p>
<h4>File: config.ru</h4>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'app'</span><br />
<br />
set <span style="color:#ff3333; font-weight:bold;">:environment</span>, ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'RACK_ENV'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_sym</span><br />
set <span style="color:#ff3333; font-weight:bold;">:app_file</span>, &nbsp; &nbsp; <span style="color:#996600;">'app.rb'</span><br />
disable <span style="color:#ff3333; font-weight:bold;">:run</span><br />
<br />
log = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;logs/sinatra.log&quot;</span>, <span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
STDOUT.<span style="color:#9900CC;">reopen</span><span style="color:#006600; font-weight:bold;">&#40;</span>log<span style="color:#006600; font-weight:bold;">&#41;</span><br />
STDERR.<span style="color:#9900CC;">reopen</span><span style="color:#006600; font-weight:bold;">&#40;</span>log<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
run <span style="color:#6666ff; font-weight:bold;">Sinatra::Application</span></div></td></tr></tbody></table></div>
<p>
<h4>File: app.rb</h4>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sinatra'</span><br />
<br />
before <span style="color:#9966CC; font-weight:bold;">do</span> <br />
&nbsp; <span style="color:#008000; font-style:italic;"># Strip the last / from the path</span><br />
&nbsp; request.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'PATH_INFO'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">gsub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">/</span>$<span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
get <span style="color:#996600;">''</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp;<span style="color:#996600;">&quot;Hello world&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>
<h3>Apache configuration</h3>
<p>Now we need to setup apache so that it can find our Sinatra app and load it.</p>
<p>The only thing you need to do is add the following line to your existing VirtualHost block:</p>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RackBaseURI /app</div></td></tr></tbody></table></div>
<p>This line will tell passenger to look into our existing webroot for a symlink thats named app and which points to our rack app.  (<a href="http://www.modrails.com/documentation/Users%20guide.html#RackBaseURI" target="_blank">RackBaseURI  documentation</a>)</p>
<p>
<h3>Virtual host entry</h3>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:80&gt;<br />
&nbsp; <span style="color: #00007f;">ServerName</span> www.example.com<br />
&nbsp; <span style="color: #00007f;">ServerAlias</span> example.com<br />
&nbsp; <span style="color: #00007f;">DocumentRoot</span> /home/my_web/htdocs/<br />
&nbsp; RackBaseURI /app<br />
<br />
&nbsp; &lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;/home/my_web/htdocs/&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span><br />
&nbsp; &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</div></td></tr></tbody></table></div>
<p>The best part is that you are allowed to specify this option multiple times. So you can easily setup multiple apps under the same virtual host.</p>
<p>Cheers! </p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/4s_5yQldT-E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-a-k-a-mod_rack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-a-k-a-mod_rack/</feedburner:origLink></item>
		<item>
		<title>Currying in JavaScript</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/14q1nNj8SxI/</link>
		<comments>http://www.pastbedti.me/2009/11/currying-in-javascript/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 21:53:16 +0000</pubDate>
		<dc:creator>Patrik Hedman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[Functional Programming]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=587</guid>
		<description><![CDATA[Whilst being an object-oriented language, JavaScript still takes a lot of ideas from functional languages. One which it dosen&#8217;t implement though, is the idea of currying.
What&#8217;s currying then? You might ask, well, here&#8217;s the definition according to wikipedia:
In mathematics and computer science, currying, invented by Moses Schönfinkel and later re-invented by Haskell Curry,[1] is the [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst being an object-oriented language, JavaScript still takes a lot of ideas from functional languages. One which it dosen&#8217;t implement though, is the idea of currying.<br />
What&#8217;s currying then? You might ask, well, here&#8217;s the definition according to wikipedia:</p>
<blockquote><p>In mathematics and computer science, currying, invented by Moses Schönfinkel and later re-invented by Haskell Curry,[1] is the technique of transforming a function that takes multiple arguments (or more accurately an n-tuple as its argument) in such a way that it can be called as a chain of functions each with a single argument.</p></blockquote>
<p>So basically, it let&#8217;s you fill in some arguments to a function before hand and return a new function which you will subsequently call instead, or default arguments on steroids if you will.<br />
Here&#8217;s a few examples of what we could do if JavaScript was capable of currying:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">// Array to csc</span><br />
Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">arrayToCsv</span> <span style="color: #339933;">=</span> Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">join</span>.<span style="color: #660066;">curry</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;Patrik&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Hedman&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Stockholm&quot;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">arrayToCsv</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//=&gt; &quot;Patrik; Hedman; Stockholm&quot;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">// And back</span><br />
String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">csvToArray</span> <span style="color: #339933;">=</span> String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">split</span>.<span style="color: #660066;">curry</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/;\s*/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Patrik; Hedman; Stockholm&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">csvToArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//=&gt; [&quot;Patrik&quot;, &quot;Hedman&quot;, &quot;Stockholm&quot;]</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">// The undefined parameter will be replaced with the </span><br />
<span style="color: #006600; font-style: italic;">// callback function passed to clicker();</span><br />
<span style="color: #003366; font-weight: bold;">var</span> clicker <span style="color: #339933;">=</span> document.<span style="color: #660066;">body</span>.<span style="color: #660066;">addEventListener</span>.<span style="color: #660066;">curry</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> undefined<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
clicker<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> <br />
&nbsp; &nbsp; console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Curryfied click event.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Pretty sweet, but it wont work since there is no curry() function in JavaScript, not a problem, implementing one is pretty straightforward:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">Function</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">curry</span> <span style="color: #339933;">=</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> <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Save references to this and the arguments so we can</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// acces them from the closure</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> fn &nbsp; <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; args <span style="color: #339933;">=</span> Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">slice</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span> arguments <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> arg <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> args.<span style="color: #660066;">length</span> <span style="color: #339933;">&amp;&amp;</span> arg <span style="color: #339933;">&lt;</span> arguments.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> args<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> undefined <span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// If the original argument is undefined</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// then replace it with the new one</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> arguments<span style="color: #009900;">&#91;</span>arg<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Call the original function with the current this as </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// the context and the newly constructed argument list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> fn.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/14q1nNj8SxI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/11/currying-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/11/currying-in-javascript/</feedburner:origLink></item>
		<item>
		<title>Grouping a timestamp field by date in Ruby On Rails / PostgreSQL</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/cWLhmc25vPM/</link>
		<comments>http://www.pastbedti.me/2009/11/grouping-a-timestamp-field-by-date-in-ruby-on-rails-postgresql/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 00:55:09 +0000</pubDate>
		<dc:creator>Mathias Stjernström</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=563</guid>
		<description><![CDATA[Recently I&#8217;ve been working a lot with dates and tonight I had a hard time finding information about how to group a model by date when the model only have a timestamp column. 
Lets pretend we have a user model with a created_at attribute which is stored as a timestamp.
If we want to plot a [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been working a lot with dates and tonight I had a hard time finding information about how to group a model by date when the model only have a timestamp column. </p>
<p>Lets pretend we have a user model with a created_at attribute which is stored as a timestamp.</p>
<p>If we want to plot a simple graph showing signups per date this is the way to extract them:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">User.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:group</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;DATE(created_at)&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>Thats all there is to it. From this you will get an OrderedHash containing the date and count of users for each date. </p>
<p>One small thing to remember if you are using PostgreSQL. You will need the DATE() function in any ORDER/SELECT statements because PostgreSQL will only select/order by fields thats in the GROUP BY statement and this is a  pretty healthy behavior that many databases (no names here) don&#8217;t care about. Think about it. If you are grouping all users by date and use * as selector how would the database know which username or email address to display?</p>
<p>This is what happens if you try to group by created_at without DATE() -></p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> User.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'created_at DESC'</span>, <span style="color:#ff3333; font-weight:bold;">:group</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;DATE(created_at)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color:#6666ff; font-weight:bold;">ActiveRecord::StatementInvalid</span>: PGError: ERROR: &nbsp;column <span style="color:#996600;">&quot;users.created_at&quot;</span> must appear <span style="color:#9966CC; font-weight:bold;">in</span> the GROUP BY clause <span style="color:#9966CC; font-weight:bold;">or</span> be used <span style="color:#9966CC; font-weight:bold;">in</span> an aggregate function<br />
: <span style="color:#CC0066; font-weight:bold;">SELECT</span> count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span> AS count_all, DATE<span style="color:#006600; font-weight:bold;">&#40;</span>created_at<span style="color:#006600; font-weight:bold;">&#41;</span> AS date_created_at FROM <span style="color:#996600;">&quot;users&quot;</span> &nbsp;GROUP BY DATE<span style="color:#006600; font-weight:bold;">&#40;</span>created_at<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp;ORDER BY created_at DESC <br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color:#006600; font-weight:bold;">/</span>tmp<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>vendor<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>activerecord<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>active_record<span style="color:#006600; font-weight:bold;">/</span>connection_adapters<span style="color:#006600; font-weight:bold;">/</span>abstract_adapter.<span style="color:#9900CC;">rb</span>:212:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">`log'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from /tmp/app/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:507:in `</span>execute<span style="color:#996600;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from /tmp/app/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:985:in `select_raw'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color:#006600; font-weight:bold;">/</span>tmp<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>vendor<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>activerecord<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>active_record<span style="color:#006600; font-weight:bold;">/</span>connection_adapters<span style="color:#006600; font-weight:bold;">/</span>postgresql_adapter.<span style="color:#9900CC;">rb</span>:972:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">`select'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from /tmp/app/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `</span>select_all_without_query_cache<span style="color:#996600;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from /tmp/app/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color:#006600; font-weight:bold;">/</span>tmp<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>vendor<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>activerecord<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>active_record<span style="color:#006600; font-weight:bold;">/</span>calculations.<span style="color:#9900CC;">rb</span>:255:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">`execute_grouped_calculation'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from /tmp/app/vendor/rails/activerecord/lib/active_record/calculations.rb:132:in `</span>calculate<span style="color:#996600;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from /tmp/app/vendor/rails/activerecord/lib/active_record/calculations.rb:130:in `catch'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color:#006600; font-weight:bold;">/</span>tmp<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>vendor<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>activerecord<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>active_record<span style="color:#006600; font-weight:bold;">/</span>calculations.<span style="color:#9900CC;">rb</span>:130:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">`calculate'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from /tmp/app/vendor/rails/activerecord/lib/active_record/calculations.rb:48:in `</span>count<span style="color:#996600;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; from (irb):18</span></div></td></tr></tbody></table></div>
<p>And this is the right way to do it:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> User.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'DATE(created_at) DESC'</span>, <span style="color:#ff3333; font-weight:bold;">:group</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;DATE(created_at)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;OrderedHash {&quot;2009-10-14&quot;=&gt;22, &quot;2009-10-25&quot;=&gt;4, &quot;2009-11-04&quot;=&gt;8, &quot;2009-10-15&quot;=&gt;9, &quot;2009-10-26&quot;=&gt;16, &quot;2009-11-05&quot;=&gt;9, &quot;2009-10-16&quot;=&gt;193, &quot;2009-10-27&quot;=&gt;14, &quot;2009-11-06&quot;=&gt;9, &quot;2009-10-17&quot;=&gt;49, &quot;2009-10-28&quot;=&gt;15, &quot;2009-11-07&quot;=&gt;6, &quot;2009-10-18&quot;=&gt;36, &quot;2009-10-29&quot;=&gt;8, &quot;2009-10-19&quot;=&gt;116, &quot;2009-10-30&quot;=&gt;15&gt;</span></div></td></tr></tbody></table></div>
<p>As you may notice the Hash does not look ordered. But if you loop over it you will get them in order:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> User.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'DATE(created_at) DESC'</span>, <span style="color:#ff3333; font-weight:bold;">:group</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;DATE(created_at)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>u<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{u[0]} -&gt; #{u[1]}&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">11</span><span style="color:#006600; font-weight:bold;">-</span>07 <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">6</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">11</span><span style="color:#006600; font-weight:bold;">-</span>06 <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">9</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">11</span><span style="color:#006600; font-weight:bold;">-</span>05 <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">9</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">11</span><span style="color:#006600; font-weight:bold;">-</span>04 <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">8</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">11</span><span style="color:#006600; font-weight:bold;">-</span>03 <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">14</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">11</span><span style="color:#006600; font-weight:bold;">-</span>02 <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">20</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">11</span><span style="color:#006600; font-weight:bold;">-</span>01 <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">10</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">31</span> <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">6</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">30</span> <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">15</span><br />
<span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">29</span> <span style="color:#006600; font-weight:bold;">-&gt;</span> <span style="color:#006666;">8</span><br />
..</div></td></tr></tbody></table></div>
<p>And thats how you group a timestamp field with just its date part.</p>
<p>Cheers!</p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/cWLhmc25vPM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/11/grouping-a-timestamp-field-by-date-in-ruby-on-rails-postgresql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/11/grouping-a-timestamp-field-by-date-in-ruby-on-rails-postgresql/</feedburner:origLink></item>
		<item>
		<title>JavaScript, a quite capable ruby in an unfortunate disguise</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/TnLY3_pmVf4/</link>
		<comments>http://www.pastbedti.me/2009/10/javascript-a-quite-capable-ruby-in-an-unfortunate-disguise/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 15:00:41 +0000</pubDate>
		<dc:creator>Patrik Hedman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=547</guid>
		<description><![CDATA[So, a few days ago I finally decided to give JavaScript a proper chance and as it turns out; All those people who&#8217;s been blabbering on about how JavaScript actually is a very powerful language where right all along!
You see, just like Ruby, JavaScript is extremely flexible, for instance, here&#8217;s how you would typically loop [...]]]></description>
			<content:encoded><![CDATA[<p>So, a few days ago I finally decided to give JavaScript a proper chance and as it turns out; All those people who&#8217;s been blabbering on about how JavaScript actually is a very powerful language where right all along!</p>
<p>You see, just like Ruby, JavaScript is extremely flexible, for instance, here&#8217;s how you would typically loop over an array:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> myArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>1<span style="color: #339933;">,</span> 2<span style="color: #339933;">,</span> 3<span style="color: #339933;">,</span> 4<span style="color: #339933;">,</span> 5<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> myArray.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>However, in Ruby land we&#8217;ve grown to know and love the [].each { |elem| &#8230; } way of looping, JavaScript doesn&#8217;t have that but fortunately adding it yourself is trivial:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">// Extend the Array object with an each function</span><br />
Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">each</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Loop through each element in this (which will be the </span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// array instance we call each on)</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Call the callback function with it's context</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// set to the current array element</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fn.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// With our new each function in place we can now iterate </span><br />
<span style="color: #006600; font-style: italic;">// over an array like this</span><br />
<span style="color: #009900;">&#91;</span>1<span style="color: #339933;">,</span> 2<span style="color: #339933;">,</span> 3<span style="color: #339933;">,</span> 4<span style="color: #339933;">,</span> 5<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">each</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><br />
&nbsp; &nbsp; <span style="color: #000066;">alert</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: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Now, even though this is a very simple example, it does give you an idea of just how powerful of a language it really is, and while it&#8217;s not as pretty to look at as ruby, thereof the unfortunate disguise, dismissing JavaScript as a toy language just isn&#8217;t viable any more.</p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/TnLY3_pmVf4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/10/javascript-a-quite-capable-ruby-in-an-unfortunate-disguise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/10/javascript-a-quite-capable-ruby-in-an-unfortunate-disguise/</feedburner:origLink></item>
		<item>
		<title>5-10 second delay when launching Terminal.app in OSX</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/N9tr8is-W8o/</link>
		<comments>http://www.pastbedti.me/2009/09/5-10-second-delay-when-launching-terminal-in-osx/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 20:29:36 +0000</pubDate>
		<dc:creator>Mathias Stjernström</dc:creator>
				<category><![CDATA[Operatingsystem]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=540</guid>
		<description><![CDATA[A couple of days ago my Terminal.app (console) got a really annoying feature. When launching the console or when I created a new tab it got stuck for about 5-10 seconds before I got my prompt. 
If you are like me and are spending most of your time in Terminal.app you understand how annoying this [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago my Terminal.app (console) got a really annoying feature. When launching the console or when I created a new tab it got stuck for about 5-10 seconds before I got my prompt. </p>
<p>If you are like me and are spending most of your time in Terminal.app you understand how annoying this is/was. </p>
<p>I tried to rename .profile, .inputrc and evey other startup script I had in my home folder but the problem did not go away. </p>
<p>Then I found an OSX user which had his Terminal crash when started. He solved his problem by cleaning up some OSX systemlogs. So I thought I try the same trick.</p>
<p>The logfiles which he removed where the asl files under /private/var/log/asl/</p>
<p>I read about them here: <a href="http://macosx.com/tech-support/can-i-deleteasl-log/24223.html">http://macosx.com/tech-support/can-i-deleteasl-log/24223.html</a></p>
<p>But I figured I&#8217;d just remove them all <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo rm -rf /private/var/log/asl/*</div></td></tr></tbody></table></div>
<p>When all asl files where removed my Terminal went back to normal again and I am sooooooo relieved. </p>
<p><strong>This worked for me BUT I do not recommend you to remove anything if you do not know what you are doing!!!<br />
</strong><br />
Cheers!</p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/N9tr8is-W8o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/09/5-10-second-delay-when-launching-terminal-in-osx/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/09/5-10-second-delay-when-launching-terminal-in-osx/</feedburner:origLink></item>
		<item>
		<title>Coder girl</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/6ik1mz1D3pU/</link>
		<comments>http://www.pastbedti.me/2009/09/coder-girl/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 20:41:28 +0000</pubDate>
		<dc:creator>Patrik Hedman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=531</guid>
		<description><![CDATA[She&#8217;s not wrapped in flash
all she wants is her java and a shell to bash
While, she&#8217;s a sight to C, plus
Her smile glimmers just like a Ruby does


You just gotta love it  
]]></description>
			<content:encoded><![CDATA[<blockquote><p>She&#8217;s not wrapped in flash<br />
all she wants is her java and a shell to bash<br />
While, she&#8217;s a sight to C, plus<br />
Her smile glimmers just like a Ruby does
</p></blockquote>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/B-m6JDYRFvk&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/B-m6JDYRFvk&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>You just gotta love it <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/6ik1mz1D3pU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/09/coder-girl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/09/coder-girl/</feedburner:origLink></item>
		<item>
		<title>Getting Vim up and running under Snow Leopard</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/1CLLge5LKo0/</link>
		<comments>http://www.pastbedti.me/2009/09/getting-vim-up-and-running-under-snow-leopard/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 19:15:54 +0000</pubDate>
		<dc:creator>Patrik Hedman</dc:creator>
				<category><![CDATA[Mouseless]]></category>
		<category><![CDATA[Operatingsystem]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[snow leopard]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=526</guid>
		<description><![CDATA[So, last night I upgraded my dev machine to Snow Leopard and what kind of a dev machine would it be without Vim?
Fortunately, for some at least, OS X still ships with Vim precompiled, unfortunately for me tough it still don&#8217;t come with ruby support enabled.
Since MacVim, which I usually use, isn&#8217;t yet compatible with [...]]]></description>
			<content:encoded><![CDATA[<p>So, last night I upgraded my dev machine to Snow Leopard and what kind of a dev machine would it be without Vim?<br />
Fortunately, for some at least, OS X still ships with Vim precompiled, unfortunately for me tough it still don&#8217;t come with ruby support enabled.</p>
<p>Since MacVim, which I usually use, isn&#8217;t yet compatible with Snow Leopard I decided to try and compile the regular vim <a href="http://www.pastbedti.me/2009/01/how-to-compile-vim-under-os-x/">as Mathias explained  in a previous blog post about compiling for leopard</a>, well that attempt crashed and burned. I did however get it to compile correctly after a minor tweak to his instructions:</p>
<p>On line 7 in src/auto/config.mk I changed the following line:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">LDFLAGS &nbsp; = -L. -arch i386 -arch x86_64</div></td></tr></tbody></table></div>
<p>To look like:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">LDFLAGS &nbsp; = -L. -arch x86_64</div></td></tr></tbody></table></div>
<p>While it did compile successfully, launching Vim just resulted in it exiting immediately with the message: abort trap.</p>
<p>Back at square one I started browsing the <a href="http://groups.google.com/group/vim_mac/browse_thread/thread/93b65296a79c7721">vim_mac mailing list</a> and here&#8217;s how I finally got it working:</p>
<p>Start off by cloning the macvim repository:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">~ $ git clone git://repo.or.cz/MacVim.git</div></td></tr></tbody></table></div>
<p>Then  change into the MacVim/src directory and configure and run make:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">~ $ cd MacVim/src<br />
MacVim/src $ ./configure --enable-gui-macvim --enable-rubyinterp<br />
MacVim/src $ make</div></td></tr></tbody></table></div>
<p>Now change into the MacVim directory:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MacVim/src $ cd MacVim</div></td></tr></tbody></table></div>
<p>Normally this is where you would run xcodebuild, however that resulted in the following:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">** BUILD FAILED **<br />
The following build commands failed:<br />
MacVim:<br />
PhaseScriptExecution &quot;Make Document Icons&quot; /Users/pmh/Downloads/MacVim/src/MacVim/build/MacVim.build/Release/MacVim.build/Script-1D1C31F00EFFBFD6003FE9A5.sh<br />
(1 failure)</div></td></tr></tbody></table></div>
<p>The way to get around this is a bit cumbersome, but works.</p>
<p>Start by deleting line 6 in the Makefile that lives under the icons directory:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MacVim/src/MacVim $ cd icons<br />
MacVim/src/MacVim/icons $ vim Makefile<br />
# delete line 6 and save</div></td></tr></tbody></table></div>
<p>Then change line 22 in make_icons.py, in the same directory, from:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dont_create = False</div></td></tr></tbody></table></div>
<p>to:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dont_create = True</div></td></tr></tbody></table></div>
<p>Change back to the MacVim directory and run xcodebuild:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MacVim/src/MacVim/icons $ cd ..<br />
MacVim/src/MacVim $ xcodebuild</div></td></tr></tbody></table></div>
<p>You should now see something like the following:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PyObjC not found, only using a stock icon for document icons.<br />
&nbsp;** BUILD SUCCEEDED **</div></td></tr></tbody></table></div>
<p>Now move the MacVim.app to the /Applications folder:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MacVim/src/MacVim $ mv build/Release/MacVim.app /Applications/</div></td></tr></tbody></table></div>
<p>In order to invoke vim from the command line you need to add the following alias to your ~/.profile or what have you:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">alias vim=/Applications/MacVim.app/Contents/MacOS/Vim</div></td></tr></tbody></table></div>
<p><del datetime="2009-09-06T12:01:59+00:00">Note however that this only lets you use the command line version of MacVim, there seems to still be some issues with the graphical one.<br />
</del><br />
Update:<br />
As Björn pointed out in the comments, the graphical version of MacVim does work under Snow Leopard, also be sure to checkout his <a href="http://b4winckler.wordpress.com/2009/09/02/macvim-on-snow-leopard/">precompiled binary</a></p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/1CLLge5LKo0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/09/getting-vim-up-and-running-under-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/09/getting-vim-up-and-running-under-snow-leopard/</feedburner:origLink></item>
		<item>
		<title>How to make vim save its *~ and *.swp files in a separate directory</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/vfVWo4KHCFU/</link>
		<comments>http://www.pastbedti.me/2009/08/how-to-make-vim-save-its-and-swp-files-in-a-separate-directory/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 06:39:23 +0000</pubDate>
		<dc:creator>Patrik Hedman</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[vim backup]]></category>
		<category><![CDATA[vimrc]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=515</guid>
		<description><![CDATA[If you, like me, are tired of vim&#8217;s pesky backup and swap files littering your project directory then you too should create a .vimtmp directory in your home folder and add this little snippet to your .vimrc
123&#34; Store vim backups and *.swp files in ~/.vimtmp with a unique name
set backupdir=~/.vimtmp//
set directory=~/.vimtmp//
Now all your backup and [...]]]></description>
			<content:encoded><![CDATA[<p>If you, like me, are tired of vim&#8217;s pesky backup and swap files littering your project directory then you too should create a .vimtmp directory in your home folder and add this little snippet to your .vimrc</p>
<div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #adadad; font-style: italic;">&quot; Store vim backups and *.swp files in ~/.vimtmp with a unique name</span><br />
set backupdir=<span style="color: #000000;">~/.</span>vimtmp<span style="color: #000000;">//</span><br />
set directory=<span style="color: #000000;">~/.</span>vimtmp<span style="color: #000000;">//</span></div></td></tr></tbody></table></div>
<p>Now all your backup and swap files will be stored in ~/.vimtmp/ and prefixed with a formatted file path, eg, %some%where%on%my%computer%some_file.ext.swp</p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/vfVWo4KHCFU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/08/how-to-make-vim-save-its-and-swp-files-in-a-separate-directory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/08/how-to-make-vim-save-its-and-swp-files-in-a-separate-directory/</feedburner:origLink></item>
		<item>
		<title>This just in: To much typing is bad for you!</title>
		<link>http://feedproxy.google.com/~r/pastbedtime/~3/JDCuzWV2grM/</link>
		<comments>http://www.pastbedti.me/2009/08/this-just-in-to-much-typing-is-bad-for-you/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 22:54:43 +0000</pubDate>
		<dc:creator>Patrik Hedman</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[ffmpeg]]></category>

		<guid isPermaLink="false">http://www.pastbedti.me/?p=509</guid>
		<description><![CDATA[So in order to save your fingers the pain I updated the ffmpeg gem today. You see, previously you had to do this:
123convert &#34;finding_that_nemo_dude.avi&#34;, :to =&#62; &#34;finding_that_nemo_dude.flv&#34; do
&#160; ...
end.run
Doesn&#8217;t look to bad, right? Well, maybe not, but if you pay attention you would notice some repetition here, since the only thing different about the filenames [...]]]></description>
			<content:encoded><![CDATA[<p>So in order to save your fingers the pain I updated the <a href="http://github.com/polly/ffmpeg/tree/master" target="_blank">ffmpeg gem</a> today. You see, previously you had to do this:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">convert <span style="color:#996600;">&quot;finding_that_nemo_dude.avi&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;finding_that_nemo_dude.flv&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; ...<br />
<span style="color:#9966CC; font-weight:bold;">end</span>.<span style="color:#9900CC;">run</span></div></td></tr></tbody></table></div>
<p>Doesn&#8217;t look to bad, right? Well, maybe not, but if you pay attention you would notice some repetition here, since the only thing different about the filenames is the extension. So, to keep things nice and dry you can now do this instead:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">convert <span style="color:#996600;">&quot;finding_that_nemo_dude.avi&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:flv</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; ...<br />
<span style="color:#9966CC; font-weight:bold;">end</span>.<span style="color:#9900CC;">run</span></div></td></tr></tbody></table></div>
<p>The old way still works if you really want a different filename all together or if you just really like to type <img src='http://www.pastbedti.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/pastbedtime/~4/JDCuzWV2grM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.pastbedti.me/2009/08/this-just-in-to-much-typing-is-bad-for-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.pastbedti.me/2009/08/this-just-in-to-much-typing-is-bad-for-you/</feedburner:origLink></item>
	</channel>
</rss>
