Removing Ubuntu partitions and GRUB on Vista

In order to remove a Linux parition you need to remove the GRUB loader and fix the master boot record (MBR). The accepted way of doing this is from a Vista install CD but my Asus laptop doesn’t have an install CD.I found a utility you can download from:

http://www.sysint.no/nedlasting/mbrfix.htm

After downloading you’ll need to unzip the files and stick them in a folder somewhere. Next from the Accessories menu run the Command Prompt. You need to run this as administrator, which you do from the right click context menu. First it might be wise to look at your partitions. You do this with

C:\> MbrFix /drive 0 listpartitions

You can then back up your paritions

C:\> MbrFix /drive 0 savembr Backup_MBR_0.bin

And then fix you master boot record with this command

C:\> MbrFix /drive 0 fixmbr /vista /yes

Don’t forget the /vista switch. You can now reboot and you should boot straight into Vista with no Grub loader. Next job is to get rid of the Linux partitions. Got to Computer from the windows menu and right click on computer in the left hand tree view. Select manage  and in the snap in that load select disk management. You should be able to indentify the Linux main and swap partitions.

Select the larger non-swap partition. Right click and select delete volume from the menu. It should say something about it not being a windows partition. This is good as it shows you’ve got the right one. If you get an error you are probably trying to delete the swap partition and this doesn’t work. Close and restart the computer management snap in and you’ll see both the paritions now show as free space.

You can now either create a volume out of the free space (right-click and select New Simple Volume..) or expand one of your existing NTFS volumes into the free space.

Analyse this

In these unusual times there has been an unusual gap in my posts. I am still working from NW10 but instead of also working from EC1 I am working from W4. Economic circumstance demands it. I am now analysing work for others to code.

Like most analysts, I presume, I’m working on new features but not a new product. The first task is to understand how everything works now. The second is to work out what it is that the client is trying to achieve. This is usually the hardest part. Finding a common language to describe a complex business process in terms that the business owner, the business analyst, the systems analyst/architect (me) and the developer all understand is a challenge.

In previous incarnations I have worked with agile processes. These have worked well for internal customers but I haven’t yet been in the privileged position of working with an external customer who wants to work in an agile way. Most projects need a business case and part of that business case is an estimate of cost. In order to accurately estimate cost I need to be as explicit as possible in what it is we will be delivering to the customer. Lots of upfront analysis, very much a waterfall.

Having said that, these are small projects. A typical project might be less than two weeks for one developer. That is practically just one user story in an interation and so, in that sense, we are iterating, we are agile. However, I don’t know of many agile stories with 20 page analysis documents.

I can’t think of a better way at present. The business can’t sit with the developers, they are 300 miles apart, and that is only in the physical location. It is my job to elicit the requirements, to interpret those into a definable change to our software at minimal cost, and to write those requirements and changes down, as explicitly and clearly as possible, to keep everyone happy, to prevent both sides from blaming the other for a failed implementation.

VIEWSTATE over use

Whatever your opinion on the usefulness or otherwise of .NET VIEWSTATE method of storing web control data on the client, there are some pretty bad uses of it out there. For example, many of Microsoft’s own pages contain unnecessary VIEWSTATE. The Vista version comparison page, that contains no visible controls that would need to maintain state, is 166KB of HTML of which 84KB, half, is BASE64 encoded VIEWSTATE that is probably never used.

Creating a Downtime Page

To show everyone but those from your IP address a downtime HTML page you can use the following in a .htaccess file. Make sure AllowOverride is set on the directory and AccessFileName is set to .htaccess (or whatever you call the file) :


RewriteEngine on
# This prevents already redirected users from being redirected again
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
# A couple of directory exceptions
RewriteRule ^testcentre - [L]
RewriteRule ^student/ecommerce - [L]
# Rule to show everyone that is not (!) from the IP address down.html
RewriteCond %{REMOTE_ADDR} "!^87\.194\.4\.226"
RewriteRule .* /down.html [L]

Simple Joomla 1.5 Module

The following module imbeds Google Analytics code into your Joomla 1.5 web site. First we have the definition file

<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
	<name>Google Analytics Tracking Module</name>
	<author>Matt Lyons</author>
	<creationDate>October 2008</creationDate>
	<copyright>(c) Matt Lyons</copyright>
	<license>http://www.opensource.org/licenses/mit-license.html</license>
	<authorEmail>none</authorEmail>
	<authorUrl>nw10.wordpress.com</authorUrl>
	<version>1.0</version>
	<description>
	<![CDATA[Google Analytics Tracker (New Code)]]>
	</description>
	<files>
		<filename module="mod_gat">mod_gat.php</filename>
	</files>
	<params>
		<param name="ucode" type="text" default="" label="Web Property ID (UA-123456-1)" description="Check your code by looking for _gat._getTracker in the tracking code provided by Google. It should start UA-" />
	</params>
</install>

Then the PHP module

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

$ucode = $params->get( 'ucode', 0 );

if($ucode){

	$html = "<script type=\"text/javascript\">\n";
	$html .= "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n";
	$html .= "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n";
	$html .= "</script>\n";
	$html .= "<script type=\"text/javascript\">\n";
	$html .= "var pageTracker = _gat._getTracker(\"" . $ucode . "\");\n";
	$html .= "pageTracker._trackPageview();\n";
	$html .= "</script>\n";
	echo $html;

}
?>

Save them as mod_gat.xml and mod_gat.php and zip them up and you have a simple, but useful, Joomla module.

Installing Trac on Red Hat 5

The following concise instructions were taken from an install I did on a Red Hat 5 server. In my case the setup is strange because everything (for historical reasons) has been set up under /home .

The subversion repository I used was in /home/subversion/csdev and I wanted the URL to be /trac/cs . You will, of course, have to use your own values for these. I also assume that mod_python and SQLite are already installed as they were on the server I was working with.

Download ez_setup.py from

http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install

Then run

  sudo python ez_setup.py

SQLite is also a requirement but version 3.3.6 appeared to already be on Red Hat 5

  [12:36:42 ~] $ sqlite3
  SQLite version 3.3.6
  Enter ".help" for instructions

Then install Trac

  sudo easy_install Trac

Now you need to create the project directory

sudo mkdir -p /home/tracproj/cs

Then run trac-admin

sudo trac-admin /home/tracproj/cs initenv

Answer the questions (apart from the project name of course) with the defaults apart from the SVN repository question to which I answered

/home/subversion/csdev/

for this project.

This script will spend time indexing the repository, which takes a while…

Then we need to add a handler section to Apache and load mod_python

LoadModule python_module modules/mod_python.so

SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /home/tracproj/cs
PythonOption TracUriRoot /trac/cs

Also the project directory needs to be owned by the apache user

  sudo chown -R apache /home/tracproj

And restart Apache. Trac should now be available on the /trac/cs URL (or your URL) although the logo will still need configuring.

Fetching Classes in PDO

In bigger projects you’ll want to be using a Object-Relational mapping design pattern of some kind but sometimes you just want an object whose public member variables map to your database table.

PDO comes with a PDO::FETCH_CLASS fetch type that returns a collection of the class you specify from a database query with columns that match the member variables. This can also be used if you are using an object mapper type pattern and you aren’t too concerned that your domain object member variables are public. Here is some example code:


<?php

// DB connection
$db = new PDO('mysql:host=10.0.0.4;dbname=wordpress',
            'wpuser',
            'pasco3');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Create the Table
$sql = "CREATE TABLE `fruit` (
         `id` int(11) NOT NULL default '0',
         `name` varchar(128) default NULL,
         `colour` varchar(20) default NULL,
         `size` varchar(20) default NULL,
          PRIMARY KEY  (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ";

$db->exec($sql);

// Insert some stuff
$data = array(
            array(1,'Banana','Yellow','Medium'),
            array(2,'Raspberry','Pink','Small'),
            array(3,'Melon','Green','Large')
        );

$stmt = $db->prepare('INSERT INTO `fruit` VALUES(?,?,?,?)');

foreach ($data as $row) {
 $stmt->execute($row);
}

unset($stmt);

// Set up our class
class fruit {
 public $id;
 public $name;
 public $size;

 function __toString() {
  return "A $name is $this->size and $this->colour
";
 }
}

// Get our data back
$stmt = $db->query('SELECT * FROM `fruit`');

$collection  = $stmt->fetchALL(PDO::FETCH_CLASS, 'fruit');

foreach ($collection as $fruit) {
 print $fruit->__toString();
}

?>

PHP and UNICODE

Having worked in other languages that have had Unicode support since inception, or at least for many years, the lack of it in PHP did come as a bit of a surprise. It seems at the time of writing we are still a long way away from Zend completing the completion of Unicode for PHP6.

I’m currently working on a new database for a PHP system and want to make sure we don’t have the immense pain that is involved in a conversion to Unicode for a Latin 1 database. Thankfully, the initial system is only likely to be used in the UK and so I hope that by sticking with UTF-8 as described here I can get away with not having to compile and use multi-byte string functions everywhere. Then when we get PHP 6 we’ll be OK.

HTML vs XHTML or browsers vs standards

As web developers we really just want standards that are going to make our life easier by not forcing us to duplicate effort for different browsers but we also want clean semantically clear code. The debate rages on between X/HTML 5 and XHTML 2 in the W3C. I think the fact that the browsers are mainly behind X/HTML 5 means it is going to win this battle and function will win over form.  This article gives a good account of the pros and cons.

Updating PHP on Red Hat 5

Red Hat 5 has a very out of date version of PHP. Thankfully someone is providing new YUM RPMs so you don’t have to build new versions from scratch. Here is how I updated our RHEL5 version of PHP.

Our PHP was updated using YUM via utterramblings http://www.jasonlitka.com/yum-repository

This required adding the GPG key

sudo rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

Then adding the repository definition to /etc/yum.repos.d/utterramblings.repo

[utterramblings]
name=Jason's Utter Ramblings Repo baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

Then running
yum update php

It’s also worth installing the devel package if you are going to want to compile modules later
sudo yum install php-devel