Bash is Back!

The renowned quote database Bash.org, is back up and running. It is a favourite of mine to while away the hours.

Documenting your code in PHP

Whilst working on this model, I found myself forgetting various parameters or names of methods I had created. I can’t believe how much I rely on an IDE to provide me with all my prompts.

I did try setting up Eclipse again with PDT (had tried to use phpEclipse in the past with dissapointing results) yet I was getting UI errors all over, no matter what I tried (updating the JRE, grabbing various packages) I could not get the thing to work.

So I resorted to the next best thing, I went and found something called phpDoc. It reads DocBlocks from your code and creates a set of html pages containing all the information about your code.

Again, I installed it from pear on the command line, there are lots of site out there to help with installing it on Windows. Once installed, you can use the phpdoc -h to get all the command line parameters.

Similar to my last post, I use an msbuild script to run the documentation tasks


<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

    <PropertyGroup>
        <BuildDir>$(MSBuildProjectDirectory)</BuildDir>
        <DocumentationTitle>Dynamic Data Model</DocumentationTitle>
        <HelpOutput>HTML:Smarty:HandS</HelpOutput>
        <DocumentationFolder>$(BuildDir)Documentation</DocumentationFolder>
    </PropertyGroup>

    <ItemGroup>
        <CodeFiles Include="$(BuildDir)***.php" Exclude="$(BuildDir)**.svn***.*;
                                 $(BuildDir)**tests***.*" />
    </ItemGroup>

    <Target Name="Clean">
        <RemoveDir Directories="$(DocumentationFolder)" Condition="Exists('$(DocumentationFolder)')" />
    </Target>

    <Target Name="Setup" DependsOnTargets="Clean">
        <MakeDir Directories="$(DocumentationFolder)" Condition="!Exists('$(DocumentationFolder)')" />
    </Target>

    <Target Name="Build" DependsOnTargets="Setup">
        <CallTarget Targets="BuildDocumentation" />
    </Target>

    <Target Name="BuildDocumentation" DependsOnTargets="Setup">
        <CreateProperty Value="@(CodeFiles, ',')">
            <Output TaskParameter="Value" PropertyName="FilesToDocument" />
        </CreateProperty>

        <Exec Command='phpdoc --sourcecode --target "$(DocumentationFolder)" --output $(HelpOutput) --title "$(DocumentationTitle)" --filename $(FilesToDocument)' />
    </Target>
</Project>

Unit testing in PHP with PHPUnit

With this dynamic data model that I am currently building in PHP, I found that for quite a complicated solution I had no unit testing at all.

After searching around I found PHPUnit, however, it all hinted at a Linux only environment. A short while later I found a blog that described how to set it up for Windows: http://usingzendframework.blogspot.com/2007/12/setting-up-phpunit.html. I use Xampp, so I did not have to change the memory limit.

Once installed I used the online pocket guide to start me off: http://www.phpunit.de/pocket_guide/index.en.php

Inside my code folder I created a tests folder where I placed all my php tests, inside that I created an includes folder for all the test related code.

folders.jpg

The first thing that the common include does is turn on all the error reporting an strict reporting. This should ensure the most quality coding.

<?php
error_reporting(E_ALL | E_STRICT);
require_once('PHPUnit/Framework.php');
?>

Once that is done, I could start with writing all the tests.

<?php
include('includes/common.php');
class ExampleTests extends PHPUnit_Framework_TestCase
{
 public function testSomeObjectTest()
 {
  /* Test code here */
 }
}
?>

Once that was done, I created a msbuild script to test them all using the TestSuite class

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
    <PropertyGroup>
        <BuildDir>$(MSBuildProjectDirectory)</BuildDir>
    </PropertyGroup>

    <ItemGroup>
        <CodeFiles Include="$(BuildDir)***.php" Exclude="$(BuildDir)**.svn***.*;
                                                           $(BuildDir)**tests***.*" />
    </ItemGroup>

    <Target Name="Build">
        <CallTarget Targets="RunTests" />
    </Target>

    <Target Name="RunTests">
        <Exec Command='phpunit --verbose "$(BuildDir)testsTestSuite.php"' WorkingDirectory="$(BuildDir)tests" />
    </Target>

</Project>

I had to add the framework folder and the php folder onto the PATH environment variable so that I could just call msbuild from the commandline

RGB to Hex Converter

I have been working on my dads website, using a wordpress theme generator and this handy colour scheme book that I bought a couple of years back. (Yeah! I have a book with lots of colour swatches in it. I’m borderline dyslexic and don’t have any colour co-ordination.)

This book, has a small section in the back for web safe colours with hex values, the rest is all RGB and CMYK values for the printed page. Because there is a greater range of swatches in the first half, I created this small app to quickly turn an RGB value into Hex:

RGB Converter Image

Features: 

  • Automatically copies the hex value to the clipboard
  • Automatically skips to the next RGB colour value after a valid 3 character colour has been entered (enter 0′s for padding)
  • Ocassionally will skip over an RGB colour field
  • Pressing any other key when an RGB colour field has focus will automatically validate that field

Grab the source code here

It is not a perfect solution but it allowed me to quickly key in an RGB value and get the hex code. The result was quite good actually, quite a few of the RGB/CYMK printed colour schemes worked well in a web browser.

HWMonitor, temperature monitor alternative

With the install of Vista, I have had some issues with my system monitoring software. The new ASUS PC Probe II leaves windows all over the place and is difficult to read and quickly check the temps.

 The nVidia hardware monitor worked for a short time up until I installed some other nVidia drivers which broke it. I shortly also learned that it wasn’t supposed to work in Vista either =/

 So I was out of options, I had nothing to monitor my system with. I am a little nuerotic about it, I am constantly worried that my old hardware will melt the next time I play a game or a fan will fail and the computer won’t tell me in time. I have been nursing my computer for the past year, to keep it ticking over until I get a new machine.

CPUID’s Hardware Monitor – http://www.cpuid.com/hwmonitor.php solved all these issues. It hooks into all the sensors on your machine and reports thier values. I now have a one application that soaks up very little CPU time to monitor everything on my system. Even some sensors that I didn’t know I had!

It can get a few things wrong, there are a couple of my sensors that don’t move or report wrong values. They have a pro version for 20 euros and even a development SDK for 999 euros… SDK is a bit much for just me, might get pro after a while.

WordPress Theme Generator

I am currently creating a website for my father. I chose WordPress as a base, its nice simple UI will be adequate for what he needs to do, it has a simple plugin system and I should be able to rapdily design a website for him.

Well its been 4 weeks and I am still stuck trying to design a template. The saviour of the day however is A WordPress Theme Generator by Yvo Schaap - http://www.yvoschaap.com/wpthemegen. Using this really simple generator, I have been plugging in various colours before I get something that looks right. I will now go off, modify the template myself and provide some drops for dad to look at :)

FileZilla, the SmartFTP alternative

With SmartFTP not offering a free license anymore there is now a space for another robust FTP client. I don’t blame them, they offered such a high quality product for free for such a long time I could see that they would do this at some point. However I feel that they could have offered a really simple cut down FTP client for the simple joe, I only need to download or upload the odd file. Maybe change a few permissions, I don’t use all the features that SmartFTP offered.

As a result, I went hunting for an alternative FTP client and FileZilla ranked highly: http://filezilla-project.org/ Its an open source client and server (separate installs) and does the job nicely.

Adventures with Vista…

This weekend just gone, I reinstalled my machine from XP to Vista (Ultimate).
Now, having used Vista at work for quite a while I have come to accept it. I can understand and use UAC correctly.

In fact, not long after installing Vista did it impress me with its ability to recognise my hardware and also find the latest drivers for me, and failing that, even point me to the correct vendor pages where I could find the right driver.

Brilliant. So far so good. Even after wrestling with Vista for control of my sound panel, where it wanted to put most of my sounds on loud as it could since it thought I was deaf, then put my microphone as low as possible with no boost since it thought no one wanted to hear me complain moan what I had to say. I was prepared to let that one go. (I still won)

But the war continues, I am very good when it comes to the organisation of my files. My documents and files go onto another drive, thats what I want to backup. But no, Vista (and OneCare which just started trying) wants to backup parts of my C: (WHY!? I mean, thats where my programs are kept) then wants to grab everything off my E: (servers and junk… ) then all of my music from my F: that I backup separately…. Wait.. I can exclude folders from backup… nice, so whenever I create a new folder on E: I have to exclude it from my backup.

Thats why I loved NT Backup so much, I could include everything I wanted, even down to the AppData/LocalSettings folders where some games kept thier saves and not include the folders where various programs keep a copy of thier installs etc.

Ah well… more open source or script majik to ensue…

 Then, only a minor annoyance. I have two different monitors, 19″ at 1280×1024 which is the primary monitor and a 21″ at 1600×1050 and Vista just cannot get the wallpaper right. In XP its was fine, I would pick a 1600×1050 wallpaper, ask it to center it and in the smaller monitor it would just cut off the edges.. fine, nice.
In Vista however, doesn’t matter whatever setting I use, it tries to fit it in the primary smaller monitor and never fits into the secondary, then always looks odd. Looks like I have either got to resort to a proper dual monitor background or stick two wallpapers into one large one just so that it looks ok in vista. I could using something like NView, but its been bloated with features that I do not care for (IE Popup Blocker… don’t need another, I already have 100s from other programs trying it on)

Apart from that its been behaving itself… I cannot deny it is a nice OS for the standard user. My father has managed to get on much better with Vista than XP. I just can’t help but feel that Vista treats me like a deaf dumb user who doesn’t know what hes doing…

 EDIT

After having stuck two wallpapers together to try and make one… the center behaviour from XP seems to occur in Vista as well. What I don’t understand is why right clicking on an image and setting it as the desktop background is different from selecting the image from the browse menu.

I also found this article: http://www.petri.co.il/installing_windows_xp_ntbackup_on_windows_vista.htm which should solve my backup problems. Bacula seems to be too advanced for my needs.

I am a state machine!

“I am a state machine!”

WPF Wiki

At work I have had the chance to get into Microsofts latest version of the .NET framework. This includes a load of really nice technologies like Xaml and LINQ. (Ok im a little late on the scene…)

Whilst trying to leverage some of our UI into doing something, I stumbled upon this site: http://www.wpfwiki.com

 The FAQ was particularly helpful.