<?xml version="1.0"?>
<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/"
	>
   <channel>
      <pubDate>Thu, 4 Dec 2008 00:55:47 GMT</pubDate>
      <lastBuildDate>Thu, 4 Dec 2008 00:55:47 GMT</lastBuildDate>
      <language>en</language>
      <docs>http://www.rssboard.org/rss-specification</docs>
      <title>CrunchBang ~ programming</title>
      <link>http://crunchbang.org/tags/programming/</link>
      <description>Code, Design &amp; GNU/Linux</description>

<item>
    <title>5 Or More Consecutive Consonants</title>
    <link>http://crunchbang.org/archives/2008/05/10/5-or-more-consecutive-consonants/</link>
    <pubDate>Sat, 10 May 2008 09:29:11 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2008/05/10/5-or-more-consecutive-consonants/</guid>
    <description><![CDATA[
    <p><img src="http://crunchbang.org/uploads/051008084936-carol_vorderman.jpg" alt="Carol Vorderman" style="float:left;border:0px;margin-right:20px;margin-bottom:10px; padding:4px; background: #babdb6;" /></p>

<p>&#34;A consonant please Carol, and another, and another, and another, and another.&#34; &#8212; actually, this post is not about <a href="http://en.wikipedia.org/wiki/Carol_Vorderman " title="Wikipedia - Carol Vorderman">Carol Vorderman</a> or <a href="http://en.wikipedia.org/wiki/Countdown_%28game_show%29 " title="Wikipedia - Countdown">Countdown</a>, it is about some interesting[<em>?</em>] script output I came across when attempting to write a new spam filter. I will explain&#8230;</p>

<p>Just lately my website has been receiving some rather odd junk comments. The comments make no sense and they have quite obviously been sent by some automated junk flinging robot. The reason the comments make no sense is because they seem to be constructed from random characters. Apart from making no sense, these comments <em>were</em> also becoming a nuisance as they <em>were</em> easily slipping past my existing keyword filters.</p>

<p>So, the other night I decided to sit down and write a new filter to try and catch these random character junk comments. I started by analysing some previously submitted comments to try and find any common patterns. One such pattern I found was multiple strings containing 5 or more consecutive consonants. Thinking this to be unusual, I ran some tests against a <a href="http://crunchbang.org/misc/common_words.txt " title="flat file containing 21110 common English words">flat file containing 21110 common English words</a>. I thought the results were interesting. Here is what I found:</p>

<ul>
<li><a href="http://crunchbang.org/wiki/strings-containing-5-or-more-consecutive-consonants/ " title="85 unique strings containing 5 or more consecutive consonants.">85 unique strings containing 5 or more consecutive consonants</a>.</li>
<li><a href="http://crunchbang.org/wiki/words-containing-5-or-more-consecutive-consonants/ " title="113 words containing 5 or more consecutive consonants.">113 words containing 5 or more consecutive consonants</a>.</li>
<li>9 words containing 5 or more consecutive consonants and no vowels: <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=crypt " title="dict.org - crypt">crypt</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=lymph " title="dict.org - lymph">lymph</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=lynch " title="dict.org - lynch">lynch</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=myrrh " title="dict.org - myrrh">myrrh</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=nymph " title="dict.org - nymph">nymph</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=pygmy " title="dict.org - pygmy">pygmy</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=rhythm " title="dict.org - rhythm">rhythm</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=sylph " title="dict.org - sylph">sylph</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=tryst " title="dict.org - tryst">tryst</a></li>
<li>10 words containing 6 or more consecutive consonants: <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=latchstring " title="dict.org - latchstring">latchstring</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=metempsychosis " title="dict.org - metempsychosis">metempsychosis</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=polysyllabic " title="dict.org - polysyllabic">polysyllabic</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=polysyllable " title="dict.org - polysyllable">polysyllable</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=porphyry " title="dict.org - porphyry">porphyry</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=rhythm " title="dict.org - rhythm">rhythm</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=skyscraper " title="dict.org - skyscraper">skyscraper</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=strychnine " title="dict.org - strychnine">strychnine</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=synchronize " title="dict.org - synchronize">synchronize</a>, <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=synchronous " title="dict.org - synchronous">synchronous</a></li>
<li>1 word containing 6 consecutive consonants and no vowels: <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=rhythm " title="dict.org - rhythm">rhythm</a></li>
<li>1 word containing 7 consecutive consonants: <a href="http://www.dict.org/bin/Dict?Form=Dict1&amp;Strategy=*&amp;Database=*&amp;Query=strychnine " title="dict.org - strychnine">strychnine</a></li>
</ul>

<p>I should state that the above results are in no way definitive. I know this because I also ran the same test against another file containing 311141 words found in the <a href="http://en.wikipedia.org/wiki/An_American_Dictionary_of_the_English_Language " title="Wikipedia - Merriam-Webster dictionary">Merriam-Webster dictionary</a>. Still, by using the results of the initial test I was able to construct a list of safe words to use with my new spam filter.</p>

<p><em>Finally, yes, I did consider not writing this post; however, I am sure my publishing of these results will not change anything. Besides, Arthur, my 80 year old neighbour, is the biggest Countdown fan on the planet, he is also quite Internet savvy and definitely thinks <a href="http://images.google.com/images?q=carol+vorderman+countdown " title="Carol Vorderman, hot or not?">Carol Vorderman is hot</a> &#8212; he may find these results quite useful in increasing his daily Countdown score!</em></p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/antispam/" title="Browse all posts tagged with &#8220;antispam&#8221;">antispam</a>, <a href="http://crunchbang.org/tags/language/" title="Browse all posts tagged with &#8220;language&#8221;">language</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/projects/" title="Browse all posts tagged with &#8220;projects&#8221;">projects</a>, <a href="http://crunchbang.org/tags/whird/" title="Browse all posts tagged with &#8220;whird&#8221;">whird</a></p>
    ]]></description>
</item>

<item>
    <title>A(nother) Regular Expression Test Tool</title>
    <link>http://crunchbang.org/archives/2008/05/07/another-regular-expression-test-tool/</link>
    <pubDate>Wed, 07 May 2008 17:44:26 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2008/05/07/another-regular-expression-test-tool/</guid>
    <description><![CDATA[
    <p>I came across another <a href="http://regex.larsolavtorvik.com/ " title="A regular expression test tool.">regular expression test tool</a> today. This one is an Ajax enabled regex tool which lets you evaluate regex expressions in several languages, including PHP PCRE and PHP POSIX, with instant results. You can choose which functions to use, such as match, match all, replace, split etc. I much prefer it to the <a href="http://crunchbang.org/archives/2008/02/18/regular-expression-test-tool/ " title="Regular Expression Test Tool">similar regex tool</a> I mentioned a couple of months ago. Everything considered, it&#39;s a very handy resource for when you are struggling with those pesky expressions.</p>

<p>URL: <a href="http://regex.larsolavtorvik.com/ " title="Regular Expression Tool">http://regex.larsolavtorvik.com/</a><br />
Blog: <a href="http://larsolavtorvik.com/ " title="Lars Olav Torvik - Programming and computer stuff.">Lars Olav Torvik - Programming and computer stuff.</a></p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/tools/" title="Browse all posts tagged with &#8220;tools&#8221;">tools</a></p>
    ]]></description>
</item>

<item>
    <title>Wiki Rewrite</title>
    <link>http://crunchbang.org/archives/2008/05/04/wiki-rewrite/</link>
    <pubDate>Sun, 04 May 2008 16:06:08 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2008/05/04/wiki-rewrite/</guid>
    <description><![CDATA[
    <p>Over the last couple of nights I have completely rewritten my <a href="http://crunchbang.org/wiki/ " title="CrunchBang Wiki">personal wiki</a>. The wiki previously used the PHP <a href="http://wikkawiki.org/ " title="WikkaWiki">WikkaWiki</a> wiki engine, it now uses a bunch of custom PHP scripts. The scripts are similar to those used by my blog software, <a href="http://crunchbang.org/projects/whird/ " title="Whird">Whird</a>. I decided to perform the rewrite for numerous reasons, some of which I have listed below:</p>

<ol>
<li><p>I was unhappy with how WikkaWiki was formatting the underlying HTML, specifically the way in which it would never use the paragraph tag, opting instead to insert break tags. While this probably sounds like a minor issue, it was really beginning to bug me.</p></li>
<li><p>I started this site [<em>crunchbang.org</em>] with the intention of coding all of the software/scripts myself. Therefore, and somewhat obviously, my use of WikkaWiki was always going to provide reason for my conscience to niggle me.</p></li>
<li><p>As mentioned before, <a href="http://crunchbang.org/archives/2008/02/10/wikka-wakka-wiki/ " title="See previous post, Wikka Wakka Wiki.">WikkaWiki is very hackable</a>; however, it was never going to be as hackable as something I had produced myself.</p></li>
<li><p>I wanted both my blog and my wiki to use the <a href="http://en.wikipedia.org/wiki/Markdown " title="Wikipedia - Markdown">Markdown</a> markup language. While this was not a problem for my blog [<em>it has always used Markdown</em>] I could not find any suitable plugins/hacks for enabling Markdown within WikkaWiki.</p></li>
</ol>

<p>The rewrite is pretty much complete and is now live. I have tried to make sure any URLs used by WikkaWiki are either reused or redirected. Please feel free to drop me a comment if you notice anything funky occurring.</p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/webdesign/" title="Browse all posts tagged with &#8220;webdesign&#8221;">webdesign</a>, <a href="http://crunchbang.org/tags/whird/" title="Browse all posts tagged with &#8220;whird&#8221;">whird</a></p>
    ]]></description>
</item>

<item>
    <title>Perplexed by Web Frameworks</title>
    <link>http://crunchbang.org/archives/2008/03/28/perplexed-by-web-frameworks/</link>
    <pubDate>Fri, 28 Mar 2008 23:40:43 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2008/03/28/perplexed-by-web-frameworks/</guid>
    <description><![CDATA[
    <p>The latest <a href="http://www.lugradio.org/ " title="Linux Radio Show - LugRadio">LugRadio</a> episode features a discussion about <a href="http://www.djangoproject.com/ " title="Django Python Web Framework">Django</a> and other web frameworks. I found the feature interesting, but I have to admit that I find the subject of web frameworks somewhat perplexing. I have yet to fully embrace any such framework, although I have played with the <a href="http://framework.zend.com/ " title="Zend Framework">Zend Framework</a>. I think there are a number of reasons I have not fully adopted any frameworks:</p>

<ol>
<li><p>I am put off by having to learn all the new classes, structures and methods employed by said frameworks. Surely my time would be better spent actually learning more about the core language?</p></li>
<li><p>I fear that using a framework would somehow stifle innovation. I am under no illusions of being the most innovative player, however, I find it hard to shake. I guess I am questioning where the innovation comes from if everyone is using the same framework?</p></li>
<li><p>It is fun to write your own code, functions, classes and routines etc. I like to experiment with code, I like to make mistakes, before fixing them &#8212; it is this that keeps me interested. I would be concerned that using a framework would takeaway much of that.</p></li>
</ol>

<p>Having said all that, I&#39;m not totally opposed to frameworks and I think they have their place; three PHP frameworks of interest to me are:</p>

<ol>
<li>Zend Framework: <a href="http://framework.zend.com/ " title="Zend Framework">http://framework.zend.com/</a></li>
<li>CakePHP: <a href="http://www.cakephp.org/ " title="CakePHP - the rapid development PHP framework.">http://www.cakephp.org/</a></li>
<li>Symfony: <a href="http://www.symfony-project.org/ " title="Symfony Open-Source PHP Web Framework">http://www.symfony-project.org/</a></li>
</ol>

<p>I am going to look into the above to see what they have to offer; however, I think I will probably continue to hack together my own code for a while to come.</p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/webdesign/" title="Browse all posts tagged with &#8220;webdesign&#8221;">webdesign</a></p>
    ]]></description>
</item>

<item>
    <title>Regular Expression Test Tool</title>
    <link>http://crunchbang.org/archives/2008/02/18/regular-expression-test-tool/</link>
    <pubDate>Mon, 18 Feb 2008 16:36:29 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2008/02/18/regular-expression-test-tool/</guid>
    <description><![CDATA[
    <p>I&#39;ve used this web based <a href="http://www.solmetra.lt/scripts/regex/ " title="Regular Expression Test Tool">regular expression test tool</a> a couple of times over the last day or so. While I don&#39;t normally struggle with <a href="http://en.wikipedia.org/wiki/Regular_expressions " title="Wikipedia - Regular Expressions">regular expressions</a>, this tool has still come in handy; it has saved me from the &#34;code it and cross your fingers&#34; approach I normally take.</p>

<p>This is a great tool for anyone who works with <a href="http://en.wikipedia.org/wiki/PHP " title="Wikipedia - PHP">PHP</a>, especially as the service uses PHP regular expression functions as a base for its operations.</p>

<p>URL: <a href="http://www.solmetra.lt/scripts/regex/ " title="Regular Expression Test Tool">http://www.solmetra.lt/scripts/regex/</a></p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/tools/" title="Browse all posts tagged with &#8220;tools&#8221;">tools</a></p>
    ]]></description>
</item>

<item>
    <title>Wicked Cool Shell Scripts</title>
    <link>http://crunchbang.org/archives/2008/02/17/wicked-cool-shell-scripts/</link>
    <pubDate>Sun, 17 Feb 2008 07:41:45 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2008/02/17/wicked-cool-shell-scripts/</guid>
    <description><![CDATA[
    <p>I&#39;ve not read the book, but the <a href="http://www.intuitive.com/wicked/index.shtml " title="Wicked Cool Shell Scripts">Wicked Cool Shell Scripts</a> site and its example shell scripts are, erm, wicked cool. The site offers a whole host of scripts, some of which could quite easily be adapted/hacked into useful tools. If you&#39;re remotely interested in Shell scripting, you should take a look, even people with scripting experience might learn a thing or two.</p>

<p>URL: <a href="http://www.intuitive.com/wicked/index.shtml " title="Wicked Cool Shell Scripts">http://www.intuitive.com/wicked/index.shtml</a></p>

<p>Download the script library: <a href="http://crunchbang.org/misc/wicked-cool-shell-scripts.tgz " title="Wicked Cool Shell Scripts">wicked-cool-shell-scripts.tgz</a></p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/bash/" title="Browse all posts tagged with &#8220;bash&#8221;">bash</a>, <a href="http://crunchbang.org/tags/code/" title="Browse all posts tagged with &#8220;code&#8221;">code</a>, <a href="http://crunchbang.org/tags/linux/" title="Browse all posts tagged with &#8220;linux&#8221;">linux</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/shell/" title="Browse all posts tagged with &#8220;shell&#8221;">shell</a></p>
    ]]></description>
</item>

<item>
    <title>Bash Script: MySQL Backup</title>
    <link>http://crunchbang.org/archives/2007/11/18/bash-script-mysql-backup/</link>
    <pubDate>Sun, 18 Nov 2007 22:11:11 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/11/18/bash-script-mysql-backup/</guid>
    <description><![CDATA[
    <p><em>I thought that it might be a good idea to start posting a few of my scripts; it&#39;ll be handy to have them on my site for future reference. Also, I learn  a lot by reading example scripts &#8212; I guess others might be able to learn from mine.</em></p>

<p>I wrote the following Bash script to perform a backup of a remote MySQL database. The script first connects via SSH and performs a MySQL dump, saving the results to file. It then connects via SFTP and downloads the file. Once the file has been downloaded, it restores the database to my local MySQL server.</p>

<p>It is quite a simple Bash script and it should be fairly straightforward to follow.</p>

<pre><code>#!/bin/sh
# Settings
#############################
REMOTEHOST="example.com"
REMOTEBACKUPDIR="backup/sql"
SQLHOST="localhost"
SQLDB="database_name"
SQLUSER="username"
SQLPASS="password"
SQLFILE="database_name.sql"
LOCALBACKUPDIR="backup/sql"
#############################
# Start main
echo "* Connecting via SSH..."
ssh $REMOTEHOST &lt;&lt;**
echo "* Performing SQL dump..."
if [ -d $REMOTEBACKUPDIR ]; then
    cd $REMOTEBACKUPDIR
else
    mkdir $REMOTEBACKUPDIR
    cd $REMOTEBACKUPDIR
fi
mysqldump -h $SQLHOST --user="$SQLUSER" --password="$SQLPASS" $SQLDB &gt; $SQLFILE
echo "* Closing SSH connection..."
exit
**
cd ~
if [ -d $LOCALBACKUPDIR ]; then
    cd $LOCALBACKUPDIR
else
    mkdir $LOCALBACKUPDIR
    cd $LOCALBACKUPDIR
fi
echo "* Connecting via SFTP..."
sftp $REMOTEHOST &lt;&lt;**
cd $REMOTEBACKUPDIR
get $SQLFILE
exit
**
echo "* Restoring SQL dump to local server..."
mysql --user "$SQLUSER" --password="$SQLPASS" $SQLDB &lt; $SQLFILE
echo "* SQL backup complete."
cd ~
exit 0
</code></pre>

<h3>Notes</h3>

<ol>
<li>For automation purposes, this script assumes that SSH and SFTP have been configured for automatic login. See &#34;<a href="http://crunchbang.org/archives/2007/10/19/creating-privatepublic-ssh-keys/ " title="Creating Private/Public SSH Keys">Creating Private/Public SSH Keys</a>&#34;</li>
<li>It also assumes there is a mirrored MySQL server and user account running on the local machine.</li>
<li>The script can be automated using <a href="http://crunchbang.org/archives/2007/10/26/howto-setup-a-crontab-file/ " title="Howto Set-up a Crontab File">Crontab</a>.</li>
<li>Lacks any error handling and/or logging!?</li>
<li>I&#39;ve worked with some commercial hosting providers who do not grant table locking privileges to their MySQL users &#8212; table locking can be bypassed by adding the &#34;<code>--skip-lock-tables</code>&#34; option to the &#34;<code>mysqldump</code>&#34; command. <em>Use with caution.</em>   </li>
</ol>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/bash/" title="Browse all posts tagged with &#8220;bash&#8221;">bash</a>, <a href="http://crunchbang.org/tags/code/" title="Browse all posts tagged with &#8220;code&#8221;">code</a>, <a href="http://crunchbang.org/tags/linux/" title="Browse all posts tagged with &#8220;linux&#8221;">linux</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/shell/" title="Browse all posts tagged with &#8220;shell&#8221;">shell</a></p>
    ]]></description>
</item>

<item>
    <title>Ternary Operator in PHP</title>
    <link>http://crunchbang.org/archives/2007/11/04/ternary-operator-in-php/</link>
    <pubDate>Sun, 04 Nov 2007 00:43:41 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/11/04/ternary-operator-in-php/</guid>
    <description><![CDATA[
    <p>Over on <a href="http://www.planet-php.net/ " title="Planet PHP - All news in one place.">Planet PHP</a> there&#39;s a running debate [<em>see <a href="http://www.alexatnet.com/node/100 " title="6 PHP coding tips to write less code.">here</a>, <a href="http://www.phpcult.com/blog/02/less-code-vs-good-code/ " title="Less code vs good code.">here</a> &amp; <a href="http://www.phpguru.org/article.php/154 " title="Less code vs good code - my take.">here</a></em>] over the use of the ternary operator. I love a good debate so I thought I&#39;d chip in with my 2 pennies.</p>

<p>The ternary operator looks attractive and can reduce the amount of code that you write. I know this but I still don&#39;t use it. I think PHP is an awesome language and a major contributing factor to its awesomeness is its simplicity. It&#39;s a relatively easy language to learn and I think that the wide spread use of the ternary operator would only increase the barrier to entry [<em>not a good thing!</em>]</p>

<p>Also, I find it interesting that the ternary operator is hardly ever referenced in the comments and code examples at <a href="http://php.net/ " title="PHP.net">PHP.net</a>. Indeed chapter 16 &#34;<a href="http://uk3.php.net/manual/en/language.control-structures.php " title="PHP - Control Structures">Control Structures</a>&#34; of the manual hardly mentions it at all.</p>

<h3>Ternary operator code example</h3>

<p>In case you&#39;ve no idea what this post is about.</p>

<p><strong>Before:</strong> <em>no ternary operator, easy to understand</em></p>

<pre><code>if ($treat == 'cream') {
    $cat = 'Happy!';
} else {
    $cat = 'Not so happy.';
}
</code></pre>

<p><strong>After:</strong> <em>ternary operator in use, less code but not so easy to understand</em></p>

<pre><code>$cat = ($treat == 'cream') ? 'Happy!' : 'Not so happy.';
</code></pre>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/code/" title="Browse all posts tagged with &#8220;code&#8221;">code</a>, <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a></p>
    ]]></description>
</item>

<item>
    <title>User Agent Sniffer</title>
    <link>http://crunchbang.org/archives/2007/10/18/user-agent-sniffer/</link>
    <pubDate>Thu, 18 Oct 2007 08:52:21 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/10/18/user-agent-sniffer/</guid>
    <description><![CDATA[
    <p>I&#39;ve currently got several web projects at various stages of development. One thing that all of these projects have in common is that they all capture and manipulate user-agent stings.</p>

<h3>What are user-agent strings?</h3>

<p>User-agents strings are used by client applications such as web browsers, feed readers, bots and other software to identify themselves to the servers they are connecting to. The strings contain important information such as application type, version, language and operating system. A typical user-agent string might look like this:</p>

<pre><code>Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.7 (like Gecko) (Kubuntu)
</code></pre>

<p>The above example is used to identify that the client is a Mozilla compatible Konqueror web browser running on Kubuntu Linux.</p>

<h3>Collecting user-agent strings</h3>

<p>To run tests on my projects I need some sample data to play around with [<em>a list or database table of user-agent strings.</em>] I figured that the best way to get this sample data would be to collect some user-agent strings from the wild. So, I wrote a quick PHP script to do just that.</p>

<p>I ran the script on this site [<em>crunchbang.org</em>] for ten days, starting on October 7th 2007. During that ten day period the script captured a total of 2272 unique user-agent strings. The captured list included both standard and non-standard strings.</p>

<h3>A few facts about user-agent strings</h3>

<p>After capturing the list I then edited the PHP script so that it would report a few facts. Here is a breakdown of what was returned:</p>

<p><strong>1.</strong> At just 6 characters in length the shortest user-agent string captured was:</p>

<pre><code>NG/2.0
</code></pre>

<p><strong>2.</strong> The longest measured in at 205 characters, it was:</p>

<pre><code>Mozilla/5.0 (compatible; MSIE 7.0; Windows; HTMLAB; .NET CLR 1.1.4322; 
MEGAUPLOAD 1.0; Seekmo; ZangoToolbar4.8.2; Alexa Toolbar; Hotbar 4.2.8.0) (compatible; 
Googlebot/2.1; +http://www.google.com/bot.html)
</code></pre>

<p><strong>3.</strong> The average computed length of the user-agent strings was 91.2750880282 characters.</p>

<p><strong>4.</strong> Most strings contained some non-alphanumeric characters, these were:</p>

<pre><code>/ . ( ; - : ) + _ ! = , @ &amp;  ' [ ] * ~ ? { }
</code></pre>

<p><strong>5.</strong> The strangest user-agent string was:</p>

<pre><code>Mmm.... Brains....
</code></pre>

<h3>View the whole report</h3>

<p>You can view the whole report here: <a href="http://crunchbang.org/misc/user-agent-report-2007-10-17.txt " title="View the User Agent Sniffer report.">http://crunchbang.org/misc/user-agent-report-2007-10-17.txt</a></p>

<h3>Get the sample data</h3>

<p>I thought it would be good to share the sample data. There&#39;s no private or confidential information in the data and I figure it may come in handy for other developers working on similar projects.</p>

<p>You can get the data as an ASCII file [<em>one user-agent string per line</em>] here: <a href="http://crunchbang.org/misc/sample-user-agents-ascii.txt " title="Get the sample data as a flat ascii file.">http://crunchbang.org/misc/sample-user-agents-ascii.txt</a></p>

<p>Or, as an SQL statement here: <a href="http://crunchbang.org/misc/sample-user-agents-mysql.txt " title="Insert the sample data into a MySQL database using this SQL statement.">http://crunchbang.org/misc/sample-user-agents-mysql.txt</a></p>

<h3>Get the PHP script</h3>

<p>If you fancy having a go at collecting your own samples you can grab my PHP script here: <a href="http://crunchbang.org/misc/ua-sniffer.txt " title="Get the User Agent Sniffer PHP script.">http://crunchbang.org/misc/ua-sniffer.txt</a></p>

<p>The script requires the use of MySQL. Other than that it&#39;s a fairly straightforward affair. Just edit the four settings to define your database name, address, username and password.</p>

<p>I ran the script by calling it with a <code>require_once</code> statement. Note that the script also sets and reads a cookie so you&#39;ll need to call on it before outputting any data to the client.</p>

<pre><code>require_once("ua-sniffer.php");
</code></pre>

<p>Once the script has collected some user-agent strings it is possible to query it and have it produce a basic report. You can do this by accessing the script through your browser like so:</p>

<pre><code>http://www.example.com/ua-sniffer.php?report=true
</code></pre>

<h3>Links to external references</h3>

<ul>
<li><a href="http://en.wikipedia.org/wiki/User_agent " title="User Agent article on Wikipedia">User Agent article on Wikipedia</a></li>
<li><a href="http://www.user-agents.org/ " title="List of User-Agents at user-agents.org">List of User-Agents at user-agents.org</a></li>
<li><a href="http://www.zytrax.com/tech/web/browser_ids.htm " title="Browser ID strings at zytrax.com">Another list of browser ID strings</a></li>
<li><a href="http://www.useragentstring.com/ " title="User agent string analysis">User agent string analysis</a></li>
</ul>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/code/" title="Browse all posts tagged with &#8220;code&#8221;">code</a>, <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/projects/" title="Browse all posts tagged with &#8220;projects&#8221;">projects</a>, <a href="http://crunchbang.org/tags/scripts/" title="Browse all posts tagged with &#8220;scripts&#8221;">scripts</a></p>
    ]]></description>
</item>

<item>
    <title>Silly Variable Names</title>
    <link>http://crunchbang.org/archives/2007/09/30/silly-variable-names/</link>
    <pubDate>Sun, 30 Sep 2007 06:19:05 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/09/30/silly-variable-names/</guid>
    <description><![CDATA[
    <p>They&#39;re not big and they&#39;re not clever. So how come they keep slipping into my code?</p>

<pre><code>if(!empty($bum)){
    unload($bum);
}
</code></pre>

<p><strong>Note to self:</strong> stop with the silly variable names already!</p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/code/" title="Browse all posts tagged with &#8220;code&#8221;">code</a>, <a href="http://crunchbang.org/tags/fun/" title="Browse all posts tagged with &#8220;fun&#8221;">fun</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a></p>
    ]]></description>
</item>

<item>
    <title>Whird Prototype - Time to Branch</title>
    <link>http://crunchbang.org/archives/2007/09/29/whird-prototype-time-to-branch/</link>
    <pubDate>Sat, 29 Sep 2007 08:25:52 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/09/29/whird-prototype-time-to-branch/</guid>
    <description><![CDATA[
    <p>CrunchBang.org is currently served up by an early prototype of a new PHP blogging application. I&#39;m creating the application [<em>which I&#39;ve provisionally named Whird</em>] on my development server at home. I mention this because I&#39;ve now reached a point where I need to make a decision.</p>

<p>An issue and potential problem has arisen due to the fact that I&#39;ve been developing the application in the style of this here site. While this hasn&#39;t given me any problems so far, I don&#39;t want cause any additional work for myself in the future. I need to branch the project so that any customisations that I make specific to CrunchBang.org don&#39;t slip into the final project.</p>

<p>I guess this is a milestone in this projects history; from now on I&#39;ll be writing for a more generic code base. Hopefully it&#39;ll stop things from getting too messy round here.</p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a>, <a href="http://crunchbang.org/tags/projects/" title="Browse all posts tagged with &#8220;projects&#8221;">projects</a>, <a href="http://crunchbang.org/tags/whird/" title="Browse all posts tagged with &#8220;whird&#8221;">whird</a></p>
    ]]></description>
</item>

<item>
    <title>Everyone Should Learn Some Programming</title>
    <link>http://crunchbang.org/archives/2007/09/29/everyone-should-learn-some-programming/</link>
    <pubDate>Sat, 29 Sep 2007 02:23:38 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/09/29/everyone-should-learn-some-programming/</guid>
    <description><![CDATA[
    <p>From <a href="http://www.hezmatt.org/~mpalmer/blog/general/the_plain_text_pda.html " title="The Plain Text PDA">an article on Brane Dump</a>:</p>

<blockquote>
  <p>This, in my opinion, is why everybody (literally, every single person) should learn to program at some fairly simple level, like learning to read and write. By using plain text and small scripts, I&#39;ve got a workflow that works for me, and it&#39;s cost me less time than I&#39;d spend learning some large pre-written app and putting all my data into it. Being able to manipulate data like this is, I think, a fairly important tool in the modern world, and I don&#39;t think it should be left to any sort of priesthood of developers &#8212; it should be as universal as most countries try to make literacy and numeracy.</p>
</blockquote>

<p>I couldn&#39;t agree more with this, however I think it&#39;s a bit of a stretch of the imagination to think it&#39;ll ever happen &#8212; more so when you <a href="http://worsethanfailure.com/Articles/Diary-of-a-ThirdClass-Programmer.aspx " title="Worse Than Failure: Diary of a Third-Class Programmer">read stuff like this</a>.</p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a></p>
    ]]></description>
</item>

<item>
    <title>PHP: strrpos() vs strpos()</title>
    <link>http://crunchbang.org/archives/2007/09/26/php-strrpos-vs-strpos/</link>
    <pubDate>Wed, 26 Sep 2007 12:45:48 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/09/26/php-strrpos-vs-strpos/</guid>
    <description><![CDATA[
    <p>I normally wouldn&#39;t post about such trivial matters, however this particular trivial matter bugged me for several hours this afternoon, so I thought I mention it.</p>

<p>It seems that one of the problems of coding on a development server that runs PHP 5 for a production server that runs PHP 4 is the subtle differences in the language. These subtle differences can really throw a spanner in the works [<em>like one did to me this afternoon.</em>]</p>

<p>Basically my development code used the <a href="http://php.net/manual/en/function.strrpos.php " title="PHP Manual - strrpos">strrpos()</a> function to attempt to find the first occurrence of a string within a string. While this worked just fine with PHP 5, it bombed big time with PHP 4 [<em>which will only find the first occurrence of a single character.</em>] Apparently I should have been using the <a href="http://php.net/manual/en/function.strpos.php " title="PHP Manual - strpos">strpos()</a> function instead!</p>

<p>Oh well, live and learn.</p>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a></p>
    ]]></description>
</item>

<item>
    <title>7 Reasons He Switched Back to PHP</title>
    <link>http://crunchbang.org/archives/2007/09/26/7-reasons-he-switched-back-to-php/</link>
    <pubDate>Wed, 26 Sep 2007 03:37:10 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2007/09/26/7-reasons-he-switched-back-to-php/</guid>
    <description><![CDATA[
    <blockquote>
  <p>I didn’t abandon the rewrite IDEA, though. I just asked myself one important question:<br />
  “Is there anything Rails can do, that PHP CAN’T do?”<br />
  The answer is no.</p>
</blockquote>

<p>Derek Silvers writes a <a href="http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html " title="7 reasons not to start using Rails.">good article</a> with 7 good reasons as to why he switched back to PHP after 2 years of coding Ruby on Rails.</p>

<p>I&#39;ve always liked the idea of learning Rails, [<em>is it just me or has Rails been portrayed as a sexy/trendy language?</em>] but I&#39;ve never started because PHP has always been good enough for my own projects. I&#39;m glad I didn&#39;t waste 2 years learning another language just to find that out!</p>

<p>My favourite reason from the article:</p>

<blockquote>
  <p>7 - PROGRAMMING LANGUAGES ARE LIKE GIRLFRIENDS: THE NEW ONE IS BETTER BECAUSE <em>YOU</em> ARE BETTER</p>
</blockquote>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/php/" title="Browse all posts tagged with &#8220;php&#8221;">php</a>, <a href="http://crunchbang.org/tags/programming/" title="Browse all posts tagged with &#8220;programming&#8221;">programming</a></p>
    ]]></description>
</item>

 </channel>
</rss>