<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alfa Jango Blog</title>
	<atom:link href="http://www.alfajango.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alfajango.com/blog</link>
	<description>Engineering, Software, and Entrepreneurship</description>
	<lastBuildDate>Wed, 10 Mar 2010 03:05:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Performance Tuning for Phusion Passenger (an Introduction)</title>
		<link>http://www.alfajango.com/blog/performance-tuning-for-phusion-passenger-an-introduction/</link>
		<comments>http://www.alfajango.com/blog/performance-tuning-for-phusion-passenger-an-introduction/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 13:54:07 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[performance tuning]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[swap]]></category>

		<guid isPermaLink="false">http://www.alfajango.com/blog/?p=142</guid>
		<description><![CDATA[Once you've launched your application and people start actually using it, you may find server experiencing excessive swapping once the traffic begins to pick up. Before getting too deep into scaling, caching, upgrading your server, etc., there are a few Passenger settings you can tune to wring out the best performance your existing stack. I'll address these settings with a few rules of thumb we've gathered from the Passenger documentation and simple trial-and-error.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfajango.com/blog/wp-content/uploads/2010/03/Picture-10.png"><img class="size-medium wp-image-151 alignright" title="Picture 10" src="http://www.alfajango.com/blog/wp-content/uploads/2010/03/Picture-10-237x300.png" alt="" width="237" height="300" /></a><a href="http://www.modrails.com/">Phusion Passenger</a> (aka mod_rails) allows for easy and scalable deployment of Ruby on Rails applications on Apache or Nginx servers. Part of what makes it so easy is that it comes with suitable default settings right out of the box, so that you don&#8217;t need to concern yourself with any of the details when deploying your application to production.</p>
<p>However, once you&#8217;ve launched your application and people start actually using it, you may find server experiencing excessive swapping once the traffic begins to pick up. Before getting too deep into scaling, caching, upgrading your server, etc., there are a few Passenger settings you can tune to wring out the best performance your existing stack. I&#8217;ll address these settings with a few rules of thumb we&#8217;ve gathered from the <a href="http://www.modrails.com/documentation.html">Passenger documentation</a> and simple trial-and-error.</p>
<p>Before getting started, we highly recommend employing Munin (<a href="http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin/">instructions for Munin with Passenger here</a>) and NewRelic Performance Monitoring for your Passenger/Rails application, so that you can fine-tune your settings for the best performance.</p>
<p><em>Note: the following settings are specific for Apache, you will need to modify the syntax/file-names for Nginx.</em></p>
<h2><span style="font-weight: normal;">Per-server Settings</span></h2>
<p><span style="font-weight: normal;">These settings are set per-server, meaning if you have multiple applications running on the server, these should be set only once throughout all of your <code class="codecolorer text default"><span class="text">.conf</span></code> files. If you have only one Rails/Passenger app on the server, then you may set these in that application&#8217;s <code class="codecolorer text default"><span class="text">.conf</span></code> file. On Ubuntu, this may be found at <code class="codecolorer text default"><span class="text">/etc/apache2/sites-available/yourapp.conf</span></code>. </span></p>
<p><span style="font-weight: normal;">A more appropriate place for these however would be in Apache&#8217;s <code class="codecolorer text default"><span class="text">.conf</span></code> file.</span></p>
<h3>PassengerMaxPoolSize and PassengerPoolIdleTime</h3>
<p><code class="codecolorer text default"><span class="text">/etc/apache2/apache2.conf</span></code>:</p>
<p><span style="font-weight: normal;"></p>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #adadad; font-style: italic;"># PassengerMaxPoolSize</span><br />
<span style="color: #adadad; font-style: italic;"># Default: 6</span><br />
<span style="color: #adadad; font-style: italic;"># For 2gb RAM: 30</span><br />
<span style="color: #adadad; font-style: italic;"># For 256 slice with MySQL running: 2</span><br />
PassengerMaxPoolSize <span style="color: #ff0000;">2</span><br />
<br />
<span style="color: #adadad; font-style: italic;"># PassengerPoolIdleTime</span><br />
<span style="color: #adadad; font-style: italic;"># Recommended to be avg time per page * 2</span><br />
<span style="color: #adadad; font-style: italic;"># In Google Analytics... (Avg time on site / Avg page views) * 2</span><br />
<span style="color: #adadad; font-style: italic;"># Default: 300</span><br />
PassengerPoolIdleTime <span style="color: #ff0000;">150</span></div></div>
<p><span style="font-weight: normal;">You can essentially copy and paste this into your apache conf file. I&#8217;ve added some notes in there to help you remember how they should be tuned.</span></p>
<p><span style="font-weight: normal;"><a href="http://modrails.com/documentation/Users%20guide%20Apache.html#_passengermaxpoolsize_lt_integer_gt"><code class="codecolorer apache default"><span class="apache">PassengerMaxPoolSize</span></code></a>: This is the number of Passenger instances that can be spawned at once for your site. This basically relates directly to the amount of RAM that is available to your application. However, it is not a linear relationship. It&#8217;s more of an exponential relationship. Numbers that we and others have found to work well are:</span></p>
<table>
<tbody>
<tr>
<th>RAM (MB)</th>
<th>PassengerMaxPoolSize</th>
</tr>
<tr>
<td>256</td>
<td>2</td>
</tr>
<tr>
<td>512</td>
<td>6 (default)</td>
</tr>
<tr>
<td>1024 (1GB)</td>
<td>15</td>
</tr>
<tr>
<td>2048 (2GB)</td>
<td>30</td>
</tr>
</tbody>
</table>
<p>Since this depends on available RAM, this will vary depending on what other processes are running on your server, such as MySQL, etc. If you have Munin installed with the Passenger plugins, you can monitor the Passenger Memory Stats and Passenger Status graphs to tweak this as necessary.</p>
<p><a href="http://modrails.com/documentation/Users%20guide%20Apache.html#PassengerPoolIdleTime"><code class="codecolorer apache default"><span class="apache">PassengerPoolIdleTime</span></code></a>: This is essentially the amount of time (in seconds) that each Passenger instance continues to run after it becomes idle (i.e. someone stops clicking around the site). According to the documentation, this should be set to the average time a visitor views a page multiplied by 2. This of course prevents Passenger instances from shutting down (and thus having to re-spawn) while someone is viewing a page.</p>
<p>If your application has been in production long enough to have a few hundred viewers and you have Google Analytics installed, an easy way to get the ideal setting for your application is to take the Average Time on Site, divide by the Average Page Views per Visit, and multiply by 2.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">( Average Time on Site / Average Page Views per Visit ) x 2</div></div>
<h3>PassengerMaxInstancesPerApp (optional)</h3>
<p>If you do have more than one Rails/Passenger application on the server, you may optionally set <code class="codecolorer text default"><span class="text">PassengerMaxInstancesPerApp</span></code>.</p>
<p><a href="http://modrails.com/documentation/Users%20guide%20Apache.html#_passengermaxinstancesperapp_lt_integer_gt"><code class="codecolorer apache default"><span class="apache">PassengerMaxInstancesPerApp</span></code></a>: This is the maximum number of instances each application may use of the total <code class="codecolorer text default"><span class="text">PassengerMaxPoolSize</span></code>. Therefore, <code class="codecolorer text default"><span class="text">PassengerMaxInstancesPerApp</span></code> must be smaller than <code class="codecolorer text default"><span class="text">PassengerMaxPoolSize</span></code>.</p>
<p>For example, if you have 2 applications running on one 256MB server, you may want to set <code class="codecolorer text default"><span class="text">PassengerMaxInstancesPerApp</span></code> to 1, so that one app may never hog all of the rails instances at the expense of the other app. If you have 2 applications running on a 512MB server (<code class="codecolorer text default"><span class="text">PassengerMaxPoolSize</span></code> 6), then you may want to set cci]PassengerMaxInstancesPerApp[/cci] to 4 or 5 to allow each app to better handle higher load (hopefully while the other app is under less load).</p>
<h3>RailsAutoDetect</h3>
<p>To get a little more performance out of your server, you can also turn the <a href="http://modrails.com/documentation/Users%20guide%20Apache.html#_railsautodetect_lt_on_off_gt"><code class="codecolorer apache default"><span class="apache">RailsAutoDetect</span></code></a> setting of Passenger off. This will make it so that each request through Apache does not check to see if it is a Rails request that requires Passenger. However, this will now require that you explicitly tell Apache which requests are Rails and do require Passenger, using <a href="http://modrails.com/documentation/Users%20guide%20Apache.html#RailsBaseURI"><code class="codecolorer apache default"><span class="apache">RailsBaseURI</span></code></a>. This is easy though.</p>
<p>Again, in your <code class="codecolorer text default"><span class="text">apache2.conf</span></code> file:</p>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #adadad; font-style: italic;"># Must be used with RailsBaseURI in Vhost</span><br />
RailsAutoDetect <span style="color: #0000ff;">off</span></div></div>
<p>Now, within your the Vhost block in your site&#8217;s <code class="codecolorer text default"><span class="text">.conf</span></code> file, you will need to set the <code class="codecolorer text default"><span class="text">RailsBaseURI</span></code>:</p>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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; ...<br />
&nbsp; RailsBaseURI /<br />
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</div></div>
<p>Here is a complete example of the Passenger block in your <code class="codecolorer text default"><span class="text">apache2.conf</span></code> file:</p>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #adadad; font-style: italic;"># PassengerMaxPoolSize</span><br />
<span style="color: #adadad; font-style: italic;"># Default: 6</span><br />
<span style="color: #adadad; font-style: italic;"># For 2gb RAM: 30</span><br />
<span style="color: #adadad; font-style: italic;"># For 256 slice with MySQL running: 2</span><br />
PassengerMaxPoolSize <span style="color: #ff0000;">2</span><br />
<br />
<span style="color: #adadad; font-style: italic;"># PassengerPoolIdleTime</span><br />
<span style="color: #adadad; font-style: italic;"># Recommended to be avg time per page * 2</span><br />
<span style="color: #adadad; font-style: italic;"># In Google Analytics... (Avg time on site / Avg page views) * 2</span><br />
<span style="color: #adadad; font-style: italic;"># Default: 300</span><br />
PassengerPoolIdleTime <span style="color: #ff0000;">144</span><br />
<br />
<span style="color: #adadad; font-style: italic;"># PassengerMaxInstancesPerApp &lt; PassengerMaxPoolSize </span><br />
PassengerMaxInstancesPerApp <span style="color: #ff0000;">1</span><br />
<br />
<span style="color: #adadad; font-style: italic;"># Must be used with RailsBaseURI in Vhost</span><br />
RailsAutoDetect <span style="color: #0000ff;">off</span></div></div>
<p>And a simple <code class="codecolorer text default"><span class="text">sites-available/yourapp.conf</span></code> may look like this:</p>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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.yourapp.com<br />
&nbsp; <span style="color: #00007f;">DocumentRoot</span> /home/deploy/yourapp/current/public<br />
&nbsp; &lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;/home/deploy/yourapp/current/public&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">FollowSymLinks</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span><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; &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
&nbsp; RailsBaseURI /<br />
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</div></div>
<p></p>
<h2>More Passenger Configuration Settings</h2>
<p>These settings so far only scratch the surface of Passenger configuration. Give the <a href="http://modrails.com/documentation/Users%20guide%20Apache.html#_configuring_phusion_passenger">Passenger documentation</a> a good read-through for more information on configuring Passenger.</p>
<h2>Further Reading: Apache Settings</h2>
<p>At this point, if you still need to squeeze more performance out of your server (and you will eventually), you&#8217;ll want to configure Apache to utilize its resources most efficiently with Passenger. I recommend reading through <a href="http://forum.slicehost.com/comments.php?DiscussionID=1776">this thread on the Slicehost forums</a> to get a good idea just how much trial-and-error this will take. <strong>Keep a close eye on your server when you tweak these settings, you may end up making it slower several times before finding that sweet spot.</strong></p>
<p>You may read the <a href="http://httpd.apache.org/docs/1.3/mod/core.html">documentation for each setting in the Apache docs</a> (note that these are the Apache 1.3 docs, but they still explain purpose of each setting well). For more information using these settings to reduce the RAM consumed by Apache, see <a href="http://forum.slicehost.com/comments.php?DiscussionID=3313">this other Slicehost forum</a> and <a href="http://programming-gone-awry.blogspot.com/2009/06/how-to-save-much-ram-when-running-rails.html">this blog post on saving RAM with Rails and Passenger</a>.</p>
<p>If you&#8217;re impatient and just want to get something better than default, here are some numbers that worked well for us on a recent application running on a 256MB VPS on Slicehost. These settings can be found in your <code class="codecolorer text default"><span class="text">apache2.conf</span></code> file.</p>
<div class="codecolorer-container apache twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #adadad; font-style: italic;"># prefork MPM</span><br />
<span style="color: #adadad; font-style: italic;"># StartServers: number of server processes to start</span><br />
<span style="color: #adadad; font-style: italic;"># MinSpareServers: minimum number of server processes which are kept spare</span><br />
<span style="color: #adadad; font-style: italic;"># MaxSpareServers: maximum number of server processes which are kept spare</span><br />
<span style="color: #adadad; font-style: italic;"># MaxClients: maximum number of server processes allowed to start</span><br />
<span style="color: #adadad; font-style: italic;"># MaxRequestsPerChild: maximum number of requests a server process serves</span><br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mpm_prefork_module&gt;<br />
&nbsp; <span style="color: #00007f;">StartServers</span>          2<br />
&nbsp; <span style="color: #00007f;">MinSpareServers</span>       1<br />
&nbsp; <span style="color: #00007f;">MaxSpareServers</span>       5<br />
&nbsp; <span style="color: #00007f;">MaxClients</span>           10<br />
&nbsp; <span style="color: #00007f;">MaxRequestsPerChild</span>   100<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;<br />
<span style="color: #adadad; font-style: italic;"># worker MPM</span><br />
<span style="color: #adadad; font-style: italic;"># StartServers: initial number of server processes to start</span><br />
<span style="color: #adadad; font-style: italic;"># MaxClients: maximum number of simultaneous client connections</span><br />
<span style="color: #adadad; font-style: italic;"># MinSpareThreads: minimum number of worker threads which are kept spare</span><br />
<span style="color: #adadad; font-style: italic;"># MaxSpareThreads: maximum number of worker threads which are kept spare</span><br />
<span style="color: #adadad; font-style: italic;"># ThreadsPerChild: constant number of worker threads in each server process</span><br />
<span style="color: #adadad; font-style: italic;"># MaxRequestsPerChild: maximum number of requests a server process serves</span><br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mpm_worker_module&gt;<br />
&nbsp; <span style="color: #00007f;">StartServers</span>          2<br />
&nbsp; <span style="color: #00007f;">MaxClients</span>           10<br />
&nbsp; <span style="color: #00007f;">MinSpareThreads</span>      25<br />
&nbsp; <span style="color: #00007f;">MaxSpareThreads</span>      75<br />
&nbsp; <span style="color: #00007f;">ThreadsPerChild</span>      25<br />
&nbsp; <span style="color: #00007f;">MaxRequestsPerChild</span>   100<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</div></div>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfajango.com/blog/performance-tuning-for-phusion-passenger-an-introduction/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Include Your Rails App Layout in Your Wordpress Theme (or any PHP application)</title>
		<link>http://www.alfajango.com/blog/how-to-include-your-rails-app-layout-in-your-wordpress-theme-or-any-php-application/</link>
		<comments>http://www.alfajango.com/blog/how-to-include-your-rails-app-layout-in-your-wordpress-theme-or-any-php-application/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 22:31:48 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[integration]]></category>

		<guid isPermaLink="false">http://www.alfajango.com/blog/?p=68</guid>
		<description><![CDATA[Here's the problem: You have a Ruby on Rails application and its Wordpress blog. For the sake of consistency and branding, you'd like to use the same layout in your Wordpress blog as you do for your Rails app. Perhaps your blog is one of the main links or tabs in your application's header.]]></description>
			<content:encoded><![CDATA[<p><strong>Here&#8217;s the problem:</strong> You have a <a href="http://rubyonrails.org/">Ruby on Rails</a> application and its <a href="http://wordpress.org/">Wordpress</a> blog. For the sake of consistency and branding, you&#8217;d like to use the same layout in your Wordpress blog as you do for your Rails app. Perhaps your blog is one of the main links or tabs in your application&#8217;s header.</p>
<p><img class="size-full wp-image-133 alignnone" title="rails-wordpress-link" src="http://www.alfajango.com/blog/wp-content/uploads/2010/02/rails-wordpress-link.jpg" alt="" width="500" height="233" /></p>
<p><strong>Why this doesn&#8217;t work:</strong> You proceed with creating a custom theme for your Wordpress blog that looks exactly like your Rails application. Then over the next couple years, you begin to realize how tedious this solution is. You have to copy over your CSS stylesheets from your Rails app, your Javascript files (if your standard layout contains any Javascript elements, like a Twitter widget in the footer or whatever), and your layout images and assets. Then, every time you change or update the layout of your Rails app, you have to copy the changes in your custom Wordpress theme. And you cannot just copy the changes, because if you have any Ruby/Rails functionality in the layout, you have to translate them into PHP functionality in your Wordpress layouts.</p>
<p>And then there&#8217;s the impossible stuff&#8230; if anything in your Rails app layout loads information from the database in your Rails app, then you cannot have those elements in your Wordpress layout, unless you do something like create an XML or JSON feed in your Rails app and then import it in your Wordpress layout. But this is quite tedious still if you want to change any of it!</p>
<p>There&#8217;s an easier way.</p>
<h3>Include Your Rails Layout Directly In Your Wordpress Layout</h3>
<p>The solution I found turns out to be quite simple. The basic idea is to create a <code class="codecolorer rails default"><span class="rails"><span style="color:#ff3333; font-weight:bold;">:partial</span></span></code> in your Rails app layout, make it publicly accessible via your <code class="codecolorer text default"><span class="text">config/routes.rb</span></code>, have it generate and simply return the appropriate html using your controller method, and then import that html (and CSS) in your Wordpress layout.</p>
<p>For this to really work well, you&#8217;ll want to make sure that you make your Rails app cache the partials to be imported into your Wordpress layout, so that a lot of traffic on your blog doesn&#8217;t cause your Rails app server to explode.</p>
<h3>1. Break Your Rails Layout into Partials</h3>
<p>The first step is to break as much of your <code class="codecolorer text default"><span class="text">app/views/layouts/application.html.erb</span></code> into partials as possible/desired. At the very least, this means a header and a footer partial. Typically, you would not include the stuff in the <code class="codecolorer html4strict default"><span class="html4strict"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span></span></code> part of the layout, because your Wordpress will likely require additional stylesheets and a different set of javascripts (not to mention you&#8217;ll want to make your meta information specific for your blog pages).</p>
<p>A simple Rails layout using this method would look something like this:</p>
<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
...<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'static/header'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&lt;div id=&quot;content&quot;&gt;<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&lt;/div&gt;<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'static/footer'</span><span style="color:#006600; font-weight:bold;">%&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'static/widgets'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&lt;/body&gt;<br />
&lt;/html&gt;</div></div>
<p>I&#8217;ve also included a widgets partial to show that this can be done with static javascript widgets as well.</p>
<p>Note that your layout and partials can have any and all Ruby/Rails code in them that you want. Since your Wordpress theme is importing this stuff from your Rails application, the Rails app will run as usual and just return the end result, which is HTML, so your Wordpress will have no problem interpreting it.</p>
<p>A simple <code class="codecolorer text default"><span class="text">app/views/static/_header.html.erb</span></code> partial may look something like this:</p>
<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;div id=&quot;header&quot;&gt;<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#5A0A0A; font-weight:bold;">image_tag</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;layout/my_logo.png&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, root_path, <span style="color:#ff3333; font-weight:bold;">:alt</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;My Rails App&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;banner_logo&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&lt;div id=&quot;menu&quot;&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">&quot;Products&quot;</span>, products_path, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">path</span> == products_path<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&lt;/li&gt;<br />
&lt;li&gt;<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">&quot;Blog&quot;</span>, blog_path, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@blog</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&lt;/li&gt;<br />
&lt;li&gt;<br />
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">&quot;Contact&quot;</span>, contact_path, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">path</span> == contact_path<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;</div></div>
<p>Notice that the normal links in the header are &#8220;active&#8221; simply if the current URL matches the link path, but the &#8220;Blog&#8221; link is active if the <code class="codecolorer ruby default"><span class="ruby"><span style="color:#0066ff; font-weight:bold;">@blog</span></span></code> variable is set and true. This is because, as you will see in the next section, the URL for the header when it is called from your blog won&#8217;t be the blog URL.</p>
<h3>2. Make Your Layout Partials Publicly Accessible</h3>
<p>The next step is to make your layout partials publicly accessible. I.e. make it so that you can access your layout partials from the browser using a direct URL, like http://mysite.com/static/header. The actual URL you use doesn&#8217;t really matter, because users won&#8217;t ever need to see or use it.</p>
<p>The way we do this is to explicitly set a path for each layout partial in our <code class="codecolorer text default"><span class="text">config/routes.rb</span></code> and then create a controller method for each that renders the HTML generated by the partial.</p>
<p>A path in your routes for your header partial might look like this:</p>
<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">ActionController::Routing</span></span>::Routes.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>map<span style="color:#006600; font-weight:bold;">|</span><br />
...<br />
<span style="color:#9900CC;">map</span>.<span style="color:#9900CC;">header_partial</span> <span style="color:#996600;">'static/my_blog_header'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'static'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'blog_header_partial'</span><br />
...<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Then in the <code class="codecolorer text default"><span class="text">app/controllers/static_controller.rb</span></code>, your corresponding action would look like this:</p>
<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> blog_header_partial<br />
<span style="color:#0066ff; font-weight:bold;">@blog</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
<span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'static/header'</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Now, hopefully you see why, in the header partial, we couldn&#8217;t just say that the blog menu item is <code class="codecolorer rails default"><span class="rails">:<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">path</span> == blog_path<span style="color:#006600; font-weight:bold;">&#41;</span></span></code>. The path that the header partial will be seeing when the Wordpress layout requests it will be the path you defined in your <code class="codecolorer text default"><span class="text">routes.rb</span></code>, in this case <code class="codecolorer text default"><span class="text">&quot;static/header&quot;</span></code>. This is why we instead say <code class="codecolorer rails default"><span class="rails">:<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@blog</span><span style="color:#006600; font-weight:bold;">&#41;</span></span></code> and then set <code class="codecolorer ruby default"><span class="ruby"><span style="color:#0066ff; font-weight:bold;">@blog</span> = <span style="color:#0000FF; font-weight:bold;">true</span></span></code> in the controller action.</p>
<h3>Include the Rails Partials In the Wordpress Layout</h3>
<p>Here&#8217;s the real trick. In order to include the Rails partials in your Wordpress layout, you might be inclined to use on of these PHP functions: <a href="http://php.net/manual/en/function.include.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a> or <a href="http://www.php.net/manual/en/function.require.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a>. This won&#8217;t work though for two reasons.</p>
<p>1) <a href="http://php.net/manual/en/function.include.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a> and <a href="http://www.php.net/manual/en/function.require.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a> both read <code class="codecolorer text default"><span class="text">.php</span></code> files. However, your publicly-accessible layout partials are going to return straight HTML.</p>
<p>2) By default, neither method allows absolute URLs due to security precautions. You can change your PHP setup to allow this, but again, this is a security issue. Not to mention, for our purposes, you still would have to deal with reason 1 above.</p>
<p>Instead, we can use PHP&#8217;s function to retreive HTML code, <a href="http://us.php.net/manual/en/function.file-get-contents.php"><code class="codecolorer php default"><span class="php"><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a>.</p>
<p>In your wp-content/themes/my_theme/header.php file, you would then include this line:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
&lt;body&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://myrailsapp.com/static/my_blog_header&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
...</div></div>
<h3>Import the Rails CSS Stylesheet for Wordpress</h3>
<p>Of course, you&#8217;ll also want to import the base stylesheet that styles your layout HTML for your Wordpress theme. You can do this a few different ways. The easiest is to just include it in your <code class="codecolorer text default"><span class="text">header.php</span></code> file in the <code class="codecolorer text default"><span class="text">&lt;head&gt;</span></code> area like any other stylesheet, just using the absolute URL to the CSS file.</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://myrailsapp.com/stylesheets/style.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php bloginfo('stylesheet_url'); ?&gt;</span></span>&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;<br />
...</div></div>
<p>Notice that we include the Rails app stylesheet before the blog stylesheet. This is so that it&#8217;s easy to override any of the styles we need to specifically in the blog stylesheet.</p>
<p>An alternative way we can do this is using the CSS <code class="codecolorer css default"><span class="css"><span style="color: #a1a100;">@import</span></span></code> method.</p>
<h3>Cache the Layout Partials On Your Rails Server</h3>
<p>The astute programmer in you may have noticed by now that this turns a single request on your blog into multiple additional requests on your Rails app server (one additional request per partial that&#8217;s imported in your Wordpress layout, e.g. header, footer, etc.). We can&#8217;t have that!</p>
<p>Luckily this is easy to fix with <a href="http://railsenvy.com/2007/2/28/rails-caching-tutorial#pagination">Rails&#8217;s built-in page-caching</a>.</p>
<p>In your <code class="codecolorer text default"><span class="text">app/controllers/static_controller.rb</span></code> file, include the following.</p>
<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails 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> StaticController <span style="color:#006600; font-weight:bold;">&amp;</span>lt; ApplicationController<br />
caches_page <span style="color:#ff3333; font-weight:bold;">:index</span>, <span style="color:#ff3333; font-weight:bold;">:blog_header_partial</span>, <span style="color:#ff3333; font-weight:bold;">:blog_header_footer</span>, <span style="color:#ff3333; font-weight:bold;">:blog_widgets</span><br />
...<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>And make sure that caching is turned on in your production app, in <code class="codecolorer text default"><span class="text">config/environments/production.rb</span></code>:</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">perform_caching</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
config.<span style="color:#9900CC;">action_view</span>.<span style="color:#9900CC;">cache_template_loading</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
...</div></div>
<h3>And/Or Cache Your Wordpress Pages (recommended)</h3>
<p>Of course, if you <a href="http://wordpress.org/extend/plugins/wp-super-cache/installation/">install and setup caching in your Wordpress installation</a> (highly recommended), then the complete layout files will be cached and never even need to make calls to your Rails application after the cached pages are generated the first time. This is even faster for your Wordpress blog, because it&#8217;ll load faster now that it doesn&#8217;t have to import portions of the layout from an external URL every time a page is loaded.</p>
<p>Note that when you do this, you&#8217;ll need to expire/delete the cached Wordpress files anytime you update the layout in your Rails app.</p>
<h3>Done!</h3>
<p>Now you have a great looking Wordpress blog that looks like you&#8217;re never leaving your Rails application. And best of all, you don&#8217;t have to tediously duplicate efforts every time you update your Rails app layout! How&#8217;s that for <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a> design?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfajango.com/blog/how-to-include-your-rails-app-layout-in-your-wordpress-theme-or-any-php-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Monitor Your Rails/Passenger App with Munin</title>
		<link>http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin/</link>
		<comments>http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 15:35:23 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[Munin]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.alfajango.com/blog/?p=65</guid>
		<description><![CDATA[Munin is a great tool to monitor resources on your server, showing graphs over time, so that you can analyze resource trends to find what's killing your server before it causes major problems. It is also very configurable and can be made to profile and graph just about anything via plugins. And with a couple tricks, you can get it to monitor your Phusion Passenger application with ease.]]></description>
			<content:encoded><![CDATA[<div id="attachment_70" class="wp-caption alignleft" style="width: 310px"><a href="http://www.alfajango.com/blog/wp-content/uploads/2010/02/Picture-10.png"><img class="size-medium wp-image-70 " title="Munin Passenger Plugin Graphs" src="http://www.alfajango.com/blog/wp-content/uploads/2010/02/Picture-10-300x189.png" alt="" width="300" height="189" /></a><p class="wp-caption-text"> </p></div>
<p><a href="http://munin.projects.linpro.no/">Munin</a> is a great tool to monitor resources on your server, showing graphs over time, so that you can analyze resource trends to find what&#8217;s killing your server before it causes major problems. It is also very configurable and can be made to profile and graph just about anything via plugins. And with a couple tricks, you can get it to monitor your <a href="http://www.modrails.com/">Phusion Passenger</a> application with ease.</p>
<p>If you already have Munin installed and working, and just want to know how to get the Passenger Plugins working, you can skip directly to Install <a href="http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin#install-munin-passenger-plugins">Munin Passenger Plugins</a>, <a href="http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin#configure-munin-for-passenger-stats">Configure Munin for Passenger Stats</a>, and be sure to read the <a href="http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin#gotcha">Gotcha</a>.</p>
<p><span id="more-65"></span></p>
<h3>Install Munin and Munin-node</h3>
<p>The first step is to install Munin. If you have your server running Ubuntu, this is pretty easy. One you&#8217;ve SSH&#8217;d into your server, enter:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo apt-get install munin munin-node -y</div></div>
<p>If you&#8217;re running another flavor of Linux, see the <a href="http://munin.projects.linpro.no/wiki/LinuxInstallation">Munin&#8217;s Linux install instructions</a>. For Mac OSX, see <a href="http://munin.projects.linpro.no/wiki/DarwinInstallation">Mac install instructions</a>.<br />
<a name="install-munin-passenger-plugins"></a></p>
<h3>Install Munin Passenger Plugins</h3>
<p>The next step is to install the Passenger plugins. The first is passenger_status:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">wget http://gist.github.com/20319.txt<br />
sudo mv 20319.txt /usr/share/munin/plugins/passenger_status<br />
sudo chmod a+x /usr/share/munin/plugins/passenger_status<br />
sudo ln -s /usr/share/munin/plugins/passenger_status /etc/munin/plugins/passenger_status</div></div>
<p>The second plugin is passenger_memory_stats:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">wget http://gist.github.com/21391.txt<br />
sudo mv 21391.txt /usr/share/munin/plugins/passenger_memory_stats<br />
sudo chmod a+x /usr/share/munin/plugins/passenger_memory_stats<br />
sudo ln -s /usr/share/munin/plugins/passenger_memory_stats /etc/munin/plugins/passenger_memory_stats</div></div>
<p>No go ahead and restart Munin-node (this is the process that runs Munin at regular intervals):</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo /etc/init.d/munin-node restart</div></div>
<h3>Configure Munin</h3>
<p>Now here are where those couple of tricks come in to get Munin playing nicely with your Rails application. First we want to tell Munin where to store the html and graph images that you can access through the browser.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo nano /etc/munin/munin.conf</div></div>
<p>And change the following lines:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">htmldir /path/to/your/rails/shared/directory/munin<br />
[yoursite.com]</div></div>
<p>Note that the htmldir can really be any directory, but make sure it&#8217;s persistent (i.e. if you&#8217;re using Capistrano to keep revisions of your app on the server, make sure the munin directory is in the shared directory outside of your rails app root directory).</p>
<p>Also note that the <code class="codecolorer text default"><span class="text">[yoursite.com]</span></code> part is only a descriptive name, so it really doesn&#8217;t matter what you call it. If you have a more complex application that runs from multiple directories or multiple servers, you can group Munin stats, and in this case, you actually have to put some thought into this line. But that&#8217;s outside the scope of this article, so you can read up on <a href="http://munin.projects.linpro.no/wiki/munin.conf">customizing Munin Master</a> on your own time if you&#8217;d like.</p>
<p>Now if you haven&#8217;t already, you need to actually create that directory you just told Munin about:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cd /path/to/your/rails/shared/directory<br />
mkdir -p munin<br />
sudo chown munin:munin munin</div></div>
<p><a name="configure-munin-for-passenger-stats"></a></p>
<h3>Configure Munin For Passenger Stats</h3>
<p>And finally, you need to allow the munin user to run the <code class="codecolorer text default"><span class="text">passenger-status</span></code> and <code class="codecolorer text default"><span class="text">passenger-memory-stats</span></code> commands without a password, since they both require sudo powers to run properly.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo visudo</div></div>
<p>And at the bottom of the file add:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">munin   ALL=(ALL) NOPASSWD:/usr/bin/passenger-status, /usr/bin/passenger-memory-stats</div></div>
<p><a name="gotcha"></a></p>
<h3>Gotcha</h3>
<p>At this point, Munin is suppose to start doing it&#8217;s stuff and all is happy in the ruby-munin marriage. For me, however, this was not the case. After combing the Munin error logs and digging through the Munin documentation and code more than I care to admit, I realized that Munin-node needs to preface the passenger stat commands with <code class="codecolorer text default"><span class="text">ruby</span></code>. So, here&#8217;s how we fix that:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo nano /etc/munin/plugin-conf.d/munin-node</div></div>
<p>And then add this to the bottom of that file:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[passenger_*]<br />
user munin<br />
command ruby %c</div></div>
<h3>Final Munin Restart</h3>
<p>Now we&#8217;ll give Munin-node one more restart and we&#8217;re in business.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo /etc/init.d/munin-node restart</div></div>
<p>After waiting a few minutes, you should start to see .html files and graphs and whatnot in the <code class="codecolorer text default"><span class="text">/path/to/your/rails/shared/directory/munin</span></code> directory. If not, you want to check out the Munin-node error logs to see what&#8217;s going on. On Ubuntu, this is found at <code class="codecolorer text default"><span class="text">/var/log/munin/munin-node.log</span></code>.</p>
<h3>View Munin From Your Browser</h3>
<p>So now, Munin is running, but what good is it if you can&#8217;t view the pretty output? Typically the best way to do this is through a sub-domain. If you have yoursite.com, let&#8217;s set up Munin to be viewable from munin.yoursite.com. All you need to do is point to the <code class="codecolorer text default"><span class="text">/path/to/your/rails/shared/directory/munin</span></code> directory for munin.yoursite.com in your site&#8217;s server conf file. For example, if you&#8217;re on Apache, you&#8217;d just do this in your <code class="codecolorer text default"><span class="text">sites-available/yoursite.conf</span></code></p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;VirtualHost *:80&gt;<br />
ServerName munin.yoursite.com<br />
DocumentRoot /path/to/your/rails/shared/directory/munin<br />
&lt;/VirtualHost&gt;</div></div>
<p>And make sure you have the proper A-name record setup for munin.yoursite.com with your NameServers.</p>
<p>Once domain propogation magic happens, you should now be able to see this when you navigate to munin.yoursite.com</p>
<div id="attachment_75" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfajango.com/blog/wp-content/uploads/2010/02/Picture-12.png"><img class="size-medium wp-image-75" title="Munin main page" src="http://www.alfajango.com/blog/wp-content/uploads/2010/02/Picture-12-300x75.png" alt="" width="300" height="75" /></a><p class="wp-caption-text">Munin main page</p></div>
<p>The Passenger stats will be in the &#8220;App&#8221; section.</p>
<p>Have fun now monitoring your Passenger Rails application with passenger usage trending. Remember to use your newfound power for good.</p>
<h4><em>(irqstats patch)</em></h4>
<p>If you find that the irqstats graph doesn&#8217;t work, you may need to <a href="http://munin.projects.linpro.no/attachment/ticket/598/munin_plugin_irqstats.patch">patch the irqstats plugin</a>. Basically you just need to <code class="codecolorer text default"><span class="text">sudo nano /etc/munin/plugins/irqstats</span></code> and change</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">if ($irq =~ /^\d+$/) {</div></div>
<p>to</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># numeric values or something like NMI/RES/CAL are accepted<br />
if (($irq =~ /^\d+$/) || ($irq =~/^[A-Z]{3}$/)) {</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.alfajango.com/blog/how-to-monitor-your-railspassenger-app-with-munin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google One-letter Suggestions</title>
		<link>http://www.alfajango.com/blog/google-one-letter-suggestions/</link>
		<comments>http://www.alfajango.com/blog/google-one-letter-suggestions/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 20:57:55 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.alfajango.com/blog/?p=38</guid>
		<description><![CDATA[The other day, I went to search for something on Google and noticed some interesting results from Google's suggest feature after typing just one letter. Wow, I thought. How presumptuous of Google to think it can guess my will and desires from one letter. Of course that then led to curiosity, and hence this post. What terms manage to garner the top 10 spots for each letter of the English alphabet? So without further ado, the top 10 terms for each letter on Google's suggest feature (along with some of my comments).]]></description>
			<content:encoded><![CDATA[<div id="attachment_45" class="wp-caption aligncenter" style="width: 531px"><a href="http://www.alfajango.com/blog/wp-content/uploads/2009/12/Picture-3.png"><img class="size-full wp-image-45 " title="Google &quot;a&quot; suggestions" src="http://www.alfajango.com/blog/wp-content/uploads/2009/12/Picture-3.png" alt="" width="521" height="414" /></a><p class="wp-caption-text">*the post below was originally written Dec 9, 2009, while this screenshot was captured on Dec 30, when the post was *published, which explains the slight discrepency... I didn&#39;t feel like going back and rewriting it</p></div>
<p><strong>The Point</strong></p>
<p>The other day, I went to search for something on Google and noticed some interesting results from Google&#8217;s suggest feature after typing just one letter. Wow, I thought. How presumptuous of Google to think it can guess my will and desires from one letter. Of course that then led to curiosity, and hence this post. What terms manage to garner the top 10 spots for each letter of the English alphabet? So without further ado, the top 10 terms for each letter on Google&#8217;s suggest feature (along with some of my comments).</p>
<p><strong>Interesting Statistics</strong></p>
<p><strong><img class="alignnone" title="Top Suggestions Categories" src="http://chart.apis.google.com/chart?cht=p3&amp;chs=650x300&amp;chf=bg,s,ffffff&amp;chd=t:75,16.9,2.3,3.5,2.3&amp;chco=006600&amp;chm=N*f0*,000000,0,-1,11&amp;chl=Brand names|Generic search terms|TV shows / movies|Famous people / bands|Search engine names&amp;chtt=Top+Suggestions Categories&amp;chts=000000,16" alt="" width="650" height="300" /></strong></p>
<p>Brand names: 195 (75%)</p>
<p>Generic Search Terms: 44 (16.9%)</p>
<p>TV Shows / Movies: 6 (2.3%)</p>
<p>Famous People / Bands: 9 (3.5%)</p>
<p>Search Engines: 6 (2.3%)</p>
<div><strong>Award of Awesomeness:</strong></div>
<div><strong><br />
</strong></div>
<div><span style="font-weight: normal;">It&#8217;s a tie between Facebook and Yahoo, both for earning top spots in &#8220;w&#8221; for &#8220;www.facebook.com&#8221; and &#8220;www.yahoo.com&#8221; of all things. My hat is off to you both.</span></div>
<div><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;"><strong><span style="font-weight: normal;"><strong>Multiple Entries</strong></span></strong></p>
<p><strong><span style="font-weight: normal;"><strong> </strong></span></strong></p>
<p><strong> </strong><strong> </strong></p>
<p><strong> </strong><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<div id="_mcePaste"><span style="font-weight: normal;">at&amp;t: 2</span></div>
<div><span style="font-weight: normal;"><br />
</span></div>
<div id="_mcePaste"><span style="font-weight: normal;">bank of america: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">comcast: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">ebay: 3</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">facebook: 3</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">google (including gmail): 6</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">itunes: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">ikea: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">mapquest: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">myspace: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">quotes: 4</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">ups: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">verizon: 3</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">virgin: 2</span></div>
<div id="_mcePaste"><span style="font-weight: normal;"><br />
</span></div>
<div><span style="font-weight: normal;">yahoo: 8</span></div>
<div>
<p><span style="font-weight: normal;">zune: 2</span></p>
<div style="display: inline !important;"><span style="font-weight: normal;">The winner for multiple entries is Yahoo, followed by Google (thought this is no doubt helped by the fact that most of Google&#8217;s competing services are directly linked to from Google&#8217;s home screen and thus don&#8217;t need to be searched for&#8230; not to mention the fact that there is less competition for the letter &#8220;y&#8221;).</span></div>
</div>
<p></span></div>
<div><span style="font-weight: normal;"><span id="more-38"></span><br />
</span></div>
<hr /><strong>a</strong></p>
<p>amazon</p>
<p>aol</p>
<p>american airlines</p>
<p>addicting games</p>
<p>ask.com<br />
<em>*interesting that one of the top results in the Google search engine is another search engine </em></p>
<p>at&amp;t<br />
<em>*people actually type the ampersand into the search box </em></p>
<p>at&amp;t wireless</p>
<p>autotrader</p>
<p>apple<br />
<em>*Apple makes it difficult for people who want to find information about fruit </em></p>
<p>american airlines</p>
<p><strong>b</strong></p>
<p>bank of america</p>
<p>best buy</p>
<p>bed bath and beyond</p>
<p>bank of america online banking</p>
<p>barnes and noble</p>
<p>bing<br />
<em>*another search engine </em></p>
<p>blockbuster</p>
<p>baby names<br />
<em>*notice that the vast majority of suggested terms are brand names&#8230; this is not </em></p>
<p>burlington coat factory</p>
<p>borders</p>
<p><strong>c</strong></p>
<p>craigslist</p>
<p>cnn</p>
<p>comcast.net</p>
<p>costco</p>
<p>chase</p>
<p>club penguin</p>
<p>capital one</p>
<p>comcast</p>
<p>continental airlines</p>
<p>cartoon network</p>
<p><strong>d</strong></p>
<p>dictionary.com</p>
<p>dictionary<br />
<em>*function people can search&#8230; like dictionary “idiosyncratic” where google has a dictionary function</em></p>
<p>disney channel</p>
<p>delta airlines</p>
<p>direct tv</p>
<p>dell</p>
<p>dillards</p>
<p>dominos<br />
<em> *another example of a proper noun making it difficult to search for a common noun&#8230; seriously, I want to know more about how to play</em></p>
<p>dancing with the stars<br />
<em>*this is one popular show</em></p>
<p>daylight savings 2009</p>
<p><strong>e</strong></p>
<p>ebay</p>
<p>espn</p>
<p>expedia</p>
<p>ebay.com</p>
<p>express</p>
<p>ebay motors</p>
<p>english to spanish translation</p>
<p>evite</p>
<p>enterprise</p>
<p>erin andrews</p>
<p><strong>f</strong></p>
<p>facebook</p>
<p>facebook login</p>
<p>fox news</p>
<p>food network</p>
<p>firefox</p>
<p>fandango</p>
<p>forever 21</p>
<p>fedex</p>
<p>free online games</p>
<p>fedex tracking</p>
<p><strong>g</strong></p>
<p>gmail</p>
<p>google maps</p>
<p>google earth</p>
<p>google.com<br />
<em>*damn kids trying to break the internet!</em></p>
<p>games</p>
<p>gamestop</p>
<p>glee</p>
<p>google translate</p>
<p>google wave</p>
<p>geico</p>
<p><strong>h</strong></p>
<p>hotmail</p>
<p>hulu</p>
<p>home depot</p>
<p>halloween costumes</p>
<p>h1n1 symptoms</p>
<p>hollister</p>
<p>horoscope</p>
<p>hobby lobby</p>
<p>hotels.com</p>
<p>hp</p>
<p><strong>i</strong></p>
<p>imdb</p>
<p>ikea</p>
<p>itunes</p>
<p>inspirational quotes</p>
<p>itunes download</p>
<p>irs</p>
<p>iphone</p>
<p>ikea usa</p>
<p>isohunt</p>
<p>inglorious bastards</p>
<p><strong>j</strong></p>
<p>jet blue</p>
<p>jcpenney</p>
<p>justin tv</p>
<p>joann fabrics</p>
<p>justin bieber</p>
<p>jobs</p>
<p>jokes</p>
<p>java</p>
<p>jimmy johns</p>
<p>jcrew</p>
<p><strong>k</strong></p>
<p>kohls</p>
<p>kelly blue book</p>
<p>kmart</p>
<p>kayak</p>
<p>kinkos</p>
<p>kings of leon</p>
<p>kroger</p>
<p>kanye west</p>
<p>kim kardashian</p>
<p>kaiser permanente</p>
<p><strong>l</strong></p>
<p>lowes</p>
<p>lyrics</p>
<p>limewire</p>
<p>lady gaga</p>
<p>love quotes</p>
<p>linkedin</p>
<p>lands end</p>
<p>louis vuitton</p>
<p>ll bean lego</p>
<p><strong>m</strong></p>
<p>myspace</p>
<p>mapquest</p>
<p>msn</p>
<p>maps<br />
<em>*yeah this could conceivably be counted as a brand name (someone on Google searching for maps is probably looking for Google maps), but we&#8217;re going to give it the benefit of the doubt as a generic term</em></p>
<p>mapquest driving directions</p>
<p>macys</p>
<p>mega millions</p>
<p>mortgage calculator</p>
<p>myspace layouts</p>
<p>miniclip</p>
<p><strong>n</strong></p>
<p>netflix</p>
<p>nfl.com</p>
<p>new york times</p>
<p>nordstrom</p>
<p>northwest airlines</p>
<p>nbc</p>
<p>nickelodeon</p>
<p>new moon</p>
<p>nick jr</p>
<p>news</p>
<p><strong>o</strong></p>
<p>office depot</p>
<p>old navy</p>
<p>orbitz</p>
<p>overstock</p>
<p>office max</p>
<p>oprah</p>
<p>online games</p>
<p>olive garden</p>
<p>owl city</p>
<p>open office</p>
<p><strong>p</strong></p>
<p>pandora</p>
<p>party city</p>
<p>photobucket</p>
<p>pizza hut<br />
<em>*who takes the top spot for the coveted pizza spot for &#8220;p&#8221;</em></p>
<p>papa johns</p>
<p>paypal</p>
<p>poptropica</p>
<p>powerball</p>
<p>pirate bay</p>
<p>people of walmart</p>
<p><strong>q</strong></p>
<p>quotes<br />
<em>*people love quotes</em></p>
<p>qvc</p>
<p>quotes about life</p>
<p>quest diagnostics</p>
<p>quicktime</p>
<p>quiznos</p>
<p>quotes about love</p>
<p>qwest</p>
<p>quizzes</p>
<p>quotes and sayings</p>
<p><strong>r</strong></p>
<p>realtor.com</p>
<p>reverse phone lookup</p>
<p>radio shack</p>
<p>redbox</p>
<p>runescape</p>
<p>recipes</p>
<p>rei</p>
<p>restoration hardware</p>
<p>rotten tomatoes</p>
<p>rate my professor</p>
<p><strong>s</strong></p>
<p>southwest airlines</p>
<p>swine flu symptoms</p>
<p>sears</p>
<p>spanish translation</p>
<p>skype</p>
<p>staples</p>
<p>sprint</p>
<p>sams club</p>
<p>sports authority</p>
<p>sparknotes</p>
<p><strong>t</strong></p>
<p>target</p>
<p>twitter</p>
<p>thesaurus</p>
<p>travelocity</p>
<p>translator</p>
<p>ticketmaster</p>
<p>tmobile</p>
<p>tv guide</p>
<p>tmz</p>
<p>toys r us</p>
<p><strong>u</strong></p>
<p>usps</p>
<p>ups</p>
<p>united airlines</p>
<p>ups tracking</p>
<p>us airways</p>
<p>urban dictionary</p>
<p>ufc</p>
<p>urban outfitters</p>
<p>usaa</p>
<p>us bank</p>
<p><strong>v</strong></p>
<p>verizon wireless</p>
<p>verizon</p>
<p>victoria secret</p>
<p>vampire diaries</p>
<p>vlc</p>
<p>virgin america</p>
<p>vh1</p>
<p>verizon.net</p>
<p>virgin mobile</p>
<p>value city furniture</p>
<p><strong>w</strong></p>
<p>walmart</p>
<p>weather</p>
<p>white pages</p>
<p>wikipedia</p>
<p>www.facebook.com</p>
<p>web md</p>
<p>www.yahoo.com</p>
<p>webkinz</p>
<p>wells fargo</p>
<p>walgreens</p>
<p><strong>x</strong></p>
<p>xbox 360</p>
<p>xm radio</p>
<p>xbox live</p>
<p>xkcd</p>
<p>xanax</p>
<p>xcel energy</p>
<p>xm radio online</p>
<p>xbox 360 games</p>
<p>xbox 720</p>
<p>xbmc</p>
<p><strong>y</strong></p>
<p>youtube</p>
<p>yahoo</p>
<p>yahoo mail</p>
<p>yellow pages</p>
<p>yahoo.com mail</p>
<p>yahoo answers</p>
<p>yahoo maps</p>
<p>youtube music</p>
<p>yahoo finance</p>
<p>yahoo fantasy football</p>
<p><strong>z</strong></p>
<p>zillow</p>
<p>zappos</p>
<p>zip codes</p>
<p>zip codes by city</p>
<p>zombieland</p>
<p>zodiac signs</p>
<p>zune</p>
<p>zune hd</p>
<p>zero punctuation</p>
<p>zabasearch</p>
<div id="_mcePaste"><strong><br />
</strong></div>
]]></content:encoded>
			<wfw:commentRss>http://www.alfajango.com/blog/google-one-letter-suggestions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cool Libraries for Ruby</title>
		<link>http://www.alfajango.com/blog/cool-libraries-for-ruby/</link>
		<comments>http://www.alfajango.com/blog/cool-libraries-for-ruby/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 16:09:25 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[open-source]]></category>

		<guid isPermaLink="false">http://www.alfajango.com/blog/?p=34</guid>
		<description><![CDATA[I was just thinking about how often I come across cool projects and libraries people are developing for Ruby. We all know you can create cool web applications Ruby on Rails, but what about all of the other cool things you can do with Ruby. So, I decided to put together a short list with summaries to help me remember why these projects are in my bookmarks.]]></description>
			<content:encoded><![CDATA[<p>I was just thinking about how often I come across cool projects and libraries people are developing for Ruby. We all know you can create cool web applications Ruby on Rails, but what about all of the other cool things you can do with Ruby. So, I decided to put together a short list with summaries to help me remember why these projects are in my bookmarks. In no particular order:</p>
<p><strong>Nanoc</strong></p>
<p><a href="http://nanoc.stoneship.org/">Nanoc&#8217;s website</a> describes it as &#8220;a tool that runs on your local computer and &#8216;compiles&#8217; documents written in HTML, Markdown, Textile, Haml, etc. into a static web site, ready for uploading to any web server.&#8221; Basically, it takes your dynamic Ruby code and turns it into static HTML which you can then upload to your server, meaning you don&#8217;t necessarily need Ruby installed on your server. Of course, this depends on what your site actually needs to do. But I could see this as a perfect fit for a Blog, for which you write posts on your local machine and deploy. Of course you&#8217;d need to implement comments with a third-party javascript widget like Disqus, but that&#8217;s just one example.</p>
<p><strong>Mongoid</strong></p>
<p><a href="http://mongoid.org/">Mongoid</a> is a Ruby ODM framework for mapping your Ruby application to use MongoDB for object storage. If you haven&#8217;t checked out <a href="http://www.mongodb.org/">MongoDB</a> as an alternative to using MySQL for your storage needs, it&#8217;s worth a look. You may not even realize you have different needs until you discover there&#8217;s a database out there to fit those needs. For another cool Database-Ruby integration alternative, see <a href="http://jamesgolick.com/2009/12/16/introducing-friendly-nosql-with-mysql-in-ruby.html">Friendly</a>, a gem that makes MySQL look like a document-store to your application.</p>
<p><strong>RAD</strong></p>
<p><a href="http://rad.rubyforge.org/">RAD</a> stands for Ruby Arduino Development, and it is a library that allows you to write Arduino programs in Ruby. If you haven&#8217;t checked it out, <a href="http://www.arduino.cc/">Arduino</a> is an open-source electronics prototyping platform. You can do lots of cool stuff with it. And with RAD, if you&#8217;re a Ruby developer, it&#8217;s now easier than ever to get started.</p>
<p><strong>Racksh</strong></p>
<p><a href="http://github.com/sickill/racksh">Racksh</a> is a console for any Ruby-based application. According to the site, &#8220;It&#8217;s like Rails&#8217; <em>script/console</em> or Merb&#8217;s <em>merb -i</em>, but for any app built on Rack. You can use it to load application environment for Rails, Merb, Sinatra, Camping, Ramaze or your own framework provided there is <em>config.ru</em> file in app&#8217;s root directory.&#8221; So if you&#8217;re building Ruby stuff and hate having to go to your browser (or compiling as the case may be) to test out functionality, this should make your life a whole lot easier.</p>
<p><strong>Miso</strong></p>
<p><a href="http://github.com/Fingertips/Miso">Miso</a> is a unified API for simple image manipulation, such as cropping and resizing. It gives your code a common API that plugs into image software libraries like Core Image for Macs and ImageMagick. No more worrying about the specificity of your environment when manipulating images in your application.</p>
<p><strong>Ruby Version Manager</strong></p>
<p><a href="http://rvm.beginrescueend.com/">RVM</a> allows you to install and use multiple versions of Ruby on your machine. RVM came highly recommended from a friend, and it sure delivers. Now you can upgrade without the irreversibility of times past. Great for those of us who have a hard time with commitment <img src='http://www.alfajango.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>Others</strong></p>
<p>Do you have any other cool Ruby projects you think should have been included? Let me know! Maybe we can make this post an awesome new series.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfajango.com/blog/cool-libraries-for-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If You&#8217;re Nervous About Quitting Your Boring Job, You&#8217;re Sane</title>
		<link>http://www.alfajango.com/blog/if-youre-nervous-about-quitting-your-boring-job-youre-sane/</link>
		<comments>http://www.alfajango.com/blog/if-youre-nervous-about-quitting-your-boring-job-youre-sane/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 02:36:36 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[Entrepreneurship]]></category>
		<category><![CDATA[planning]]></category>
		<category><![CDATA[quitting]]></category>

		<guid isPermaLink="false">http://www.alfajango.com/blog/?p=30</guid>
		<description><![CDATA[I recently stumbled upon an article called, "If You're Nervous About Quitting Your Boring Job, Don't Do It"

As you can tell by the title of my post, I disagree. Let's put aside the fact that I would not come to the conclusion that Lisa (the case study for the above post) should not have quit her job based purely on the fact that she failed the first time out. That's completely normal, and I'd be excited to see what Lisa learned and how she applies it to her next endeavor. No, even more than that, I disagree with sentiment of the post.]]></description>
			<content:encoded><![CDATA[<div>
<p>I recently stumbled upon an article called, &#8220;<a href="http://calnewport.com/blog/2009/12/26/if-youre-nervous-about-quitting-your-boring-job-dont-do-it/trackback/">If You&#8217;re Nervous About Quitting Your Boring Job, Don&#8217;t Do It</a>&#8221;</p>
<p>As you can tell by the title of my post, I disagree. Let&#8217;s put aside the fact that I would not come to the conclusion that Lisa (the case study for the above post) should not have quit her job based purely on the fact that she failed the first time out. That&#8217;s completely normal, and I&#8217;d be excited to see what Lisa learned and how she applies it to her next endeavor. No, even more than that, I disagree with sentiment of the post.</p>
<p>Who knows what the future will bring, but I think I fall into the category of people &#8220;who have built up rare and highly desirable skills&#8221; and have accomplished a lot since I left my full-time engineering job to pursue my entrepreneurial passions.</p>
<p>My point here isn&#8217;t to brag, but simply to say that when I decided to pursue my passion and the desireable lifestyle of entrepreneurship, quitting my full-time job was one of the most nerve-racking and toughest decisions I&#8217;ve ever made, full of doubt and second-guessing. <em><strong>If you are having doubts or second thoughts about quitting your job, then congratulations, you are a pragmatic, rational, sane human-being.</strong></em></p>
<p>That said, I did a lot of option-weighing and analysis of my situation, and I don&#8217;t think quitting your job is for everyone. I didn&#8217;t have a family to support, I already bought a car and had a place to live (topic for another post: &#8220;what entrepreneurship does to your credit&#8221;), and I had a business that was on the verge of profitability at the time I quit. I would not advise anyone to quit without seriously thinking this decision through. In fact, if at all possible, check out these <a title="alternatives to quitting your job" href="http://money.cnn.com/magazines/business2/business2_archive/2006/05/01/8375910/index.htm">alternatives to quitting your job outright</a> to start your own company.</p>
<p>I&#8217;m not trying to pick on the guys over at <a href="http://calnewport.com/blog">Study Hacks</a>, but I think that it is very easy to say, &#8220;if I wanted to start my own company (which I don’t), I wouldn’t feel nervous,&#8221; when you have no real intention of quitting your job or starting your own company.</p>
<p>For instance, I can tell you that if I won the lottery, I would give all of the money to charity, because I don&#8217;t need it and I wouldn&#8217;t want it to come between me and my friends or family. Also, if I were ever confronted by a gun-wielding Agent Smith, I would calmly flex my space-time muscles, look square in his bright-green, scrolling-character soul, and extract the light from inside of his bursting flesh. And I can make both claims with equal sincerity, because I have no expectations or intentions of either ever happening.</p>
<p>My point is, don&#8217;t quit your job because I tell you to. And don&#8217;t <em>not </em>quit your job because he tells you not to. Just remember, the only certain path to failure is to not try.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.alfajango.com/blog/if-youre-nervous-about-quitting-your-boring-job-youre-sane/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
