<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Two Guys Arguing</title>
	<atom:link href="http://twoguysarguing.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://twoguysarguing.wordpress.com</link>
	<description>colorful back and forth from two highly opinionated programmers</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:14:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='twoguysarguing.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Two Guys Arguing</title>
		<link>http://twoguysarguing.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://twoguysarguing.wordpress.com/osd.xml" title="Two Guys Arguing" />
	<atom:link rel='hub' href='http://twoguysarguing.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Competing Parsers</title>
		<link>http://twoguysarguing.wordpress.com/2011/09/28/competing-parsers/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/09/28/competing-parsers/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 23:17:30 +0000</pubDate>
		<dc:creator>youngnh</dc:creator>
				<category><![CDATA[clojure]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[parsec]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1320</guid>
		<description><![CDATA[So, I&#8217;m writing a parser for the Turtle serialization format for RDF. In addition to being a format we use all the time at Revelytix, its a decently compact grammar, giving me a good chance to implement it using The Parsatron and suss out some of the library&#8217;s rough edges. I hit my first rough [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1320&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;m writing a parser for the Turtle serialization format for RDF. In addition to being a format we use all the time at <a href="http://revelytix.com">Revelytix</a>, its a decently compact <a href="http://www.w3.org/TeamSubmission/turtle/#sec-grammar-grammar">grammar</a>, giving me a good chance to implement it using The Parsatron and suss out some of the library&#8217;s rough edges.</p>
<p>I hit my first rough edge with the <code>longString</code> production:</p>
<pre><code>longString ::= """" lcharacter* """</code></pre>
<p>but, having already implemented the <code>lcharacter</code> parser already, I didn&#8217;t see the subtleties in this production and plowed ahead with this straightforward definition:</p>
<pre><code>(defparser long-string []
  (between (times 3 (char \")) (times 3 (char \"))
           (many (lcharacter))))
</code></pre>
<p>Which looks great and compiles without complaint, but when you feed it input, it immediately complains:</p>
<pre><code>&gt; (run (long-string) "\"\"\"roughshod\"\"\"")

Unexpected end of input at line: 1 column: 16
[Thrown class java.lang.RuntimeException]
</code></pre>
<p>The message here could be better, and I&#8217;ll work on that. I would want it to say <code>Unexpected end of input, expected '"""'</code>, because what happened was the <code>(many (lcharacter))</code> parser consumed too much.</p>
<p>Turns out, <code>lcharacter</code> is defined in the grammar to include double quotes, so <code>(many (lcharacter))</code> ate as many as it could until it literally ran out of input.</p>
<p>A good regex can handle this:</p>
<pre><code>&gt; (re-find #"\"\"\".*\"\"\"" "\"\"\"roughshod\"\"\"")
"\"\"\"roughshod\"\"\""
</code></pre>
<p>So we should be able to as well. To keep track of whether or not we&#8217;ve consumed a hat trick of quotes, my first attempt looked something like this:</p>
<pre><code>(defparser long-string []
  (letfn [(middle-part [s]
            (let-&gt;&gt; [c (lcharacter)]
              (if (= c \")
                (two-left s)
                (middle-part (concat s [c])))))
          (two-left [s]
            (let-&gt;&gt; [c (lcharacter)]
              (if (= c \")
                (one-left s)
                (middle-part (concat s [\" c])))))
          (one-left [s]
            (let-&gt;&gt; [c (lcharacter)]
              (if (= c \")
                (always s)
                (middle-part (concat s [\" \" c])))))]
    (&gt;&gt; (times 3 (char \"))
        (middle-part []))))
</code></pre>
<p>Which uses 3 local, mutually-recursive functions to &#8220;count&#8221; each consecutive double quote. And they all look a lot alike. I refactored to this:</p>
<pre><code>(defparser long-string []
  (letfn [(middle-part [s n]
            (let-&gt;&gt; [c (lcharacter)]
              (if (= c \")
                (case n
                      0 (middle-part s 1)
                      1 (middle-part s 2)
                      2 (always s))
                (middle-part (concat s (repeat n \") [c]) 0))))]
    (&gt;&gt; (times 3 (char \"))
        (middle-part [] 0))))
</code></pre>
<p>The above works well, but the problem arises in the first place because <code>lcharacter</code> and <code>"""</code> share the same single-character lookahead. By examining only the next character in the input, we can&#8217;t<br />
tell if it should belong to <code>lcharacter</code> or <code>"""</code>. This suggests that we can lookahead 3 characters at a time and if we receive <code>"""</code>, then we can interpret that not as 3 <code>lcharacter</code>s, but as a terminating triple double quote.</p>
<pre><code>(defparser long-string []
  (between (times 3 (char \")) (times 3 (char \"))
           (many
            (let-&gt;&gt; [cs (lookahead (times 3 (lcharacter)))]
              (if (= cs [\" \" \"])
                (never)
                (lcharacter))))))
</code></pre>
<p>I&#8217;m not sure quite which way to go, nor can I immediately see a way to make a higher-level lookahead parser that ensures that 2 parsers don&#8217;t stomp all over each other, though that would be quite ideal. If you can, chime in below in the comments.</p>
<p>If you&#8217;d like to follow the development of The Parsatron, it&#8217;s on <a href="https://github.com/youngnh/parsatron">github</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1320/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1320&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/09/28/competing-parsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cf86a97e3c95ee19defeaee55a84f5d7?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">youngnh</media:title>
		</media:content>
	</item>
		<item>
		<title>Pro Tips: Get Your Windows MSI Installer Logs</title>
		<link>http://twoguysarguing.wordpress.com/2011/07/25/pro-tips-get-your-windows-msi-installer-logs/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/07/25/pro-tips-get-your-windows-msi-installer-logs/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 16:33:17 +0000</pubDate>
		<dc:creator>benjaminplee</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[notes_to_self]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[msi]]></category>
		<category><![CDATA[pro-tips]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1316</guid>
		<description><![CDATA[Want more information about what an .msi is doing on your system or what caused a generic and completely useless error message to pop up?  Run the following command substituting the path to your .msi from the command line and the output file will contain verbose logs.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1316&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Want more information about what an .msi is doing on your system or what caused a generic and completely useless error message to pop up?  Run the following command substituting the path to your .msi from the command line and the output file will contain verbose logs.</p>
<p><pre class="brush: plain;">
msiexec /i filename.msi /l*v log.txt
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1316&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/07/25/pro-tips-get-your-windows-msi-installer-logs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe3038bf78f8cd98c1ad37ee7ce45d3e?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">benjaminplee</media:title>
		</media:content>
	</item>
		<item>
		<title>Pro Tips: Run Multiple Jenkins CI Servers on a Single Machine</title>
		<link>http://twoguysarguing.wordpress.com/2011/07/24/pro-tips-run-multiple-jenkins-ci-servers-on-a-single-machine/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/07/24/pro-tips-run-multiple-jenkins-ci-servers-on-a-single-machine/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 02:43:21 +0000</pubDate>
		<dc:creator>benjaminplee</dc:creator>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[software testing]]></category>
		<category><![CDATA[continuous-integration]]></category>
		<category><![CDATA[hudson]]></category>
		<category><![CDATA[jenkins]]></category>
		<category><![CDATA[pro-tips]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1310</guid>
		<description><![CDATA[Jenkins (or Hudson if you work for Oracle) is a great, simple and steady continuous integration and build server.  One of its greatest features is that despite being packaged as a standard .war ready to be dropped into your JEE web container of choice &#8230; it also contains an embedded web container that makes the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1310&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://jenkins-ci.org/">Jenkins</a></strong> (<em>or Hudson if you work for Oracle</em>) is a great, simple and steady continuous integration and build server.  One of its greatest features is that despite being packaged as a standard .war ready to be dropped into your JEE web container of choice &#8230; it also contains an <a href="http://weblogs.java.net/blog/kohsuke/archive/2007/02/hudson_became_s.html">embedded web container</a> that makes the .war everything you need in most situations.  Simply run</p>
<p><pre class="brush: plain; light: true;">
java -jar jenkins.war
</pre></p>
<p>and up starts Jenkins on port 8080 in all of its glory.  All of Jenkins&#8217; configuration files, plugins, and working directories go under &lt;USER_HOME&gt;/.jenkins by default.  Perfect.</p>
<p>Except if you want to run multiple instances on the same machine.  We are going to get a config folder collision.  It turns out this is a piece of cake, but <a href="https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins">the docs</a> are hard to find.  Jenkins will use a JENKINS_HOME path environement variable for its configuration files if one is set so a simple change means we can run Jenkins out of any directory we desire:</p>
<p><pre class="brush: plain; light: true;">
java -DJENKINS_HOME=/path/to/configs -jar jenkins.war
</pre></p>
<p>What about the port you say?  <a href="http://www.java.net/external?url=http://winstone.sourceforge.net/">Winston</a>, the embedded web container used, has a simple property for this too:</p>
<p><pre class="brush: plain; light: true;">
java -DJENKINS_HOME=/path/to/configs -jar jenkins.war --httpPort=9090
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1310/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1310&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/07/24/pro-tips-run-multiple-jenkins-ci-servers-on-a-single-machine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe3038bf78f8cd98c1ad37ee7ce45d3e?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">benjaminplee</media:title>
		</media:content>
	</item>
		<item>
		<title>Pro Tips: Color Your Tail With Perl</title>
		<link>http://twoguysarguing.wordpress.com/2011/03/22/pro-tips-color-your-tail-with-perl/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/03/22/pro-tips-color-your-tail-with-perl/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 16:48:57 +0000</pubDate>
		<dc:creator>benjaminplee</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[pro-tips]]></category>
		<category><![CDATA[tail]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1303</guid>
		<description><![CDATA[We ran into a situation today where our JEE server was logging everything twice.  Sadly, this meant that errors and warnings were logged as INFO and were missed. Since we watched the logs most often using the tail command, the quick and dirty solution was to have tail output lines containing WARN/ERROR/SEVERE in different colors [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1303&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We ran into a situation today where our JEE server was logging everything twice.  Sadly, this meant that errors and warnings were logged as INFO and were missed.</p>
<p><pre class="brush: plain;">
2011-03-22 11:40:40,884 INFO  [STDOUT] (main) 11:40:40,884 WARN [ProcessRoles] Could NOT find role XXXX
</pre></p>
<p>Since we watched the logs most often using the tail command, the quick and dirty solution was to have tail output lines containing WARN/ERROR/SEVERE in different colors that would stand out as the scrolled past.  The bash/perl script below is the fruit of my hacking.  Suggestions for improvements welcome.</p>
<p><pre class="brush: bash;">
t() {
tail -100f $1 | perl -pe 's/^.*SEVERE.*$/\e[1;37;45m$&amp;\e[0m/g' | perl -pe 's/^.*ERROR.*$/\e[1;37;41m$&amp;\e[0m/g' | perl -pe 's/^.*WARN.*$/\e[1;33;40m$&amp;\e[0m/g'
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1303/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1303&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/03/22/pro-tips-color-your-tail-with-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe3038bf78f8cd98c1ad37ee7ce45d3e?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">benjaminplee</media:title>
		</media:content>
	</item>
		<item>
		<title>guarding an expression</title>
		<link>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 01:00:35 +0000</pubDate>
		<dc:creator>youngnh</dc:creator>
				<category><![CDATA[clojure]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1295</guid>
		<description><![CDATA[Oftentimes, I want to make some computation, apply the result to a predicate, and if it passes, return that result. If the predicate does not succeed, I usually want to return some other value. I&#8217;ve run into this situation before, with no satisfying resolution. My code usually ends up looking like so: (let [value (some-computation [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1295&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Oftentimes, I want to make some computation, apply the result to a predicate, and if it passes, return that result.  If the predicate does not succeed, I usually want to return some other value.  I&#8217;ve run into <a href="http://twitter.com/natesbrain/status/24199589657">this situation</a> before, with no satisfying resolution. My code usually ends up looking like so:</p>
<pre><code>(let [value (some-computation x y z)]
  (if (check? value)
    value
    some-other-default-value))
</code></pre>
<p>Which is overly verbose, even for Clojure, if you ask me.  There&#8217;s a <code>let</code> and <code>value</code> appears 3 times for a fairly straightforward idiom.  I think what I&#8217;d like to write instead is:</p>
<pre><code>(guard check?
  (some-computation x y z)
  some-other-default-value)
</code></pre>
<p>The following macro does the trick of expanding to the verbose form I&#8217;ve been writing:</p>
<pre><code>(defmacro guard [pred then else]
  `(let [x# ~then]
     (if (~pred x#)
       x#
       ~else)))
</code></pre>
<p>Now, the awkward thing about the above is that unlike an if-statement, the order in which you read things is not the order in which they get executed in.  Reading it, the execution happens on line 2 first, line 1 second, and then possibly on line 3.  My question to the blogosphere is, does Clojure already have something like this lurking in a lib somewhere? Or is there a blindingly obvious solution to this that I&#8217;m overlooking?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1295&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cf86a97e3c95ee19defeaee55a84f5d7?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">youngnh</media:title>
		</media:content>
	</item>
		<item>
		<title>2011.tech_resolutions.pop(5.questions)</title>
		<link>http://twoguysarguing.wordpress.com/2011/01/06/2011-tech_resolutions-pop5-questions/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/01/06/2011-tech_resolutions-pop5-questions/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 17:04:43 +0000</pubDate>
		<dc:creator>youngnh</dc:creator>
				<category><![CDATA[questions]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1280</guid>
		<description><![CDATA[What are you currently hacking on? Just before Christmas, I put together a small LL(1) parser-generator in Clojure. LL(1) has the distinction of being one of the simplest classes of grammars to parse, and a great number of textbooks on the subject will tell you that it&#8217;s often quicker to write a parser by hand [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1280&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<ol>
<li>
<h3>What are you currently hacking on?</h3>
<p>Just before Christmas, I put together a small LL(1) parser-generator in Clojure.  LL(1) has the distinction of being one of the simplest classes of grammars to parse, and a great number of textbooks on the subject will tell you that it&#8217;s often quicker to write a parser by hand for a LL(1) grammar than to go to the trouble of using a parser-generator.  I think my code removes most of those objections.  However, it currently suffers from 4 problems that I vowed I would remedy before it saw the light of day: its very slow for only marginally deep parse trees, it has no tests, no documentation, and the error messages it spews forth are currently only meaningful to myself.  None of these problems are sexy, nor could the process of solving them be construed as &#8220;hacking&#8221;, so my motivation to finish the project has plummeted.</p>
</li>
<li>
<h3>What do you want to hack on more in 2011?</h3>
<p>I have no shortage of ideas that could be expressed via computational algorithms, but recently I&#8217;ve had a harder and harder time convincing myself that any of them are significant in any way other than the challenge in realizing them.  This year I&#8217;d like to stay away from the &#8220;because it&#8217;s there&#8221; projects.  I&#8217;d like to hack on things that:</p>
<ul>
<li><strong>someone would pay money for:</strong> <em>a fart app, for example, or possibly one that does facial recognition so that if you think you&#8217;ve seen somebody famous on the street or simply can&#8217;t remember the name of the person you&#8217;re currently talking to, you can pull out your phone and shove its tiny camera in their face</em></li>
<li><strong>something that people I&#8217;ve never met before would find useful:</strong> <em>most of my keystrokes are deleted, a select few are saved to files, fewer still find themselves a part of a working project, and of those projects that people other than myself get their hands on, their purpose could generously be described as niche.  I write software largely for the compulsive pleasure of seeing an ephemeral thought produce flashing pixels on a screen, but I&#8217;d like to try writing something that might be useful to others at the same time.</em></li>
<li><strong>change an old way of doing things:</strong>  <em><a href="http://www.eaipatterns.com/ramblings/18_starbucks.html">Starbucks changed the way you order drinks</a>, <a href="http://reprog.wordpress.com/2010/03/30/a-brief-yet-helpful-lesson-on-elementary-resource-locking-strategy/">parenting at dinner is a contentious process</a>, and the airline industry has been sticking with a sub-optimal solution to <a href="http://en.wikipedia.org/wiki/Traveling_salesman_problem">one of the hardest problems in all of computation</a> but that doesn&#8217;t mean a <a href="http://www.greglindsay.org/articles/flight_plan/">few guys didn&#8217;t throw a bunch of servers at the problem</a> and give it <a href="http://en.wikipedia.org/wiki/DayJet">a go of their own</a> (and crashed and burned).  These are hacks in the best sense of the word.</em></li>
<li><strong>change how non-programmers interact with computers:</strong> <em>it pains me to watch people use software.  You might already be rolling your eyes in preparation for a rant from a programmer about non-technical people&#8217;s poor computer skills, but that&#8217;s not it.  What I see when my mother-in-law or grandfather use their computers is the incredibly resourceful, thoughtful and clever way in which they approach an inanimate, ineffable and often arbitrary hunk of plastic and silicon, and manage to make it do unbelievably complex things.  I&#8217;ve read the manuals, I spent four years in college and all of my professional career learning how these things are put together and I can barely get my wireless printer to work.  The only difference between us is that I have the ability to change the machine to match their understanding of it.  Helping non-programmers is my peace corps, my doctors without borders.</em></li>
</ul>
</li>
<li>
<h3>What do you want to stop hacking on in 2011?</h3>
<p>I think what I wrote above covered most of what I&#8217;d like to hack on, and being a very good dichotomist, I&#8217;d like to stop hacking on anything that isn&#8217;t a Big Idea.  This is not to confuse Big Ideas with small hacks.  Big projects never get finished.  Short sprints of interesting and valuable concepts are strongly encouraged, not the least for morale.  Anything that someone might ask &#8220;Why that?&#8221; of, and that I would respond with &#8220;well, because it just seemed neat&#8230;&#8221; should be viewed with strong suspicion in 2011.</p>
</li>
<li>
<h3>Big idea that just needs a free weekend to come to life?</h3>
<p>As you wrote big idea with a little &#8220;i&#8221;, and I&#8217;ve just finished pontificating on big &#8220;I&#8221; ideas, I&#8217;m going to say a Java compiler that does type inference.  I haven&#8217;t done my homework and checked if something like this already exists, so if it does, please point me in its direction.  Aside from the massive amount of typing (lol) it&#8217;d save, why should Scala get to have all the fun?  A slightly more powerful compiler might lead to a better, if sloppier, place for the Java masses.</p>
</li>
<li>
<h3>How can we get more arguing on this blog?</h3>
<p>We could go find that youtube video of two kids having an argument and put it up here, thereby reclaiming the rest of the hits from Google searches for &#8220;two guys arguing&#8221;.</p>
<p>If you&#8217;d like something software-related, pick the &#8220;social sciences&#8221; of programming, like methodologies, or productivity enhancements or what editor to use, as they often don&#8217;t have verifiable outcomes and thus can generate argument indefinitely.</p>
<p>Personally, I&#8217;ve found that <a href="2010/07/26/7-rules-for-writing-clojure-programs/">being wrong about a thing</a> leads to more comments and discussion than solving that thing competently.  On a positive note, I&#8217;d like to think that it has been our extreme competence in what we do that has kept this blog from rocketing us into the stratosphere of computer scientists around the world.</p>
</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1280/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1280&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/01/06/2011-tech_resolutions-pop5-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cf86a97e3c95ee19defeaee55a84f5d7?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">youngnh</media:title>
		</media:content>
	</item>
		<item>
		<title>A Solution from Purgatory (for the Matrix from Hell)</title>
		<link>http://twoguysarguing.wordpress.com/2011/01/02/a-solution-from-purgatory-for-the-matrix-from-hell/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/01/02/a-solution-from-purgatory-for-the-matrix-from-hell/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 06:26:39 +0000</pubDate>
		<dc:creator>benjaminplee</dc:creator>
				<category><![CDATA[challenge]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[puzzle]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1274</guid>
		<description><![CDATA[This post attempts to recount some of my thought process which eventually (more than a year later) lead to the Matrix from Hell puzzle I posted about a few days ago.  If you don't want to know my answer, don't read the rest of this post.  My final solution is at the bottom.

You have been warned.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1274&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://xkcd.com/74/"><img class="alignright" title="Binary Sudoku" src="http://imgs.xkcd.com/comics/su_doku.jpg" alt="" width="100" height="125" /></a>This post attempts to recount some of my thought process which eventually (more than a year later) lead to the <a title="Matrix Puzzle From Hell or: How I Learned to Stop Worrying and Love the Patterns" href="http://twoguysarguing.wordpress.com/2010/12/30/matrix-puzzle-from-hell-or-how-i-learned-to-stop-worrying-and-love-the-patterns/" target="_blank">Matrix from Hell puzzle</a> I posted about a few days ago.  <span style="text-decoration:underline;"><strong>If you don&#8217;t want to know my answer, don&#8217;t read the rest of this post.  My final solution is at the bottom.</strong></span></h3>
<h4>&#8230;</h4>
<h4><em>You have been warned.</em></h4>
<p style="text-align:center;">~~~~~~~~~~~~~~~~~~~</p>
<p style="text-align:center;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
<p style="text-align:center;">~~~~~~~~~~~~~~~~~~~</p>
<p>Below is a list of my general thought process and the main ideas/revelations/halucinations that I know helped me to my solution.  An annotated matrix is at the bottom with some of the ideas highlighted in different colors.</p>
<ul>
<li>Should indices start at 0 or 1?</li>
<li>Values along either axis count up by 1 in both directions when the other =0</li>
<li>Values are duplicated over the f(x)=y axis &#8211;&gt; Order of indices given to function is inmaterial since they can be swapped<br />
<em>[The <span style="text-decoration:underline;color:#ff0000;">RED</span> 5 can be seen duplicated over the diagonal] </em></li>
<li>Calculation of max/min index is O(1) so stop worry about it and &#8220;forget&#8221; the bottom half of the matrix (assume X&gt;= Y)</li>
<li>Values generally increase as they go right/down but not always</li>
<li><strong>f(x,x)=0</strong>, f(x,0)=x</li>
<li>Values are symmetrical perpendicular to f(x)=y IFF the bounding square in question is a power of 2</li>
<li><strong>&#8220;Quad&#8221;</strong> patterns can be seen repeating for every power of 2.  In each &#8220;Quad&#8221; the top left quadrant is the same as the bottom right and the top right is the same as the bottom left.<br />
<em>[Each "Quad" of the example matrix is outlined in <span style="text-decoration:underline;"><span style="color:#0000ff;">BLUE</span></span> with the quadrants in <span style="text-decoration:underline;"><span style="color:#33cccc;">LIGHT BLUE</span></span>. <span style="text-decoration:underline;color:#ff00ff;">PINK</span> shows the repetition] </em></li>
<li>power of 2 repeating nature of the values leads to thinking of <strong>binary trees</strong></li>
<li>binary trees leads to thinking about a possible solution which could run in O(log2 n) time:
<ul>
<li>In a nut shell, for a given (X,Y), algorithm would find smallest boudning power of 2 including X and would <strong>walk</strong> back &#8220;Quad&#8221;s by each successivly smaller power of 2 &#8220;Quad&#8221; until the last one is met.  For each &#8220;Quad&#8221; determine which quadrant the value lives in and remap to root values.</li>
<li>Debate if this would really work for large numbers and if it could be reduced to constant time function by math that I have forgotton from college/HS</li>
<li>Dismiss b/c I can&#8217;t remember a way and base idea is &gt; O(1)</li>
</ul>
</li>
<li>Binary trace back algorithm idea makes me realize that it can be also looked at as the <strong>&#8220;binary&#8221; representation</strong> of a number (e.g. 01011011010) where each 1 represents a &#8220;Quad&#8221; where the value was in the upper right or bottom left and vica-verca.<br />
<em>[Following the matrix value at (5,6) can be seen <span style="text-decoration:underline;"><span style="color:#ff9900;">ORANGE</span></span>.  The value 3 is in the bottom right  of the 1st "Quad", then BL, &amp; TR. {BR BL TR} =&gt; {101} =&gt; {3}]</em></li>
<li><strong>Remembered that f(x,y)=0 IFF x==y &#8230;. which means that difference between X and Y is important to value of f()</strong></li>
<li><em><span style="color:#808080;"><strong>Eureka!</strong></span><strong></strong></em>
<ul>
<li><strong><span style="color:#ffffff;">F(X, Y) = X xor Y</span></strong></li>
<li><em><span style="color:#999999;">solution typed above in white on white to protect the innocent. highlight to view.</span></em></li>
</ul>
</li>
</ul>
<h3><a href="http://twoguysarguing.files.wordpress.com/2011/01/matrix_annotated.png"><img class="aligncenter size-medium wp-image-1276" title="matrix_annotated" src="http://twoguysarguing.files.wordpress.com/2011/01/matrix_annotated.png?w=242&#038;h=300" alt="sample matrix with some of my thought process drawn out" width="242" height="300" /></a></h3>
<h3 style="text-align:center;">That is it.  I never said it was pretty or made any sense.</h3>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1274/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1274&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/01/02/a-solution-from-purgatory-for-the-matrix-from-hell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe3038bf78f8cd98c1ad37ee7ce45d3e?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">benjaminplee</media:title>
		</media:content>

		<media:content url="http://imgs.xkcd.com/comics/su_doku.jpg" medium="image">
			<media:title type="html">Binary Sudoku</media:title>
		</media:content>

		<media:content url="http://twoguysarguing.files.wordpress.com/2011/01/matrix_annotated.png?w=242" medium="image">
			<media:title type="html">matrix_annotated</media:title>
		</media:content>
	</item>
		<item>
		<title>2011.tech_resolutions.push(5.questions)</title>
		<link>http://twoguysarguing.wordpress.com/2011/01/01/2011-tech_resolutions-push5-questions/</link>
		<comments>http://twoguysarguing.wordpress.com/2011/01/01/2011-tech_resolutions-push5-questions/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 05:25:14 +0000</pubDate>
		<dc:creator>benjaminplee</dc:creator>
				<category><![CDATA[questions]]></category>
		<category><![CDATA[5 questions]]></category>
		<category><![CDATA[new year]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1270</guid>
		<description><![CDATA[In the spirit of the first posts to this blog and the new year I poste the following 5 questions to Mr Young&#8230; What are you currently hacking on? What do you want to hack on more in 2011? What do you want to stop hacking on in 2011? Big idea that just needs a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1270&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>In the spirit of the first posts to this blog and the new year I poste the following 5 questions to Mr Young&#8230;</h2>
<ol>
<li>
<h3>What are you currently hacking on?</h3>
</li>
<li>
<h3>What do you want to hack on more in 2011?</h3>
</li>
<li>
<h3>What do you want to stop hacking on in 2011?</h3>
</li>
<li>
<h3>Big idea that just needs a free weekend to come to life?</h3>
</li>
<li>
<h3>How can we get more arguing on this blog?</h3>
</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1270/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1270&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2011/01/01/2011-tech_resolutions-push5-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe3038bf78f8cd98c1ad37ee7ce45d3e?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">benjaminplee</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Meta-Programming And Extension Methods Question</title>
		<link>http://twoguysarguing.wordpress.com/2010/12/30/c-meta-programming-and-extension-methods-question/</link>
		<comments>http://twoguysarguing.wordpress.com/2010/12/30/c-meta-programming-and-extension-methods-question/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 21:22:36 +0000</pubDate>
		<dc:creator>benjaminplee</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[asp.net mvc 2]]></category>
		<category><![CDATA[metaprogramming]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1262</guid>
		<description><![CDATA[First, it should be noted that my ASP.Net MVC-foo is yet great and I know this.  If you know a better way to do this, please take the time to explain how you are superior.  If you don&#8217;t, how will we ever know? Working with ASP.Net MVC 2 client-side form validation this past week, I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1262&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><span style="color:#808080;"><em>First, it should be noted that my ASP.Net MVC-foo is yet great and I know this.  If you know a better way to do this, please take the time to explain how you are superior.  If you don&#8217;t, how will we ever know?</em></span></p></blockquote>
<p><a href="http://www.flickr.com/photos/fiftyfeet/248822545/"><img class="alignright size-full wp-image-1263" title="for rant" src="http://twoguysarguing.files.wordpress.com/2010/12/248822545_f88acdbb33_m.jpg?w=720" alt=""   /></a>Working with <strong>ASP.Net MVC 2</strong> client-side form validation this past week, I ran into two unfortunate (IMHO) facts which kept tripping me up:</p>
<ol>
<li><strong>Html.ClientValidationEnabled()</strong> must be called as a scriptlet BEFORE the form is created</li>
<li><strong>Html.ValidateFor</strong> or <strong>Html.ValidationMessageFor</strong> must be called for EACH property of the model you want validated.</li>
</ol>
<p><em><span style="color:#808080;">*** This <a href="http://stackoverflow.com/questions/1581344/how-does-validation-in-asp-net-mvc-2-actually-work" target="_blank">StackOverflow</a> <a href="http://stackoverflow.com/questions/1581344/how-does-validation-in-asp-net-mvc-2-actually-work" target="_blank">answer</a> includes a couple other important &amp; useful things to note</span></em></p>
<p>These two issues (and many more) bother me about ASP.Net MVC 2 client-side validation but #2 in particular was really ticking me off.  I like that I can conditionally turn validation on/off on a field by field basis &#8230; but why make me enumerate all validation-needed model fields twice in my view!?  Especially in my case where I want validation turned on for ALL model object fields that have DataAnnotation Validations defined for.  Obviously the fields are going to be enumerated in the view once; how else are the text boxes and drop downs going to be created, but why make me list out each field AGAIN just to turn on validation?</p>
<h3><em>All of this amounts to one <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank">WET</a> solution. Am I missing something?</em></h3>
<p>The best solution I have seen, and the one I am about to start implementing, is this one by <a href="http://blogs.msdn.com/b/rickandy/archive/2009/08/18/dry-ing-out-the-mvc-2-templated-helpers.aspx" target="_blank">Rick Anderson over at MSDN</a> found via this related <a href="http://forums.asp.net/p/1540494/3753267.aspx" target="_blank">forum post</a>.  The idea is to create additional Html helper extension methods which will combine the creation of the HTML form element with turning on and configuring validation.  This solution has the benefit of making me enumerate the model fields being used only ONCE in my view code and reads cleaner.</p>
<p>The only problem is that I have to walk through our application, find anywhere that is using a built in HtmlHelper extension method to build an HTML form element (e.g. input tag), build a new validating wrapper extension method that matches the signature of the original, and then replace the original code with the new extension method.  This can be done, but is time consuming and error prone.  And I am lazy.</p>
<h3>The real issue &#8230;</h3>
<blockquote><p>I want to &#8230; create additional HtmlHelper extension methods based on all existing ones that produce form elements and take in a Linq expression to find the model property that first pass that expression to helper.ValidateFor() and then return the original extension method&#8217;s valued.</p></blockquote>
<h3><strong>Is there any meta-programming feature or technique in C# that will allow me to concisely do that?</strong></h3>
<p><em>e.g.</em></p>
<p>Since Html.TextBoxFor(user =&gt; user.FirstName) is used in our app, as it stands I will am going to create a custom extension method similar to:</p>
<p><pre class="brush: csharp;">
public static class ValidatingFormElementsExtension
{
  public static MvcHtmlString ValidatedTextBoxFor&lt;TModel, TProperty&gt;(this HtmlHelper&lt;TModel&gt; helper, Expression&lt;Func&lt;TModel, TProperty&gt;&gt; expression)
  {
    helper.ValidateFor(expression);
    return helper.TextBoxFor(expression);
  }

  // and so on for EACH one we use

}
</pre></p>
<p><strong>Anyone have any ideas?  Am I completely off base with this? Is there a better way?</strong></p>
<p style="text-align:center;">~~~~~~~~~~</p>
<p>&lt;mini-related-rant&gt;</p>
<p>A few more quick cracks at ASP.Net MVC  that I need to get off my chest</p>
<ul>
<li>Why are so many things done in scriptlets!?  I feel like I am back in the vanilla JSP days of yesteryear.</li>
<li>They are Annotations in Java and Attributes in C# &#8230;. so why are the data validation attributes defined in System.ComponentModel.DataAnnotations?</li>
<li>I get that HTML checkbox form input fields have TRUE/FALSE values passed back when the form is submitted, and that doesn&#8217;t map perfectly to how other fields are handled by the Required attribute &#8230;. but why was NOTHING included to do this?  Having to use a RegularExpression validator for [Tt]rue is clumsy no?</li>
</ul>
<p>&lt;/mini-related-rant&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1262/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1262/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1262/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1262&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2010/12/30/c-meta-programming-and-extension-methods-question/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe3038bf78f8cd98c1ad37ee7ce45d3e?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">benjaminplee</media:title>
		</media:content>

		<media:content url="http://twoguysarguing.files.wordpress.com/2010/12/248822545_f88acdbb33_m.jpg" medium="image">
			<media:title type="html">for rant</media:title>
		</media:content>
	</item>
		<item>
		<title>Matrix Puzzle From Hell or: How I Learned to Stop Worrying and Love the Patterns</title>
		<link>http://twoguysarguing.wordpress.com/2010/12/30/matrix-puzzle-from-hell-or-how-i-learned-to-stop-worrying-and-love-the-patterns/</link>
		<comments>http://twoguysarguing.wordpress.com/2010/12/30/matrix-puzzle-from-hell-or-how-i-learned-to-stop-worrying-and-love-the-patterns/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 19:33:03 +0000</pubDate>
		<dc:creator>benjaminplee</dc:creator>
				<category><![CDATA[challenge]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[puzzle]]></category>

		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1246</guid>
		<description><![CDATA[The Stage About a year ago, Mr. King (@Adkron) posed a math puzzle on our team&#8217;s whiteboard first thing one morning.  The problem seemed at the same time very complex and strangely simple.  Amos said that he had found it surfing the web the night before and that it was from some company&#8217;s interview or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1246&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h5 style="text-align:left;"><span style="font-size:20px;"><a href="http://www.flickr.com/photos/arimoore/3810971713/"><img class="alignright size-full wp-image-1258" title="matrix food" src="http://twoguysarguing.files.wordpress.com/2010/12/3810971713_d1248bb29e_m.jpg?w=720" alt=""   /></a>The Stage</span></h5>
<p>About a year ago, Mr. King (<a title="Amos on Twitter" href="http://twitter.com/#!/adkron" target="_blank">@Adkron</a>) posed a math puzzle on our team&#8217;s whiteboard first thing one morning.  The problem seemed at the same time very complex and strangely simple.  Amos said that he had found it surfing the web the night before and that it was from some company&#8217;s interview or resume-submitting questions.</p>
<p>After several passionate whiteboarding sessions including members of our team, and any poor souls who walked by (I believe Mr. Young falls into this group), no one had a solution.  Eventually the whiteboard was clearred for more &#8220;important&#8221; work but the puzzle lingered with me.  On several occasions over the past year I have redrawn the matrix on a pad of paper and spent and hour or two trying to decipher the patterns and make sense of the answer tickling at edge of my brain.</p>
<p>This past week, while drifting off to sleep, the puzzle popped back into my head.  After a few moments a number of ideas I had had months before fell together in just the right way for me to FINALLY figure out a solution.  <strong><em>Eureka</em></strong>! (I mentally shouted) and got out of bed to find a piece of paper to work through some more examples and prove myself right.</p>
<h2>The Puzzle</h2>
<blockquote><p><em>Given a 2D matrix such that each cell&#8217;s value is defined as follows:</em></p>
<p><em>&gt;&gt; The smallest non-negative integer not already present to the &#8220;left&#8221; or &#8220;above&#8221; &lt;&lt;</em></p>
<p><em>Determine an constant time function ( <a title="Wikipedia article for Big-O Notation" href="http://en.wikipedia.org/wiki/Big_O_notation" target="_blank">O(1)</a> ) which given X and Y indices will return the value of the matrix cell at (X,Y).</em></p></blockquote>
<p>For the visual people in the crowd, the top left corner or said matrix looks something like this:</p>
<div id="attachment_1254" class="wp-caption aligncenter" style="width: 252px"><a href="http://twoguysarguing.files.wordpress.com/2010/12/matrix.png"><img class="size-medium wp-image-1254" title="First 8x8 cells of matrix puzzle" src="http://twoguysarguing.files.wordpress.com/2010/12/matrix.png?w=242&#038;h=300" alt="First 8x8 cells of matrix puzzle" width="242" height="300" /></a><p class="wp-caption-text">First 8x8 cells of matrix puzzle</p></div>
<p>The picture only shows the top 8&#215;8 of the defined matrix as an example.  We can see that whatever f(x,y) you come up with needs to equal the following example values</p>
<p>f(0,0) = 0<br />
f(1,0) = 1<br />
f(2,0) = 2<br />
f(3,0) = 3<br />
f(3,1) = 2<br />
f(3,2) = 1<br />
&#8230;&#8230;</p>
<p><strong>The real key here is that the solution needs to function in constant time: <a href="http://en.wikipedia.org/wiki/Big_O_notation" target="_blank">O(1)</a></strong>.  This means that computing the matrix value at (6,3) should be the same cost computationally as computing the matrix value at (10000000,4500005).</p>
<p><span style="color:#008000;"><strong>Anyone can write a program to compute the whole matrix out to your point (in theory) but can you come up with a better solution? In less than a year?</strong></span></p>
<h2>The Solution</h2>
<h2><span style="font-weight:normal;font-size:13px;">Not just yet.  I will post my thought process and eventual solution soon in a separate post.</span></h2>
<h5 style="text-align:center;"><span style="color:#888888;"><em>** I didn&#8217;t think of this puzzle, nor guarantee that I am remembering it correctly **</em></span><br />
<span style="color:#888888;"><em>** If you know who did or have any corrections, please leave a comment  below **</em></span></h5>
<p><span style="font-weight:normal;font-size:13px;"><br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twoguysarguing.wordpress.com/1246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twoguysarguing.wordpress.com/1246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twoguysarguing.wordpress.com/1246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twoguysarguing.wordpress.com/1246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twoguysarguing.wordpress.com/1246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twoguysarguing.wordpress.com/1246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twoguysarguing.wordpress.com/1246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twoguysarguing.wordpress.com/1246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twoguysarguing.wordpress.com/1246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twoguysarguing.wordpress.com/1246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twoguysarguing.wordpress.com/1246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twoguysarguing.wordpress.com/1246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twoguysarguing.wordpress.com/1246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twoguysarguing.wordpress.com/1246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twoguysarguing.wordpress.com&amp;blog=6764274&amp;post=1246&amp;subd=twoguysarguing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twoguysarguing.wordpress.com/2010/12/30/matrix-puzzle-from-hell-or-how-i-learned-to-stop-worrying-and-love-the-patterns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe3038bf78f8cd98c1ad37ee7ce45d3e?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">benjaminplee</media:title>
		</media:content>

		<media:content url="http://twoguysarguing.files.wordpress.com/2010/12/3810971713_d1248bb29e_m.jpg" medium="image">
			<media:title type="html">matrix food</media:title>
		</media:content>

		<media:content url="http://twoguysarguing.files.wordpress.com/2010/12/matrix.png?w=242" medium="image">
			<media:title type="html">First 8x8 cells of matrix puzzle</media:title>
		</media:content>
	</item>
	</channel>
</rss>
