<?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 &#187; Coding</title>
	<atom:link href="http://rtmatheson.com/category/coding/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>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>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>Renaming files in ruby</title>
		<link>http://rtmatheson.com/2011/03/renaming-files-in-ruby/</link>
		<comments>http://rtmatheson.com/2011/03/renaming-files-in-ruby/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 01:36:43 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[glob]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[renaming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=289</guid>
		<description><![CDATA[Its programs like this that make me love ruby. I think the code looks fucking awesome when its done. require 'fileutils' Dir.glob&#40;&#34;*.jpg&#34;&#41;.each do &#124;file_name&#124; new_name = file_name&#91;2..file_name.length&#93; new_name.gsub! &#34;-&#34;, &#34;_&#34; puts &#34;Renaming #{file_name} =&#62; #{new_name}&#34; File.rename file_name, new_name end]]></description>
			<content:encoded><![CDATA[<p>Its programs like this that make me love ruby. I think the code looks fucking awesome when its done.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fileutils'</span>
<span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;*.jpg&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file_name<span style="color:#006600; font-weight:bold;">|</span>
  new_name = file_name<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span>..<span style="color:#9900CC;">file_name</span>.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
  new_name.<span style="color:#CC0066; font-weight:bold;">gsub!</span> <span style="color:#996600;">&quot;-&quot;</span>, <span style="color:#996600;">&quot;_&quot;</span> 
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Renaming #{file_name} =&gt; #{new_name}&quot;</span>
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">rename</span> file_name, new_name
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/03/renaming-files-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deploying a Django site with Fabric</title>
		<link>http://rtmatheson.com/2011/03/deploying-a-django-site-with-fabric/</link>
		<comments>http://rtmatheson.com/2011/03/deploying-a-django-site-with-fabric/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 00:36:50 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[fabfile]]></category>
		<category><![CDATA[fabric]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=280</guid>
		<description><![CDATA[I just deployed my first Django site. Parts of it where slightly painful because I am new to python/django/mod_wsgi. Also because for some reason that still escapes me now I opted for centos and not ubuntu. I am not saying anything about about centos its just different to ubuntu&#8230; what I normally work with. However [...]]]></description>
			<content:encoded><![CDATA[<p>I just deployed my first Django site. Parts of it where slightly painful because I am new to python/django/mod_wsgi. Also because for some reason that still escapes me now I opted for centos and not ubuntu. I am not saying anything about about centos its just different to ubuntu&#8230; what I normally work with.  However one thing I really liked about the process was fabric. It just works and don&#8217;t we all just love that. I did however notice that a lot of the &#8220;fabfiles&#8221; out there are not up to date. Others out there are very specific to peoples set ups and others out there do things that did not make any sense to me. So here is mine that will work on the latest version of fabric at hte time of this writing. Its also generic so you should be able to plonk it in to any django project and have it work. I used capistarno as a model to create it.</p>
<p>Things to note about this fabfile:<br />
1. It assumes that you have your wsgi file in your project dir.(dont worry this is moved out after the deployment in to a shared folder)<br />
2. It assumes your using git. You should be but incase your not it&#8217;s not hard to change.<br />
3. It assumes your using virtualenv<br />
4. It creates a new folder each time you run the deploy task allowing you to roll back<br />
5. It moves wsgi files out of the project folder in to a shared folder<br />
6. It creates a folder structure all under one folder of your choosing</p>
<p>Things that the file does not do:<br />
1. Roll back versions<br />
2. Set up web server config</p>
<p>Anyway. Here it is.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">env.<span style="color: black;">hosts</span> = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'name@host'</span><span style="color: black;">&#93;</span>
env.<span style="color: black;">path</span> = <span style="color: #483d8b;">'/root/deployment/path'</span>
env.<span style="color: black;">virtual_env_path</span> = <span style="color: #483d8b;">'%(path)s/virtual_env'</span> <span style="color: #66cc66;">%</span> env <span style="color: #808080; font-style: italic;"># virtual env path</span>
env.<span style="color: black;">project_name</span> = <span style="color: #483d8b;">'your_project_name'</span>
env.<span style="color: black;">activate</span> = <span style="color: #483d8b;">'source %(path)s/virtual_env/bin/activate'</span> <span style="color: #66cc66;">%</span> env <span style="color: #808080; font-style: italic;"># how to activate your virtual env</span>
env.<span style="color: black;">deploy_user</span> = <span style="color: #483d8b;">'deployment_user_name'</span>
env.<span style="color: black;">python_version</span> = <span style="color: #483d8b;">'2.6'</span> <span style="color: #808080; font-style: italic;">#nuf said</span>
env.<span style="color: black;">site_packages_path</span> = <span style="color: #483d8b;">'/%(virtual_env_path)s/lib/python%(python_version)s/site-packages'</span> <span style="color: #66cc66;">%</span> env <span style="color: #808080; font-style: italic;"># where do your virtual env site packages live</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> pythonversion<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'python -V'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> virtualenv<span style="color: black;">&#40;</span>command<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">cd</span><span style="color: black;">&#40;</span>env.<span style="color: black;">path</span><span style="color: black;">&#41;</span>:
        sudo<span style="color: black;">&#40;</span>env.<span style="color: black;">activate</span> + <span style="color: #483d8b;">'&amp;&amp;'</span> + command, <span style="color: #dc143c;">user</span>=env.<span style="color: black;">deploy_user</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> create_deployment_folders<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Create the base set of folders for the deployment
    &quot;&quot;&quot;</span>
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mkdir %(path)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">cd</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%(path)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>:
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mkdir releases'</span><span style="color: black;">&#41;</span>
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mkdir shared'</span><span style="color: black;">&#41;</span>
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mkdir tmp'</span><span style="color: black;">&#41;</span>
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mkdir content'</span><span style="color: black;">&#41;</span>
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'chmod 777 content'</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> build_virtual_env<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Create virtual env for the project
    &quot;&quot;&quot;</span>
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mkdir %(virtual_env_path)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">cd</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%(virtual_env_path)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>:
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'virtualenv --no-site-packages --python=python%(python_version)s .'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> install_requirements<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Install the required packages from the requirements file using pip
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">cd</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%(path)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>:
        virtualenv<span style="color: black;">&#40;</span><span style="color: #483d8b;">'pip install -r ./%(project_name)s/requirements.txt'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> reinstall_requirements<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Reinstall the required packages from the requirements file using pip
    &quot;&quot;&quot;</span>
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'rm -Rf %(virtual_env_path)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
    build_virtual_env<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    install_requirements<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    restart_webserver<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> setup<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Setup a fresh virtualenv as well as a few useful directories, then run
    a full deployment
    &quot;&quot;&quot;</span>
    create_deployment_folders<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    build_virtual_env<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> deploy<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Deploy the latest version of the site to the servers, install any
    required third party modules, install the virtual host and 
    then restart the webserver
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
    env.<span style="color: black;">release</span> = <span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%Y%m%d%H%M%S'</span><span style="color: black;">&#41;</span>
    upload_tar_from_git<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    symlink_current_release<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    install_requirements<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;">#migrate()</span>
    restart_webserver<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> upload_tar_from_git<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Create an archive from the current Git master branch and upload it&quot;</span>
    local<span style="color: black;">&#40;</span><span style="color: #483d8b;">'git archive --format=tar master | gzip &gt; %(release)s.tar.gz'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mkdir %(path)s/releases/%(release)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
    put<span style="color: black;">&#40;</span><span style="color: #483d8b;">'%(release)s.tar.gz'</span> <span style="color: #66cc66;">%</span> env, <span style="color: #483d8b;">'%(path)s/tmp/'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">cd</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%(path)s/releases/%(release)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>:
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'tar zxf ../../tmp/%(release)s.tar.gz'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'rm ../../tmp/%(release)s.tar.gz'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
    local<span style="color: black;">&#40;</span><span style="color: #483d8b;">'rm %(release)s.tar.gz'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> symlink_current_release<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Symlink our current release&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">with</span> settings<span style="color: black;">&#40;</span>warn_only=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>:
        run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'rm %(path)s/%(project_name)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'ln -sf %(path)s/releases/%(release)s %(path)s/%(project_name)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mv -f %(path)s/%(project_name)s/%(project_name)s.wsgi %(path)s/shared'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> migrate<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Update the database&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">cd</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%(path)s/%(project_name)s'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>:
        virtualenv<span style="color: black;">&#40;</span><span style="color: #483d8b;">'python manage.py syncdb --settings=&quot;production_settings&quot; --noinput'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> restart_webserver<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Restart the web server&quot;</span>
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'touch %(path)s/shared/%(project_name)s.wsgi'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> link_admin_media<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Add the admin media to the site&quot;</span>
    run<span style="color: black;">&#40;</span><span style="color: #483d8b;">'ln -sf %(site_packages_path)s/django/contrib/admin/media %(path)s/shared/admin_media'</span> <span style="color: #66cc66;">%</span> env<span style="color: black;">&#41;</span></pre></div></div>

<p>This deployment file is based on the one at the &#8220;mnorethanseven&#8221; blog. Check this <a href="http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p.html">detailed yet out-dated post about django deployment</a> for further reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/03/deploying-a-django-site-with-fabric/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Object Oriented Javascript with jQuery</title>
		<link>http://rtmatheson.com/2011/01/object-orientated-javascript/</link>
		<comments>http://rtmatheson.com/2011/01/object-orientated-javascript/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 06:13:24 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oo programming]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=264</guid>
		<description><![CDATA[Lately I have been working with Javascript. A lot. As a result I have been doing research on javascript.  The more I learn about it the more intrigued I am. I love using jQuery but never fully understood what javascript was about. Now I have a better idea I would like to share with you a rough [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I have been working with Javascript. A lot. As a result I have been doing research on javascript.  The more I learn about it the more intrigued I am. I love using jQuery but never fully understood what javascript was about. Now I have a better idea I would like to share with you a rough pattern that I use when writing javascript for jQuery.</p>
<p>Firstly I like to think of every bit of javascript functionality as its own object. This allows for two things. Firstly it keeps scope nice and tidy and secondly it keeps the frequency in which your searching the DOM to a minimum which helps make your scripts run faster.</p>
<p>Here is a simple example that adds behavior  to a search bar. I have commented each line to explain what&#8217;s happening.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// everything in its own function. This creates an object when using the new key word</span>
<span style="color: #003366; font-weight: bold;">function</span> SideBarSearch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//text value for the field</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initValue</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Search the blog&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">//Find the search field element. Once found we dont have to reference the dom again. This is a good thing as searching the dom is very slow.</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchField</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#blog_query'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">//setting the value of the search field. This could also be done with html.</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchField</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initValue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">//This next line copies the whole scope of this object so it can be used in jQuery callbacks. Make sure you do this because the jQuery callback will set its own scope.</span>
        <span style="color: #003366; font-weight: bold;">var</span> self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">//the jQuery event call back.</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchField</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: #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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'#000'</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: #006600; font-style: italic;">//another jquery event call back. Note nether of these search the dom.</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchField</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: #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>self.<span style="color: #660066;">initValue</span><span style="color: #009900;">&#41;</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;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'#9A9A9A'</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchField</span>.<span style="color: #660066;">keypress</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//note the === always use this and not == as == can return unexpected results.</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'13'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.search-bar .loading'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'inline'</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></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2011/01/object-orientated-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing assert-random</title>
		<link>http://rtmatheson.com/2010/08/introducing-assert-random/</link>
		<comments>http://rtmatheson.com/2010/08/introducing-assert-random/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 11:11:15 +0000</pubDate>
		<dc:creator>Stewart Matheson</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://rtmatheson.com/?p=232</guid>
		<description><![CDATA[Something I have been meaning to do for a long time now is create and release a ruby gem. Today I have done this. Introducing assert-random. Its a VERY simple gem that adds an assertion to test/unit. Assert random as a test accepts a block and runs this block 10 times. Once the block has [...]]]></description>
			<content:encoded><![CDATA[<p>Something I have been meaning to do for a long time now is create and release a ruby gem. Today I have done this. Introducing assert-random. Its a VERY simple gem that adds an assertion to test/unit. Assert random as a test accepts a block and runs this block 10 times. Once the block has been run it then checks the results of the block. Currently it tests to make sure that no objects that are the result of the block match. Not much but its a start.</p>
<p>Example that passes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">assert_random <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">rand</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1000</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Example that fails:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">assert_random <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#006666;">1000</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Basic stuff but I plan to extend it in the future so something like this will fail:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">counter = <span style="color:#006666;">1</span>
assert_random <span style="color:#9966CC; font-weight:bold;">do</span>
    counter <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>I used the gem Jeweler. I got up and running very quickly and was able to focus on the functionality of the gem and not all of the meta details a gem needs. All that was generated for me. Awesome really.</p>
<p>Source: <a href="http://github.com/stewartmatheson/assert-random">http://github.com/stewartmatheson/assert-random</a><br />
RubyGem: <a href="http://rubygems.org/gems/assert-random">http://rubygems.org/gems/assert-random</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rtmatheson.com/2010/08/introducing-assert-random/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

