<?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>#! &#187; Hacks</title>
	<atom:link href="http://hash-bang.net/tag/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://hash-bang.net</link>
	<description>The start of all wonderful things</description>
	<lastBuildDate>Sun, 15 May 2011 03:36:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<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('p151code3'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1513"><td class="code" id="p151code3"><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('p151code4'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1514"><td class="code" id="p151code4"><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('p136code9'); return false;">View Code</a> PERL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1369"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p136code9"><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('p136code10'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13610"><td class="code" id="p136code10"><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('p136code11'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13611"><td class="code" id="p136code11"><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('p136code12'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13612"><td class="code" id="p136code12"><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>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="p12715"><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="p127code15"><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="p12716"><td class="code" id="p127code16"><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>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="p9519"><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="p95code19"><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('p95code20'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9520"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p95code20"><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>13</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="p8123"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p81code23"><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('p81code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8124"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p81code24"><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>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('p48code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4827"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p48code27"><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="p4828"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p48code28"><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="p4230"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p42code30"><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>

