<?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>CommitBlog</title>
	<atom:link href="http://blog.laaz.org/tech/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.laaz.org/tech</link>
	<description>Programming, technology and IT-survival</description>
	<lastBuildDate>Tue, 24 Jan 2012 22:04:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Turn Linux into a remote AirPlay speaker</title>
		<link>http://blog.laaz.org/tech/2012/01/25/turn-linux-into-a-remote-airplay-speaker/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2012/01/25/turn-linux-into-a-remote-airplay-speaker/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 22:04:05 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Rest of the World]]></category>
		<category><![CDATA[Airfoil]]></category>
		<category><![CDATA[AirPlay]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[ShairPort]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=417</guid>
		<description><![CDATA[Some time ago Apple game out with the AirPlay feature (an upgraded AirTunes) which enables iOS devices and iTunes play music and videos on a remote device. &#160; In our office we have a Linux box, a set of speakers and &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2012/01/25/turn-linux-into-a-remote-airplay-speaker/">Read more &#187;</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Some time ago Apple game out with the <a title="AirPlay" href="http://www.apple.com/itunes/airplay/">AirPlay</a> feature (an upgraded AirTunes) which enables iOS devices and iTunes play music and videos on a remote device.</p>
<p>&nbsp;</p>
<p>In our office we have a Linux box, a set of speakers and a few laptops sporting Mac and Windows. Tonight I set out with a goal to turn that Linux box into an AirPlay speaker so that each of us can play music from their laptop without having to reconnect the cables every time.</p>
<h2>Airfoil</h2>
<p><img class="alignright" title="Airfoil" src="http://rogueamoeba.com/global/images/icons/96/airfoil96.png" alt="" width="96" height="96" />First off I stubled upon RougeAmoeba&#8217;s <a href="http://rogueamoeba.com/airfoil/">Airfoil</a>, which is a $25 sofware piece that, enables half a dozen device classes to be hooked up as remote speakers to a Mac or Windows (yes, that too). And, better yet, instead of only enabling iTunes to play, it can reroute all sound to that remote speaker. Though, it&#8217;s Linux speaker software is free download, it still seems to require paid Airfoil to route audio, because bare iTunes couldn&#8217;t care less of the wannabe Linux speaker that should have appeared to the WiFi. As the price would have been multiplied by the number of laptops, it was unfortunately out of question.</p>
<h2>Shairport</h2>
<p><img class="size-full wp-image-418 alignright" title="ShairPort" src="http://blog.laaz.org/tech/wp-content/uploads/2012/01/shairplay.png" alt="" width="192" height="77" /></p>
<p>With a bit of googling around, I next found <a href="https://github.com/albertz/shairport">Shairport</a>, which (if I got it correctly) is based on data found in a hacked and reverse engineered AirPort Express. ShairPort turns a random PC into a fake AirPlay speaker set. The software itself got installed relatively quickly after going through the short docs (perhaps because I had most of the dependencies like avahi etc already in place because of the Airfoil).</p>
<p>&nbsp;</p>
<p>Also, for Airfoil, I had already opened firewall to Zeroconf/Bonjour and ports <strong>TCP:5000-5005</strong> and <strong>UDP:6000-6005</strong>  which seemed to apply to Shairport too.</p>
<p>After starting up the daemon, all of our iTunes magically discovered the new remote speakers and allowed us to play music there with a simple mouse click. Even from Windows. And from iPhone. And, if wanted, all at the same time. Voila!</p>
<p>This is definitely much easier than messing with the wires all the time.</p>
<p>&nbsp;</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2012/01/25/turn-linux-into-a-remote-airplay-speaker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>desopafy Wikipedia</title>
		<link>http://blog.laaz.org/tech/2012/01/18/desopafy-wikipedia/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2012/01/18/desopafy-wikipedia/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 08:14:17 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Rest of the World]]></category>
		<category><![CDATA[SOPA]]></category>
		<category><![CDATA[wikipedia]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=405</guid>
		<description><![CDATA[Today Wikipedia has a blackout. This is because US is passing a law that can threaten open Internet. Please read all about the SOPA blackout in the Wikipedia article. I have signed a petition against SOPA and I am fully concerned &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2012/01/18/desopafy-wikipedia/">Read more &#187;</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Today Wikipedia has a blackout. This is because US is passing a law that can threaten open Internet.</p>
<p><img class="alignright" title="Wikipedia Blackout" src="http://upload.wikimedia.org/wikipedia/commons/9/98/WP_SOPA_Splash_Full.jpg" alt="" width="362" height="313" /></p>
<p>Please read all about the <a href="http://en.wikipedia.org/wiki/Wikipedia:SOPA_initiative/Learn_more">SOPA blackout in the Wikipedia article</a>. I have signed a petition against SOPA and I am fully concerned about what this could mean to Internet.</p>
<p>Wikipedia is main source of information for me and when googling around I hit Wikipedia dozens of times a day. I would not even like to think about what it would be like if Wikipedia would be blocked, because of linking to webpages that, among other things, contained some alleged pirated materials.</p>
<p>&nbsp;</p>
<h2>Now what?</h2>
<p>Having said all this and having already put in my 2 cents, I now have work to do and this blackout is hindering my progress, even if for just one day. Fortunately Wikipedia has not removed itself from Internet. It only has drawn a black blanket over it&#8217;s contents. So, after viewing this black page and dedicating a few (milli)seconds to think about the consequences of SOPA, tech-savvy people can still reach the articles and make use of them.</p>
<p><strong>NOTE</strong>: This post is <strong>not</strong> about avoiding Wikipedia blackout. This post is about getting work done, <strong>after</strong> you have signed some anti-SOPA petition or written a letter of concern to the US Senate or your own Ministry of Foreign Affairs if you live outside US.</p>
<h2>Desopafy</h2>
<p>There are several ways to still access Wikipedia today. Wikipedia itself has pointed out that mobile Wikipedia is still accessible and as the blackout is JavaScript-based, disabling JavaScript, will avoid the blackout too. But being JavaScript based, the blackout can also be reversed with JS. My initial code was a bit crude, so I googled around and found a more thorough version (thanks <a href="https://gist.github.com/timraymond">timraymond</a> and <a href="https://gist.github.com/kballenegger">kballenegger</a>). Add this link to your bookmarks (or drag it to your bookmark bar):</p>
<p><a style="border: 1px solid white; background-color: black; color: white; font-weight: bold; padding: 0.5em;" href="javascript:%24(%22%23mw-page-base%2C%20%23mw-head-base%2C%20%23content%2C%20%23mw-head%2C%20%23mw-panel%2C%20%23footer%22).css(%22display%22%2C%22inherit%22)%3B%24(%22%23mw-sopaOverlay%22).css(%22display%22%2C%22none%22)#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Desopafy_Wikipedia</a></p>
<p>This bookmarklet will hide the blackout and show the Wikipedia article. But please, do at least think of what this blackout means, before you remove it.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2012/01/18/desopafy-wikipedia/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gimp Resyntesize: remove unwanted objects from photos</title>
		<link>http://blog.laaz.org/tech/2011/10/17/gimp-resyntesize-remove-unwanted-objects-from-photos/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/10/17/gimp-resyntesize-remove-unwanted-objects-from-photos/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 08:13:02 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Rest of the World]]></category>
		<category><![CDATA[GIMP]]></category>
		<category><![CDATA[photo editing]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=391</guid>
		<description><![CDATA[Use open-source GIMP to remove unwanted objects from your photos.<p class="read-more"><a href="http://blog.laaz.org/tech/2011/10/17/gimp-resyntesize-remove-unwanted-objects-from-photos/">Read more &#187;</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Probably many of us have seen at least demos of using Photoshop to un-clutter your photos, resulting in almost unseemingly removed objects and restored background. While I won&#8217;t argue that Photoshop does excellent job at this, it is good to know that open-source GIMP this functionality too.</p>
<p>The GIMP <a title="GIMP Resynthesizer" href="http://registry.gimp.org/node/25219" target="_blank">Resynthesizer plugin</a> makes it easy to intelligently remove unwanted objects from photos. There seems to be a 2.0 version of this plugin available at the developer&#8217;s github page (<a href="https://github.com/bootchk/resynthesizer" target="_blank">bootchk/resynthesizer</a>), but I haven&#8217;t tried that yet.</p>
<p>How this plugin works has been covered number of times before, (e.g this <a title="Content-Aware Fill in GIMP" href="http://www.youtube.com/watch?v=6OOYnZyY2rs" target="_blank">&#8220;Content-Aware Fill&#8221; clip</a> or this <a href="http://www.hutsby.net/2010/04/howto-use-resynthesizer-for-gimp-on-osx.html" target="_blank">resynthesizer tutorial</a>), so I won&#8217;t go into details of this here.</p>
<p>Only difference for me was that I used the <code>Enchance &gt; Smart remove selection...</code> filter rather than <code>Map &gt; Resynthesize...</code> and the result is displayed below.</p>
<p><a href="http://blog.laaz.org/tech/wp-content/uploads/2011/10/Gimp_resynthesizer.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-393" title="GIMP Resynthesizer" src="http://blog.laaz.org/tech/wp-content/uploads/2011/10/Gimp_resynthesizer.png" alt="Using GIMP Resynthesizer to remove unwanted objects" width="560" height="420" /></a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/10/17/gimp-resyntesize-remove-unwanted-objects-from-photos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mail.app Gmail style related messages</title>
		<link>http://blog.laaz.org/tech/2011/09/06/mail-app-gmail-style-related-messages/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/09/06/mail-app-gmail-style-related-messages/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 16:22:32 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[Mail.app]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=383</guid>
		<description><![CDATA[Mac OS X Lion Mail.app has a ton of new features and not the least of them is the conversation view that makes it look much in like Gmail. Still, unlike Gmail, Mail.app by default shows only incoming conversation and &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2011/09/06/mail-app-gmail-style-related-messages/">Read more &#187;</a></p>
Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2009/11/16/location-aware-time-machine/' rel='bookmark' title='Location Aware Time Machine'>Location Aware Time Machine</a></li>
<li><a href='http://blog.laaz.org/tech/2010/11/09/address-book-groups/' rel='bookmark' title='Address Book groups'>Address Book groups</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Mac OS X Lion Mail.app has a ton of <a href="http://www.apple.com/macosx/whats-new/mail.html">new features</a> and not the least of them is the conversation view that makes it look much in like Gmail.</p>
<p>Still, unlike Gmail, Mail.app by default shows only incoming conversation and omits sent messages, unless one presses the &#8220;<em>Show related messages</em>&#8221; button.</p>
<p>Fortunately there is a preference option to turn this on constantly.</p>
<p><a href="http://blog.laaz.org/tech/wp-content/uploads/2011/09/Show-related-messages-1.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-388" title="Show related messages" src="http://blog.laaz.org/tech/wp-content/uploads/2011/09/Show-related-messages-1.png" alt="" width="552" height="506" /></a></p>
<p>Go to menu &#8220;Mail &gt; Preferences &gt; View&#8221; and check &#8220;<em>Include related messages</em>&#8221; box.</p>
<p>I wonder why this option is turned off by default?</p>
<p>Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2009/11/16/location-aware-time-machine/' rel='bookmark' title='Location Aware Time Machine'>Location Aware Time Machine</a></li>
<li><a href='http://blog.laaz.org/tech/2010/11/09/address-book-groups/' rel='bookmark' title='Address Book groups'>Address Book groups</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/09/06/mail-app-gmail-style-related-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Rack servers benchmark</title>
		<link>http://blog.laaz.org/tech/2011/08/25/ruby-rack-servers-benchmark/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/08/25/ruby-rack-servers-benchmark/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 11:18:23 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[thin]]></category>
		<category><![CDATA[unicorn]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=363</guid>
		<description><![CDATA[Facing the question which Ruby Rack server perform best behind Nginx front-end and failing to google out any exact comparison, I decided to do a quick test myself. The servers: Passenger 3.0.8 Unicorn 4.1.0 Thin 1.2.11 Later I tried to &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2011/08/25/ruby-rack-servers-benchmark/">Read more &#187;</a></p>
Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2009/07/09/railsvacation/' rel='bookmark' title='RailsVacation'>RailsVacation</a></li>
<li><a href='http://blog.laaz.org/tech/2010/04/27/ruby-lambda/' rel='bookmark' title='Ruby lambda'>Ruby lambda</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Facing the question which Ruby Rack server perform best behind Nginx front-end and failing to google out any exact comparison, I decided to do a quick test myself.</p>
<p>The servers:</p>
<ul>
<li><a href="http://modrails.com">Passenger</a> 3.0.8</li>
<li><a href="http://unicorn.bogomips.org/">Unicorn</a> 4.1.0</li>
<li><a href="http://code.macournoyer.com/thin/">Thin</a> 1.2.11</li>
</ul>
<p>Later I tried to test <a href="http://projects.unbit.it/uwsgi/">UWSGI</a> server too as it now boasts built-in RACK module, but dropped it for two reasons: <strong>(1)</strong> it required tweaking OS to raise <code>kern.ipc.somaxconn</code> above 128 (which none other server needed) and later Nginx&#8217;s <code>worker_connections</code> above 1024 too and <strong>(2)</strong> it still lagged far behind at ~ 130 req/s, so after successful concurrency of 1000 requests, I got tired of waiting for the tests to complete and gave up seeking it&#8217;s break point. Still, UWSGI is very interesting project that I will keep my eye on, mostly because of it&#8217;s <a href="http://projects.unbit.it/uwsgi/wiki/Emperor">Emperor</a> and <a href="http://projects.unbit.it/uwsgi/wiki/ZergMode">Zerg</a> modes and ease of deployment for dynamic mass-hosting Rack apps.</p>
<p>As UWSGI was originally developed for Python, I wasted a bit of time trying to get it working with some simple Python framework for comparison, but probably lack of knowledge on my part was the failure of it.</p>
<h2>Testing</h2>
<p>The test platform consisted of:</p>
<ul>
<li>MacBook Pro (dual Core i7 HT)</li>
<li><a href="http://nginx.net/">Nginx</a> 1.0.5</li>
<li><a href="http://jakarta.apache.org/jmeter/">JMeter</a> 2.4</li>
</ul>
<p>To set up a basic testcase, I wrote a simple Rack app that responds every request with the request IP address. I dediced to output IP because this involves some Ruby code in the app, but should be rather simple still.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ip = <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>env<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">200</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;Content-Type&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;text/plain&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#91;</span>env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;REMOTE_ADDR&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
run ip</pre></div></div>

<p>Tweaking the concurrency number N (see below) with resolution of 100, I found out the break point of each of the servers (when they started giving errors) and recorded the previous throughput (the one that didn&#8217;t give any errors).</p>
<h2>Results</h2>
<p>The results are as follows:</p>
<p><a href="http://blog.laaz.org/tech/wp-content/uploads/2011/08/ruby_servers_bench.001.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-376" title="ruby_servers_bench.001" src="http://blog.laaz.org/tech/wp-content/uploads/2011/08/ruby_servers_bench.001.png" alt="" width="614" height="461" /></a></p>
<ol>
<li>Unicorn &#8211; 2451 req/s @ 1500 concurrent request</li>
<li>Thin &#8211; 2102 req/s @ 900 concurrent requests</li>
<li>Passenger &#8211; 1549 req/s @ 400 concurrent requests</li>
</ol>
<p>The following are screenshots from JMeter results:</p>
<div id="attachment_371" class="wp-caption alignnone" style="width: 717px"><a href="http://blog.laaz.org/tech/wp-content/uploads/2011/08/nginx_unicorn-1500x10.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="size-full wp-image-371 " title="nginx_unicorn 1500x10" src="http://blog.laaz.org/tech/wp-content/uploads/2011/08/nginx_unicorn-1500x10.png" alt="" width="707" height="31" /></a><p class="wp-caption-text">Unicorn @1500 concurrent request</p></div>
<div id="attachment_365" class="wp-caption alignnone" style="width: 717px"><a href="http://blog.laaz.org/tech/wp-content/uploads/2011/08/nginx_thin-900x10.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="size-full wp-image-365 " title="nginx_thin 900x10" src="http://blog.laaz.org/tech/wp-content/uploads/2011/08/nginx_thin-900x10.png" alt="" width="707" height="33" /></a><p class="wp-caption-text">Thin @900 concurrent requests</p></div>
<div id="attachment_366" class="wp-caption alignnone" style="width: 719px"><a href="http://blog.laaz.org/tech/wp-content/uploads/2011/08/nginx_passenger-400x10.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="size-full wp-image-366 " title="nginx_passenger 400x10" src="http://blog.laaz.org/tech/wp-content/uploads/2011/08/nginx_passenger-400x10.png" alt="" width="709" height="32" /></a><p class="wp-caption-text">Passenger @400 concurrent requests</p></div>
<p>None of these throughputs are bad, but still Unicorn and Thin beat the crap out of Passenger.</p>
<p><span style="font-size: 20px; font-weight: bold;">Details</span></p>
<h3>The JMeter testcase</h3>
<ol>
<li>ramp up to N requests concurrently</li>
<li>send request to the server</li>
<li>assert that response contains IP address</li>
<li>loop all of this 10 times</li>
</ol>
<h3>Nginx configuration:</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;"># Passenger</span>
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      listen <span style="color: #000000;">8080</span>;
      server_name localhost;
      root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>public;
      passenger_enabled on;
      rack_env production;
      passenger_min_instances <span style="color: #000000;">4</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Unicorn</span>
    upstream unicorn_server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      server unix:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>unicorn.sock <span style="color: #007800;">fail_timeout</span>=<span style="color: #000000;">0</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      listen <span style="color: #000000;">8081</span>;
      server_name localhost;
      root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>public;
&nbsp;
      location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        proxy_pass http:<span style="color: #000000; font-weight: bold;">//</span>unicorn_server;
      <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Thin</span>
    upstream thin_server<span style="color: #7a0874; font-weight: bold;">&#123;</span>
      server unix:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>thin.0.sock <span style="color: #007800;">fail_timeout</span>=<span style="color: #000000;">0</span>;
      server unix:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>thin.1.sock <span style="color: #007800;">fail_timeout</span>=<span style="color: #000000;">0</span>;
      server unix:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>thin.2.sock <span style="color: #007800;">fail_timeout</span>=<span style="color: #000000;">0</span>;
      server unix:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>thin.3.sock <span style="color: #007800;">fail_timeout</span>=<span style="color: #000000;">0</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      listen <span style="color: #000000;">8082</span>;
      server_name localhost;
      root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>laas<span style="color: #000000; font-weight: bold;">/</span>proged<span style="color: #000000; font-weight: bold;">/</span>rack_test<span style="color: #000000; font-weight: bold;">/</span>public;
&nbsp;
      location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        proxy_pass http:<span style="color: #000000; font-weight: bold;">//</span>thin_server;
      <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>As is only logical, having processes match the number of cores (dual HT = 4 cores) gave best results for both Thin and Unicorn (thouch the variations were small).</p>
<h3>Unicorn configuration</h3>
<p>Passenger requires no additional configuration and Thin was configured from command line to use 4 servers and Unix sockets, but Unicorn required a separate file (I modified Unicorn example config for my purpose):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">worker_processes <span style="color:#006666;">4</span>
working_directory <span style="color:#996600;">&quot;/Users/laas/proged/rack_test/&quot;</span>
listen <span style="color:#996600;">'/Users/laas/proged/rack_test/tmp/unicorn.sock'</span>, <span style="color:#ff3333; font-weight:bold;">:backlog</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">512</span>
timeout <span style="color:#006666;">120</span>
pid <span style="color:#996600;">&quot;/Users/laas/proged/rack_test/tmp/pids/unicorn.pid&quot;</span>
&nbsp;
preload_app <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">GC</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:copy_on_write_friendly</span>=<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#CC00FF; font-weight:bold;">GC</span>.<span style="color:#9900CC;">copy_on_write_friendly</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h2>Disclaimer</h2>
<p>I admit that this is extremely basic test and with better configuration much can be squeezed out from all of these servers, but this simple test surved my purpose and hopefully is of help to others too.</p>
<p>Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2009/07/09/railsvacation/' rel='bookmark' title='RailsVacation'>RailsVacation</a></li>
<li><a href='http://blog.laaz.org/tech/2010/04/27/ruby-lambda/' rel='bookmark' title='Ruby lambda'>Ruby lambda</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/08/25/ruby-rack-servers-benchmark/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>git terminal graph with branch names</title>
		<link>http://blog.laaz.org/tech/2011/08/24/git-terminal-graph-with-branch-names/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/08/24/git-terminal-graph-with-branch-names/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 11:34:10 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=353</guid>
		<description><![CDATA[I have searched several times how to produce graph tree in terminal similar to Gitk or other GUI visualizers. Compiling the knowledge in this StackOverflow question together, I came up with the following command: git log --graph --full-history --all --color &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2011/08/24/git-terminal-graph-with-branch-names/">Read more &#187;</a></p>
Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2009/07/09/railsvacation/' rel='bookmark' title='RailsVacation'>RailsVacation</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I have searched several times how to produce graph tree in terminal similar to Gitk or other GUI visualizers. Compiling the knowledge in <a href="http://stackoverflow.com/questions/1838873/visualizing-branch-topology-in-git">this StackOverflow</a> question together, I came up with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> log <span style="color: #660033;">--graph</span> <span style="color: #660033;">--full-history</span> <span style="color: #660033;">--all</span> <span style="color: #660033;">--color</span> <span style="color: #660033;">--date</span>=short <span style="color: #660033;">--pretty</span>=format:<span style="color: #ff0000;">&quot;%x1b[31m%h%x09%x1b[0m%x20%ad%x1b[32m%d%x1b[0m %s %x1b[30m(%an)%x1b[0m&quot;</span></pre></div></div>

<p><strong>UPDATE</strong>: I added annotation to the end of line in dark-grey (not shown in the image) so that you can blame people quicker.</p>
<p>This produces graph shown on the image.</p>
<div id="attachment_359" class="wp-caption alignnone" style="width: 532px"><a href="http://blog.laaz.org/tech/wp-content/uploads/2011/08/git_tree2.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="size-full wp-image-359 " title="git_tree" src="http://blog.laaz.org/tech/wp-content/uploads/2011/08/git_tree2.png" alt="GIT graph in terminal" width="522" height="134" /></a><p class="wp-caption-text">GIT graph in terminal with branch names</p></div>
<p>If you noticed, I have aliased all of this for a much shorter command <code>git tree</code>, which can be done with the following <code>git config</code> line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> alias.tree <span style="color: #ff0000;">'log --graph --full-history --all --color --date=short --pretty=format:&quot;%x1b[31m%h%x09%x1b[0m%x20%ad%x1b[32m%d%x1b[0m %s %x1b[30m(%an)%x1b[0m&quot;'</span></pre></div></div>

<p>Notice the two sets of quatation marks.</p>
<p>Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2009/07/09/railsvacation/' rel='bookmark' title='RailsVacation'>RailsVacation</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/08/24/git-terminal-graph-with-branch-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brolog is now CommitBlog</title>
		<link>http://blog.laaz.org/tech/2011/08/23/brolog-is-now-commitblog/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/08/23/brolog-is-now-commitblog/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 14:13:48 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=351</guid>
		<description><![CDATA[Today I woke up with a new name for my blog. It is now known as CommitBlog. Simple as that. The why When starting something new, there is always the problem with the name. The worst part is that, most &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2011/08/23/brolog-is-now-commitblog/">Read more &#187;</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Today I woke up with a new name for my blog. It is now known as <strong>CommitBlog</strong>.</p>
<p>Simple as that.</p>
<h2><strong>The why</strong></h2>
<p>When starting something new, there is always the problem with the name. The worst part is that, most of the time, you need to come up with a name just in the middle of creation and when you least know, whether the beast will walk, swim or fly. And the name sticks. And sometimes the name stinks too. After some initial moments, I never really liked the name Brolog (being not-so-clever wordplay on Prolog and Blog). Given that I have never actually seen Prolog in action and know nothing of the language it seemed a bit false. So today I woke up and had a new name, that relates more to what I do daily &#8211; commit to GIT. Or write to commitlog if you will.</p>
<p>So. There you have it. CommitBlog.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/08/23/brolog-is-now-commitblog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inkscape CSV merge</title>
		<link>http://blog.laaz.org/tech/2011/08/10/inkscape-csv-merge/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/08/10/inkscape-csv-merge/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 23:17:04 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[inkscape]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=345</guid>
		<description><![CDATA[Merge SVG files with CSV file using Inkscape<p class="read-more"><a href="http://blog.laaz.org/tech/2011/08/10/inkscape-csv-merge/">Read more &#187;</a></p>
Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2007/08/19/aardwolf-kill-script/' rel='bookmark' title='Aardwolf kill script'>Aardwolf kill script</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I just uploaded <a href="https://github.com/borgand/inkscape_merge">inkscape_merge</a> gem v0.1.0.</p>
<p>This is a script to merge SVG files with CSV data-files using Inkscape, to produce one outputfile (e.g. PDF) per data-row.</p>
<p>Script inspired by and based on Aurélio A. Heckert excellent InkscapeGenerator (<a href="http://wiki.colivre.net/Aurium/InkscapeGenerator">wiki.colivre.net/Aurium/InkscapeGenerator</a>)</p>
<p>Heckert’s original script unfortunately broke for me several times and I took the opportunity to rewrite it and make it more extendable for future.</p>
<p>&nbsp;</p>
<h1>USAGE</h1>
<h2>Install the gem</h2>
<pre>gem install inkscape_merge</pre>
<h2>Create files</h2>
<p>Create CSV data file with first row as a header. The values from this row are used as keys in the SVG file substitution.</p>
<p>Create SVG file that contains some variables in the form:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>VAR_name<span style="color: #000000; font-weight: bold;">%</span></pre></div></div>

<p>Where `name` is the name of a column in the CSV file created previously. These variables can be anywhere inside the SVG, from plain text nodes to color values. This script just brute-forcedly `gsubs` these values as text w/o any thought.</p>
<h2>Run the script</h2>
<p>The script requires at least three arguments:</p>
<ul>
<li>the input SVG file</li>
<li>the input CSV file</li>
<li>and the output file `pattern`</li>
</ul>
<p>Note: output pattern undergoes the same substitutions as the SVG file, so to create easily unique file names. Additionally the output pattern can contain `%d` which is replaced with current row number.</p>
<p>Example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">inkscape_merge <span style="color: #660033;">-f</span> postcard.svg <span style="color: #660033;">-d</span> names.csv <span style="color: #660033;">-o</span> postcards<span style="color: #000000; font-weight: bold;">/</span>card_<span style="color: #000000; font-weight: bold;">%</span>d.pdf</pre></div></div>

<p>This produces files like:</p>
<ul>
<li>postcards/
<ul>
<li>card_1.pdf</li>
<li>card_2.pdf</li>
</ul>
</li>
</ul>
<p>Related posts:<ol>
<li><a href='http://blog.laaz.org/tech/2007/08/19/aardwolf-kill-script/' rel='bookmark' title='Aardwolf kill script'>Aardwolf kill script</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/08/10/inkscape-csv-merge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MacFuse and Mac OS X Lion</title>
		<link>http://blog.laaz.org/tech/2011/07/23/macfuse-and-mac-os-x-lion/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/07/23/macfuse-and-mac-os-x-lion/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 18:37:42 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[macfuse]]></category>
		<category><![CDATA[macfusion]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=340</guid>
		<description><![CDATA[Now that I have upgraded to Mac OS X Lion, I found that MacFusion does not work. Before diving into a workaround as back in Snow Leopard days I remembered that then it was because of MacFuse and even that &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2011/07/23/macfuse-and-mac-os-x-lion/">Read more &#187;</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Now that I have upgraded to Mac OS X Lion, I found that MacFusion does not work. Before diving into a <a href="http://blog.laaz.org/tech/2010/04/13/macfusion-workaround/#more-249#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">workaround as back in Snow Leopard</a> days I remembered that then it was because of MacFuse and even that time there turned out to be a build floating around the web that would have worked. As is the case now.</p>
<p><a href="https://oxygen.zendesk.com/entries/466509-installation-on-mac-osx-10-7-lion">This forum</a> listed one of them that got it working for me - <a href="http://www.tuxera.com/mac/macfuse-core-10.5-2.1.9.dmg">macfuse-core-10.5-2.1.9.dmg</a>.</p>
<p>Though, <a href="http://www.offthehill.org/articles/2011/07/21/macfuse-for-os-x-lion/">pardsbane here</a> tells of another project &#8211; <a href="https://github.com/osxfuse">OSXFUSE</a> &#8211; one the way that will support Lion out of the box (when the box is released).</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/07/23/macfuse-and-mac-os-x-lion/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP site root</title>
		<link>http://blog.laaz.org/tech/2011/03/29/php_site_root/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.laaz.org/tech/2011/03/29/php_site_root/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 13:05:43 +0000</pubDate>
		<dc:creator>Laas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[site root]]></category>
		<category><![CDATA[wwwroot]]></category>

		<guid isPermaLink="false">http://blog.laaz.org/tech/?p=336</guid>
		<description><![CDATA[How to get the root of your site, regardless of the folder depth of your script while taking into account any Aliases your webserver might have? Say, for example, that you have in your apache conf the following lines: DocumentRoot &#8230;<p class="read-more"><a href="http://blog.laaz.org/tech/2011/03/29/php_site_root/">Read more &#187;</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>How to get the <strong>root of your site,</strong> regardless of the folder depth of your script while taking into account any <em>Aliases</em> your webserver might have?</p>
<p>Say, for example, that you have in your apache conf the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">  <span style="color: #00007f;">DocumentRoot</span> /var/www/htdocs
  <span style="color: #00007f;">Alias</span> /phpsite /var/www/mysite</pre></div></div>

<p>That means that your PHP site resides in <em>/var/www/mysite</em>, while rest of your web resides in <em>/var/www/htdocs</em>. How will your PHP scripts know that <strong>/phpsite</strong> portion, without hardcoding this into scripts, when they do not know how many levels deep in directory structure they themselves are in your site (e.g /phpsite/posts/update.php).</p>
<p><strong>First</strong>, if you already don&#8217;t have, create a script (call it what ever you like, e.g. <strong>config.php</strong>) somewhere in your site folder. Preferred is at the top level, but subfolders work too (more on this later).</p>
<p><strong>Secondly,</strong> put the following inside that file:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$wwwroot</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span>
      <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span>
        <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span>
          <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
          <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you placed your config.php in some <strong>subfolder</strong>, then you have to multiply the <strong>dirname()</strong> calls for every subfolder level. E.g if your config.php is in conf/config.php, i.e second level, you need 2 dirname() calls and your 4th line should look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>Third</strong>, include this file in every script, even in subfolders and prepend to links:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;../config.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=&quot;</span><span style="color: #000088;">$wwwroot</span><span style="color: #339933;">/</span>some<span style="color: #339933;">/</span>script<span style="color: #339933;">.</span>php<span style="color: #0000ff;">&quot;&gt;Some script&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Voila!</p>
<h2>Under the hood</h2>
<p>What this script does is actually rather simple string algebra. The contents of those special variable is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span>
    <span style="color: #666666; font-style: italic;"># =&gt; example.com
</span><span style="color: #009900; font-weight: bold;">__FILE__</span>
    <span style="color: #666666; font-style: italic;"># =&gt; /var/www/mysite/config.php - the name of the script where this is written
</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span>
    <span style="color: #666666; font-style: italic;"># =&gt; /var/www/mysite/dir/script.php - the full path to script that included config.php
</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span>
    <span style="color: #666666; font-style: italic;"># =&gt; /phpsite/dir/script.php - the URL path of the script that included config.php</span></pre></div></div>

<p>You might already start to grasp what we&#8217;re about to do. Leaving aside the obvious hostname part, what the <em>str_replace</em> part does is the following:</p>
<ol>
<li>calculate filesystem path to the base of the site: dirname(__FILE__): <em>/var/www/mysite/config.php =&gt; /var/www/mysite</em></li>
<li>substract this path from the SCRIPT_FILENAME =&gt; <em>/var/www/mysite/dir/script.php =&gt; /<em>dir/script.php</em></em></li>
<li>substract the result from the URL SCRIPT_NAME =&gt; <em>/phpsite/dir/script.php =&gt; /phpsite</em></li>
</ol>
<p>This method works even if you change the Alias or remove it altogether.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.laaz.org/tech/2011/03/29/php_site_root/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

