<?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>christopherowen.id.au &#187; nerd</title>
	<atom:link href="http://christopherowen.id.au/blog/category/nerd/feed/" rel="self" type="application/rss+xml" />
	<link>http://christopherowen.id.au/blog</link>
	<description>Stuff cubed plus one</description>
	<lastBuildDate>Wed, 18 Aug 2010 23:21:57 +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>The Happy Toggler</title>
		<link>http://christopherowen.id.au/blog/2010/01/11/the-happy-toggler/</link>
		<comments>http://christopherowen.id.au/blog/2010/01/11/the-happy-toggler/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 12:23:49 +0000</pubDate>
		<dc:creator>Christopher Owen</dc:creator>
				<category><![CDATA[nerd]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://christopherowen.id.au/blog/?p=156</guid>
		<description><![CDATA[So I've been writing a lot of boolean toggling code recently, and it's been making me sad. Can't we make it happier?]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing a lot of UI code lately, and one of the bread-and-butter operations in UI code is toggling boolean state, usually in response to a button press. Now, what does toggling code look like? </p>
<p>Say I have an object that likes to transition solely between happy states every time a certain event occurs. Here&#8217;s how I might handle it:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"> theObject.<span style="color: #006633;">happy</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>theObject.<span style="color: #006633;">happy</span><span style="color: #339933;">;</span></pre></div></div>

<p>There. Simple huh? Something you probably learn how to do in an introductory programming course. It might be surprising to you, but someone <a href="http://stackoverflow.com/questions/224311/cleanest-way-to-toggle-a-boolean-variable-in-java">asked a question on how to do this on Stack Overflow</a>. The other alternative provided in the answer is the somewhat more cerebral:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">theObject.<span style="color: #006633;">happy</span> <span style="color: #339933;">^=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>Thanks Spock. Of course if your language doesn&#8217;t have an assigning XOR operator this option is ruled out. If you value clarity of code, or you simply don&#8217;t want less brainy maintainers pestering you about what your code is doing, you rule this option out as well.</p>
<p>So I&#8217;ve been writing a lot of code recently of the first form, and it&#8217;s been making me sad. There&#8217;s a strong feeling of non object oriented-ness about it. I mean, to toggle the state of an object I have to:</p>
<ol>
<li>ask it what its current state is;
<li>flip that state locally;
<li>and then tell the object to take on this new state.
</ol>
<p>Bleh! Why the hell should I care what state it currently is in? I just want to toggle it! Shouldn&#8217;t I just be able to ask the object to toggle it&#8217;s own state; perhaps of even multiple properties in a batch sequence? </p>
<p>Naturally, nobody wants to write a toggling method for every writable boolean property of their objects. So either there needs to be automatic support in the platform or some ability to provide a general toggling abstraction.</p>
<p>One such example of a crude toggling abstraction would be a Ruby module defined like the following.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Toggler
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> ToggleHelper
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>target<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@target</span> = target
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>sym<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@target</span>.<span style="color:#9900CC;">toggle</span><span style="color:#006600; font-weight:bold;">&#40;</span>sym<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> toggle; <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> toggle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>sym<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> ToggleHelper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> sym.<span style="color:#9900CC;">empty</span>?
&nbsp;
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{sym}=&quot;</span>, !<span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>sym<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Such a module could be mixed-in at the appropriate levels of an inheritance hierarchy, or maybe even at the root level if you&#8217;re game.</p>
<p>With the mix-in mixed-in, toggling code would be more concise and less repetitious:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">the_object.<span style="color:#9900CC;">toggle</span>.<span style="color:#9900CC;">happy</span>
the_object.<span style="color:#9900CC;">toggle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:happy</span><span style="color:#006600; font-weight:bold;">&#41;</span>
the_object.<span style="color:#9900CC;">toggle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:wanted</span>, <span style="color:#ff3333; font-weight:bold;">:happy</span>, <span style="color:#ff3333; font-weight:bold;">:virtuous</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Doesn&#8217;t a declarative syntax such as this feel much more happy?</p>
]]></content:encoded>
			<wfw:commentRss>http://christopherowen.id.au/blog/2010/01/11/the-happy-toggler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bash your Fish</title>
		<link>http://christopherowen.id.au/blog/2009/06/05/bash-your-fish/</link>
		<comments>http://christopherowen.id.au/blog/2009/06/05/bash-your-fish/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 13:22:56 +0000</pubDate>
		<dc:creator>Christopher Owen</dc:creator>
				<category><![CDATA[nerd]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[fish]]></category>
		<category><![CDATA[functions]]></category>

		<guid isPermaLink="false">http://christopherowen.id.au/blog/?p=109</guid>
		<description><![CDATA[I've recently started to spend some time with the Fish shell, although there is a problem with it: my collection of Bash functions that I've accumulated over the years in <kbd>.bashrc</kbd> are rendered impotent in this environment. Fortunately there is a quick way to bridge the gap.]]></description>
			<content:encoded><![CDATA[<p>I love shells. I spend an inordinate amount of every working day in one. That one happens to be Bash, arguably the most ubiquitous CLI shell in the world. It&#8217;s not bad at all, although sometimes I think CLIs could be so much more than they are today. Some <a href="http://directwebremoting.org/blog/joe/2009/05/27/command_lines.html">other people agree too</a>, but that delectable future seems a little way off.</p>
<p>An existing shell that aims to provide a better interactive experience is the <a href="http://fishshell.org/index.php">Friendly Interactive SHell &#8212; Fish</a>. I&#8217;ve recently started to spend some time with this shell although there is a problem with it: my collection of Bash functions that I&#8217;ve accumulated over the years in <kbd>.bashrc</kbd> are rendered impotent in this environment. Sure, I could spend some time and redefine them all in Fish&#8217;s shellscript dialect; or I could just abandon trying something new in the name of efficiency and laziness and head back to Bash. That does seem sad, and fortunately there is a way to bridge the gap.</p>
<p>For other souls in a similar situation to me, here&#8217;s some script you can pop in your <kbd>~/.config/fish/config.fish</kbd> (Fish&#8217;s equivalent to <kbd>.bashrc</kbd>)</p>
<pre>
function bash_env
    set -x BASH_ENV ~/.bash_functions
    bash -c "$argv"
end

for BASH_FUNCTION in (bash_env 'declare -F' | awk '{print $3}')
    eval "function $BASH_FUNCTION; bash_env $BASH_FUNCTION \$argv; end"
end
</pre>
<p>You&#8217;ll need to change the <kbd>BASH_ENV</kbd> setting on the second line to point to the file where you declare your Bash functions. I&#8217;ve moved my functions out of <kbd>.bashrc</kbd> and into a separate file that I source from <kbd>.bashrc</kbd>. This is because I also source <kbd>/etc/bash_completion</kbd> from <kbd>.bashrc</kbd>, and that is quite a time consuming process to do every time you want to run a simple Bash function from Fish.</p>
<p>Once that&#8217;s done, simply fire up Fish and type &#8216;functions&#8217;. You should see all of your old, dear Bash functions appear in the list, ready to aid you in your daily endeavours, just like times of old. Now, try the Fish!</p>
]]></content:encoded>
			<wfw:commentRss>http://christopherowen.id.au/blog/2009/06/05/bash-your-fish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fluid Rails search</title>
		<link>http://christopherowen.id.au/blog/2009/05/05/fluid-rails-search/</link>
		<comments>http://christopherowen.id.au/blog/2009/05/05/fluid-rails-search/#comments</comments>
		<pubDate>Mon, 04 May 2009 13:48:57 +0000</pubDate>
		<dc:creator>Christopher Owen</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[nerd]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ssb]]></category>

		<guid isPermaLink="false">http://christopherowen.id.au/blog/?p=86</guid>
		<description><![CDATA[Having quick access to API documentation is one of the absolutely essential requirements during my development day. Here's what I use to for quick access to Rails documentation.]]></description>
			<content:encoded><![CDATA[<p>Having quick access to API documentation is one of the absolutely essential requirements during my development day. I have knowledge of so many different technologies, APIs, syntaxes, runtime behaviours, protocols, editing environment commands and shortcuts crammed into my head that I&#8217;m well beyond having perfect recall of every single detail of whatever I happen to be working with. At the start of my Ruby programming adventures, I was always trawling through the online Ruby and RoR documentation, either using Google to find references or Firefox&#8217;s inbuilt page search to find a method, module or class in the framed documentation lists. This was wholly unsatisfying, particularly with how web browsers search through frame-sets. I also seem to have a major personality defect in which I will persist in certain kinds of suboptimal practices for far too long; I&#8217;m often loath to steal time from a current task to thrash out a solution to something that is bothering me at the fringes. Eventually I snapped and asked my colleagues what they used to satisfy their API reference needs when working with Rails. I was dismayed when I was told they used the same strategy as mine. There had to be something a little less primitive.</p>
<h2>Enter the Rails Searchable API Doc</h2>
<p>A few weeks ago I was directed to <a href="http://railsapi.com/">the Rails Searchable API Doc beta</a> by Vladimir Kolesnikov: a nicely bundled, offline, HTML Rails API reference with full search facilities. Simply download a bundle (Rails, Ruby and gem documentation bundles are available) and unpack in a convenient location. Open the <tt>index.html</tt> file and voila! You now have a nice and fast Rails API reference available offline. The only problem with this is that a web browser is a very ad-hoc environment. I often have scores of tabs open, browsing random resources around the web. This meant that I now had the problem of trying to find my current Rails documentation amidst all of the other random guff that builds up in my browser. </p>
<h2>Enter Fluid</h2>
<p><a href="http://fluidapp.com">Fluid</a> is a Mac OS X application that enables the configuration of <a href="http://en.wikipedia.org/wiki/Site-specific_browser">site-specific browsers</a>. An SSB can essentially make a web application appear much like a first-class desktop application via a dedicated web browser sandbox. An SSB is a great way to keep your Google Reader, Facebook or other web sessions completely separate from each other, hosted in separate processes complete with individual Dock icons. It also turns out to be a really handy way of keeping HTML based references close at hand.</p>
<p>Simply:</p>
<ol>
<li>Grab <a href="http://fluidapp.com/">Fluid</a> and <a href="http://railsapi.com/">the Rails Searchable API.</a></li>
<li>Snag <a href="http://azizash.deviantart.com/art/Ruby-on-Rails-icon-pack-81755219">a nice Ruby on Rails icon</a>. This is to be used for the Dock.</li>
<li>Unpack all of these bundles into appropriate places.</li>
<li>Launch Fluid and set up a Rails API site-specific browser.</li>
<p><img src="http://christopherowen.id.au/blog/wp-content/uploads/2009/05/fluid.jpg" alt="Fluid configuration" title="fluid" width="555" height="323" class="size-full wp-image-88" />
</li>
<li>Consider dragging the generated SSB to the Dock.</li>
<li>Enjoy!<br />
<img src="http://christopherowen.id.au/blog/wp-content/uploads/2009/05/fluid-rails-api-11.jpg" alt="fluid-rails-api-11" title="fluid-rails-api-11" width="530" height="410" class="alignnone size-full wp-image-92" />
</li>
</ol>
<p>Fluid uses WebKit as its rendering engine, and configuration of the browser is naturally very similar to Safari. By default it maximizes browsing area by eliminating the tool and status bars but these can be added via the menu. In the screen shot you can see I&#8217;ve added back, forward and font resizing buttons. For a documentation SSB, it also makes sense to set Fluid to only hide the window when the window is closed. Such a setting is available in the <tt>Behaviour</tt> tab of the application preferences.</p>
<p>For those with open source cravings, Mozilla Labs has an SSB project called <a href="http://labs.mozilla.com/projects/prism/">Prism</a> that offers similar functionality, although I find their offering a little more sparse.</p>
]]></content:encoded>
			<wfw:commentRss>http://christopherowen.id.au/blog/2009/05/05/fluid-rails-search/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTTP Humour</title>
		<link>http://christopherowen.id.au/blog/2008/08/01/http-humour/</link>
		<comments>http://christopherowen.id.au/blog/2008/08/01/http-humour/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 06:44:45 +0000</pubDate>
		<dc:creator>Christopher Owen</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[nerd]]></category>
		<category><![CDATA[gone]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://christopherowen.id.au/blog/?p=45</guid>
		<description><![CDATA[This post contains bad nerd humour. Please exercise caution.]]></description>
			<content:encoded><![CDATA[<p>Today I posted this picture to an internal discussion at <a href="http://www.atlassian.com/">Atlassian</a> on RESTful APIs.</p>
<div>
<img src="http://christopherowen.id.au/blog/wp-content/uploads/2008/08/tombstone-410-300x180.jpg" alt="Tombstone with \&quot;410\&quot; GONE engraved" title="tombstone-410" width="300" height="180" class="size-medium wp-image-44" />
</div>
<p><a href="http://fishbowl.pastiche.org/">Charles</a> added some additional, thoughtful alternatives:</p>
<blockquote><p>Depending on your belief or not in an afterlife/reincarnation, it could be <tt>301 Moved Permanently</tt>, or if you believe <a href="http://en.wikipedia.org/wiki/John_Edward" rel="nofollow">John Edward</a>, <tt>305 Use Proxy</tt>.</p></blockquote>
<p>Yes &#8212; we do think this is funny <img src='http://christopherowen.id.au/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If you do to, perhaps <a href="http://www.atlassian.com/about/jobs.jsp">you should consider joining us</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://christopherowen.id.au/blog/2008/08/01/http-humour/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
