<?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>Tim&#039;s Bandwagon</title>
	<atom:link href="http://www.twisty.com/bandwagon/feed" rel="self" type="application/rss+xml" />
	<link>http://www.twisty.com/bandwagon</link>
	<description>Hitch your wagon to a chicken</description>
	<lastBuildDate>Sat, 16 Jul 2011 13:19:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>PHPUnit: How to show more info in testdox output when using data providers</title>
		<link>http://www.twisty.com/bandwagon/archives/2011/07/16/141959</link>
		<comments>http://www.twisty.com/bandwagon/archives/2011/07/16/141959#comments</comments>
		<pubDate>Sat, 16 Jul 2011 13:19:59 +0000</pubDate>
		<dc:creator>Tim Brayshaw</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/?p=255</guid>
		<description><![CDATA[Probably the geekiest and most obscure blog post title I&#8217;ll ever write, but we&#8217;ll see! &#60;?php &#160; class DataProviderExampleTest extends PHPUnit_Framework_TestCase &#123; /** * @dataProvider colourStatementsProvider */ public function testItemIsCorrectColour&#40;$statement, $item, $colour&#41; &#123; $parts = explode&#40;' is ', $statement&#41;; $this-&#62;assertEquals&#40;$parts&#91;0&#93;, $item&#41;; $this-&#62;assertEquals&#40;$parts&#91;1&#93;, $colour&#41;; &#125; &#160; public function colourStatementsProvider&#40;&#41; &#123; return array&#40; 'apple-is-green' =&#62; array&#40;'apple is [...]]]></description>
				<content:encoded><![CDATA[<p>Probably the geekiest and most obscure blog post title I&#8217;ll ever write, but we&#8217;ll see!</p>


<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DataProviderExampleTest <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Framework_TestCase
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * @dataProvider colourStatementsProvider
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testItemIsCorrectColour<span style="color: #009900;">&#40;</span><span style="color: #000088;">$statement</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$parts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' is '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$statement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> colourStatementsProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'apple-is-green'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'apple is green'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'green'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'apple-is-red'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'apple is red'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'sky-is-blue'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sky is blue'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sky'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'grey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>Now run the test:</p>


<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">% phpunit DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.
&nbsp;
..F
&nbsp;
Time: 0 seconds
&nbsp;
There was 1 failure:
&nbsp;
1) DataProviderExampleTest::testItemIsCorrectColour with data set &quot;sky-is-blue&quot; ('sky is blue', 'sky', 'grey')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-blue
+grey
&nbsp;
/Users/tim/Desktop/DataProviderExampleTest.php:12
&nbsp;
FAILURES!
Tests: 3, Assertions: 6, Failures: 1.</pre></td></tr></table></div>


<p>Here&#8217;s the testdox output:</p>


<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">% phpunit --testdox DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.
&nbsp;
DataProviderExample
 [ ] Item is correct colour</pre></td></tr></table></div>


<p>In previous versions of PHPUnit there used to be more info&#8230;</p>

<p>in PHPUnit_Util_TestDox_ResultPrinter change the following line (246) from (part of the startTest function)</p>

<p>from:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>246
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestMethodPrettified</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prettifier</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prettifyTestMethod</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>to:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>246
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestMethodPrettified</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prettifier</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prettifyTestMethod</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">% phpunit --testdox DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.
&nbsp;
DataProviderExample
 [x] Item is correct colour with data set &quot;apple-is-green&quot;
 [x] Item is correct colour with data set &quot;apple-is-red&quot;
 [ ] Item is correct colour with data set &quot;sky-is-blue&quot;</pre></td></tr></table></div>


<p>much better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2011/07/16/141959/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import Ricoh GX100 RAW files into Apple’s Aperture in MacOS 10.5 Leopard</title>
		<link>http://www.twisty.com/bandwagon/archives/2007/11/16/175701</link>
		<comments>http://www.twisty.com/bandwagon/archives/2007/11/16/175701#comments</comments>
		<pubDate>Fri, 16 Nov 2007 16:57:01 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/archives/2007/11/16/175701</guid>
		<description><![CDATA[Here’s a little hack to enable you to use Ricoh GX100 RAW files in Apple’s Aperture. Make a backup of the following file: /System/Library/CoreServices/RawCamera.bundle/Contents/Resources/Raw.plist Find the key for the Leica D-LUX 3 (line 3316 in MacOS 10.5.1): 3316: &#60;key&#62;Leica D-LUX 3&#60;/key&#62; &#60;string&#62;Panasonic DMC-LX2&#60;/string&#62; &#60;!-- 10.4.10 --&#62; Then insert the following line before the line showing [...]]]></description>
				<content:encoded><![CDATA[<p>Here’s a little hack to enable you to use Ricoh GX100 RAW files in Apple’s Aperture.</p>

<p>Make a backup of the following file:</p>

<pre><code>/System/Library/CoreServices/RawCamera.bundle/Contents/Resources/Raw.plist</code></pre>

<p>Find the key for the Leica D-LUX 3 (line 3316 in MacOS 10.5.1):</p>

<pre><code>3316: &lt;key&gt;Leica D-LUX 3&lt;/key&gt; &lt;string&gt;Panasonic DMC-LX2&lt;/string&gt; &lt;!-- 10.4.10 --&gt;
</code></pre>

<p>Then insert the following line before the line showing the Leica D-LUX 3:</p>

<pre><code>3316: &lt;key&gt;RICOH Caplio GX100&lt;/key&gt; &lt;string&gt;Panasonic DMC-LX2&lt;/string&gt;
3317: &lt;key&gt;Leica D-LUX 3&lt;/key&gt; &lt;string&gt;Panasonic DMC-LX2&lt;/string&gt; &lt;!-- 10.4.10 --&gt;
</code></pre>

<p>You should now be able to use the Ricoh’s RAW files in Aperture.</p>

<p>This is based on a previous hack (<a href="http://forums.dpreview.com/forums/read.asp?forum=1013&amp;message=23723763">detailed here</a>), which doesn&#8217;t apply to Leopard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2007/11/16/175701/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Bristol City Council’s Planning application documents only viewable using Internet Explorer</title>
		<link>http://www.twisty.com/bandwagon/archives/2007/08/01/104320</link>
		<comments>http://www.twisty.com/bandwagon/archives/2007/08/01/104320#comments</comments>
		<pubDate>Wed, 01 Aug 2007 09:43:20 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Bristol]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/archives/2007/08/01/104320</guid>
		<description><![CDATA[From Britol City Council’s PublicAccess for Planning page: Please note that the documents within PublicAccess can only be accessed by using Internet Explorer. This is due to a limitation within the system which has been raised with the suppliers. Not good enough. Here’s form I knocked-up in about 2 minutes that gives users of other [...]]]></description>
				<content:encoded><![CDATA[<p>From Britol City Council’s <a href="http://www.bristol.gov.uk/ccm/content/Environment-Planning/Planning/publicaccess-for-planning.en">PublicAccess for Planning</a> page:</p>

<blockquote>
    <p>Please note that the documents within PublicAccess can only be accessed by using Internet Explorer. This is due to a limitation within the system which has been raised with the suppliers.</p>
</blockquote>

<p>Not good enough. Here’s form I knocked-up in about 2 minutes that gives users of other browsers access to associated planning documents. The associated documents are things like supporting letters, photographs, a copy of the application form etc.</p>

<p>Enter a planning application number to view any supporting documents.</p>

<form action="http://e2edocs.bristol-city.gov.uk/WAM/findCaseFile.do" method="get" accept-charset="utf-8">
<input type="hidden" name="appName" value="planning" id="appName"/>
<p><label for="appNumber">Application number</label> (e.g. <code>02/00001/FUL</code>)<br /><input type="text" name="appNumber" value="" id="appNumber" /> <input type="submit" value="Show Documents" /></p>
</form>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2007/08/01/104320/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ActionScript trim function</title>
		<link>http://www.twisty.com/bandwagon/archives/2007/07/23/162642</link>
		<comments>http://www.twisty.com/bandwagon/archives/2007/07/23/162642#comments</comments>
		<pubDate>Mon, 23 Jul 2007 15:26:42 +0000</pubDate>
		<dc:creator>Tim Brayshaw</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/archives/2007/07/23/162642</guid>
		<description><![CDATA[ActionScript 2.0 doesn&#8217;t have a trim function to strip whitespace from the start and end of a string. Here&#8217;s a simple function I wrote because I couldn&#8217;t find a satisfactory example on Google! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 function trim&#40;str:String&#41;:String &#123; var stripCharCodes = [...]]]></description>
				<content:encoded><![CDATA[<p>ActionScript 2.0 doesn&#8217;t have a <code>trim</code> function to strip whitespace from the start and end of a string. Here&#8217;s a simple function I wrote because I couldn&#8217;t find a satisfactory example on Google!</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> trim<span style="color: #66cc66;">&#40;</span>str:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> stripCharCodes = <span style="color: #66cc66;">&#123;</span>
        code_9  : <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #808080; font-style: italic;">// tab</span>
        code_10 : <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #808080; font-style: italic;">// linefeed</span>
        code_13 : <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #808080; font-style: italic;">// return</span>
        code_32 : <span style="color: #000000; font-weight: bold;">true</span>  <span style="color: #808080; font-style: italic;">// space</span>
    <span style="color: #66cc66;">&#125;</span>;
    <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>stripCharCodes<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;code_&quot;</span> + str.<span style="color: #0066CC;">charCodeAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        str = str.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, str.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>stripCharCodes<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;code_&quot;</span> + str.<span style="color: #0066CC;">charCodeAt</span><span style="color: #66cc66;">&#40;</span>str.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        str = str.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, str.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> str;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>


<p>The horrible <code>"code_"</code> prefix hack is there because I don&#8217;t think there&#8217;s a native way to search an array or object for a key or value in ActionScript.</p>

<p><ins>Update:</ins> just found this function at: <a href="http://www.frogstyle.ch/p.cfm?s=18">frogstyle.ch</a>. This one does a similar thing, but strips more characters.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> trim<span style="color: #66cc66;">&#40;</span>str:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i = <span style="color: #cc66cc;">0</span>; str.<span style="color: #0066CC;">charCodeAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">33</span>; i++<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j = str.<span style="color: #006600;">length</span>-<span style="color: #cc66cc;">1</span>; str.<span style="color: #0066CC;">charCodeAt</span><span style="color: #66cc66;">&#40;</span>j<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">33</span>; j--<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">return</span> str.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span>i, j+<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>


<p><ins>Update:</ins> <a href="http://code.google.com/p/as3corelib/">as3corelib</a> has a static trim method in <code>com.adobe.utils.StringUtil</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2007/07/23/162642/feed</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>array_mode</title>
		<link>http://www.twisty.com/bandwagon/archives/2007/05/03/104903</link>
		<comments>http://www.twisty.com/bandwagon/archives/2007/05/03/104903#comments</comments>
		<pubDate>Thu, 03 May 2007 09:49:03 +0000</pubDate>
		<dc:creator>Tim Brayshaw</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/archives/2007/05/03/104903</guid>
		<description><![CDATA[If you&#8217;ve ever needed to get calculate a mode value in php, you&#8217;ll notice that there isn&#8217;t a native function to do so. I couldn&#8217;t get the function in Pear&#8217;s Math_Statistics to work with non-numeric values, so here&#8217;s a function that does. 1 2 3 4 5 6 7 8 9 10 11 12 13 [...]]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve ever needed to get calculate a mode value in php, you&#8217;ll notice that there isn&#8217;t a native function to do so.</p>

<p>I couldn&#8217;t get the function in Pear&#8217;s <a href="http://pear.php.net/package/Math_Stats/" title="PEAR :: Package :: Math_Stats">Math_Statistics</a> to work with non-numeric values, so here&#8217;s a function that does.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Calculates the frequently occuring value(s) in an array.
 *
 * @param  array $data
 * @return array
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> array_mode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</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;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'First argument $data must be an array.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$frequencies</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_count_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Double-check that frequencies are sorted in reverse order,</span>
    <span style="color: #666666; font-style: italic;">// I think array_count_values actually returns in this format</span>
    <span style="color: #666666; font-style: italic;">// already, but the manual doesn't mention it.</span>
    <span style="color: #990000;">arsort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequencies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$isFirst</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Yuk</span>
    <span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequencies</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$thisValue</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$thisFrequency</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: #000088;">$isFirst</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$isFirst</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Wince</span>
            <span style="color: #000088;">$mode</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thisValue</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$modeFrequency</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thisFrequency</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$modeFrequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$thisFrequency</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$mode</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thisValue</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$modeFrequency</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$thisFrequency</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">break</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;">$mode</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>array_mode<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array(1) {
  [0]=&gt;
  string(1) &quot;a&quot;
}
*/</span>
&nbsp;
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>array_mode<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array(2) {
  [0]=&gt;
  string(1) &quot;a&quot;
  [1]=&gt;
  string(1) &quot;b&quot;
}
*/</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2007/05/03/104903/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magners</title>
		<link>http://www.twisty.com/bandwagon/archives/2007/04/29/103203</link>
		<comments>http://www.twisty.com/bandwagon/archives/2007/04/29/103203#comments</comments>
		<pubDate>Sun, 29 Apr 2007 09:32:03 +0000</pubDate>
		<dc:creator>Tim Brayshaw</dc:creator>
				<category><![CDATA[Bristol]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/archives/2007/04/29/103203</guid>
		<description><![CDATA[mankners&#8230;, originally uploaded by i y e r s. My thoughts precisely. It&#8217;s depressing how this stuff has become so popular when there&#8217;s such a variety of decent local cider producers within a 25 mile radius of Bristol. Given the food-miles accumulated importing apples from the UK, France and the Netherlands to Ireland and shipping [...]]]></description>
				<content:encoded><![CDATA[<p><a title="photo sharing" href="http://www.flickr.com/photos/i_y_e_r_s/474471473/"><img src="http://farm1.static.flickr.com/178/474471473_febbb1e3c8.jpg" /></a></p>

<p><a href="http://www.flickr.com/photos/i_y_e_r_s/474471473/">mankners&#8230;</a>, originally uploaded by <a href="http://www.flickr.com/people/i_y_e_r_s/">i y e r s</a>.</p>

<p>My thoughts precisely. It&#8217;s depressing how this stuff has become so popular when there&#8217;s such a variety of decent local cider producers within a 25 mile radius of Bristol.</p>

<p>Given the food-miles accumulated importing apples from the <a href="http://news.independent.co.uk/business/news/article1269438.ece">UK, France and the Netherlands</a> to Ireland and shipping them back as cider, its a tad ironic that they have to <a href="http://www.dailymail.co.uk/pages/live/articles/news/news.html?in_article_id=394737&amp;in_page_id=1770">import CO<sub>2</sub> from Poland</a> to make it fizzy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2007/04/29/103203/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone</title>
		<link>http://www.twisty.com/bandwagon/archives/2007/01/12/021649</link>
		<comments>http://www.twisty.com/bandwagon/archives/2007/01/12/021649#comments</comments>
		<pubDate>Fri, 12 Jan 2007 01:16:49 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/archives/2007/01/12/021649</guid>
		<description><![CDATA[Remove the phone cruft; add some sensible storage for a media player, and I&#8217;ll buy one!]]></description>
				<content:encoded><![CDATA[<p>Remove the phone cruft; add some sensible storage for a media player, and I&#8217;ll buy one!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2007/01/12/021649/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Macworld Wishes</title>
		<link>http://www.twisty.com/bandwagon/archives/2007/01/08/011553</link>
		<comments>http://www.twisty.com/bandwagon/archives/2007/01/08/011553#comments</comments>
		<pubDate>Mon, 08 Jan 2007 00:15:53 +0000</pubDate>
		<dc:creator>Tim Brayshaw</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/archives/2007/01/08/011553</guid>
		<description><![CDATA[Everyone seems to be up to it at the moment, so here&#8217;s what I&#8217;d like to see announced at Macworld Expo this year&#8230; A refund to anyone that has ever paid money for .mac That&#8217;s all.]]></description>
				<content:encoded><![CDATA[<p>Everyone seems to be up to it at the moment, so here&#8217;s what I&#8217;d like to see announced at Macworld Expo this year&#8230;</p>

<ol>
    <li>A refund to anyone that has ever paid money for .mac</li>
</ol>

<p>That&#8217;s all.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2007/01/08/011553/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy Day of Slav Letters in Bulgaria</title>
		<link>http://www.twisty.com/bandwagon/archives/2006/05/24/114740</link>
		<comments>http://www.twisty.com/bandwagon/archives/2006/05/24/114740#comments</comments>
		<pubDate>Wed, 24 May 2006 10:47:40 +0000</pubDate>
		<dc:creator>Tim Brayshaw</dc:creator>
				<category><![CDATA[Foo]]></category>
		<category><![CDATA[Typography]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/?p=242</guid>
		<description><![CDATA[Today is the &#8220;Day of Slav Letters in Bulgaria&#8221;. I&#8217;m not Bulgarian, and have never been there, and definitely can&#8217;t spell your name in Bulgarian for a school project. I just like the idea of holding a national holiday to celebrate letter-forms and their creators, like Korean Alphabet Day.]]></description>
				<content:encoded><![CDATA[<p>Today is the &#8220;Day of Slav Letters in Bulgaria&#8221;. I&#8217;m not Bulgarian, and have never been there, and definitely can&#8217;t spell your name in Bulgarian for a school project. I just like the idea of holding a national holiday to celebrate letter-forms and <a href="http://en.wikipedia.org/wiki/Saints_Cyril_and_Methodius">their creators</a>, like <a href="http://www.twisty.com/bandwagon/archives/2003/10/09/200339">Korean Alphabet Day</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2006/05/24/114740/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Preview Markdown Documents in BBEdit</title>
		<link>http://www.twisty.com/bandwagon/archives/2005/10/31/195241</link>
		<comments>http://www.twisty.com/bandwagon/archives/2005/10/31/195241#comments</comments>
		<pubDate>Mon, 31 Oct 2005 18:52:41 +0000</pubDate>
		<dc:creator>Tim Brayshaw</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Markup and CSS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.twisty.com/bandwagon/?p=241</guid>
		<description><![CDATA[A quickie: here&#8217;s a way of directly previewing Markdown documents in the BBEdit preview window using PHP. (Inspired by this Python method that does the same thing). Make a template file (you&#8217;ll probably want to add some styles to this). ~/Sites/markdown-preview/template.html 1 2 3 4 5 6 7 8 9 10 11 &#60;!DOCTYPE html PUBLIC [...]]]></description>
				<content:encoded><![CDATA[<p>A quickie: here&#8217;s a way of directly previewing <a href="http://daringfireball.net/projects/markdown/">Markdown</a> documents in the <a href="http://www.barebones.com/products/bbedit/">BBEdit</a> preview window using <a href="http://www.php.net/">PHP</a>. (Inspired by this <a href="http://blog.mostrom.pp.se/?p=63" title="Preview Markdown documents using BBEdit">Python method</a> that does the same thing).</p>

<ol>
<li><p>Make a template file (you&#8217;ll probably want to add some styles to this).</p>
<p><em>~/Sites/markdown-preview/template.html</em></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1//EN&quot;</span>
<span style="color: #00bbdd;">        &quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content-type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Markdown Preview<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
##markdown##
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>


</li>
<li><p>Make the php file, and follow the instructions in the PHP comments.</p>
<p><em>~/Sites/markdown-preview/index.php</em></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Download these and put them somewhere in your php path:
 *
 *     &lt;a href=&quot;http://www.michelf.com/projects/php-markdown/&quot;&gt;http://www.michelf.com/projects/php-markdown/&lt;/a&gt;
 *     &lt;a href=&quot;http://www.michelf.com/projects/php-smartypants/&quot;&gt;http://www.michelf.com/projects/php-smartypants/&lt;/a&gt;
 */</span>
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'markdown.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'smartypants.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * You'll need to change this:
 */</span>
<span style="color: #000088;">$markdownDocsDir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'MARKDOWN_DOCS_DIR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'MARKDOWN_DOCS_DIR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'/Users/username/Documents'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * You'll need to set up BBEdit to use something like this as the Preview Server URL:
 *
 *     http://localhost/markdown-preview/?file=/
 */</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$markdownDocsDir</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$formatted</span> <span style="color: #339933;">=</span> SmartyPants<span style="color: #009900;">&#40;</span>Markdown<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Display the formatted text via a simple template.
 */</span>
<span style="color: #000088;">$templateFile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./template.html'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$templateText</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_exists</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$templateFile</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">file_get_contents</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$templateFile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;##markdown##&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">str_replace</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'##markdown##'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$formatted</span><span style="color: #339933;">,</span> <span style="color: #000088;">$templateText</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.twisty.com/bandwagon/archives/2005/10/31/195241/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching using disk: basic

 Served from: www.twisty.com @ 2013-06-19 20:42:15 by W3 Total Cache -->