<?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>stew (@) rtmatheson.com</title>
	<atom:link href="http://rtmatheson.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rtmatheson.com</link>
	<description>My name is Stewart Matheson. I work with code, servers and anything else that makes the web work.  I am also avaiable for hire to help you with any of your projects.</description>
	<lastBuildDate>Mon, 12 Dec 2011 02:02:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Ruby Acronyms</title>
		<link>http://rtmatheson.com/2011/12/ruby-acronyms/</link>
		<comments>http://rtmatheson.com/2011/12/ruby-acronyms/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 02:02:16 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rambling]]></category>
		<category><![CDATA[acronym]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[core_ext]]></category>
		<category><![CDATA[faker]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=383</guid>
		<description><![CDATA[I love extending the ruby core! Makes code so neat and works so well with rails initializers. This method allows you to fetch the Acronym of an array of strings. It would be kinda cool to write something that works the other way taking a single string. Make using Faker&#8230; but I can&#8217;t think of [...]]]></description>
			<content:encoded><![CDATA[<p>I love extending the ruby core! Makes code so neat and works so well with rails initializers. This method allows you to fetch the Acronym of an array of strings. It would be kinda cool to write something that works the other way taking a single string. Make using <a href="http://rubygems.org/gems/faker" title="http://rubygems.org/gems/faker">Faker</a>&#8230; but I can&#8217;t think of any use. Then again IBM could not understand why people needed computers in their home so who knows. Anyway&#8230; it&#8217;s code time.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">Array</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> acronym
    result = <span style="color:#996600;">&quot;&quot;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>item<span style="color:#006600; font-weight:bold;">|</span>
      result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> item<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    result
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/12/ruby-acronyms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rounding time to the closest hour in Ruby</title>
		<link>http://rtmatheson.com/2011/12/rounding-time-to-the-closest-hour-in-ruby/</link>
		<comments>http://rtmatheson.com/2011/12/rounding-time-to-the-closest-hour-in-ruby/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 00:10:08 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rambling]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[core_ext]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[hour]]></category>
		<category><![CDATA[round]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[seconds]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[time.new]]></category>
		<category><![CDATA[time.now]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=377</guid>
		<description><![CDATA[Ahhh&#8230; its one of the moments in life that make you so happy your a ruby developer. class Time def round&#40;seconds = 60&#41; Time.at&#40;&#40;self.to_f / seconds&#41;.round * seconds&#41; end &#160; def floor&#40;seconds = 60&#41; Time.at&#40;&#40;self.to_f / seconds&#41;.floor * seconds&#41; end &#160; def round_to_closest_hour if self.min &#62; 30 self.round&#40;1.hour&#41; else self.floor&#40;1.hour&#41; end end end Source: http://stackoverflow.com/questions/449271/how-to-round-a-time-down-to-the-nearest-15-minutes-in-ruby]]></description>
			<content:encoded><![CDATA[<p>Ahhh&#8230; its one of the moments in life that make you so happy your a ruby developer.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> round<span style="color:#006600; font-weight:bold;">&#40;</span>seconds = <span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">to_f</span> <span style="color:#006600; font-weight:bold;">/</span> seconds<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">round</span> <span style="color:#006600; font-weight:bold;">*</span> seconds<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> floor<span style="color:#006600; font-weight:bold;">&#40;</span>seconds = <span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">to_f</span> <span style="color:#006600; font-weight:bold;">/</span> seconds<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">floor</span> <span style="color:#006600; font-weight:bold;">*</span> seconds<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> round_to_closest_hour
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">min</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">30</span>
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">round</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>.<span style="color:#9900CC;">hour</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">floor</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>.<span style="color:#9900CC;">hour</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Source:<br />
<a href="http://stackoverflow.com/questions/449271/how-to-round-a-time-down-to-the-nearest-15-minutes-in-ruby">http://stackoverflow.com/questions/449271/how-to-round-a-time-down-to-the-nearest-15-minutes-in-ruby</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/12/rounding-time-to-the-closest-hour-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting dates form Javascript to Rails</title>
		<link>http://rtmatheson.com/2011/11/converting-dates-form-javascript-to-rails/</link>
		<comments>http://rtmatheson.com/2011/11/converting-dates-form-javascript-to-rails/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 11:55:37 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=374</guid>
		<description><![CDATA[Time based web applications written in rails and javascript will sooner or later have to think about the following object life cycle. 1. Javascript Object 2. Request Params 3. Rails object 4. MySQL row While rails has the last two covered and jQuery has mostly the second covered how do we get our data in [...]]]></description>
			<content:encoded><![CDATA[<p>Time based web applications written in rails and javascript will sooner or later have to think about the following object life cycle.</p>
<p>1. Javascript Object<br />
2. Request Params<br />
3. Rails object<br />
4. MySQL row</p>
<p>While rails has the last two covered and jQuery has mostly the second covered how do we get our data in to a form where this flow will be smooth. Javascript date objects don&#8217;t directly fit so I extended the date prototype to allow for this. This porototype mirrors the rails date time form helper and creates the correct data with the keys rails would expect to have.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  Date.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">toRails</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> dateParams<span style="color: #339933;">;</span>
    dateParams <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    dateParams<span style="color: #009900;">&#91;</span><span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;(1i)&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    dateParams<span style="color: #009900;">&#91;</span><span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;(2i)&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    dateParams<span style="color: #009900;">&#91;</span><span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;(3i)&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    dateParams<span style="color: #009900;">&#91;</span><span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;(4i)&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getHours</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    dateParams<span style="color: #009900;">&#91;</span><span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;(5i)&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getMinutes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> dateParams<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">//Use</span>
&nbsp;
  d <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  date <span style="color: #339933;">=</span> d.<span style="color: #660066;">toRails</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">//now we can put this object on the server</span>
  $.<span style="color: #660066;">ajax</span>
      ...
      <span style="color: #660066;">data</span> <span style="color: #339933;">:</span> date
      ...</pre></div></div>

<p>As far as rails is concerned we might as well be using the datetime helper.</p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/11/converting-dates-form-javascript-to-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Readline requirements with Cent OS 5 and RVM</title>
		<link>http://rtmatheson.com/2011/11/readline-requirements-with-cent-os-5-and-rvm/</link>
		<comments>http://rtmatheson.com/2011/11/readline-requirements-with-cent-os-5-and-rvm/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 04:38:26 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[1.9.2]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[ncurses]]></category>
		<category><![CDATA[ncurses-devel]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rvm]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=371</guid>
		<description><![CDATA[It seems that &#8220;rvm requirements&#8221; omits to mention the install of ncurses-devel when setting up for ruby installations with readline on Centos 5. Although you can install the readline package and and ruby its self with out getting an error there is a issue with the shared object. You will see this issue the first [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that &#8220;rvm requirements&#8221; omits to mention the install of ncurses-devel when setting up for ruby installations with readline on Centos 5. Although you can install the readline package and and ruby its self with out getting an error there is a issue with the shared object. You will see this issue the first time you run irb. Ruby will complain that it can&#8217;t load readline. This took me the best part of two hours to figure out however it ended up being a missing package. Make sure you&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> yum <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ncurses-devel</pre></div></div>

<p>before you install ruby. Then you can install ruby compiling it with readline. HTH.</p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/11/readline-requirements-with-cent-os-5-and-rvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Want to learn Javascript?</title>
		<link>http://rtmatheson.com/2011/10/want-to-learn-javascript/</link>
		<comments>http://rtmatheson.com/2011/10/want-to-learn-javascript/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 04:21:16 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=365</guid>
		<description><![CDATA[I have set-up a tutorial site for JavaScript with plans to add other languages. Its a getting started guide for any new programmers looking to start out with JavaScript development. If I get some positive feedback I will add more tutorials. To check them out head to Stewtorials]]></description>
			<content:encoded><![CDATA[<p>I have set-up a tutorial site for JavaScript with plans to add other languages. Its a getting started guide for any new programmers looking to start out with JavaScript development. If I get some positive feedback I will add more tutorials. To check them out head to <a href="http://stewtorials.rtmatheson.com" title="Stewtorials" target="_blank">Stewtorials</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/10/want-to-learn-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Ruby 1.9.2 on Mac os x 10.7 (Lion)</title>
		<link>http://rtmatheson.com/2011/09/installing-ruby-1-9-2-on-mac-os-x-10-7-lion/</link>
		<comments>http://rtmatheson.com/2011/09/installing-ruby-1-9-2-on-mac-os-x-10-7-lion/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 02:30:01 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[1.9.2]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=355</guid>
		<description><![CDATA[The other day I updated to Lion from Leopard. I know&#8230; I was keeping it real with an old OS but it got to the point where new apps where not working with leopard. While everything with the operating system update was fine there was a lot of time spent getting my ruby on rails [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I updated to Lion from Leopard. I know&#8230; I was keeping it real with an old OS but it got to the point where new apps where not working with leopard. While everything with the operating system update was fine there was a lot of time spent getting my ruby on rails install back up and running. One thing I did not understand is that I had made the leap to a 64bit system. This means a lot of recompiling as I hate package managers for osx.</p>
<h3>Reinstalling MySQL</h3>
<p>First things first you will need to recompile MySQL from source. I am using 5.1. It seems to be the version of mysql that everyone is using. Some people might stick with sqlite however as I would never use it in production I would also never use it in development so I stick with MySQL. These commands are taken from  Dan Benjamin&#8217;s hivelogic blog. Great work Dan! The link to the article is below in the sources section so if you run in to trouble check the article out.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src
curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>mysql.he.net<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>MySQL-<span style="color: #000000;">5.1</span><span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.33.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf mysql-5.1.33.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> mysql-5.1.33
<span style="color: #007800;">CC</span>=<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #007800;">CFLAGS</span>=<span style="color: #ff0000;">&quot;-O3 -fno-omit-frame-pointer&quot;</span> <span style="color: #007800;">CXX</span>=<span style="color: #c20cb9; font-weight: bold;">gcc</span> 
<span style="color: #007800;">CXXFLAGS</span>=<span style="color: #ff0000;">&quot;-O3 -fno-omit-frame-pointer -felide-constructors 
-fno-exceptions -fno-rtti&quot;</span> 
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql 
<span style="color: #660033;">--with-extra-charsets</span>=complex <span style="color: #660033;">--enable-thread-safe-client</span> 
<span style="color: #660033;">--enable-local-infile</span> <span style="color: #660033;">--enable-shared</span> <span style="color: #660033;">--with-plugins</span>=innobase
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<h3>Removing the old ruby</h3>
<p>After these steps you should have the database recompiled for the new architecture of Lion. Great lets move on. Its worth noting that I am using RVM. The first thing I needed to do after the update is remove my existing version of ruby. This is the 32bit version and will not work.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm remove 1.9.2</pre></div></div>

<h3>Reinstalling dependencies</h3>
<p>With that done we need to reinstall ruby 1.9.2. We can use RVM to do this however there are a few things we need to update before this. Lets start with libxml. Download the latest version and compile it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf libxml2-2.7.3.tar.gz 
<span style="color: #7a0874; font-weight: bold;">cd</span> libxml2-2.7.3
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-python</span>=<span style="color: #000000; font-weight: bold;">/</span>System<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>Python.framework<span style="color: #000000; font-weight: bold;">/</span>Versions<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.3</span><span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>After this we need to install libxlst.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src
curl <span style="color: #660033;">-O</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>xmlsoft.org<span style="color: #000000; font-weight: bold;">/</span>libxslt<span style="color: #000000; font-weight: bold;">/</span>libxslt-1.1.20.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> libxslt-1.1.20
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>All done now lets move on to readline.</p>
<h3>Installing Readline</h3>
<p>At the time of this writing I was unable to install readline via rvm packages. There is a patch that fixes this however I am not sure its in head yet. The catch here is that in the current state when you install readline it will say that the install has been successful. This is not true. There is <a href="http://groups.google.com/group/rubyversionmanager/browse_thread/thread/4130f40a654242a6?hl=en">a topic on the RVM mailing list</a> about this. For the moment I was able to get around this by compiling and installing readline myself. I have no doubt that this will be fixed soon but for the moment you will need to take this step. This last step is done assuming that you have readline 5.2 downloaded and untared. If you need help then I can add the download link.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MACOSX_DEPLOYMENT_TARGET</span>=<span style="color: #000000;">10.7</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64 -g -Os -pipe -no-cpp-precomp&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CCFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64 -g -Os -pipe&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CXXFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64 -g -Os -pipe&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LDFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64 -bind_at_load&quot;</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> shlib
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/-dynamic/-dynamiclib/'</span> Makefile <span style="color: #000000; font-weight: bold;">&gt;</span> Makefile.good
<span style="color: #c20cb9; font-weight: bold;">mv</span> Makefile.good Makefile
<span style="color: #7a0874; font-weight: bold;">cd</span> ..
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Next lets install zlib and iconv and openssh via RVM.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm pkg <span style="color: #c20cb9; font-weight: bold;">install</span> zlib
rvm pkg <span style="color: #c20cb9; font-weight: bold;">install</span> iconv
rvm pkg <span style="color: #c20cb9; font-weight: bold;">install</span> openssl</pre></div></div>

<h3>Installing Ruby</h3>
<p>Now we can install ruby 1.9.2. This will install the 64 bit version for us.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.9.2-head <span style="color: #660033;">-C</span> --enable-shared,--with-readline-dir=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #660033;">--with-iconv-dir</span>=<span style="color: #007800;">$rvm_path</span><span style="color: #000000; font-weight: bold;">/</span>usr  <span style="color: #660033;">--with-zlib-dir</span>=<span style="color: #007800;">$rvm_path</span><span style="color: #000000; font-weight: bold;">/</span>usr <span style="color: #660033;">--with-openssl-dir</span>=<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>usr,--build=x86_64-apple-darwin10</pre></div></div>

<h3>Finishing Up</h3>
<p>Once you have recompiled ruby you will need to create a new gem set. For me I have a gem set for each one of my projects so it was a matter of creating the gem set again and then running a bundle install.</p>
<h3>Sources</h3>
<p>http://www.markhneedham.com/blog/2010/07/08/installing-ruby-1-9-2-with-rvm-on-snow-leopard/</p>
<p>http://stackoverflow.com/questions/6317980/bundle-rake-error</p>
<p>http://exceptionz.wordpress.com/2010/02/03/how-to-fix-the-iconv-require-error-in-ruby-1-9/</p>
<p>http://groups.google.com/group/rubyversionmanager/browse_thread/thread/4130f40a654242a6?hl=en</p>
<p>http://techdebug.com/blog/2009/01/03/compiling-readline-on-an-osx-105-intel-x86_64</p>
<p>https://rvm.beginrescueend.com/packages/zlib/</p>
<p>http://nokogiri.org/tutorials/installing_nokogiri.html</p>
<p>http://hivelogic.com/articles/installing-mysql-on-mac-os-x/</p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/09/installing-ruby-1-9-2-on-mac-os-x-10-7-lion/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Setting up Nginx to work with Rails, Capistrano and SSL.</title>
		<link>http://rtmatheson.com/2011/07/setting-up-nginx-to-work-with-rails-capistrano-and-ssl/</link>
		<comments>http://rtmatheson.com/2011/07/setting-up-nginx-to-work-with-rails-capistrano-and-ssl/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 12:15:42 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[chown]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rvm]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[sudoers]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[useradd]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=316</guid>
		<description><![CDATA[I need to set up a billing system. I want to run you though how to set up such a system on a server complete with SSL and nginx as its a rails application we are deploying. I will be using a brand new install of Ubuntu however the ideas in this post should work [...]]]></description>
			<content:encoded><![CDATA[<p>I need to set up a billing system. I want to run you though how to set up such a system on a server complete with SSL and nginx as its a rails application we are deploying. I will be using a brand new install of Ubuntu however the ideas in this post should work with any server. First off lets set up our linux box</p>
<h3>Base Linux Setup</h3>
<p>After you log in the first time you want to change your root password.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></div></div>

<p>The system will prompt you to change the root password. Once you have done this then you can create a new user. You should NEVER log in with the root user.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser username</pre></div></div>

<p>This command will prompt you to enter details about the user your creating however you only really need to enter the password. This is the user that we will use from this stage on so we need to add it to sudoers. If the user is not a sudoer then we cant install/compile anything. Nor can we make changes to system settings. Open the sudoers file with your favorite editor and add the following line</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sudoers
<span style="color: #666666; font-style: italic;">## Add this line to the file</span>
username <span style="color: #007800;">ALL</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>ALL<span style="color: #7a0874; font-weight: bold;">&#41;</span>       ALL</pre></div></div>

<p>Where username is the name of the user you have just created. Great now we have done this we have a user account and we don&#8217;t need to worry about our root user any more. Log out and then log back in with the new user. You should be able to run sudo commands.</p>
<h3>SSH</h3>
<p>First lets set up SSH Keys. This allows us to log in to our server with out having to enter a password. This is such a time saver and worth setting up. Any time we are doing a deployment using capistrano we are going to be glad to have our SSH key in place. First off if you don&#8217;t have it create a .ssh folder in your home directory(on your local machine &#8211; not on the server). Windows users&#8230; sorry your on your own here. You might have to read the PuTTY doc.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> .ssh</pre></div></div>

<p>After you have created the .ssh folder cd to it and run&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa</pre></div></div>

<p>This will create two files. One public and one private key. Never give out the private key. The public key can be given to anyone. In this case we are going to put the public key on our server. The public key is called id_rsa.pub.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub username<span style="color: #000000; font-weight: bold;">@</span>serveraddress:</pre></div></div>

<p>You will have to enter your password here. Once we have the key up there log back in to your server. You will still have to enter the password at this stage. You need to move the key file to a file called authorized_keys and set the ownership and permissions correctly on it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> .ssh
<span style="color: #c20cb9; font-weight: bold;">mv</span> id_rsa.pub .ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> username:username .ssh<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> .ssh<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> .ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>Done! Logout and log back in. You should NOT be asked for a password. Once we have our keys set up there is one more thing that I would recommend doing at this stage. Changing the default SSH port. I always like  to use the same port so set it to something that you will remember. Write it down because if you can not remember the port number you may be locked out of your system. To change the port we need to edit the ssh config file. Do so like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>sshd_config</pre></div></div>

<p>The port setting should be on the first line. Chagne it save the file. The settings will not take effect until you restart ssh.  At this point I would recommend you set up IP tables. While I am not going to talk about this in the first revision of this post I intend to add it later down the track when I have more time.</p>
<p>Now restart sshd</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> reload</pre></div></div>

<p>When you login you should use the new port. Remember that ssh keys do not have any port information so you will still need to tell ssh what port we want to use as its no longer set to default.</p>
<h3>Install Ruby</h3>
<p>Once we have logged back in we need to install RVM. Ruby Version Manager is a great application that will help us manage ruby versions and gemsets. We can have many different gemsets and different versions of ruby. This allows us to serve applications from the same server in different ways.</p>
<p>First lets install some dependencies that RVM has.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> git-core curl build-essential <span style="color: #c20cb9; font-weight: bold;">vim</span> libcurl4-openssl-dev</pre></div></div>

<p>Next we run the remote script that will install and setup rvm for us</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">su</span>
user$ <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>curl <span style="color: #660033;">-s</span> https:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>rvm<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>This script will use git to download RVM and install it. Note how we changed to the super user. This is because we want RVM multisite install. This is best for when we are installing RVM on servers.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">type</span> rvm <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-1</span></pre></div></div>

<p>This should output the string &#8220;rvm is a function&#8221;. If so then we are in business and rvm has been installed.</p>
<p>We still have not installed ruby. Ruby its self has a number of dependencies. Lets install them first. The package names may differ from distro to distro so you might want to double check what all of them are. They should work for ubuntu though.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential <span style="color: #c20cb9; font-weight: bold;">bison</span> openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-<span style="color: #000000;">0</span> libsqlite3-dev sqlite3 libxml2-dev libxslt-dev <span style="color: #c20cb9; font-weight: bold;">autoconf</span></pre></div></div>

<p>Currently we only have sqlite. If you want to use mysql run the following line.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server libmysqlclient-dev libmysql-ruby</pre></div></div>

<p>Now lets use RVM to install some packages for ruby.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm pkg <span style="color: #c20cb9; font-weight: bold;">install</span> zlib
rvm pkg <span style="color: #c20cb9; font-weight: bold;">install</span> openssl
rvm pkg <span style="color: #c20cb9; font-weight: bold;">install</span> readline</pre></div></div>

<p>Now we can install ruby 1.9.2</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.9.2 <span style="color: #660033;">--with-zlib-dir</span>=<span style="color: #007800;">$rvm_path</span><span style="color: #000000; font-weight: bold;">/</span>usr <span style="color: #660033;">--with-openssl-dir</span>=<span style="color: #007800;">$rvm_path</span><span style="color: #000000; font-weight: bold;">/</span>usr <span style="color: #660033;">--with-readline-dir</span>=<span style="color: #007800;">$rvm_path</span><span style="color: #000000; font-weight: bold;">/</span>usr</pre></div></div>

<p>Now we need to install bundler and passenger so we need to create a gem set. Gemsets are logical groups of gems. I normally go one gem set per application.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm gemset create application_name</pre></div></div>

<p>Now install bundler. This is how rails will manage the gems it needs.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> bundler</pre></div></div>

<p>OK now we have ruby installed lets install the passenger gem. This makes live so easy as it will configure and compile nginx for us.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger</pre></div></div>

<p>Once we have the gem installed we have access to some VERY helpful commands. passenger-install-nginx-module is the one we are going to run. This will install passenger for us and better yet it will go ahead and compile nginx for us too. All the time checking for any software that nginx might need. Very handy. I will not guide you though this process aside from running the command because the Phusion guys have created an amazing easy to use installer. To start the installer run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvmsudo passenger-install-nginx-module</pre></div></div>

<p>Once we are complete nginx will be installed with passenger and our webserver will be set up. Phusion even include the SSL module for Nginx which is great because we will need to use it for our credit card gateway. Incase you missed it nginx also gives you a configuration snippet. Incase you missed it here it is.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    listen <span style="color: #000000;">80</span>;
    server_name www.yourhost.com;
    root <span style="color: #000000; font-weight: bold;">/</span>somewhere<span style="color: #000000; font-weight: bold;">/</span>public;   <span style="color: #666666; font-style: italic;"># &lt;--- be sure to point to 'public'!                                                       </span>
    passenger_enabled on;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>We will keep this handy as we will need it for our rails application when we set it up. Now we have everything installed we need to get a rails application on our server. I am going to assume you already have an application and that you are ready for deployment.</p>
<h3>Deploying The Application</h3>
<p>We will use capistrano to manage the deployment of the application. Lets log out of our server and go back to our application so we can install the capistrano gem locally. I will assume that your using RVM on your development machine and have not already got cap installed</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> capistrano</pre></div></div>

<p>With the gem installed lets &#8220;capify&#8221; our project. Make sure your in your current project directory and run the following command.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">capify .</pre></div></div>

<p>This should create a couple of files but the one we are interested in is deploy.rb. This file holds all of the details that cap needs to deploy the application to our server. It also gives us a place to write any extra tasks that might need to be performed on our application.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$:.<span style="color:#9900CC;">unshift</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'./lib'</span>, ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'rvm_path'</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;">&#41;</span> 
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rvm/capistrano&quot;</span>                  
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;bundler/capistrano&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:rvm_ruby_string</span>, <span style="color:#996600;">'1.9.2@gemset'</span>
set <span style="color:#ff3333; font-weight:bold;">:rvm_bin_path</span>, <span style="color:#996600;">&quot;/usr/local/rvm/bin&quot;</span></pre></div></div>

<p>The above code tells cap what gem set we want or application to useon the server. It also tells cap that we are working with a single user install of RVM. Cap has a number of other details that need to be set for the deployment to work correctly. These include user names and server addresses. At this stage I like to add some tasks to my cap deploy file. These are&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Create database yaml in shared path&quot;</span> 
  task <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    db_config = <span style="color:#CC00FF; font-weight:bold;">ERB</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>EOF
    base: <span style="color:#006600; font-weight:bold;">&amp;</span>base
      adapter: mysql
      username: username
      password: password
&nbsp;
    development:
      database: <span style="color:#008000; font-style:italic;">#{application}_dev</span>
      <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>base
&nbsp;
    test:
      database: <span style="color:#008000; font-style:italic;">#{application}_test</span>
      <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>base
&nbsp;
    production:
      database: <span style="color:#008000; font-style:italic;">#{application}_production</span>
      <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>base
    EOF
&nbsp;
    run <span style="color:#996600;">&quot;mkdir -p #{shared_path}/config&quot;</span> 
    put db_config.<span style="color:#9900CC;">result</span>, <span style="color:#996600;">&quot;#{shared_path}/config/database.yml&quot;</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Make symlink for database yaml&quot;</span> 
  task <span style="color:#ff3333; font-weight:bold;">:symlink</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml&quot;</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:rvm</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Create correct RVM file&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:create_rvmrc</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;cd #{current_path} &amp;&amp; rvm use 1.9.2@#{application} --rvmrc --create&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
before <span style="color:#996600;">&quot;deploy:setup&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:db</span>
after <span style="color:#996600;">&quot;deploy:update_code&quot;</span>, <span style="color:#996600;">&quot;db:symlink&quot;</span>
after <span style="color:#996600;">&quot;deploy:symlink&quot;</span>, <span style="color:#996600;">&quot;rvm:create_rvmrc&quot;</span></pre></div></div>

<p>The above tasks manage our database configuration and create the correct RVM file. They are very handy as they completely automate the install on the server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cap deploy:setup</pre></div></div>

<p>This will login to the server and create all the folders. This is where our rails application will be set up on our server. Note how we don&#8217;t have to enter a password. SSH keys are great when dealing with cap because entering a password for each deployment gets old quickly.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cap deploy:check</pre></div></div>

<p>Cap will go ahead and make sure your server has correct permissions to deploy your application. It will also check for any needed software such as source control managers. Once this is done and works then we are ready to deploy our application. Next lets deploy our application</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cap deploy</pre></div></div>

<p>This will install the application on the server in the deploy_to path. It will also create a number of symlinks. Its a great way of deploying an application because if something goes wrong it will roll back to the last version. Since this is the first time that we have deployed this does not apply to us. Now lets set up the database.yml file on our server. This is done with the &#8220;db&#8221; cap task.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cap db</pre></div></div>

<p>Run another cap deploy after this and the database file will correctly link to the application. The next thing to do is create a database for the application and a database user.  In the cap task make sure you replace username and password with the user account we are about to set up in mysql. Remember these can be any username and password you like. Just remember that the username and password in the database.yml file need to match what has been created in mysql. To create the user and pass in mysql do the following</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> application_name_production;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">USER</span> <span style="color: #ff0000;">'username'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'password'</span>;
<span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> application_name_production<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'username'</span>@<span style="color: #ff0000;">'localhost'</span>
<span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">OPTION</span>;</pre></div></div>

<h3>Basic overview on SSL</h3>
<p>SSL uses private key authentication to verify that a site is who it claims to be. This is done by matching up keys. Much the same way as installing SSH keys works. To do this we generate our own private key. This is super secret! We do this on our server and it stays on the server. It is a security risk taking it off the server as you will have to transfer it over a network(this is unless you have physical access to your server). With this private key we create a certificate signing request. This CSR is then given to our SSL provider. Based on the CSR your SSL provider will create a certificate and send it back to you. They might do this via email as there is no risk if your certificate is out in the open. This certificate will only match the private key that we have on our server meaning that there is only one server that the certificate will match. Your SSL provider should have information available on how to prepare the certificate for use with Nginx as most people will most likely be running Apache(poor fools). One you have th crt file ready to go we point Nginx at that file and the private key we generated. The server will match the two up and users will be safe sending their credit card details via https.</p>
<h3>Configuring Nginx with SSL</h3>
<p>Okay so we have everything installed. We have our application deployed. We have our application settings correct (we think&#8230; time will tell). The next thing to do is configure nginx to pick up on our rails application and work over SSL. Remember the code snippet we got when we installed nginx. Place that in your nginx config file with some changes. Here is the code snippet set up to work for SSL.</p>
<p>Open nginx.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>nginx.conf</pre></div></div>

<p>Add our server configuration.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen <span style="color: #000000;">443</span>;
        server_name domain.com;
        root <span style="color: #000000; font-weight: bold;">/</span>where<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>is;
        passenger_enabled on;
        ssl on;
        ssl_certificate <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>server.crt;
        ssl_certificate_key <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>server.key;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Note the ssl configuration is pointing at two files. A certificate and a key. For this setup we will generate the certificate and sign it our selves. This will NOT do in production as it will show users that the certificate is not trusted however for now its fine.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs
openssl genrsa <span style="color: #660033;">-des3</span> <span style="color: #660033;">-out</span> server.key <span style="color: #000000;">1024</span>
openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-key</span> server.key <span style="color: #660033;">-out</span> server.csr
<span style="color: #c20cb9; font-weight: bold;">cp</span> server.key server.key.org
openssl rsa <span style="color: #660033;">-in</span> server.key.org <span style="color: #660033;">-out</span> server.key
openssl x509 <span style="color: #660033;">-req</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">365</span> <span style="color: #660033;">-in</span> server.csr <span style="color: #660033;">-signkey</span> server.key <span style="color: #660033;">-out</span> server.crt</pre></div></div>

<p>OK now we have nginx all ready to go lets create our init script. The init script allows us to stop and start nginx when we need to and its not provided for us when we install nginx via passenger.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx</pre></div></div>

<p>Add the following to this file and save.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### BEGIN INIT INFO</span>
<span style="color: #666666; font-style: italic;"># Provides:          nginx</span>
<span style="color: #666666; font-style: italic;"># Required-Start:    $all</span>
<span style="color: #666666; font-style: italic;"># Required-Stop:     $all</span>
<span style="color: #666666; font-style: italic;"># Default-Start:     2 3 4 5</span>
<span style="color: #666666; font-style: italic;"># Default-Stop:      0 1 6</span>
<span style="color: #666666; font-style: italic;"># Short-Description: starts the nginx web server</span>
<span style="color: #666666; font-style: italic;"># Description:       starts nginx using start-stop-daemon</span>
<span style="color: #666666; font-style: italic;">### END INIT INFO</span>
&nbsp;
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #007800;">DAEMON</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx
<span style="color: #007800;">NAME</span>=nginx
<span style="color: #007800;">DESC</span>=nginx
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Include nginx defaults if available</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
        . <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>nginx
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
                <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_OPTS</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
                <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #000000; font-weight: bold;">|</span>force-reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> \
                <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> \
                <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_OPTS</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Reloading <span style="color: #007800;">$DESC</span> configuration: &quot;</span>
      start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--signal</span> HUP <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
          <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span>
      <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
      <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">N</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: <span style="color: #007800;">$N</span> {start|stop|restart|force-reload}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Now we have everything set up lets start nginx.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx start</pre></div></div>

<p>Once this is started point your browser to the correct domain via https and test your site out. Good luck!</p>
<h3>Sources</h3>
<p><a href="http://articles.slicehost.com/2010/10/18/ubuntu-maverick-setup-part-1">http://articles.slicehost.com/2010/10/18/ubuntu-maverick-setup-part-1</a></p>
<p><a href="http://articles.slicehost.com/2007/12/19/ubuntu-gutsy-nginx-ssl-and-vhosts">http://articles.slicehost.com/2007/12/19/ubuntu-gutsy-nginx-ssl-and-vhosts</a></p>
<p><a href="http://www.modrails.com/install.html">http://www.modrails.com/install.html</a></p>
<p><a href="http://blog.bigrocksoftware.com/2011/01/07/rvm-nginx-passenger-rails-3/">http://blog.bigrocksoftware.com/2011/01/07/rvm-nginx-passenger-rails-3/</a></p>
<p><a href="https://rvm.beginrescueend.com/rvm/install/">https://rvm.beginrescueend.com/rvm/install/</a></p>
<p><a href="http://excid3.com/blog/ruby-on-rails-3-and-mysql-on-ubuntu-10-10/">http://excid3.com/blog/ruby-on-rails-3-and-mysql-on-ubuntu-10-10/</a></p>
<p><a href="http://stackoverflow.com/questions/3644897/rvm-cannot-use-ruby-with-sudo">http://stackoverflow.com/questions/3644897/rvm-cannot-use-ruby-with-sudo</a></p>
<p><a href="http://help.github.com/deploy-with-capistrano/">http://help.github.com/deploy-with-capistrano/</a></p>
<p><a href="http://beginrescueend.com/integration/capistrano/">http://beginrescueend.com/integration/capistrano/</a></p>
<p><a href="http://blog.ninjahideout.com/posts/a-guide-to-a-nginx-passenger-and-rvm-server">http://blog.ninjahideout.com/posts/a-guide-to-a-nginx-passenger-and-rvm-server</a></p>
<p><a href="http://blog.ninjahideout.com/posts/the-path-to-better-rvm-and-passenger-integration">http://blog.ninjahideout.com/posts/the-path-to-better-rvm-and-passenger-integration</a></p>
<p><a href="http://stackoverflow.com/questions/4349628/rails-3-app-deployment-bundler-rake-issues">http://stackoverflow.com/questions/4349628/rails-3-app-deployment-bundler-rake-issues</a></p>
<p><a href="http://wiki.nginx.org/HttpSslModule">http://wiki.nginx.org/HttpSslModule</a></p>
<h3>Post updates</h3>
<p>23/08/2011 Added links to sources, added intro to ssl.</p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/07/setting-up-nginx-to-work-with-rails-capistrano-and-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New theme</title>
		<link>http://rtmatheson.com/2011/06/new-theme/</link>
		<comments>http://rtmatheson.com/2011/06/new-theme/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 02:24:45 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=309</guid>
		<description><![CDATA[Simple&#8230; fast&#8230; better for screen reading.]]></description>
			<content:encoded><![CDATA[<p>Simple&#8230; fast&#8230; better for screen reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/06/new-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reload values on blur with jQuery</title>
		<link>http://rtmatheson.com/2011/05/reload-values-on-blur-with-jquery/</link>
		<comments>http://rtmatheson.com/2011/05/reload-values-on-blur-with-jquery/#comments</comments>
		<pubDate>Mon, 02 May 2011 07:15:07 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[blur]]></category>
		<category><![CDATA[existing]]></category>
		<category><![CDATA[focus]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[values]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=303</guid>
		<description><![CDATA[Sometimes an existing value in a HTML field can do so much for usability. The problem is these &#8220;existing values&#8221; can sometimes get in the way and make the page more difficult to use. Its fair to say that you want to clear that value when the user is ready to fill out the form. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes an existing value in a HTML field can do so much for usability. The problem is these &#8220;existing values&#8221; can sometimes get in the way and make the page more difficult to use. Its fair to say that you want to clear that value when the user is ready to fill out the form. The focus event has you covered in this situation, but what about when the user does not enter any data after clicking on the form element? The element needs to perform some sort of persistence to reload the value that it was initialised with.</p>
<p>jQuery provides a great way to do this with the &#8220;data()&#8221; function. This function allows any data to be attached any DOM element. Very handy when you throw(excuse the pun) it in with a jQuery function. Here is my solution to reloading values for DOM form elements. Works best with type=&#8221;text&#8221; <img src='http://rtmatheson.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">contentOnBlur</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>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> value<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'initValue'</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'changed'</span><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>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'changed'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'changed'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'changed'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'initValue'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/05/reload-values-on-blur-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The little compiler that could</title>
		<link>http://rtmatheson.com/2011/04/the-little-compiler-that-could/</link>
		<comments>http://rtmatheson.com/2011/04/the-little-compiler-that-could/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 07:06:26 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Rambling]]></category>
		<category><![CDATA[1100]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[Assignment]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[double equals]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=298</guid>
		<description><![CDATA[Action script three continues to impress me. Just got this warning that has saved me a lot of headache. Warning: 1100: Assignment within conditional. Did you mean == instead of =? Thanks compiler&#8230; I sure did mean == and not =. This is so handy. Well done AS3! Keep the nice surprises coming.]]></description>
			<content:encoded><![CDATA[<p>Action script three continues to impress me. Just got this warning that has saved me a lot of headache.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Warning: <span style="color: #cc66cc;">1100</span>: Assignment within conditional.  <span style="color: #006600;">Did</span> you mean == instead of =?</pre></div></div>

<p>Thanks compiler&#8230; I sure did mean == and not =.  This is so handy. Well done AS3! Keep the nice surprises coming.</p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/04/the-little-compiler-that-could/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

