<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Chicken of the Web</title>
	<atom:link href="http://webkist.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://webkist.wordpress.com</link>
	<description>webkist.com</description>
	<lastBuildDate>Tue, 07 Jul 2009 15:20:19 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='webkist.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/55ab13e4e6e605ec369eca0c8efb9ca1?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Chicken of the Web</title>
		<link>http://webkist.wordpress.com</link>
	</image>
			<item>
		<title>YUI Sparkline Widget</title>
		<link>http://webkist.wordpress.com/2009/06/30/yui-sparkline-widget/</link>
		<comments>http://webkist.wordpress.com/2009/06/30/yui-sparkline-widget/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 19:26:06 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[internet]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=37</guid>
		<description><![CDATA[Edward Tufte&#8217;s sparklines are a nice way to present small minimal graphs in contexts where larger, full charts are not needed or warranted. The growing support for the HTML &#60;canvas&#62;  tag gives an opportunity to create these graphs dynamically in Javascript.
(Download yahoo-widget-sparkline-1.0b.zip.)
This widget was built against YUI version 2.7.0 but may work in other [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=37&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Edward Tufte&#8217;s <a href="http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR">sparklines</a> are a nice way to present small minimal graphs in contexts where larger, full charts are not needed or warranted. The growing support for the HTML &lt;canvas&gt;  tag gives an opportunity to create these graphs dynamically in Javascript.</p>
<p>(Download <a href="http://s3.amazonaws.com/MikeWebkistShared/yahoo-widget-sparkline-1.0b.zip">yahoo-widget-sparkline-1.0b.zip</a>.)</p>
<p>This widget was built against YUI version 2.7.0 but may work in other versions. It subclasses the &#8220;charts&#8221; module and is easily loaded via YUILoader. The <a href="http://www.webkist.com/secret/sparkline/test.html">test.html</a> creates a auto-updating sparkline based on a simple FunctionDataSource within a paragraph of text.</p>
<h2>Features:</h2>
<ul>
<li>If passed a height of &#8220;font-size&#8221; or &#8220;line-height&#8221; will cause the module to examine the CSS of the element to which it will be rendered to determine its height. This allows you to easily insert a sparkline into blocks of text without worrying about scaling the graph by hand.</li>
<li>By default it will remove all content within the element that will contain the &lt;canvas&gt;. This allows &#8220;alt=&#8221; type data to be displayed when &lt;canvas&gt; is not available.</li>
<li>Arbitrary highlighting of points with custom colors.</li>
<li>mean, median, standard deviation and arbitrary &#8220;normal&#8221; range shading.</li>
<li>Uses the Chart object&#8217;s polling setup to auto-update charts by re-polling the DataSource.</li>
</ul>
<h2>Usage:</h2>
<h3>Pull in the module:</h3>
<pre style="padding-left:30px;">var loader = new YAHOO.util.YUILoader();
loader.addModule({ name: 'sparklinecss', type: 'css',
                   fullpath: 'Sparkline.css'});
loader.addModule({ name: 'widget.Sparkline', type: 'js',
                   requires: ['charts', 'sparklinecss'],
                   fullpath: 'Sparkline.js'});
loader.require('widget.Sparkline', 'datasource', 'element');</pre>
<h3>Then create a sparkline:</h3>
<pre>var sl = new YAHOO.widget.Sparkline("sparkline-container",
                                    myDataSource,
                                    { height: 20, yField: "value" });
sl.subscribe("sparklineUpdate", updateHandler);</pre>
<h2>Configuration Options:</h2>
<p style="padding-left:30px;">
<dl>
<dt>max</dt>
<dd>Force a maximum y-value. Default is the largest value in the data.</dd>
<dt>min</dt>
<dd>Force a minimum y-value. Default is the smallest value in the data.</dd>
<dt>width</dt>
<dd>Width of the graph. Default is one pixel per data point.</dd>
<dt>height</dt>
<dd>A pixel value or &#8220;font-size&#8221; or &#8220;line-height&#8221;. Default is 20 pixels.</dd>
<dt>logscale</dt>
<dd>Change the y-axis to a logarithmic scale.</dd>
<dt>clearParent</dt>
<dd>Remove any children of the node passed to <code>render()</code> before adding the canvas. Default <code>true</code></dd>
<dt>zero, mean, median</dt>
<dd>Add horizontal lines at the appropriate places. Each can have a boolean <code>true</code> value or a string specifying the color for the line.</dd>
<dt>stddev</dt>
<dd>Calculate the standard deviation of the data and shade the background between +/- one standard deviation from the mean. Can be <code>true</code> or a color.</dd>
<dt>normal</dt>
<dd>An object with two or three fields: min, max, and (optionally) color. A background rectangle covering the range will be drawn in the specified (or default) color.</dd>
<dt>color</dt>
<dd>Graph color</dd>
<dt>highlightPoints</dt>
<dd>An array of two-field objects: x and color. <code>x</code> is the index of the point in <code>data</code> to highlight and <code>color</code> is the color to use. x-values of <code>max</code> and <code>min</code> highlight the maximum and minimum values. An x-value of <code>-1</code> highlights the last point in the data. </dd>
</dl>
<h2>To Do:</h2>
<ol>
<li>Graceful failure when &lt;canvas&gt; is unavailable.</li>
<li>Allow graphing of data extracted from HTML markup.</li>
</ol>
<p>(updated 7/7/2009)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=37&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2009/06/30/yui-sparkline-widget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>Perl Memcached Message Queue</title>
		<link>http://webkist.wordpress.com/2008/10/29/perl-memcached-message-queue/</link>
		<comments>http://webkist.wordpress.com/2008/10/29/perl-memcached-message-queue/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 21:17:22 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=29</guid>
		<description><![CDATA[Many years ago I wrote a simple perl+mysql polling script for work. It collected votes for multiple-choice polls, stored them in a database, and returned a results page. It was so simple and easy to use, we&#8217;ve continued using it for YEARS. Every so often we ask a question that is HIGHLY controversial (I&#8217;m looking [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=29&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many years ago I wrote a simple perl+mysql polling script for work. It collected votes for multiple-choice polls, stored them in a database, and returned a results page. It was so simple and easy to use, we&#8217;ve continued using it for YEARS. Every so often we ask a question that is HIGHLY controversial (I&#8217;m looking at you <a href="http://www.pbs.org/now/palin-poll.html">NOW</a>) and we are suddenly inundated with votes, causing much of the site to slow down or return errors.</p>
<p>The last time this happened I made some changes to the code that made it more difficult to vote more than once. Part of that involved storing the current vote totals in Memcached instead of asking the database each time. But even with that change, we&#8217;re still running a steady 3 or 4 votes per second and would be vulnerable to legitimate spikes in traffic from on-air promotion or something similar.</p>
<p>So today, I&#8217;ve reworked the script to run ALL traffic through memcached and NEVER hit the database at all unless memcached is completely unavailable. The basis for this is <a href="http://broddlit.wordpress.com/2008/04/09/memcached-as-simple-message-queue/">BroddlIT&#8217;s &#8220;memcached as simple message queue&#8221;</a> at least as far as I can figure from his rough sketch.</p>
<p>The general idea is, there&#8217;s a lock, a pointer to the next slot in the queue, and the queue entries themselves.</p>
<h2>Getting the lock</h2>
<p>This waits up to a second to get the lock by sleeping for 1/1000th of a second between attempts. You can implement multiple queues by varying the $key_prefix. If the loop exits without getting the lock, you have to decide what to do.</p>
<pre>  my $key_prefix = "poll-queue";
  my $total_sleep = 1000000;
  while($total_sleep &gt; 0) {
    my $lock_key = $memd-&gt;incr("$key_prefix-lock");

    if(!defined $lock_key) { # No key in cache.
      $memd-&gt;set("$key_prefix-lock", $lock_key = 1);
      $memd-&gt;set("$key_prefix-curr", 0);
      last;
    } elsif($lock_key == 1) { # We got the lock.
      last;
    }

    # Someone else has the lock, so wait 1/1000th of a second.
    $total_sleep -= usleep(1000);
  }
  if($total_sleep &lt;= 0) {
    # You didn't get the lock. Figure something out.
  }</pre>
<p>If you make sure you normally hold the lock for a very small amount of time, you can assume that waiting significantly longer than that without success gives you reasonable cause to take over the lock. The only trick there, as you might expect, is that you need to then release it before another process makes the same assumption.</p>
<h2>Get Next Key Pointer</h2>
<p>The $key_prefix-curr memcached key contains the index of the last entry in the queue. By calling the $memd-&gt;incr() method we get the next one and update the memcache at the same time. If for some reason the pointer doesn&#8217;t exist, it is created. The $key variable becomes the memcached key for this message.</p>
<pre>  my $next_key = $memd-&gt;incr("$key_prefix-curr");
  if(!defined($next_key)) { $memd-&gt;set("$key_prefix-curr", 1); }
  my $key = sprintf("$key_prefix-key-%d", $next_key);</pre>
<h2>Store the Message in the Queue</h2>
<p>Simple. Run this and the previous step in a loop to insert multiple values. But be careful because the lock is active, so the longer you take the longer you block other requests.</p>
<pre>  $memd-&gt;set($key, $message);</pre>
<h2>Release the Lock</h2>
<p>This releases the lock, which allows another process to insert its messages.</p>
<pre>  $memd-&gt;set("$key_prefix-lock", 0);</pre>
<h2>Reading and Flushing the Queue</h2>
<p>Obtain the lock in the same way as above, then get the $key_prefix-curr value and loop from 1. Just make sure you process the values after you release the lock so you don&#8217;t block new entries.</p>
<pre>  my $last_key = $memd-&gt;get("$key_prefix-curr");
  for(my $i=1; $i&lt;=$last_key; $i++) {
    my $key = sprintf("$key_prefix-key-%d", $i);
    push @messages, $memd-&gt;get($key);
  }
  $memd-&gt;set("$key_prefix-curr", 0);
  $memd-&gt;set("$key_prefix-lock", 0);

  process_messages(@messages);</pre>
<p>So that&#8217;s it. It should require only Cache::Memcached and Time::HiRes.</p>
<p>Update: if you run multiple memcached daemons and connect to them all (allowing key-hash load balancing), you will probably want to set the &#8220;no_rehash&#8221; flag and add a bit more error checking. If you allow Cache::Memcached to re-hash your keys if a server connection fails, you could end up losing the various keys temporarily.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=29&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/10/29/perl-memcached-message-queue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>rsync&#8217;ing a defined set of subdirectories</title>
		<link>http://webkist.wordpress.com/2008/10/06/rsyncing-a-defined-set-of-subdirectories/</link>
		<comments>http://webkist.wordpress.com/2008/10/06/rsyncing-a-defined-set-of-subdirectories/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 16:49:35 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[unix]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=27</guid>
		<description><![CDATA[So you have a directory structure that contains all of the applications needed to run a set of servers, but no server needs the entire tree. This rsync configuration is the easiest way I can come up with to rsync only what is needed for a single server:
If /export/apps contains bin, lib, var, etc, share [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=27&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So you have a directory structure that contains all of the applications needed to run a set of servers, but no server needs the entire tree. This rsync configuration is the easiest way I can come up with to rsync only what is needed for a single server:</p>
<p>If <code>/export/apps</code> contains <code>bin</code>, <code>lib</code>, <code>var</code>, <code>etc</code>, <code>share</code> and <code>sbin</code> but you only want <code>bin</code>, <code>lib</code>, and one subdirectory of <code>share</code> rsynced, <code>`hostname`-exclude-list.txt</code> then looks like this:</p>
<pre>+ /apps/bin/
+ /apps/lib/
+ /apps/share/vim/
- /apps/share/*
- /apps/*</pre>
<p>Using this command, you can then sync the directories:</p>
<pre># rsync -avz --delete-excluded \
        --exclude-from=`hostname`-exclude-list.txt \
        /export/apps /local</pre>
<p>With the <code>--delete-excluded</code>, if you change the exclude file, newly excluded entries will be removed from the destination. The copy will end up in <code>/local/apps</code>. More usefully, <code>/export/apps</code> could be on a remote server and the destination would be <code>/export</code>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=27&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/10/06/rsyncing-a-defined-set-of-subdirectories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>Reservoir Sampling in Perl</title>
		<link>http://webkist.wordpress.com/2008/10/01/reservoir-sampling-in-perl/</link>
		<comments>http://webkist.wordpress.com/2008/10/01/reservoir-sampling-in-perl/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 17:45:23 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=21</guid>
		<description><![CDATA[A method for randomly selecting N values from a finite (but unknown length) list of elements, without replacement. Algorithm is from Taming Uncertainty. This version takes lines of input on STDIN (or files on @ARGV) and selects 20 of them at random and prints the results to STDOUT.
#!/usr/bin/perl

use strict;
my $N = 20;
my $k;
my @r;

while(&#60;&#62;) {
 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=21&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A method for randomly selecting N values from a finite (but unknown length) list of elements, without replacement. Algorithm is from <a href="http://blogs.msdn.com/spt/archive/2008/02/05/reservoir-sampling.aspx">Taming Uncertainty</a>. This version takes lines of input on STDIN (or files on @ARGV) and selects 20 of them at random and prints the results to STDOUT.</p>
<pre>#!/usr/bin/perl

use strict;
my $N = 20;
my $k;
my @r;

while(&lt;&gt;) {
  if(++$k &lt;= $N) {
    push @r, $_;
  } elsif(rand(1) &lt;= ($N/$k)) {
    $r[rand(@r)] = $_;
  }
}

print @r;</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=21&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/10/01/reservoir-sampling-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>I&#8217;ll eat just about anything.</title>
		<link>http://webkist.wordpress.com/2008/08/29/ill-eat-just-about-anything/</link>
		<comments>http://webkist.wordpress.com/2008/08/29/ill-eat-just-about-anything/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 17:11:29 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=19</guid>
		<description><![CDATA[
The VGT Omnivore’s Hundred


1) Copy this list into your blog or journal, including these instructions.
2) Bold all the items you’ve eaten.
3) Cross out any items that you would never consider eating.
4) Optional extra: Post a comment at www.verygoodtaste.co.uk linking to your results.
I’ve eaten 60/100.
I’ll skip 4/100.
(via. Dean Sabatino)
1. Venison
2. Nettle tea
 3. Huevos rancheros
4. Steak [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=19&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div id="blog">
<h2>The VGT Omnivore’s Hundred</h2>
<div id="entry">
<div class="storycontent">
<p>1) Copy this list into your blog or journal, including these instructions.<br />
2) Bold all the items you’ve eaten.<br />
3) Cross out any items that you would never consider eating.<br />
4) Optional extra: Post a comment at <a href="http://www.verygoodtaste.co.uk/uncategorised/the-omnivores-hundred/">www.verygoodtaste.co.uk</a> linking to your results.</p>
<p>I’ve eaten 60/100.<br />
I’ll skip 4/100.</p>
<p>(via. <a href="http://www.deansabatino.com/2008/08/29/138/">Dean Sabatino</a>)</p>
<p><strong>1. Venison</strong><br />
2. Nettle tea<br />
<strong> 3. Huevos rancheros<br />
4. Steak tartare<br />
5. Crocodile</strong><br />
6. Black pudding<br />
<strong> 7. Cheese fondue<br />
8. Carp<br />
9. Borscht<br />
10. Baba ghanoush<br />
11. Calamari<br />
12. Pho<br />
13. PB&amp;J sandwich<br />
14. Aloo gobi<br />
15. Hot dog from a street cart</strong><br />
16. Epoisses<br />
<strong> 17. Black truffle</strong><br />
18. Fruit wine made from something other than grapes<br />
<strong>19. Steamed pork buns<br />
20. Pistachio ice cream<br />
21. Heirloom tomatoes<br />
22. Fresh wild berries<br />
23. Foie gras<br />
24. Rice and beans</strong><br />
25. Brawn, or head cheese<br />
<strong> 26. Raw Scotch Bonnet pepper</strong><br />
<strong>27. Dulce de leche<br />
28. Oysters<br />
29. Baklava</strong><br />
30. Bagna cauda<br />
<strong>31. Wasabi peas<br />
32. Clam chowder in a sourdough bowl<br />
33. Salted lassi<br />
34. Sauerkraut<br />
35. Root beer float</strong><br />
<span style="text-decoration:line-through;"> 36. Cognac with a fat cigar</span><br />
37. Clotted cream tea<br />
<strong>38. Vodka jelly/Jell-O<br />
39. Gumbo<br />
40. Oxtail<br />
41. Curried goat</strong><br />
<span style="text-decoration:line-through;"> 42. Whole insects</span><br />
43. Phaal<br />
44. Goat’s milk<br />
45. Malt whisky from a bottle worth £60/$120 or more<br />
46. Fugu<br />
<strong>47. Chicken tikka masala<br />
48. Eel<br />
49. Krispy Kreme original glazed doughnut</strong><br />
50. Sea urchin<br />
51. Prickly pear<br />
52. Umeboshi<br />
53. Abalone<br />
<strong>54. Paneer<br />
55. McDonald’s Big Mac Meal<br />
56. Spaetzle<br />
57. Dirty gin martini<br />
58. Beer above 8% ABV</strong><br />
<strong> 59. Poutine</strong><br />
<strong> 60. Carob chips</strong><br />
<strong> 61. S’mores</strong><br />
62. Sweetbreads<br />
<span style="text-decoration:line-through;"> 63. Kaolin</span><br />
64. Currywurst<br />
65. Durian<br />
66. Frogs’ legs<br />
<strong> 67. Beignets, churros, elephant ears or funnel cake</strong><br />
68. Haggis<br />
<strong> 69. Fried plantain</strong><br />
70. Chitterlings, or andouillette<br />
<strong> 71. Gazpacho</strong><br />
72. Caviar and blini<br />
<strong> 73. Louche absinthe</strong><br />
74. Gjetost, or brunost<br />
75. Roadkill<br />
76. Baijiu<br />
<strong> 77. Hostess Fruit Pie</strong><br />
<strong> 78. Snail</strong><br />
79. Lapsang souchong<br />
80. Bellini<br />
81. Tom yum<br />
<strong>82. Eggs Benedict<br />
83. Pocky</strong><br />
84. Tasting menu at a three-Michelin-star restaurant.<br />
85. Kobe beef<br />
<strong>86. Hare</strong><br />
87. Goulash<br />
88. Flowers<br />
<span style="text-decoration:line-through;"> 89. Horse</span><br />
90. Criollo chocolate<br />
<strong> 91. Spam</strong><br />
<strong> 92. Soft shell crab</strong><br />
93. Rose harissa<br />
<strong> 94. Catfish</strong><br />
<strong> 95. Mole poblano</strong><br />
<strong> 96. Bagel and lox</strong><br />
97. Lobster Thermidor<br />
<strong>98. Polenta<br />
99. Jamaican Blue Mountain coffee</strong><br />
100. Snake</div>
</div>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/webkist.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/webkist.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=19&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/08/29/ill-eat-just-about-anything/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL for getting the closest Zipcodes</title>
		<link>http://webkist.wordpress.com/2008/06/04/sql-for-getting-the-closest-zipcodes/</link>
		<comments>http://webkist.wordpress.com/2008/06/04/sql-for-getting-the-closest-zipcodes/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 19:02:35 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[geography]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=14</guid>
		<description><![CDATA[If you have a database of zipcodes and their latitudes and longitudes, you can use a version of this query to get the geographically closest zipcodes:
SELECT b.zipcode, b.city, b.state, b.latitude, b.longitude,
       ACOS(SIN(RADIANS(a.latitude))
          * SIN(RADIANS(b.latitude)) +
      [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=14&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you have a database of zipcodes and their latitudes and longitudes, you can use a version of <a href="http://www.zcentric.com/blog/2007/03/calculate_distance_in_mysql_wi.html">this query</a> to get the geographically closest zipcodes:</p>
<pre>SELECT b.zipcode, b.city, b.state, b.latitude, b.longitude,
       ACOS(SIN(RADIANS(a.latitude))
          * SIN(RADIANS(b.latitude)) +
            COS(RADIANS(a.latitude))
          * COS(RADIANS(b.latitude))
          * COS(RADIANS(a.longitude - b.longitude))) as distance
 FROM zipcodes.zip_to_latlong a,
      zipcodes.zip_to_latlong b
WHERE a.zipcode=?
ORDER BY distance
LIMIT 20</pre>
<p>The &#8220;distance&#8221; there is&#8230;I dunno&#8230;radians? I think the original is assuming the points are on a sphere, and converts from radians to degrees to miles using the <a href="http://en.wikipedia.org/wiki/Mile#Nautical_miles">1.1515 statue miles per nautical mile</a> standard.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/webkist.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/webkist.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=14&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/06/04/sql-for-getting-the-closest-zipcodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>Python Memcache module extension</title>
		<link>http://webkist.wordpress.com/2008/06/04/python-memcache-module-extension/</link>
		<comments>http://webkist.wordpress.com/2008/06/04/python-memcache-module-extension/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 14:45:06 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=11</guid>
		<description><![CDATA[I&#8217;m mostly a Perl guy (with secret love of Javascript), so I try to stay out of the Python stuff at dayjob where possible. But recently I&#8217;ve been taking the lead on a bunch of Memcached optimizations, which are starting to trickle over into the Python side.
A nice feature of the Perl Cache::Memcached module is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=11&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m mostly a Perl guy (with secret love of Javascript), so I try to stay out of the Python stuff at <a href="http://www.pbs.org/">dayjob</a> where possible. But recently I&#8217;ve been taking the lead on a bunch of <a href="http://www.danga.com/memcached/">Memcached</a> optimizations, which are starting to trickle over into the Python side.</p>
<p>A nice feature of the Perl <code>Cache::Memcached</code> module is the ability to define a &#8220;namespace&#8221; when you create the Memcached object:</p>
<pre>my $memd = new Cache::Memcached (namespace =&gt; "foo_");
</pre>
<p>Then, any keys passed to the <code>$memd</code> object via <code>get</code>/<code>set</code>/etc. are automatically prefixed with &#8220;foo_&#8221;: <code>$memd-&gt;get("123")</code> actually requests the memcached key &#8220;foo_123&#8243;.</p>
<p>Python&#8217;s memcache module supports namespaces for the *<code>_multi</code> methods, but not on the individual <code>get</code>/<code>set</code>/etc calls. Also, the namespace must be passed on each call &#8212; you can&#8217;t specify it in the constructor. Well, subclassing saves the day again:</p>
<pre>class Client(memcache.Client):
    def __init__(self, servers=None, debug=0, namespace=None):
        super(Client, self).__init__(servers, debug=debug)

        if namespace:
            self._namespace = namespace
        else:
            self._namespace=""

    # GET
    def get(self, key):
        try:
            val=self.get_multi([ key ])[key]
        except KeyError:
            val=None
        return val

    def get_multi(self, keys, key_prefix=''):
        if self._namespace: key_prefix=self._namespace + key_prefix
        return super(Client, self).get_multi(keys, key_prefix=key_prefix)

    # SET
    def set(self, key, val, time=0, min_compress_len=0):
        return self.set_multi({ key : val }, time=time, min_compress_len=min_compress_len)

    def set_multi(self, mapping, time=0, key_prefix='', min_compress_len=0):
        if self._namespace: key_prefix=self._namespace + key_prefix
        return super(Client, self).set_multi(mapping, time=time, key_prefix=key_prefix, min_compress_len=min_compress_len)

    # DELETE
    def delete(self, key, time=0):
        return self.delete_multi([key], time=time)

    def delete_multi(self, keys, seconds=0, key_prefix=''):
        if self._namespace: key_prefix=self._namespace + key_prefix
        return super(Client, self).delete_multi(keys, seconds=seconds, key_prefix=key_prefix)

    # EVERYTHING ELSE
    def add(self, key, val, time=0, min_compress_len=0):
        if self._namespace: key=self._namespace + str(key)
        super(Client, self).add(key, val, time=time, min_compress_len=min_compress_len)

    def incr(self, key, delta=1):
        if self._namespace: key=self._namespace + str(key)
        super(Client, self).incr(key, delta=delta)

    def replace(self, key, val, time=0, min_compress_len=0):
        if self._namespace: key=self._namespace + str(key)
        super(Client, self).replace(key, val, time=time, min_compress_len=min_compress_len)

    def decr(self, key, delta=1):
        if self._namespace: key=self._namespace + str(key)
        super(Client, self).decr(key, delta=delta)
</pre>
<p>The <code>__init__</code> method is overridden to take an additional &#8220;namespace&#8221; parameter, which is stored in <code>self._namespace</code>. The <code>get</code>/<code>set</code>/<code>delete</code> methods all have namespace-capable *<code>_multi</code> versions, so for those I just pass the calls off to the appropriate one. The *<code>_multi</code> methods themselves are subclassed to check the <code>self._namespace</code> value as well as the namespace parameter, like normal. Finally, the <code>add</code>/<code>incr</code>/<code>replace</code>/<code>decr</code> methods are all modified to check the <code>self._namespace</code> value and prefix it to the key. Obviously, <code>get</code>/<code>set</code>/<code>delete</code> could have been done the same way.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/webkist.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/webkist.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=11&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/06/04/python-memcache-module-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>XSLT and Apache Server Side Includes:</title>
		<link>http://webkist.wordpress.com/2008/05/22/xslt-and-apache-server-side-includes/</link>
		<comments>http://webkist.wordpress.com/2008/05/22/xslt-and-apache-server-side-includes/#comments</comments>
		<pubDate>Thu, 22 May 2008 14:50:54 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mod_include]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=10</guid>
		<description><![CDATA[Yesterday at work someone was trying to pass traditional Apache SSI directives through an XSL transformation on a Google search appliance. Long story short, they vanished: HTML comments don&#8217;t make it out of that device.
Anyway&#8230;I had a simple solution. Since we were pumping the Google results through a Perl CGI anyway, there was no reason [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=10&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Yesterday at work someone was trying to pass traditional Apache SSI directives through an XSL transformation on a Google search appliance. Long story short, they vanished: HTML comments don&#8217;t make it out of that device.</p>
<p>Anyway&#8230;I had a simple solution. Since we were pumping the Google results through a Perl CGI anyway, there was no reason we couldn&#8217;t just output a fake HTML tag which the CGI would then turn into an SSI comment for Apache. This was born <code>&lt;ssi virtual="/foo/bar.html" /&gt;</code>.</p>
<p>Then a simple <code>s/&lt;ssi (virtual=\"[^\"]+\")&gt;&lt;\/ssi&gt;/&lt;!--#include $1 --&gt;/;</code> in Perl will give something Apache can understand.</p>
<p>That solved the immediate problem, but got me thinking about emulating the full Apache mod_include set of SSI directives using the <code>&lt;ssi&gt;</code> tag. I&#8217;m thinking of something like this:</p>
<pre>&lt;ssi element="include" virtual="/foo/bar.html" /&gt;

&lt;ssi element="set" var="FOO" value="BAR" /&gt;

&lt;ssi element="if"&gt;
  &lt;ssi_if expr="test_condition"&gt;YES!&lt;/ssi_if&gt;
  &lt;ssi_elif expr="test_condition"&gt;MAYBE!&lt;/ssi_elif&gt;
  &lt;ssi_else&gt;NO!&lt;/ssi_else&gt;
&lt;/ssi&gt;
</pre>
<p>And with that format, the original version still works if you assume a missing &#8220;element&#8221; attribute implies <code>element="include"</code>. The <code>&lt;!--#if --&gt;</code> block isn&#8217;t quite satisfying here &#8212; any text nodes inside the <code>&lt;ssi&gt;</code> block but outside the <code>&lt;ssi_(if|elif|else)&gt;</code> blocks would be ignored, but that&#8217;s no different than odd content in, say, a <code>&lt;table&gt;</code> that doesn&#8217;t actually fall into a cell.</p>
<p>I don&#8217;t actually have the Perl that would do the transformation, but it wouldn&#8217;t be hard. I&#8217;ll wait until someone actually needs it.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/webkist.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/webkist.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=10&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/05/22/xslt-and-apache-server-side-includes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>Apache2::Localtime</title>
		<link>http://webkist.wordpress.com/2008/05/16/apache2localtime/</link>
		<comments>http://webkist.wordpress.com/2008/05/16/apache2localtime/#comments</comments>
		<pubDate>Fri, 16 May 2008 20:46:45 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mod_perl]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=9</guid>
		<description><![CDATA[mod_perl 2 has an annoying&#8230;feature. Because the system environ struct is not thread safe, mod_perl&#8217;s perl-script handler unties the %ENV hash from the actual environment. That means, anything that uses the C getenv/setenv/unsetenv functions to read the environment will not see changes that were made to %ENV.
An obvious example is Perl&#8217;s localtime function. It actually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=9&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>mod_perl 2 has an annoying&#8230;feature. Because the system <code>environ</code> struct is not thread safe, mod_perl&#8217;s <code>perl-script</code> handler unties the <code>%ENV</code> hash from the actual environment. That means, anything that uses the C <code>getenv</code>/<code>setenv</code>/<code>unsetenv</code> functions to read the environment will not see changes that were made to <code>%ENV</code>.</p>
<p>An obvious example is Perl&#8217;s <code>localtime</code> function. It actually calls the system <code>localtime</code> function, which uses the C <code>getenv</code> to check the current value of the timezone environment variable <code>TZ</code>. If you try to change the timezone in a mod_perl2 program by assigning to <code>$ENV{TZ}</code>, <code>localtime</code> won&#8217;t know it.</p>
<p>The solution is to use the <code>Env::C</code> module and it&#8217;s <code>getenv</code>/<code>setenv</code>/<code>unsetenv</code> wrappers. It works fine, but it&#8217;s a bit cumbersome. But a simple module, loaded at server-startup time, can wrap the system <code>localtime</code> in a function that takes care of the environment.</p>
<pre>
package Apache2::Localtime;

use Env::C;
use Exporter;
use strict;

our @ISA = qw(Exporter);
our @EXPORT = qw(localtime);

sub import {
  my $class = shift;
  $class-&gt;export('CORE::GLOBAL', 'localtime');
}

sub localtime {
  my $time = shift || time;
  return localtime($time) unless $ENV{TZ};

  my $orig_tz = Env::C::getenv('TZ');
  Env::C::setenv('TZ', $ENV{TZ}, 1);
  my(@ret, $ret);
  if(wantarray) {
    @ret = CORE::localtime($time);
  } else {
    $ret = CORE::localtime($time);
  }
  if(defined $orig_tz) {
    Env::C::setenv('TZ', $orig_tz, 1);
  } else {
    Env::C::unsetenv('TZ');
  }
  return wantarray ? @ret : $ret;
}

1;
</pre>
<p>Put that in your <code>@INC</code> path at <code>Apache2/Localtime.pm</code> and then add <code>use Apache2::Localtime</code> to a <code>PerlRequire .../initialize.pl</code> script or something similar. The new function should override the built-in <code>localtime</code> and keep your timeonzes in sync.</p>
<p>The code was mostly taken from <a href="http://aspn.activestate.com/ASPN/Mail/Message/perl-mod_perl/3594080">here</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/webkist.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/webkist.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=9&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/05/16/apache2localtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
		<item>
		<title>Cache::Memcached extension</title>
		<link>http://webkist.wordpress.com/2008/04/17/cachememcached-extension/</link>
		<comments>http://webkist.wordpress.com/2008/04/17/cachememcached-extension/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 14:59:21 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://webkist.wordpress.com/?p=8</guid>
		<description><![CDATA[I&#8217;ve been using Memcached for a few weeks, trying to offload some VERY heavy database load. It&#8217;s nice and blazing fast, but the implementation is sort of clunky. If I have this simple bit of code:
$key = "foobar";
$val = calculate_val($key);
It turns into this:
$key = "foobar";
$val = $memd-&#62;get($key);
if(! defined($val)) {
  $val = calculate_val($key);
  $memd-&#62;set($key, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=8&subd=webkist&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been using <code>Memcached</code> for a few weeks, trying to offload some VERY heavy database load. It&#8217;s nice and blazing fast, but the implementation is sort of clunky. If I have this simple bit of code:</p>
<pre>$key = "foobar";
$val = calculate_val($key);</pre>
<p>It turns into this:</p>
<pre>$key = "foobar";
$val = $memd-&gt;get($key);
if(! defined($val)) {
  $val = calculate_val($key);
  $memd-&gt;set($key, $val);
}</pre>
<p>Repeatedly I came back to the idea of a <code>get_or_set</code> method that would handle this stuff, but until the obvious solution hit me, I couldn&#8217;t get it:</p>
<pre>$key = "foobar";
$val = $memd-&gt;get_or_set($key, sub { calculate_val($key) });</pre>
<p>A simple closure around the actual calculation block which is then passed to the <code>get_or_set</code> method as a callback. If the lookup finds a value the method returns it, otherwise it returns the result of calling the callback function.</p>
<p>The only change to Cache::Memcached is adding the get_or_set function. The easiest way is to just subclass Cache::Memcached:</p>
<pre>package My::Memcached
use base qw(Cache::Memcached);
sub get_or_set {
  my $self = shift;
  my($key, $callback) = @_;
  my $val = $self-&gt;get($key);
  unless(defined $val) {
    $val = &amp;$callback;
    $self-&gt;set($key, $val);
  }
  return $val;
}

1;</pre>
<p>Now you have this simple interface:</p>
<pre>use My::Memcached;

my $memd = new My::Memcached { servers =&gt; [...] };
my $foo = $memd-&gt;get_or_set("bar", sub { get_val("bar") });</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/webkist.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/webkist.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webkist.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webkist.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webkist.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webkist.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webkist.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webkist.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webkist.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webkist.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webkist.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webkist.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webkist.wordpress.com&blog=1459179&post=8&subd=webkist&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://webkist.wordpress.com/2008/04/17/cachememcached-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c080d32f94ed01529c5d140d34288fbf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Mike</media:title>
		</media:content>
	</item>
	</channel>
</rss>