<?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>Confessions of a Guru</title>
	<atom:link href="http://www.guru.net.nz/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.guru.net.nz/blog</link>
	<description>Random stuff from a Dunedin (NZ) based web developer, beer drinker and dad</description>
	<lastBuildDate>Sun, 22 Apr 2012 20:56:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Dunedin area code to location list</title>
		<link>http://www.guru.net.nz/blog/2012/04/dunedin-area-code-to-location-list.html</link>
		<comments>http://www.guru.net.nz/blog/2012/04/dunedin-area-code-to-location-list.html#comments</comments>
		<pubDate>Sun, 22 Apr 2012 12:47:33 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=480</guid>
		<description><![CDATA[When you know an area well you get to know the area code for local suburbs &#8211; e.g. Mosgiel people know that all other Mosgiel people (and some close neighbours) are &#8220;489&#8243;. I figured it shouldn&#8217;t be too hard to collect that data from online services and then do some analysis on it. Armed with [...]]]></description>
			<content:encoded><![CDATA[<p>When you know an area well you get to know the area code for local suburbs &#8211; e.g. Mosgiel people know that all other Mosgiel people (and some close neighbours) are &#8220;489&#8243;. I figured it shouldn&#8217;t be too hard to collect that data from online services and then do some analysis on it. Armed with PHP and jQuery (which I must commend for being super accommodating through this process) I present you with the results.</p>
<pre>--------------------------------------------------------------------------
DUNEDIN PHONE NUMBER TO AREA LIST
--------------------------------------------------------------------------
  This list is based on a subset of 2,795 phone numbers
  Generated Mon, 23 Apr 2012 00:44:03 +1200 from public phone number lists.
  Compiled by bob@guru.net.nz, www.guru.net.nz.
  This list contains 28 phone suffixes and 96 distinct areas.

  Note: The % in the list is how many numbers in that area code are in the
  listed suburb (e.g. if 03-453 says Mornington 44% and Belleknowes 21% then
  that means that 44% of the 03-453 area numbers are Mornington based and 21%
  are Belleknowes based)
</pre>
<p><span id="more-480"></span></p>
<pre>--------------------------------------------------------------------------
Prefix 03-453 (based on 139 numbers):
	Mornington: 44%
	Belleknowes: 21%
	Kenmure: 14%
	Maryhill: 11%
	Bradford: 6%
	Kaikorai Valley: 3%
	Balaclava: 2%
	Caversham: 1%

Prefix 03-454 (based on 141 numbers):
	Andersons Bay: 36%
	Waverley: 34%
	Highcliff: 11%
	Vauxhall: 7%
	Ocean Grove: 5%
	Portobello: 3%
	Tainui: 3%
	Shiel Hill: 3%
	Bayfield: 2%

Prefix 03-455 (based on 230 numbers):
	St Kilda: 30%
	South Dunedin: 25%
	Saint Clair: 14%
	Caversham: 13%
	Musselburgh: 10%
	Forbury: 4%
	Tainui: 3%
	Andersons Bay: 2%
	Maryhill: 1%
	The Glen: 1%
	Kenmure: 1%
	Clyde Hill: 1%
	St Clair: 1%
	Abbotsford: 1%
	Waverley: 1%
	Highcliff: 1%

Prefix 03-456 (based on 67 numbers):
	South Dunedin: 26%
	St Kilda: 26%
	Caversham: 17%
	Saint Clair: 12%
	Musselburgh: 5%
	Portobello: 5%
	Tainui: 3%
	Andersons Bay: 3%
	Forbury: 3%
	Belleknowes: 2%
	Kenmure: 2%

Prefix 03-464 (based on 47 numbers):
	Maori Hill: 43%
	Middlemarch: 24%
	Roslyn: 18%
	Wakari: 7%
	Kaikorai: 5%
	Highgate: 5%
	Balmacewen: 3%

Prefix 03-465 (based on 32 numbers):
	Waikouaiti: 100%

Prefix 03-466 (based on 30 numbers):
	Wakari: 27%
	Maori Hill: 27%
	Balmacewen: 10%
	Roslyn: 7%
	South Dunedin: 7%
	Andersons Bay: 7%
	Highgate: 7%
	Saint Clair: 4%
	Mornington: 4%
	Kaikorai: 4%

Prefix 03-467 (based on 77 numbers):
	Maori Hill: 38%
	Glenleith: 21%
	Roslyn: 17%
	Woodhaugh: 8%
	Wakari: 7%
	Kaikorai: 4%
	Highgate: 3%
	Dunedin North: 3%
	Balmacewen: 2%

Prefix 03-470 (based on 5 numbers):
	Liberton: 20%
	Kaikorai Valley: 20%
	Kenmure: 20%
	Roslyn: 20%
	Dunedin Central: 20%

Prefix 03-471 (based on 31 numbers):
	Ravensbourne: 55%
	St Leonards: 26%
	Roslyn: 13%
	Mosgiel: 4%
	Maia: 4%

Prefix 03-472 (based on 50 numbers):
	Port Chalmers: 80%
	Sawyers Bay: 12%
	Aramoana: 4%
	Roseneath: 4%

Prefix 03-473 (based on 98 numbers):
	North East Valley: 38%
	Pine Hill: 18%
	Opoho: 14%
	Dalmore: 10%
	Normanby: 9%
	Liberton: 9%
	Dunedin North: 5%
	Mornington: 2%
	Dunedin Central: 2%

Prefix 03-474 (based on 10 numbers):
	Roslyn: 30%
	Belleknowes: 30%
	Aramoana: 10%
	Pine Hill: 10%
	Green Island: 10%
	Dunedin Central: 10%

Prefix 03-476 (based on 170 numbers):
	Brockville: 22%
	Halfway Bush: 21%
	Macandrew Bay: 19%
	Helensburgh: 13%
	Wakari: 12%
	Kaikorai: 9%
	Portobello: 3%
	Company Bay: 2%
	Roslyn: 2%
	Kaikorai Valley: 1%
	Kenmure: 1%
	Highcliff: 1%

Prefix 03-477 (based on 46 numbers):
	Roslyn: 48%
	Belleknowes: 18%
	Dunedin North: 9%
	Dunedin Central: 5%
	Mosgiel: 5%
	Taieri Mouth: 5%
	Maori Hill: 3%
	Kaikorai Valley: 3%
	Highgate: 3%
	Company Bay: 3%
	Halfway Bush: 3%
	Kaikorai: 3%

Prefix 03-478 (based on 36 numbers):
	Portobello: 53%
	Broad Bay: 31%
	Harwood: 12%
	Harington Point: 6%

Prefix 03-479 (based on 8 numbers):
	Roslyn: 88%
	Mornington: 13%

Prefix 03-481 (based on 34 numbers):
	Brighton: 68%
	Taieri Mouth: 21%
	Musselburgh: 3%
	Ocean View: 3%
	Saddle Hill: 3%
	Taieri Beach: 3%

Prefix 03-482 (based on 29 numbers):
	Warrington: 32%
	Waitati: 32%
	Long Beach: 11%
	Doctors Point: 7%
	Pigeon Flat: 4%
	Waikouaiti: 4%
	Port Chalmers: 4%
	Osborne: 4%
	Mount Cargill: 4%
	Purakaunui: 4%

Prefix 03-484 (based on 32 numbers):
	Mosgiel: 72%
	East Taieri: 13%
	North Taieri: 7%
	Wyllies Crossing: 7%
	Wingatui: 4%

Prefix 03-486 (based on 20 numbers):
	Outram: 90%
	Maungatua: 5%
	Henley: 5%

Prefix 03-487 (based on 101 numbers):
	Caversham: 29%
	Corstorphine: 23%
	Saint Clair: 22%
	Kew: 16%
	Concord: 9%
	Green Island: 2%

Prefix 03-488 (based on 169 numbers):
	Green Island: 28%
	Fairfield: 25%
	Abbotsford: 20%
	Concord: 6%
	Brighton: 6%
	Waldronville: 5%
	Burnside: 3%
	Sunnyvale: 3%
	Kenmure: 3%
	Kaikorai Valley: 2%
	Mornington: 2%
	Mosgiel: 1%

Prefix 03-489 (based on 312 numbers):
	Mosgiel: 85%
	East Taieri: 6%
	Wingatui: 2%
	Outram: 2%
	Allanton: 2%
	Saddle Hill: 1%
	Taieri Plains: 1%
	R D 1: 1%
	North Taieri: 1%
	Kinmont Park: 1%
	Chain Hills: 1%
	Wyllies Crossing: 1%

Prefix 03-552 (based on 8 numbers):
	Dunedin Central: 38%
	Liberton: 13%
	Brockville: 13%
	North East Valley: 13%
	Waverley: 13%
	Normanby: 13%

Prefix 03-742 (based on 2 numbers):
	Highcliff: 50%
	Portobello: 50%

Prefix 03-949 (based on 4 numbers):
	St Kilda: 50%
	Dunedin Central: 50%

Prefix 04-387 (based on 2 numbers):
	Melrose: 100%</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2012/04/dunedin-area-code-to-location-list.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up an Ubuntu 10.10 laptop for LAMP development</title>
		<link>http://www.guru.net.nz/blog/2011/12/setting-up-an-ubuntu-10-10-laptop-for-lamp-development.html</link>
		<comments>http://www.guru.net.nz/blog/2011/12/setting-up-an-ubuntu-10-10-laptop-for-lamp-development.html#comments</comments>
		<pubDate>Mon, 12 Dec 2011 08:42:04 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=449</guid>
		<description><![CDATA[I&#8217;m blogging this mostly for my reference as I occasionally reinstall my laptop and always forget the steps to get back to a good state. Aim: Ubuntu Linux 10.10 desktop Apache 2.2 MySQL 5.1 PHP 5.2 Firstly, install Ubuntu 10.10. Make sure you opt to encrypt your home directory. While this means it&#8217;s difficult to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m blogging this mostly for my reference as I occasionally reinstall my laptop and always forget the steps to get back to a good state.</p>
<p>Aim:</p>
<ul>
<li>Ubuntu Linux 10.10 desktop</li>
<li>Apache 2.2</li>
<li>MySQL 5.1</li>
<li>PHP 5.2</li>
</ul>
<p>Firstly, install Ubuntu 10.10. Make sure you opt to encrypt your home directory. While this means it&#8217;s difficult to recover contents of your home directory in the event of an OS crash, it&#8217;s also means you can sleep at night knowing that if you lose your laptop you haven&#8217;t lost your intellectual property. The system overhead for doing this is not really noticable. The down side of this is that you cannot access the files unless you&#8217;re logged on (see the bit later about the projects directory and Apache).</p>
<p>Now, let&#8217;s install Apache, MySQL and PHP. Note that I&#8217;m installing some extra packages that I need for my development purposes.</p>
<pre>bob@bob-laptop:~$ sudo apt-get install libapache2-mod-php5 mysql-server php5-mysql
bob@bob-laptop:~$ sudo apt-get install php5-curl php-pear  # some extras I use
bob@bob-laptop:~$ sudo apt-get install openssh-server subversion bzr  # some extras I use</pre>
<p>During the installation of those packages you&#8217;ll be asked for a password for the MySQL root user. I always use &#8220;root&#8221; for my convenience. You can use whatever you like. This user does not have root access to the system, but will have full access to the MySQL databases. By default MySQL only listens on the localhost interface so an insecure password like &#8220;root&#8221; is acceptable for my purposes. You&#8217;ll see later that we can shift certain databases to reside on the encrypted home directory if that&#8217;s important to you.</p>
<p><strong>Set up the projects directory</strong></p>
<p>I like to keep all my web stuff in a subdirectory of my home directory called projects. The full path to that will be /home/bob/projects. In order to be able to browse these projects with Apache I&#8217;ll put a symlink in /var/www (Apache&#8217;s default web root directory) to it.</p>
<p>Here&#8217;s a terminal session where I create the projects directory.</p>
<pre>bob@bob-laptop:~$ mkdir ~/projects
bob@bob-laptop:~$ sudo ln -s ~/projects /var/www/projects
bob@bob-laptop:~$ ls -l /var/www
total 4
-rw-r--r-- 1 root root 177 2011-12-11 15:30 index.html
lrwxrwxrwx 1 root root  18 2011-12-12 21:25 projects -&gt; /home/bob/projects</pre>
<p>Great. But now if you try to access <a href="http://localhost/projects">http://localhost/projects</a> you&#8217;ll get a 403 Forbidden page. This is because Apache isn&#8217;t able to see your home directory. A small tweak will fix that.</p>
<pre>bob@bob-laptop:~$ chmod o+x ~</pre>
<p>Note that this command will allow any other user (of which Apache&#8217;s www-data is one) on your system to see the files in your home directory. For me this isn&#8217;t an issue as I&#8217;m the only user on my system.</p>
<p>Now if you revisit <a href="http://localhost/projects">http://localhost/projects</a> you&#8217;ll get a directory index instead of a 403 Forbidden page. You can now create files in /home/bob/projects (or whatever your user name is) and Apache will be able to serve them up to your web browser.</p>
<p>Note that because we opted to encrypt the home directory, the /home/bob directory is only mounted when bob logs in. This means that if you boot your system and try to access it over the network without being logged in, you&#8217;ll likely get a 403 Forbidden or 404 Page Not Found error for any URL in /projects. Other files can be placed in /var/www/whateveryoulike and will be accessible regardless.</p>
<p>Example:</p>
<pre>bob@bob-laptop:~/projects$ cat &gt; phpinfo.php
&lt;?php phpinfo(); ?&gt;</pre>
<p>(press Ctrl-D after typing the phpinfo() line to save the file)</p>
<p>Now if you browse to <a href="http://localhost/projects/phpinfo.php">http://localhost/projects/phpinfo.php</a> you will get the standard PHP Information page.</p>
<p><strong>Using an encrypted database</strong></p>
<p>We&#8217;re not so much using an encrypted database as we are moving it onto an encrypted file system. We use the same trick that we used for Apache but we&#8217;re doing this for MySQL. Note that while it is possible to have all databases encrypted, you will need to make sure you log on first before you start MySQL. Here I will just encrypt one database:</p>
<pre>-- Create a mysql directory in my home dir.
bob@bob-laptop:~$ mkdir ~/mysql

-- Create a sample mysql database called 'secure'
bob@bob-laptop:~$ mysqladmin -uroot -proot create secure

-- Stop the mysql service
bob@bob-laptop:~$ sudo stop mysql
mysql stop/waiting

-- Move the newly created 'secure' database to my home dir
bob@bob-laptop:~$ sudo mv /var/lib/mysql/secure ~/mysql

-- Create a symbolic link for mysql to use
bob@bob-laptop:~$ sudo ln -s ~/mysql/secure /var/lib/mysql/secure

-- Start mysql again
bob@bob-laptop:~$ sudo start mysql
mysql start/running, process 2778

-- Now access the database in the new place
bob@bob-laptop:~$ mysql -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.1.49-1ubuntu8.1 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql&gt; use secure;
Database changed</pre>
<p>No errors &#8211; the connection was successful. Again the same thing applies in that you can only access this database while you are logged on.</p>
<p><strong>.htaccess files</strong> (optional, but recommended)<br />
Out of the box, Apache won&#8217;t read .htaccess files. To enable these permanently for all directories under your /var/www directory (including the project directory), edit the /etc/apache2/sites-enabled/000-default file (as root) and change line 11 to say &#8220;AllowOverride All&#8221; (instead of None).</p>
<p><strong>mod_rewrite</strong> (optional, but recommended)</p>
<p>Also, you may want to enable mod_rewrite as many web applications use this to generate nice looking URL&#8217;s.</p>
<pre>bob@bob-laptop:~$ sudo a2enmod rewrite
bob@bob-laptop:~$ sudo apache2ctl restart</pre>
<p><strong>xdebug plugin for PHP</strong></p>
<p>The xdebug plugin gives you nice stack traces and formatted var_dump()s which makes it easier to develop. It also comes with breakpoints, remote debugging and a range of other things. Check out the whole shebang at <a href="http://xdebug.org/">http://xdebug.org/</a>.</p>
<p>Installation is simple:</p>
<pre>
bob@bob-laptop:~$ sudo apt-get install php5-xdebug
</pre>
<p>Restart Apache for the change to take effect (sudo apache2ctl restart).</p>
<p><strong>Enabling display of errors in your browser</strong></p>
<p>By default PHP ships with display_errors = Off. This is a requirement for a production system but it will drive you nuts on a development box. When off, any errors are logged to Apache&#8217;s error_log file in /var/log/apache.</p>
<p>To turn it on, edit the file /etc/php5/apache2/php.ini and look for the lines like this:</p>
<pre>
display_errors = Off
display_startup_errors = Off
html_errors = Off
</pre>
<p>And change them all to &#8220;On&#8221;. Again, restart Apache for the change to take effect (sudo apache2ctl restart).</p>
<p>Happy developing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2011/12/setting-up-an-ubuntu-10-10-laptop-for-lamp-development.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consistency</title>
		<link>http://www.guru.net.nz/blog/2011/12/consitency.html</link>
		<comments>http://www.guru.net.nz/blog/2011/12/consitency.html#comments</comments>
		<pubDate>Sat, 10 Dec 2011 10:57:37 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=433</guid>
		<description><![CDATA[Warning: this may be the most valuable blog post you ever read. I&#8217;ve been developing for a long time &#8211; the first programs that I first wrote that other people were using was back in 1992. At the time, I was the only one working on the code and there was no reason for others [...]]]></description>
			<content:encoded><![CDATA[<p>Warning: this may be the most valuable blog post you ever read.</p>
<p>I&#8217;ve been developing for a long time &#8211; the first programs that I first wrote that other people were using was back in 1992. At the time, I was the only one working on the code and there was no reason for others to get involved. In fact back then it seemed that we were driven by one-upmanship and sharing code was almost unheard of, unless you had to get an assignment in the next day and you had some stupid reason for not being able to complete it, then someone might take pity on your ass and bail you out. Back then, consistency wasn&#8217;t important &#8211; what mattered was whether the code ran or not. Even better if it ran and you got paid.</p>
<p>If there&#8217;s one thing I could share with you about my experiences over the last twenty years, I would have to say that it&#8217;s this. Be consistent.</p>
<p>Consider the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'select * from customer where id = 123'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$identifier</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$identifier</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We&#8217;re fetching a row from a table and echoing out the id field. The code above doesn&#8217;t really matter, but what does matter is the inconsistency. Can you spot it?</p>
<p>The inconsistency is that the field in the database is called &#8220;id&#8221; and we put it into a variable called $identifier. This does not break the code, but it does mean that you have just introduced an inconsistency that will bite you.</p>
<p>That&#8217;s a pretty simple example, but imagine those kind of differences across an entire application, a database schema or even your whole organisation. It happens, and all too frequently.</p>
<p>The consistency issue isn&#8217;t a coding style issue &#8211; let me be very clear on that &#8211; it&#8217;s more a culture issue. You need to work hard to spot these inconsistencies in your organisation and nip them in the bud really early. And they may not appear in code either. You can find them anywhere from code, to documentation, to common usage in discussions in the workplace.</p>
<p>If you let these inconsistencies propagate you&#8217;re going to have to deal with them time and time again. Here&#8217;s a real world example: I am dealing with a system at the moment where products are identified by their SKU number (Stock Keeping Unit). This number has been referred to as the following in various places (code, documentation, wiki pages, emails etc):</p>
<ul>
<li>ItemCode</li>
<li>ItemId</li>
<li>Item_Id</li>
<li>ItemID (yes, case makes a difference!)</li>
<li>ItemSKU</li>
<li>Identifier</li>
<li>Identifer (yes, misspelling of Identifier)</li>
<li>ProductId</li>
<li>ProductSku</li>
<li>SKU</li>
</ul>
<p>The boat has sailed on that one &#8211; there is no way that this situation could be wrestled under control, you&#8217;ll have to do what you can if you come across this. But if you have the luxury of a fresh project then it&#8217;s time to gather your troops and spell it out on the board &#8211; CONSISTENCY. Drum it into your processes and procedures, your code reviews and commit messages. There&#8217;s no excuse for any inconsistency at all &#8211; especially when it will cost you in time chasing bugs because the value isn&#8217;t turning up like it should or the record isn&#8217;t saving.</p>
<p>If you haven&#8217;t already I highly recommend putting together some coding standards for your company &#8211; or even for yourself. And follow them to the letter. It doesn&#8217;t really matter what style of indenting you use (K&amp;R, Allman, BSD KNF, Whitesmiths etc) &#8211; what matters is that you&#8217;re &#8230; you know what I&#8217;m going to say don&#8217;t you.</p>
<p>Feel free to borrow from the <a title="Turboweb Coding Standards" href="http://dev.turboweb.co.nz/turboweb-coding-standards/" target="_blank">Turboweb Coding Standards</a> (which in turn were based on the Drupal Coding Standards). Make sure that your new starts read your coding standards and understand them. And take time to teach them well.</p>
<p>Addendum: Ironically I managed to misspell the title of this blog post, I&#8217;ve now corrected it but as the link is out and about on various social media sites I can&#8217;t change that, therefore if you&#8217;re viewing this post by itself you&#8217;ll see that the URL says &#8220;consitency&#8221; <img src='http://www.guru.net.nz/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2011/12/consitency.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Debian Testing from USB Key</title>
		<link>http://www.guru.net.nz/blog/2011/12/installing-debian-testing-from-usb-key.html</link>
		<comments>http://www.guru.net.nz/blog/2011/12/installing-debian-testing-from-usb-key.html#comments</comments>
		<pubDate>Fri, 09 Dec 2011 10:22:25 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=427</guid>
		<description><![CDATA[I&#8217;ve been on the hunt for a new Linux Distribution for a while &#8211; Ubuntu 11.10 &#8211; while impressive &#8211; is too much for my seven year old laptop. I&#8217;m a bit disgusted really that with 704MB of available RAM that it doesn&#8217;t really work as snappily as a plain TTY But, to be fair [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been on the hunt for a new Linux Distribution for a while &#8211; Ubuntu 11.10 &#8211; while impressive &#8211; is too much for my seven year old laptop. I&#8217;m a bit disgusted really that with 704MB of available RAM that it doesn&#8217;t really work as snappily as a plain TTY <img src='http://www.guru.net.nz/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  But, to be fair to Ubuntu I am running it on my work PC now as of yesterday and while there are some obvious annoyances (e.g. no panels in Unity, sometimes losing applications from the task switcher) it&#8217;s certainly a promising start. They tell me 12.04 is going to be well polished &#8211; ps. Good luck Thomi with the new job!</p>
<p>I&#8217;ve tried Linux Mint and again, the standard of this distribution is exceptional, but again the seven-year-old super-laptop grimaces a little too much under the weight.</p>
<p>This blog post is about installing Debian Testing from a USB key. I hunted around for how to do it and the answer wasn&#8217;t immediately apparent. There are tutorials that help you out by getting you to zcat a boot.img.gz onto your USB key, then copy the Debian ISO etc but this didn&#8217;t work for me. I think this was because the method was outdated and not compatible with the latest ISO.</p>
<p>By the way &#8211; don&#8217;t be put off by the term &#8220;testing&#8221; when it comes to Debian. The stable release may seem to be the likely choice and it is very stable &#8211; it hardly changes and is deliberately out of date. Only security updates are applied to it. This is suitable for a server environment, or for your mum if having slightly out of date applications isn&#8217;t an issue and you don&#8217;t want things changing on her. If you want a more up to date distribution that keeps pace with the latest applications, go for Debian Testing. If you want the bleeding edge latest developer release, go for Debian Unstable. You probably don&#8217;t want this though.</p>
<p>Anyway, back to the installation &#8211; fortunately the solution is very simple. <a href="http://wiki.debian.org/DebianEeePC/HowTo/InstallUsingStandardInstaller">Over here</a> they say that the latest Debian ISO&#8217;s can be directly dd&#8217;d to a USB drive. This means that you can simply:</p>
<ol>
<li>Download the Debian Testing ISO (I chose the netinst ISO which will bootstrap me onto the network during the install process and then drag the rest off the internet as required)</li>
<li>Plug in your USB key to your linux box</li>
<li>Unmount it if it got automatically mounted (e.g. right click it on the desktop and choose unmount)</li>
<li>Install it onto your USB key with the following command: dd if=/path/to/debian-testing-i386-netinst.iso <strong>of=/dev/sdd</strong> bs=1M</li>
<li>When that has finished, boot your computer from your USB key and the Debian installer will lead you through the installation process (I&#8217;m at 87% currently)</li>
</ol>
<div>Note that the of=/dev/sdd in bold above has to be the correct name of your USB key. You can find this out by plugging in your key and using the command &#8220;sudo fdisk -l&#8221; which will list all disk devices plugged into your computer. Look for the one that has just appeared and is the correct size.</div>
<div>Also note that when you issue the dd command that all information on your USB key will be overwritten. If you don&#8217;t know, the dd command can be used to take a file (generally) and write the contents of that file to a physical media (e.g. a hard drive, or a USB key) in such a way that it overwrites the entire filesystem on that device.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2011/12/installing-debian-testing-from-usb-key.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP&#8217;s DateTime built-in class vs. Zend_Date</title>
		<link>http://www.guru.net.nz/blog/2011/10/phps-datetime-built-in-class-vs-zend_date.html</link>
		<comments>http://www.guru.net.nz/blog/2011/10/phps-datetime-built-in-class-vs-zend_date.html#comments</comments>
		<pubDate>Sun, 30 Oct 2011 21:59:43 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=423</guid>
		<description><![CDATA[If you ever wanted a reason not to use PHP&#8217;s built-in DateTime class or to lie awake wondering about your code that uses it, here&#8217;s a good one. I&#8217;ve not looked into why this happens but 31st October minus one month gives 1st October. It should give 30th September. Zend_Date works in this respect: Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever wanted a reason not to use PHP&#8217;s built-in DateTime class or to lie awake wondering about your code that uses it, here&#8217;s a good one. I&#8217;ve not looked into why this happens but 31st October minus one month gives 1st October. It should give 30th September. Zend_Date works in this respect:</p>
<p>Here&#8217;s a session showing this in action:</p>
<p><tt>bob@desktop:~$ php -a<br />
Interactive shell</p>
<p>php &gt; $m = new DateTime();<br />
php &gt; echo $m-&gt;format( 'r' );<br />
<strong>Mon, 31 Oct 2011</strong> 09:39:12 +1300<br />
php &gt; echo $m-&gt;modify('-1 month')-&gt;format( 'r' );<br />
<strong>Sat, 01 Oct 2011</strong> 09:39:12 +1300</tt></p>
<p>*cries*</p>
<p><tt>bob@desktop:~$ php -a<br />
Interactive shell</p>
<p>php &gt; $m = new Zend_Date();<br />
php &gt; echo $m;<br />
<strong>Oct 31, 2011</strong> 9:47:50 AM<br />
php &gt; echo $m-&gt;sub( 1, Zend_Date::MONTH );<br />
<strong>Sep 30, 2011</strong> 9:48:25 AM</tt></p>
<p>*correct*</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2011/10/phps-datetime-built-in-class-vs-zend_date.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adjusting the screen DPI in Ubuntu</title>
		<link>http://www.guru.net.nz/blog/2011/08/adjusting-the-screen-dpi-in-ubuntu.html</link>
		<comments>http://www.guru.net.nz/blog/2011/08/adjusting-the-screen-dpi-in-ubuntu.html#comments</comments>
		<pubDate>Sun, 07 Aug 2011 10:04:50 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=418</guid>
		<description><![CDATA[My laptop has a screen resolution of 1280&#215;800 (it&#8217;s a 16:10 ratio widescreen). Sometimes it seems that the screen is a little crowded. Fortunately on most operating systems there&#8217;s a solution &#8211; adjust the screen DPI to get more pixels per inch. The simplest way to do this in Gnome (the default window manager for [...]]]></description>
			<content:encoded><![CDATA[<p>My laptop has a screen resolution of 1280&#215;800 (it&#8217;s a 16:10 ratio widescreen). Sometimes it seems that the screen is a little crowded. Fortunately on most operating systems there&#8217;s a solution &#8211; adjust the screen DPI to get more pixels per inch.</p>
<p>The simplest way to do this in Gnome (the default window manager for Ubuntu) is to go into the following:</p>
<ol>
<li>System, Preferences, Appearance</li>
<li>Click on the Fonts tab</li>
<li>Click on the Details button in the bottom right</li>
<li>Adjust the &#8220;Resolution&#8221; value.</li>
</ol>
<div>The default value is 96 &#8211; I find that 84 is a good number for me, but even down at 70 the text is still very readable.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2011/08/adjusting-the-screen-dpi-in-ubuntu.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmarking PHP &#8211; a hands on solution</title>
		<link>http://www.guru.net.nz/blog/2011/07/benchmarking-php-a-hands-on-solution.html</link>
		<comments>http://www.guru.net.nz/blog/2011/07/benchmarking-php-a-hands-on-solution.html#comments</comments>
		<pubDate>Tue, 05 Jul 2011 11:45:46 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=393</guid>
		<description><![CDATA[Sometime you will be in a situation where benchmarking is to solve a particular performance problem. You can imagine how it goes &#8211; the system performs well on an unloaded development server with a few hundred records, but once in the wild on a production server with tens of thousands of records all of a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.guru.net.nz/blog/images/Benchmarking-PHP.jpg" alt="Screenshot of some PHP code" title="Benchmarking PHP" width="324" height="321" style="margin: 10px;" class="alignright size-full wp-image-396" />Sometime you will be in a situation where benchmarking is to solve a particular performance problem. You can imagine how it goes &#8211; the system performs well on an unloaded development server with a few hundred records, but once in the wild on a production server with tens of thousands of records all of a sudden you&#8217;ve got an issue.</p>
<p>Finding bottlenecks in code isn&#8217;t always an easy task and it&#8217;s helpful to have some way of measuring the time it takes to run a process accurately. Sure, there&#8217;s the stopwatch method but this only scales so far. Accurately benchmarking is also great for measuring performance of code where the speed isn&#8217;t currently an issue. You can benchmark a known operation, then repeat this benchmark process in the future to ensure that no unintentional degradation of performance has occurred as a result of development.</p>
<p>Here&#8217;s an example piece of code to help you quickly benchmark code. It supports loading multiple tests into it and simply does a var_dump of the results. Using these results in creative ways is an exercise for the reader.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">class</span> Benchmark
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$results</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Our benchmarking may take some time - disable the time limit</span>
            <span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">0</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;">private</span> <span style="color: #000000; font-weight: bold;">function</span> benchmark<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> <span style="color: #000088;">$callback</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</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;">$callback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">results</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$test</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</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;">$start</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> runTests<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// -- Test #1 ---------------------------------------</span>
&nbsp;
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">benchmark</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Fetch all contacts'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                TwSCM<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'broadcast/contact'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// -- Test #2 ---------------------------------------</span>
&nbsp;
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">benchmark</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Fetch objects for tag 4'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                TwSCM<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'tag'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObjectsForTag</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// -- Test #3 ---------------------------------------</span>
&nbsp;
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">benchmark</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Count to one million'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">1000000</span><span style="color: #339933;">;</span> <span style="color: #000088;">$a</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">// Do nothing ...</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// -- Output the results ----------------------------</span>
&nbsp;
            <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">results</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$benchmark</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Benchmark<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$benchmark</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">runTests</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The above code requires at least PHP 5.3 (it uses closures to run the tests and time/store the results) and currently some tests that I&#8217;ve been running to profile <a href="http://www.turboweb.co.nz/pages/13-15/Simple-Web-Manager">Turboweb&#8217;s Simple Web Manager</a> application. The benchmark() method takes two parameters &#8211; the first is the name of the test (this is displayed when $this->results is var_dump()ed) and the second is an anonymous function containing the test to be run.</p>
<p>By modifying the contents of the anonymous function and running this script multiple times you will be able to test and tweak your functions to as quickly as they can.</p>
<p>Good hunting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2011/07/benchmarking-php-a-hands-on-solution.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redshift &#8211; visual help for night owl programmers</title>
		<link>http://www.guru.net.nz/blog/2011/05/redshift-visual-help-for-night-owl-programmers.html</link>
		<comments>http://www.guru.net.nz/blog/2011/05/redshift-visual-help-for-night-owl-programmers.html#comments</comments>
		<pubDate>Tue, 24 May 2011 12:27:36 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[gnome]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=377</guid>
		<description><![CDATA[If you&#8217;re a night owl like me the first thing you do when you crank up your laptop at night is to bust down the brightness down to minimum to save yourself some eyestrain. After coming across a page showing The Best Of Linux Software I saw mention of a program called redshift. Redshift makes [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a night owl like me the first thing you do when you crank up your laptop at night is to bust down the brightness down to minimum to save yourself some eyestrain.  After coming across a page showing <a href="www.makeuseof.com/pages/best-linux-software">The Best Of Linux Software</a> I saw mention of a program called redshift. Redshift makes your screen redder by adjusting the gamma curves, and thus making your screen easier to see.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bob<span style="color: #000000; font-weight: bold;">@</span>bob-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> redshift libnotify-bin</pre></div></div>

<p>(libnotify is not required to run redshift, but is used by the script below).</p>
<p>The ocular science behind this is straightforward &#8211; to quote <a href="http://en.wikipedia.org/wiki/Night_vision">Wikipedia</a>:</p>
<blockquote><p>In biological night vision, molecules of rhodopsin in the rods of the eye undergo a change in shape as they absorb light. Rhodopsin is the chemical that allows night-vision, and is extremely sensitive to light. Exposed to a spectrum of light, the pigment immediately bleaches, and it takes about 30 minutes to regenerate fully, but most of the adaptation occurs within the first five or ten minutes in the dark. Rhodopsin in the human rods is less sensitive to the longer red wavelengths of light, so many people use red light to help preserve night vision as it only slowly depletes the eye&#8217;s rhodopsin stores in the rods and instead is viewed by the cones.</p></blockquote>
<p>Anyway, the utility is simple enough to use, but requires that it be launched from the command line.  I don&#8217;t mind that at all, but I don&#8217;t want the hassle of having to do that.  Instead what I ended up doing was writing a wrapper script for redshift that I placed on my Gnome panel which would effectively toggle redshift on and off when I click the icon.  Here&#8217;s the script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Redshift toggle script</span>
<span style="color: #666666; font-style: italic;"># @author: Bob Brown, gurubob@gmail.com</span>
<span style="color: #666666; font-style: italic;"># @blog: http://www.guru.net.nz/</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;"># Required packages: redshift libnotify-bin</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Lat/Long for Dunedin, New Zealand</span>
<span style="color: #007800;">LAT</span>=-<span style="color: #000000;">45.8</span>
<span style="color: #007800;">LONG</span>=<span style="color: #000000;">170.5</span>
<span style="color: #007800;">NOTIFYIMAGE</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>icons<span style="color: #000000; font-weight: bold;">/</span>Humanity<span style="color: #000000; font-weight: bold;">/</span>actions<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">22</span><span style="color: #000000; font-weight: bold;">/</span>object-inverse.svg
&nbsp;
<span style="color: #007800;">RUNNING</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #c20cb9; font-weight: bold;">ps</span> aux<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> redshift<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">grep</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> redshift.sh<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RUNNING</span> <span style="color: #660033;">-gt</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>
	notify-send <span style="color: #660033;">-i</span> <span style="color: #007800;">$NOTIFYIMAGE</span> <span style="color: #ff0000;">&quot;Stopping Redshift&quot;</span> <span style="color: #ff0000;">&quot;Redshift is shutting down&quot;</span>
	<span style="color: #c20cb9; font-weight: bold;">killall</span> redshift
<span style="color: #000000; font-weight: bold;">else</span>
	notify-send <span style="color: #660033;">-i</span> <span style="color: #007800;">$NOTIFYIMAGE</span> <span style="color: #ff0000;">&quot;Starting Redshift&quot;</span> <span style="color: #ff0000;">&quot;Redshift has been started with your location as per $0&quot;</span>
	<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>redshift <span style="color: #660033;">-l</span> <span style="color: #007800;">$LAT</span>:<span style="color: #007800;">$LONG</span> <span style="color: #000000; font-weight: bold;">&amp;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>You can see the script is straightforward and requires a little configuration &#8211; redshift requires your latitude and longitude as it adjusts the redshift of your screen based on the time of day, swinging between maximum redness at midnight and no redness during daylight hours (the website claims this, but I have not yet seen it as I&#8217;ve been running redshift for about an hour so far and it&#8217;s 12:13am). You can use this <a href="http://itouchmap.com/latlong.html">interactive map</a> to find your latitude and longitude.</p>
<p>The shift to red is dramatic at first, especially going from the cool blue-white of maximum screen output but after a few minutes I find myself hardly noticing it at all.  It will be interesting to see whether redshift finds a permanent place on my laptop.</p>
<p>By the way, there is a GTK front-end for redshift too and it works just as well.  It allows you to toggle the application by right clicking the red lightbulb icon in the notification area of the gnome panel.  Simply install it like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bob<span style="color: #000000; font-weight: bold;">@</span>bob-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> gtk-redshift</pre></div></div>

<p>and then place it into your startup applications in Gnome:</p>
<ol>
<li>System, Preferences, Startup Applications</li>
<li>Click Add</li>
<li>Enter &#8220;Redshift&#8221; for the name</li>
<li>Enter <em>/usr/bin/gtk-redshift -l YOURLAT:YOURLONG</em> for the command (my command is <em>/usr/bin/gtk-redshift -l -45:170</em>, roughly)
<li>Click Add</li>
<ol>
<p>Presumably now redshift will start when you log in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2011/05/redshift-visual-help-for-night-owl-programmers.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wubi &#8211; the Windows Ubuntu Installer</title>
		<link>http://www.guru.net.nz/blog/2010/09/wubi-the-windows-ubuntu-installer.html</link>
		<comments>http://www.guru.net.nz/blog/2010/09/wubi-the-windows-ubuntu-installer.html#comments</comments>
		<pubDate>Fri, 03 Sep 2010 11:04:31 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=356</guid>
		<description><![CDATA[So you&#8217;ve heard about Ubuntu and you&#8217;ve been interested but when you found out that it (can) completely replace your current operating system you thought better of it.  After all, the last thing you want to happen when you try a piece of new software is for you to lose everything. Enter Wubi.  Wubi is [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve heard about Ubuntu and you&#8217;ve been interested but when you found out that it (can) completely replace your current operating system you thought better of it.  After all, the last thing you want to happen when you try a piece of new software is for you to lose everything.</p>
<p>Enter Wubi.  Wubi is a small installer program (about 1MB) that will install Ubuntu on your Windows computer (Mac and Linux versions are coming) that will install the whole operating system into a &#8220;container file&#8221; on your existing Windows hard drive. What this means for you is that there&#8217;s virtually no risk installing Ubuntu as if you don&#8217;t like it or if you want to go back to how things were you simply remove the Wubi application through the Windows control panel.</p>
<p>How it works:</p>
<ol>
<li>Wubi asks you where you want to install Ubuntu and how much disk space you want to give it</li>
<li>Wubi then downloads an Ubuntu 10.04 ISO file</li>
<li>The ISO file is unpacked into the container file along with grub (the boot loader that comes with Ubuntu)</li>
<li>The Windows startup options are modified to include booting into Ubuntu as an option.</li>
<li>Your PC restarts and the installation completes.</li>
</ol>
<p>The performance of Ubuntu running in a container file is good &#8211; there will be overheads far greater than running native file systems like ext4 directly on the disk but as a no-risk introduction to Ubuntu for the Windows user, this is a great start.</p>
<p>As far as I know, the only thing that DOESN&#8217;T work in Ubuntu installed using this method is the hibernate support.  Attempting to hibernating your Ubuntu desktop environment simply results in the screen being locked requiring your password to continue (presumably the hibernation failed).</p>
<p>Check out this YouTube video of Shawn Powers from Linux Journal installing Wubi (4:24s).<br />
<object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/n5x9iJWXbUY?fs=1&amp;hl=en_US&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/n5x9iJWXbUY?fs=1&amp;hl=en_US&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object><br />
Happy Ubuntuing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2010/09/wubi-the-windows-ubuntu-installer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Grid plugin in Compiz</title>
		<link>http://www.guru.net.nz/blog/2010/08/using-the-grid-plugin-in-compiz.html</link>
		<comments>http://www.guru.net.nz/blog/2010/08/using-the-grid-plugin-in-compiz.html#comments</comments>
		<pubDate>Tue, 31 Aug 2010 09:09:51 +0000</pubDate>
		<dc:creator>GuruBob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ubuntu compiz]]></category>

		<guid isPermaLink="false">http://www.guru.net.nz/blog/?p=345</guid>
		<description><![CDATA[Recently I&#8217;ve been introduced to the Grid plugin in Compiz &#8211; this is a fantastic little plugin that snaps your windows to predefined positions on the screen. After using it for the last couple of weeks I can&#8217;t imagine going back to not using it. To get access to it you will need to install [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been introduced to the Grid plugin in Compiz &#8211; this is a fantastic little plugin that snaps your windows to predefined positions on the screen.  After using it for the last couple of weeks I can&#8217;t imagine going back to not using it.</p>
<p>To get access to it you will need to install the compiz settings manager, and load Compiz&#8217;s &#8220;Fusion Plugins Extra&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> \
    compizconfig-settings-manager \
    compiz-fusion-plugins-extra</pre></div></div>

<p>Once you&#8217;ve done this simply enable it:</p>
<ol>
<li>System, Preferences, CompizConfig Settings Manager</li>
<li>In the Filter box in the top left, type in &#8220;grid&#8221;</li>
<li>Tick the box to enable it and click &#8220;Close&#8221; (bottom left)</li>
</ol>
<p>Now try using Ctrl-Alt and numbers on your keypad.  CA-9 will snap a window into the top right corner (press it a few more times to get different sizes) and CA-8 will make it snap to the top half of the screen (the number is the position on the screen, you&#8217;ll get the gist of it).</p>
<p>Check out this demo video:</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Z9hZb7blbVg?fs=1&amp;hl=en_US&amp;color1=0x2b405b&amp;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Z9hZb7blbVg?fs=1&amp;hl=en_US&amp;color1=0x2b405b&amp;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p>Happy Ubuntuing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guru.net.nz/blog/2010/08/using-the-grid-plugin-in-compiz.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

