<?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>Self-Amusement Park &#187; Geekery</title>
	<atom:link href="http://selfamusementpark.com/blog/categories/geekery/feed/" rel="self" type="application/rss+xml" />
	<link>http://selfamusementpark.com/blog</link>
	<description>I have nothing interesting to say. Don't believe me? Read this:</description>
	<lastBuildDate>Mon, 12 Apr 2010 07:02:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails 2.3.3 + mocha = confusion</title>
		<link>http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/</link>
		<comments>http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 23:48:22 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=92</guid>
		<description><![CDATA[I just updated a project to Rails 2.3.3 for the cool new &#8220;touch&#8221; feature, and saw here that I needed to update to Mocha 0.9.7. I did that, but found that my tests were failing &#8211; I got lots of NoMethodError: undefined method `stub&#8217; for #&#60;SomeTest:0&#215;7f2c1d921f80&#62; errors.
In my project, I&#8217;d declared my dependence on the [...]]]></description>
			<content:encoded><![CDATA[<p>I just updated a project to <a href="http://weblog.rubyonrails.org/2009/7/20/rails-2-3-3-touching-faster-json-bug-fixes" target="blank">Rails 2.3.3</a> for the cool new &#8220;touch&#8221; feature, and saw <a href="http://railspikes.com/2009/7/29/rails-2-3-3-upgrade-notes/" target="blank">here</a> that I needed to update to Mocha 0.9.7. I did that, but found that my tests were failing &#8211; I got lots of <b>NoMethodError: undefined method `stub&#8217; for #&lt;SomeTest:0&#215;7f2c1d921f80&gt;</b> errors.</p>
<p>In my project, I&#8217;d declared my dependence on the Mocha gem in my config/environment.rb file, so that &#8220;sudo rake gems:install&#8221; would load everything required for development in one shot (which is why the dependency isn&#8217;t in config/environments/test.rb). I&#8217;ll cut to the chase: I needed to add an extra option to that declaration:</p>
<pre>config.gem 'mocha', :version => '=0.9.7'<b>, :lib =&gt; false</b></pre>
<p>The problem is that mocha configures itself based on what test library you&#8217;ve <i>already</i> included when you require Mocha. Unfortunately, the config.gem declaration causes mocha to be loaded before Rails has loaded Test::Unit, so Mocha doesn&#8217;t configure itself&#8230; so no &#8220;stub.&#8221; Setting :lib to false postpones loading Mocha until you actually do it in your test/test_helper.rb (or wherever).</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automatic wireless goodness</title>
		<link>http://selfamusementpark.com/blog/2009/03/07/automatic-wireless-goodness/</link>
		<comments>http://selfamusementpark.com/blog/2009/03/07/automatic-wireless-goodness/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 23:29:18 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[ubuntu wireless security vpn networkmanager gist]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=88</guid>
		<description><![CDATA[I often work in coffeeshops and other places that provide free wireless networks. Since anyone could sniff traffic sent over these networks, I&#8217;ve set up my own virtual private network at home so that my traffic will be encrypted before it leaves my laptop, then decrypted on a server at home and sent out from [...]]]></description>
			<content:encoded><![CDATA[<p>I often work in coffeeshops and other places that provide free wireless networks. Since anyone could sniff traffic sent over these networks, I&#8217;ve set up my own virtual private network at home so that my traffic will be encrypted before it leaves my laptop, then decrypted on a server at home and sent out from my home network &#8211; this also gives me secure access to a couple of machines at home that aren&#8217;t otherwise accessible from the internet. I use OpenVPN for this; it&#8217;s open-source, it was relatively easy to set up on my Ubuntu server, and there&#8217;s good support for OpenVPN in the Network Manager included on my laptop (also running Ubuntu).</p>
<p>This worked great for a while, but a few things bugged me:
<ul>
<li>The VPN connection doesn&#8217;t happen automatically &#8211; I had to remember to do it, and would sometimes forget;</li>
<li>my favorite hangouts&#8217; wireless networks ask me to accept terms of service every time I use them, and that got annoying;</li>
<li>and whenever the DHCP lease renews (which is every few minutes in some places), the DNS server configuration would be reset to point at the shop&#8217;s DNS server instead of the one I run (so I&#8217;d lose the ability to refer to my home machines by name; it&#8217;s also possible that the public DNS server is less secure than mine, so that&#8217;s not good).</li>
</ul>
<p>I set out to remedy these problems, and it turned out to not be too difficult; I learned a bit about Network Manager in the process, too. Network Manager can automatically run a script when it associates with a wireless network, so I wrote <a href="http://gist.github.com/75475" target="_blank">this Python script</a>; it solves the first two problems: it looks to see what network we associated with, and if it&#8217;s not my home network, it creates the VPN connection. First, though, if it&#8217;s one of the networks that requires a terms-of-service acceptance, it accepts them and submits the form. (The latter mechanism is specific to the <a href="http://www.personaltelco.net/" target="_blank">Portland Telco Project</a> networks we have here in Portland, but you can probably figure out how to customize it to your own networks &#8211; if not, leave a comment.)</p>
<p>The third problem, where DHCP renewal clobbers DNS settings, seems to be known but unfixed: here&#8217;s <a href="https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/90681" target="_blank">a bug about it</a>. The person who reported the bug posted a workaround for this problem. I&#8217;m not sure it&#8217;s the right change for everyone, but I&#8217;m happy with it in my case: it&#8217;s a one-line addition to <code>/sbin/dhclient-script</code>; insert this line just after the start of the <code>make_resolve_conf</code> function that&#8217;s first in that file:<br />
<code><br />
    [ "$reason" = "RENEW" ] &#038;&#038; return<br />
</code><br />
This shortcuts the function that would be overwriting the DNS settings to do nothing if we&#8217;re renewing the DHCP settings. (Admittedly, if the DNS server addresses changed, I wouldn&#8217;t know about it, but my home DNS server&#8217;s address hasn&#8217;t changed in a while, and I wasn&#8217;t in a coffeeshop when it did.)</p>
<p>With these mechanisms in place, I can open my laptop and see Network Manager&#8217;s progress by looking at its icon in the menu bar: I see it associate with a network and go through the VPN connection process, without me having to do anything. Perfect.</p>
<p>[Update: Almost perfect: in cleaning up the script for posting, I broke it &mdash; I've fixed it.]</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2009/03/07/automatic-wireless-goodness/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>My &#8220;Day On&#8221;</title>
		<link>http://selfamusementpark.com/blog/2009/01/19/my-day-on/</link>
		<comments>http://selfamusementpark.com/blog/2009/01/19/my-day-on/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 19:50:36 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Around Here]]></category>
		<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=81</guid>
		<description><![CDATA[Today on Martin Luther King Day, I participated in Day On, yet another great Portland tech community event: local geeks gathered at CubeSpace to volunteer to help non-profits with technical issues. A couple of dozen folks showed up to offer help, and though only a few folks came by to ask for assistence or asked [...]]]></description>
			<content:encoded><![CDATA[<p>Today on Martin Luther King Day, I participated in <a href="http://dayon.org/blog/geeks-day-2009" target="_blank">Day On</a>, yet another great Portland tech community event: local geeks gathered at <a href="http://cubespacepdx.com/" target="_blank">CubeSpace</a> to volunteer to help non-profits with technical issues. A couple of dozen folks showed up to offer help, and though only a few folks came by to ask for assistence or asked using the Day On website, a great time was had by all, and we hope the event will continue and grow.</p>
<p>I was one of several folks who got to help Dean Suhr of the <a href="http://mldfoundation.org/" target="_blank">MLD Foundation</a>, a resource for families affected by Metachromatic Leukodystrophy; one page of the Foundation&#8217;s website displays a Google map showing families affected by the disease, and the map display wasn&#8217;t working right. I was able to find a workaround for a problem in a map-display library, and I&#8217;m hoping to work with the library&#8217;s developer to help fix the underlying problem.</p>
<p>After I showed Dean my fix, I got an unexpected bonus: Dean mentioned that he was considering using Google Maps&#8217; &#8220;clustering&#8221; feature, which allows a single symbol to represent many individual map tacks when zoomed out to show a large map area &mdash; it&#8217;s a feature that helps reduce map clutter when a map holds a lot of symbols.</p>
<p>Dean had thus far elected not to use this feature &mdash; instead, when zoomed out, he&#8217;d used a smaller version of the butterfly symbol that represented each family, to help each individual family show up better on the big map. As he told me this, I thought about the effect of the disease on Dean and his family, multiplied by each of these families, and thought that Dean had already chosen the perfect representation (and said so).</p>
<p>I was lucky to be able to volunteer today, lucky to meet Dean and help a little with the Foundation&#8217;s site, and especially lucky to make that connection between the work today and groups like Dean&#8217;s who help so many people. Tomorrow I&#8217;m getting up early to head back to CubeSpace to watch the Inauguration with more of my Portland tech community friends, and I feel even more strongly that I&#8217;m lucky to be part of such a terrific community.</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2009/01/19/my-day-on/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fixing a little VPN annoyance</title>
		<link>http://selfamusementpark.com/blog/2008/11/17/fixing-a-little-vpn-annoyance/</link>
		<comments>http://selfamusementpark.com/blog/2008/11/17/fixing-a-little-vpn-annoyance/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 18:54:56 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Toys]]></category>
		<category><![CDATA[vpn dns dhcp ubuntu]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=75</guid>
		<description><![CDATA[I&#8217;m writing this in a coffee shop, and when I&#8217;m using a public wireless network, I like to secure my network traffic using a virtual private network (VPN) that I set up on my server at home. Without this, anyone else close by could spy on what I&#8217;m doing (including seeing passwords I&#8217;m sending to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing this in a coffee shop, and when I&#8217;m using a public wireless network, I like to secure my network traffic using a virtual private network (VPN) that I set up on my server at home. Without this, anyone else close by could spy on what I&#8217;m doing (including seeing passwords I&#8217;m sending to badly-secured web sites). Unfortunately, the connection appears to go bad after a short while, and it took me weeks to spend the minute it took to find a fix.<br />
<span id="more-75"></span></p>
<p>Here&#8217;s where things get a little buzzwordy: You might know that every computer needs a way to translate domain names (like &#8220;selfamusementpark.com&#8221;) into network addresses (like &#8220;192.168.1.5&#8243;); the Domain Name System does this (hence its catchy name, <a href="http://en.wikipedia.org/wiki/Domain_Name_System" target="_blank">DNS</a>). </p>
<p>When my computer wants to use a public network, it gets assigned a network address by the wireless base station, using something called Dynamic Host Configuration Protocol &#8211; <a href="http://en.wikipedia.org/wiki/Dhcp" target="_blank">DHCP</a>. As part of this assignment, my computer also gets the address of a local DNS server address to use for name lookups.  When I open my VPN connection, my computer automatically starts using my DNS server at home, to be able to look up the names of computers at home that aren&#8217;t on the public internet. (Yeah, I know: it&#8217;s weird that I leave the house to work on computers at home, huh?)</p>
<p>Here&#8217;s the catch: periodically, the base station requires my computer to &#8220;renew&#8221; its address, and when it does, my computer gets switched back to use the coffee shop&#8217;s DNS server (even though my VPN connection is still open). This is annoying, and I finally decided to look for a fix. </p>
<p>I found one in <a href="https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/90681" target="_blank">this Ubuntu bug</a>. It&#8217;s a one-line change to a system script that prevents the DNS server switch if it&#8217;s happening because of an address renewal. </p>
<p>(Finding this took 30 seconds because I picked good search words, and applying the fix took 30 more because I understood what was going on at this level of the system.  I&#8217;m blogging this because someone less technical than me might have more trouble with each; if this is something that bugs you and you have trouble with this fix, add a comment.)</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2008/11/17/fixing-a-little-vpn-annoyance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Android fonts on my desktop are beautiful</title>
		<link>http://selfamusementpark.com/blog/2008/11/15/android-fonts/</link>
		<comments>http://selfamusementpark.com/blog/2008/11/15/android-fonts/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 18:15:19 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=70</guid>
		<description><![CDATA[I&#8217;ve been tinkering with developing software for the Android phone platform (and loving my G1 phone that runs it)&#8230; the Android folks at Google hired Ascender to create a new font family for the phone, the only family that the phone comes with. Here&#8217;s a sample from Ascender&#8217;s press release.
It occurred to me that because [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ascendercorp.com/graphics/DroidGraphic300.jpg" alt="Droid family font sample" style="float: right; padding-left: 10px"/>I&#8217;ve been tinkering with developing software for the Android phone platform (and loving my G1 phone that runs it)&#8230; the Android folks at Google hired Ascender to create a new font family for the phone, the only family that the phone comes with. Here&#8217;s a sample from <a href="http://www.ascendercorp.com/pr/pr2007_11_12.html" target="_blank">Ascender&#8217;s press release</a>.</p>
<p>It occurred to me that because the fonts were designed for legibility at small point sizes, Droid Mono might be a good replacement for the terminal font I do much of my programming in. It turns out that the whole family makes excellent replacements for the default fonts on my Ubuntu systems: they&#8217;re so legible that I&#8217;ve been able to reduce the default sizes as well, effectively giving me more screen real estate. Several times in the last couple of days, it&#8217;s occurred to me how much more beautiful my working environment is, now that I&#8217;m looking at a well-designed font.</p>
<p>You can get the fonts from within the Android SDK, but another helpful blogger has put them up as a <a href="http://damieng.com/blog/2007/11/14/droid-font-family-courtesy-of-google-ascender" target="_blank">separate download</a>. (If you&#8217;re installing them on Linux like I did, put them in a folder in /usr/share/fonts, then do &#8220;sudo  fc-cache -f -v&#8221; to get the system to notice them.)</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2008/11/15/android-fonts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Android AIDL regeneration</title>
		<link>http://selfamusementpark.com/blog/2008/09/30/android-aidl-regeneration/</link>
		<comments>http://selfamusementpark.com/blog/2008/09/30/android-aidl-regeneration/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 19:37:52 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[AIDL]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=65</guid>
		<description><![CDATA[I&#8217;m working on a couple of Android projects; one has an Android IDL file (.aidl) for a service, and for some reason, the development environment didn&#8217;t automatically generate the corresponding .java file from it. I wasn&#8217;t able to figure out what caused this, and recreating the .aidl file didn&#8217;t fool the IDE into doing it, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a couple of Android projects; one has an Android IDL file (.aidl) for a service, and for some reason, the development environment didn&#8217;t automatically generate the corresponding .java file from it. I wasn&#8217;t able to figure out what caused this, and recreating the .aidl file didn&#8217;t fool the IDE into doing it, nor was I able to find a solution to this with the usual Googling.</p>
<p>I did find that right-clicking the project in the hierarchy and choosing &#8220;Android Tools&#8221; -> &#8220;Fix Project Properties&#8221; fixed this. Subsequent changes to the .aidl file automatically regenerated the .java file, too, so that&#8217;s nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2008/09/30/android-aidl-regeneration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clearing apt-cacher&#8217;s cache</title>
		<link>http://selfamusementpark.com/blog/2008/09/15/clearing-apt-cachers-cache/</link>
		<comments>http://selfamusementpark.com/blog/2008/09/15/clearing-apt-cachers-cache/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 18:25:21 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[apt-cacher]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=57</guid>
		<description><![CDATA[I frequently reinstall Ubuntu from scratch, so I&#8217;ve set up apt-cacher on my fileserver to cache the packages I install &#8211; this not only reduces my impact on the mirrors, but also speeds up my installs.
Occasionally, though, I see strange problems during installs: apt-get install retrying the download of an apparently-cached package. I haven&#8217;t figured [...]]]></description>
			<content:encoded><![CDATA[<p>I frequently reinstall Ubuntu from scratch, so I&#8217;ve set up <code>apt-cacher</code> on my fileserver to cache the packages I install &#8211; this not only reduces my impact on the mirrors, but also speeds up my installs.</p>
<p>Occasionally, though, I see strange problems during installs: <code>apt-get install</code> retrying the download of an apparently-cached package. I haven&#8217;t figured out what&#8217;s wrong, and frequently I just want to get the reinstall going again. In these situations, it seems optimal to just dump the cache and start over; I haven&#8217;t found clear documentation of how to do this, but in case it isn&#8217;t obvious, this works for me (my cache is in /var/cache/apt-cacher, and I run it as www-data):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Stop the service</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apt-cacher stop
<span style="color: #666666; font-style: italic;"># Move the old cache out of the way, so we can delete it </span>
<span style="color: #666666; font-style: italic;"># in the background (it can take a while)</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>apt-cacher <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>apt-cacher.old
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>apt-cacher.old <span style="color: #000000; font-weight: bold;">&amp;</span>
<span style="color: #666666; font-style: italic;"># Make the new cache hierarchy, and set its ownership properly</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>apt-cacher<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>headers,import,packages,private,temp<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> www-data:www-data <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>apt-cacher
<span style="color: #666666; font-style: italic;"># Restart the service</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apt-cacher start</pre></div></div>

<p>Update: I found <a href="http://www.zyxware.com/articles/2008/07/27/how-to-fix-hash-sum-mismatch-and-size-mismatch-errors-from-apt-get-apt-cacher" target="_blank">this blog post</a> helpful for manually removing troublesome packages from the cache.</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2008/09/15/clearing-apt-cachers-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails script/performance/request needed a little help</title>
		<link>http://selfamusementpark.com/blog/2008/08/29/rails-scriptperformancerequest-needed-a-little-help/</link>
		<comments>http://selfamusementpark.com/blog/2008/08/29/rails-scriptperformancerequest-needed-a-little-help/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 17:29:34 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=53</guid>
		<description><![CDATA[While following another great Ryan Bates Railscast, I had a couple of problems on my Ubuntu 8.04 development machine:

Rails 2.1.0&#8217;s ActionController wants version 0.6.1 or later of the ruby-prof gem, but the usual gem repositories only have 0.6.0 now. I found suggestions to install Jeremy Kemper&#8217;s fork on Github, but though I&#8217;d added GitHub as [...]]]></description>
			<content:encoded><![CDATA[<p>While following <a href="http://railscasts.com/episodes/98-request-profiling">another great Ryan Bates Railscast</a>, I had a couple of problems on my Ubuntu 8.04 development machine:
<ul>
<li>Rails 2.1.0&#8217;s ActionController wants version 0.6.1 or later of the ruby-prof gem, but the usual gem repositories only have 0.6.0 now. I found suggestions to install <a href="http://github.com/jeremy/ruby-prof">Jeremy Kemper&#8217;s fork on Github</a>, but though I&#8217;d <a href="http://github.com/blog/97-github-loves-rubygems-1-2">added GitHub as a gem source</a>, installing jeremy-ruby-prof didn&#8217;t work because that installed his version with that name, which didn&#8217;t help ActionController. What worked was:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem uninstall jeremy-ruby-prof <span style="color: #666666; font-style: italic;"># be sure to uninstall old attempts!</span>
git clone git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jeremy<span style="color: #000000; font-weight: bold;">/</span>ruby-prof.git
<span style="color: #7a0874; font-weight: bold;">cd</span> ruby-prof
rake gem
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> pkg<span style="color: #000000; font-weight: bold;">/</span>ruby-prof-0.6.1.gem</pre></div></div>

</li>
<li>Then, script/performance/request ran, but generated several strange error messages instead of producing results:
<pre>
Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
</pre>
<p>This turned out to be because <code>script/performance/request</code> wants to use &#8216;open&#8217; to open its output files (a text file and an HTML document), but on Ubuntu, <code>/usr/bin/open</code> is a link to <code>/usr/bin/openvt</code>, which didn&#8217;t do what we want (and generated those error messages). I&#8217;m not sure what else uses &#8216;open&#8217;, but this did the right thing: it lets Firefox open the files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-sf</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>firefox <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>open</pre></div></div>

</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2008/08/29/rails-scriptperformancerequest-needed-a-little-help/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>named_scope, joins, &amp; includes</title>
		<link>http://selfamusementpark.com/blog/2008/07/10/named_scope-joins-includes/</link>
		<comments>http://selfamusementpark.com/blog/2008/07/10/named_scope-joins-includes/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 20:51:25 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[named_scope]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/?p=51</guid>
		<description><![CDATA[I used Rails 2.1&#8217;s named_scope to implement various ways to sort things on OsoEco. When I implemented &#8220;most discussed&#8221; on the Question model (questions have many comments), it involved joining in the comments table to count comments for each question. Initially, it looked something like:
named_scope :most_active, :joins => :comments, :group => "questions.id", order => "count(questions.id) [...]]]></description>
			<content:encoded><![CDATA[<p>I used Rails 2.1&#8217;s named_scope to implement various ways to sort things on <a href="http://osoeco.com" target="_blank">OsoEco</a>. When I implemented &#8220;most discussed&#8221; on the Question model (questions have many comments), it involved joining in the comments table to count comments for each question. Initially, it looked something like:<br />
<code>named_scope :most_active, :joins => :comments, :group => "questions.id", order => "count(questions.id) desc"</code></p>
<p>That caused a problem, which the Pivotal Labs folks also <a href="http://pivots.pivotallabs.com/users/joe/blog/articles/465-standup-07-10-2008">commented on today:</a></p>
<blockquote><p>
When using <code>named_scope</code>, adding a <code>:joins</code> option will &#8220;mix-in&#8221; all of the attributes from that join table into your retrieved object, potentially overwriting any colliding attributes (including <code>id</code> &#8230; ouch!). There was consensus that this was a valuable feature, when used &#8220;properly&#8221;. Adding <code>:select</code> option can avoid this, or use <code>:include</code>.
</p></blockquote>
<p>Like they said, I fixed this with :select &#8212; the second try looked like this<br />
<code>named_scope :most_active, </code><b><code>:select => "questions.*",</code></b><code> :joins => :comments, :group => "questions.id", order => "count(questions.id) desc"</code></p>
<p>That worked (and fixed that problem), but it occurred to me that if my controller wanted to <code>:include</code> additional tables to add onto this scope (and that&#8217;s one of the cool things that <code>named_scope</code> enables), it wouldn&#8217;t work: <code>Question.most_active.scoped(:include => :comments)</code> raises a bad-SQL exception.</p>
<p>Fixing this required a bit of table aliasing, and led to this:<br />
<code>named_scope :most_active, :select => "questions.*", :joins =>  </code><b><code>"left join comments as comments_for_count on comments_for_count.question_id = questions.id",</code></b><code> :group => "questions.id", order => "count(questions.id) desc"</code></p>
<p>This worked, even with the <code>:include</code> added in a subsequent (anonymous) scope.</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2008/07/10/named_scope-joins-includes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hiding in plain sight</title>
		<link>http://selfamusementpark.com/blog/2008/02/26/hiding-in-plain-sight/</link>
		<comments>http://selfamusementpark.com/blog/2008/02/26/hiding-in-plain-sight/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 20:43:47 +0000</pubDate>
		<dc:creator>stearns</dc:creator>
				<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://selfamusementpark.com/blog/2008/02/26/hiding-in-plain-sight/</guid>
		<description><![CDATA[ In writing my bio for Portland on Fire, I mentioned that I&#8217;d hidden my first name upside down in the &#8220;Read Me&#8221; file icon used on Macintosh during the late 1980&#8217;s: millions of people clicked on this icon to get help, and as far as I know, none of them noticed my name. The [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/pic/blog/readme.png?width=48&#038;height=48&#038;thumb=1&#038;sekrit=7CRHNQ" height="184" class="photo" onClick="window.open('/pic/blog/readme.png?width=48&#038;height=48&#038;web=1&#038;sekrit=ZOXN5A', '_blank', 'height=640,width=640');" width="184"/> In writing <a href="http://www.portlandonfire.com/bryanstearns/" target="_blank">my bio for Portland on Fire</a>, I mentioned that I&#8217;d hidden my first name upside down in the &#8220;Read Me&#8221; file icon used on Macintosh during the late 1980&#8217;s: millions of people clicked on this icon to get help, and as far as I know, none of them noticed my name. The Wikipedia page for TeachText (the application I&#8217;d written which provides this icon) doesn&#8217;t mention this trivia (nor that I wrote it!).</p>
<p>After several years, TeachText was replaced by SimpleText, written by Tom Dowdy; Tom rightfully replaced my name with his; I&#8217;m just happy he kept the same style of icon. (I do rib Tom that TeachText was only 19K, where SimpleText was several times that in size.)</p>
<p>UPDATE: Sadly, I learned recently that Tom passed away. I&#8217;ll miss him: like many people I got to work with at Apple back then, he was smart and fun. I looked forward to seeing him every year at Apple&#8217;s developer conference, where we shared the distinction of being the only &#8220;Stump the Experts&#8221; experts who&#8217;d attended every session of that panel over the years.</p>
]]></content:encoded>
			<wfw:commentRss>http://selfamusementpark.com/blog/2008/02/26/hiding-in-plain-sight/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
