<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Mario's Blog]]></title>
  <link href="http://www.mariovisic.com/atom.xml" rel="self"/>
  <link href="http://www.mariovisic.com/"/>
  <updated>2012-01-05T17:18:54+08:00</updated>
  <id>http://www.mariovisic.com/</id>
  <author>
    <name><![CDATA[Mario Visic]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[OSX Lion Colour Sampling using DigitalColor Meter]]></title>
    <link href="http://www.mariovisic.com/blog/2012/01/05/osx-lion-colour-sampling-using-digitalcolor-meter/"/>
    <updated>2012-01-05T14:38:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2012/01/05/osx-lion-colour-sampling-using-digitalcolor-meter</id>
    <content type="html"><![CDATA[<p>Previously when I was running Mac OSX Snow Leopard I would use the built
in tool &#8216;DigitalColor Meter&#8217; to grab RGB values from my screen. Using the
tool is is very quick to grab colours from websites, photoshop files,
anything really.</p>

<p>When I upgraded to OSX Lion and opened the colour meter for the first
time I realised that it had changed and I could no longer quickly grab
colour values to use. I realised though by changing one of the menu
settings I could get back the previous functionality; here&#8217;s how:</p>

<!-- more -->


<p>First open the DigitalColor Meter app, you can find it using Spotlight.</p>

<p><img src="http://www.mariovisic.com/images/blog/digital_color_meter/meter_1.png" alt="Opening the Application using Spotlight" /></p>

<p>It looks like this, you&#8217;ll notice that the displayed values are in
absolute RGB 0-255 values.</p>

<p><img src="http://www.mariovisic.com/images/blog/digital_color_meter/meter_2.png" alt="DigitalColor Meter Application" /></p>

<p>Select <code>View</code> => <code>Display Values</code> => <code>As Hexadecimal</code></p>

<p><img src="http://www.mariovisic.com/images/blog/digital_color_meter/meter_3.png" alt="Setting the display value to hexadecimal" /></p>

<p>Now you can sample a colour simply by hovering over the colour you want.
Once you are ready press <code>Command</code> + <code>Shift</code> + <code>C</code>. It should copy the
hexadecimal colour to your clipboard.</p>

<p>You should be able to notice it is copying the colour as the Color item
on the top menu will highlight monetarily.</p>

<p><img src="http://www.mariovisic.com/images/blog/digital_color_meter/meter_4.png" alt="Setting the display value to hexadecimal" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Open sourcing like a pro]]></title>
    <link href="http://www.mariovisic.com/blog/2011/12/15/open-sourcing-like-a-pro/"/>
    <updated>2011-12-15T19:48:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/12/15/open-sourcing-like-a-pro</id>
    <content type="html"><![CDATA[<p>For a little while I haven&#8217;t had any spare time to do any original open source work. I&#8217;d still been contributing to <a href="http://www.locomotivecms.com/">Locomotive CMS</a>, fixing bugs and generally just helping out, but I haven&#8217;t had the chance to work on anything new. Thankfully for a client project of mine I had the chance to create a new gem.</p>

<p>So, yesterday at work I released the <a href="https://rubygems.org/gems/activemerchant-bpoint">activemerchant-bpoint gem</a>. A small plugin for Active Merchant that provides a billing gateway for the commonwealth bank&#8217;s BPOINT merchant gateway service. It&#8217;s really great to work in <a href="http://www.sentia.com.au/">an environment that encourages open source work</a>. Hopefully this is just the start and I hope in the future that i&#8217;ll be able to open source much more of the work I do.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Declarative cucumber scenarios]]></title>
    <link href="http://www.mariovisic.com/blog/2011/10/28/declarative-cucumber-scenarios/"/>
    <updated>2011-10-28T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/10/28/declarative-cucumber-scenarios</id>
    <content type="html"><![CDATA[<p>I did a tech talk at work about how we were using cucumber and how we should be
using it instead. It goes over using declarative cucumber scenarios instead of
imperative.</p>

<p>Slides are available here: <a href="http://mariovisic.github.com/declarative_cucumber">http://mariovisic.github.com/declarative_cucumber</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How Good is cheese]]></title>
    <link href="http://www.mariovisic.com/blog/2011/09/30/how-good-is-cheese/"/>
    <updated>2011-09-30T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/09/30/how-good-is-cheese</id>
    <content type="html"><![CDATA[<p>So… I got bored tonight and this happened <a href="http://www.howgoodischeese.com">howgoodischeese.com</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Ruby 1.9.3rc with RVM]]></title>
    <link href="http://www.mariovisic.com/blog/2011/09/25/ruby-193rc-with-rvm/"/>
    <updated>2011-09-25T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/09/25/ruby-193rc-with-rvm</id>
    <content type="html"><![CDATA[<p>The Ruby MRI 1.9.3 RC1 has just been released and I wanted to try it out, the
latest version of rvm only lists the 1.9.3 preview1 and 1.9.3-head which
doesn&#8217;t appear to work correctly. Here&#8217;s how I managed to get 1.9.3
installed using rvm:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> rvm install ruby-1.9.3-tv1_9_3_rc1 --with-libyaml-dir=$HOME/.rvm/usr
</span><span class='line'> rvm alias create 1.9.3-rc ruby-1.9.3-tv1_9_3_rc1
</span><span class='line'>
</span><span class='line'> rvm use 1.9.3-rc</span></code></pre></td></tr></table></div></figure>


<p>Ruby 1.9.3 works quite well (all of my tests still seem to be green), although
there are a few small issues at the moment. For example ruby-debug19
doesn&#8217;t currently install.
Running a quick test shows that 1.9.3 does indeed seem to load up a rails
environment much quicker, here is a comparison of running rspec and cucumber
tests for a rails 3.1 project.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> Using /Users/mario/.rvm/gems/ruby-1.9.3-tv1_9_3_rc1
</span><span class='line'>
</span><span class='line'> time rspec spec
</span><span class='line'> Finished in 22.81 seconds
</span><span class='line'>
</span><span class='line'> real  0m28.469s
</span><span class='line'> user  0m11.000s
</span><span class='line'> sys   0m0.895s
</span><span class='line'>
</span><span class='line'> time cucumber
</span><span class='line'> 0m4.816s
</span><span class='line'>
</span><span class='line'> real  0m12.955s
</span><span class='line'> user  0m10.579s
</span><span class='line'> sys   0m0.701s</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> Using /Users/mario/.rvm/gems/ruby-1.9.2-p290
</span><span class='line'>
</span><span class='line'> time rspec spec
</span><span class='line'> Finished in 25.69 seconds
</span><span class='line'>
</span><span class='line'> real  0m43.826s
</span><span class='line'> user  0m18.193s
</span><span class='line'> sys   0m1.367s
</span><span class='line'>
</span><span class='line'> time cucumber
</span><span class='line'> 0m6.007s
</span><span class='line'>
</span><span class='line'> real  0m24.559s
</span><span class='line'> user  0m19.324s
</span><span class='line'> sys   0m1.200s</span></code></pre></td></tr></table></div></figure>


<p>As you can see the actual tests themselves ran faster but not by much, the
total execution time went down a lot though as 1.9.3 has some new fixes to
dramatically speed up the time it takes to require libraries.</p>

<h2>Update</h2>

<p>1.9.3rc1 is now available directly through RVM. Simply run:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> rvm get head
</span><span class='line'> rvm reload
</span><span class='line'> rvm install 1.9.3</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Locomotive CMS]]></title>
    <link href="http://www.mariovisic.com/blog/2011/09/03/locomotive-cms/"/>
    <updated>2011-09-03T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/09/03/locomotive-cms</id>
    <content type="html"><![CDATA[<p>A few months ago a friend and coworker of mine pointed me towards <a href="http://www.locomotivecms.com/">Locomotive CMS</a>, a content management system built on ruby on rails which has multi site
support out of the box and has a really pretty admin interface.</p>

<p>I have been helping out Locomotive CMS for a while now in my spare time. I&#8217;ve been fixing bugs here and there and helping out users that require assistance. A couple of days ago I was appointed as one of the maintainers for the project, YAY.</p>

<p>Locomotive is really neat, you should totally check it out!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Squeel]]></title>
    <link href="http://www.mariovisic.com/blog/2011/08/09/squeel/"/>
    <updated>2011-08-09T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/08/09/squeel</id>
    <content type="html"><![CDATA[<p>I&#8217;ve been using a really neat gem lately called Squeel, it provides extra
support for active record to do lots of neat things. There&#8217;s heaps of
examples <a href="http://erniemiller.org/projects/squeel/">at the homepage</a>.</p>

<p>Today I managed to get a patch into squeel (YAY!). I found a bug which was only
occurring on ruby 1.9.2 sporadically. I wrote a failing spec and the author
<a href="http://twitter.com/erniemiller">Ernie</a> created a fix on the very same day.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Adding additional processing support to CarrierWave]]></title>
    <link href="http://www.mariovisic.com/blog/2011/03/31/adding-additional-processing-support-to-carrierwave/"/>
    <updated>2011-03-31T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/03/31/adding-additional-processing-support-to-carrierwave</id>
    <content type="html"><![CDATA[<p><a href="http://blog.thefrontiergroup.com.au/2011/03/adding-additional-to-carrierwave/">My first blog post in a little while for the TFG blog.</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using arel directly in rails]]></title>
    <link href="http://www.mariovisic.com/blog/2011/02/27/using-arel-directly-in-rails/"/>
    <updated>2011-02-27T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/02/27/using-arel-directly-in-rails</id>
    <content type="html"><![CDATA[<p>Today I was creating a model method which would return some associated objects.
It wasn&#8217;t hugely complex but I basically needed to match an sql string
which looked something like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'> <span class="no">SELECT</span> <span class="o">*</span> <span class="no">FROM</span> <span class="n">table</span> <span class="no">WHERE</span> <span class="n">column_one</span> <span class="o">=</span> <span class="n">something</span> <span class="no">AND</span> <span class="n">column_two</span> <span class="o">=</span> <span class="n">something</span>
</span><span class='line'> <span class="no">OR</span> <span class="n">column_three</span> <span class="o">=</span> <span class="n">something</span> <span class="no">AND</span> <span class="n">column_four</span> <span class="o">=</span> <span class="n">something</span>
</span></code></pre></td></tr></table></div></figure>


<p>After reading some arel documentation, I came up this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'> <span class="n">version</span>  <span class="o">=</span> <span class="no">Version</span><span class="o">.</span><span class="n">arel_table</span>
</span><span class='line'> <span class="n">versions</span> <span class="o">=</span> <span class="no">Version</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">version</span><span class="o">[</span><span class="ss">:c1</span><span class="o">].</span><span class="n">eq</span><span class="p">(</span><span class="n">something</span><span class="p">)</span><span class="o">.</span><span class="n">and</span><span class="p">(</span><span class="n">version</span><span class="o">[</span><span class="ss">:c2</span><span class="o">].</span><span class="n">eq</span>
</span><span class='line'> <span class="p">(</span><span class="n">something</span><span class="p">))</span><span class="o">.</span><span class="n">or</span><span class="p">(</span><span class="n">version</span><span class="o">[</span><span class="ss">:c3</span><span class="o">].</span><span class="n">eq</span><span class="p">(</span><span class="n">something</span><span class="p">)</span><span class="o">.</span><span class="n">and</span><span class="p">(</span><span class="n">version</span><span class="o">[</span><span class="ss">:c4</span><span class="o">].</span><span class="n">eq</span><span class="p">(</span><span class="n">something</span><span class="p">))))</span>
</span></code></pre></td></tr></table></div></figure>


<p>If this is a bit too fiddly for you then there are some nice gems that do this
for you, such as <a href="http://erniemiller.org/projects/squeel/">Squeel</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Things to remember in Vim]]></title>
    <link href="http://www.mariovisic.com/blog/2011/02/23/things-to-remember-in-vim/"/>
    <updated>2011-02-23T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/02/23/things-to-remember-in-vim</id>
    <content type="html"><![CDATA[<p>I’ve been using Vim for a couple of months now and soo far it’s been great. I’m still learning new things all the time which is really good as well. Here’s some of the tips and trick’s i’ve picked up</p>

<p>To Automatically indent the current line where it should reside when programming use <code>==</code></p>

<p>Use <code>Ctrl + c</code> instead of having to reach for the <code>ESC</code> key all the time.</p>

<p>The comment plugin adds the mapping <code>\c Space</code> which comments a line (Or multiple visually selected lines). It also uncomments already commented lines.</p>

<p><code>:A</code> to cycle between the test and the implementation (Using the rails plugin).</p>

<p><code>:R</code> to cycle between related files, eg from a view to the controller and back (Using the rails plugin).</p>

<p><code>.</code> Repeats the last action.</p>

<p><code>Align [param]</code> Align the visually selected lines based on the parameter given. So for example <code>Align =</code> would align lines based on the equal signs.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Moving from REE to 1.9.2 in production]]></title>
    <link href="http://www.mariovisic.com/blog/2011/02/06/moving-from-ree-to-192-in-production/"/>
    <updated>2011-02-06T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/02/06/moving-from-ree-to-192-in-production</id>
    <content type="html"><![CDATA[<p>I moved my production box from REE to 1.9.2 today. The process was made very
easy by using <a href="http://beginrescueend.com/">RVM</a>. As i&#8217;m using nginx and passenger, I needed to compile
a new copy of nginx with the passenger module included.</p>

<p>Once all done, I benchmarked the <a href="http://www.knightsarmy.net/">knightsarmy</a> site the same way I had done <a href="http://www.mariovisic.com/post/2674945799/simple-caching-for-blog-posts">in an earlier post</a>. With REE i was hitting <strong>25.07 requests per second</strong>. With 1.9.2 I
managed <strong>33.93 per second</strong>.</p>

<p>Neat!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Checking if objects or relations exist in Ruby on Rails]]></title>
    <link href="http://www.mariovisic.com/blog/2011/02/04/checking-if-objects-or-relations-exist-in-ruby-on-rails/"/>
    <updated>2011-02-04T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/02/04/checking-if-objects-or-relations-exist-in-ruby-on-rails</id>
    <content type="html"><![CDATA[<p>I was pair programming with <a href="http://keithpitt.com/">the great magician Keith</a> yesterday when he pointed out something interesting when checking if objects or relations exist in a collection.</p>

<p>To check if there were any items present in a collection I would do something like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">object</span><span class="o">.</span><span class="n">relation</span><span class="o">.</span><span class="n">present?</span>
</span></code></pre></td></tr></table></div></figure>


<p>Keith told me to use:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">object</span><span class="o">.</span><span class="n">relation</span><span class="o">.</span><span class="n">any?</span>
</span></code></pre></td></tr></table></div></figure>


<p>Turns out that the <code>any?</code> method will perform a <code>COUNT (*)</code> SQL query where as the
<code>present?</code> method will perform a <code>SELECT (*)</code> which is infinitely slower than
performing a count.</p>

<p>So from now on i&#8217;ll be using the <code>any?</code> method instead of <code>present?</code></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Remote website Backups with mysqldump and rsync]]></title>
    <link href="http://www.mariovisic.com/blog/2011/01/29/remote-website-backups-with-mysqldump-and-rsync/"/>
    <updated>2011-01-29T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/01/29/remote-website-backups-with-mysqldump-and-rsync</id>
    <content type="html"><![CDATA[<p>Today I went through the process of creating a very simple automated backup
solution for my linux web server using mysqldump and rysnc. I thought i&#8217;d
share as it&#8217;s <strong>really easy</strong> to do and you should always be backing up your
info.</p>

<p>The machine i&#8217;m backing up hosts my live websites, database server
(mysql) and git repositories. I also have a linux machine at home that can be
accessed over ssh which will be receiving the backups. The rsync setup process
will differ if you&#8217;re using a local machine.</p>

<p>The first thing to do is to setup mysqldump to output the contents of the
database. This can be fairly system intensive for large databases, but mine is
quite small so it&#8217;s ok to run and finishes fairly quickly.</p>

<p>The mysqldump tool should be included in your mysql installation, there are
similar tools for other DBMS&#8217;s too. By default mysqldump outputs to the
STDOUT, so we can redirect the output to a file of our choice, here&#8217;s
how:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>mysqldump -AR -u [username] -p[password] &gt; [location]</span></code></pre></td></tr></table></div></figure>


<p>Just fill in your database username, password and the output location you want
and run it on the terminal, <em>and yes there SHOULD NOT be a space between -p and your password</em> :)</p>

<p>You should have a sql file with all of your database data.
The dump can be setup as a cron task, i&#8217;ve set mine up to run every day
at midnight. Simply run <code>crontab -e</code> to modify your cron configuration and put in
the following line.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>0 0 * * * mysqldump --all-databases -u [username] -p[password] &gt; [location]</span></code></pre></td></tr></table></div></figure>


<p>We can now go ahead and setup rsync to backup our information. Rsync was
already installed on my system but if you don&#8217;t have it already you can
grab it using apt or any other package manage, here&#8217;s how in apt.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo apt-get install rsync</span></code></pre></td></tr></table></div></figure>


<p>Once installed we need to setup our backups. Rsync can be setup using
configuration files that can be altered to suit your needs. Just for
convenience i&#8217;ve just run rsync directly rather than using configuration
files. Here&#8217;s how.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rsync -e ssh -p 50001 -azvP /var/backups/mysql/ [username]@[hostname]:[path]</span></code></pre></td></tr></table></div></figure>


<p>OK, so there&#8217;s a bit much there, here&#8217;s what each part does.
We&#8217;re calling the rsync command, my machine that will be getting the
backups is available through ssh on port 50001, so the <code>-e</code> command sets up rsync
to use ssh on port 50001. The <code>-a</code> flag sets archive mode which will recursively
look through directories and preserve symlinks/times/groups and owners of
files, <code>-v</code> gives us a verbose output with more info and <code>-P</code> gives us a nice
little progress bar.</p>

<p>You can just copy the example code and fill in the username, hostname and path
with your own receiving servers details and then run the command on the command
line.</p>

<p>Once it&#8217;s all working we can put it into cron and specify that it gets
run once daily. We can set it up to run at 10 minutes past midnight, this
should give our mysql dump a chance to finish before we back it up. For the
cron task we won&#8217;t need a verbose output or a progress bar so we&#8217;re
only using <code>-az</code> and not <code>-azvP</code>. The P flag does allow for partial transfers which
we still want, so i&#8217;ve added <code>--partial</code> to the cron.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>10 0 * * * rsync -e ssh -p 50001 -az --partial /var/backups/mysql/
</span><span class='line'>[username]@[hostname]:[path]</span></code></pre></td></tr></table></div></figure>


<p>That&#8217;s it. We&#8217;re all done!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Simple caching for blog posts.]]></title>
    <link href="http://www.mariovisic.com/blog/2011/01/10/simple-caching-for-blog-posts/"/>
    <updated>2011-01-10T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2011/01/10/simple-caching-for-blog-posts</id>
    <content type="html"><![CDATA[<p>I maintain a website for my local soccer team called <a href="http://www.knightsarmy.net/">Knights Army</a> which is written in rails3 using a basic blog system I wrote myself. I&#8217;m using the
<a href="http://rubygems.org/gems/RedCloth">RedCloth gem</a> to process textile for blog posts.</p>

<p>The website only gets a very small amount of visitors a day, so performance
isn&#8217;t a concern of mine at all. The website does feel very snappy when
navigating already. I was looking over the code that I had written a few months
back and noticed that for each post (can be up to 10 shown per page) I was
running RedCloth over the body contents like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># app/views/posts/_post.html.haml</span>
</span><span class='line'><span class="o">=</span> <span class="n">post</span><span class="o">.</span><span class="n">body_html</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># app/models/post.rb</span>
</span><span class='line'><span class="c1"># Yes i realise post is a really bad name for a model</span>
</span><span class='line'><span class="k">def</span> <span class="nf">body_html</span>
</span><span class='line'>  <span class="no">RedCloth</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="nb">self</span><span class="o">.</span><span class="n">body</span><span class="p">)</span><span class="o">.</span><span class="n">to_html</span><span class="o">.</span><span class="n">html_safe</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>I had a simple idea to improve the performance of loading the posts. I created
a new text database column called cached_body on the posts table, then added
some logic so that it only runs RedCloth when the post contents change, or when
there is no cached_body already.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># db/migrate/20110109030634_add_cached_body_to_posts.rb</span>
</span><span class='line'><span class="k">class</span> <span class="nc">AddCachedBodyToPosts</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span>
</span><span class='line'>  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">up</span>
</span><span class='line'>    <span class="n">add_column</span> <span class="ss">:posts</span><span class="p">,</span> <span class="ss">:cached_body</span><span class="p">,</span> <span class="ss">:text</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">down</span>
</span><span class='line'>    <span class="n">remove_column</span> <span class="ss">:posts</span><span class="p">,</span> <span class="ss">:cached_body</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># app/models/post.rb</span>
</span><span class='line'>
</span><span class='line'><span class="n">before_save</span> <span class="ss">:set_cached_body</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">body_html</span>
</span><span class='line'>  <span class="k">if</span> <span class="n">cached_body</span><span class="o">.</span><span class="n">blank?</span>
</span><span class='line'>    <span class="n">set_cached_body</span>
</span><span class='line'>    <span class="n">save!</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>  <span class="n">cached_body</span><span class="o">.</span><span class="n">html_safe</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="kp">protected</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">set_cached_body</span>
</span><span class='line'>  <span class="nb">self</span><span class="o">.</span><span class="n">cached_body</span> <span class="o">=</span> <span class="no">RedCloth</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="nb">self</span><span class="o">.</span><span class="n">body</span><span class="p">)</span><span class="o">.</span><span class="n">to_html</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>I ran some benchmarks using the <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">apache benchmark tool</a> for a rough guide of the performance gains. I ran the command <code>ab -c 100 -n 1000 http://www.knightsarmy.net</code> a total of 5 times and then took the 3 middle scores to
make an average, here&#8217;s the results:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="no">Before</span><span class="p">:</span>
</span><span class='line'>  <span class="no">Average</span> <span class="no">Time</span><span class="p">:</span> <span class="mi">57</span><span class="o">.</span><span class="mi">49</span> <span class="n">seconds</span>
</span><span class='line'>  <span class="no">Average</span> <span class="no">RPS</span><span class="p">:</span>  <span class="mi">17</span><span class="o">.</span><span class="mi">40</span> <span class="o">[</span><span class="c1">#/sec] (mean)</span>
</span><span class='line'>
</span><span class='line'><span class="no">After</span><span class="p">:</span>
</span><span class='line'> <span class="no">Average</span> <span class="no">Time</span><span class="p">:</span>  <span class="mi">39</span><span class="o">.</span><span class="mi">89</span> <span class="n">seconds</span>
</span><span class='line'> <span class="no">Average</span> <span class="no">RPS</span><span class="p">:</span>   <span class="mi">25</span><span class="o">.</span><span class="mo">07</span> <span class="o">[</span><span class="c1">#/sec] (mean)</span>
</span></code></pre></td></tr></table></div></figure>


<p>That&#8217;s a 44% increase in requests per second and a 30% reduction in
response time. Neat!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Damned 1997 Factory car stereo anti theft systems]]></title>
    <link href="http://www.mariovisic.com/blog/2010/11/08/damned-1997-factory-car-stereo-anti-theft-systems/"/>
    <updated>2010-11-08T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2010/11/08/damned-1997-factory-car-stereo-anti-theft-systems</id>
    <content type="html"><![CDATA[<p>My car which was made in 1997 has a factory CD player installed. If the stereo ever loses power then you need to enter the security code to use the CD player again. The system was installed to stop thieves from just ripping out the stereo to sell, as the system was once worth much more than the $20 it would go for these days.</p>

<p>The CD player has a funny way of getting you to input the 4 digit code. You basically have to press numbers 1 through 4 the appropriate amount of times to increment each of the 4 numbers to get your code.</p>

<p>So for my code, which is 6104 (<strong>please don’t steal my stereo</strong>) would logically have me pressing the 1 digit six times, 2 once, 3 zero times and 4 four times. Or at least I thought! Turns out you need to press the number 10 times to get to 0, otherwise it doesn’t register.</p>

<p>I wasted a good 5 minutes figuring that out! Odd!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stephen Fry at the Sydney Opera House]]></title>
    <link href="http://www.mariovisic.com/blog/2010/10/29/stephen-fry-at-the-sydney-opera-house/"/>
    <updated>2010-10-29T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2010/10/29/stephen-fry-at-the-sydney-opera-house</id>
    <content type="html"><![CDATA[<iframe src="http://www.youtube.com/embed/1id1J3recyM" frameborder="0" allowfullscreen></iframe>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[I finally caved and got a twitter account]]></title>
    <link href="http://www.mariovisic.com/blog/2010/10/15/i-finally-caved-and-got-a-twitter-account/"/>
    <updated>2010-10-15T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2010/10/15/i-finally-caved-and-got-a-twitter-account</id>
    <content type="html"><![CDATA[<p>I finally caved and got a twitter account, thankfully there was this easy to understand video to get me going. This was almost more useful than the zombies in plain english video.</p>

<p>You can find me on twitter at <a href="twitter.com/mariovisic">@mariovisic</a></p>

<iframe src="http://www.youtube.com/embed/ddO9idmax0o" frameborder="0" allowfullscreen></iframe>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Rspec Array Matching]]></title>
    <link href="http://www.mariovisic.com/blog/2010/10/07/rspec-array-matching/"/>
    <updated>2010-10-07T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2010/10/07/rspec-array-matching</id>
    <content type="html"><![CDATA[<p>I started my new job today, for the first day they paired me with one of my friends who I knew before getting the position.</p>

<p>We were creating some tests for a method which returned an array of objects, we
knew the objects that would come out but it was hard to get them in the right
order. Trying to match the two arrays didn&#8217;t work:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'>  <span class="vi">@result</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="vi">@expected_array</span>
</span></code></pre></td></tr></table></div></figure>


<p>We didn&#8217;t want to simply sort both arrays as the test would get longer
and we shouldn&#8217;t really have to, so after poking around a bit we (well
mostly Darcy) discovered that rspec provides the <code>~=</code> matcher to match an array
for any given order. So this works flawlessly</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'>  <span class="vi">@result</span><span class="o">.</span><span class="n">should</span> <span class="o">=~</span> <span class="vi">@expected_array</span>
</span></code></pre></td></tr></table></div></figure>


<p>:)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Autoresize Textarea extension for the Radiant CMS]]></title>
    <link href="http://www.mariovisic.com/blog/2010/09/21/autoresize-textarea-extension-for-the-radiant-cms/"/>
    <updated>2010-09-21T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2010/09/21/autoresize-textarea-extension-for-the-radiant-cms</id>
    <content type="html"><![CDATA[<p><a href="http://www.dirkkelly.com/">Dirk, a close friend of mine</a> had previously modified the radiant CMS so that all textarea controls in the administration interface would automatically
resize to fit their contents. It was really neat and worked well, although we
both talked about moving it into a radiant extension so that it could easily be
used by others.</p>

<p>Getting started creating radiant extensions is really easy thanks to the
generator that is provided. In a couple of hours, armed with my favourite text
editor and a rubygems.org account the extension was published as a gem and
ready to use. Here&#8217;s how you go about using it:</p>

<p>Either create or get hold of an existing radiant project. The extension should
work with radiant version 0.9 or greater, then simply run:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gem install radiant-autoresize_textarea-extension</span></code></pre></td></tr></table></div></figure>


<p>Now add the following line to your <code>config/environment.rb</code></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>config.gem radiant-autoresize_textarea-extension, :lib =&gt; false</span></code></pre></td></tr></table></div></figure>


<p>Now we&#8217;re almost done, we just need to run update on our extension to
copy over the required files.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rake radiant:extensions:autoresize_textarea:update</span></code></pre></td></tr></table></div></figure>


<p>Also, if I could think of a better name instead of &#8220;autoresize_textarea&#8221; I would have named it something else, add a note with your suggestion if you can think of one.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Messing around with Project Euler]]></title>
    <link href="http://www.mariovisic.com/blog/2010/09/10/messing-around-with-project-euler/"/>
    <updated>2010-09-10T00:00:00+08:00</updated>
    <id>http://www.mariovisic.com/blog/2010/09/10/messing-around-with-project-euler</id>
    <content type="html"><![CDATA[<p>So I got a little bit bored today and wanted a change to my daily routine. I realised that I haven’t done any Project Euler problems in quite a while. If you don’t know what Project Euler is and you’re into programming or math <a href="http://projecteuler.net/index.php?section=about">then have a read over here</a>.</p>

<p>It’s basically a great way to practise your math and programming skills. You can compete with your friends also which is fun :) I started when my friend <a href="http://tyknowles.com/">Tyson</a> suggested he could solve me than me.</p>

<p>I’ve been solving my euler problems in Ruby because … well why not? Today I managed to solve 3 problems, taking my grand total to <strong>33 out of a possible 300 problems</strong>. &lt;=== Sounds more exciting when it’s in bold, right?</p>

<p>So while solving all these problems i’m slowly developing a set of simple libraries that are used across multiple problems. Seems to be saving me a bit of time now. The helper libraries (well only 1 at the moment) <a href="http://github.com/mariovisic/Project-Euler-Ruby-Helpers">are available over at github</a>.</p>
]]></content>
  </entry>
  
</feed>

