<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>redemption in a blog</title>
	
	<link>http://blog.codefront.net</link>
	<description>Ruby, Rails, Firefox, Anime, Mac</description>
	<lastBuildDate>Fri, 25 May 2012 02:59:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/riab" /><feedburner:info uri="riab" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Friab" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Friab" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Friab" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/riab" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Friab" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Friab" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Friab" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
		<title>Summer 2011 anime (and some from Spring 2011)</title>
		<link>http://feedproxy.google.com/~r/riab/~3/dnaUQxpVlUE/</link>
		<comments>http://blog.codefront.net/2011/07/12/summer-2011-anime-and-some-from-spring-2011/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 10:43:30 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Anime]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1346</guid>
		<description><![CDATA[Some of you might know that I&#8217;m a rabid anime fan. I don&#8217;t talk much about it on this blog (actually, I don&#8217;t talk much on this blog anymore, seeing as I haven&#8217;t blogged this year). Anyway, yeah, one of my biggest passions and failings is my love for anime and I can&#8217;t stop myself [...]]]></description>
				<content:encoded><![CDATA[<p>Some of you <a href="http://blog.codefront.net/about/">might know</a> that I&#8217;m a rabid anime fan. I don&#8217;t talk much about it on this blog (actually, I don&#8217;t talk much on this blog <em>anymore</em>, seeing as I haven&#8217;t blogged <em>this year</em>). Anyway, yeah, one of my biggest passions and failings is my love for anime and I can&#8217;t stop myself from collecting those <a href="http://www.goodsmile.info/product/en/2499/Nendoroid+Saber+Lily.html">cute</a> <a href="http://www.goodsmile.info/product/en/2040/Nendoroid+Yoko.html">Nendoroids</a> too.</p>
<p>This summer 2011 season, I&#8217;m watching 4 new series and 2 older series that started in spring 2011, Hanasaku Iroha and Nichijou:</p>
<p><a href="http://blog.codefront.net/wp-content/uploads/2011/07/currently-watching-anime-summer-2011.png"><img src="http://blog.codefront.net/wp-content/uploads/2011/07/currently-watching-anime-summer-2011.png" alt="Currently watching anime, Summer 2011" title="Currently watching anime, Summer 2011" width="510" height="510" class="alignnone size-full wp-image-1355" /></a></p>
<p>Top row: <a href="http://myanimelist.net/anime/10162/Usagi_Drop">Usagi Drop</a>, <a href="http://myanimelist.net/anime/10721/Mawaru_Penguindrum">Mawaru Penguindrum</a>, <a href="http://myanimelist.net/anime/9938">Ikoku Meiro no Croisée</a>.<br />
Bottom row: <a href="http://myanimelist.net/anime/10161/No.6">No.6</a>, <a href="http://myanimelist.net/anime/9289">Hanasaku Iroha</a>, <a href="http://myanimelist.net/anime/10165">Nichijou</a>.</p>
<p>I&#8217;m a sucker for the <a href="http://en.wikipedia.org/wiki/Slice_of_life">slice of life</a> genre (5 out of 6 series above are &#8220;slice of life&#8221;). Usagi Drop in particular is very promising &#8211; looking forward to how Daikichi and Rin&#8217;s story unfolds. Mawaru Penguindrum is probably the winner in terms of &#8220;interestingness&#8221; though &#8211; after all, it has penguins. After the brilliant <a href="http://myanimelist.net/anime/9989/Ano_Hi_Mita_Hana_no_Namae_wo_Bokutachi_wa_Mada_Shiranai">Ano Hana</a> from spring 2011, Usagi Drop is looking to be my mainstay for this season.</p>
<p>If you&#8217;re an anime fan, please leave a comment on what you&#8217;re watching or <a href="http://twitter.com/chuyeow">ping me on twitter</a> (I&#8217;m <a href="http://twitter.com/chuyeow">@chuyeow</a>) &#8211; I&#8217;d love to know what you guys like to watch when you&#8217;re not coding.</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/dnaUQxpVlUE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2011/07/12/summer-2011-anime-and-some-from-spring-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2011/07/12/summer-2011-anime-and-some-from-spring-2011/</feedburner:origLink></item>
		<item>
		<title>Firefox nightly builds add a combined Stop/Go/Refresh button to the Location Bar</title>
		<link>http://feedproxy.google.com/~r/riab/~3/Bf9NuPXt2Lg/</link>
		<comments>http://blog.codefront.net/2010/09/20/firefox-nightly-builds-add-a-combined-stopgorefresh-button-to-the-location-bar/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 06:22:13 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1322</guid>
		<description><![CDATA[In an effort to streamline Firefox&#8217;s UI, the latest Firefox nightly builds have moved the Stop/Refresh button into the right corner of the Location Bar. I like this move even if the Firefox developers are simply copying design ideas from other browsers (in this case, I believe Safari was first). When you&#8217;re typing in the [...]]]></description>
				<content:encoded><![CDATA[<p>In an effort to streamline Firefox&#8217;s UI, the latest Firefox nightly builds have moved the Stop/Refresh button into the right corner of the Location Bar. I like this move even if the Firefox developers are simply copying design ideas from other browsers (in this case, I believe Safari was first).</p>
<p>When you&#8217;re typing in the Location Bar, a green Go button is shown:<br />
<img src="http://blog.codefront.net/wp-content/uploads/2010/09/Screen-shot-2010-09-20-at-PM-01.46.57.png" alt="" title="Firefox Location Bar Go button" width="359" height="69" class="aligncenter size-full wp-image-1324" /></p>
<p>That switches to a red Stop button when the page is loading:<br />
<img src="http://blog.codefront.net/wp-content/uploads/2010/09/Screen-shot-2010-09-20-at-PM-01.47.20.png" alt="" title="Firefox Location Bar Stop button" width="360" height="37" class="aligncenter size-full wp-image-1325" /></p>
<p>The thin line you see in the location bar is a progress indicator that indicates how much of the current web page has loaded &#8211; I don&#8217;t like the way it looks and I think it&#8217;ll probably change in future.</p>
<p>When the page has fully loaded, it changes to a Refresh button:<br />
<img src="http://blog.codefront.net/wp-content/uploads/2010/09/Screen-shot-2010-09-20-at-PM-02.12.02.png" alt="" title="Firefox Location Bar Refresh button active" width="364" height="33" class="aligncenter size-full wp-image-1329" /></p>
<p>This leaves a minimalist and compact toolbar:<br />
<img src="http://blog.codefront.net/wp-content/uploads/2010/09/Screen-shot-2010-09-20-at-PM-02.19.48.png" alt="" title="Firefox 4 beta 7 toolbar" width="487" height="38" class="aligncenter size-full wp-image-1334" /></p>
<p>I should actually remove the Home button &#8211; I don&#8217;t ever use it.</p>
<p>To try out the new stuff coming in Firefox, download a <a href="http://nightly.mozilla.org/">Firefox nightly build</a> now.</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/Bf9NuPXt2Lg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2010/09/20/firefox-nightly-builds-add-a-combined-stopgorefresh-button-to-the-location-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2010/09/20/firefox-nightly-builds-add-a-combined-stopgorefresh-button-to-the-location-bar/</feedburner:origLink></item>
		<item>
		<title>Rendering plists from your Rails app</title>
		<link>http://feedproxy.google.com/~r/riab/~3/V52T_N8USks/</link>
		<comments>http://blog.codefront.net/2010/06/14/rendering-plists-from-your-rails-app/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 03:22:50 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1315</guid>
		<description><![CDATA[Jeena emailed me recently about his Rails plugin, plistifier, that allows you to render plists (property lists). It allows you to render your ActiveRecord objects as plists (among other things): def show @post = Post.find(params[:id]) respond_to do &#124;format&#124; format.xml { render :xml =&#62; @post } format.plist { render :plist =&#62; @post } end end Jeena [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://github.com/jeena/">Jeena</a> emailed me recently about his Rails plugin, <a href="http://github.com/jeena/plistifier">plistifier</a>, that allows you to render <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html">plists</a> (property lists).</p>
<p>It allows you to render your ActiveRecord objects as plists (among other things):</p>
<pre><code class="ruby">def show
  @post = Post.find(params[:id])

  respond_to do |format|
    format.xml   { render :xml =&gt; @post }
    format.plist { render :plist =&gt; @post }
  end
end</code></pre>
<p>Jeena was kind enough to let me know he &#8220;stole&#8221; my old <a href="http://blog.codefront.net/2007/07/11/better-json-output-from-rails-with-the-jsonifier-plugin/">Jsonifier plugin</a> (<a href="http://github.com/chuyeow/jsonifier">github</a>) code in <a href="http://github.com/jeena/plistifier">plistifier</a>.</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/V52T_N8USks" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2010/06/14/rendering-plists-from-your-rails-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2010/06/14/rendering-plists-from-your-rails-app/</feedburner:origLink></item>
		<item>
		<title>Railscasts Xcode theme</title>
		<link>http://feedproxy.google.com/~r/riab/~3/8SuGAmbZL7w/</link>
		<comments>http://blog.codefront.net/2010/02/04/railscasts-xcode-theme/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 14:12:27 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1291</guid>
		<description><![CDATA[For those of you who use the excellent Railscasts TextMate theme and want to replicate the theme in Xcode, you can grab my version from Github. This is what it looks like: Save it into ~/Library/Application Support/Xcode/Color Themes/, restart Xcode, and open its Preferences. You will be able to pick the Railscasts Color Theme in [...]]]></description>
				<content:encoded><![CDATA[<p>For those of you who use the excellent <a href="http://railscasts.com/about">Railscasts TextMate theme</a> and want to replicate the theme in Xcode, you can grab my version <a href="http://gist.github.com/raw/294642/4956c43399c3cfa7d248fb581b23054e5bfa92ab/Railscasts.xccolortheme">from Github</a>. This is what it looks like:</p>
<p><a href="http://blog.codefront.net/wp-content/uploads/2010/02/Railscasts-Xcode-e1265292666981.png"><img src="http://blog.codefront.net/wp-content/uploads/2010/02/Railscasts-Xcode-e1265292666981.png" alt="Railscasts Xcode theme" title="Railscasts Xcode" width="510" height="440" class="aligncenter size-full wp-image-1292" /></a></p>
<p>Save it into <code>~/Library/Application Support/Xcode/Color Themes/</code>, restart Xcode, and open its Preferences. You will be able to pick the Railscasts Color Theme in the Fonts &#038; Colors tab.</p>
<p>I dug this theme up after realizing that I haven&#8217;t actually saved the Railscasts theme I&#8217;d replicated from several months ago and was too lazy to set up another one in my other Mac.</p>
<p><a href="http://blog.10to1.be/">Koen Van Der Auwera</a> did a similar theme too so if you find that mine doesn&#8217;t work so well (I&#8217;ve only used it for Cocoa Touch development, not at all for developing Mac apps), scoot over to his <a href="http://blog.10to1.be/cocoa/2009/09/25/railscasts-xcode-theme/">blog post</a>.</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/8SuGAmbZL7w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2010/02/04/railscasts-xcode-theme/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2010/02/04/railscasts-xcode-theme/</feedburner:origLink></item>
		<item>
		<title>Setting up virtualization on Ubuntu with KVM</title>
		<link>http://feedproxy.google.com/~r/riab/~3/FSAtotl_iEM/</link>
		<comments>http://blog.codefront.net/2010/02/01/setting-up-virtualization-on-ubuntu-with-kvm/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 14:18:13 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1271</guid>
		<description><![CDATA[These instructions have been tested on Ubuntu 9.10 (Karmic) 64-bit. Skip right to the instructions if you&#8217;re short on time. After being a happy Xen user for several years now, I&#8217;ve recently had to switch to an alternative virtualization solution. My colleague Arun (@iamclovin) actually struggled for a week with Xen VMs that locked up [...]]]></description>
				<content:encoded><![CDATA[<p>These instructions have been tested on <strong>Ubuntu 9.10 (Karmic) 64-bit</strong>. <a href="#kvm_guide_start">Skip right to the instructions</a> if you&#8217;re short on time.</p>
<p>After being a <a href="http://blog.codefront.net/2007/06/26/installing-xen-on-ubuntu-feisty-fawn-the-complete-newbies-guide/">happy Xen user</a> for several years now, I&#8217;ve recently had to switch to an alternative virtualization solution. My colleague Arun (<a href="http://twitter.com/iamclovin">@iamclovin</a>) actually struggled for a week with Xen VMs that locked up on Hardy; we&#8217;ve had much success with Hardy and Xen before, so we attributed it to a hardware problem since these were our first blade servers.</p>
<p>Out of ideas, we tried Karmic (Ubuntu 9.10) only to discover that Xen support via the apt package system is gone. I went down the path of compiling a <a href="http://wiki.xensource.com/xenwiki/XenParavirtOps">paravirt_ops</a> Dom0 kernel (<a href="http://www.itkovian.net/base/the-xen-hypervisor-with-ubuntu-karmic-koala/">this article</a> was <em>very</em> useful) but ended up deciding the process took far too long despite being successful.</p>
<p>With <a href="http://news.cnet.com/8301-13580_3-9867657-39.html">KVM gaining official support from Ubuntu</a> as <strong>the</strong> virtualization solution, I ended up ditching Xen and switching to <a href="http://www.linux-kvm.org/">KVM</a> for these new servers on Karmic. The rest of the entry is a step-by-step guide on setting up KVM VMs on a Ubuntu server; I&#8217;m putting this down because like all wikis, the <a href="https://help.ubuntu.com/community/KVM">Ubuntu KVM wiki</a> has grown a little too organically to be useful.</p>
<h3 id="kvm_guide_start">Preparing a host server for KVM</h3>
<ol>
<li>
    Update and upgrade apt packages (use your own discretion on whether this is necessary):</p>
<pre><code>aptitude update &#038;&#038; aptitude dist-upgrade</code></pre>
</li>
<li>
    Check whether CPU supports hardware virtualization:</p>
<pre><code>egrep '(vmx|svm)' --color=always /proc/cpuinfo</code></pre>
<p>    You should see lines with either &#8220;vmx&#8221; or &#8220;svm&#8221; highlighted.
  </li>
<li>
    Install these packages:</p>
<pre><code>aptitude install kvm libvirt-bin ubuntu-vm-builder bridge-utils</code></pre>
<p>    If you see a <code>FATAL: Error inserting kvm_intel</code> message during installation, it means that virtualization is not enabled in your machine&#8217;s BIOS. You&#8217;ll need to reboot your machine, enter the BIOS setup and enable virtualization (you&#8217;ll have to hunt for the option).<br />
    <a href="http://blog.codefront.net/wp-content/uploads/2010/02/BIOS-virtualization-option.png"><img src="http://blog.codefront.net/wp-content/uploads/2010/02/BIOS-virtualization-option.png" alt="" title="BIOS virtualization option" width="399" height="243" class="aligncenter size-full wp-image-1283" /></a><br />
    After enabling virtualization in the BIOS and rebooting, run:</p>
<pre><code>modprobe kvm-intel</code></pre>
<p>    There should be no error shown (in fact, no console response).
  </li>
<li>
    Optionally, install virt-top, a top-like tool for your VMs:</p>
<pre><code>aptitude install virt-top</code></pre>
</li>
<li>
    Verify that you can connect to the hypervisor:</p>
<pre><code>virsh -c qemu:///system list</code></pre>
<p>    You should see something like this:</p>
<pre><code>Connecting to uri: qemu:///system
 Id Name                 State
 ----------------------------------</code></pre>
</li>
<li>
    Setup a network bridge on the server for VMs. Edit <code>/etc/network/interfaces</code> so it looks like this (use your own IPs):</p>
<pre><code>auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
 address 192.168.1.222
 netmask 255.255.255.0
 network 192.168.1.0
 broadcast 192.168.1.255
 gateway 192.168.1.167
 bridge_ports eth0
 bridge_stp off
 bridge_fd 9
 bridge_hello 2
 bridge_maxage 12
 bridge_maxwait 0</code></pre>
</li>
<li>
    Make sure that you have a direct console to the server because you&#8217;re going to restart networking:</p>
<pre><code>/etc/init.d/networking restart</code></pre>
</li>
<li>
    Verify that your changes took place with <code>ifconfig</code>. You should see 2 entries like these:</p>
<pre><code>br0       Link encap:Ethernet  HWaddr 00:11:22:33:44:55
          inet addr:192.168.1.215  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::223:aeff:fefe:1f14/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1099 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:74665 (74.6 KB)  TX bytes:6223 (6.2 KB)

eth0      Link encap:Ethernet  HWaddr 00:66:77:88:99:00
          inet6 addr: fe80::223:aeff:fefe:1f14/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4939 errors:0 dropped:0 overruns:0 frame:0
          TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:532798 (532.7 KB)  TX bytes:5585 (5.5 KB)
          Interrupt:36 Memory:da000000-da012800</code></pre>
</li>
</ol>
<h3>Setting up a VM</h3>
<ol>
<li>
    Setup a VM with <code>vmbuilder</code>:</p>
<pre><code>vmbuilder kvm ubuntu \
    -v \
    --suite=karmic \
    --libvirt=qemu:///system \
    --arch=amd64 \
    --cpus=2 \
    --mem=2048 \
    --swapsize=4096 \
    --rootsize=20480 \
    --flavour=server \
    --hostname=billiejean \
    --ip=192.168.1.240 \
    --mask=255.255.255.0 \
    --net=192.168.1.0 \
    --bcast=192.168.1.255 \
    --gw=192.168.1.167 \
    --dns='202.157.163.157 202.157.131.118' \
    --bridge=br0 \
    --mirror=http://archive.ubuntu.com/ubuntu \
    --components='main,universe' \
    --addpkg=openssh-server \
    --user=administrator \
    --pass=icanhaspasswd \
    --dest=/root/vm-billiejean \
    --tmpfs=-</code></pre>
<p>    The options you need to care about are:</p>
<ol>
<li><code>suite</code>: Version of Ubuntu to install (e.g. karmic, hardy).</li>
<li><code>cpus</code>: Number of CPUs to assign to VM.</li>
<li><code>mem</code>: Amount of RAM in MB to assign to VM.</li>
<li><code>swapsize</code>: Size of swap in MB of VM.</li>
<li><code>rootsize</code>: Size of root filesystem in MB of VM.</li>
<li><code>flavour</code>: The &#8220;flavour&#8221; of kernel to use in the VM. Either &#8220;virtual&#8221; or &#8220;server&#8221;.</li>
<li><code>hostname</code>: Hostname of VM.</li>
<li><code>ip</code>: IP address of VM.</li>
<li><code>mask</code>: Netmask of VM.</li>
<li><code>net</code>: Network of VM.</li>
<li><code>bcast</code>: Broadcast address of VM.</li>
<li><code>gw</code>: Gateway of VM.</li>
<li><code>dns</code>: DNS server(s) for VM.</li>
<li><code>addpkg</code>: APT packages to install in the VM. openssh-server is needed so that we can login to the VM to setup the virsh console.</li>
<li><code>user</code> and <code>pass</code>: User account that&#8217;s setup for you to access the VM.</li>
<li><code>dest</code>: Destination directory on server where VM disk image will reside.</li>
</ol>
</li>
<li>
    If your VM is created successfully, there&#8217;ll be a config file for the VM in <code>/etc/libvirt/qemu/</code> (e.g. <code>/etc/libvirt/qemu/billiejean.xml</code>), and a disk image in the directory specified in the <code>--dest</code> option (e.g. <code>/root/vm-billiejean/disk0.qcow2</code>).
  </li>
<li>
    You can verify that it works by starting the VM and SSHing into it (virsh console will not work yet).</p>
<pre><code>virsh start billiejean</code></pre>
</li>
</ol>
<h3>Converting Disk Images to LVM Logical Volumes</h3>
<p>Now, we have the VM setup but it&#8217;s running off a disk image. For better performance, running the VM off a LVM logical volume will optimize disk IO.</p>
<p>vmbuilder is supposed to support the <code>--raw</code> option to write the VM to a block device (such as a LVM logical volume), but I&#8217;ve had no success with it (as does Mark Imbriaco, sysadmin of 37signals: <a href="http://twitter.com/markimbriaco/status/7437688341">http://twitter.com/markimbriaco/status/7437688341</a> and <a href="http://twitter.com/markimbriaco/status/7437699338">http://twitter.com/markimbriaco/status/7437699338</a>). We&#8217;re going to convert the disk images using qemu-img and write the bits into a LVM logical volume instead.</p>
<ol>
<li>Stop the VM if it&#8217;s running:
<pre><code>virsh shutdown billiejean</code></pre>
</li>
<li>Convert the VM&#8217;s qcow2 (QEMU image format) disk image to a raw disk image:
<pre><code>qemu-img convert disk0.qcow2 -O raw disk0.raw</code></pre>
</li>
<li>Create a logical volume to house the VM, making sure it&#8217;s big enough for the VM&#8217;s rootsize and swapsize options:
<pre><code>lvcreate -L24GB -n &lt;logical_volume_name&gt; &lt;volume_group_name&gt;</code></pre>
</li>
<li>Copy raw image into the logical volume:
<pre><code>dd if=disk0.raw of=/dev/&lt;volume_group_name&gt;/&lt;logical_volume_name&gt; bs=1M</code></pre>
<p>      This will take awhile (the bigger your image, the longer it takes).</li>
<li>Edit the VM&#8217;s config so that it uses your new logical volume:
<pre><code>virsh edit billiejean</code></pre>
<p>    Change <code>&lt;disk&gt;</code> to point to the logical volume:</p>
<pre><code>&lt;disk type='block' device='disk'&gt;
  &lt;source dev='/dev/&lt;volume_group_name&gt;/&lt;logical_volume_name&gt;'/&gt;
  &lt;target dev='hda' bus='ide'/&gt;
&lt;/disk&gt;</code></pre>
</li>
<li>Startup the VM. You might wanna rename the original <code>disk0.qcow2</code> image first just to make sure your VM isn&#8217;t still using it.</li>
<li>Once you&#8217;re sure your VM is running off your LVM logical volume, you can delete or backup the original qcow2 disk image.</li>
</ol>
<h3>Getting a console to your VM from the Host Server</h3>
<p>Now, we have to setup the VM so that virsh console works. This is a console to the VM from the host server that works even when the networking in the VM is not.</p>
<ol>
<li>Edit the VM&#8217;s settings:
<pre><code>virsh edit billiejean</code></pre>
<p>    In the <code>&lt;devices&gt;</code> block, add:</p>
<pre><code>&lt;serial type='pty'&gt;
  &lt;target port='0'/&gt;
&lt;/serial&gt;</code></pre>
</li>
<li>Startup your VM:
<pre><code>virsh start billiejean</code></pre>
</li>
<li>SSH into VM and create a file <code>/etc/init/ttyS0.conf</code>:
<pre><code>start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -8 38400 ttyS0 vt102</code></pre>
<p>      Start the tty with:</p>
<pre><code>start ttyS0</code></pre>
</li>
<li>Still in the VM, install acpid so that the VM will respond to shutdown commands from the server:
<pre><code>aptitude install acpid</code></pre>
</li>
<li>Reboot the VM.</li>
<li>Verify the console works by opening a console to the VM from the server:
<pre><code>virsh console billiejean</code></pre>
<p>      You may have to hit &#8220;Enter&#8221; before you see any console output.
  </li>
</ol>
<h3>Miscellaneous VM Setup</h3>
<p>That&#8217;s it, your VM is ready! You&#8217;ll probably want to do these:</p>
<ul>
<li>Set a root password and possibly delete the user you setup using <code>vmbuilder</code>.</li>
<li>Set the timezone with <code>dpkg-reconfigure tzdata</code>.</li>
</ul>
<img src="http://feeds.feedburner.com/~r/riab/~4/FSAtotl_iEM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2010/02/01/setting-up-virtualization-on-ubuntu-with-kvm/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2010/02/01/setting-up-virtualization-on-ubuntu-with-kvm/</feedburner:origLink></item>
		<item>
		<title>Stop and Reload buttons merged in Firefox</title>
		<link>http://feedproxy.google.com/~r/riab/~3/VgaKEdR8vrc/</link>
		<comments>http://blog.codefront.net/2010/01/14/stop-and-reload-buttons-merged-in-firefox/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 10:41:53 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1265</guid>
		<description><![CDATA[A minor UI improvement to Firefox has been made to Firefox and it&#8217;s currently only available on nightly builds of Firefox: the Stop and Reload buttons have been merged into a single button. This change should make it into Firefox 3.6. While a page is loading, the button acts as a Stop button: When it&#8217;s [...]]]></description>
				<content:encoded><![CDATA[<p>A minor UI improvement to Firefox has been made to Firefox and it&#8217;s currently only available on nightly builds of Firefox: the Stop and Reload buttons have been merged into a single button. This change should make it into Firefox 3.6.</p>
<p>While a page is loading, the button acts as a Stop button:<br />
<a href="http://blog.codefront.net/wp-content/uploads/2010/01/Firefox-merged-stop-reload-stop.png"><img src="http://blog.codefront.net/wp-content/uploads/2010/01/Firefox-merged-stop-reload-stop.png" alt="" title="Firefox merged stop-reload stop" width="294" height="262" class="aligncenter size-full wp-image-1266" /></a></p>
<p>When it&#8217;s done loading, it becomes a Reload button.<br />
<a href="http://blog.codefront.net/wp-content/uploads/2010/01/Firefox-merged-stop-reload-reload.png"><img src="http://blog.codefront.net/wp-content/uploads/2010/01/Firefox-merged-stop-reload-reload.png" alt="" title="Firefox merged stop-reload reload" width="295" height="231" class="aligncenter size-full wp-image-1267" /></a></p>
<p>I&#8217;m always up for 1 less unnecessary button. I think this feature is copied from Safari (I might be wrong).</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/VgaKEdR8vrc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2010/01/14/stop-and-reload-buttons-merged-in-firefox/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2010/01/14/stop-and-reload-buttons-merged-in-firefox/</feedburner:origLink></item>
		<item>
		<title>Firefox quick tip: view images in a new tab quickly</title>
		<link>http://feedproxy.google.com/~r/riab/~3/3yDfHNJ0IDY/</link>
		<comments>http://blog.codefront.net/2009/11/25/firefox-quick-tip-view-images-in-a-new-tab-quickly/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 11:13:21 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1183</guid>
		<description><![CDATA[A mini-tip on viewing images quickly in a new tab in Firefox. Useful for web devs who want to look at the URL of an image quickly. As an example, here&#8217;s the Youtube webpage of the owner of Maru the Cat: To open the thumbnail image of Maru in a new tab, right-click the image, [...]]]></description>
				<content:encoded><![CDATA[<p>A mini-tip on viewing images quickly in a new tab in Firefox. Useful for web devs who want to look at the URL of an image quickly.</p>
<p>As an example, here&#8217;s the <a href="http://www.youtube.com/user/mugumogu">Youtube webpage</a> of the owner of <a href="http://en.wikipedia.org/wiki/Maru_the_Cat">Maru the Cat</a>:</p>
<p><img src="http://blog.codefront.net/wp-content/uploads/2009/06/ff3-middle-click-step-1.png" alt="ff3-middle-click-step-1" title="ff3-middle-click-step-1" width="320" height="148" class="alignnone size-full wp-image-1186" /></p>
<p>To open the thumbnail image of Maru in a new tab, right-click the image, and then <strong>middle-click</strong> the <strong>View Image</strong> item from the context menu:</p>
<p><img src="http://blog.codefront.net/wp-content/uploads/2009/06/ff3-middle-click-step-2.png" alt="ff3-middle-click-step-2" title="ff3-middle-click-step-2" width="416" height="222" class="alignnone size-full wp-image-1185" /></p>
<p>It should open up in a new tab:</p>
<p><img src="http://blog.codefront.net/wp-content/uploads/2009/06/ff3-middle-click-step-3.png" alt="ff3-middle-click-step-3" title="ff3-middle-click-step-3" width="507" height="226" class="alignnone size-full wp-image-1184" /></p>
<p>You can also do the same for background images (middle-click <strong>View Background Image</strong> from the right-click context menu).</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/3yDfHNJ0IDY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/11/25/firefox-quick-tip-view-images-in-a-new-tab-quickly/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2009/11/25/firefox-quick-tip-view-images-in-a-new-tab-quickly/</feedburner:origLink></item>
		<item>
		<title>How my simple iPhone app made it to the top of the App Store</title>
		<link>http://feedproxy.google.com/~r/riab/~3/iZvWkYeVikA/</link>
		<comments>http://blog.codefront.net/2009/09/22/singtel-data-usage-iphone-app/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 14:26:33 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1223</guid>
		<description><![CDATA[Slightly more than a month back I wrote this little iPhone app (App Store link), almost a toy app really, to check the usage of my data plan with my local telco (Singtel). I wanted to scratch an itch and I also really didn&#8217;t want to exceed my data plan &#8211; the fees are excessive. [...]]]></description>
				<content:encoded><![CDATA[<p>Slightly more than a month back I wrote <a href="http://sliceoflifeapps.com/iphone/datausage/">this little iPhone app</a> (<a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=327567068&#038;mt=8&#038;uo=6">App Store link</a>), almost a toy app really, to check the usage of my data plan with my local telco (Singtel). I wanted to scratch an itch and I also <em>really</em> didn&#8217;t want to exceed my data plan &#8211; the fees are <em>excessive</em>.</p>
<p>Anyway, I submitted it to the iPhone App Store for approval as a free app and named it <strong>Singtel Data Usage</strong>. No points for creativity with the name but I thought it&#8217;d be nice to know exactly what the app did from just reading its name. After one keyword rejection (which was unfounded but I wasn&#8217;t going to argue with the app reviewers), it finally got approved a few days ago.</p>
<p><img src="http://blog.codefront.net/wp-content/uploads/2009/09/iphone-data-usage.gif" alt="Singtel Data Usage iPhone app screenshot" title="Singtel Data Usage iPhone app screenshot" width="300" height="559" class="aligncenter size-full wp-image-1225" /></p>
<p>Yeah that&#8217;s what it looks like. I stole part of the design from another iPhone app &#8211; can anyone guess which one? I think I spent 80% of development time changing the design over and over again, tweaking font sizes, and agonizing over which icons to use.</p>
<p>Thanks to folks on Twitter (I&#8217;m <a href="http://twitter.com/chuyeow">@chuyeow</a> &#8211; do follow me if you&#8217;re reading my blog), word got around and by the 3rd day of it being approved, my app was the Top Free app on the Singapore App Store. Going to take a time out for the vanity shot:</p>
<p><img src="http://blog.codefront.net/wp-content/uploads/2009/09/Screen-shot-2009-09-22-at-PM-10.39.06.png" alt="" title="" width="510" height="376" class="aligncenter size-full wp-image-1242" /></p>
<p>A similar app, <a href="http://ibbomapp.appspot.com/">iBBOM</a>, was approved around the same time but I believe I got a head start because of all the awesome people on Twitter who retweeted <a href="http://twitter.com/chuyeow/status/4093690396">my tweet</a> and the kind folks who gave glowing reviews on the App Store (thanks especially to <a href="http://deepcalm.com/">Andy Croll</a> for the 1st review). iBBOM actually looks much better than my app (I can&#8217;t help tweeting <a href="http://twitter.com/chuyeow/status/4162960802">about</a> <a href="http://twitter.com/sliceoflifer/status/4119270971">it</a>) and works perfectly (only thing I don&#8217;t like are the ads). I believe I couldn&#8217;t have gotten to the top of the App Store without the guys and gals who spread the word on Twitter.</p>
<p>On to the not so fun part of this post. Yet another similar app, <a href="http://mugunthkumar.com/pages/iPhone_Apps/Entries/2009/7/13_SingTel_BBoM.html">SG BBOM</a>, was <a href="http://www.imerlion.com/2009/09/sg-bbom-app-pulled-from-app-store.html">pulled from the App Store by Singtel</a> (the telco) recently so I&#8217;m expecting to hear from Singtel really soon. We shall see.</p>
<p>In the meantime, if you own an iPhone and have a Singtel data plan, do check out <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=327567068&#038;mt=8&#038;uo=6">my app</a> (App Store link) and give an honest review on the App Store. If you&#8217;ve already downloaded it, I&#8217;d like to know what you think in a review as well. Thanks!</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/iZvWkYeVikA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/09/22/singtel-data-usage-iphone-app/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2009/09/22/singtel-data-usage-iphone-app/</feedburner:origLink></item>
		<item>
		<title>Blog redesigned</title>
		<link>http://feedproxy.google.com/~r/riab/~3/fX7eTY5wOc4/</link>
		<comments>http://blog.codefront.net/2009/07/05/blog-redesigned/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 06:50:00 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1212</guid>
		<description><![CDATA[After 5 long years of using the same old blog theme, which I&#8217;d handcrafted from scratch way back in 2004, I&#8217;ve finally got down to refreshing it to a more contemporary look. I&#8217;ve also updated the woefully outdated About page. Here&#8217;s a before and after shot: I think it&#8217;s much better, definitely more modern and [...]]]></description>
				<content:encoded><![CDATA[<p>After 5 long years of using the same old blog theme, which I&#8217;d handcrafted from scratch way back in 2004, I&#8217;ve finally got down to refreshing it to a more contemporary look. I&#8217;ve also updated the woefully outdated <a href="/about/">About page</a>.</p>
<p>Here&#8217;s a before and after shot:</p>
<p><img src="http://blog.codefront.net/wp-content/uploads/2009/07/blog-theme-before-and-after.png" alt="Blog theme - before and after" title="Blog theme - before and after" width="515" height="659" class="alignnone size-full wp-image-1214" /></p>
<p>I think it&#8217;s much better, definitely more modern and minimalist.</p>
<p>The new blog theme is basically a heavily modified version of the<br />
wonderful and free <a href="http://designdisease.com/blog/compositio-wordpress-theme/">Compositio WordPress theme</a> &#8211;<br />
you can check out a <a href="http://designdisease.com/preview/compositio">demo of Compositio here</a> to see how different it is.</p>
<p>The only thing I kept from my old theme, which I affectionately called &#8220;Clover&#8221;, was the same clover logo. I did that with the shape tool in Photoshop &#8211; it&#8217;s a simple logo and no skill was required to create it, obviously!</p>
<p>If you&#8217;re reading this in a feed reader or one of those aggreggator-type sites, you can help me out by checking out the blog itself and giving me some good old constructive criticism.</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/fX7eTY5wOc4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/07/05/blog-redesigned/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2009/07/05/blog-redesigned/</feedburner:origLink></item>
		<item>
		<title>Upgraded to iPhone OS 3.0 and running out of battery fast?</title>
		<link>http://feedproxy.google.com/~r/riab/~3/Y2pENY7zFGA/</link>
		<comments>http://blog.codefront.net/2009/06/22/upgraded-to-iphone-os-3-0-and-running-out-of-battery-fast/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:31:47 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1177</guid>
		<description><![CDATA[After upgrading my girlfriend&#8217;s iPhone 3G to OS 3.0 recently, I noticed that the iPhone&#8217;s battery was getting depleted really quickly. I&#8217;d left it overnight with Wifi, 3G, Bluetooth, Push Notifications all off, and the battery went from 80% to a jaw-dropping OMGWTFBBQ 10%. I attributed it to the recent jailbreak (I&#8217;ve already removed the [...]]]></description>
				<content:encoded><![CDATA[<p>After upgrading my girlfriend&#8217;s iPhone 3G to OS 3.0 recently, I noticed that the iPhone&#8217;s battery was getting depleted really quickly. I&#8217;d left it overnight with Wifi, 3G, Bluetooth, Push Notifications all off, and the battery went from 80% to a jaw-dropping <em>OMGWTFBBQ</em> 10%.</p>
<p>I attributed it to the recent jailbreak (I&#8217;ve already removed the jailbreak trying to figure out this problem) at first. I only realized something was really wrong when the iPhone&#8217;s battery <strong>started draining while it was charging via USB</strong>!</p>
<p>Looking around on <a href="http://www.urbandictionary.com/define.php?term=interwebs">teh interwebs</a>, I managed to solve it (easily!) by following the suggestions from <a href=" http://discussions.apple.com/message.jspa?messageID=9664702">this thread at the Apple support forums</a>. Here&#8217;s what worked for me:</p>
<ol>
<li>Go to <strong>Settings</strong> on your iPhone.</li>
<li>Turn <strong>Notifications</strong> off. I&#8217;m not sure if this is necessary but did so just in case.</li>
<li>Go to <strong>Mail, Contacts, Calendars</strong> and <strong>delete all your accounts</strong> (I deleted even Calendar accounts just in case). You may want to write down or backup your account settings first.</li>
<li>Go to <strong>Fetch New Data</strong> (also in the same Mail, Contacts, Calendars settings) and make sure <strong>Push</strong> is <strong>Off</strong>.</li>
<li>It&#8217;s probably not necessary but you may want to restart your iPhone (power it on and off) here.</li>
<li>Add back all your accounts. You can turn <strong>Push</strong> back on <strong>Fetch New Data</strong> now.</li>
<li>You can also turn <strong>Notifications</strong> back on if you wish.</li>
</ol>
<p>It seems like the iPhone 3.0 OS update has a bug where email accounts with active push notifications were set to keep fetching new email even if push is turned off explicitly. Hopefully this post will help solve your battery problems, if not, you&#8217;ve gotta keep looking &#8211; the <a href="http://discussions.apple.com/forum.jspa?forumID=1139">Apple iPhone Support forums</a> is a good place to start.</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/Y2pENY7zFGA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/06/22/upgraded-to-iphone-os-3-0-and-running-out-of-battery-fast/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2009/06/22/upgraded-to-iphone-os-3-0-and-running-out-of-battery-fast/</feedburner:origLink></item>
		<item>
		<title>A curl-ier Curb – better cookie support in Curb</title>
		<link>http://feedproxy.google.com/~r/riab/~3/r6OSGyc6gZU/</link>
		<comments>http://blog.codefront.net/2009/06/18/better-cookie-support-in-curb/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 01:42:10 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1144</guid>
		<description><![CDATA[As of Curb 0.3.7, Curb comes with slightly better cookie support that makes it more &#8220;curl-like&#8221;. It probably sounds like shameless self-promotion that I&#8217;m blogging about these changes since I&#8217;d contributed them. Well, yeah that&#8217;s true, but I&#8217;m also doing so because I doubt these changes will ever be made known since Curb doesn&#8217;t publicize [...]]]></description>
				<content:encoded><![CDATA[<p>As of <a href="http://github.com/taf2/curb/tree/master">Curb</a> 0.3.7, Curb comes with slightly better cookie support that makes it more &#8220;<a href="http://curl.haxx.se/">curl</a>-like&#8221;.</p>
<p>It probably sounds like shameless self-promotion that I&#8217;m blogging about these changes since I&#8217;d contributed them. Well, yeah that&#8217;s true, but I&#8217;m also doing so because I doubt these changes will ever be made known since Curb doesn&#8217;t publicize any updates or changelogs. </p>
<p>Curb is my current number 1 HTTP client for Ruby so the more love it gets, the better.</p>
<h3>Passing cookies as a string in Curb requests</h3>
<p>Curl veterans will probably know how to do this with the curl binary:</p>
<pre><code>curl -b "auth=abcdef; ASP.NET_SessionId=lotsatext;" example.com</code></pre>
<p>This sends a request to example.com with 2 cookies named &#8220;auth&#8221; and &#8220;ASP.NET_SessionId&#8221; (I hate those big-ass ASP.NET cookies btw). There wasn&#8217;t a way to set this in Curb, so I looked up the <a href="http://curl.haxx.se/libcurl/c/">libcurl C API docs</a> and replicated the same option in Curb (<a href="http://github.com/taf2/curb/commit/3c3e53c64a2417f78aa19f593a5f66e3ddffc969">commit on Github</a>). An example:</p>
<pre><code class="ruby">curl = Curl::Easy.new('http://example.com/')
curl.cookies = 'auth=abcdef; ASP.NET_SessionId=big-wall-of-text;'
curl.perform</code></pre>
<p>Of course, the cookies will more often be retrieved/constructed rather than a literal like in the example above. In my case, I was proxying cookies while trying to wrap an API around a site that doesn&#8217;t have one.</p>
<h3>Passing cookies as a file via the &#8220;cookiefile&#8221; option</h3>
<p>The second change is the new <code>cookiefile</code> option. This replicates curl commands like these:</p>
<pre><code>curl -b cookies-to-send.txt www.example.com</code></pre>
<p>with something like this in ruby:</p>
<pre><code class="ruby">curl = Curl::Easy.new('http://example.com/')
curl.cookiefile = '/path/to/cookies-to-send.txt'
curl.perform</code></pre>
<p>The cookies file looks like this (you can get a sample with the <code>--cookie-jar</code> option to curl, e.g. <code>curl --cookie-jar cookies.txt www.wego.com</code>):</p>
<pre><code>www.wego.com	FALSE	/	FALSE	0	lang	
www.wego.com	FALSE	/	FALSE	0	user_country_code	SG</code></pre>
<p>Check out the <a href="http://github.com/taf2/curb/commit/a4910c25198441796f8e6d1958e144998833c7ec">commit on Github</a> if you&#8217;re interested.</p>
<h3>Why would I use these?</h3>
<p>Now you might be wondering how these 2 changes are useful &#8211; well, they <em>are</em> totally irrelevant to you if you&#8217;re not expecting any cookie support in Curb. However, if you&#8217;re accessing or scraping a site that uses <strong>cookie-based authentication</strong>, these changes allow you to keep your Curb client authenticated across sessions, even when doing HTTP POSTs (Curb doesn&#8217;t send cookies properly in POST requests even if <code>curl.enable_cookies</code> is set).</p>
<p>I&#8217;ve found these changes to Curb particularly useful since I vastly prefer Curb to most HTTP clients for its speed and lightweight implementation, and heavier scraper-type HTTP clients like <a href="http://mechanize.rubyforge.org/mechanize/">Mechanize</a> are a last resort.</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/r6OSGyc6gZU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/06/18/better-cookie-support-in-curb/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2009/06/18/better-cookie-support-in-curb/</feedburner:origLink></item>
		<item>
		<title>Don’t kill your app when using ActiveRecord in Rails Metal, release your database connections</title>
		<link>http://feedproxy.google.com/~r/riab/~3/rrS2AG92Ksk/</link>
		<comments>http://blog.codefront.net/2009/06/15/activerecord-rails-metal-too-many-connections/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 06:49:51 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1143</guid>
		<description><![CDATA[Rails Metal has been available on Rails since version 2.3 &#8211; it&#8217;s old news. But if you haven&#8217;t used it or heard about it, you can find out more about Rails Metal on the RoR weblog and on Jesse Newland&#8217;s blog. So anyway, I am one of those laggards and only wrote a Rails Metal [...]]]></description>
				<content:encoded><![CDATA[<p>Rails Metal has been available on Rails since version 2.3 &#8211; it&#8217;s old news. But if you haven&#8217;t used it or heard about it, you can find out more about Rails Metal on the <a href="http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal">RoR weblog</a> and on <a href="http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m">Jesse Newland&#8217;s blog</a>.</p>
<p>So anyway, I am one of those laggards and only wrote a Rails Metal piece not too long ago for a Rails app on <a href="http://www.wego.com/">Wego.com</a> in an effort to optimize some high volume requests. It looked something like this:</p>
<pre><code class="ruby">class Adamantine
  def self.call(env)
    if env['PATH_INFO'] =~ ROUTE_REGEX
      location = Location.find(1) # Use ActiveRecord.

      [200, { 'Content-Type' => 'text/html' }, [location.to_json]]
    else
      # Leave it to Rails to deal with the request.
      [404, { 'Content-Type' => 'text/html' }, ['Not Found']]
    end
  end
end</code></pre>
<p>Notice the use of an ActiveRecord model. It ran for quite awhile, almost 30 minutes, in <em>production</em> until I started getting notification emails about &#8220;<strong>Too many open database connections</strong>&#8221; to the MySQL server! The change was promptly rolled back and there was no cheezburger for me.</p>
<p><a href="http://icanhascheezburger.com/2008/04/25/funny-pictures-dam-it-dam-it-dam-it/"><img src="http://icanhascheezburger.wordpress.com/files/2008/04/funny-pictures-beaver-dam-it.jpg" alt="dam it!" /></a></p>
<p>As it turns out, Rails doesn&#8217;t take care of certain things in Rails Metal pieces, including the releasing of connections back to the database connection pool. A bit of googling turned up this <a href="https://rails.lighthouseapp.com/projects/8994/tickets/1882-rails-metal-with-activerecord-too-slow">bug in Rails&#8217; bug tracker</a> (see Josh Peek&#8217;s comment about <code>ActiveRecord::Base.clear_active_connections!</code>).</p>
<p>I rewrote the Rails Metal piece to always ensure it clears any active database connections with <code>ActiveRecord::Base.clear_active_connections!</code>:</p>
<pre><code class="ruby">class Adamantine
  def self.call(env)
    if env['PATH_INFO'] =~ ROUTE_REGEX
      location = Location.find(1)

      [200, { 'Content-Type' => 'text/html' }, [location.to_json]]
    else
      # Leave it to Rails to deal with the request.
      [404, { 'Content-Type' => 'text/html' }, ['Not Found']]
    end
  ensure
    # Release the connections back to the pool.
    ActiveRecord::Base.clear_active_connections!
  end
end</code></pre>
<p>Moral of the story: Don&#8217;t forget to release your database connections if you&#8217;re using ActiveRecord in your Rails Metal. Or even better, don&#8217;t use ActiveRecord in Rails Metal &#8211; you&#8217;re aiming for raw speed anyway right?</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/rrS2AG92Ksk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/06/15/activerecord-rails-metal-too-many-connections/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2009/06/15/activerecord-rails-metal-too-many-connections/</feedburner:origLink></item>
		<item>
		<title>I’m still alive, and on FriendFeed and Twitter</title>
		<link>http://feedproxy.google.com/~r/riab/~3/k2ls-XxTpAA/</link>
		<comments>http://blog.codefront.net/2009/03/24/im-still-alive-and-on-friendfeed-and-twitter/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 14:48:58 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1136</guid>
		<description><![CDATA[Wow, it seems like I haven&#8217;t posted anything this year. Don&#8217;t worry, you aren&#8217;t rid of me yet. I&#8217;m still alive and posting updates to FriendFeed and (less often) to Twitter. If you belong to what I imagine must be now the microscopic population of loyal readers of my blog, please do hook up with [...]]]></description>
				<content:encoded><![CDATA[<p>Wow, it seems like I haven&#8217;t posted anything this year. Don&#8217;t worry, you aren&#8217;t rid of me yet. I&#8217;m still alive and posting updates to <a href="http://friendfeed.com/chuyeow">FriendFeed</a> and (less often) to <a href="http://twitter.com/chuyeow">Twitter</a>.</p>
<p>If you belong to what I imagine must be now the microscopic population of loyal readers of my blog, please do hook up with me on <a href="http://friendfeed.com/chuyeow">FriendFeed</a> or <a href="http://twitter.com/chuyeow">Twitter</a>. I&#8217;ll follow you back if you&#8217;re a reader!</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/k2ls-XxTpAA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/03/24/im-still-alive-and-on-friendfeed-and-twitter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2009/03/24/im-still-alive-and-on-friendfeed-and-twitter/</feedburner:origLink></item>
		<item>
		<title>Dragging tab to a new window coming to Firefox</title>
		<link>http://feedproxy.google.com/~r/riab/~3/uCkdyQIxBL8/</link>
		<comments>http://blog.codefront.net/2008/11/16/dragging-tab-to-a-new-window-coming-to-firefox/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 14:15:05 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1132</guid>
		<description><![CDATA[Completely by accident, I discovered that you can now drag a tab out from its current window to a new window in a recent Firefox nightly. A short video 24-second better explains what I&#8217;m talking about: This tab tearing capability is a pretty neat feature &#8211; I know you can already do this in Safari, [...]]]></description>
				<content:encoded><![CDATA[<p>Completely by accident, I discovered that you can now drag a tab out from its current window to a new window in a recent Firefox nightly. A short video 24-second better explains what I&#8217;m talking about:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/yecyFamSh6c&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/yecyFamSh6c&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>This tab tearing capability is a pretty neat feature &#8211; I know you can already do this in Safari, Opera and Galeon. It&#8217;s really well done in Safari, which I think is what Firefox is emulating. Nice to see Firefox follow suit!</p>
<p>If you can&#8217;t wait for Firefox 3.1, try it out in a recent <a href="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/">Firefox nighty build</a> (remember to <a href="http://support.mozilla.com/en-US/kb/Managing+profiles">use a new profile</a> unless you are willing to risk corrupting your daily profile).</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/uCkdyQIxBL8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/11/16/dragging-tab-to-a-new-window-coming-to-firefox/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2008/11/16/dragging-tab-to-a-new-window-coming-to-firefox/</feedburner:origLink></item>
		<item>
		<title>Optimize Firefox’s memory usage by tweaking session preferences</title>
		<link>http://feedproxy.google.com/~r/riab/~3/TXurQJR9M3U/</link>
		<comments>http://blog.codefront.net/2008/09/10/optimize-firefoxs-memory-usage-by-tweaking-session-preferences/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 12:57:24 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1130</guid>
		<description><![CDATA[I&#8217;m a heavy tabbed browsing user &#8211; I have around 30 tabs open in my day-to-day Firefox profile all the time. Since the day Firefox 3 was released, I&#8217;ve noticed Firefox progressively getting slower with this particular Firefox profile (I use a different profile for web development). When it got to the point where changing [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m a heavy tabbed browsing user &#8211; I have around 30 tabs open in my day-to-day Firefox profile all the time. Since the day Firefox 3 was released, I&#8217;ve noticed Firefox progressively getting slower with this particular Firefox profile (I use a different profile for web development). When it got to the point where changing tabs took a noticeable pause of 1-2 seconds, I tweaked some of Firefox&#8217;s session store and history preferences and now things are blazing fast again.</p>
<p>Here&#8217;s what you can do:</p>
<ol>
<li>Go to <a href="about:config">about:config</a> in Firefox.</li>
<li>Type in &#8220;session&#8221; in the &#8220;Filter&#8221; box.</li>
<li>Edit <strong>browser.sessionhistory.max_entries</strong> &#8211; this is the number of pages stored in the history of your browsing session. Basically these are pages that can be reached using your Back and Forward buttons. The default is 50 &#8211; I reduced it to 20.</li>
<li>Edit <strong>browser.sessionhistory.max_total_viewers</strong> &#8211; this is the number of pages that are stored in RAM so that they aren&#8217;t re-processed by Firefox&#8217;s rendering engine. This is what allows you to go Back to a page in Firefox and have it load almost instantaneously. The number of pages stored actually depends on the amount of RAM on your machine (<a href="http://kb.mozillazine.org/Browser.sessionhistory.max_total_viewers">see this</a>). I reduced this to 4 (I have 2GB RAM).</li>
<li>Edit <strong><a href="http://kb.mozillazine.org/Browser.sessionstore.max_tabs_undo">browser.sessionstore.max_tabs_undo</a></strong> &#8211; the number of tabs you can restore after closing them (you can do this with Ctrl/Cmd-Shift-T). The default of 10 is more than I really need, so I reduced it to 3 tabs.</li>
<li>Edit <strong><a href="http://kb.mozillazine.org/Browser.sessionstore.interval">browser.sessionstore.interval</a></strong> &#8211; Firefox saves your session after every 10 seconds by default. I changed this to a more conservative 30000 milliseconds.</li>
</ol>
<p>You can <a href="http://kb.mozillazine.org/About:config_entries">read more about these preferences and more at the MozillaZine Knowledge Base</a>. If you&#8217;ve any tips on how to improve Firefox&#8217;s performance, be sure to share!</p>
<img src="http://feeds.feedburner.com/~r/riab/~4/TXurQJR9M3U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/09/10/optimize-firefoxs-memory-usage-by-tweaking-session-preferences/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		<feedburner:origLink>http://blog.codefront.net/2008/09/10/optimize-firefoxs-memory-usage-by-tweaking-session-preferences/</feedburner:origLink></item>
	</channel>
</rss>
