<?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/"
	>

<channel>
	<title>parsed&#124;out.com</title>
	<atom:link href="http://parsedout.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://parsedout.com</link>
	<description>comments on software, the internet, and all apsects of their development</description>
	<pubDate>Fri, 22 Aug 2008 22:13:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Lambda</title>
		<link>http://parsedout.com/2008/08/22/lambda/</link>
		<comments>http://parsedout.com/2008/08/22/lambda/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 22:09:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[coding]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://parsedout.com/?p=8</guid>
		<description><![CDATA[PHP has been in dire need of some new features for some
time. PHP 5.3 plans to add a slew of new features, finally
adding lambdas a/k/a anonymous functions to the language.

That is&#8230; &#8230;once it gets out of alpha. Then out of beta. Then onto
production systems.

(PHP haters can now stop sipping quite so much hater-ade in that [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://php.net">PHP</a> has been in dire need of some new features for some
time. PHP 5.3 plans to add a <a href="http://www.php.net/archive/2008.php#id2008-08-01-1">slew of new features</a>, <em>finally</em>
adding lambdas a/k/a <em>anonymous functions</em> to the language.</p>

<p>That is&#8230; &#8230;once it gets out of alpha. Then out of beta. Then onto
production systems.</p>

<p>(PHP haters can now stop sipping quite so much hater-ade in that PHP now also
supports namespaces, but I don&#8217;t find that new feature particularly
interesting.)</p>

<p>What makes lambdas so interesting is how much simpler and cleaner they can
make your code.</p>

<p>Consider the problem of wanting to sort a list where some of the items have
the words &#8216;The&#8217; or &#8216;A&#8217; as a prefix. We want to sort the list</p>

<ul>
<li>Beck</li>
<li>The Starting Line</li>
<li>Blue October</li>
<li>The All American Rejects</li>
</ul>

<p>to be</p>

<ul>
<li>The All American Rejects</li>
<li>Beck</li>
<li>Blue October</li>
<li>The Starting Line</li>
</ul>

<p>and <strong>not</strong></p>

<ul>
<li>Beck</li>
<li>Blue October</li>
<li>The All American Rejects</li>
<li>The Starting Line</li>
</ul>

<p>Without the use of lambdas, we have to do something like this in <em>old</em> PHP:</p>

<pre><code>    function stem_the($a)
    {
        return preg_replace( 
            '/^(a|the) *(.*)$/i, '$2', $a 
        );
    }

    function cmp_the($a,$b)
    {
        $a = stem_the($a);
        $b = stem_the($b);
        return strcmp($a,$b);
    }

    $bands = array( 'The All American Rejects',
                    'Beck', 'Blue October',
                    'The Starting Line' );

    usort( $bands, 'cmp_the' );
</code></pre>

<p><code>usort</code>&#8217;s second argument is a <strong>string</strong>. This is really ugly. <em>Old</em> PHP
didn&#8217;t have functions as first-class citizens, so that <em>was</em> the only way we
could do something like this. It&#8217;s <em>ugly</em> and <em>slow</em>.</p>

<p>Moreover, we&#8217;re forced to create two functions <code>stem_the()</code> and <code>cmp_the()</code>
(my names are always this creative). We&#8217;ve cluttered the global function
namespace for our very trivial task.</p>

<p>Enter stage left, Dr. Martin Luther Lambda. His dream is promoting functions
to first-class citizens&#8230;</p>

<p>With lambdas, we can rewrite that entire mess to be the clean, simple,
<em>elegant</em> mess that follows:</p>

<pre><code>    $bands = array( 'The All American Rejects',
                    'Beck', 'Blue October',
                    'The Starting Line' );

    usort( $bands, function($a,$b)
    {
        list($a,$b) = array_map(function($s) {
            return preg_replace('/^(a|the) *(.*)$/i','$2', $s);
        }, array($a,$b));
        return strcmp($a,$b);
    });
</code></pre>

<p>Notice that this code doesn&#8217;t create any new functions in the global
namespace. It&#8217;s slightly harder to read initially (mostly because of the
gratuitous use of the <code>list()</code> language construct), but it is vastly cleaner
and, in a word <em>elegant</em>.</p>

<p>(Aside: calling super geeky things elegant is not even close to pass&eacute;
yet.)</p>

<p>We can also now perform the operation of <strong><a href="http://en.wikipedia.org/wiki/Currying">currying</a></strong>&#8212;partially
instantiating a function with multiple parameters. Let&#8217;s say we want to apply
a function to each item in a list that adds 7 to that item. PHP has a built-in
<code>array_map()</code> function, used above, that allows us to apply a function to
every item in an array, but its argument is again a string, and we still have
to create a global-namespace function to accomplish this.</p>

<p>Let&#8217;s just say we have a function <code>add()</code> such as</p>

<pre><code>    function add($x,$y) { return $x + $y; }
</code></pre>

<p>and we want to create a function <code>add7($x)</code> that returns <code>$x + 7</code>. We could
simply create it:</p>

<pre><code>    function add7($x){ return $x + 7; }
</code></pre>

<p>Now what we want to do is <em>partially instantiate</em> our <code>add()</code> function to have
a sort of &#8216;hard-coded&#8217; first argument 7. In this way, we would define <code>add7()</code>
to be</p>

<pre><code>    function add7($x){ return add(7,$x); }
</code></pre>

<p>We just had to create another function in the global namespace: bloating our
memory footprint and creating an obtrusive disaster of our codebase to
accomplish a trivial task.</p>

<p>With currying, we could simply do this:</p>

<pre><code>    $add  = function()( $x, $y ) { return $x + $y; };
    $add7 = curry($add,7);
</code></pre>

<p>The punchline is that <code>curry()</code> <em>returns a function</em>. It&#8217;s a robot that gives
birth to new robots. Elegant?</p>

<p>So we can increment every item in an array by 7 very simply:</p>

<pre><code>    $nums = array( 1, 2, 3, 4 );
    $add  = function()( $x, $y ) { return $x + $y; };
    $nums = array_map( curry($add,7), $num );
</code></pre>

<p>(This example is very contrived, of course, since there was no reason to use
currying here&#8212;we could have simply had</p>

<pre><code>    $nums = array( 1, 2, 3, 4 );
    $nums = array_map( function($x){ return $x + 7; }, $num );
</code></pre>

<p>but cut me some slack.)</p>

<p><strong>Unfortunately</strong> <code>curry()</code> is not yet part of the PHP standard library. It&#8217;s
also not inherently obvious how to implement it&#8212;the necessary language
constructs were only introduced a mere three weeks ago today.</p>

<p><strong>Fortunately</strong>, I have implemented <code>curry()</code> for you. It&#8217;s a bit ugly, but it
works. It&#8217;s actually fairly fast as well (although my initial tests of it were
not exhaustive).</p>

<pre><code>    function curry($fn, $arg)
    {
        return function() use ($fn, $arg)
        {
            $args = func_get_args();
            array_unshift( $args, $arg );
            return call_user_func_array( $fn, $args );
        };
    }
</code></pre>

<p>It&#8217;s cool because you can chain it to itself. So if you wanted a function that
always returned 7, you could simply say:</p>

<pre><code>     $return7 = curry(curry($add,3),4);
</code></pre>

<p>or if you had a function that took three arguments and you wanted a new
function with the first two &#8216;hard-coded&#8217; (imagine <code>g(x) = f(1,3,x)</code> from
math), you could simply &#8220;curry <code>f()</code>&#8221; twice:</p>

<pre><code>    $g = curry(curry($f,3),1);
</code></pre>

<p>A better implementation would be for <code>curry()</code> to take a variable number of
arguments and to curry all of them in:</p>

<pre><code>    $g = curry($f,3,1); // or `curry($f,1,3)` maybe?
</code></pre>

<p>I&#8217;ll leave this as &#8216;an exercise for the reader&#8217;, but it&#8217;s not too difficult to
implement.</p>

<p>Awesome, <em>n&#8217;est-ce pas</em>?</p>

<p>You, too, can have some PHP 5.3 alpha goodness by running the following
nonsense on your command line:</p>

<pre><code>    mkdir -p "$HOME/src/php53alpha/build"
    cd "$HOME/src/php53alpha"
    wget http://downloads.php.net/johannes/php-5.3.0alpha1.tar.gz
    tar zxf php-5.3.0alpha1.tar.gz
    cd php-5.3.0alpha1
    ./configure --prefix="$PWD/../build"
    make
    make install
</code></pre>

<p>This installs the <code>php</code> binary in <em>~/src/php53alpha/build/bin</em>, so you can run
your <em>.php</em> scripts by simply calling, e.g.,</p>

<pre><code>    ~/src/php53alpha/build/bin/php my_script_file.php
</code></pre>

<p>Also read:</p>

<ul>
<li><a href="http://wiki.php.net/rfc/closures">PHP.net&#8217;s explanation of lambdas and closures</a></li>
<li><a href="http://www.php.net/archive/2008.php#id2008-08-01-1">PHP.net&#8217;s release notes for PHP 5.3 alpha1</a></li>
</ul>

<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://parsedout.com/2008/08/22/lambda/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installing Pubcookie 3.3 on Ubuntu 7.10 with Apache 2</title>
		<link>http://parsedout.com/2007/12/19/installing-pubcookie-33-on-ubuntu-710-with-apache-2/</link>
		<comments>http://parsedout.com/2007/12/19/installing-pubcookie-33-on-ubuntu-710-with-apache-2/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 20:28:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[configuration]]></category>

		<category><![CDATA[guide]]></category>

		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://parsedout.com/2007/12/19/installing-pubcookie-33-on-ubuntu-710-with-apache-2/</guid>
		<description><![CDATA[I recently had the wonderful experience of configuring UW&#8217;s Pubcookie for use on
Ubuntu&#8217;s package-manager version of Apache2. I took modest notes while doing this, and
it was spread out over several weeks whenever I could find the time, so maybe don&#8217;t
take this as a guide so much as a few installation notes, but these are the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the wonderful experience of configuring UW&#8217;s Pubcookie for use on
Ubuntu&#8217;s package-manager version of Apache2. I took modest notes while doing this, and
it was spread out over several weeks whenever I could find the time, so maybe don&#8217;t
take this as a guide so much as a few installation notes, but these are the spots that
gave me the most trouble.</p>

<p>This accompanies the Pubcookie Apache Module installation guide at
<a href="http://pubcookie.org/docs/install-mod_pubcookie-3.3.html">http://pubcookie.org/docs/install-mod_pubcookie-3.3.html</a> and the UW-specific
guide notes at <a href="http://www.washington.edu/computing/pubcookie/uwash-install.html">http://www.washington.edu/computing/pubcookie/uwash-install.html</a>.</p>

<p>(Of course following the convention that <code>$</code> are commands run as a limited user
while <code>#</code> commands are run as root.)</p>

<ol>
<li><p>Ensure Apache2 is installed and configured with OpenSSL:</p>

<pre><code># apt-get install apache2-threaded-dev apache2 openssl 
# mkdir -p /etc/apache2/ssl
</code></pre></li>
<li><p>Obtain Weblogin Server Registration for your hostname at
<a href="https://server-reg.cac.washington.edu/pubcookie/">https://server-reg.cac.washington.edu/pubcookie/</a></p></li>
<li><p>Get the UW Root Cert from 
<a href="http://certs.cac.washington.edu/?req=svpem">http://certs.cac.washington.edu/?req=svpem</a></p>

<p>I put this file at <strong>/etc/apache2/ssl/server.pem</strong>.  This is the
server&#8217;s public key.</p></li>
<li><p>Get the CA Bundle from 
<a href="http://www.washington.edu/computing/pubcookie/ca-bundle.crt">http://www.washington.edu/computing/pubcookie/ca-bundle.crt</a></p>

<p>I put this file at <strong>/etc/apache2/ssl/ca-bundle.crt</strong></p>

<p>This file allows the server to verify peers&#8217; certificates and is used
by keyclient.</p></li>
<li><p>Generate your cert&#8217;s private key and have it signed by your CA.</p>

<p>Information on how to generate a private key and a signature signing
request are probably documented on whatever site is signing your certificate.
The UW CA&#8217;s Technical Information can be found at
<a href="https://www.washington.edu/computing/ca/infra/">https://www.washington.edu/computing/ca/infra/</a>.</p>

<p>Generating a request for the UW CA (and probably all other CAs as well)
is simply a matter of:</p>

<pre><code># cd /etc/apache2/ssl
# openssl req -nodes -newkey 1024 \
    -keyout key.pem -out req.pem
</code></pre>

<p>When I went through the request process, the CA gave me the following 
values to fill in to the request UI:</p>

<pre><code>Country (C)         US
State (ST)          WA or Washington
Organization (O)    Optional
Organizational Unit (OU)    Optional
Common Name (CN)    Your host's fully qualified domain name
</code></pre></li>
<li><p>Put your private key at <strong>/etc/apache2/ssl/key.pem</strong> and your
CA-signed certificate at <strong>/etc/apache2/ssl/cert.pem</strong>.</p>

<p>(Note that the above step should generate the key and the request
at these locations already.)</p></li>
<li><p>Working in $HOME, get the Pubcookie tarball and unzip:</p>

<pre><code>$ mkdir -p $HOME/pubcookie
$ wget http://www.pubcookie.org/downloads/pubcookie-3.3.3.tar.gz
$ tar xzf pubcookie-3.3.3.tar.gz
</code></pre></li>
<li><p>Modify the configure script to know where apache&#8217;s PREFIX is.  This problem
seems to come from the fact that Apache isn&#8217;t built from source locally
when using aptitude.</p>

<p>The diff for this modification is</p>

<pre><code>3783c3783
 &lt;   APACHE_PREFIX=`$APXS -q PREFIX`
 ---
 &gt;   APACHE_PREFIX="/usr/share/apache2" #`$APXS -q PREFIX`
</code></pre>

<p>This via a message from the Pubcookie mailing list.</p></li>
<li><p>Configure, compile install:</p>

<pre><code>$ cd $HOME/pubcookie/pubcookie-3.3.3/
$ ./configure   \
    --enable-apache  \
    --prefix=/usr/local/pubcookie  \
    --with-apxs=/usr/bin/apxs2
$ make
$ sudo make install
</code></pre></li>
<li><p>Based on information from the installation guide, the following serves
as a good checkpoint:</p>

<pre><code>$ ls -F /usr/local/pubcookie
keyclient*      keys/
</code></pre></li>
<li><p>Here is my keyclient configuration file, <strong>/usr/local/pubcookie/config</strong></p>

<pre><code># ssl config
ssl_key_file: /etc/apache2/ssl/key.pem
ssl_cert_file: /etc/apache2/ssl/cert.pem


# keyclient-specific config


keymgt_uri: https://weblogin.washington.edu:2222
ssl_ca_file: /etc/apache2/ssl/ca-bundle.crt
</code></pre></li>
<li><p>Run keyclient to request a new key and to download the &#8220;granting&#8221; certificate:</p>

<pre><code># cd /user/local/pubcookie
# ./keyclient
# ./keyclient -G keys/pubcookie_granting.cert
</code></pre></li>
<li><p>Create a pubcookie load file so we can continue to use Ubuntu&#8217;s methodology
for managing Apache extensions (e.g. using <code>a2enmod</code> and <code>a2dismod</code>, which
really only create/modify symlinks in <strong>/etc/apache2/mods-enabled</strong> but
are sometimes reportedly used by other installation scripts):</p>

<pre><code># echo 'LoadModule pubcookie_module /usr/lib/apache2/modules/mod_pubcookie.so' \
&gt; /etc/apache2/mods-available/pubcookie.load
</code></pre></li>
<li><p>Stop Apache and load the pubcookie module:</p>

<pre><code># apache2ctl stop
# a2enmod pubcookie
</code></pre></li>
<li><p>Set Pubcookie directives in <strong>/etc/apache2/httpd.conf</strong>:</p>

<pre><code>PubcookieGrantingCertFile /usr/local/pubcookie/keys/pubcookie_granting.cert
PubcookieSessionKeyFile /etc/apache2/ssl/key.pem
PubcookieSessionCertFile /etc/apache2/ssl/cert.pem
PubcookieLogin https://weblogin.washington.edu/
PubcookieLoginMethod POST
PubcookieDomain .washington.edu
PubcookieKeyDir /usr/local/pubcookie/keys/
PubCookieAuthTypeNames UWNetID null SecurID
</code></pre>

<p>Note that Ubuntu&#8217;s Apache likes to have lots of configuration files.  The main
configuration happens in <strong>/etc/apache2/apache2.conf</strong> while &#8220;user&#8221; modifications
appen in the httpd.conf file as per above.  You will also need to have Apache
listen for SSL requests on port 443 by modifying <strong>/etc/apache2/ports.conf</strong>
to include</p>

<pre><code>Listen *:443
</code></pre></li>
<li><p>Enable SSL on your default site.  This can usually be done by modifying
<strong>/etc/apache2/sites-available/default</strong> to include</p>

<pre><code>SSLEngine on
SSLCertificateFile /etc/apache2/ssl/cert.pem
SSLCertificateKeyFile /etc/apache2/ssl/key.pem
</code></pre>

<p>You might be able to get away with only enabling SSL on select virtual
hosts if your environment is such that you have multiple host names pointing
to the same Apache instance.  I was able to accomplish this to some degree
but am still working out a few ambiguities that Apache isn&#8217;t telling me about.</p></li>
<li><p>Restart Apache and you&#8217;re good to go:</p>

<pre><code># apache2ctl -k start
</code></pre></li>
</ol>

<p>You now have the usual <strong>.htaccess</strong> directives at your disposal.  E.g.:</p>

<pre><code>AuthType UWNetID
Require valid-user
</code></pre>

<p>Have some sorbet?</p>
]]></content:encoded>
			<wfw:commentRss>http://parsedout.com/2007/12/19/installing-pubcookie-33-on-ubuntu-710-with-apache-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An end to WWW</title>
		<link>http://parsedout.com/2007/09/09/an-end-to-www/</link>
		<comments>http://parsedout.com/2007/09/09/an-end-to-www/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 18:43:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://parsedout.com/2007/09/09/an-end-to-www/</guid>
		<description><![CDATA[One of the problems I&#8217;ve always had with URLs is, well, they&#8217;re hard to say or hard to remember.  Every domain name I&#8217;ve registered has had as its basic premise either ease of typing or memorability.  I hate that my school (and work) TLD (top-level domain) is something as horridly long as &#8220;washington.edu&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the problems I&#8217;ve always had with URLs is, well, they&#8217;re hard to say or hard to remember.  Every domain name I&#8217;ve registered has had as its basic premise either ease of typing or memorability.  I hate that my school (and work) TLD (top-level domain) is something as horridly long as &#8220;washington.edu&#8221;, and I&#8217;m driven to tears every time I have to type in a subdomain of that TLD.  I have even purchased domain names for some of the pages on that domain because I hate typing them out so much.</p>

<p>Anything that contributes to this madness drives me to insanity.</p>

<p>This is 2007.  We have CNAMES and mod-rewrite and all sorts of fun things that help users with URLs.  You do <em>not</em> need the &#8220;www&#8221; in front of a URL.  It&#8217;s almost as absurd as the &#8220;http://&#8221;.  There are occasional exceptions, but 99% of the time, the sites are set up to automatically redirect to the proper page, and the user never even sees it.</p>

<p>So please, do your users (and me) a favor, and stop advertising your site with the darn w-w-w&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://parsedout.com/2007/09/09/an-end-to-www/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Finally! Post NumÃ©ro Uno</title>
		<link>http://parsedout.com/2007/09/08/finally-post-numero-uno/</link>
		<comments>http://parsedout.com/2007/09/08/finally-post-numero-uno/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 00:30:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[meta-post]]></category>

		<guid isPermaLink="false">http://parsedout.com/2007/09/08/finally-post-numero-uno/</guid>
		<description><![CDATA[Welcome to my new blog.  The name, &#8220;$ parsed &#124; out.com&#8220;, is supposed to be a bit of a pun and a bit of a (BaSH) code joke, Ã  la:


1
2
$  parsed &#124; out
.com


(Okay, so that was just an excuse for me to try out my syntax highlighter plugin. :)  I decided that [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to my new blog.  The name, &#8220;<code>$ parsed | out</code><sub><code>.com</code></sub>&#8220;, is supposed to be a bit of a pun and a bit of a (BaSH) code joke, Ã  la:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash">$  parsed <span style="color: #000000; font-weight: bold;">|</span> out
.com</pre></td></tr></table></div>


<p>(Okay, so that was just an excuse for me to try out my syntax highlighter plugin. :)  I decided that it was better than &#8220;allparsedout.com&#8221; and &#8220;implicitlydiffed.com&#8221;, which I also registered.  I&#8217;ve had this domain for a while and have finally gotten around to setting up a blog on it.  For now it&#8217;s running on <a href="http://wordpress.org">Wordpress</a>, which makes me a little nervous, but it&#8217;s the best of the free blog systems I looked at.  And it&#8217;s better than me spending six weeks writing my own.</p>

<p>Hopefully I&#8217;ll write in this more often than I do in my other blog-like things&#8230;</p>

<p>More to come soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://parsedout.com/2007/09/08/finally-post-numero-uno/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
