<?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>Whomwah.com &#187; howto</title>
	<atom:link href="http://whomwah.com/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://whomwah.com</link>
	<description>The website of Duncan Robertson, currently computing for the BBC</description>
	<lastBuildDate>Fri, 06 Jan 2012 12:55:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fixing the trailing slash in Nginx</title>
		<link>http://whomwah.com/2010/07/05/fixing-the-trailing-slash-in-nginx/</link>
		<comments>http://whomwah.com/2010/07/05/fixing-the-trailing-slash-in-nginx/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 10:16:35 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=1975</guid>
		<description><![CDATA[The solution as usual is super simple. The problem I was having was that when you didn&#8217;t put a trailing slash on a url, it would not handle it and throw a 404. I saw lots of fixes with complex re-write rules, but it turns out that a simple fix for me was to add [...]]]></description>
			<content:encoded><![CDATA[<p>The solution as usual is super simple. The problem I was having was that when you didn&#8217;t put a trailing slash on a url, it would not handle it and throw a 404. I saw lots of fixes with complex re-write rules, but it turns out that a simple fix for me was to add this to my .conf file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># http://wiki.nginx.org/NginxHttpCoreModule#server_name_in_redirect</span>
server_name_in_redirect off;</pre></div></div>

<p>So your *.conf would look like this</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  listen  <span style="color: #000000;">80</span>;
  server_name  localhost;
  ...
  server_name_in_redirect off;
  ...
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2010/07/05/fixing-the-trailing-slash-in-nginx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Nokogiri on CentOS5</title>
		<link>http://whomwah.com/2008/11/13/installing-nokogiri-on-centos5/</link>
		<comments>http://whomwah.com/2008/11/13/installing-nokogiri-on-centos5/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 09:45:52 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=736</guid>
		<description><![CDATA[Nokogiri is an HTML, XML, SAX, and Reader parser with XPath and CSS selector support. It claims to be a drop in replacement for Hpricot, and it claims to be faster. I think the latter has been addressed but the drop-in bit, well. You see, the Hpricot&#8217;s gem had always in the past, just installed, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nokogiri.rubyforge.org/nokogiri/">Nokogiri</a> is an HTML, XML, SAX, and Reader parser with XPath and CSS selector support. It claims to be a drop in replacement for <a href="http://code.whytheluckystiff.net/hpricot/">Hpricot</a>, and it claims to be faster. I think the latter has been addressed but the drop-in bit, well. You see, the Hpricot&#8217;s gem had always in the past, just installed, but with Nokogiri I had dependency problems. Turns out I needed a few extra libs that were not installed on my machine. Here&#8217;s how I got things going again:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># It seems you need the latest version of rubygems
sudo gem update --system
# and some RPM's
sudo yum install libxml libxml-devel libxslt libxslt-devel
# now the gem should install ok
sudo gem install nokogiri</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2008/11/13/installing-nokogiri-on-centos5/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Installing daemontools on CentOS5 x86_64</title>
		<link>http://whomwah.com/2008/11/04/installing-daemontools-on-centos5-x86_64/</link>
		<comments>http://whomwah.com/2008/11/04/installing-daemontools-on-centos5-x86_64/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 20:43:36 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[daemontools]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[slicehost]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=719</guid>
		<description><![CDATA[[UPDATE] It turns out you need to apply the patch below on any recent Linux distribution, not just 64 bit architectures, if that helps anyone. More head scratching, web searching, friend asking, and huzzah, finally solved. How to actually install daemonstools on my SliceHost CentOS5 slice. The catch for me was that it wouldn&#8217;t compile [...]]]></description>
			<content:encoded><![CDATA[<p class="update">[UPDATE] It turns out you need to apply the patch below on any recent Linux distribution, not just 64 bit architectures, if that helps anyone.</a></p>
<p>More head scratching, web searching, friend asking, and huzzah, finally solved. How to actually install <a href="http://cr.yp.to/daemontools.html">daemonstools</a> on my <a href="http://slicehost.com">SliceHost</a> CentOS5 slice. The catch for me was that it wouldn&#8217;t compile because &#8216;it required <a href="http://www.qmail.org/moni.csi.hu/pub/glibc-2.3.1/daemontools-0.76.errno.patch">a patch</a>&#8216;. Who&#8217;d of known? So here&#8217;s my notes:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ sudo mkdir -p /package
$ sudo chmod 1755 /package/
$ cd /package/
$ sudo wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
$ sudo tar xzf daemontools-0.76.tar.gz
$ sudo wget http://www.qmail.org/moni.csi.hu/pub/glibc-2.3.1/daemontools-0.76.errno.patch
$ cd admin/daemontools-0.76
$ sudo patch -p1 &lt; ../../daemontools-0.76.errno.patch
$ sudo rm ../../daemontools-0.76.errno.patch ../../daemontools-0.76.tar.gz
$ sudo ./package/install
...
...
Adding svscanboot to inittab...
init should start svscan now.</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2008/11/04/installing-daemontools-on-centos5-x86_64/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Installing Python&#8217;s Twisted on CentOS5 x86_64</title>
		<link>http://whomwah.com/2008/10/26/installing-pythons-twisted-on-centos5-x86_64/</link>
		<comments>http://whomwah.com/2008/10/26/installing-pythons-twisted-on-centos5-x86_64/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 09:43:45 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=657</guid>
		<description><![CDATA[I had to do a bit of searching to find the correct way to install Twisted on a 64 bit CentOS 5 machine, like the one I have via virtual hosting with SliceHost. But once I had the answers it was very actually very simple, so this should save you the same headache. I was [...]]]></description>
			<content:encoded><![CDATA[<p>I had to do a bit of searching to find the correct way to install <a href="http://twistedmatrix.com/trac/">Twisted</a> on a 64 bit <a href="http://www.centos.org">CentOS</a> 5 machine, like the one I have via virtual hosting with <a href="http://www.slicehost.com">SliceHost</a>. But once I had the answers it was very actually very simple, so this should save you the same headache.</p>
<p>I was having an import problem with Twisted&#8217;s subpackages, and was also initially having a problem building the lib from source. The first problem was caused by the fact that 64 bit CentOS installs things in both /usr/lib and /usr/lib64 which confuses Twisted, as it expects things in the same directory. The final problems was due to me trying to compile Twisted without the python-devel lib and the <a href="http://twistedmatrix.com/projects/core/documentation/upgrades/2.0/components.html">Twisted Zope Interfaces which is a dependancy</a>.</p>
<p>So to install, run these commands:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ sudo yum install python-devel python-crypto pyOpenSSL zope
$ mkdir src;cd src
$ wget http://tmrc.mit.edu/mirror/twisted/Twisted/8.1/Twisted-8.1.0.tar.bz2
$ tar jxvf Twisted-8.1.0.tar.bz2
$ cd Twisted-8.1.0
$ sudo python setup.py install --install-lib /usr/lib64/python2.4</pre></div></div>

<p>Bingo, and you should now be able to test with:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">$ python
...
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> twisted
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> twisted.<span style="color: black;">web</span></pre></div></div>

<p>The lines above should give you no output.</p>
]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2008/10/26/installing-pythons-twisted-on-centos5-x86_64/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Installing MySQL gem on CentOS</title>
		<link>http://whomwah.com/2008/10/13/installing-mysql-gem-on-centos/</link>
		<comments>http://whomwah.com/2008/10/13/installing-mysql-gem-on-centos/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 09:20:24 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=649</guid>
		<description><![CDATA[Old news, but you&#8217;d be surprised how many times the same: Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. ... error brings everything to a halt. Well on Centos the way to install the MySQL gem is: $ sudo yum install mysql mysql-devel gcc ... &#160; # 32 [...]]]></description>
			<content:encoded><![CDATA[<p>Old news, but you&#8217;d be surprised how many times the same:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Could <span style="color:#9966CC; font-weight:bold;">not</span> create Makefile due to some reason, probably lack of
necessary libraries <span style="color:#9966CC; font-weight:bold;">and</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#9966CC; font-weight:bold;">or</span> headers.
...</pre></div></div>

<p>error brings everything to a halt. Well on <a href="http://www.centos.org">Centos</a> the way to install the <a href="http://www.tmtm.org/en/mysql/ruby/">MySQL gem</a> is:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ sudo yum install mysql mysql<span style="color:#006600; font-weight:bold;">-</span>devel gcc
...
&nbsp;
<span style="color:#008000; font-style:italic;"># 32 bit machine</span>
$ sudo gem install mysql <span style="color:#006600; font-weight:bold;">--</span> \
<span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006600; font-weight:bold;">--</span>with<span style="color:#006600; font-weight:bold;">-</span>mysql<span style="color:#006600; font-weight:bold;">-</span><span style="color:#9966CC; font-weight:bold;">include</span>=<span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>mysql \
<span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006600; font-weight:bold;">--</span>with<span style="color:#006600; font-weight:bold;">-</span>mysql<span style="color:#006600; font-weight:bold;">-</span>lib=<span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>mysql
&nbsp;
<span style="color:#008000; font-style:italic;"># or 64 bit like they are on SliceHost</span>
$ sudo gem install mysql <span style="color:#006600; font-weight:bold;">--</span> \
<span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006600; font-weight:bold;">--</span>with<span style="color:#006600; font-weight:bold;">-</span>mysql<span style="color:#006600; font-weight:bold;">-</span><span style="color:#9966CC; font-weight:bold;">include</span>=<span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>mysql \
<span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006600; font-weight:bold;">--</span>with<span style="color:#006600; font-weight:bold;">-</span>mysql<span style="color:#006600; font-weight:bold;">-</span>lib=<span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>lib64<span style="color:#006600; font-weight:bold;">/</span>mysq
&nbsp;
Building native extensions.  <span style="color:#9900CC;">This</span> could take a <span style="color:#9966CC; font-weight:bold;">while</span>...
<span style="color:#9900CC;">Successfully</span> installed mysql<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">2.7</span>
<span style="color:#006666;">1</span> gem installed
...</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2008/10/13/installing-mysql-gem-on-centos/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Setting the timezone on CentOS</title>
		<link>http://whomwah.com/2008/10/01/setting-the-timezone-on-centos/</link>
		<comments>http://whomwah.com/2008/10/01/setting-the-timezone-on-centos/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 11:51:29 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=582</guid>
		<description><![CDATA[I forget this pretty much all the time, even though it&#8217;s a fairly simple operation. There are loads of timezone data files stored in: /usr/share/zoneinfo So for my CentOS install, to set my machine to London time, I use: # # this is not correct for me # $ date Wed Oct 1 07:43:58 CDT [...]]]></description>
			<content:encoded><![CDATA[<p>I forget this pretty much all the time, even though it&#8217;s a fairly simple operation. There are loads of timezone data files stored in:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">/usr/share/zoneinfo</pre></div></div>

<p>So for my <a href="http://www.centos.org/">CentOS</a> install, to set my machine to London time, I use:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># this is not correct for me</span>
<span style="color:#008000; font-style:italic;">#</span>
$ date
Wed Oct  <span style="color:#006666;">1</span> 07:<span style="color:#006666;">43</span>:<span style="color:#006666;">58</span> CDT <span style="color:#006666;">2008</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># to fix it</span>
<span style="color:#008000; font-style:italic;">#</span>
$ sudo rm <span style="color:#006600; font-weight:bold;">/</span>etc<span style="color:#006600; font-weight:bold;">/</span>localtime
$ sudo ln <span style="color:#006600; font-weight:bold;">-</span>s <span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>share<span style="color:#006600; font-weight:bold;">/</span>zoneinfo<span style="color:#006600; font-weight:bold;">/</span>Europe<span style="color:#006600; font-weight:bold;">/</span>London <span style="color:#006600; font-weight:bold;">/</span>etc<span style="color:#006600; font-weight:bold;">/</span>localtime
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># now check it's ok</span>
<span style="color:#008000; font-style:italic;">#</span>
$ date
Wed Oct  <span style="color:#006666;">1</span> <span style="color:#006666;">12</span>:<span style="color:#006666;">42</span>:<span style="color:#006666;">33</span> GMT <span style="color:#006666;">2008</span></pre></div></div>

<p>I imagine this works on <a href="http://www.redhat.com/">Redhat</a> and <a href="http://fedoraproject.org/">Fedora</a> as well, but I can&#8217;t be sure on other Linux distros.</p>
]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2008/10/01/setting-the-timezone-on-centos/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Twammer, sending stuff from Twitter to Yammer</title>
		<link>http://whomwah.com/2008/09/28/twammer-sending-stuff-from-twitter-to-yammer/</link>
		<comments>http://whomwah.com/2008/09/28/twammer-sending-stuff-from-twitter-to-yammer/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 19:12:25 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jabber]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[xmpp]]></category>
		<category><![CDATA[yammer]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=564</guid>
		<description><![CDATA[I use Twitter. I don&#8217;t really post much, but I do like to dip in and hear what my friends are doing. Yammer is like a private Twitter for companies. We have just had a network set up for the BBC, which is interesting. Again, I like the idea of posting what I am doing [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://twitter.com/whomwah">Twitter</a>. I don&#8217;t really post much, but I do like to dip in and hear what <a href="http://twitter.com/whomwah/friends">my friends</a> are doing. <a href="https://www.yammer.com/">Yammer</a> is like a private Twitter for companies. We have just had a network set up for the <a href="http://bbc.co.uk/">BBC</a>, which is interesting. Again, I like the idea of posting what I am doing and dipping into what other people are doing around the organisation. </p>
<p>So you can see my problem, I&#8217;m doubling up here a bit. When I post something to <a href="http://twitter.com/">Twitter</a>, and I think it would be relevant for work too, I don&#8217;t want to have to open a different interface and post it again. Now there are services like <a href="http://ping.fm/">ping.fm</a> which will sync every site you belong to, but I what to decide what gets posted at work and what doesn&#8217;t in this instance. The simple answer is to build something that looks at <a href="http://twitter.com/statuses/user_timeline/47983.rss">my Twitter feed</a> and if it sees anything new, then posts it off to Yammer. My friend <a href="http://www.aelius.com/njh/">Mr Humfrey</a> does that very thing. I wanted more than this though, I wanted to filter, plus I wanted to make it easy to use, so I have written <a href="http://code.whomwah.com/ruby/twammer">this very simple app</a> that does the job:</p>
<ol>
<li>Read my Twitter feed every n minutes for changes</li>
<li>Keep messages with my chosen keyword</li>
<li>Remove keyword, and send off to Yammer</li>
</ol>
<p><a href="http://code.whomwah.com/ruby/twammer">Twammer</a> usage:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Display help</span>
.<span style="color:#006600; font-weight:bold;">/</span>twammer <span style="color:#006600; font-weight:bold;">-</span>h
&nbsp;
<span style="color:#008000; font-style:italic;"># check Twitter messages with last 5 mins (default)</span>
<span style="color:#008000; font-style:italic;"># filter by #bbc but don't send anything to Yammer</span>
.<span style="color:#006600; font-weight:bold;">/</span>twammer <span style="color:#006600; font-weight:bold;">-</span>t 47983 <span style="color:#006600; font-weight:bold;">-</span>u user <span style="color:#006600; font-weight:bold;">-</span><span style="color:#CC0066; font-weight:bold;">p</span> pass <span style="color:#006600; font-weight:bold;">-</span>f bbc <span style="color:#006600; font-weight:bold;">-</span>q
&nbsp;
<span style="color:#008000; font-style:italic;"># check Twitter messages within last 10 mins</span>
<span style="color:#008000; font-style:italic;"># send anything to Yammer. Show output</span>
.<span style="color:#006600; font-weight:bold;">/</span>twammer <span style="color:#006600; font-weight:bold;">-</span>t 47983 <span style="color:#006600; font-weight:bold;">-</span>u user <span style="color:#006600; font-weight:bold;">-</span><span style="color:#CC0066; font-weight:bold;">p</span> pass <span style="color:#006600; font-weight:bold;">-</span>d <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">-</span>v</pre></div></div>

<p>This is designed to be run as a <a href="http://en.wikipedia.org/wiki/Cron">cron</a> job. You must also make sure you run it at the same interval as the &#8211;delay in the app. Here&#8217;s what my crontab looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">0,5,10,15,20,25,30,35,40,45,50,55 <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006600; font-weight:bold;">/</span>home<span style="color:#006600; font-weight:bold;">/</span>duncan<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>twammer <span style="color:#006600; font-weight:bold;">-</span>t 47983 <span style="color:#006600; font-weight:bold;">-</span>u user <span style="color:#006600; font-weight:bold;">-</span><span style="color:#CC0066; font-weight:bold;">p</span> pass <span style="color:#006600; font-weight:bold;">-</span>f bbc <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>dev<span style="color:#006600; font-weight:bold;">/</span>null</pre></div></div>

<p class="update">[UPDATE] Changed to using the correct API instead of scraping the RSS</p>
]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2008/09/28/twammer-sending-stuff-from-twitter-to-yammer/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Shuffling an Array in Ruby</title>
		<link>http://whomwah.com/2006/11/10/shuffling-an-array-in-ruby/</link>
		<comments>http://whomwah.com/2006/11/10/shuffling-an-array-in-ruby/#comments</comments>
		<pubDate>Fri, 10 Nov 2006 11:40:56 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Open source]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=299</guid>
		<description><![CDATA[[UPDATE] Someone called NoKarma and perraultd have posted even nicer versions on the Code Snippets site, thanks! class Array def shuffle sort_by &#123; rand &#125; end &#160; def shuffle! self.replace shuffle end end I had a situation when I need to shuffle the contents of an array to randomize the stuff inside. After hunting and [...]]]></description>
			<content:encoded><![CDATA[<p class="update">[UPDATE] Someone called NoKarma and perraultd have posted even nicer versions on the <a href="http://www.bigbold.com/snippets/posts/show/2994#comments">Code Snippets</a> site, thanks!</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> shuffle
    sort_by <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#CC0066; font-weight:bold;">rand</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> shuffle!
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">replace</span> shuffle
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I had a situation when I need to shuffle the contents of an array to randomize the stuff inside. After hunting and hacking the final solution appeared to be:</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> shuffle!
    size.<span style="color:#9900CC;">downto</span><span style="color:#006600; font-weight:bold;">&#40;</span>1<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>n<span style="color:#006600; font-weight:bold;">|</span> push delete_at<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">rand</span><span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So you just enhance the <a href="http://www.ruby-doc.org/core/classes/Array.html">Array Class</a> and give it a new funky method <em>shuffle!</em> so you can do stuff like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span>,<span style="color:#006666;">4</span>,<span style="color:#006666;">5</span>,<span style="color:#006666;">6</span>,<span style="color:#006666;">7</span>,<span style="color:#006666;">8</span>,<span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>
a.<span style="color:#9900CC;">shuffle</span>!
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">5</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">8</span>, <span style="color:#006666;">7</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">1</span>, <span style="color:#006666;">6</span>, <span style="color:#006666;">4</span>, <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>Just how cool is <a href="http://www.ruby-lang.org/en/">Ruby</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2006/11/10/shuffling-an-array-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another tag cloud script for Ruby on Rails</title>
		<link>http://whomwah.com/2006/07/06/another-tag-cloud-script-for-ruby-on-rails/</link>
		<comments>http://whomwah.com/2006/07/06/another-tag-cloud-script-for-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 06 Jul 2006 08:09:06 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://whomwah.com/?p=286</guid>
		<description><![CDATA[Or any other Ruby program really. I know there are attempts already out there but none that really suited my purposes. I needed a simple way of creating that tag-cloud-look for many situations. I needed a tag cloud by size or by colour and I didn&#8217;t want it to do everything, just provide me with [...]]]></description>
			<content:encoded><![CDATA[<p>Or any other <a href="http://www.ruby-lang.org/">Ruby</a> program really. I know there are <a href="http://blog.craz8.com/articles/2005/10/28/acts_as_taggable-is-a-cool-piece-of-code">attempts already out there</a> but none that really suited my purposes. I needed a simple way of creating that tag-cloud-look for many situations. I needed a <a href="http://en.wikipedia.org/wiki/Tag_cloud">tag cloud</a> by size or by colour and I didn&#8217;t want it to do everything, just provide me with the style attributes I needed to get the job done. Below is an example of what gets returned by default:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span>70<span style="color: #00AA00;">,</span>70<span style="color: #00AA00;">,</span>70<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>Here&#8217;s the code; it comes with no warranty.</p>
<p>With all these tags cloud scripts you really only need 3 parameters:</p>
<ol>
<li>The total counts of items &#8211; For example you have 10 tags each that has been used numerous times. The total counts would be all of the uses added together</li>
<li>The minimum count of items in a batch &#8211; Using the example above this would be a count of the uses for the tag that has been used least</li>
<li>The maximum count of items in a batch  &#8211; Using the example above this would be a count of the uses for the tag that has been used most</li>
</ol>
<p>Below is the actual script and then below that I have stuck a quick example of how you could use it.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> font_size_for_tag_cloud<span style="color:#006600; font-weight:bold;">&#40;</span> total, lowest, highest, options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#9966CC; font-weight:bold;">if</span> total.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> highest.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> lowest.<span style="color:#0000FF; font-weight:bold;">nil</span>?
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># options</span>
  maxf = options.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:max_font_size</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> 14
  minf = options.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:min_font_size</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> 11
  maxc = options.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:max_color</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006600; font-weight:bold;">&#91;</span> 0, 0, 0 <span style="color:#006600; font-weight:bold;">&#93;</span>
  minc = options.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:min_color</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006600; font-weight:bold;">&#91;</span> 156, 156, 156 <span style="color:#006600; font-weight:bold;">&#93;</span>
  hide_sizes = options.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:hide_sizes</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  hide_colours = options.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:hide_colours</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># function to work out rgb values</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> rgb_color<span style="color:#006600; font-weight:bold;">&#40;</span> a, b, i, x<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#9966CC; font-weight:bold;">if</span> i <span style="color:#006600; font-weight:bold;">&lt;</span>= 1 <span style="color:#9966CC; font-weight:bold;">or</span> x <span style="color:#006600; font-weight:bold;">&lt;</span>= 1
    <span style="color:#9966CC; font-weight:bold;">if</span> a <span style="color:#006600; font-weight:bold;">&amp;</span> b
      a<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Math</span>.<span style="color:#9900CC;">log</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">-</span>b<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#CC00FF; font-weight:bold;">Math</span>.<span style="color:#9900CC;">log</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">floor</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Math</span>.<span style="color:#9900CC;">log</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>b<span style="color:#006600; font-weight:bold;">-</span>a<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#CC00FF; font-weight:bold;">Math</span>.<span style="color:#9900CC;">log</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span>a<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">floor</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># work out colours</span>
  c = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">&#40;</span>0..2<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> c <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> rgb_color<span style="color:#006600; font-weight:bold;">&#40;</span> minc<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span>, maxc<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span>, total, highest <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  colors = c.<span style="color:#9900CC;">compact</span>.<span style="color:#9900CC;">empty</span>? ? minc.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span> : c.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># work out the font size</span>
  spread = highest.<span style="color:#9900CC;">to_f</span> <span style="color:#006600; font-weight:bold;">-</span> lowest.<span style="color:#9900CC;">to_f</span>
  spread = 1.<span style="color:#9900CC;">to_f</span> <span style="color:#9966CC; font-weight:bold;">if</span> spread <span style="color:#006600; font-weight:bold;">&lt;</span>= 0
  fontspread = maxf.<span style="color:#9900CC;">to_f</span> <span style="color:#006600; font-weight:bold;">-</span> minf.<span style="color:#9900CC;">to_f</span>
  fontstep = spread <span style="color:#006600; font-weight:bold;">/</span> fontspread
  size = <span style="color:#006600; font-weight:bold;">&#40;</span> minf <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#40;</span> total.<span style="color:#9900CC;">to_f</span> <span style="color:#006600; font-weight:bold;">/</span> fontstep <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_i</span>
  size = maxf <span style="color:#9966CC; font-weight:bold;">if</span> size <span style="color:#006600; font-weight:bold;">&gt;</span> maxf
  <span style="color:#008000; font-style:italic;">#</span>
  <span style="color:#008000; font-style:italic;"># display the results</span>
  size_txt = <span style="color:#996600;">&quot;font-size:#{ size.to_s }px;&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> hide_sizes
  color_txt = <span style="color:#996600;">&quot;color:rgb(#{ colors });&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> hide_colours
  <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#91;</span> size_txt, color_txt <span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>and now a quick example of it&#8217;s use in a rails view. This code assumes the db find call looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@foo</span> = Foo.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:all</span>,
  :<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'*, COUNT(DISTINCT(i.id)) AS item_cnt'</span>,
  <span style="color:#ff3333; font-weight:bold;">:joins</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'AS f INNER JOIN bars AS b ON f.id=b.foo_id'</span>,
  <span style="color:#ff3333; font-weight:bold;">:group</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'b.id'</span>,
  <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'item_cnt DESC'</span>,
  <span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">50</span>
<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Below just loop through your db results and calls <em>font_size_for_tag_cloud</em> for each item, passing in the required parameters. There are a few options available but if you leave them out you should still see something useful.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&lt;ul&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">for</span> f <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#0066ff; font-weight:bold;">@foo</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= content_tag<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'li'</span>, f.<span style="color:#9900CC;">some_label</span>, <span style="color:#ff3333; font-weight:bold;">:style</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> font_size_for_tag_cloud<span style="color:#006600; font-weight:bold;">&#40;</span> f.<span style="color:#9900CC;">bars</span>.<span style="color:#9900CC;">size</span>, 
  f.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">count_items</span>, 
  f.<span style="color:#9900CC;">last</span>.<span style="color:#9900CC;">count_items</span>,  
<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
&lt;/ul&gt;</pre></div></div>

<p>That&#8217;s it! I guess I should turn it into a plugin but hey, there&#8217;s to much reading to be done on <a href="http://www.ryandaigle.com/articles/2006/06/30/whats-new-in-edge-rails-activeresource-is-here">ActiveResource</a> at the moment heyhey!</p>
]]></content:encoded>
			<wfw:commentRss>http://whomwah.com/2006/07/06/another-tag-cloud-script-for-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

