<?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>Mike's Blog &#187; Tech</title>
	<atom:link href="http://www.mikeheijmans.com/category/tech/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikeheijmans.com</link>
	<description>A site about everything and nothing at all</description>
	<lastBuildDate>Mon, 27 Sep 2010 04:54:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using $LOAD_PATH for better library loading in ruby</title>
		<link>http://www.mikeheijmans.com/2010/09/using-load_path-for-better-library-loading-in-ruby/</link>
		<comments>http://www.mikeheijmans.com/2010/09/using-load_path-for-better-library-loading-in-ruby/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 04:54:29 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/?p=168</guid>
		<description><![CDATA[Today I discovered the beauty of $LOAD_PATH in ruby. Here is the problem: I created a couple of libraries for an app I&#8217;m working on and put them in a ./lib directory and they reference each other like this: ##./lib/lib-a.rb## require &#8216;lib-b&#8217; &#8230;lib does stuff with classes included in lib-b&#8230; ##./lib/lib-b.rb## require &#8216;lib-a&#8217; &#8230;lib does [...]]]></description>
			<content:encoded><![CDATA[<p>Today I discovered the beauty of $LOAD_PATH in ruby.</p>
<p><strong>Here is the problem:</strong></p>
<p>I created a couple of libraries for an app I&#8217;m working on and put them in a ./lib directory and they reference each other like this:</p>
<p>##./lib/lib-a.rb##<br />
require &#8216;lib-b&#8217;<br />
&#8230;lib does stuff with classes included in lib-b&#8230;</p>
<p>##./lib/lib-b.rb##<br />
require &#8216;lib-a&#8217;<br />
&#8230;lib does stuff with classes included in lib-a&#8230;</p>
<p>##main.rb##<br />
require &#8216;./lib/lib-a&#8217;<br />
&#8230;use lib-a which tries using lib-b&#8230;</p>
<p>Well when I&#8217;m in the top-level directory and try including one of the libraries it won&#8217;t work because lib-a.rb will look for lib-b.rb in the current directory and it doesn&#8217;t know to look in ./lib</p>
<p>If I change lib-a.rb to call require &#8216;./lib/lib-b&#8217; it will work from the main script because it knows how to get to lib-b from the top level directory.</p>
<p>The real problem is that the application is bound by that top level directory now. If I try to make a test in ./tests/test.rb like this:</p>
<p>##./tests/test.rb##<br />
require &#8216;../lib/lib-a.rb&#8217;</p>
<p>The problem is that lib-a is looking for lib-b in ./tests/lib/ because of the ./lib reference&#8230;.</p>
<p>The basic problem here is that, even though we are using relative paths, the paths are like absolute paths relative to the current directory. We need to avoid such relative paths as much as absolute paths in our code. How do we do this?</p>
<p><strong>The solution:</strong></p>
<p>The ruby require uses the global variable $LOAD_PATH to figure out where to look for libraries. $LOAD_PATH is an array of directories that you can add to to get your libraries loaded properly without any directory spec in the require statement. Here is an example:</p>
<p>##./lib/lib-a.rb##<br />
require &#8216;lib-b&#8217;</p>
<p>##./lib/lib-b.rb##<br />
require &#8216;lib-a&#8217;</p>
<p>##main.rb##<br />
$LOAD_PATH << &#8216;./lib&#8217;<br />
require &#8216;lib-a&#8217;</p>
<p>##./tests/test.rb##<br />
$LOAD_PATH << &#8216;../lib&#8217;<br />
require &#8216;lib-a&#8217;</p>
<p>This will set up the load path to be passed to everything properly so that ruby can just work its magic. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2010/09/using-load_path-for-better-library-loading-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write tests and save time</title>
		<link>http://www.mikeheijmans.com/2009/08/write-tests-and-save-time/</link>
		<comments>http://www.mikeheijmans.com/2009/08/write-tests-and-save-time/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 23:12:21 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/?p=148</guid>
		<description><![CDATA[I never could understand why developers didn&#8217;t write tests. The concept of a test is simple. You write a little extra code now that tests the outcome you want or have so that, in the future, when you add a feature or decide to refactor into something simpler or better, you know that you didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I never could understand why developers didn&#8217;t write tests. The concept of a test is simple. You write a little extra code now that tests the outcome you want or have so that, in the future, when you add a feature or decide to refactor into something simpler or better, you know that you didn&#8217;t break anything without having to walk through all the test cases by hand.</p>
<p>There are two approaches to writing tests and one of them is more conducive to test writing then the other.</p>
<p>The first way is to write your application code first then write the tests to back it up. The first problem with this is a matter of motivation really. After writing all the application code and making it work, I find it very hard to motivate myself to write the little extra bit of tests instead of diving right in to the new feature on the roadmap. Why write the tests after you know it works? Well, again, what if you have to wedge a feature in there or refactor? Then you have to recall all the stuff that you tested by hand while you were building it and then test it again, by hand, or write tests at that point and Murphy&#8217;s law says that you will forget at least one critical case the second time around.  That is why the second choice is the better.</p>
<p>The second way to develop with tests is to write the tests for the functionality that you want and then write the code to make the tests pass. This is the Agile approach and, in my opinion, the better. Why? Well, you are writing tests based on requirements. So you will know as soon as your code does what you want. Second, you are writing tests based on what you are encountering while writing the application. This lends itself to more coverage because you will be writing tests for all the little edge cases you will encounter while writing the application. This means that, in the future, when you refactor or go muddling around, you can verify, RIGHT THEN, if you broke anything.</p>
<p>I have heard managers complain about developers spending time on tests and not on features first because users and clients won&#8217;t see the tests and time should be spent on user/client features. Well, here is the reality, a little time spent at the beginning of a project writing tests saves a lot of time in the end because you don&#8217;t need to spend so much time verifying feature requirements while writing. Plus the QA process is much faster and smoother because you are handing of working code from the beginning. Writing tests at the beginning usually saves me more than 10% time on the same project where I write the application code only with no tests! That is 10% faster to release and ensures better user experience in the long run because I verified that the project is doing what it should and handling errors properly before I even wrote the application!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2009/08/write-tests-and-save-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Damnit Bluehost and your gem updates!</title>
		<link>http://www.mikeheijmans.com/2009/07/damnit-bluehost-and-your-gem-updates/</link>
		<comments>http://www.mikeheijmans.com/2009/07/damnit-bluehost-and-your-gem-updates/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 23:31:12 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/2009/07/damnit-bluehost-and-your-gem-updates/</guid>
		<description><![CDATA[I host some stuff with bluehost and I have to say that I am pretty fed up with them and shared hosting! I know shared hosting is never a good idea but for something as simple as http://isitabugorfeature.com it should be a non-issue. Bluehost has &#8220;rails support&#8221; but the assholes keep updating gems without letting [...]]]></description>
			<content:encoded><![CDATA[<p>I host some stuff with bluehost and I have to say that I am pretty fed up with them and shared hosting! I know shared hosting is never a good idea but for something as simple as http://isitabugorfeature.com it should be a non-issue. Bluehost has &#8220;rails support&#8221; but the assholes keep updating gems without letting anyone know and there isn&#8217;t a list or anything I can subscribe to that would let me know about these sort of very relevant updates. I have been burned again.</p>
<p>Today someone mentioned to me that bug or feature was down and I logged in and found that, sure enough, they had updated the rails gem. So I changed my gem requirement in my environment.rb file but my app relies on some 2.2.2 specific stuff so it wouldn&#8217;t start. So, I am forced to get the rails-2.2.2 tag from github and put it in vendor/rails to get the site back up again. I am so tired of this. I am done with bluehost and shared hosting. I am going to begin migrating everything to my slicehost slices and call it a day.</p>
<p>Goodbye bluehost, I would love to say it was all great but I can&#8217;t&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2009/07/damnit-bluehost-and-your-gem-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HellaNZB and HellaTweet</title>
		<link>http://www.mikeheijmans.com/2009/01/hellanzb-and-hellatweet/</link>
		<comments>http://www.mikeheijmans.com/2009/01/hellanzb-and-hellatweet/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 22:49:39 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/2009/01/hellanzb-and-hellatweet/</guid>
		<description><![CDATA[Over the weekend I was playing around with my media server, bigsur. I use HellaNZB as my downloader and I really wanted a way to know when things are finished downloading. I thought to myself, wouldn&#8217;t it be nice to have my mediaserver ping me somehow when it is done downloading and processing an nzb? [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend I was playing around with my media server, bigsur. I use HellaNZB as my downloader and I really wanted a way to know when things are finished downloading. I thought to myself, wouldn&#8217;t it be nice to have my mediaserver ping me somehow when it is done downloading and processing an nzb? I then went on a search for such an application and could not find it. Could I be the first in need of such an application? Surely someone has built it&#8230; no? I couldn&#8217;t find a thing. So I decided to build my own notifier using twitter. That&#8217;s right&#8230; a twitter feed for my media server. I call it HellaTweet and you can download it from <a href="http://hellatweet.mikeheijmans.com/">hellatweet.mikeheijmans.com</a>. </p>
<p><img style="max-width: 800px;" src="http://img.skitch.com/20090120-md6thjhx3ae6k92186skr1pwiu.jpg" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2009/01/hellanzb-and-hellatweet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Socks Proxy over SSH &#8211; Mac/Linux HowTo</title>
		<link>http://www.mikeheijmans.com/2009/01/socks-proxy-over-ssh-maclinux-howto/</link>
		<comments>http://www.mikeheijmans.com/2009/01/socks-proxy-over-ssh-maclinux-howto/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 22:44:27 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/2009/01/socks-proxy-over-ssh-maclinux-howto/</guid>
		<description><![CDATA[Here is the problem. You are at work or visiting your mom back in your home state and you want to get access to your home network. You could: spend hours/days/years making a vpn work using a consumer grade vpn router which, lets face it, is a cheapo unreliable piece of hardware. buy a $500+ [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the problem. You are at work or visiting your mom back in your home state and you want to get access to your home network. You could:</p>
<ul>
<li>spend hours/days/years making a vpn work using a consumer grade vpn router which, lets face it, is a cheapo unreliable piece of hardware.</li>
<li>buy a $500+ commercial grade vpn appliance</li>
<li>spend hours/days/years building your own router using linux and add a vpn server to that</li>
</ul>
<p><b><br />OR</b></p>
<p><font face="sans-serif">You can use ssh to create a socks proxy. </p>
<p>What is a socks proxy? Socks is an internet protocol that facilitates the routing of network packets&nbsp; between client-server applications via a proxy server.</p>
<p>The first requirement is an open ssh server. You can use ssh on your router (if it has the feature &#8211; look at <a target="_blank" href="http://openwrt.org/">OpenWRT</a> if not) or you can forward the ssh port from a server inside your network using the router. Most routers have port forwarding so this is the easiest solution. Make sure you set up something like <a target="_blank" href="http://www.dyndns.com/">dyndns</a> so that you don&#8217;t have to remember your ip address. Plus most isp&#8217;s use dynamic ip addresses so your ip will change from time to time and dyndns will allow that to happen without you needing to do a thing.</p>
<p>Now that you can ssh to your home network you want to setup the tunnel. In the terminal you want to use the -D command to set the local socks port. Here is an example:</p>
<p></font><br />
<blockquote><font face="sans-serif">ssh -D 1080 -p 22 username@homenetwork.net</font></p></blockquote>
<p><font face="sans-serif"><br />In the example 1080 is the port for your socks proxy to accept connections and 22 is ssh port that you are connecting to. Lastly is your username and host to connect to. Once you have logged in to the machine you can minimize the window.</p>
<p>Next, in firefox&#8217;s Preferrences -&gt; Advanced -&gt; Network -&gt; Settings Window or your computer&#8217;s network proxy settings. You configure the socks proxy as 127.0.0.1 port 1080. </p>
<p>That&#8217;s it. Now when you browse the internet the packet is going to the machine you connected to via ssh first. This means that you are browsing as if you were at that machine. You can then browse to local ip addresses in your home network and access those pages. For example, if your router&#8217;s status page is at 192.168.1.1/status you can type that in the url and get that page. Try it. <br /></font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2009/01/socks-proxy-over-ssh-maclinux-howto/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Look for the New Year</title>
		<link>http://www.mikeheijmans.com/2009/01/new-look-for-the-new-year/</link>
		<comments>http://www.mikeheijmans.com/2009/01/new-look-for-the-new-year/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 21:23:29 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/?p=117</guid>
		<description><![CDATA[If you are one of my regular readers, I am sure that you have noticed that I changed my blog&#8217;s look. I felt it was time for a change for 2009. (Plus my old theme had a bug that pissed me off) This new theme is a tweaked version of the carrington theme featured on [...]]]></description>
			<content:encoded><![CDATA[<p>If you are one of my regular readers, I am sure that you have noticed that I changed my blog&#8217;s look. I felt it was time for a change for 2009. (Plus my old theme had a bug that pissed me off) This new theme is a tweaked version of the <a title="Carrington Theme Site" href="http://carringtontheme.com/">carrington</a> theme featured on the wordpress theme site.  I tweaked the layout to match my style as you can see from the darker body background with the white content box and the full width footer. The problem is that the theme doesn&#8217;t seem to render properly in Internet Exploder. Stoopid microsoft :=/ I don&#8217;t support that browser anyway and if you are reading my blog with Internet Explorer&#8230; you should switch to <a href="http://www.getfirefox.com">Firefox</a>, It is far superior! I have verified that it works great in Firefox and Safari. So enjoy the new look.</p>
<p><a href="http://www.apple.com/safari/download/"><img class="alignnone size-full wp-image-118" title="Safari - Better than Internet Exploder" src="http://www.mikeheijmans.com/wp-content/uploads/2009/01/safari-logo.jpg" alt="safari = good" width="95" height="95" /></a><a href="http://www.getfirefox.com"><img class="alignnone size-full wp-image-119" title="FireFox - Better than Internet Exploder" src="http://www.mikeheijmans.com/wp-content/uploads/2009/01/firefox-logo.jpg" alt="firefox = good" width="87" height="87" /></a><a title="IE=EVIL" href="http://toastytech.com/evil/index.html" target="_blank"><img class="alignnone size-full wp-image-121" title="Get outta here with that crap!" src="http://www.mikeheijmans.com/wp-content/uploads/2009/01/no-ie2-1.jpg" alt="IE = bad" width="85" height="84" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2009/01/new-look-for-the-new-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Club Nintendo Fail!</title>
		<link>http://www.mikeheijmans.com/2008/12/club-nintendo-fail/</link>
		<comments>http://www.mikeheijmans.com/2008/12/club-nintendo-fail/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 00:08:36 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Video Games]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/2008/12/club-nintendo-fail/</guid>
		<description><![CDATA[Much like many people, I got a Nintendo WII for the holidays and much like most of those people I attempted to signup for club nintendo &#8211; club.nintendo.com. I say attempted because nintendo doesn&#8217;t seem to know how to run a java web application or they didn&#8217;t plan for the kind of hit their application [...]]]></description>
			<content:encoded><![CDATA[<p>Much like many people, I got a Nintendo WII for the holidays and much like most of those people I attempted to signup for club nintendo &#8211; club.nintendo.com. I say attempted because nintendo doesn&#8217;t seem to know how to run a java web application or they didn&#8217;t plan for the kind of hit their application would receive after the holiday rush. I have been trying to register my wii serial number with them to extend my warranty and create my family account all day only to be met with 500 error after 500 error. The worst part is that they didn&#8217;t even create a custom error page. It is the standard error document. You will also notice that there was a 404 when the server attempted to fetch the error page it is supposed to display. It is bad enough that they can&#8217;t keep their app servers running but because of the sorry error document handling, I FAIL YOU NINTENDO!</p>
<p><img src="http://img.skitch.com/20081231-bbjiim466piea95unegd2tj9wr.jpg" alt="" width="400" height="186" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2008/12/club-nintendo-fail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OpenWRT and DynDNS</title>
		<link>http://www.mikeheijmans.com/2008/12/openwrt-and-dyndns/</link>
		<comments>http://www.mikeheijmans.com/2008/12/openwrt-and-dyndns/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 00:11:47 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/?p=108</guid>
		<description><![CDATA[I have a Linksys WRT54G router and thanks to OpenWRT, its just about the best piece of home networking hardware I have. I recently moved and had to switch to DynDNS account for OpenWRT was very heavy. I&#8217;m an Engineer so I decided to make a really simple implementation of 2 scripts. A checker that [...]]]></description>
			<content:encoded><![CDATA[<p>I have a Linksys WRT54G router and thanks to OpenWRT, its just about the best piece of home networking hardware I have. I recently moved and had to switch to DynDNS account for OpenWRT was very heavy. I&#8217;m an Engineer so I decided to make a really simple implementation of 2 scripts. A checker that runs every 15 minutes to verify that DynDNS is up to date and an updater script to update it if that check fails. After reading the api documention on DynDNS.com, I realized that it should be cake. Put them both in the /bin directory on your router. Here are the files.</p>
<p>(substitute your parameters)</p>
<p><script src="http://gist.github.com/14091.js"></script></p>
<p>Lastly add this to your /etc/crontabs/root file:</p>
<p>0,15,30,45 * * * * /bin//check_dns.sh &gt; /dev/null<br />
0 1 * * 1 /bin/update_dns.sh &gt; /dev/null</p>
<p>The first line will add your check for every 15 minutes and the second will run the update every Monday morning at 1:00A.M. to keep your account up to date.</p>
<p>And there you have it. Easy and simple. The lightest weight DynDNS updater for your OpenWRT router.</p>
<p>(P.S. You can use this on any *NIX system with a little tweaking)</p>
<p>Links:<br />
OpenWRT &#8211; <a href="http://openwrt.org">http://openwrt.org</a><br />
DynDNS &#8211; <a href="http://dyndns.com">http://dyndns.com</a><br />
Gist Repo &#8211; <a href="http://gist.github.com/14091">http://gist.github.com/14091</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2008/12/openwrt-and-dyndns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I want my ruby</title>
		<link>http://www.mikeheijmans.com/2008/11/i-want-my-ruby/</link>
		<comments>http://www.mikeheijmans.com/2008/11/i-want-my-ruby/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 20:04:05 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/2008/11/i-want-my-ruby/</guid>
		<description><![CDATA[I have been working on a jms consumer for a tibco server that can monitor and do some calculations on the fly based on what is on the bus and I am going insane. I have to write the thing in java and I want remove my eyes with a spork&#8230; I forgot how annoying [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a jms consumer for a tibco server that can monitor and do some calculations on the fly based on what is on the bus and I am going insane. I have to write the thing in java and I want remove my eyes with a spork&#8230; I forgot how annoying static languages are and all I want is my ruby language back. Why does tibco jms have to be so java&#8230; I would settle for python at this point. I hate java.</p>
<p>public void static main(String[] args) {<br />
System.out.println(&#8220;Kill me&#8221;); }</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2008/11/i-want-my-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting TinyUrl&#8217;s in Rails</title>
		<link>http://www.mikeheijmans.com/2008/09/getting-tinyurls-in-rails/</link>
		<comments>http://www.mikeheijmans.com/2008/09/getting-tinyurls-in-rails/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 22:59:49 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.mikeheijmans.com/?p=103</guid>
		<description><![CDATA[If you have used twitter I am sure you have noticed that if you post a long url in your update it gets turned in to a tinyurl for you. This is really cool functionality and I have created a helper in rails to do it for me. First, let&#8217;s talk about how you get [...]]]></description>
			<content:encoded><![CDATA[<p>If you have used twitter I am sure you have noticed that if you post a long url in your update it gets turned in to a tinyurl for you. This is really cool functionality and I have created a helper in rails to do it for me.</p>
<p>First, let&#8217;s talk about how you get a tinyurl. Tinyurl has a really simple api that you can call that will return a tiny url. It is rediculous how simple it is. You just call this url with a GET: http://tinyurl.comapi-create.php?url=http://example.com</p>
<p>The returned page will be a single line with the tinyurl equivalent. It is that simple. Now on to the rails part.</p>
<p>In your application.rb helper you would add this:</p>
<p>require &#8216;net/http&#8217;<br />
require &#8216;uri&#8217;</p>
<p>def tinyfy(newurl)<br />
&nbsp;&nbsp;&nbsp;url = URI.parse(&#8216;http://tinyurl.com/&#8217;)<br />
&nbsp;&nbsp;&nbsp;res = Net::HTTP.start(url.host, url.port) {|http|<br />
&nbsp;&nbsp;&nbsp;http.get(&#8216;/api-create.php?url=&#8217; + newurl)<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;if res.body.empty?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#tinyurl is not responding properly&#8230; Return the original url<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return newurl<br />
&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return res.body<br />
&nbsp;&nbsp;&nbsp;end<br />
end</p>
<p>
Now if you call the tinyfy method in your app, let&#8217;s say in your view, with the url you want to tinyurlify as the parameter the return will be the tinyurl. I take this one step further and have the tinyfy method make the url a link by adding the &#8216;a&#8217; tags in the method like so:</p>
<p>require &#8216;net/http&#8217;<br />
require &#8216;uri&#8217;</p>
<p>def tinyfy(newurl)<br />
&nbsp;&nbsp;&nbsp;url = URI.parse(&#8216;http://tinyurl.com/&#8217;)<br />
&nbsp;&nbsp;&nbsp;res = Net::HTTP.start(url.host, url.port) {|http|<br />
&nbsp;&nbsp;&nbsp;http.get(&#8216;/api-create.php?url=&#8217; + newurl)<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;if res.body.empty?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#tinyurl is not responding properly&#8230; Return the original url<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return &#8216;&lt;a href=&#8217; + newurl + &#8216;&gt;&#8217; + newurl + &#8216;&lt;/a&gt;&#8217;<br />
&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return &#8216;&lt;a href=&#8217; + res.body + &#8216;&gt;&#8217; + res.body + &#8216;&lt;/a&gt;&#8217;<br />
&nbsp;&nbsp;&nbsp;end<br />
end</p>
<p>
That will return a nice linked tinyurl in your view. That is all there is to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeheijmans.com/2008/09/getting-tinyurls-in-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

