<?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>obfuscated.org &#187; Programming</title>
	<atom:link href="http://www.obfuscated.org/folksonomy/tags/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.obfuscated.org</link>
	<description>I will not explain what this weblog is all about in a few words.</description>
	<lastBuildDate>Fri, 16 Jul 2010 17:57:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Twitter is my randomness entropy</title>
		<link>http://www.obfuscated.org/2009/10/twitter-is-my-randomness-entropy/</link>
		<comments>http://www.obfuscated.org/2009/10/twitter-is-my-randomness-entropy/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 05:06:51 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/?p=792</guid>
		<description><![CDATA[Inspired by Henry&#8217;s Facebook comment. import urllib2, hashlib TWITTER = 'http://twitter.com/statuses/public_timeline.json' def hashed(seq): sha1 = hashlib.sha1() for x in seq: sha1.update(x) yield sha1.digest() def words(wordsize, seq): for x in seq: for i in xrange(0, len(x), wordsize): yield int(x[i:(wordsize + i)].encode('hex'), 16) def twitrandoms(wordsize = 4, chunksize = 37): def infinite_twitrandom(): while True: data = urllib2.urlopen(TWITTER).read() [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by Henry&#8217;s Facebook comment.</p>

<pre>import urllib2, hashlib

TWITTER = 'http://twitter.com/statuses/public_timeline.json'

def hashed(seq):
    sha1 = hashlib.sha1()
    for x in seq:
        sha1.update(x)
        yield sha1.digest()

def words(wordsize, seq):
    for x in seq:
        for i in xrange(0, len(x), wordsize):
            yield int(x[i:(wordsize + i)].encode('hex'), 16)

def twitrandoms(wordsize = 4, chunksize = 37):
    def infinite_twitrandom():
        while True:
            data = urllib2.urlopen(TWITTER).read()
            for i in range(0, len(data), chunksize):
                yield data[i:(chunksize + i)]
    return words(wordsize, hashed(infinite_twitrandom()))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2009/10/twitter-is-my-randomness-entropy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Help me write idiomatically correct Python</title>
		<link>http://www.obfuscated.org/2008/09/help-me-write-idiomatically-correct-python/</link>
		<comments>http://www.obfuscated.org/2008/09/help-me-write-idiomatically-correct-python/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 03:19:36 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/?p=585</guid>
		<description><![CDATA[Why can&#8217;t the features I like from every programming language be available all the time? It really bugs me that, for instance, I can&#8217;t get lazy lists and patter matching in Python and I can&#8217;t get, well, there&#8217;s got to be something that Python has that&#8217;s sort of a pain in Haskell. I/O, for example. [...]]]></description>
			<content:encoded><![CDATA[<p>Why can&#8217;t the features I like from every programming language be available all the time?  It really bugs me that, for instance, I can&#8217;t get lazy lists and patter matching in Python and I can&#8217;t get, well, there&#8217;s got to be something that Python has that&#8217;s sort of a pain in Haskell.  I/O, for example.</p>

<p>Anyway, I want code that does this:</p>

<pre><code>import Prelude hiding (Left, Right)

data EitherBoth a = Left a | Right a | Both a a deriving Show

cmpseq :: (Ord a) =&gt; (a -&gt; a -&gt; Ordering) -&gt; [a] -&gt; [a] -&gt; [EitherBoth a]
cmpseq _ [] rs = map Right rs
cmpseq _ ls [] = map Left  ls
cmpseq cmp (l:ls) (r:rs) = case (cmp l r) of
                             LT -&gt; Left   l : cmpseq cmp ls  (r:rs)
                             GT -&gt; Right  r : cmpseq cmp (l:ls) rs
                             EQ -&gt; Both l r : cmpseq cmp ls     rs
</code></pre>

<p>So given two ordered lists and a comparison function, I want to know (efficiently, and preserving order) which elements are just in one list and which are in both.  The Haskell version is pretty clear and pretty concise.  (Bonus points: if you have a better way to do this in Haskell &mdash; and I&#8217;m sure there is one &mdash; I&#8217;d love to hear about it.)</p>

<p>So far, the best I can do in Python is this rather ugly mess:</p>

<pre><code>def cmpseq(f, xs, ys):
    nx, ny = len(xs), len(ys)
    ix, iy = 0, 0
    while ix &lt; nx and iy &lt; ny:
        r = f(xs[ix], ys[iy])
        if -1 == r:
            yield (xs[ix], None)
            ix = 1 + ix
        elif 1 == r:
            yield (None, ys[iy])
            iy = 1 + iy
        else:
            yield (xs[ix], ys[iy])
            ix, iy = 1 + ix, 1 + iy
    while ix &lt; nx:
        yield (xs[ix], None)
        ix = 1 + ix
    while iy &lt; ny:
        yield (None, ys[iy])
        iy = 1 + iy
</code></pre>

<p>Yuck.  I&#8217;m going to go out on a limb and say that five yields is too many.  What&#8217;s the idiomatically correct way to do this?  Perhaps something to do with feeding values back in to generators?  Python language lawyers: please show me the error of my ways!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2008/09/help-me-write-idiomatically-correct-python/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>One-liner syndrom</title>
		<link>http://www.obfuscated.org/2007/12/one-liner-syndrom/</link>
		<comments>http://www.obfuscated.org/2007/12/one-liner-syndrom/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 00:20:00 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Noise]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/12/04/one-liner-syndrom/</guid>
		<description><![CDATA[Jeff Atwood talks about card shuffling algorithms in a recent blog post. As it turns out, the easiest way to implement a shuffle is by sorting. It&#8217;s not exactly faster, as the typical sort is O(n log n) compared to the O(n) of the Knuth Fisher-Yates shuffle algorithm. We&#8217;ll just sort by a random number&#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Jeff Atwood talks about <a href="http://www.codinghorror.com/blog/archives/001008.html">card shuffling algorithms</a> in a recent blog post.</p>

<blockquote>
  <p>As it turns out, the easiest way to implement a shuffle is by sorting. It&#8217;s not exactly faster, as the typical sort is O(n log n) compared to the O(n) of the Knuth Fisher-Yates shuffle algorithm. We&#8217;ll just sort by a random number&#8211; in this case, a GUID.</p>
  
  <p><code><pre>
   var cards = Enumerable.Range(0, 51);
   var shuffledcards = cards.OrderBy(a => Guid.NewGuid());</pre></code></p>
  
  <p>So we can ultimately implement a secure, unbiased shuffle as a one-liner in a modern programming language.</p>
</blockquote>

<p>The obligatory nerd response here is to bang out the one-liner in your language of choice.  Here&#8217;s one for Python:</p>

<pre><code>&gt;&gt;&gt; from random import random
&gt;&gt;&gt; shuffled = [ b for (a,b) in sorted((random(), x) for x in cards) ]
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/12/one-liner-syndrom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Synchronous HTTP GET in JavaScript</title>
		<link>http://www.obfuscated.org/2007/10/synchronous-http-get-in-javascript/</link>
		<comments>http://www.obfuscated.org/2007/10/synchronous-http-get-in-javascript/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 03:44:17 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/10/17/synchronous-http-get-in-javascript/</guid>
		<description><![CDATA[Taking the &#8220;A&#8221; out of &#8220;AJAX.&#8221; function get(url) { var ajax = new XMLHttpRequest(); ajax.open('GET', url, false); ajax.send(null); return ajax.responseText; } Of course this will be different for IE&#8230;.]]></description>
			<content:encoded><![CDATA[<p>Taking the &#8220;A&#8221; out of &#8220;AJAX.&#8221;</p>

<pre><code> function get(url) {
  var ajax = new XMLHttpRequest();
  ajax.open('GET', url, false);
  ajax.send(null);
  return ajax.responseText;
}
</code></pre>

<p>Of course this will be different for IE&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/10/synchronous-http-get-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roman Numeral Parser</title>
		<link>http://www.obfuscated.org/2007/09/roman-numeral-parser/</link>
		<comments>http://www.obfuscated.org/2007/09/roman-numeral-parser/#comments</comments>
		<pubDate>Thu, 20 Sep 2007 04:58:23 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/09/19/roman-numeral-parser/</guid>
		<description><![CDATA[I wondered the other night how straightforward a task parsing roman numerals (up to 4999) is. As revealed by about 30 seconds of Googling: pretty straightforward. Here it is in Python: import re ROMAN_RE = re.compile(""" ^ # beginning of string (M{0,4}) # thousands - 0 to 4 M's (CM&#124;CD&#124;D?C{0,3}) # hundreds - 900 (CM), [...]]]></description>
			<content:encoded><![CDATA[<p>I wondered the other night how straightforward a task parsing roman numerals (up to 4999) is.  As revealed by about <a href="http://www.diveintopython.org/regular_expressions/roman_numerals.html">30 seconds of Googling</a>: pretty straightforward.  Here it is in <a href="http://www.python.org/">Python</a>:</p>

<pre><code>import re

ROMAN_RE = re.compile("""
    ^                   # beginning of string
    (M{0,4})            # thousands - 0 to 4 M's
    (CM|CD|D?C{0,3})    # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),
                        #            or 500-800 (D, followed by 0 to 3 C's)
    (XC|XL|L?X{0,3})    # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's),
                        #        or 50-80 (L, followed by 0 to 3 X's)
    (IX|IV|V?I{0,3})    # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),
                        #        or 5-8 (V, followed by 0 to 3 I's)
    $                   # end of string
""", re.VERBOSE)

ROMAN_DIGITS  = {
    'M'    : 1000, 'MM'   : 2000, 'MMM'  : 3000, 'MMMM' : 4000,
    'CM'   : 900,  'CD'   : 400,  'D'    : 500,  'DC'   : 600,
    'DCC'  : 700,  'DCCC' : 800,  'C'    : 100,  'CC'   : 200,
    'CCC'  : 300,  'XC'   : 90,   'XL'   : 40,   'L'    : 50,
    'LX'   : 60,   'LXX'  : 70,   'LXXX' : 80,   'X'    : 10,
    'XX'   : 20,   'XXX'  : 30,   'IX'   : 9,    'IV'   : 4,
    'V'    : 5,    'VI'   : 6,    'VII'  : 7,    'VIII' : 8,
    'I'    : 1,    'II'   : 2,    'III'  : 3
}

def rtoi(roman):
    match = ROMAN_RE.match(roman.upper())
    if match and 0 &lt; sum(1 for x in match.groups() if 0 &lt; len(x)):
        return sum(ROMAN_DIGITS[x] for x in match.groups() if 0 &lt; len(x))
    return None
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/09/roman-numeral-parser/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pleasing small victories</title>
		<link>http://www.obfuscated.org/2007/09/pleasing-small-victories/</link>
		<comments>http://www.obfuscated.org/2007/09/pleasing-small-victories/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 05:59:29 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/09/10/pleasing-small-victories/</guid>
		<description><![CDATA[So a coworker got me hooked on Project Euler today, and I&#8217;ve been spending far too much of my free time on it. However, it did lead to a very pleasing moment. One of the problems deals with Collatz sequences: For any number, divide by two if the number is evenly divisible by two, multiply [...]]]></description>
			<content:encoded><![CDATA[<p>So a coworker got me hooked on <a href="http://projecteuler.net/">Project Euler</a> today,
and I&#8217;ve been spending far too much of my free time on it.  However, it did lead to a very pleasing moment.</p>

<p>One of the problems deals with <a href="http://en.wikipedia.org/wiki/Collatz_conjecture">Collatz
sequences</a>: For any
number, divide by two if the number is evenly divisible by two,
multiply by three and add one otherwise.  Stop when you reach the
number 1.  The task at hand was to find the number between 1 and
1,000,000 with the longest Collatz sequence.</p>

<p>My first attempt at counting this sequence, rather predictably, failed on
large input:</p>

<pre><code> collatzsz 1 = 1
 collatzsz n = 1 + collatzsz nxt where
     nxt = if 0 == mod n 2 then div n 2 else 3 * n + 1
</code></pre>

<p>Duh.  Stack overflows everywhere.  (Note: there&#8217;s probably a flag for GHC
that will make this Just Work.)  I figured that Haskell would probably go
ahead and optimize tail calls for me, so I gave it a go:</p>

<pre><code> collatzsz 1 accum = 1 + accum
 collatzsz n accum = collatzsz nxt (1+accum) where
     nxt = if 0 == mod n 2 then div n 2 else 3 * n + 1
</code></pre>

<p>Sure enough, it works for even the most obnoxiously large values of n.</p>

<p>Yes, I know that this is exactly what the language is supposed to do, but
sometimes it seems like a small victory when a piece of software does even
that.  So thanks to the good folks who make GHC.  You made me smile today.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/09/pleasing-small-victories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An ode to Python 3000</title>
		<link>http://www.obfuscated.org/2007/09/an-ode-to-python-3000/</link>
		<comments>http://www.obfuscated.org/2007/09/an-ode-to-python-3000/#comments</comments>
		<pubDate>Tue, 04 Sep 2007 18:19:54 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/09/04/an-ode-to-python-3000/</guid>
		<description><![CDATA[Inspired by the what&#8217;s new page: def reduce(f, seq, val = None): if val is None: val = next(seq) for x in seq: val = f(val, x) return val]]></description>
			<content:encoded><![CDATA[<p><em>Inspired by the <a href="http://docs.python.org/dev/3.0/whatsnew/3.0.html">what&#8217;s new</a> page:</em></p>

<pre><code> def reduce(f, seq, val = None):
     if val is None: val = next(seq)        
     for x in seq:
         val = f(val, x)
     return val
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/09/an-ode-to-python-3000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java programmers are funny</title>
		<link>http://www.obfuscated.org/2007/09/java-programmers-are-funny/</link>
		<comments>http://www.obfuscated.org/2007/09/java-programmers-are-funny/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 03:24:57 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/09/02/java-programmers-are-funny/</guid>
		<description><![CDATA[Having dealt with code of the ObjectModelAdapterFactoryBuilderInterfaceFacade variety before, I of course find Stevey&#8217;s comments about Java to be spot on. Sun Microsystems Demands University Study Retraction The University of Washington, apparently hoping to capitalize on the recent hype around their controversial study on Baby Einsteinâ„¢-style videos, followed up yesterday with another, similar study. In [...]]]></description>
			<content:encoded><![CDATA[<p>Having dealt with code of the ObjectModelAdapterFactoryBuilderInterfaceFacade variety before, I of course find <a href="http://steve-yegge.blogspot.com/2007/09/steveys-tech-news-issue-1.html">Stevey&#8217;s comments about Java</a> to be spot on. </p>

<blockquote>
  <p><strong>Sun Microsystems Demands University Study Retraction</strong></p>
  
  <p>The University of Washington, apparently hoping to capitalize on the recent hype around their controversial study on Baby Einsteinâ„¢-style videos, followed up yesterday with another, similar study. In the new study, researchers found that Java programmers understand an average of seven fewer Computer Science concepts per hour spent with Java each day compared to similar programmers using other languages. Sun calls the study &#8220;seriously flawed&#8221;, citing the fact that you can combine the names of Gang of Four Design Patterns to form new Computer Science concepts that all Java programmers understand, such as the ObserverFactoryBridge, the BridgeFactoryObserver, and the well-known FactoryObserverBridgeChainOfCommandSingletonProxy, beloved of Java programmers everywhere. Java experts at Sun say they&#8217;re not sure how many combinations there are of the twenty-three pattern names, but there are &#8220;definitely a lot of them.&#8221;</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/09/java-programmers-are-funny/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Haskell Unit Tests with HUnit</title>
		<link>http://www.obfuscated.org/2007/08/haskell-unit-tests-with-hunit/</link>
		<comments>http://www.obfuscated.org/2007/08/haskell-unit-tests-with-hunit/#comments</comments>
		<pubDate>Thu, 23 Aug 2007 20:02:45 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/08/23/haskell-unit-tests-with-hunit/</guid>
		<description><![CDATA[I read an OnLamp article today called A Beautiful Regex Matcher&#8230; In Haskell. Interesting little piece of code, but there was a (silly little) bug in it. This struck me as a fine opportunity to figure out how HUnit &#8212; one of Haskell&#8217;s unit testing frameworks &#8212; works. Here&#8217;s what I came up with: import [...]]]></description>
			<content:encoded><![CDATA[<p>I read an OnLamp article today called <a href="http://www.oreillynet.com/onlamp/blog/2007/08/a_beautiful_regex_matcher_in_h.html">A Beautiful Regex Matcher&#8230; In Haskell</a>.  Interesting little piece of code, but there was a (silly little) bug in it.  This struck me as a fine opportunity to figure out how HUnit &#8212; one of Haskell&#8217;s unit testing frameworks &#8212; works.  Here&#8217;s what I came up with:</p>

<pre><code>import Test.HUnit
import Regex

tests = TestList [ TestLabel (makeLabel x) (makeTest x) | x &lt;- test_data ]
    where makeTest  tup@(reg, str, bool) = 
              TestCase $ assertEqual (makeLabel tup) bool (match reg str)
          makeLabel (reg, str, bool) | True == bool  = reg ++ " =~ " ++ str
                                     | False == bool = reg ++ " !~ " ++ str
          test_data = [ ("foo",  "foo",     True),
                        ("foo",  "bar",     False),
                        ("",     "foo",     True),
                        (".",    "Foo",     True),
                        (".*",   "Foo",     True),
                        ("F.",   "Foo",     True),
                        ("F.*",  "Foo",     True),
                        ("Fo*",  "Foo",     True),
                        ("Fo*d", "foo",     False),
                        ("Fo*d", "Foooood", True) ]

main = runTestTT tests
</code></pre>

<p>As mentioned in the article&#8217;s comments, the case where &#8220;.*&#8221; (&#8220;match anything&#8221;) is supposed to match &#8220;Foo&#8221; fails.  Here&#8217;s the test output for the original code:</p>

<pre><code>% runhaskell TestRegex.hs
### Error in:   4:.* =~ Foo                
user error (HUnit:.* =~ Foo
expected: True
 but got: False)
### Error in:   6:F.* =~ Foo               
user error (HUnit:F.* =~ Foo
expected: True
 but got: False)
 Cases: 10  Tried: 10  Errors: 2  Failures: 0
Counts {cases = 10, tried = 10, errors = 2, failures = 0}
% 
</code></pre>

<p>Easy enough.  Finding out which cases fail makes tracking the problem down relatively straightforward.  Turns out that the &#8220;matchstar&#8221; method doesn&#8217;t deal properly with periods at the end of the match.  The original code:</p>

<pre><code>matchstar c [] (y:ys) = c == y
</code></pre>

<p>Replace it with the following:</p>

<pre><code>matchstar c [] (y:ys) = if c == '.' then True else c == y
</code></pre>

<p>And you get the following out of the unit tests:</p>

<pre><code>% runhaskell TestRegex.hs
Cases: 10  Tried: 10  Errors: 0  Failures: 0
Counts {cases = 10, tried = 10, errors = 0, failures = 0}
% 
</code></pre>

<p>Horray!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/08/haskell-unit-tests-with-hunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New in Python 2.6: ORM made easy</title>
		<link>http://www.obfuscated.org/2007/08/new-in-python-26-orm-made-easy/</link>
		<comments>http://www.obfuscated.org/2007/08/new-in-python-26-orm-made-easy/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 03:48:09 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/08/19/new-in-python-26-orm-made-easy/</guid>
		<description><![CDATA[From the What&#8217;s New in Python 2.6 page: A new data type in the collections module: NamedTuple(typename, fieldnames) is a factory function that creates subclasses of the standard tuple whose fields are accessible by name as well as index. For example: var_type = collections.NamedTuple(&#8216;variable&#8217;, &#8216;id name type size&#8217;) var = var_type(1, &#8216;frequency&#8217;, &#8216;int&#8217;, 4) print [...]]]></description>
			<content:encoded><![CDATA[<p>From the <a href="http://docs.python.org/dev/whatsnew/2.6.html">What&#8217;s New in Python 2.6</a> page:</p>

<blockquote>
  <p>A new data type in the collections module: NamedTuple(typename, fieldnames) is a factory function that creates subclasses of the standard tuple whose fields are accessible by name as well as index. For example:</p>
  
  <p>var_type = collections.NamedTuple(&#8216;variable&#8217;, &#8216;id name type size&#8217;)</p>
  
  <p>var = var_type(1, &#8216;frequency&#8217;, &#8216;int&#8217;, 4)</p>
  
  <p>print var[0], var.id               # Equivalent</p>
  
  <p>print var[2], var.type          # Equivalent</p>
</blockquote>

<p>Neat!  It all exists in libraryspace, so it&#8217;s not a groundbreaking change to the language.  Still, this has to save time.  Without this creating the same sort of class would have taken something like:</p>

<pre><code>class variable(object):
    def __init__(self, id, name, typ, size):
      self.id, self.name, self.type, self.size = id, name, typ, size
</code></pre>

<p>Not too much typing, but certainly more, and you can&#8217;t even access it as a tuple without additional work.  I wonder if the various Python ORM libraries use techniques like this?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/08/new-in-python-26-orm-made-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>White on black or black on white?</title>
		<link>http://www.obfuscated.org/2007/07/white-on-black-or-black-on-white/</link>
		<comments>http://www.obfuscated.org/2007/07/white-on-black-or-black-on-white/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 17:41:50 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Me!]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/07/18/white-on-black-or-black-on-white/</guid>
		<description><![CDATA[Whenever I use the web or write email, my working environment displays in black on white and I&#8217;m just fine with that. When I edit text, black on white just seems wrong and I always switch things around to be white on black. This never struck me as odd until today. Does anybody else think [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I use the web or write email, my working environment displays in black on white and I&#8217;m just fine with that.  When I edit text, black on white just seems wrong and I always switch things around to be white on black.  This never struck me as odd until today.  Does anybody else think it&#8217;s odd that one color scheme would make perfect sense in one context but come off as very wrong in another rather similar context?  Or is it just me?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/07/white-on-black-or-black-on-white/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fair Dice (for Settlers of Catan and other games using dice)</title>
		<link>http://www.obfuscated.org/2007/07/fair-dice-for-settlers-and-other-games-using-dice/</link>
		<comments>http://www.obfuscated.org/2007/07/fair-dice-for-settlers-and-other-games-using-dice/#comments</comments>
		<pubDate>Sun, 08 Jul 2007 23:30:19 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/07/08/fair-dice-for-settlers-and-other-games-using-dice/</guid>
		<description><![CDATA[I love games, but I hate dice. They vex me so. Especially while playing Settlers of Catan. If you&#8217;re twice as likely to roll a seven as you are a four, then why in the hell has four come up five turns out of the last six? Etc etc. You get the idea. Inspired by [...]]]></description>
			<content:encoded><![CDATA[<p>I love games, but I hate dice.  They vex me so.  Especially while playing <a href="http://en.wikipedia.org/wiki/Settlers_of_Catan">Settlers of Catan</a>.  If you&#8217;re twice as likely to roll a seven as you are a four, then why in the hell has four come up five turns out of the last six?  Etc etc.  You get the idea.</p>

<p>Inspired by <a href="http://erich-schneider.livejournal.com/">Erich&#8217;s</a> dice-by-cards Catan variant (and also by not having a spare deck of playing cards, and also by having recently taken <a href="http://flickr.com/photos/cap/sets/72157600502595033/">pictures of a six-sided die</a>) I put together <a href="http://games.obfuscated.org/dice/">Fair Dice</a>.  It&#8217;s a goofy little JavaScript application that will roll all thirty-six combinations of two dice once in random order.  When it&#8217;s done, it will do it again.</p>

<p>Now, is this sort of thing useful?  Who knows.  Probably half the fun of a game like Settlers is watching people fume when threes and elevens come up over and over and over again while those sixes and eights that they so wisely choose at the beginning of the game go fallow.  So you know me: I like to destroy fun.</p>

<p>A random non-gaming aside: How do people write web pages without <a href="http://www.getfirebug.com/">FireBug</a>?  I looked <em>briefly</em> at making sure that this works correctly on IE and Safari, and I couldn&#8217;t tell what in the <em>world</em> was going on.  For the longest time the page didn&#8217;t do <em>anything</em> because apparently Safari and IE (IE 6, at least) don&#8217;t understand the &#8220;const&#8221; keyword in JavaScript.  Infuriating!  Anyway, if you&#8217;re having to contend with JavaScript, I can&#8217;t recommend FireBug quite enough.</p>

<p>(<a href="http://games.obfuscated.org/dice/">Fair Dice</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/07/fair-dice-for-settlers-and-other-games-using-dice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Applying lessons from journalism to UI design</title>
		<link>http://www.obfuscated.org/2007/06/applying-lessons-from-journalism-to-ui-design/</link>
		<comments>http://www.obfuscated.org/2007/06/applying-lessons-from-journalism-to-ui-design/#comments</comments>
		<pubDate>Sat, 23 Jun 2007 19:19:40 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/06/23/applying-lessons-from-journalism-to-ui-design/</guid>
		<description><![CDATA[flow&#124;state has a very good UI design piece up currently. Its simple recommendation: make sure the important bits of the UI are front and center. Can you see the disaster in progress? Most users can&#8217;t either. This dialog has buried the lede. It focuses the user&#8217;s attention on the fact that there is another file [...]]]></description>
			<content:encoded><![CDATA[<p>flow|state has a <a href="http://miksovsky.blogs.com/flowstate/2007/06/dont-bury-the-l.html">very good UI design piece</a> up currently.  Its simple recommendation: make sure the important bits of the UI are front and center.</p>

<blockquote>
  <p>Can you see the disaster in progress? Most users can&#8217;t either.</p>
  
  <p>This dialog has buried the lede. It focuses the user&#8217;s attention on the fact that there is another file with the same name in the destination folder. It fails to point out a much, much more interesting condition: <strong>The user is about to overwrite a newer file with an older file.</strong></p>
  
  <p>[...]</p>
  
  <p>The above dialog&#8217;s text fails at this, as does its layout and typography. There are numerous pieces of text competing for attention, but among the most prominent are the bolded file names. That&#8217;s a bit odd, since the entire premise of the dialog is that these two file names will be the same. The dialog has carefully drawn the user&#8217;s attention to information which is guaranteed to be redundant. (If the user is moving multiple files, only some of which have conflicts, the file names are relevantâ€”but that case can and should be handled specially.)</p>
</blockquote>

<p>I&#8217;ve never thought consciously of following the <a href="http://en.wikipedia.org/wiki/Inverted_pyramid">inverted pyramid</a> while laying out a UI, but it makes a lot of sense.  I&#8217;m curious to look in on some of the screens I&#8217;m working on currently to see how well I stick to this principle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/06/applying-lessons-from-journalism-to-ui-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An open letter to JPL</title>
		<link>http://www.obfuscated.org/2007/06/an-open-letter-to-jpl/</link>
		<comments>http://www.obfuscated.org/2007/06/an-open-letter-to-jpl/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 06:10:09 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Letters to Nobody]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/06/20/an-open-letter-to-jpl/</guid>
		<description><![CDATA[Sirs and Madams, Thank you for releasing your CLARAty software to the public. That is a wonderful move that we can all appreciate. However, I have one comment regarding your installation procedures: Csh? Really? Good Day.]]></description>
			<content:encoded><![CDATA[<p>Sirs and Madams,</p>

<p>Thank you for <a href="http://www-robotics.jpl.nasa.gov/news/newsStory.cfm?NewsID=69">releasing</a> your <a href="http://claraty.jpl.nasa.gov/man/overview/index.php">CLARAty</a> software to the public.  That is a wonderful move that we can all appreciate.  However, I have one comment regarding your <a href="http://claraty.jpl.nasa.gov/man/software/download/index.php">installation procedures</a>:  <a href="http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/">Csh</a>?  Really?</p>

<p>Good Day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/06/an-open-letter-to-jpl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling Java applets from JavaScript</title>
		<link>http://www.obfuscated.org/2007/06/calling-java-applets-from-javascript/</link>
		<comments>http://www.obfuscated.org/2007/06/calling-java-applets-from-javascript/#comments</comments>
		<pubDate>Mon, 04 Jun 2007 21:08:17 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/06/04/calling-java-applets-from-javascript/</guid>
		<description><![CDATA[I ran in to a situation recently where I had a big mess of code written in Java that I really wanted to call from a client-side web application. I could wrap said code up in a servlet, but that would be a lot of work. As it turns out, you can call methods on [...]]]></description>
			<content:encoded><![CDATA[<p>I ran in to a situation recently where I had a big mess of code
written in Java that I really wanted to call from a client-side web
application.  I <em>could</em> wrap said code up in a servlet, but that would
be a lot of work.  As it turns out, you can call methods on Applets
directly from JavaScript, so all I have to do is wrap my code in one of those.  Bonus!</p>

<p>Here&#8217;s a brief example</p>

<p><b>DoublerApplet.java</b></p>

<pre><code>package org.obfuscated.example;

import java.applet.Applet;

public class DoublerApplet extends Applet {
    public double f(double x) {
        return x + x;
    }
}
</code></pre>

<p>Nothing special there.  Note that I&#8217;ve not yet tried passing classes
or the like to an applet.  I imagine that they might be trouble.</p>

<p><b>index.html</b></p>

<pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Applet Test&lt;/title&gt;
    &lt;script src="prototype.js"&gt;&lt;/script&gt;
    &lt;script src="doubleit.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;object id="doubler"
       classid="java:org.obfuscated.example.DoublerApplet.class" 
       type="application/x-java-applet"
       archive="DoublerApplet.jar" 
       height="1" width="1" &gt;
      &lt;param name="scriptable" value="true"/&gt;
    &lt;/object&gt;

    &lt;b&gt;Double me!&lt;/b&gt;
    &lt;br/&gt;
    2 * &lt;input size="5" type="text" id="x"/&gt; = &lt;span id="answer"&gt;???&lt;/span&gt;
    &lt;br/&gt;
    &lt;input type="submit" id="go"/&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>The important part is the <em>&#8220;scriptable&#8221;</em> parameter.  It tells the
applet to listen to the JavaScript.</p>

<p><b>doubleit.js</b></p>

<pre><code>var init = function() {
    Event.observe('go', 'click', function() {
        var x = Number($('x').value);
        var applet = $('doubler');
        $('answer').innerHTML = applet.f(x);
        return false;
    });
};

Event.observe(window, 'load', init);
</code></pre>

<p>The &#8220;$&#8221; magic that makes the JavaScript code quite so terse is <a href="http://www.prototypejs.org/">Prototype</a>, which I can&#8217;t quite recommend enough.  </p>

<p>Anyway, I&#8217;m quite pleased that I&#8217;m able to use this technique, as dragging out Tomcat, keeping it running, etc., would be a whole lot of work just to be able to call one function.  (Which is all I need to do in this particular case.)  I&#8217;m sure the server-based solution would be more correct if I needed to do more in Java-land, but for quick and dirty things or one-off&#8217;s, JavaScript to Applet communication is nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/06/calling-java-applets-from-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Parsec in simple Haskell programs</title>
		<link>http://www.obfuscated.org/2007/05/using-parsec-in-simple-haskell-programs/</link>
		<comments>http://www.obfuscated.org/2007/05/using-parsec-in-simple-haskell-programs/#comments</comments>
		<pubDate>Sun, 27 May 2007 05:30:16 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/05/26/using-parsec-in-simple-haskell-programs/</guid>
		<description><![CDATA[I read two very useful articles about Haskell recently. First is Haskell IO for Imperative Programmers which explains how to do simple IO. (It&#8217;s less obvious than you&#8217;d think, especially if you&#8217;re coming from one of the more popular languages like Java or Ruby.) The second is called JSON Parser in Haskell. It covers in [...]]]></description>
			<content:encoded><![CDATA[<p>I read two very useful articles about Haskell recently.  First is
<a href="http://blogs.nubgames.com/code/?p=22">Haskell IO for Imperative
Programmers</a> which explains how
to do simple IO.  (It&#8217;s less obvious than you&#8217;d think, especially if
you&#8217;re coming from one of the more popular languages like Java or
Ruby.)  The second is called <a href="http://snippets.dzone.com/posts/show/3660">JSON Parser in
Haskell</a>.  It covers in a
brief yet very informative way the exceptionally useful
<a href="http://www.cs.uu.nl/~daan/parsec.html">Parsec</a> library that ships
with many Haskell implementations.</p>

<p>Each of these articles are incredibly useful.  You have to know how to
get data in and out of your program, and there aren&#8217;t a lot of tasks
that don&#8217;t require parsing data.  The two techniques together, as you
might expect, are crazy useful.</p>

<p>To summarize perhaps too quickly, you can do simple stdin/stdout IO using the &#8220;interact&#8221; function.  Here&#8217;s the Haskell implementation of the popular &#8220;tac&#8221; utility:</p>

<pre><code>main = interact $ unlines . (map reverse) . lines
</code></pre>

<p>The &#8220;lines&#8221; method turns a large string (stdin) in to a list of
strings, &#8220;unlines&#8221; turns a list of strings in to one large string
(stdout), &#8220;interact&#8221; ties the whole process together, and &#8220;(map
reverse)&#8221; is where you would put your code.</p>

<p>In place of &#8220;lines&#8221; you can usefully drop Parsec in such that you can
work directly on data structures instead of fussing with lines of
text.  (Haskell isn&#8217;t Perl, after all.)  Here&#8217;s a quick example that 
reads pairs of integers:</p>

<pre><code>module Main where
import Text.Printf
import Text.ParserCombinators.Parsec

atoi :: String -&gt; Int
atoi = read

intsList :: Parser [(Int,Int)]
intsList = do
  intsList' &lt;|&gt; (eof &gt;&gt; return [])
      where intsList' = do
              a &lt;- many1 digit
              many1 space
              b &lt;- many1 digit
              newline
              r &lt;- ( many space &gt;&gt; (intsList' &lt;|&gt; return []))
              return ((atoi a, atoi b) : r)

parseInput :: String -&gt; [(Int,Int)]
parseInput s = case parse intsList "stdin" s of
                 Left err -&gt; []
                 Right cs -&gt; cs

rpt :: (Int,Int) -&gt; String
rpt (a,b) = let c = maximum $ map ( length . cyc ) [a..b]
            in printf "%d %d %d" a b c
    where cyc n | 1 == n       = [1]
                | 1 == mod n 2 = n : cyc (1 + 3 * n)
                | otherwise    = n : cyc  (div n 2)

main = interact $ unlines . (map rpt) . parseInput
</code></pre>

<p>And just like that you can move input parsing in to a parser where it
belongs and not worry about it in the rest of your system.  Certainly
a lot more work than the same thing in, for instance, Ruby:</p>

<pre><code>STDIN.each { |l| a,b = l.split.map {|x| x.to_i} ; puts whatever(a, b) }
</code></pre>

<p>However, dropping Parsec works the same way for arbitrarily complex data structures.  This same code structure workspairs of integers, HTTP, JSON, whatever.  Needless to say, I find this very pleasing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/05/using-parsec-in-simple-haskell-programs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dave Thomas on Paying Back</title>
		<link>http://www.obfuscated.org/2007/05/dave-thomas-on-paying-back/</link>
		<comments>http://www.obfuscated.org/2007/05/dave-thomas-on-paying-back/#comments</comments>
		<pubDate>Tue, 22 May 2007 17:21:18 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/05/22/dave-thomas-on-paying-back/</guid>
		<description><![CDATA[Dave Thomas has a fine idea for improving conferences by adding a focus on charitable giving: Just imagine the difference we could make if, as an industry, we turned each of these conferences into a chance to raise much needed money for worthy charities. Imagine if, rather than getting yet one more burlap bag with [...]]]></description>
			<content:encoded><![CDATA[<p>Dave Thomas has a fine idea for <a href="http://pragdave.pragprog.com/pragdave/2007/05/paying_back.html">improving conferences  by adding a focus on charitable giving</a>:</p>

<blockquote>Just imagine the difference we could make if, as an industry, we turned each of these conferences into a chance to raise much needed money for worthy charities. Imagine if, rather than getting yet one more burlap bag with a sponsor&#8217;s name on it, you instead got a slip of paper saying that the price of that bag was being used to buy vaccine for 5 kids, or a book for a literacy project. Imagine what could happen if a conference with 5,000 attendees raised just $20 per attendee. Then imagine $50, or $100. It starts to get serious.</blockquote>

<p>As somebody who falls squarely in to the &#8220;I&#8217;m not going to use your Complete Enterprise Solution even if you give me a tote bag and a glow-in-the-dark yo-yo&#8221; camp, I think this is a great idea.  Nobody needs another Sun-branded pen or Google Frisbee; there are lots of people out there who could make good use of a nerd&#8217;s pocket change.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/05/dave-thomas-on-paying-back/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Things to do when you&#8217;re a nerd and you can&#8217;t type</title>
		<link>http://www.obfuscated.org/2007/05/things-to-do-when-youre-a-nerd-and-you-cant-type/</link>
		<comments>http://www.obfuscated.org/2007/05/things-to-do-when-youre-a-nerd-and-you-cant-type/#comments</comments>
		<pubDate>Mon, 21 May 2007 00:25:36 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[The 'Hoo]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/05/20/things-to-do-when-youre-a-nerd-and-you-cant-type/</guid>
		<description><![CDATA[I spent Thursday and Friday at work essentially without fingers. Well, I had fingers, but only one useful hand of them. Interestingly enough, I learned that I&#8217;m at least in the short term incapable of hunt-and-peck typing. Finger muscle memory takes over when I try and everything goes all crazy-go-nuts. Not a good time. My [...]]]></description>
			<content:encoded><![CDATA[<p>I spent Thursday and Friday at work essentially without fingers.  Well, I had fingers, but only one useful hand of them.  Interestingly enough, I learned that I&#8217;m at least in the short term incapable of hunt-and-peck typing.  Finger muscle memory takes over when I try and everything goes all crazy-go-nuts.  Not a good time.</p>

<p>My original plan for my convalescence was to go charge a book on JavaScript to the company account and see if I couldn&#8217;t learn a bit about a language that I&#8217;m likely going to use for an upcoming project.  However I don&#8217;t know what the good JavaScript books are, and walking to the book store is a lot more work than surfing the internet, so I checked for good online resources.</p>

<p>It turns out that there are many.  In particular, Yahoo!&#8217;s <a href="http://developer.yahoo.com/yui/" title="YUI">YUI</a> team has put together  large collection of <a href="http://developer.yahoo.com/yui/theater/" title="YUI Theater">videos about JavaScript</a>. I watched videos of three of Douglas Crockford&#8217;s lectures:  &#8220;<a href="http://video.yahoo.com/video/play?vid=cccd4aa02a3993ab06e56af731346f78.1710507" title="The JavaScript Programming Language">The JavaScript Programming Language</a>,&#8221; &#8220;<a href="http://video.yahoo.com/video/play?vid=cccd4aa02a3993ab06e56af731346f78.992708" title="The Theory of the DOM">An Inconvenient API: The Theory of the DOM</a>&#8221; and  &#8220;<a href="http://video.yahoo.com/video/play?vid=cccd4aa02a3993ab06e56af731346f78.1027823" title="Advanced JavaScript">Advanced JavaScript</a>.&#8221;  All three were good lectures.  They were, for shots of a lecture about a programming language, well produced, and Crockford&#8217;s talks were well structured.  I got a lot more out of the first talk than the other two, but that could arguably be couched more as a compliment for the introduction video than a knock on the other two, as I felt like I knew the language pretty well after it.   (I&#8217;d never used the language seriously before.)</p>

<p>I didn&#8217;t get too far in to any of the other videos, but there are a ton of them there, so there&#8217;s got to be at least a few more good ones.  If you&#8217;re looking to pick up JavaScript, I can recommend the YUI Theater as a good place to start.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/05/things-to-do-when-youre-a-nerd-and-you-cant-type/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Disturbingly Concise</title>
		<link>http://www.obfuscated.org/2007/05/disturbingly-concise/</link>
		<comments>http://www.obfuscated.org/2007/05/disturbingly-concise/#comments</comments>
		<pubDate>Sun, 06 May 2007 07:25:23 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/05/06/disturbingly-concise/</guid>
		<description><![CDATA[import Control.Monad powerset :: [a] -&#62; [[a]] powerset = filterM (const [True, False]) I saw this over on a rather good introduction to dynamic programming. It does exactly what you&#8217;d expect it to do. (i.e., powerset [1,2] = [[1,2],[1],[2],[]].) Outstanding.]]></description>
			<content:encoded><![CDATA[<blockquote><code> </code>


<pre>
import Control.Monad

powerset :: [a] -&gt; [[a]]
powerset = filterM (const [True, False])</pre>


</blockquote>

<p>I saw this over on a <a href="http://sequence.complete.org/node/263">rather good introduction to dynamic programming</a>.  It does exactly what you&#8217;d expect it to do.  (i.e., <code>powerset [1,2] = [[1,2],[1],[2],[]]</code>.)</p>

<p>Outstanding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/05/disturbingly-concise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thought for the day (nerd edition)</title>
		<link>http://www.obfuscated.org/2007/03/thought-for-the-day-nerd-edition/</link>
		<comments>http://www.obfuscated.org/2007/03/thought-for-the-day-nerd-edition/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 17:07:45 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.obfuscated.org/2007/03/30/thought-for-the-day-nerd-edition/</guid>
		<description><![CDATA[Though the debates will forever rage about which JVM dynlang should carry us into the future, the same facts that have guided programming for half a century still apply today: No one language will be enough to carry us forward; no languages will survive indefinitely; and the language you&#8217;ll use in ten years you&#8217;ve probably [...]]]></description>
			<content:encoded><![CDATA[<blockquote>Though the debates will forever rage about which JVM dynlang should carry us into the future, the same facts that have guided programming for half a century still apply today: No one language will be enough to carry us forward; no languages will survive indefinitely; and the language you&#8217;ll use in ten years you&#8217;ve probably not even heard of yet</blockquote>

<p>From <a href="http://headius.blogspot.com/2007/03/ruby-on-grails-why-hell-not.html">Ruby on Grails? Why the hell not?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.obfuscated.org/2007/03/thought-for-the-day-nerd-edition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
