<?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>A Tempest of Thoughts &#187; Lua</title>
	<atom:link href="http://tempe.st/category/lua/feed/" rel="self" type="application/rss+xml" />
	<link>http://tempe.st</link>
	<description>aka blog.to_int(:inig)</description>
	<lastBuildDate>Thu, 07 Apr 2011 08:24:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>WordPress + Lighttpd + WP-Supercache + Mobile Support</title>
		<link>http://tempe.st/2009/11/wordpress-lighttpd-wp-supercache-mobile-support/</link>
		<comments>http://tempe.st/2009/11/wordpress-lighttpd-wp-supercache-mobile-support/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 16:35:10 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Lua]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[wp-supercache]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=305</guid>
		<description><![CDATA[Last year I made some work on lighttpd support for wp-supercache. It instantly became very popular and basically anyone running wordpress on lighttpd uses it, even if it lacks support for wp-supercache newest features. The amazing Jean Pierre Wenzel has recently released an updated version that adds a much needed mobile support. You can check [...]]]></description>
			<content:encoded><![CDATA[	<p>Last year I made <a href="http://tempe.st/2008/05/lightning-speed-wordpress-with-lighttpd-and-supercache-part-ii/">some work</a> on lighttpd support for wp-supercache. It instantly became very popular and basically anyone  running wordpress on lighttpd uses it, even if it lacks support for wp-supercache newest features.</p>
	<p>The amazing <a href="http://github.com/jpwenzel">Jean Pierre Wenzel</a> has recently released an updated version that adds a much needed mobile support.</p>
	<p>You can check it out <a href="http://github.com/jpwenzel/wp-lighttpd-rewrite">here.</a></p>
	<p>Thanks Jean Pierre!</p>


 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2009/11/wordpress-lighttpd-wp-supercache-mobile-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lightning speed WordPress with Lighttpd and Supercache, part II</title>
		<link>http://tempe.st/2008/05/lightning-speed-wordpress-with-lighttpd-and-supercache-part-ii/</link>
		<comments>http://tempe.st/2008/05/lightning-speed-wordpress-with-lighttpd-and-supercache-part-ii/#comments</comments>
		<pubDate>Mon, 05 May 2008 09:13:44 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[wp-supercache]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=210</guid>
		<description><![CDATA[There was an error in the code I wrote for my previous post about lighttpd and wp-supercache. If you kept GZip disabled in you wp-supercache configuration, and your browser sent an Accepts gzip header, lightpress would serve the dynamic page (instead of the cached html page). I did some refactoring and testing, and here&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[	<p>There was an error in the code I wrote for my previous post about <a href="http://tempe.st/2008/04/lighttpd-and-wp-supercache-now-you-can/">lighttpd and wp-supercache</a>. If you kept GZip disabled in you wp-supercache configuration, and your browser sent an Accepts gzip header, lightpress would serve the dynamic page (instead of the cached html page). </p>
	<p>I did some refactoring and testing, and here&#8217;s the current version of rewrite.lua. This one will serve the correct gzipped or text content, while solving another bug with urls ending in &#8221;/&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #b1b100;">function</span> serve_html<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>lighty.stat<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> cached_page
    <span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Serving cached page: &quot;</span> .. cached_page<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">true</span>
  <span style="color: #b1b100;">else</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">false</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">function</span> serve_gzip<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>lighty.stat<span style="color: #66cc66;">&#40;</span>cached_page .. <span style="color: #ff0000;">&quot;.gz&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    lighty.header<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Content-Encoding&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;gzip&quot;</span>
    lighty.header<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;&quot;</span>
    lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> cached_page .. <span style="color: #ff0000;">&quot;.gz&quot;</span>
    <span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Serving gzipped page: &quot;</span> .. cached_page .. <span style="color: #ff0000;">&quot;.gz&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">true</span>
  <span style="color: #b1b100;">else</span>
    <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">false</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span>
&nbsp;
attr <span style="color: #66cc66;">=</span> lighty.stat<span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> attr<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;/index.php&quot;</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.rel-path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.path&quot;</span><span style="color: #66cc66;">&#93;</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span> .. lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.rel-path&quot;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
  query_condition <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.query&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">and</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.query&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #ff0000;">&quot;.*s=.*&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  user_cookie <span style="color: #66cc66;">=</span> lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Cookie&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #ff0000;">&quot;no_cookie_here&quot;</span>
  cookie_condition <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*comment_author.*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*wordpress.*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*wp-postpass_.*&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>query_condition <span style="color: #b1b100;">and</span> cookie_condition<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    accept_encoding <span style="color: #66cc66;">=</span> lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Accept-Encoding&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #ff0000;">&quot;no_acceptance&quot;</span>
    cached_page <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span> .. <span style="color: #ff0000;">&quot;/wp-content/cache/supercache/&quot;</span> .. lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Host&quot;</span><span style="color: #66cc66;">&#93;</span> .. lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;request.uri&quot;</span><span style="color: #66cc66;">&#93;</span> .. <span style="color: #ff0000;">&quot;/index.html&quot;</span>
    cached_page <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">string.gsub</span><span style="color: #66cc66;">&#40;</span>cached_page, <span style="color: #ff0000;">&quot;//&quot;</span>, <span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>accept_encoding, <span style="color: #ff0000;">&quot;gzip&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> serve_gzip<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span> serve_html<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">else</span>
      serve_html<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">end</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span></pre></div></div>



 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/05/lightning-speed-wordpress-with-lighttpd-and-supercache-part-ii/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Lighttpd and WP-Supercache? Now you can!</title>
		<link>http://tempe.st/2008/04/lighttpd-and-wp-supercache-now-you-can/</link>
		<comments>http://tempe.st/2008/04/lighttpd-and-wp-supercache-now-you-can/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 13:53:45 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wp-cache]]></category>
		<category><![CDATA[wp-supercache]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=202</guid>
		<description><![CDATA[Update: there are some bugs with this code. You can find the newest (and best) version here It&#8217;s often said that if you can&#8217;t find something in Google it doesn&#8217;t exist, and when I couldn&#8217;t find a way to serve WP-Supercached pages via Lighttpd I was pretty sure no one had ever published on the [...]]]></description>
			<content:encoded><![CDATA[	<p><strong>Update:</strong> there are some bugs with this code. You can find the newest (and best) version <a href="http://tempe.st/2008/05/lightning-speed-wordpress-with-lighttpd-and-supercache-part-ii/">here</a></p>
	<p>It&#8217;s often said that if you can&#8217;t find something in Google it doesn&#8217;t exist, and when I couldn&#8217;t find a way to serve <a href="http://ocaoimh.ie/wp-super-cache/">WP-Supercache</a>d pages via Lighttpd I was pretty sure no one had ever published on the net a solution to my problem.</p>
	<p>Nice permalinks were easy to fix, thanks to <a href="http://sudhaker.com/2008/04/wordpress-permalinks-lighttpd/">this tutorial</a>, but cache was a no-go: the lighttpd wiki and the wordpress forums had no info, so I had to cook a solution for myself. </p>
	<p>It was easier than I thought though:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- rewrite.lua, in your WP_ROOT</span>
attr <span style="color: #66cc66;">=</span> lighty.stat<span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> attr<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;/index.php&quot;</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.rel-path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.path&quot;</span><span style="color: #66cc66;">&#93;</span>
  lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span> .. lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.rel-path&quot;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
  query_condition <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.query&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">and</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uri.query&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #ff0000;">&quot;.*s=.*&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  user_cookie <span style="color: #66cc66;">=</span> lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Cookie&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #ff0000;">&quot;no_cookie_here&quot;</span>
  cookie_condition <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*comment_author.*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*wordpress.*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>user_cookie, <span style="color: #ff0000;">&quot;.*wp-postpass_.*&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>query_condition <span style="color: #b1b100;">and</span> cookie_condition<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
    accept_encoding <span style="color: #66cc66;">=</span> lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Accept-Encoding&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">or</span> <span style="color: #ff0000;">&quot;no_acceptance&quot;</span>
    cached_page <span style="color: #66cc66;">=</span> lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.doc-root&quot;</span><span style="color: #66cc66;">&#93;</span> .. <span style="color: #ff0000;">&quot;/wp-content/cache/supercache/&quot;</span> .. lighty.request<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Host&quot;</span><span style="color: #66cc66;">&#93;</span> .. lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;request.uri&quot;</span><span style="color: #66cc66;">&#93;</span> .. <span style="color: #ff0000;">&quot;/index.html&quot;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string.find</span><span style="color: #66cc66;">&#40;</span>accept_encoding, <span style="color: #ff0000;">&quot;gzip&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>lighty.stat<span style="color: #66cc66;">&#40;</span>cached_page .. <span style="color: #ff0000;">&quot;.gz&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
        lighty.header<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Content-Encoding&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;gzip&quot;</span>
        lighty.header<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;&quot;</span>
        lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> cached_page
      <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">else</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>lighty.stat<span style="color: #66cc66;">&#40;</span>cached_page<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
        lighty.env<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;physical.path&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> cached_page
      <span style="color: #b1b100;">end</span>
    <span style="color: #b1b100;">end</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span></pre></div></div>

	<p>This rewrite.lua will serve compressed cached pages to those who accept gzip and plain html to those who prefer not to get gzip, while retaining the nice permalinks.</p>


 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/04/lighttpd-and-wp-supercache-now-you-can/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The battle of the languages part II</title>
		<link>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/</link>
		<comments>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/#comments</comments>
		<pubDate>Wed, 23 May 2007 15:41:21 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/</guid>
		<description><![CDATA[My previous post about a programming contest I had with my friends was wildly popular. Much much more than I even thought possible. I started with a simple comparison of PHP, C, Ruby, Erlang and Javascript and ended up with lots of comments where people posted interesting implementations in more and more languages, even obscure [...]]]></description>
			<content:encoded><![CDATA[	<p><a href="http://tempe.st/2007/05/erlang-ruby-and-php-battle-it-out">My previous post</a> about a programming contest I had with my friends was wildly popular. Much much more than I even thought possible.</p>
	<p>I started with a simple comparison of PHP, C, Ruby, Erlang and Javascript and ended up with lots of comments where people posted interesting implementations in more and more languages, even obscure ones (to me) like Haskell and Ocaml.</p>
	<p>I owe everyone a fairer benchmark so I will do the test again, this time testing the following languages:</p>
	<ul>
		<li>C</li>
		<li>Common Lisp</li>
		<li>Erlang</li>
		<li>Haskell</li>
		<li>Javascript</li>
		<li>Java</li>
		<li>Ocaml</li>
		<li>Perl</li>
		<li>PHP</li>
		<li>Python</li>
		<li>Ruby</li>
	</ul>
	<p>I need submissions for most of these languages, and I actually am quite open to submissions for the languages I speak <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
	<p>The rules are simple, the program has to store the results in an array (not just count them) and has to run without any strange libraries or compilers or compiler switches. To avoid interpreter starting time problems, please submit programs that autotime themselves.</p>
	<p>As usual we&#8217;ll find the pythagorean triplets up to 5000. The reference implementation is the following, in Ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">t = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
result = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006666;">2</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5000</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> 
  <span style="color:#006666;">1</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span>c<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span>
    a = <span style="color:#CC00FF; font-weight:bold;">Math</span>.<span style="color:#9900CC;">sqrt</span><span style="color:#006600; font-weight:bold;">&#40;</span>c<span style="color:#006600; font-weight:bold;">*</span>c <span style="color:#006600; font-weight:bold;">-</span> b<span style="color:#006600; font-weight:bold;">*</span>b<span style="color:#006600; font-weight:bold;">&#41;</span>
    result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>a.<span style="color:#9900CC;">to_i</span>, b, c<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> a.<span style="color:#9900CC;">to_i</span> == a 
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">-</span> t</pre></div></div>

	<p>This code takes 15.70s to run on my macbook pro. </p>
	<p>Now it&#8217;s your turn!</p>
	<p><strong>Update:</strong> Lua version by Sindisil</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #b1b100;">local</span> tt <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">local</span> result <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">local</span> c
  <span style="color: #b1b100;">for</span> c <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">5000</span> <span style="color: #b1b100;">do</span>
    <span style="color: #b1b100;">local</span> b
    <span style="color: #b1b100;">for</span> b <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>, c-<span style="color: #cc66cc;">1</span> <span style="color: #b1b100;">do</span>
      <span style="color: #b1b100;">local</span> a <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">math.sqrt</span><span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">*</span>c - b<span style="color: #66cc66;">*</span>b<span style="color: #66cc66;">&#41;</span>
      <span style="color: #b1b100;">if</span> a <span style="color: #66cc66;">==</span> <span style="color: #b1b100;">math.floor</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      result<span style="color: #66cc66;">&#91;</span>#result+<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> a, b, c <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">end</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - tt<span style="color: #66cc66;">&#41;</span></pre></div></div>

	<p>It takes 5.48s to run on my box.</p>
	<p><strong>Update:</strong> new Ruby version.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#CC00FF; font-weight:bold;">Math</span>
&nbsp;
a, b, c = <span style="color:#006666;">0</span>
result = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006666;">2</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5000</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> 
  d = c <span style="color:#006600; font-weight:bold;">*</span> c
  <span style="color:#006666;">1</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span>c<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span>
    a = sqrt<span style="color:#006600; font-weight:bold;">&#40;</span>d <span style="color:#006600; font-weight:bold;">-</span> b<span style="color:#006600; font-weight:bold;">*</span>b<span style="color:#006600; font-weight:bold;">&#41;</span>
    result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>a.<span style="color:#9900CC;">floor</span>, b, c<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> a.<span style="color:#9900CC;">floor</span> == a 
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC00FF; font-weight:bold;">Process</span>.<span style="color:#9900CC;">times</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

	<p>Following Gabriele Renzi&#8217;s suggestions we now have a faster ruby version: 12.30s</p>
	<p><strong>Update:</strong> faster Lua version from Chris Swetenham, it runs in 3.44s</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #b1b100;">local</span> tt <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">local</span> result <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">local</span> c
<span style="color: #b1b100;">local</span> n <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>
<span style="color: #b1b100;">local</span> <span style="color: #b1b100;">math</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">math</span>
<span style="color: #b1b100;">local</span> <span style="color: #b1b100;">sqrt</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">math.sqrt</span>
<span style="color: #b1b100;">local</span> <span style="color: #b1b100;">floor</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">math.floor</span>
&nbsp;
<span style="color: #b1b100;">for</span> c <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">5000</span> <span style="color: #b1b100;">do</span>
  <span style="color: #b1b100;">local</span> b
  <span style="color: #b1b100;">for</span> b <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>, c-<span style="color: #cc66cc;">1</span> <span style="color: #b1b100;">do</span>
    <span style="color: #b1b100;">local</span> a <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">sqrt</span><span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">*</span>c - b<span style="color: #66cc66;">*</span>b<span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">if</span> a <span style="color: #66cc66;">==</span> <span style="color: #b1b100;">floor</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      result<span style="color: #66cc66;">&#91;</span>n<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> a, b, c <span style="color: #66cc66;">&#125;</span>
      n <span style="color: #66cc66;">=</span> n + <span style="color: #cc66cc;">1</span>
    <span style="color: #b1b100;">end</span>
  <span style="color: #b1b100;">end</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">os.clock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - tt<span style="color: #66cc66;">&#41;</span></pre></div></div>

	<p><strong>Update:</strong> PHP version by <a href="http://fullo.net">Fullo</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> <span style="color: #000088;">$c</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">5000</span><span style="color: #339933;">;</span> <span style="color: #000088;">$c</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$b</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span> <span style="color: #000088;">$b</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">*</span><span style="color: #000088;">$c</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$b</span><span style="color: #339933;">*</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span> 
       <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #000088;">$b</span><span style="color: #339933;">,</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>              
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

	<p>It runs in 9.73s.</p>
	<p><strong>Update:</strong> Python version from ludo, it runs in 11.2s</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">time</span> <span style="color: #ff7700;font-weight:bold;">import</span> clock
&nbsp;
start = clock<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">math</span> <span style="color: #ff7700;font-weight:bold;">import</span> sqrt
&nbsp;
results = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> c <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">5001</span><span style="color: black;">&#41;</span>:
  d = c <span style="color: #66cc66;">*</span> c
  <span style="color: #ff7700;font-weight:bold;">for</span> b <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, c<span style="color: black;">&#41;</span>:
    a = sqrt<span style="color: black;">&#40;</span>d - b <span style="color: #66cc66;">*</span> b<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> a <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">1</span> == <span style="color: #ff4500;">0.0</span>:
      results.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>a, b, c<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> clock<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - start</pre></div></div>

	<p>The results for now:</p>
	<ol>
		<li>Lua 3.44</li>
		<li>PHP 9.73</li>
		<li>Python 11.20</li>
		<li>Ruby 12.30</li>
	</ol>


 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
	</channel>
</rss>

