<?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>#!</title>
	<atom:link href="http://hash-bang.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://hash-bang.net</link>
	<description>The start of all wonderful things</description>
	<lastBuildDate>Mon, 30 Apr 2012 00:28:33 +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>Weather or not</title>
		<link>http://hash-bang.net/2011/05/weather-or-not/</link>
		<comments>http://hash-bang.net/2011/05/weather-or-not/#comments</comments>
		<pubDate>Sun, 15 May 2011 03:36:16 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=180</guid>
		<description><![CDATA[Ok, seriously. Can&#8217;t we master simple PHP classes like a sensible weather data retrieval library? I&#8217;ve tried a few solutions but all of them suck due to poor documentation (PHP Weather I&#8217;m looking at you), jingoistic support for only USA airports (PHPWeatherLib) or being otherwise perfect but too simplistic (Google Weather API). Herein lies a [...]]]></description>
				<content:encoded><![CDATA[<p>Ok, seriously. Can&#8217;t we master simple PHP classes like a sensible weather data retrieval library?</p>
<p>I&#8217;ve tried a few solutions but all of them suck due to poor documentation (<a href="http://phpweather.sourceforge.net/">PHP Weather</a> I&#8217;m looking at you), jingoistic support for only USA airports (<a href="http://www.ebrueggeman.com/phpweatherlib/">PHPWeatherLib</a>) or being otherwise perfect but too simplistic (<a href="http://blog.programmableweb.com/2010/02/08/googles-secret-weather-api/">Google Weather API</a>).</p>
<p><a href="https://github.com/hash-bang/PHP-Wunderground">Herein lies a GitHub submission for a simple weather forecast wrapper</a> around <a href="http://www.wunderground.com/">Weather Underground</a>&#8216;s beautifully simple API.<br />
Its designed to be as simplistic as possible while still providing some handy functionality.<br />
I&#8217;ll probably keep adding to its functionality as needed.</p>
<p>Documentation is provided inline (<a href="http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.pkg.html">PHPDoc</a>) as well as in the docs folder with fancy frames and such.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2011/05/weather-or-not/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple bash variable security with OpenSSL</title>
		<link>http://hash-bang.net/2010/11/bash-security-with-openssl/</link>
		<comments>http://hash-bang.net/2010/11/bash-security-with-openssl/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 05:25:10 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=171</guid>
		<description><![CDATA[Lets say you have a script that requires a number of variables to operate such as a database connection that requires a server, username and password. It&#8217;s usually a good idea to keep all this config in one place but dumping this in a plain text file is usually a bad idea. The example below [...]]]></description>
				<content:encoded><![CDATA[<p>Lets say you have a script that requires a number of variables to operate such as a database connection that requires a server, username and password. It&#8217;s usually a good idea to keep all this config in one place but dumping this in a plain text file is usually a bad idea.<br />
The example below allows you to place application level config into a decently encrypted file and keep it all behind one master password.<br />
To do all this we need two files. The first is obviously the encrypted variable config itself. The second is your script file which needs to decrypt the config file and perform whatever action is needed.</p>
<p>In this example I&#8217;m going to assume we are connecting to a remote database. Most protocols require three pieces of data to pull this off: a server, a username and a password. We are going to store these three pieces of data in a file called <i>config.plain</i>, encrypt this file (making <i>config.aes</i>), extract its variables and finally connect to our remote database.</p>
<p>I&#8217;m going to use the following example <i>config.plain</i> file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=171&amp;download=config.plain">config.plain</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1717"><td class="code" id="p171code7"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SERVER</span>=FooBar
<span style="color: #007800;">USER</span>=JOE
<span style="color: #007800;">PASS</span>=RANDOM</pre></td></tr></table></div>

<p>So we need to encrypt our config.plain file and turn it into config.aes (AES being the encryption standard we are using). The following example is cheerfully swiped from the example given over at <a href="http://tombuntu.com/index.php/2007/12/12/simple-file-encryption-with-openssl/">Tombuntu</a>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p171code8'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1718"><td class="code" id="p171code8"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span>openssl aes-<span style="color: #000000;">256</span>-cbc <span style="color: #660033;">-a</span> <span style="color: #660033;">-salt</span> <span style="color: #660033;">-in</span> config.plain <span style="color: #660033;">-out</span> config.aes</pre></td></tr></table></div>

<p>So if we wanted to reverse this and decrypt the config.aes file on the command line we could run:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p171code9'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1719"><td class="code" id="p171code9"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span>openssl aes-<span style="color: #000000;">256</span>-cbc <span style="color: #660033;">-d</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-salt</span> <span style="color: #660033;">-in</span> config.aes</pre></td></tr></table></div>

<p><b>NOTE:</b> For some reason the OpenSSL CLI doesn&#8217;t obey the Unix standard of specifying &#8216;-&#8217; as a file name to output to the console. Omitting the &#8216;-out&#8217; argument will instead output to STDOUT.</p>
<h1>Putting it all together</h1>
<p>The <i>config.plain</i> example file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=171&amp;download=config.plain">config.plain</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17110"><td class="code" id="p171code10"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SERVER</span>=FooBar
<span style="color: #007800;">USER</span>=JOE
<span style="color: #007800;">PASS</span>=RANDOM</pre></td></tr></table></div>

<p>The <i>config.aes</i> file (same as above but after encryption using the password &#8216;password&#8217;):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=171&amp;download=config.aes">config.aes</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17111"><td class="code" id="p171code11"><pre class="text" style="font-family:monospace;">U2FsdGVkX19aTdTnSuV1p5R6DCQxp21yrlCc+9j9dap/ziojbiDP1SbSM+6HXF0T
PabsGQgSdV8Ir4rmMjgyFA==</pre></td></tr></table></div>

<p>The actual <i>script</i> file which does the decryption and performs the final actions on the data.<br />
We are going to accept the master password from the command line (so we would run the below as &#8216;script password&#8217; &#8211; assuming our script was called &#8216;script&#8217; and the password was &#8216;password&#8217;). This is not the most secure method available since you can see the launch method of all applications running on the system using &#8216;ps&#8217;. If you want more security I would instead store your password in a system variable and use that instead of reading from the command line. If you wish to do this you can simply strip out all the lines that do error checking and use &#8216;KEY&#8217; as a system variable to store the master password.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=171&amp;download=script">script</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17112"><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
</pre></td><td class="code" id="p171code12"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># USAGE: script &lt;password&gt;</span>
<span style="color: #666666; font-style: italic;"># Do something with the associated config.aes script in a reasonably secure way</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Example config.plain content:</span>
<span style="color: #666666; font-style: italic;"># SERVER=FooBar</span>
<span style="color: #666666; font-style: italic;"># USER=JOE</span>
<span style="color: #666666; font-style: italic;"># PASS=RANDOM</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Command to encrypt config.plain -&gt; config.aes</span>
<span style="color: #666666; font-style: italic;"># openssl aes-256-cbc -a -salt -in config.plain -out config.aes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Do some housekeeping to check we launched with the requisite number of arguments</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$#&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;USAGE: $0 &lt;password&gt;&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #007800;">KEY</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Import the variables from our decrypted stream</span>
<span style="color: #007800;">STREAM</span>=<span style="color: #000000; font-weight: bold;">`</span>openssl aes-<span style="color: #000000;">256</span>-cbc <span style="color: #660033;">-d</span> <span style="color: #660033;">-pass</span> <span style="color: #ff0000;">&quot;pass:<span style="color: #007800;">$KEY</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-salt</span> <span style="color: #660033;">-in</span> config.aes<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Invalid password specified to decrypt configuration file. Aborting.&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$STREAM</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># REPLACE THE STUFF BELOW THIS LINE WITH WHAT YOU WANT TO DO WITH YOUR SECURE VARIABLES</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Server: <span style="color: #007800;">$SERVER</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Username: <span style="color: #007800;">$USER</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Password: <span style="color: #007800;">$PASS</span>&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2010/11/bash-security-with-openssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last.FM submissions with Audacious</title>
		<link>http://hash-bang.net/2010/06/lastfm-with-audacious/</link>
		<comments>http://hash-bang.net/2010/06/lastfm-with-audacious/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 00:35:10 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[Fixes]]></category>
		<category><![CDATA[Audacious]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=162</guid>
		<description><![CDATA[Some time ago the good folks behind my favorite media player Audacious decided to abandon in-built support for Last.FM submissions. The reasoning behind this seems to be that the Last.FM API was becoming a little too much to maintain which I suppose is fair enough in its quest to remain just a music player i.e. [...]]]></description>
				<content:encoded><![CDATA[<p>Some time ago the good folks behind my favorite media player <a href="http://audacious-media-player.org/">Audacious</a> decided to abandon in-built support for Last.FM submissions.</p>
<p>The reasoning behind this seems to be that the Last.FM API was <a href="https://bugs.launchpad.net/ubuntu/+source/audacious-plugins/+bug/568651">becoming a little too much to maintain</a> which I suppose is fair enough in its quest to remain <em>just a music player</em> i.e. not a screen-hogging iTunes clone like so many others.</p>
<p>Heres how to put Last.FM support back into Audacity.</p>
<p>I&#8217;m going to assume you are a sensible person and using a Debian based system rather than Fedora. If you are one of these hat loving deviants, substitute &#8216;yum&#8217; for apt-get below and feel free to voyage though the countless pains required to get Yum to actually do its job.</p>
<h2>Installing LastFMSubmitD</h2>
<p>I&#8217;m not sure on the capitalization of the daemon process LastFMSubmitD so that might be the wrong name entirely.</p>
<p>Anyway, first install pretty much the only component we need:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p162code16'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p16216"><td class="code" id="p162code16"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> lastfmsubmitd</pre></td></tr></table></div>

<h2>OPTIONAL &#8211; Set up the HTTP_PROXY</h2>
<p>For some reason the daemon does not get proxy details right. This is easily fixed by opening <em>/etc/init.d/lastfmsubmitd</em> in your favorite editor and inserting the following line somewhere near the top (I put it after the &#8216;GROUP=&#8217; line which should be the last bit of the daemon config area).<br />
If you have no idea what a proxy is or why you should be doing this you can probably skip this section.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p162code17'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p16217"><td class="code" id="p162code17"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">http_proxy</span>=<span style="color: #ff0000;">&quot;http://whatever.stupid.proxy.edu.au:8080/&quot;</span></pre></td></tr></table></div>

<h2>Parse Audacious output</h2>
<p>Dump the following script somewhere you can find it. For this example I will use <em>/home/user/bin/scrobble</em></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=162&amp;download=scrobble">scrobble</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p16218"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p162code18"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-x</span> <span style="color: #ff0000;">'/usr/lib/lastfmsubmitd/lastfmsubmit'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;LastFMSubmitD does not appear to exist on this machine&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;You can install it using Apt or Yum&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$#&quot;</span> == <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Usage: scrobble &quot;&lt;artist&gt; - &lt;song&gt;&quot; &quot;&lt;length&gt;&quot;'</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">ARTIST</span>=<span style="color: #800000;">${1%% - *}</span>
<span style="color: #007800;">SONG</span>=<span style="color: #800000;">${1##* - }</span>
<span style="color: #007800;">LENGTH</span>=$<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$2</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1000</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ARTIST = [<span style="color: #007800;">$ARTIST</span>]&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SONG = [<span style="color: #007800;">$SONG</span>]&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;LENGTH = [<span style="color: #007800;">$LENGTH</span>]&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>lastfmsubmitd<span style="color: #000000; font-weight: bold;">/</span>lastfmsubmit <span style="color: #660033;">--artist</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ARTIST</span>&quot;</span> <span style="color: #660033;">--title</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SONG</span>&quot;</span> <span style="color: #660033;">--length</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$LENGTH</span>&quot;</span></pre></td></tr></table></div>

<h2>Pointing Song Change at your script</h2>
<p>First make sure you have the Song Change plugin enabled in Audacious first.</p>
<p>Now point the command Audacious is to run when starting a new song at the script in the following way:</p>
<pre>
/home/user/bin/scrobble "%s" "%l"
</pre>
<p>All done. Now any tracks played via Audacious will be passed to the script which will parse the incoming song title into a format that the LastFMSubmitD daemon can use.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2010/06/lastfm-with-audacious/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Interactive file merging with Unison</title>
		<link>http://hash-bang.net/2009/08/ia-merging-unison/</link>
		<comments>http://hash-bang.net/2009/08/ia-merging-unison/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 03:23:48 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Unison]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=151</guid>
		<description><![CDATA[After trying in vein to find decent documentation on the Merge functionality of Unison I eventually gave in and invested an hour or two trying out different Linux based merge programs in order to find something Unison, the merge program and I were happy with. So onto the diff-merging candidates: VimDiff (part of Vim) Doesn&#8217;t [...]]]></description>
				<content:encoded><![CDATA[<p>After trying in vein to find decent documentation on the Merge functionality of <a href="http://www.cis.upenn.edu/~bcpierce/unison/">Unison</a> I eventually gave in and invested an hour or two trying out different Linux based merge programs in order to find something Unison, the merge program and I were happy with.</p>
<p>So onto the diff-merging candidates:</p>
<h2><a href="http://linux.about.com/library/cmd/blcmdl1_vimdiff.htm">VimDiff</a> (part of <a href="http://www.vim.org/">Vim</a>)</h2>
<p>Doesn&#8217;t work too well with Unison. I can&#8217;t get <a href="http://en.wikipedia.org/wiki/GNOME_Terminal">gnome-terminal</a> (my terminal of choice) to execute synchronously so I was forced to fall back on <a href="http://invisible-island.net/xterm/">XTerm</a> instead.</p>
<p>After using XTerm I immediately hit upon a problem: there is no sensible way of outputting the results of a merge in VimDiff. Which is a pity because I do prefer VIM as an editor but this lack of functionality is annoying (yes I could have used a wrapper script but I&#8217;m trying to keep this simple).</p>
<h2><a href="http://meld.sourceforge.net/">Meld</a></h2>
<p>Very pretty but lacks features such as &#8216;Use Left-hand-side-file for all changes&#8217; and some of the other filtering options provided by KDiff3.</p>
<p>Also, like, VimDiff, does not provide any sensible output mechanism of the eventually merged file.</p>
<h2><a href="http://kdiff3.sourceforge.net/">KDiff3</a></h2>
<p>Not as good looking as Meld but provides pretty much everything I want in a merge program including the all important merged file output that Unison requires.</p>
<p>Can get a little annoying though with its insentient pop-up boxes. I wish there were a &#8216;Dont show this option again&#8217; option to each. KDE is usually quite good with this so I&#8217;m not sure why KDiff3 managed to escape this unspoken standard.</p>
<h2>Conclusion</h2>
<p>So how to use KDiff3 with Unison? First install kdiff3:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p151code21'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15121"><td class="code" id="p151code21"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> kidff3</pre></td></tr></table></div>

<p>Then open your Unison profiles .prf file and insert the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p151code22'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15122"><td class="code" id="p151code22"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">merge</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Name * -&gt; kdiff3 CURRENT1 CURRENT2 -L1 'Local File' -L2 'Remote File' -o NEW -m</span>
<span style="color: #000099;">confirmmerge</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span></pre></td></tr></table></div>

<p>If you are comfortable with KDiff3 you could remove the &#8216;confirmmerge&#8217; line which forces Unison to double check you actually want to accept the changes.</p>
<p>The downside to the above interactive merging process is there is no sensible way to preview the merge in Unison (the &#8216;View Merge&#8217; button in the confirmation dialogue). For now though its preferable to not having this functionality at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/08/ia-merging-unison/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Converting Null</title>
		<link>http://hash-bang.net/2009/04/converting-null/</link>
		<comments>http://hash-bang.net/2009/04/converting-null/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 03:49:01 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[Fixes]]></category>
		<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Filters]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=136</guid>
		<description><![CDATA[Simple shell script fix this week &#8211; convert all newlines to null characters. Since most Linux shells have a major problem with doing this in a sensible way, the following (on my box called simply &#8217;0&#8242;) takes any input (either from files or via a pipe) and converts the characters. ?View Code PERL1 2 3 [...]]]></description>
				<content:encoded><![CDATA[<p>Simple shell script fix this week &#8211; convert all newlines to null characters.</p>
<p>Since most Linux shells have a major problem with doing this in a sensible way, the following (on my box called simply &#8217;0&#8242;) takes any input (either from files or via a pipe) and converts the characters.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code27'); return false;">View Code</a> PERL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13627"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p136code27"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #666666; font-style: italic;"># From: http://hash-bang.net/2009/04/converting-nullconverting-null/</span>
<span style="color: #666666; font-style: italic;"># Author: Matt Carter &lt;m@ttcarter.com&gt;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009966; font-style: italic;">s/\n/\x00/g</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">print</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So now commands like:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code28'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13628"><td class="code" id="p136code28"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #660033;">-type</span> f <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">mplayer</span></pre></td></tr></table></div>

<p>work perfectly (in the above case to play all files in directories recursively.</p>
<p>You may well ask why I don&#8217;t use the simple &#8216;-print0&#8242; argument for the find program &#8211; because it doesn&#8217;t work when using later pipes.</p>
<p>For example if i wanted to sort the above, &#8216;sort&#8217; would see the null symbol as a regular character.</p>
<p>So &#8217;0&#8242; works nicely in this case:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code29'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13629"><td class="code" id="p136code29"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #660033;">-type</span> f <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">mplayer</span></pre></td></tr></table></div>

<p>Or even:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code30'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13630"><td class="code" id="p136code30"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #660033;">-type</span> f <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">|</span> shuffle <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">mplayer</span></pre></td></tr></table></div>

<p>To play all files recursively, in random order. See the article on <a href="http://hash-bang.net/2009/04/shuffling-shell-input/">shuffle</a> for the source code of that filter.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/04/converting-null/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shuffling shell input</title>
		<link>http://hash-bang.net/2009/04/shuffling-shell-input/</link>
		<comments>http://hash-bang.net/2009/04/shuffling-shell-input/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 04:10:02 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Filters]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=144</guid>
		<description><![CDATA[While the Fisher-Yates shuffle sounds like 1920&#8242;s dance move, it is the standard method for shuffling larger arrays of data. The below operates like a simple Unix filter taking an array of data (separated by newlines) and returning a quickly sorted output. ?Download shuffle1 2 3 4 5 6 7 8 9 10 11 12 [...]]]></description>
				<content:encoded><![CDATA[<p>While the <a href="http://en.wikipedia.org/wiki/Fisher-Yates_shuffle">Fisher-Yates shuffle</a> sounds like 1920&#8242;s dance move, it is the standard method for shuffling larger arrays of data.</p>
<p>The below operates like a simple Unix filter taking an array of data (separated by newlines) and returning a quickly sorted output.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=144&amp;download=shuffle">shuffle</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14433"><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
</pre></td><td class="code" id="p144code33"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #666666; font-style: italic;"># Usage: cat file | shuffle</span>
<span style="color: #666666; font-style: italic;"># From: http://hash-bang.net/2009/04/shuffling-shell-inputshuffling-shell-input/</span>
<span style="color: #666666; font-style: italic;"># Return a shuffled version of the input stream</span>
<span style="color: #666666; font-style: italic;"># Author: Matt Carter &lt;m@ttcarter.com&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> fisher_yates_shuffle <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$array</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@$array</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span><span style="color: #0000ff;">$i</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$j</span> <span style="color: #339933;">=</span> <span style="color: #000066;">int</span> <span style="color: #000066;">rand</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">next</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$j</span><span style="color: #339933;">;</span>
		<span style="color: #0000ff;">@$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$j</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">chomp</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">push</span> <span style="color: #0000ff;">@input</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">&amp;fisher_yates_shuffle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">\@input</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">@input</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>For example:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p144code34'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14434"><td class="code" id="p144code34"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">|</span> shuffle</pre></td></tr></table></div>

<p>Returns a randomized list of files in the current directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/04/shuffling-shell-input/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Easy Apache VirtualHost config</title>
		<link>http://hash-bang.net/2009/03/easy-apache-virtualhost/</link>
		<comments>http://hash-bang.net/2009/03/easy-apache-virtualhost/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 11:23:13 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=127</guid>
		<description><![CDATA[Like most of the word I use Apache to serve up both my live and test websites. The downside to having a box for development though is the constant config of apache to host these sites, most of which require absolute links (e.g. &#8216;/css/style.css&#8217;) to function. The Apache snippet below sets up dynamic sub-domains which [...]]]></description>
				<content:encoded><![CDATA[<p>Like <a href="http://news.netcraft.com/archives/web_server_survey.html">most of the word</a> I use <a href="http://httpd.apache.org/">Apache</a> to serve up both my live and test websites.</p>
<p>The downside to having a box for development though is the constant config of apache to host these sites, most of which require absolute links (e.g. &#8216;/css/style.css&#8217;) to function.</p>
<p>The Apache snippet below sets up dynamic sub-domains which can be changed <i>without</i> reloading Apache every time you add, remove or update anything something. Simply drop your sites inside /var/www whenever you want a new subdomain. Alternatively you can symlink if they are hosted elsewhere on the box.</p>
<p>Its pretty easy to install, simply paste the below in your /etc/apache2/apache.conf file&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=127&amp;download=apache-conf-snippet.txt">apache-conf-snippet.txt</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12737"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p127code37"><pre class="text" style="font-family:monospace;"># Easy virtual host config
# See http://hash-bang.net/2009/03/easy-apache-virtualhosteasy-apache-virtualhost/
&lt;VirtualHost *&gt;
DocumentRoot /var/www/
ServerAdmin admin@localhost
Options +FollowSymLinks -Indexes
LogLevel debug
ServerAlias localhost
ServerName localhost
RewriteEngine  on
RewriteLogLevel 3
RewriteCond    %{HTTP_HOST}  ^localhost
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^www.*
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^(.*)\.localhost
RewriteRule    ^(.*)$        /%1/$1 [L]
&lt;/VirtualHost&gt;</pre></td></tr></table></div>

<p>Now add your servers to the /etc/hosts file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=127&amp;download=hosts-snippet">hosts-snippet</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12738"><td class="code" id="p127code38"><pre class="text" style="font-family:monospace;">127.0.0.1      server.localhost</pre></td></tr></table></div>

<p>Now any directory you place in the /var/www directory automatically becomes a subdomain. You can now visit http:///server.localhost as a fully fledged webhost.</p>
<p>If you want to use another name than the rather boring &#8216;localhost&#8217; simply replace the text in both text pastes above.</p>
<p>If only there were a way of removing that /etc/hosts hack it would mean zero config from then on. If anyone has any ideas do let me know. The addition to the hosts file seems to need applying if you are working from the same box the Apache server resides on. If you arn&#8217;t and the box is a local dedicated server its not needed at all and domains can be added and removed as necessary.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/03/easy-apache-virtualhost/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trash with Bash</title>
		<link>http://hash-bang.net/2009/03/trash-with-bash/</link>
		<comments>http://hash-bang.net/2009/03/trash-with-bash/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 05:15:15 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=121</guid>
		<description><![CDATA[One of the regrettably unavoidable aspects of the Unix shell like environments is the impedance between what a user says and what a user means. While this is present in all computing environments the sheer power of Unix based command lines make a potential mistake catastrophic. Who amongst us has not at some point done [...]]]></description>
				<content:encoded><![CDATA[<p>One of the regrettably unavoidable aspects of the Unix shell like environments is the impedance between what a user <i>says</i> and what a user <i>means</i>. While this is present in all computing environments the sheer power of Unix based command lines make a potential mistake catastrophic.</p>
<p>Who amongst us has not at some point done something like:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code42'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12142"><td class="code" id="p121code42"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">*</span> .tmp</pre></td></tr></table></div>

<p>or</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p121code43'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12143"><td class="code" id="p121code43"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">*&gt;</span>tmp</pre></td></tr></table></div>

<p>The former makes the mistake of a space between the dot and the &#8216;tmp&#8217; part and the latter the accidental holding down of the shift key while pressing the intended full stop.</p>
<p>While searching for an alternative for the I-have-done-this-too-many-times-and-now-its-embarrassing approach of nuking everything with the &#8216;rm&#8217; command its time i did something about it.</p>
<p>Inserting the following in your ~/.bashrc file will remap the &#8216;rm&#8217; command to a slightly safer move-to-trash like behavior. Its not comprehensive but it has saved my life on more than one occasion.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=121&amp;download=.bashrc">.bashrc</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12144"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p121code44"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Trash support by Matt Carter &lt;m@ttcarter.com</span>
<span style="color: #666666; font-style: italic;"># Source and information: http://hash-bang.net/2009/03/trash-with-bash</span>
<span style="color: #000000; font-weight: bold;">function</span> trash<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.trashcan/$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #666666; font-style: italic;"># Already exists in bin - remove</span>
		<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.trashcan/$1&quot;</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #660033;">--target-directory</span>=<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.trashcan<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">--</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #ff0000;">&quot;rm=trash&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #ff0000;">&quot;emptytrash=/bin/rm -rf <span style="color: #007800;">$HOME</span>/.trashcan/* <span style="color: #007800;">$HOME</span>/.trashcan/.??*&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #ff0000;">'rm!=/bin/rm -r'</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>.trashcan <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></td></tr></table></div>

<p>Now the command &#8216;rm&#8217; moves files into ~/.trashcan. You can also use the command &#8216;rm!&#8217; when you really mean delete immediately and the utility command &#8216;emptytrash&#8217; to clean everything out.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/03/trash-with-bash/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Error reporting with CodeIgniter</title>
		<link>http://hash-bang.net/2009/02/error-reporting-with-ci/</link>
		<comments>http://hash-bang.net/2009/02/error-reporting-with-ci/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 02:38:46 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Helpers]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=100</guid>
		<description><![CDATA[While CodeIgniter does come with a reasonable error logging tool its simple nature of just dumping a single line report to a file on a distant server does not seem too pro-active for my tastes. The following helper replaces the default CI error reporting with a new error reporting interface that also emails any errors [...]]]></description>
				<content:encoded><![CDATA[<p>While CodeIgniter does come with a reasonable error logging tool its simple nature of just dumping a single line report to a file on a distant server does not seem too pro-active for my tastes.</p>
<p>The following helper replaces the default CI error reporting with a new error reporting interface that also emails any errors that occur to a nominated developer.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=100&amp;download=err_helper.php">err_helper.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10047"><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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
</pre></td><td class="code" id="p100code47"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
* Sensibly report of errors that occur in the system by sending that
* error to the developer
* Author: Matt Carter &lt;m@ttcarter.com&gt;
* Info: http://hash-bang.net/2009/02/error-reporting-with-cierror-reporting-with-ci/
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Where to send the error report. Leave blank for nowhere</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_TO'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'someone@somewhere.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// Literal name of that person</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_TO_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Joe Random'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_FROM'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root@freesweetsite.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_FROM_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Error Daemon'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_METHOD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'SMTP'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Supported: SMTP</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_SENDER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root@somewhere.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// The subject of the mail. Supported tags: [TYPE], [FILE], [LINE], [STRING], [BASENAME]</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_SUBJECT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Error detected: [TYPE] @ [BASENAME]:[LINE]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">// Other things of interest to include in the email. CSV of supported values: POST, GET, SERVER, GLOBALS, SESSION</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_FOOTERS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'POST,GET,SESSION'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Relative location of PHP mailer to this file</span>
<span style="color: #666666; font-style: italic;">// (Not relative to the working directory because that doesn't specify correctly with fatal errors).</span>
<span style="color: #666666; font-style: italic;">// By default this assumes that the 'phpMailer' folder is located in the same directory as this script.</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_PATH_PHPMAILER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'phpMailer/class.phpmailer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> err<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errline</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errcontext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$errtable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Fatal'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">4</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Parse Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">8</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Notice'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">16</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Core Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">32</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Core Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">64</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Compile Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">128</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Compile Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">256</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">512</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">1024</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Notice'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">2048</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Strict Notice'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">4096</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Recoverable Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">8192</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Deprecated'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">16384</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Deprecated'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;style&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-box {border: 1px solid #4A98AF}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table th {background: #4A98AF; text-align: right; white-space: nowrap}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table td, .err-table th {padding: 5px}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table-stack th {background: #4A98AF; text-align: left}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table-stack th, .err-table-stack td {font-size: 12px}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/style&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>err-box<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;table class=<span style="color: #000099; font-weight: bold;">\&quot;</span>err-table<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th width=<span style="color: #000099; font-weight: bold;">\&quot;</span>100px<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Type:&lt;/th&gt;&lt;td&gt;{<span style="color: #006699; font-weight: bold;">$errtable</span>[<span style="color: #006699; font-weight: bold;">$errno</span>]}&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;Error:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errstr</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;File:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errfile</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;Line:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errline</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;Context:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errcontext</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$traces</span> <span style="color: #339933;">=</span> <span style="color: #990000;">debug_backtrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'err_shutdown'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Ignore fatal shutdown traces</span>
		<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;table width=<span style="color: #000099; font-weight: bold;">\&quot;</span>100%<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>err-table-stack<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;tr&gt;&lt;th width=<span style="color: #000099; font-weight: bold;">\&quot;</span>50px<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Line&lt;/th&gt;&lt;th&gt;Function&lt;/th&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$offset</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$trace</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Calculate line number</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// First in trace</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td style=<span style="color: #000099; font-weight: bold;">\&quot;</span>text-align: center<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$errline</span>&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Nth in trace</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td style=<span style="color: #000099; font-weight: bold;">\&quot;</span>text-align: center<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'&amp;nbsp;'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// Calculate arg stack</span>
			<span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'args'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'args'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'args'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$arg</span><span style="color: #009900;">&#41;</span>
					<span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> _err_human<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' , '</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// Output context</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'object'</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: #666666; font-style: italic;">// Object error</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$trace['class']}</span>-&gt;<span style="color: #006699; font-weight: bold;">{$trace['function']}</span>(<span style="color: #006699; font-weight: bold;">{$trace['argstack']}</span>)&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Function error</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$trace['function']}</span>(<span style="color: #006699; font-weight: bold;">{$trace['argstack']}</span>)&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ERR_MAIL_TO<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;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> ERR_PATH_PHPMAILER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Cannot find PHP mailer at the relative path '&quot;</span> <span style="color: #339933;">.</span> ERR_PATH_PHPMAILER <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'. Make sure it is located there to send mails&quot;</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: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PhpMailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ERR_MAIL_METHOD <span style="color: #339933;">==</span> <span style="color: #0000ff;">'SMTP'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsSMTP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsHTML</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CharSet</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'utf-8'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span> <span style="color: #339933;">=</span> ERR_MAIL_HOST<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Sender</span> <span style="color: #339933;">=</span> ERR_MAIL_SENDER<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">From</span> <span style="color: #339933;">=</span> ERR_MAIL_FROM<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FromName</span> <span style="color: #339933;">=</span> ERR_MAIL_FROM_NAME<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span>ERR_MAIL_TO<span style="color: #339933;">,</span> ERR_MAIL_TO_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtr</span><span style="color: #009900;">&#40;</span>ERR_MAIL_SUBJECT<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'[TYPE]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errtable</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$errno</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[FILE]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[BASENAME]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[LINE]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errline</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[STRING]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$extras</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\s*,\s*/'</span><span style="color: #339933;">,</span> ERR_MAIL_FOOTERS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Get'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SESSION'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SESSION</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: #0000ff;">'Session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SERVER'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Server'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBALS'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GLOBALS</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Globals'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Catch fatal errors</span>
<span style="color: #000000; font-weight: bold;">function</span> err_shutdown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #990000;">error_get_last</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ERROR</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_CORE_ERROR</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_COMPILE_ERROR</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		err<span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$err</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;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Fatal error'</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;">function</span> _err_human<span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</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;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Array[&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$what</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</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;">$array</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;table class=&quot;err-table-stack&quot;&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th colspan=<span style="color: #000099; font-weight: bold;">\&quot;</span>2<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Dump of <span style="color: #006699; font-weight: bold;">$title</span> array&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Key&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;<span style="color: #006699; font-weight: bold;">$key</span>&lt;/th&gt;&lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> _err_human<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/table&gt;'</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;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;div&gt;<span style="color: #006699; font-weight: bold;">$title</span> is empty&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">set_error_handler</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'err'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_ALL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">register_shutdown_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'err_shutdown'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Installation of the component is similar to any CI helper: drop the file into the application/system/helpers directory and create the associated entry in the application/system/config/autoload.php file like so:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code48'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10048"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p100code48"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'helper'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then open the above and change the constants at the top of the file to specify where the error messages are sent.</p>
<p>In order to send mail the above component needs the truly excellent <a href="http://phpmailer.codeworxtech.com/index.php?pg=phpmailer">PHPMailer</a> package which can be stashed in the same helpers directory. If you do decide to move it somewhere else change the corresponding constant that specifies the location of the library. A small note of warning though &#8211; the path to the PHP mailer libraries must be relative to the current file NOT the current working directory. This is due to how PHP handles fatal errors which for some reason sets the working directory to &#8216;/&#8217;.</p>
<p>Should there be any interest I may extend the above with other useful features such as RSS, SMS (text messaging) or other non-SMTP methods of emailing.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/02/error-reporting-with-ci/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Talking in tongues &#8211; UTF8 with CodeIgniter</title>
		<link>http://hash-bang.net/2009/02/utf8-with-codeigniter/</link>
		<comments>http://hash-bang.net/2009/02/utf8-with-codeigniter/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 02:55:23 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[UTF8]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=95</guid>
		<description><![CDATA[PHP 4 &#038; 5 unfortunately have major problems working with UTF8. Hopefully this will be solved with PHP6 and its fancy pants new rendering interface. Until then we have to make do and mend. First setup your database to work with UTF8. I won&#8217;t waste time telling you how to do this in MySQL as [...]]]></description>
				<content:encoded><![CDATA[<p>PHP 4 &#038; 5 unfortunately have major problems working with UTF8. Hopefully this <a href="http://www.bionictomato.com/users/Marti-en/154-Preparing-yourself-for-PHP-60.html">will be solved with PHP6</a> and its fancy pants new rendering interface.</p>
<p>Until then we have to make do and mend.</p>
<p>First setup your database to work with UTF8. I won&#8217;t waste time telling you how to do this in MySQL as many people far brighter than I have written <a href="http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html">more on the subject</a>.</p>
<p>CodeIgniter comes with UTF8 enabled out of the box so there is little to do configuration wise. Unfortunately pasting a test string such as: 検索 (which I stole from <a href="http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8">this Wikipedia page</a>) into a CI input box will quickly lead to calamity as CI tries to save the string as ASCII.</p>
<p>Simple solution then, save the following helper in your system/application/helpers folder:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=95&amp;download=utf8_helper.php">utf8_helper.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9551"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p95code51"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
* Rewrite all outgoing text into UTF8 compatible streams
* Author: Matt Carter &lt;m@ttcarter.com&gt;
* Info: http://hash-bang.net/2009/02/utf8-with-codeigniter
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> ob_utf8<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ob_utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Re-write all incoming text into UTF8 streams</span>
	<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Then simply add it to your system/application/autoload.php:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p95code52'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9552"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p95code52"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'helper'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The helper will automatically convert incoming POST data into MySQL compatible UTF8 and convert outgoing text into HTML UTF8 streams.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/02/utf8-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Zapping processes in Bash</title>
		<link>http://hash-bang.net/2009/01/zapping-processes-in-bash/</link>
		<comments>http://hash-bang.net/2009/01/zapping-processes-in-bash/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 00:14:15 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=89</guid>
		<description><![CDATA[The following is a handy little script I wrote which politely asks a collection of matching processes to exit. After a second the process is forcibly killed. This command is designed as a drop-in replacement for the slightly cryptic pgrep and pkill commands. ?Download zap.sh1 2 3 4 5 6 7 8 9 10 11 [...]]]></description>
				<content:encoded><![CDATA[<p>The following is a handy little script I wrote which politely asks a collection of matching processes to exit. After a second the process is forcibly killed.</p>
<p>This command is designed as a drop-in replacement for the slightly cryptic pgrep and pkill commands.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=89&amp;download=zap.sh">zap.sh</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8956"><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
</pre></td><td class="code" id="p89code56"><pre class="bash" style="font-family:monospace;">zap<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># Usage: zap [SIGNAL|-NUMERIC|shoot] &lt;fgrep&gt;</span>
	<span style="color: #007800;">SIGNAL</span>=<span style="color: #ff0000;">''</span>
	<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
		shoot<span style="color: #000000; font-weight: bold;">|</span>-<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">SIGNAL</span>=<span style="color: #ff0000;">'SHOOT'</span><span style="color: #000000; font-weight: bold;">;;</span>
		term<span style="color: #000000; font-weight: bold;">|</span>-<span style="color: #000000;">15</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">SIGNAL</span>=<span style="color: #ff0000;">'TERM'</span><span style="color: #000000; font-weight: bold;">;;</span>
		<span style="color: #c20cb9; font-weight: bold;">kill</span><span style="color: #000000; font-weight: bold;">|</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">SIGNAL</span>=<span style="color: #ff0000;">'KILL'</span><span style="color: #000000; font-weight: bold;">;;</span>
		hup<span style="color: #000000; font-weight: bold;">|</span>-<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">SIGNAL</span>=<span style="color: #ff0000;">'HUP'</span><span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #000000; font-weight: bold;">esac</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SIGNAL</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">''</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">shift</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #007800;">SIGNAL</span>=<span style="color: #ff0000;">'SHOOT'</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #007800;">PROCS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> ax <span style="color: #660033;">-eo</span> pid,<span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">fgrep</span> <span style="color: #ff0000;">&quot;$1&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">MODE</span>=<span style="color: #000000;">0</span>
	<span style="color: #000000; font-weight: bold;">for</span> DATA <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$PROCS</span>; <span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MODE</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #007800;">PID</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$DATA</span>&quot;</span>
			<span style="color: #007800;">MODE</span>=<span style="color: #000000;">1</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			<span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$DATA</span>&quot;</span>
			<span style="color: #007800;">MODE</span>=<span style="color: #000000;">0</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SIGNAL</span>&quot;</span> == <span style="color: #ff0000;">'SHOOT'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
				<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Shooting #<span style="color: #007800;">$PID</span> - <span style="color: #007800;">$CMD</span>...&quot;</span>
				<span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #007800;">$PID</span>
				<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
				<span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-9</span> <span style="color: #007800;">$PID</span>
				<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Shot&quot;</span>
			<span style="color: #000000; font-weight: bold;">else</span>
				<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Killing #<span style="color: #007800;">$PID</span> - <span style="color: #007800;">$CMD</span>...&quot;</span>
				<span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #007800;">$SIGNAL</span> <span style="color: #007800;">$PID</span>
				<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Killed&quot;</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>To install it simply dump the above text inside your existing ~/.bashrc file.</p>
<p>Usage is quite simple:</p>
<p>To politely kill all processes (then force-killing if it still does not die) containing the string &#8216;gnome&#8217;:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p89code57'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8957"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p89code57"><pre class="bash" style="font-family:monospace;">zap gnome</pre></td></tr></table></div>

<p>To just kill-forcefully:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p89code58'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8958"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p89code58"><pre class="bash" style="font-family:monospace;">zap <span style="color: #660033;">-9</span> gnome</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/01/zapping-processes-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autorun as Administrator in Vista</title>
		<link>http://hash-bang.net/2009/01/autorun-as-administrator-in-vista/</link>
		<comments>http://hash-bang.net/2009/01/autorun-as-administrator-in-vista/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 22:16:24 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[Batch files]]></category>
		<category><![CDATA[DOS]]></category>
		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=84</guid>
		<description><![CDATA[When asked how to automate the installation of software the other day I was a little dismayed that no-one seemed to have covered the topic of auto-running a batch file from a USB disk as an administrative user. Admin level access is obviously required in order to install software without relentless &#8216;Program X requires administrative [...]]]></description>
				<content:encoded><![CDATA[<p>When asked how to automate the installation of software the other day I was a little dismayed that no-one seemed to have covered the topic of auto-running a batch file from a USB disk as an administrative user.</p>
<p>Admin level access is obviously required in order to install software without relentless &#8216;Program X requires administrative access&#8217; UAC prompts.</p>
<p>Like most things in Vista the solution is exceptionally stupid and requires significant trips with Google to rather obscure second-hand Microsoft knowledge base articles.</p>
<p>The overview is something like this:</p>
<p><img src="http://hash-bang.net/wp-content/uploads/mockup-289x300.png" alt="Autorun as admin process diagram" title="Autorun as admin process diagram" width="289" height="300" class="aligncenter size-medium wp-image-85" /></p>
<p>First create the autorun.inf file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=84&amp;download=autorun.inf">autorun.inf</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8462"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p84code62"><pre class="text" style="font-family:monospace;">[autorun] 
open=invoke.bat 
icon=autorun.ico,0
label=Setup computer from USB disk</pre></td></tr></table></div>

<p>So this file simply sets up the autorun.inf file which contains exactly what to list in the Vista &#8216;Autoplay&#8217; dialog when the USB disk is inserted. You will probaly want to rename the &#8216;Label&#8217; line and perhaps put a pretty icon on your disk called &#8216;autorun.ico&#8217;.</p>
<p>Now create your actual batch file that you wish to run as admin and call it &#8216;setup.bat&#8217;.</p>
<p>As a small note of caution. For some reason Vista does not change to this files active working directory when executing. I can really think of no reason this behavior exists so you might want to add the following rather cryptic command as the first in the batch file. This changes the active directory into the current batch file (in this case &#8216;setup.bat&#8217;) directory.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=84&amp;download=setup.bat">setup.bat</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8463"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p84code63"><pre class="text" style="font-family:monospace;">@ECHO OFF
cd /d %~dp0</pre></td></tr></table></div>

<p>There obvious when you think about it isn&#8217;t it. Shame on you for not knowing about the handy and invisible shell variable &#8220;~dp0&#8243;. I am sure there is a long and interesting story about why this variable is so called and why it doesnt show up with the rest of things when you type &#8216;set&#8217;. This is why I switched to Linux some time ago.</p>
<p>Anyway, now we&#8217;ve done that create a shortcut to the &#8216;Setup.bat&#8217; file and rename it to &#8216;setup.lnk&#8217; (remember that the &#8216;.lnk&#8217; bit will always be invisible to you anyway so when you rename in explorer all you will see is the &#8216;setup&#8217; bit sans extension).</p>
<p>Open the shortcuts properties and hit the &#8216;Advanced&#8217; button. Tick the &#8216;Run as Administrator&#8217; box.</p>
<p>Finally, lets join it all together by creating the &#8216;Invoke.bat&#8217; file which runs the shortcut (which will in turn run the &#8216;setup.bat&#8217; program after asking via UAC for administrative permission).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=84&amp;download=invoke.bat">invoke.bat</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8464"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p84code64"><pre class="text" style="font-family:monospace;">@ECHO OFF
&quot;Setup.lnk&quot;</pre></td></tr></table></div>

<p>Now save everything and remove you disk (safely) and re-insert. You will now be able to run the &#8216;setup.bat&#8217; file which should contain all your auto-install scripts after a UAC admin prompt. Yey.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/01/autorun-as-administrator-in-vista/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Pretty URLS in CodeIgniter</title>
		<link>http://hash-bang.net/2009/01/pretty-urls-in-codeigniter/</link>
		<comments>http://hash-bang.net/2009/01/pretty-urls-in-codeigniter/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 22:49:21 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=81</guid>
		<description><![CDATA[CodeIgniter has to be my favorite framework for PHP. The way it keeps out of your way while working to an MVC standard is something deserving of the highest praise. For reasons passing understanding though the programmers of this excellent system have desided not to provide pretty URL&#8217;s out of the box. Getting infomation on [...]]]></description>
				<content:encoded><![CDATA[<p>CodeIgniter has to be my favorite framework for PHP. The way it keeps out of your way while working to an MVC standard is something deserving of the highest praise.</p>
<p>For reasons passing understanding though the programmers of this excellent system have desided not to provide pretty URL&#8217;s out of the box. Getting infomation on this is a little tricky so here is my take on the situation.</p>
<p>Simply dump the following into a file called &#8216;.htaccess&#8217; (Note the starting Dot) in the root path (thats the one at the very start of your path tree that should contain the &#8216;system&#8217; folder).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=81&amp;download=.htaccess">.htaccess</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8167"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p81code67"><pre class="text" style="font-family:monospace;">RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$		- [L]
&nbsp;
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]</pre></td></tr></table></div>

<p>As with most mod_rewrite hacks you will need that enabled on an apache server. Its very rare to find a hosting company that doesn&#8217;t use this setup so you should be fine.</p>
<p>You will also need to change the following variable to a blank value in the system/application/config/config.php file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code68'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8168"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p81code68"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'index_page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And you&#8217;re done. From now on your Urls are addressed in the form: http://SITE/CONTROLLER/METHOD/VALUE1/VALUE2 (e.g. http://mysite.com/users/edit/123123)</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/01/pretty-urls-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Missing PHP Functions: getopts()</title>
		<link>http://hash-bang.net/2008/12/missing-php-functions-getopts/</link>
		<comments>http://hash-bang.net/2008/12/missing-php-functions-getopts/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 04:24:51 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Libraries]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=68</guid>
		<description><![CDATA[Replacing the horribly inflexible getopt() PHP function with something that allows complex parameters and long argument strings such as --download instead of just -d.]]></description>
				<content:encoded><![CDATA[<p>This function is intended as a complete replacement for the horribly crippled <a href="http://www.php.net/manual/en/function.getopt.php">getopt()</a> native PHP function and provide extended functionality.</p>
<p>The use of this library means lots of great command-line-fu becomes readily available without any unnecessary validation tediousness messing up the first half of your script.</p>
<p>To use simply add the (ahem) hash-bang to the top of your PHP script and make the script executable.</p>
<p>An example of a correct setup would be:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=68&amp;download=getopts_example.php">getopts_example.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6869"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p68code69"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/php -qC
</span><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'getopts.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$opts</span> <span style="color: #339933;">=</span> getopts<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;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'switch'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> GETOPT_SWITCH<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'switch'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'letterb'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> GETOPT_SWITCH<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'c'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'switch'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> GETOPT_VAL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'default'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'defaultval'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'d'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'switch'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> GETOPT_KEYVAL<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'e'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'switch'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'e'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> GETOPT_ACCUMULATE<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'f'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'switch'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'f'</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: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argv'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$opts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In the above the script can now be run as:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p68code70'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6870"><td class="code" id="p68code70"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>getopts_example.php <span style="color: #660033;">-a</span> <span style="color: #660033;">-b</span></pre></td></tr></table></div>

<p>With the incoming options (in this case the switches &#8216;a&#8217; and &#8216;b&#8217;) being set in the $opts variable.</p>
<p>Full documentation as well as extensive examples are included in the source which can be found below.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=68&amp;download=getopts.php">getopts.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6871"><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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
</pre></td><td class="code" id="p68code71"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/php -qC
</span><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">/**********************************************************************************
	* Coded by Matt Carter (M@ttCarter.net)                                           *
	***********************************************************************************
	* getOpts                                                                       *
	* Extended CLI mode option and switch handling                                    *
	*                                                                                 *
	**********************************************************************************/</span>
<span style="color: #666666; font-style: italic;">/*
GetOpt Readme
+++++++++++++++
&nbsp;
getOpt is a library to load commandline options in replacement for the horribly inflexible 'getopts' native php function. It can be invoked using the typical 'require', 'include' (or their varients) from any PHP scripts.
&nbsp;
LEGAL STUFF
===========
This code is covered under the GPL with republishing permissions provided credit is given to the original author Matt Carter (M@ttCarter.com).
&nbsp;
LATEST VERSIONS
===============
The latest version can be found on the McStuff website currently loadted at http://ttcarter.com/mcstuff or by contacting the author at M@ttCarter.com (yes thats an email address).
&nbsp;
QUICK EXAMPLE
=============
#!/usr/bin/php -qC
&lt;?php
require('getopts.php');
$opts = getopts(array(
	'a' =&gt; array('switch' =&gt; 'a','type' =&gt; GETOPT_SWITCH),
	'b' =&gt; array('switch' =&gt; array('b','letterb'),'type' =&gt; GETOPT_SWITCH),
	'c' =&gt; array('switch' =&gt; 'c', 'type' =&gt; GETOPT_VAL, 'default' =&gt; 'defaultval'),
	'd' =&gt; array('switch' =&gt; 'd', 'type' =&gt; GETOPT_KEYVAL),
	'e' =&gt; array('switch' =&gt; 'e', 'type' =&gt; GETOPT_ACCUMULATE),
	'f' =&gt; array('switch' =&gt; 'f'),
),$_SERVER['argv']);
?&gt;
&nbsp;
When used with the commandline:
&gt;./PROGRAM.php -ab -c 15 -d key=val -e 1 --letterb -d key2=val2 -eeeeeee 2 3
&nbsp;
Gives the $opt variable the following structure:
$opt = Array (
	[cmdline] =&gt; Array (
		[0] =&gt; 1
		[1] =&gt; 2
		[2] =&gt; 3
	)
	[a] =&gt; 1
	[b] =&gt; 1
	[c] =&gt; 15
	[d] =&gt; Array (
		[key] =&gt; val
		[key2] =&gt; val2
	)
	[e] =&gt; 8
	[f] =&gt; 0
)
&nbsp;
Of course the above is a complex example showing off most of getopts functions all in one.
&nbsp;
Types and there meanings
========================
&nbsp;
GETOPT_SWITCH
	This is either 0 or 1. No matter how many times it is specified on the command line.
&nbsp;
	&gt;PROGRAM -c -c -c -cccc
	Gives:
	$opt['c'] = 1;
&nbsp;
	&gt;PROGRAM
	Gives:
	$opt['c'] = 0
&nbsp;
GETOPT_ACCUMULATE
	Each time this switch is used its value increases.
&nbsp;
	&gt;PROGRAM -vvvv
	Gives:
	$opt['v'] = 4
&nbsp;
GETOPT_VAL
	This expects a value after its specification.
&nbsp;
	&gt;PROGRAM -c 32
	Gives:
	$opt['c'] = 32
&nbsp;
	Multiple times override each precursive invokation so:
&nbsp;
	&gt;PROGRAM -c 32 -c 10 -c 67
	Gives:
	$opt['c'] = 67
&nbsp;
GETOPT_MULTIVAL
	The same format as GETOPT_VAL only this allows multiple values. All incomming variables are automatically formatted in an array no matter how few items are present.
&nbsp;
	&gt;PROGRAM -c 1 -c 2 -c 3
	Gives:
	$opt['c'] = array(1,2,3)
&nbsp;
	&gt;PROGRAM -c 1
	Gives:
	$opt['c'] = array(1)
&nbsp;
	&gt;PROGRAM
	Gives:
	$opt['c'] = array()
&nbsp;
GETOPT_KEYVAL
	Allows for key=value specifications.
&nbsp;
	&gt;PROGRAM -c key=val -c key2=val2 -c key3=val3 -c key3=val4
	Gives:
	$opt['c'] = array('key1' =&gt; 'val2','key2' =&gt; 'val2','key3' =&gt; array('val3','val4');
&nbsp;
*/</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GETOPT_NOTSWITCH'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Internal use only</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GETOPT_SWITCH'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GETOPT_ACCUMULATE'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GETOPT_VAL'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GETOPT_MULTIVAL'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GETOPT_KEYVAL'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* @param array $options The getOpts specification. See the documentation for more details
* @param string|array $fromarr Either a command line of switches or the array structure to take options from. If omitted $_SERVER['argv'] is used
* @return array Processed array of return values
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> getopts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span><span style="color: #000088;">$fromarr</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</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;">$fromarr</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$fromarr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argv'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">elseif</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;">$fromarr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$fromarr</span> <span style="color: #339933;">=</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;">$fromarr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Split it into an array if someone passes anything other than an array</span>
	<span style="color: #000088;">$opts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cmdline'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</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;">// Output options</span>
	<span style="color: #000088;">$optionslookup</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: #666666; font-style: italic;">// Reverse lookup table mapping each possible option to its real $options key</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$optitem</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$props</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Default all options</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;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</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: #666666; font-style: italic;">// User didnt specify type...</span>
				<span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$optitem</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> GETOPT_SWITCH<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Default to switch</span>
				<span style="color: #000088;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> GETOPT_SWITCH<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// And again because we're not using pointers here</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">case</span> GETOPT_VAL<span style="color: #339933;">:</span>
					<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</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: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$optitem</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// else fallthough...</span>
				<span style="color: #b1b100;">case</span> GETOPT_ACCUMULATE<span style="color: #339933;">:</span>
				<span style="color: #b1b100;">case</span> GETOPT_SWITCH<span style="color: #339933;">:</span>
					<span style="color: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$optitem</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">case</span> GETOPT_MULTIVAL<span style="color: #339933;">:</span>
				<span style="color: #b1b100;">case</span> GETOPT_KEYVAL<span style="color: #339933;">:</span>
					<span style="color: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$optitem</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'switch'</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: #666666; font-style: italic;">// Create the $optionslookup var from an array of aliases</span>
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'switch'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$switchalias</span><span style="color: #009900;">&#41;</span>
					<span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$switchalias</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$optitem</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: #666666; font-style: italic;">// Create the $optionslookup ref as a simple pointer to the hash</span>
			<span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$props</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'switch'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$optitem</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$inswitch</span> <span style="color: #339933;">=</span> GETOPT_NOTSWITCH<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$inswitch</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> GETOPT_MULTIVAL<span style="color: #339933;">:</span>
			<span style="color: #b1b100;">case</span> GETOPT_VAL<span style="color: #339933;">:</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Throw error if the user tries to simply set another switch while the last one is still 'open'</span>
					<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The option '{<span style="color: #006699; font-weight: bold;">$fromarr</span>[<span style="color: #006699; font-weight: bold;">$i</span>]}' needs a value.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				GETOPT_setval<span style="color: #009900;">&#40;</span><span style="color: #000088;">$opts</span><span style="color: #339933;">,</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span><span style="color: #000088;">$inswitch_key</span><span style="color: #339933;">,</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$inswitch</span> <span style="color: #339933;">=</span> GETOPT_NOTSWITCH<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Reset the reader to carry on reading normal stuff</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> GETOPT_KEYVAL<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// Yes, the awkward one.</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Throw error if the user tries to simply set another switch while the last one is still 'open'</span>
					<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The option '{<span style="color: #006699; font-weight: bold;">$fromarr</span>[<span style="color: #006699; font-weight: bold;">$i</span>]}' needs a value.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Replace all ':' with '=' (keeping things simple and fast.</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'='</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
					<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The option '<span style="color: #006699; font-weight: bold;">$inswitch_userkey</span>' needs a key-value pair. E.g. '-<span style="color: #006699; font-weight: bold;">$inswitch_userkey</span> option=value'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				GETOPT_setval<span style="color: #009900;">&#40;</span><span style="color: #000088;">$opts</span><span style="color: #339933;">,</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span><span style="color: #000088;">$inswitch_key</span><span style="color: #339933;">,</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;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</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: #000088;">$inswitch</span> <span style="color: #339933;">=</span> GETOPT_NOTSWITCH<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Reset the reader to carry on reading normal stuff</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> GETOPT_NOTSWITCH<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// General invokation of no previously complex cmdline options (i.e. i have no idea what to expect next)</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// Probably the start of a switch</span>
					<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'--'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Single switch OR long opt (might be a weird thing like VAL, MULTIVAL etc.)</span>
							<span style="color: #000088;">$userkey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ltrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$userkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
									<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unknown option '-<span style="color: #006699; font-weight: bold;">$userkey</span>'<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								<span style="color: #000088;">$hashkey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$userkey</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Replace with the REAL key</span>
							<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hashkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> GETOPT_SWITCH<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hashkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> GETOPT_ACCUMULATE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
								GETOPT_setval<span style="color: #009900;">&#40;</span><span style="color: #000088;">$opts</span><span style="color: #339933;">,</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span><span style="color: #000088;">$hashkey</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Simple enough - Single option specified in switch that needs no params.</span>
							<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// OK the option needs a value. This is where the fun begins</span>
								<span style="color: #000088;">$inswitch</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hashkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Set so the next process cycle will pick it up</span>
								<span style="color: #000088;">$inswitch_key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hashkey</span><span style="color: #339933;">;</span>
								<span style="color: #000088;">$inswitch_userkey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$userkey</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">// Multiple letters. Probably a bundling</span>
						<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$o</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$o</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$o</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$hashkey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$o</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hashkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
									<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unknown option '-<span style="color: #006699; font-weight: bold;">$hashkey</span>'<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hashkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> GETOPT_SWITCH<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hashkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> GETOPT_ACCUMULATE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
								<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Option '-<span style="color: #006699; font-weight: bold;">$hashkey</span>' requires a value.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							GETOPT_setval<span style="color: #009900;">&#40;</span><span style="color: #000088;">$opts</span><span style="color: #339933;">,</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span><span style="color: #000088;">$optionslookup</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hashkey</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cmdline'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fromarr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Just detritus on the cmdline</span>
				<span style="color: #009900;">&#125;</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;">$opts</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> GETOPT_setval<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$opts</span><span style="color: #339933;">,&amp;</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> GETOPT_VAL<span style="color: #339933;">:</span>
		<span style="color: #b1b100;">case</span> GETOPT_SWITCH<span style="color: #339933;">:</span>
			<span style="color: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> GETOPT_ACCUMULATE<span style="color: #339933;">:</span>
			<span style="color: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> GETOPT_MULTIVAL<span style="color: #339933;">:</span>
			<span style="color: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> GETOPT_KEYVAL<span style="color: #339933;">:</span>
			<span style="color: #000088;">$opts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you do use this script, please take a moment to add any comments or suggestions below.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2008/12/missing-php-functions-getopts/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Missing PHP Functions: array_totree()</title>
		<link>http://hash-bang.net/2008/12/missing-php-functions-array_totree/</link>
		<comments>http://hash-bang.net/2008/12/missing-php-functions-array_totree/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 01:57:01 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=61</guid>
		<description><![CDATA[?View Code PHParray_totree&#40; $array, $seperator = &#34;/&#34; &#41; Splits a given array into a tree formed hash array. This is useful when a large array of strings needs splitting into a hierarchical array structure. For example in incoming array structure ?View Code PHP1 2 3 4 5 6 7 $a = array&#40; 'a/a/a', 'a/b/b', 'a/b/c', [...]]]></description>
				<content:encoded><![CDATA[
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p61code76'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6176"><td class="code" id="p61code76"><pre class="php" style="font-family:monospace;">array_totree<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$seperator</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Splits a given array into a tree formed hash array.</p>
<p>This is useful when a large array of strings needs splitting into a hierarchical array structure.</p>
<p>For example in incoming array structure</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p61code77'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6177"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p61code77"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'a/a/a'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'a/b/b'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'a/b/c'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'a/c/c'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'c/a/a'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Is returned as:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p61code78'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6178"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p61code78"><pre class="text" style="font-family:monospace;">array(
	&quot;a&quot; =&gt; array(
		&quot;a&quot; =&gt; array(
			&quot;a&quot; =&gt; array()
		),
	),
	&quot;b&quot; =&gt; array(
		&quot;b&quot; =&gt; array(),
		&quot;c&quot; =&gt; array()
	),
	&quot;c&quot; =&gt; array(
		&quot;c&quot; =&gt; array()
	),
	&quot;c&quot; =&gt; array(
		&quot;a&quot; =&gt; array(
			&quot;a&quot; =&gt; array()
		)
	)
);</pre></td></tr></table></div>

<p>The function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=61&amp;download=array_totree.php">array_totree.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6179"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p61code79"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> array_totree<span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span> <span style="color: #000088;">$splitchar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$out</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;">$in</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$bits</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$splitchar</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;">$outref</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$bits</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$bit</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;">$outref</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$bit</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                                <span style="color: #000088;">$outref</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$bit</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$outref</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$outref</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$bit</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;">$out</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2008/12/missing-php-functions-array_totree/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Templating in PHP in 10 seconds flat</title>
		<link>http://hash-bang.net/2008/12/templating-in-php-in-10-seconds-flat/</link>
		<comments>http://hash-bang.net/2008/12/templating-in-php-in-10-seconds-flat/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 21:50:16 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=48</guid>
		<description><![CDATA[One of the rather messy practices that the PHP documentation actually encourages is the practice of using include or require to correctly layout a web page. The PHP manual suggests that two pages be created: header and footer, and that these are included at the beginning and end of each document. Thus for a &#8216;contact [...]]]></description>
				<content:encoded><![CDATA[<p>One of the rather messy practices that the PHP documentation actually encourages is the practice of using <a href="http://au.php.net/manual/en/function.include.php">include</a> or <a href="http://au.php.net/manual/en/function.require.php">require</a> to correctly layout a web page.</p>
<p>The PHP manual suggests that two pages be created: header and footer, and that these are included at the beginning and end of each document.</p>
<p>Thus for a &#8216;contact us&#8217; page the contact.php file would look something like:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p48code82'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4882"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p48code82"><pre class="php" style="font-family:monospace;"><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;">&quot;header.php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">...</span> The contact pages HTML <span style="color: #339933;">...</span>
<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;">&quot;footer.php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>While this does work, there are easier ways to accomplish the same thing and still maintain compatibility with editors such as Dreamweaver which seems to choke on even a small amount of PHP.</p>
<p>The under-documented <a href="http://au.php.net/ini.core">auto_prepend_value and auto_append_values</a> get a brief mention in the ini directives documentation but I thought it would be nice to show an example of how these can be used in the wild,</p>
<p>Adding the following to either an existing &#8216;.htaccess&#8217; (note the starting dot) or downloading the below file will do pretty much the same as the above contact.php file example did only without needing to specify the files in the beginning and ends of each separate file.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=48&amp;download=.htaccess">.htaccess</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4883"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p48code83"><pre class="text" style="font-family:monospace;">php_value auto_prepend_file &quot;header.php&quot;
php_value auto_append_file &quot;footer.php&quot;</pre></td></tr></table></div>

<p>And as with all .htaccess directives you can override these on a directory basis. So if you need a different header and footer when inside the &#8216;invoices&#8217; directory dump another copy of the above into that directory changing it as needed.</p>
<p>And <i>yes</i> this method can be merged with the <a href="http://hash-bang.net/2008/11/url-prettyfication-in-10-seconds-flat/">previous post</a> to work with the URL prettifier.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2008/12/templating-in-php-in-10-seconds-flat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL prettification in 10 seconds flat</title>
		<link>http://hash-bang.net/2008/11/url-prettyfication-in-10-seconds-flat/</link>
		<comments>http://hash-bang.net/2008/11/url-prettyfication-in-10-seconds-flat/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 21:35:25 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=42</guid>
		<description><![CDATA[A word to all PHP, ASP, Python and Perl web-devs out there: http://somewhere.com/contact.php Is soooo 1990&#8242;s. URL prettification has always been seen to be the exclusive domain of larger frameworks but with Apache it really isn&#8217;t that hard. Simply paste the following into a file named &#8216;.htaccess&#8217; (note the starting &#8216;dot&#8217;) and dump it in [...]]]></description>
				<content:encoded><![CDATA[<p>A word to all PHP, ASP, Python and Perl web-devs out there:</p>
<p>http://somewhere.com/contact.php</p>
<p>Is soooo 1990&#8242;s.</p>
<p>URL prettification has always been seen to be the exclusive domain of larger frameworks but with Apache it really isn&#8217;t that hard.</p>
<p>Simply paste the following into a file named &#8216;.htaccess&#8217; (note the starting &#8216;dot&#8217;) and dump it in your website to allow the extension of your script to be &#8216;guessed&#8217; by Apache should it not be provided.</p>
<p>This hack obviously requires mod_rewrite but since every hosting provider and their dog provides this these days i would say not having it enabled would be the exception rather than the rule</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=42&amp;download=.htaccess">.htaccess</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4285"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p42code85"><pre class="php" style="font-family:monospace;">RewriteEngine On
RewriteBase <span style="color: #339933;">/</span>
&nbsp;
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span><span style="color: #339933;">.</span>php <span style="color: #339933;">-</span>f
RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$		$<span style="color: #cc66cc;">1</span><span style="color: #339933;">.</span>php <span style="color: #009900;">&#91;</span>L<span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>ASP, Python and Perl people either add your .asp, .py or .pl sections under or above the .php bits or simply replace them.</p>
<p>There, now we can use:</p>
<p>http://somewhere.com/contact</p>
<p>But the old way (with .php extension) is still valid too.</p>
<p>Finally we put an end to this silly file extension nastiness.<br />
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2008/11/url-prettyfication-in-10-seconds-flat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
