<?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>Mats Lindh &#187; Programming</title>
	<atom:link href="http://e-mats.org/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://e-mats.org</link>
	<description>Where desperate is just another word for a regular day.</description>
	<lastBuildDate>Fri, 23 Jul 2010 14:23:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Unbreak My Hea.. Firefox Ctrl Click Please!</title>
		<link>http://e-mats.org/2010/03/unbreak-my-hea-firefox-ctrl-click-please/</link>
		<comments>http://e-mats.org/2010/03/unbreak-my-hea-firefox-ctrl-click-please/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 21:57:34 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ctrl click]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[stoppropagation]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=765</guid>
		<description><![CDATA[When we launched Gamer.no over a year ago, we had to come up with a wallpaper advertising solution in a rush (everything were a rush back then as we built and launched a site from scratch (after disagreements between the previous owner and Gamer) in just under four days (or 96 hours)). While this solution [...]]]></description>
			<content:encoded><![CDATA[<p>When we launched Gamer.no over a year ago, we had to come up with a wallpaper advertising solution in a rush (everything were a rush back then as we built and launched a site from scratch (after disagreements between the previous owner and Gamer) in just under four days (or 96 hours)). While this solution has worked .. good enough .. it has always had a few irky bugs that I&#8217;ve never really had the right inspiration to uncover the cause of. Usually I&#8217;ve spent an hour and decided that the time wasn&#8217;t worth it at the moment and then moved onto something else, but today! Today is a glorious day! </p>
<p>The bug has been fixed!</p>
<p>The wallpaper element is placed around the main content div, which sadly also makes the wallpaper element receive any click elements that the main content div receives. This leads to the wallpaper getting clicked and the wallpaper ad window opening regardless of where people click &#8211; which will get very, very annoying very quick. So to battle this issue the original solution was to call <code>.stopPropagation()</code> on the evt object in a click handler for the main content div. This solved the issue and everyone rejoiced! However, all was not perfect in paradise.</p>
<p>Some time later we discovered that the .stopPropagation() fix borked ctrl-click a link in Firefox. Other browsers handled it just fine, but Firefox were obviously not happy. Not happy at all. Mad and going on a killing spree it shot down the proposed fixes from both myself and other people who had a brief look at the code. It wasn&#8217;t a big issue as we only run the wallpaper code for small intervals of time and people didn&#8217;t complain (maybe we were some of the few who had the issue).</p>
<p>Today I decided to have a look at the issue again, and finally I realized that we had been way to focused on our call to <code>.stopPropagation()</code>. Everyone had been planning how we could get .stopPropagation to do what we wanted it to do &#8211; after all &#8211; the issue was that stopPropagation didn&#8217;t behave when we ctrl-clicked in Firefox. But wait.</p>
<p>If you instead think of the original problem; the window.open gets triggered when people click the inner element instead of the outer, there may be alternative solutions to using stopPropagation. And yes, THAT was quite a simple fix. Instead of trying to stop the event from bubling up through the cloud.. let&#8217;s just set a status variable that tells the code handling the wallpaper click that THIS CLICK IS NOT FOR YOU BAD HANDLER GO AWAY LET OTHER GROWNUPS HANDLE THIS. So that I did.</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; innerClick = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#39;#wallpaper&#39;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>innerClick<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; innerClick = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; window.<span class="kw3">open</span><span class="br0">&#40;</span><span class="st0">&quot;..&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#39;#content&#39;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>evt<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; innerClick = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>As soon as I actually spent some time on what we were trying to solve instead of what seemed like the cause of the issue .. everything went better than expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/03/unbreak-my-hea-firefox-ctrl-click-please/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing Issue With PHPs SoapClient Overwriting Duplicate Attribute and Tag Names</title>
		<link>http://e-mats.org/2010/02/fixing-issue-with-phps-soapclient-overwriting-duplicate-attribute-and-tag-names/</link>
		<comments>http://e-mats.org/2010/02/fixing-issue-with-phps-soapclient-overwriting-duplicate-attribute-and-tag-names/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 13:48:59 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[soapclient]]></category>
		<category><![CDATA[subclassing]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=750</guid>
		<description><![CDATA[The setting: An SOAP request contains an Id attribute &#8211; and an element with the exact name in the response (directly beneath the element containing the attribute &#8211; an immediate child): &#60;res z:Id=&#34;i123&#34;&#62; &#160; &#60;Id&#62;foobar&#60;/Id&#62; &#60;/res&#62; The problem is that the generated result object from the SoapClient (at least of PHP 5.2.12) contains the attribute [...]]]></description>
			<content:encoded><![CDATA[<p>The setting:</p>
<p>An SOAP request contains an Id attribute &#8211; and an element with the exact name in the response (directly beneath the element containing the attribute &#8211; an immediate child):</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;res</span> <span class="re0">z:Id</span>=<span class="st0">&quot;i123&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Id<span class="re2">&gt;</span></span></span>foobar<span class="sc3"><span class="re1">&lt;/Id<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/res<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>The problem is that the generated result object from the SoapClient (at least of PHP 5.2.12) contains the attribute value, and not the element value. In our case we could ignore the z:Id attribute, as it was simply an Id to identify the element in the response (this might be something that ASP.NET or some other .NET component does).</p>
<p>Our solution is to subclass the internal SoapClient and handle the <em>__doRequest</em> method, stripping out the part of the request that gives the wrong value for the Id field:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Provider_SoapClient <span class="kw2">extends</span> SoapClient</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __doRequest<span class="br0">&#40;</span><span class="re1">$request</span><span class="sy0">,</span> <span class="re1">$location</span><span class="sy0">,</span> <span class="re1">$action</span><span class="sy0">,</span> <span class="re1">$version</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> parent<span class="sy0">::</span>__doRequest<span class="br0">&#40;</span><span class="re1">$request</span><span class="sy0">,</span> <span class="re1">$location</span><span class="sy0">,</span> <span class="re1">$action</span><span class="sy0">,</span> <span class="re1">$version</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st0">&#39;/ z:Id=&quot;i[0-9]+&quot;/&#39;</span><span class="sy0">,</span> <span class="st0">&#39;&#39;</span><span class="sy0">,</span> <span class="re1">$result</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re1">$result</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This removes the attribute from all the values (there is no danger that the string will be present in any other of the elements. If there is &#8211; be sure to adjust the regular expression). And voilá, it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/02/fixing-issue-with-phps-soapclient-overwriting-duplicate-attribute-and-tag-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoid Escaping Spaces in the Query String in a Solr Query</title>
		<link>http://e-mats.org/2010/01/avoid-escaping-spaces-in-the-query-string-in-a-solr-query/</link>
		<comments>http://e-mats.org/2010/01/avoid-escaping-spaces-in-the-query-string-in-a-solr-query/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 22:24:14 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[escaping]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[spaces]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=744</guid>
		<description><![CDATA[Following up on the previous post about escaping values in a Solr query string, it&#8217;s important to note that you should not escape spaces in the query itself. The reason for this is that if you escape spaces in the query &#8220;foo bar&#8221;, the search will be performed on the term &#8220;foo bar&#8221; itself, and [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on <a href="http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/">the previous post about escaping values in a Solr query string</a>, it&#8217;s important to note that you should not escape spaces in the query itself. The reason for this is that if you escape spaces in the query &#8220;foo bar&#8221;, the search will be performed on the term &#8220;foo bar&#8221; itself, and not with &#8220;foo&#8221; as one term and &#8220;bar&#8221; as the other. This will only return documents that has the string &#8220;foo bar&#8221; in sequence.</p>
<p>The solution is to either remove the space from the escape list in the previous function &#8211; and use another function for escaping values where you actually should escape the spaces &#8211; or break up the string into &#8220;escapable&#8221; parts.</p>
<p>The code included beneath performs the last task; it splits the string into different parts delimited by space and then escapes each part of the query by itself.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$queryParts</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&#39; &#39;</span><span class="sy0">,</span> <span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">getQuery</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$queryEscaped</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$queryParts</span> <span class="kw1">as</span> <span class="re1">$queryPart</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$queryEscaped</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> self<span class="sy0">::</span><span class="me2">escapeSolrValue</span><span class="br0">&#40;</span><span class="re1">$queryPart</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$queryEscaped</span> <span class="sy0">=</span> <span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39; &#39;</span><span class="sy0">,</span> <span class="re1">$queryEscaped</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/avoid-escaping-spaces-in-the-query-string-in-a-solr-query/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Simple Smarty Modifier to Generate a Chart Through Google Chart API</title>
		<link>http://e-mats.org/2010/01/a-simple-smarty-modifier-to-generate-a-chart-through-google-chart-api/</link>
		<comments>http://e-mats.org/2010/01/a-simple-smarty-modifier-to-generate-a-chart-through-google-chart-api/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 22:48:55 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[google chart]]></category>
		<category><![CDATA[google chart api]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=739</guid>
		<description><![CDATA[After the longest title of my blog so far follows one of the shortest posts. The function has two required parameters &#8211; the first one is provided automagically for you by smarty (it&#8217;s the value of the variable you&#8217;re applying the modifier to). This should be an array of objects containing the value you want [...]]]></description>
			<content:encoded><![CDATA[<p>After the longest title of my blog so far follows one of the shortest posts.</p>
<p>The function has two required parameters &#8211; the first one is provided automagically for you by smarty (it&#8217;s the value of the variable you&#8217;re applying the modifier to). This should be an array of objects containing the value you want to graph. The only required argument you have to provide to the modifier is the method to use for fetching the values for graphing. </p>
<p>Usage:<br />
{$objects|googlechart:&#8221;getValue&#8221;}</p>
<p>This will dynamically load your plugin from the file modifier.googlechart.php in your Smarty plugins directory, or you can register the plugin manually by calling register_modifier on the template object after you&#8217;ve created it.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> smarty_modifier_googlechart<span class="br0">&#40;</span><span class="re1">$points</span><span class="sy0">,</span> <span class="re1">$method</span><span class="sy0">,</span> <span class="re1">$size</span> <span class="sy0">=</span> <span class="st0">&quot;600&#215;200&quot;</span><span class="sy0">,</span> <span class="re1">$low</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re1">$high</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$pointStr</span> <span class="sy0">=</span> <span class="st0">&#39;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$maxValue</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$minValue</span> <span class="sy0">=</span> INT_MAX<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$points</span> <span class="kw1">as</span> <span class="re1">$point</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="re1">$maxValue</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$maxValue</span> <span class="sy0">=</span> <span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&lt;</span> <span class="re1">$minValue</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$minValue</span> <span class="sy0">=</span> <span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re1">$high</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$maxValue</span> <span class="sy0">=</span> <span class="re1">$high</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$scale</span> <span class="sy0">=</span> <span class="nu0">100</span> <span class="sy0">/</span> <span class="re1">$maxValue</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$points</span> <span class="kw1">as</span> <span class="re1">$point</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$pointStr</span> <span class="sy0">.=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="re1">$scale</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st0">&#39;,&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$pointStr</span> <span class="sy0">=</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re1">$pointStr</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">-1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// labels (5)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$labels</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$steps</span> <span class="sy0">=</span> <span class="nu0">4</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$interval</span> <span class="sy0">=</span> <span class="re1">$maxValue</span> <span class="sy0">/</span> <span class="re1">$steps</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re1">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="re1">$i</span> <span class="sy0">&lt;</span> <span class="re1">$steps</span><span class="sy0">;</span> <span class="re1">$i</span><span class="sy0">++</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$labels</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="re1">$i</span> <span class="sy0">*</span> <span class="re1">$interval</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$labels</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="re1">$maxValue</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&#39;http://chart.apis.google.com/chart?cht=lc&amp;amp;chd=t:&#39;</span> <span class="sy0">.</span> <span class="re1">$pointStr</span> <span class="sy0">.</span> <span class="st0">&#39;&amp;amp;chs=&#39;</span> <span class="sy0">.</span> <span class="re1">$size</span> <span class="sy0">.</span> <span class="st0">&#39;&amp;amp;chxt=y&amp;amp;chxl=0:|&#39;</span> <span class="sy0">.</span> <span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39;|&#39;</span><span class="sy0">,</span> <span class="re1">$labels</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The function does not support the short version of the Google Chart API Just Yet &#8482; as it is an simple proof of concept hack made a few months ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/a-simple-smarty-modifier-to-generate-a-chart-through-google-chart-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Dismantle An Atomic HTTP Query .. String.</title>
		<link>http://e-mats.org/2010/01/how-to-dismantle-an-atomic-http-query-string/</link>
		<comments>http://e-mats.org/2010/01/how-to-dismantle-an-atomic-http-query-string/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 20:48:40 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[dots]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[http_dismantle_query]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[underscores]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=737</guid>
		<description><![CDATA[Following up on yesterday&#8217;s gripe about PHPs (old and now useless) automagic translation of dots in GET and POST parameters to underscores, today&#8217;s edition manipulates the query string in place instead of returning it as an array. This is useful if you have a query string you want to pass on to another service, and [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on <a href="/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/">yesterday&#8217;s gripe about PHPs (old and now useless) automagic translation of dots in GET and POST parameters to underscores</a>, today&#8217;s edition manipulates the query string in place instead of returning it as an array.</p>
<p>This is useful if you have a query string you want to pass on to another service, and for some reason the default behaviour in PHP will barf barf and barf. That might happen because of the dot translation issue or that some services (such as Solr) rely on a parameter name being repeatable (in PHP the second parameter value will overwrite the first).</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> http_dismantle_query<span class="br0">&#40;</span><span class="re1">$queryString</span><span class="sy0">,</span> <span class="re1">$remove</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$removeKeys</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">is_array</span><span class="br0">&#40;</span><span class="re1">$remove</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$remove</span> <span class="kw1">as</span> <span class="re1">$removeKey</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$removeKeys</span><span class="br0">&#91;</span><span class="re1">$removeKey</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$removeKeys</span><span class="br0">&#91;</span><span class="re1">$remove</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$resultEntries</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$segments</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&quot;&amp;&quot;</span><span class="sy0">,</span> <span class="re1">$queryString</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$segments</span> <span class="kw1">as</span> <span class="re1">$segment</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$parts</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&#39;=&#39;</span><span class="sy0">,</span> <span class="re1">$segment</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$key</span> <span class="sy0">=</span> <span class="kw3">urldecode</span><span class="br0">&#40;</span><span class="kw3">array_shift</span><span class="br0">&#40;</span><span class="re1">$parts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re1">$removeKeys</span><span class="br0">&#91;</span><span class="re1">$key</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$resultEntries</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re1">$segment</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39;&amp;&#39;</span><span class="sy0">,</span> <span class="re1">$resultEntries</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I&#8217;m not really sure what I&#8217;ll call the next function in this series, but there sure are loads of candidates out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/how-to-dismantle-an-atomic-http-query-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Dots to Work in PHP and GET / POST / COOKIE Variable Names</title>
		<link>http://e-mats.org/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/</link>
		<comments>http://e-mats.org/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 22:22:21 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[dots]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[request variables]]></category>
		<category><![CDATA[underscore]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=735</guid>
		<description><![CDATA[One of the oldest and ugliest relics of the register_globals era of PHP are the fact that all dots in request variable names gets replaced with &#8220;_&#8221;. If your variable was named &#8220;foo.bar&#8221;, PHP will serve it to you as &#8220;foo_bar&#8221;. You cannot turn this off, you cannot use extract() or parse_str() to avoid it [...]]]></description>
			<content:encoded><![CDATA[<p>One of the oldest and ugliest relics of the register_globals era of PHP are the fact that all dots in <a href="http://no.php.net/manual/en/language.variables.external.php">request variable names gets replaced with &#8220;_&#8221;</a>. If your variable was named &#8220;foo.bar&#8221;, PHP will serve it to you as &#8220;foo_bar&#8221;. You cannot turn this off, you cannot use extract() or parse_str() to avoid it and you&#8217;re mostly left out in the dark. Luckily the QUERY_STRING enviornment (in _SERVER if you&#8217;re running mod_php, etc) contains the raw string, and this string contains the dots.</p>
<p>The following &#8220;&#8221;parser&#8221;" is a work in progress and does currently not support the array syntax for keys that PHP allow, but it solves the issue for regular vars. I will try to extend this later on to do actually replicate the functionality of the regular parser.</p>
<p>Here&#8217;s the code. No warranties. Ugly hack. You&#8217;re warned. Leave a comment if you have any good suggestions regarding this (.. or know of an existing library doing the same..).</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> http_demolish_query<span class="br0">&#40;</span><span class="re1">$queryString</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$segments</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&quot;&amp;&quot;</span><span class="sy0">,</span> <span class="re1">$queryString</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$segments</span> <span class="kw1">as</span> <span class="re1">$segment</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$parts</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&#39;=&#39;</span><span class="sy0">,</span> <span class="re1">$segment</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$key</span> <span class="sy0">=</span> <span class="kw3">urldecode</span><span class="br0">&#40;</span><span class="kw3">array_shift</span><span class="br0">&#40;</span><span class="re1">$parts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$value</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$parts</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$value</span> <span class="sy0">=</span> <span class="kw3">urldecode</span><span class="br0">&#40;</span><span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39;=&#39;</span><span class="sy0">,</span> <span class="re1">$parts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span><span class="br0">&#91;</span><span class="re1">$key</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re1">$value</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="re1">$result</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>(OK, that&#8217;s not the real function name, but it&#8217;s aptly named to be the nemesis of <a href="http://no.php.net/http_build_query">http_build_query</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving URLs in Parallel With CURL and PHP</title>
		<link>http://e-mats.org/2010/01/retrieving-urls-in-parallel-with-curl-and-php/</link>
		<comments>http://e-mats.org/2010/01/retrieving-urls-in-parallel-with-curl-and-php/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 10:00:50 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[fetching]]></category>
		<category><![CDATA[footo]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[php_curl]]></category>
		<category><![CDATA[retrieving]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=724</guid>
		<description><![CDATA[As we&#8217;ve recently added support for querying Solr servers in parallel, one of the things we added was a simple class to allow us to query several servers at the same time. The CURL library (which has a PHP extension) even provides an abstraction layer for doing the nitty gritty work for you, as long [...]]]></description>
			<content:encoded><![CDATA[<p>As we&#8217;ve recently added support for querying Solr servers in parallel, one of the things we added was a simple class to allow us to query several servers at the same time. The CURL library (which <a href="http://no.php.net/curl">has a PHP extension</a>) even provides an abstraction layer for doing the nitty gritty work for you, as long as you keep track of the resources. The code beneath is based on examples in the documentation and a few tweaks of my own.</p>
<p>The code beneath is licensed <a href="http://en.wikipedia.org/wiki/MIT_License">under a MIT license</a>. You can also <a href="/resources/Footo_Content_Retrieve_HTTP_CURLParallel.php.gz">download the file</a> (gzipped).</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Footo_Content_Retrieve_HTTP_CURLParallel</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Fetch a collection of URLs in parallell using cURL. The results are</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* returned as an associative array, with the URLs as the key and the</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* content of the URLs as the value.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* @param array&lt;string&gt; $addresses An array of URLs to fetch.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* @return array&lt;string&gt; The content of each URL that we&#39;ve been asked to fetch.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;**/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> retrieve<span class="br0">&#40;</span><span class="re1">$addresses</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$multiHandle</span> <span class="sy0">=</span> curl_multi_init<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$handles</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$results</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$addresses</span> <span class="kw1">as</span> <span class="re1">$url</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$handle</span> <span class="sy0">=</span> curl_init<span class="br0">&#40;</span><span class="re1">$url</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$handles</span><span class="br0">&#91;</span><span class="re1">$url</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re1">$handle</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt_array<span class="br0">&#40;</span><span class="re1">$handle</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_HEADER <span class="sy0">=&gt;</span> <span class="kw2">false</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CURLOPT_RETURNTRANSFER <span class="sy0">=&gt;</span> <span class="kw2">true</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_multi_add_handle<span class="br0">&#40;</span><span class="re1">$multiHandle</span><span class="sy0">,</span> <span class="re1">$handle</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//execute the handles</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> CURLM_CALL_MULTI_PERFORM<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$running</span> <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// set up and make any requests..</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re1">$result</span> <span class="sy0">==</span> CURLM_CALL_MULTI_PERFORM<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> curl_multi_exec<span class="br0">&#40;</span><span class="re1">$multiHandle</span><span class="sy0">,</span> <span class="re1">$running</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// wait until data arrives on all sockets</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span><span class="br0">&#40;</span><span class="re1">$running</span> <span class="sy0">&amp;&amp;</span> <span class="br0">&#40;</span><span class="re1">$result</span> <span class="sy0">==</span> CURLM_OK<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>curl_multi_select<span class="br0">&#40;</span><span class="re1">$multiHandle</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="nu0">-1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> CURLM_CALL_MULTI_PERFORM<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// while we need to process sockets</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re1">$result</span> <span class="sy0">==</span> CURLM_CALL_MULTI_PERFORM<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> curl_multi_exec<span class="br0">&#40;</span><span class="re1">$multiHandle</span><span class="sy0">,</span> <span class="re1">$running</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// clean up</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$handles</span> <span class="kw1">as</span> <span class="re1">$url</span> <span class="sy0">=&gt;</span> <span class="re1">$handle</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$results</span><span class="br0">&#91;</span><span class="re1">$url</span><span class="br0">&#93;</span> <span class="sy0">=</span> curl_multi_getcontent<span class="br0">&#40;</span><span class="re1">$handle</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_multi_remove_handle<span class="br0">&#40;</span><span class="re1">$multiHandle</span><span class="sy0">,</span> <span class="re1">$handle</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curl_close<span class="br0">&#40;</span><span class="re1">$handle</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; curl_multi_close<span class="br0">&#40;</span><span class="re1">$multiHandle</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re1">$results</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="/resources/Footo_Content_Retrieve_HTTP_CURLParallel.php.gz">Download the file</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/retrieving-urls-in-parallel-with-curl-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java and NetBeans: Illegal escape character</title>
		<link>http://e-mats.org/2010/01/java-and-netbeans-illegal-escape-character/</link>
		<comments>http://e-mats.org/2010/01/java-and-netbeans-illegal-escape-character/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 10:00:32 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[defining]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[escaping]]></category>
		<category><![CDATA[illegal escape character]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=720</guid>
		<description><![CDATA[When defining strings in programming languages, they&#8217;re usually delimited by &#8221; and &#8220;, such as &#8220;This is a string&#8221; and &#8220;Hello World&#8221;. The immediate question is what do you do when the string itself should contain a &#8220;? &#8220;Hello &#8220;World&#8221;" is hard to read and practically impossible to parse for the compiler (which tries to [...]]]></description>
			<content:encoded><![CDATA[<p>When defining strings in programming languages, they&#8217;re usually delimited by &#8221; and &#8220;, such as &#8220;This is a string&#8221; and &#8220;Hello World&#8221;. The immediate question is what do you do when the string itself should contain a &#8220;? &#8220;Hello &#8220;World&#8221;" is hard to read and practically impossible to parse for the compiler (which tries to make sense out of everything you&#8217;ve written). To solve this (and similiar issues) people started using escape characters, special characters that tell the parser that it should pay attention to the following character(s) (some escape sequences may contain more than one character after the escape character). </p>
<p>Usually the escape character is \, and rewriting our example above we&#8217;ll end up with &#8220;Hello \&#8221;World\&#8221;". The parser sees the \, telling it that it should parse the next characters in a special mode and then inserts the &#8221; into the string itself instead of using it as a delimiter. In Java, C, PHP, Python and several other languages there are also special versions of the escape sequences that does something else than just insert the character following the escape character. </p>
<p>\n &#8211; Inserts a new line.<br />
\t &#8211; Inserts a tab character.<br />
\xNN &#8211; Inserts a byte with the byte value provided (\x13, \xFF, etc). </p>
<p>A <a href="http://no.php.net/manual/en/language.types.string.php#language.types.string.syntax.double">list of the different escape sequences that PHP supports</a> can be found in the PHP manual.</p>
<p>Anyways, the issue is that Java found an escape sequence that it doesn&#8217;t know how to handle. Attempting to define a string such as &#8220;! # \ % &#038;&#8221; will trigger this message, as it sees the escape character \, and then attempts to parse the following byte &#8211; which is a space (&#8221; &#8220;). The escape sequence &#8220;\ &#8221; is not a valid escape sequence in the Java language specification, and the parser (or NetBeans or Eclipse) is trying to tell you this is probably not what you want. </p>
<p>The correct way to define the string above would be to escape the escape character (now we&#8217;re getting meta): &#8220;! # \\ % &#038;&#8221;. This would define a string with just a single backlash in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/java-and-netbeans-illegal-escape-character/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery, .getJSON and the Same-Origin Policy</title>
		<link>http://e-mats.org/2010/01/jquery-getjson-and-the-same-origin-policy/</link>
		<comments>http://e-mats.org/2010/01/jquery-getjson-and-the-same-origin-policy/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 10:00:00 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[getjson]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[jsonp]]></category>
		<category><![CDATA[same-origin]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=712</guid>
		<description><![CDATA[When creating a simple mash-up with data from external sources, you usually want to read the data in a suitable format &#8211; such as JSON. The tool for the job tends to be javascript, running in your favourite browser. The only problem is that requests made with XHR (XMLHttpRequest) has to follow the same origin [...]]]></description>
			<content:encoded><![CDATA[<p>When creating a simple mash-up with data from external sources, you usually want to read the data in a suitable format &#8211; such as JSON. The tool for the job tends to be javascript, running in your favourite browser. The only problem is that requests made with XHR  (XMLHttpRequest) has to follow the same origin policy, meaning that the request cannot be made for a resource living on another host than the host serving the original request.</p>
<p>To get around this clients usually use JSONP &#8211; or a simple modification of the usual JSON output. The data is still JSON, but the output also includes a simple callback at the end of the request, triggering a javascript in the local browser. This way the creator of the data actually tells the browser (in so many hacky ways) that it&#8217;s OK, I&#8217;ve actually thought this through. Help yourself.</p>
<p>In jQuery you can trigger the usual handling of events by using &#8220;?&#8221; as the name of your callback function. jQuery will handle this transparently and then trigger the function you provided to .getJSON in the first place.</p>
<h3>Example</h3>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">url = <span class="st0">&quot;http://feeds.delicious.com/v2/json/recent?callback=?&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$.<span class="me1">getJSON</span><span class="br0">&#40;</span>url, <span class="kw2">function</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span>; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>There&#8217;s an <a href="http://www.ibm.com/developerworks/library/wa-aj-jsonp1/">article up at IBM&#8217;s developerWorks</a> giving quite a few more examples and information about the issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/jquery-getjson-and-the-same-origin-policy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One Possible Reason for Missing Munin Graphs</title>
		<link>http://e-mats.org/2010/01/one-possible-reason-for-missing-munin-graphs/</link>
		<comments>http://e-mats.org/2010/01/one-possible-reason-for-missing-munin-graphs/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 10:00:14 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[ejabberd]]></category>
		<category><![CDATA[munin]]></category>
		<category><![CDATA[munin-node]]></category>
		<category><![CDATA[server administration]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=680</guid>
		<description><![CDATA[We&#8217;re currently expanding our munin reporting cluster at Derdubor, but after installing munin-node on one of our servers we never got any graphs. The only section available on the munin server was &#8220;Other&#8221;, and that didn&#8217;t contain any information at all (which indicates that you&#8217;re not getting any response from the server). The first step [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re currently expanding our munin reporting cluster at Derdubor, but after installing <em>munin-node</em> on one of our servers we never got any graphs. The only section available on the munin server was &#8220;Other&#8221;, and that didn&#8217;t contain any information at all (which indicates that you&#8217;re not getting any response from the server).</p>
<p>The first step I make when trying to debug a munin connection is to telnet into the munin port, as this confirms that the two servers are able to talk to each other and that the munin daemon listens to the correct interface and port.</p>
<pre>
# telnet localhost 4949
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
#
</pre>
<p>The connection was established, but then munin closed the connection as soon as it was created. This usually means one thing: the host you&#8217;re connecting from isn&#8217;t added to the cidr_allow list or the allow list, or in the denied hosts list. This time it meant neither, the host was added and we didn&#8217;t have any denied hosts list. </p>
<p>The next step was to take a look at the <em>munin-node.log</em> in <em>/var/log/munin</em> (at least under under debian).</p>
<p>The last message was:</p>
<p><code><br />
User "ejabberd" in configuration file "/etc/munin/plugin-conf.d/munin-node" nonexistant. Skipping plugin. at /usr/sbin/munin-node line 615, <IN> line 83.<br />
Something wicked happened while reading "/etc/munin/plugins/munin-node". Check the previous log lines for spesifics. at /usr/sbin/munin-node line 261, <IN> line 83.<br />
</code></p>
<p>We don&#8217;t have ejabberd installed, but the ejabberd config reference was apparently added to the configuration file in <em>/etc/munin/plugin-conf.d/munin-node</em>. This made our version of munin-node barf, as the user it reference wasn&#8217;t available.</p>
<p>Next step was to remove the section from the file and restarting munin-node:</p>
<pre>
/etc/init.d/munin-node restart
</pre>
<p>After restarting munin, I did the telnet check again:</p>
<pre>
# telnet localhost 4949
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
# munin node at example.com
.
fetch load
load.value 0.02
.
quit
Connection closed by foreign host.
#
</pre>
<p>Wait 10 &#8211; 15 minutes and you should start seeing graphs again &#8211; if this actually were your problem. Probably not (and then you should probably read <a href="http://munin.projects.linpro.no/wiki/Debugging_Munin_plugins">Debuggning Munin Plugins</a> and other documentation on the Wiki). But if it were, you&#8217;ll be happy happy joy joy now. </p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/one-possible-reason-for-missing-munin-graphs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
