<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Digital Ambulation</title>
	<atom:link href="http://www.alanbriolat.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alanbriolat.co.uk</link>
	<description>Life, programming and general geekery</description>
	<pubDate>Sun, 20 Sep 2009 20:00:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>When Dynamic Typing Goes Wrong</title>
		<link>http://www.alanbriolat.co.uk/2009/07/when-dynamic-typing-goes-wrong/</link>
		<comments>http://www.alanbriolat.co.uk/2009/07/when-dynamic-typing-goes-wrong/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 19:01:32 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=388</guid>
		<description><![CDATA[Yesterday I found out first-hand how using a dynamically typed language can get you into trouble in unexpected ways whilst writing unit tests for CSF (my PHP framework).

Take a look at this code&#8212;what do you think it should do?

$foo = 'bar';
var_dump&#40;isset&#40;$foo&#91;'xyz'&#93;&#41;&#41;;
var_dump&#40;$foo&#91;'xyz'&#93;&#41;;

Most people would assume that indexing a string on another string is nonsensical, and they [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I found out first-hand how using a dynamically typed language can get you into trouble in unexpected ways whilst writing unit tests for <a href="http://codescape.net/csf/">CSF</a> (my PHP framework).</p>
<p><span id="more-388"></span></p>
<p>Take a look at this code&#8212;what do you think it should do?</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bar'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$foo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'xyz'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$foo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'xyz'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Most people would assume that indexing a string on another string is nonsensical, and they would be right&#8212;in PHP you can only index a string with an integer.  The logical extension would be that isset($foo['xyz']) would be false and/or any attempt to index using a string would raise an error.  And that is where they would be wrong.  In fact, isset($foo['xyz']) is true, and $foo['xyz'] is &#8220;b&#8221;.</p>
<p>PHP is <a href="http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing">dynamically typed</a>, which generally means there is a lot of implicit casting between types going on.  In this case, while indexing a string can only be done with an integer, there is an implicit cast from a string to an integer, so this cast is performed and the result used as the index.  However, the usual way of converting from a string to an integer is to use digits (0&#8211;9) up until the first non-digit character (after taking the minus sign into account if there is one).  This means the integer value of &#8216;xyz&#8217; is 0, since there are no digits to add up.</p>
<p>When explained, this may seem like sensible behaviour, but let&#8217;s think about the effect this has when coding and debugging: if you accidentally index a string with another string somewhere, you won&#8217;t know about it straight away.  Instead, you&#8217;ll just be getting &#8220;wrong&#8221; values and scratching your head over where they could be coming from.  I&#8217;m of the opinion that if you can only index a string on an integer, then indexing it on a string should be at the very least a warning.  Silently doing something completely different isn&#8217;t very helpful.</p>
<p>And so that this doesn&#8217;t seem like a nonsensical contrived example, here&#8217;s a reduced version of the code that raised the issue:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$default</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$item</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">func_num_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> 3<span style="color: #009900;">&#41;</span>
                throw <span style="color: #000000; font-weight: bold;">new</span> ItemNotFound<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">else</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$default</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$item</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What this function does is traverse a multi-dimensional array with a &#8220;key path&#8221;, i.e. &#8220;key1.key2&#8243; gets $array['key1']['key2'].  Since isset() is the most common way people check the existence of an array, this is what I used here.  However, things break down in this example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'bar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> get_item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foo.xyz'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The expected behaviour is that the exception should be thrown, since $array['foo'] is not an array with a &#8220;xyz&#8221; key, but the issue described above instead leads this to return &#8220;b&#8221;.</p>
<p>In this case, there is a way around it: what I really should have been using is the following check:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>This has more interesting consequences&#8212;it means that a very very large number of people are using &#8220;isset&#8221; where they mean &#8220;is_array and array_key_exists&#8221;.  As for me, I just fixed a bug in my code exposed by a unit test, so I&#8217;m happy (even if a little bewildered by PHP).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/07/when-dynamic-typing-goes-wrong/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why .NET Won&#8217;t Beat Java (Yet)</title>
		<link>http://www.alanbriolat.co.uk/2009/06/why-net-wont-beat-java-yet/</link>
		<comments>http://www.alanbriolat.co.uk/2009/06/why-net-wont-beat-java-yet/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 10:14:10 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[.net]]></category>

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

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=383</guid>
		<description><![CDATA[It&#8217;s been no real secret that the .NET CLR (Common Language Runtime) has been Microsoft&#8217;s answer to Java.  Garbage collection, bytecode compilation, large set of core libraries, it&#8217;s all there.  But there is a problem that I&#8217;ve encountered recently: distribution size and install base.
A fairly clean Windows XP machine is fairly certain to [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been no real secret that the .NET CLR (Common Language Runtime) has been Microsoft&#8217;s answer to Java.  Garbage collection, bytecode compilation, large set of core libraries, it&#8217;s all there.  But there is a problem that I&#8217;ve encountered recently: distribution size and install base.</p>
<p>A fairly clean Windows XP machine is fairly certain to not have anything higher than .NET 1.x installed.  Anything really compelling in the .NET framework requires 3.5.  This means somehow you need to get version 3.5 onto the machine somehow.  This isn&#8217;t a problem in Windows Vista and later, which include the framework.   Microsoft&#8217;s answer to simple deployment is it&#8217;s &#8220;ClickOnce&#8221; system, where an application automatically installs .NET from the Internet (if necessary) before installing itself.   Sure, it&#8217;s a 60MB download, but it only needs to be done once.</p>
<p>The real issue is when you can&#8217;t guarantee an Internet connection or a working .NET 3.5 installation.  At this point you must resort to the offline installation, and this is where .NET and Java are very different.  For Java 1.6 SE, the offline installer is 16MB for Windows 32-bit.  For .NET 3.5, the offline installer is a <strong>200MB</strong> universal package, with no way to cut out the parts you don&#8217;t need.  Java in fact is so small relatively speaking that many applications actually include the JRE in their package (for example OpenOffice - 148MB with JRE vs. 134MB without), whereas .NET can turn a 10MB application into a 210MB monstrosity.</p>
<p>Now in my particular situation, I&#8217;m embarassed to have chosen to use C#/.NET/WPF for a simple tool at work.  For programming the tool itself, it was certainly the fastest option - other kinds of Windows programming, e.g. MFC or Forms, just look painful, and I thought the barrier to entry would be lower than Java.  However this 1MB tool requires the 200MB .NET offline installer to be carted around with it because the network it&#8217;s used on is completely separate from the Internet.</p>
<p>.NET will only be <em>really</em> appealing once it&#8217;s ubiquitous, but then &#8220;critical mass&#8221; is one of the big problems for lots of software.  For now, I think I&#8217;m going to try Java next time&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/06/why-net-wont-beat-java-yet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mouse Button Remapping with HAL</title>
		<link>http://www.alanbriolat.co.uk/2009/06/mouse-button-remapping-with-hal/</link>
		<comments>http://www.alanbriolat.co.uk/2009/06/mouse-button-remapping-with-hal/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 09:02:05 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=365</guid>
		<description><![CDATA[I&#8217;ve had a Logitech MX1000 mouse for a few years now, and the two most important features for me have been the ergonomic build and the few extra buttons.  Something I&#8217;ve always found with many-buttoned mice is that the side button closest to the thumb is a much more ergonomic way to &#8220;middle click&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a Logitech MX1000 mouse for a few years now, and the two most important features for me have been the ergonomic build and the few extra buttons.  Something I&#8217;ve always found with many-buttoned mice is that the side button closest to the thumb is a much more ergonomic way to &#8220;middle click&#8221; than the actual middle mouse button&#8212;it&#8217;s a much more natural motion.  Middle clicks are quite useful these days, especially with them being a standard way of closing tabs (and opening them in browsers), and having such a popular button perched on a rocking and rolling peak is far from ideal.</p>
<p>Since I&#8217;m primarily a Linux user, I don&#8217;t have Logitech&#8217;s own SetPoint software at my disposal, so I&#8217;ve always had to find a way to get this functionality in some other way.  When I first got the mouse, this method involved deliberately using a &#8220;basic&#8221; mouse driver (referred to in xorg.conf as &#8220;IMPS/2&#8243;), which didn&#8217;t support many mouse buttons.  The effect was that the button mappings wrapped around, leaving button 8, my preferred &#8220;middle click&#8221;, mapped to button 2 (8 mod 3), the real middle button.</p>
<p>Unfortunately, newer Xorg versions became smarter and better capable of handling more buttons, and this workaround ceased to function.  For the next while, I used something even more hackish: <a href="http://freshmeat.net/projects/xbindkeys/">xbindkeys</a> combined with <a href="http://xmacro.sourceforge.net/">xmacroplay</a> to simulate a middle click with the following part of my .xbindkeysrc:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&quot;echo ButtonRelease 8 ButtonPress 2 ButtonRelease 2 | xmacroplay -d 0 :0.0 &amp;&quot;
    b:8</pre></div></div>

<p>The downside to this solution is that there are some cases where the button events don&#8217;t work correctly, one of them being open-in-tab from a bookmark menu in Firefox.  It seemed the best solution would be to get Xorg to remap the buttons in such a way that button 8 really was just an extra button 2.  The &#8220;xinput&#8221; utility lets you set button maps in this way&#8212;<a href="https://wiki.ubuntu.com/X/Config/Input#Example:%20Disabling%20middle-mouse%20button%20paste%20on%20a%20scrollwheel%20mouse">this wiki entry</a> shows how to remap mouse buttons (even if for a different purpose).</p>
<p>This method worked fine, and I put it in my startup programs for GNOME, but it didn&#8217;t persist after suspend/resume.  It appears that when resuming, USB devices get &#8220;reattached&#8221;, and therefore don&#8217;t keep the settings applied to them the last time they were attached.  The workaround for this is to set a policy using a HAL (Hardware Abstraction Layer) .fdi file.  These files live in /etc/hal/fdi/policy (at least they do on Ubuntu) and allow you to set various properties on input devices.  <a href="https://help.ubuntu.com/community/Logitech_Marblemouse_USB">This page on the Ubuntu wiki</a> gave me the recipe I needed to remap buttons based on the device name.  I ended up with the following .fdi file (which I saved at /etc/hal/fdi/policy/logitech-mx1000.fdi):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;deviceinfo</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;0.2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- Remap Logitech MX1000 buttons so that the most accessible side button</span>
<span style="color: #808080; font-style: italic;">     acts as a middle button --&gt;</span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;device<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;info.product&quot;</span> <span style="color: #000066;">string</span>=<span style="color: #ff0000;">&quot;Logitech USB RECEIVER&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;merge</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;input.x11_options.ButtonMapping&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1 2 3 4 5 6 7 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/merge<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/match<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/device<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/deviceinfo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now, whenever my Logitech mouse is connected, it gets the buttons remapped&#8212;this includes when resuming from suspend.  Problem solved&#8230; until things are changed again of course!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/06/mouse-button-remapping-with-hal/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Rise and Fail of Facebook</title>
		<link>http://www.alanbriolat.co.uk/2009/06/the-rise-and-fail-of-facebook/</link>
		<comments>http://www.alanbriolat.co.uk/2009/06/the-rise-and-fail-of-facebook/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 09:33:18 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[web 2.0]]></category>

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=362</guid>
		<description><![CDATA[A recent Lifehacker story about a Greasemonkey script to remove quiz stuff from Facebook made me realise something: you know your site is too &#8220;web 2.0&#8243; when users are going out of their way to remove features. A quick search on Userscripts.org reveals that a substantial proportion of the Facebook-related scripts are either for removing [...]]]></description>
			<content:encoded><![CDATA[<p>A recent <a href="http://lifehacker.com/5284511/facebook-purity-removes-eye+gouging-quiz-updates">Lifehacker story</a> about a Greasemonkey script to remove quiz stuff from <a href="http://www.facebook.com/">Facebook</a> made me realise something: <strong>you know your site is too &#8220;web 2.0&#8243; when users are going out of their way to remove features.</strong> A quick <a href="http://userscripts.org/scripts/search?q=facebook&amp;sort=rating">search on Userscripts.org</a> reveals that a substantial proportion of the Facebook-related scripts are either for removing features or auto-playing game applications.</p>
<p>I feel that Facebook started off pretty well.  The initial target audience seemed to be students, and that&#8217;s what most of the users were.  It was friendly and uncluttered, compared to other social networking sites like MySpace.  This spread to a wider audience, first sucking in kids and then adults.  This was less than ideal for some, the idea of their parents on a social networking site being horrifying, but still not a disaster.</p>
<p>But in the midst of all this, the apocalypse happened: a powerful API which allowed other people to extend the functionality of Facebook by creating applications that people could add to their account.  Gradually  users became innundated with an unstoppable torrent of application requests, caused by application developers making the &#8220;tell all your friends&#8221; step seem (or be) necessary to using their application.  The average user&#8217;s profile became a mess of applications competing for screen space.  The target audience became those who have the time to play endless Flash games, answer endless quizzes, and generally clutter the &#8220;requests&#8221; page of their friends.</p>
<p>And so Facebook became <a href="http://myspace.com/">MySpace</a> 2.0&#8212;gaudy and cluttered, with infinite ability to add more clutter.  Maybe the lesson learned is that the moment you allow anything &#8220;shiny&#8221; in a social networking site, your demographic will degenerate to schoolkids who want to fill their profiles with as much of it as possible.</p>
<p>Personally, I&#8217;ve reduced my Facebook interaction for the past 2 years to having the site email me when anybody says something directly to me either via message or on my &#8220;wall&#8221;.  There is just too much clutter now for me to wade through the endless application requests, friend requests from people I don&#8217;t know, and news feed items generated by the latest viral quiz.  And maybe pictures of friends getting drunk have lost their novelty value&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/06/the-rise-and-fail-of-facebook/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Spectacular IE7 CSS box model failure</title>
		<link>http://www.alanbriolat.co.uk/2009/05/spectacular-ie7-css-box-model-failure/</link>
		<comments>http://www.alanbriolat.co.uk/2009/05/spectacular-ie7-css-box-model-failure/#comments</comments>
		<pubDate>Sun, 17 May 2009 16:31:54 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=353</guid>
		<description><![CDATA[When re-theming DokuWiki to fit in with the general look-and-feel of this blog, I thought it would look good to have buttons with images relevant to what they did.  Having created the necessary, CSS, I subjected it to my multi-browser test bed (actually a Windows XP virtual machine with the latest versions of the [...]]]></description>
			<content:encoded><![CDATA[<p>When re-theming DokuWiki to fit in with the general look-and-feel of this blog, I thought it would look good to have buttons with images relevant to what they did.  Having created the necessary, CSS, I subjected it to my <a href="http://iris.codescape.net/~alan/IE-rendering-fail-3.png" rel="lightbox[353]">multi-browser test bed</a> (actually a Windows XP virtual machine with the latest versions of the top 5 browsers running in it).  The CSS I used was along the lines of this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.dokuwiki</span> form<span style="color: #6666ff;">.btn_show</span> <span style="color: #6666ff;">.button</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> 0 <span style="color: #933;">1px</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/page.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0px</span> <span style="color: #933;">1px</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>One thing that became apparent is that IE7 has absolutely no idea how to render this.  The correct rendering (as produced by Firefox 3 and all the other browsers) is this:</p>
<p style="text-align: center;"><a href="http://www.alanbriolat.co.uk/wp-content/uploads/2009/05/button-background-image-ff3.png" rel="lightbox[353]"><img class="size-full wp-image-354 aligncenter" title="button-background-image-ff3" src="http://www.alanbriolat.co.uk/wp-content/uploads/2009/05/button-background-image-ff3.png" alt="button-background-image-ff3" width="243" height="31" /></a></p>
<p>IE7&#8217;s take on rendering this looked more like this:</p>
<p style="text-align: center;"><a href="http://www.alanbriolat.co.uk/wp-content/uploads/2009/05/button-background-image-ie7.png" rel="lightbox[353]"><img class="size-full wp-image-355 aligncenter" title="button-background-image-ie7" src="http://www.alanbriolat.co.uk/wp-content/uploads/2009/05/button-background-image-ie7.png" alt="button-background-image-ie7" width="317" height="41" /></a></p>
<p>After a bit more experimentation, I came up with the following illustration which roughly shows what is happening:</p>
<p style="text-align: center;"><a href="http://iris.codescape.net/~alan/IE7-button-rendering.png" rel="lightbox[353]"><img class="aligncenter" title="IE7 button rendering" src="http://iris.codescape.net/~alan/IE7-button-rendering.png" alt="" width="361" height="155" /></a></p>
<p>The nice thing is that this is fixed in the upcoming IE8, so I&#8217;ve taken the stress-free approach; since it&#8217;s a relatively &#8220;minor&#8221; visual bug, there&#8217;s no sense it tearing my hair out trying to make it render correctly everywhere.  On this occasion I&#8217;ve decided that people can either deal with the fact their browser is behind the times, or upgrade, or wait for the upgrade to happen for them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/05/spectacular-ie7-css-box-model-failure/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Quick and dirty screen scraping of UK MP expenses data</title>
		<link>http://www.alanbriolat.co.uk/2009/05/quick-and-dirty-screen-scraping-of-uk-mp-expenses-data/</link>
		<comments>http://www.alanbriolat.co.uk/2009/05/quick-and-dirty-screen-scraping-of-uk-mp-expenses-data/#comments</comments>
		<pubDate>Wed, 13 May 2009 21:41:56 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

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

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=340</guid>
		<description><![CDATA[A dominating story in the news recently has been that of UK Members of Parliament &#8220;abusing&#8221; the expenses system.  As part of this, expense claims data has been released to the public, but unsurprisingly not in a simple CSV format that just anybody can play with.  All I could find were PDF files [...]]]></description>
			<content:encoded><![CDATA[<p>A dominating story in the news recently has been that of UK Members of Parliament &#8220;abusing&#8221; the expenses system.  As part of this, expense claims data has been released to the public, but unsurprisingly not in a simple CSV format that just anybody can play with.  All I could find were PDF files and news sites representing the data in their own way.</p>
<p>This led me to wonder how easy it would be to &#8220;scrape&#8221; the data from one of these sites.  Having heard about <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a>, a Python HTML &#8220;tag soup&#8221; parser, I opened up an interactive Python session and started to play with the data from <a href="http://news.bbc.co.uk/1/hi/uk_politics/8044207.stm">this BBC News page</a>.  Luckily for me, the BBC page&#8217;s HTML isn&#8217;t <em>too</em> ugly, so figuring out how to get the data rows wasn&#8217;t that hard.</p>
<p>The end result is the following Python script which scrapes the data from the BBC News page and saves it in both CSV and JSON formats.</p>
Note: There is a file embedded within this post, please visit this post to download the file.
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/05/quick-and-dirty-screen-scraping-of-uk-mp-expenses-data/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mozilla/1.22 (compatible; MSIE 2.0; Windows 95)</title>
		<link>http://www.alanbriolat.co.uk/2009/05/mozilla122-compatible-msie-20-windows-95/</link>
		<comments>http://www.alanbriolat.co.uk/2009/05/mozilla122-compatible-msie-20-windows-95/#comments</comments>
		<pubDate>Mon, 11 May 2009 09:46:24 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=333</guid>
		<description><![CDATA[Browsing the visitor stats today, I found this little gem:

&#8220;Mozilla/1.22 (compatible; MSIE 2.0; Windows 95)&#8221;?  Who uses such a browser?  My bet is on it being a zombie machine that somebody has completely forgotten about, which would explain the several other hits I have from versions of IE before 5.0&#8230;  These visitors turn up, hit [...]]]></description>
			<content:encoded><![CDATA[<p>Browsing the visitor stats today, I found this little gem:</p>
<p><a href="http://www.alanbriolat.co.uk/wp-content/uploads/2009/05/ancient-browser1.png" rel="lightbox[333]"><img class="alignnone size-full wp-image-337" title="Ancient browser user agent" src="http://www.alanbriolat.co.uk/wp-content/uploads/2009/05/ancient-browser1.png" alt="Ancient browser user agent" width="592" height="255" /></a></p>
<p>&#8220;Mozilla/1.22 (compatible; MSIE 2.0; Windows 95)&#8221;?  Who uses such a browser?  My bet is on it being a zombie machine that somebody has completely forgotten about, which would explain the several other hits I have from versions of IE before 5.0&#8230;  These visitors turn up, hit the same page repeatedly, and then leave.  Unfortunately I deleted my spam before seeing this, otherwise I&#8217;d be able to verify this theory.  Maybe I&#8217;ll look more closely next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/05/mozilla122-compatible-msie-20-windows-95/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tpl - A tiny PHP template engine</title>
		<link>http://www.alanbriolat.co.uk/2009/04/tpl-a-tiny-php-template-engine/</link>
		<comments>http://www.alanbriolat.co.uk/2009/04/tpl-a-tiny-php-template-engine/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 16:03:44 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

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

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=303</guid>
		<description><![CDATA[While developing CodeScape Framework I came up with a simple template engine that instead of implementing it&#8217;s own language just provided some structure-related hooks, and I&#8217;ve now got around to separating out and releasing Tpl, a simple, self-contained, hierarchical template engine for PHP.
Tpl&#8217;s role is centred around template structure, not content&#8212;it&#8217;s not a huge library [...]]]></description>
			<content:encoded><![CDATA[<p>While developing <a href="http://codescape.net/csf/">CodeScape Framework</a> I came up with a simple template engine that instead of implementing it&#8217;s own language just provided some structure-related hooks, and I&#8217;ve now got around to separating out and releasing <a href="http://codescape.net/tpl/">Tpl</a>, a simple, self-contained, hierarchical template engine for PHP.</p>
<p>Tpl&#8217;s role is centred around template structure, not content&#8212;it&#8217;s not a huge library of helper functions for creating links, displaying images, etc.  Like any template engine, the aim is to separate presentation logic from application logic, but it doesn&#8217;t attempt this by creating a template language.  PHP is <a href="http://php.net/manual/en/history.php.php">designed</a> to be interleaved with &#8220;static&#8221; output, which means it&#8217;s already a template language.  Trying to replace it for the purpose of templating rarely adds anything useful, incurs hefty performance overheads (which you then have to mitigate with caching) and usually is more restrictive than PHP.  To me, that doesn&#8217;t seem like a sensible application of effort.  Instead Tpl provides its functionality in the form of hooks&#8212;functions which are called from within the template to specify the structure.  Instead of PHP being replaced, it is extended.</p>
<p>The main motivating factor for creating Tpl is that all PHP template engines seem to be centred around <em>inclusion</em> rather than <em>inheritance</em>, something I only noticed after spending time working with <a href="http://www.djangoproject.com/">Django</a>.  For example, a typical PHP template might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!-- header.php --&gt;
&lt;html&gt;
    &lt;head&gt;&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$title</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;&lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;header&quot;&gt;Website Name&lt;/div&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span> footer<span style="color: #339933;">.</span>php <span style="color: #339933;">--&gt;</span>
        <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;footer&quot;</span><span style="color: #339933;">&gt;</span>Some footer text<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!-- content.php --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div id=&quot;content&quot;&gt;
    Some content
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The main problem with this is that it bears no real relation to the logical structure of the page, just the order in which stuff should appear in the HTML.  If you modify something in the header, you need to make sure you&#8217;ve updated the footer too.  The equivalent Django template would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{# base.html #}
&lt;html&gt;
    &lt;head&gt;&lt;title&gt;{{ title }}&lt;/title&gt;&lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;header&quot;&gt;Website Name&lt;/div&gt;
&nbsp;
        {% block content %}{% endblock %}
&nbsp;
        &lt;div id=&quot;footer&quot;&gt;Some footer text&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{# content.html #}
{% extends &quot;base.html&quot; %}
&nbsp;
{% block content %}
&lt;div id=&quot;content&quot;&gt;
    Some content
&lt;/div&gt;
{% endblock %}</pre></div></div>

<p>The point to note is that the structure is coherent and in one place, and the parts that change are defined as logical blocks which can be replaced.  This is the method I&#8217;ve adopted in Tpl&#8212;the equivalent template would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!-- base.php --&gt;
&lt;html&gt;
    &lt;head&gt;&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$C</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;&lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;header&quot;&gt;Website Name&lt;/div&gt;
&nbsp;
        <span style="color: #000000; font-weight: bold;">&lt;?</span> Tpl<span style="color: #339933;">::</span><span style="color: #004000;">block</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span> Tpl<span style="color: #339933;">::</span><span style="color: #004000;">endblock</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
        &lt;div id=&quot;footer&quot;&gt;Some footer text&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!-- content.php --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?</span> Tpl<span style="color: #339933;">::</span><span style="color: #004000;">inherit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'base.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?</span> Tpl<span style="color: #339933;">::</span><span style="color: #004000;">block</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;content&quot;&gt;
    Some content
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?</span> Tpl<span style="color: #339933;">::</span><span style="color: #004000;">endblock</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>More information about Tpl and how to download it can be found at the <a href="http://codescape.net/tpl/">Tpl project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/04/tpl-a-tiny-php-template-engine/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Enable Bitmap Fonts on Ubuntu Jaunty</title>
		<link>http://www.alanbriolat.co.uk/2009/04/enable-bitmap-fonts-on-ubuntu-jaunty/</link>
		<comments>http://www.alanbriolat.co.uk/2009/04/enable-bitmap-fonts-on-ubuntu-jaunty/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 16:18:01 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

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

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

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=283</guid>
		<description><![CDATA[I like to use tiny bitmap fonts like MonteCarlo for programming, but by default Ubuntu has bitmap font support turned off.  From (at least) Gutsy through to Intrepid, this method worked for enabling bitmap font support, but after installing the Jaunty beta I found this no longer works.
Luckily, after a brief look in /etc/fonts, I [...]]]></description>
			<content:encoded><![CDATA[<p>I like to use tiny bitmap fonts like <a href="http://www.bok.net/MonteCarlo/">MonteCarlo</a> for programming, but by default Ubuntu has bitmap font support turned off.  From (at least) Gutsy through to Intrepid, <a href="http://www.nazgum.com/2007/12/09/ubuntu-pcf-fonts/">this method</a> worked for enabling bitmap font support, but after installing the Jaunty beta I found this no longer works.</p>
<p>Luckily, after a brief look in /etc/fonts, I found that font configuration now follows the nice pattern of a conf.avail directory containing all the available configuration parts, and conf.d containing symlinks to these parts.  This makes enabling bitmap fonts even simpler now:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># &quot;Un-disable&quot; bitmap fonts</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">70</span>-no-bitmaps.conf
<span style="color: #666666; font-style: italic;"># Clear the font cache</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> fc-cache <span style="color: #660033;">-f</span> <span style="color: #660033;">-v</span></pre></div></div>

<p>Now you should be able to drop bitmap (i.e. PCF) fonts into ~/.fonts as you would with TTF fonts and be able to use them with no extra hassle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/04/enable-bitmap-fonts-on-ubuntu-jaunty/feed/</wfw:commentRss>
		</item>
		<item>
		<title>VDB 0.1.0 (alpha) Released</title>
		<link>http://www.alanbriolat.co.uk/2009/04/vdb-010-alpha-released/</link>
		<comments>http://www.alanbriolat.co.uk/2009/04/vdb-010-alpha-released/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 22:23:52 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

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

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=275</guid>
		<description><![CDATA[Recently I&#8217;ve been working on a program that will let me do a full-text search of my 1500-file digital video library.  The result is something I&#8217;ve unimaginatively called &#8220;VDB&#8221;, short for &#8220;Video Database&#8221;.
This release doesn&#8217;t do much: you can add your library of video files, and it will let you do a full-text search on [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been working on a program that will let me do a full-text search of my 1500-file digital video library.  The result is something I&#8217;ve unimaginatively called &#8220;VDB&#8221;, short for &#8220;Video Database&#8221;.</p>
<p><a href="http://www.alanbriolat.co.uk/wp-content/uploads/2009/03/vdb-010.png" rel="lightbox[275]"><img class="alignright size-medium wp-image-271" title="VDB Interface" src="http://www.alanbriolat.co.uk/wp-content/uploads/2009/03/vdb-010-300x233.png" alt="VDB Interface" width="300" height="233" /></a>This release doesn&#8217;t do much: you can add your library of video files, and it will let you do a full-text search on the filename.  You can double-click an item in the list to launch the video with &#8216;gnome-open&#8217; (which should honour user settings for preferred applications).</p>
<p>Feel free to download it, mess around with it, and send me any feedback you have.  I have plenty of future plans for it, including &#8220;watch folders&#8221;, tagging, metadata, fetching information from IMDB, and being able to search on all of this information.  (Think queries like &#8220;actor:&#8217;johnny depp&#8217; tag:crime&#8221;.)</p>
<p><a href="http://codescape.net/vdb/">Visit the VDB project page.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/04/vdb-010-alpha-released/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
