Enforce Coding Standards with PHP_CodeSniffer and Eclipse IDE on Ubuntu Linux
ENUMs, User Preferences, and the MySQL SET Datatype
G3D on Ubuntu Linux
Changing Mailman Python Scripts for Virtual Host Support
Using PHP pspell Spell Check Functions with a Custom Dictionary
Using Multi-Byte Character Sets in PHP (Unicode, UTF-8, etc)
Microsoft Office Open XML
PHP Snippets Saturday, 2nd August 08
compton

Closing HTML Tags for a snippet

The XML DOM class which comes built-in to PHP as standard offers the ability to fix the markup in an HTML snippet. Say for instance you have a string of HTML code $htmlCode and wish to show a preview on a webpage, you could do the following:

$htmlSnippet = substr($htmlCode, 0, 500);
$snippetMaker = new DOMDocument();
@$snippetMaker->loadHTML($htmlSnippet);
echo $snippetMaker->saveHTML();

Note that we suppress warnings generated by the loadHTML() function by prefixing it with an at symbol @.

Random Password Generator

Several times I've come across some rather long-winded solutions to the problem of generating a random string of characters, e.g. for a random password or capcha text for instance.

It's easy to do this using just two lines of PHP, no need for anything complicated:

   for ($count = 0; $count       $pword .= chr(rand(65, 90));

The PHP chr() ... ...
Eclipse and PHP: Which is the Best Plug-in, phpEclipse or PDT? Monday, 19th April 10
compton

The differences between these two plugins are varied but subtle. After having used phpEclipse for the last couple of years, I decided to give PDT a proper try as I needed to do a fresh install in order to get the PHP CodeSniffer Plugin working fully.

PDT

  • Excellent HTML validation, and built-in CSS support (code highlighting, intellisense and autocompletion for both)
  • Good JavaScript support (code highlighting and syntax checking. However it often reports bogus errors when JS is embedded in HTML)
  • Jump to file by right-clicking and choosing 'Open Selection' e.g. to open a HTML page referenced by a form action attribute
  • More informational 'Mark Occurences' feature. The Mark Occurences is feature is one of my most used Eclipse features. It highlights all other occurences of the variable or function at the current cursor location. Usually ... ...
Using the JavaHL Native SVN Library in Eclipse Wednesday, 28th April 10
compton

With later versions of Eclipse and/or the SVN plugin, you have the option of using the Java native interface (JNI) library for Subversion support. For performance and platform independence, Subversion is written in C. The JavaHL library is written by the Subversion team, and basically provides Java wrappers for Subversion's C API. You can use SVNkit, which is a pure Java Subversion library, but until you've sorted it out one way or the other, you're likely to see lots of error messages reading "Failed to load JavaHL Library".

In Eclipse, go to Window > Preferences, and expand Team in the left-hand pane and click on SVN. Towards the bottom of the options on the right-hand side, you'll see a drop-down labelled SVN Interface. By default this is set to JavaHL but this option requires the JavaHL SVN libraries to be installed by following the steps below. If you can't be bothered installing the extra stuff, you can simply set this dropdown to SVNkit (Pure Java).

However, if you wish ... ...

Enforce Coding Standards with PHP_CodeSniffer and Eclipse IDE on Ubuntu Linux Friday, 9th April 10
compton

The PEAR PHP_CodeSniffer project provides an invaluable tool for enforcing a consistent set of coding standards across a whole PHP project. Thanks to the guys at PHPsrc, it can now be installed as an Eclipse plug-in, to provide annotations about code standard violations right in your editor:



In order to get this set up and running, you first need Eclipse 3.3 or greater. You can download the package with PDT incorporated from the eclipse site. Get any other tools you need, such as subclipse for SVN.

Now you're ready to install the PHP tools from PHPsrc, which is accomplished by adding http://www.phpsrc.org/eclipse/pti/ as a new update site to the Eclipse plug-in finder found at Help > Install New Software...

Once that's complete and you've restarted Eclipse to ensure all the changes are applied, you need to ... ...

ENUMs, User Preferences, and the MySQL SET Datatype Saturday, 6th March 10
compton

The MySQL SET datatype is a very space-efficient way to store sets of binary flags. It's a little like the ENUM type, in that you define a range of possible string values, but unlike the ENUM, a column that holds a SET can have any number of the string values at one time.

It's useful to consider how MySQL stores SETs and ENUMs in order to appreciate what benefits they can bring.

Here's a simple table with an ENUM column and a SET column:

CREATE TEMPORARY TABLE critters (
   species ENUM ('cat', 'dog', 'mouse', 'bear', 'elephant') NOT NULL DEFAULT 'cat',
   eats SET ('cat', 'dog', 'mouse', 'ant', 'bear') NOT NULL DEFAULT 'mouse'
);


Any ENUM column always occupies a single byte in a table, and each string defined for the ENUM is mapped to one of the possible values that an 8-bit byte may hold. The string values can be arbitrarily long, and may even contain spaces if desired. Because the ENUM must fit in a single byte, you can only have as many string values as ... ...

Turn Eclipse into a full-featured Perl IDE on Ubuntu Wednesday, 28th April 10
compton

With all the plug-ins freely available for it, Eclipse is rapidly becoming the one-stop IDE of choice for all your programming needs. The Perl plug-in from EPIC (Eclipse Perl Integration) is compatible with Eclipse v3.1 and higher.

You need Perl installed on your system in order to make use of all the plug-ins features, such as syntax highlighting and source code formatting. If you're running Linux (why wouldn't you be??), you'll most likely already have an up-to-date Perl. Check by issuing the command perl --version at the command line.

To install the plug-in, you can use the Eclipse Update Manager. Open it by selecting Help > Install New Software from the Eclipse menu. Click the Add button and enter http://e-p-i-c.sf.net/updates/testing as the update site.

Proceed through the installation process, and you should be good to go. OK any of the usual 'unsigned content' warnings, and ... ...

How To Make a Firefox Plug-in (or Extension) 23 Jan 10
compton
Firefox's so-called browser chrome is written using JavaScript and XUL; XUL being an XML dialect that defines UI components, aka widgets. So it's logical that the functionality of Firefox extensions should itself be coded using a combination of JS and XUL. In addition, you need an RDF file, another XML dialect, to describe the extension so that it can be correctly installed. Your XUL files will define a XUL Overlay, which is merged with Firefox's built-in 'master' XUL.
Restore GRUB After Installing Windows XP 3 Jan 10
compton

Note that when using grub commands, spaces are important. In particular, a space is required after the commands root and setup (but before the first bracket) and no spaces should be used inside the brackets.

1) Boot from a Live CD
2) Open a terminal window or switch to a TTY and enter:
sudo grub
3) At the grub prompt, use the following command to determine where grub is installed:
find /boot/grub/stage1
4) Using the hard disk and partition given by ... ...

G3D on Ubuntu Linux 19 Dec 09
compton

G3D is a cross-platform OpenGL library in C++. I haven't used it in a couple of years, when I first experimented with 3D C++ programming. The current version is 8 beta 2.

To install on Linux, you'll need to compile the G3D code from source. In my case, on Ubuntu 9.10, I had to install the following dependencies first:

sudo apt-get install libsdl1.2-dev xorg-dev libglu1-mesa-dev libzip-dev libavutil-dev

Then compilation is a question of running the following command from ... ...

Changing Mailman Python Scripts for Virtual Host Support 22 Sep 09
compton

Mailman is a tried-and-tested Open Source mailing list manager. It's robust and reasonably efficient when running, however it organises lists internally by their local name only. In other words, you can't have one list called maillist@domain.org on the same server as another list called maillist@somewhereelse.com on the same machine, unless you have a separate mailman installation for each domain.

Many production environments do appear to use the separate installation per domain approach, ... ...

File Structure of ezmlm Mailing Lists 25 Nov 09
compton
The ezmlm mailing list stores configuration options for a list as files on the file system (rather than using a config table in a database, or even a single config file). In order to migrate a list from ezmlm to another list manager, such as mailman, it's necessary to understand the file structure in order to work out how the list is configured.
Mailman Virtual Hosts Info Collected from the Web 17 Sep 09
compton

From http://www.webmasterworld.com/forum92/3366.htm:

The situation is this: A single server with multiple IP addresses and related hostnames acts as a mailman server. Mailman is a mailing list manager with a builtin web archive and subscription management system written in php. As shipped it injects a file called mailman.conf into /etc/httpd/conf.d that uses mod_alias to redirect traffic of the form ... ...

IPsec and other jargon 13 Nov 05
compton
Editing a book about creating VPNs on Linux with IPsec. 200-300 pages long, which works out at about £450.
Using PHP pspell Spell Check Functions with a Custom Dictionary 2 Jan 08
compton

The pspell_* functions are a very useful feature of PHP, allowing you to scan text and highlight words which are potentially misspelt. Pspell implements the open source aspell spell-checking routines in PHP.

Basic Usage

Before using the functions, you need to open up the dictionary you're going to use by calling the pspell_new() function, specifying at least the language to use. You can also specify a second argument, if the language you plan to use has multiple ... ...
BT Wholesale systems & process interface workshop 19 Jul 09
compton

Invitation to:


BT Wholesale systems & process interface workshop


Date: 20thJuly 2009


Venue:   etc Venues, Dexter House, No.2 Royal Mint Court, Tower Hill, London,  EC3N 4QN               http://www.etcvenues.co.uk/venues/dexter%5Fhouse/ 


Times: 09:30am registration, 10.00am workshop start, 13.00pm workshop close & lunch






How can we collaborate to produce world class systems and process interfaces to ... ...

Compiling and Installing on Ubuntu Linux 17 Oct 08
compton

Compiling from .tar.gz

The archive contains the source code files and supporting resources (bitmaps etc). So we'll need to compile this to make our executable program.

First extract the archive somewhere. I use a subdirectory off my home called src:

cd ~/src
tar -zxvf ~/download/newapp.tar.gz

If the archive is compressed with bzip (extension is .bz2), use option j instead of z:

cd ~/src
tar -jxvf ... ...
Using Multi-Byte Character Sets in PHP (Unicode, UTF-8, etc) 15 Oct 08
compton

The following list details the PHP string functions which could cause problems when handling multi-byte strings. The multi-byte safe alternative is given when available:

Try mb_send_mail() instead.


Customising Joomla 20 Nov 06
compton

My first task is to investigate how we can create a single consistent look & feel for the admin GUI. I'll need to get a good understanding of how the admin GUI works and is organised.

When the admin first logs in, you have a grid of square buttons on the left, and some stats on the right. The page shows as index2.php in the address bar.

index2.php has the following structure:

  • includes
  • start session
  • get option and task request ... ...
Development Resource Project 22 Feb 07
compton

The aim is to provide a resource where developers can go in order to get code for a specific task.

Objectives

  1. To reduce time from design to deployment
  2. to help maintain code quality
  3. to reduce need for maintanence and support
  4. to help ensure code meets specific requirements (including FF support, security, performance)
  5. to facilitate group work through standardization
  6. to grant designers the ability to easily understand the ... ...
A Simple ISAPI Filter for Authentication on IIS 12 Dec 07
compton

The MDSN samples include a C++ project for building a ISAPI DLL which performs authentication for web resources against a text file. This project, AuthFilt, is one of the samples supplied with the .NET Platform SDK, available from here. Once you've installed the SDK, the sample code is located in the AuthFilt folder at Program Files\Microsoft Platform ... ...

Carisma Running Problems 22 May 06
compton

The main problem this car has suffered since I bought it has been its poor idle. For the first six or so months, it ran absolutely fine, but then it began to stall regularly when idling, and it's steadily got worse. Even now it's got warmer has not improved, and happens equally whether the engine is warm or cold.

The stalling problem did not appear to be a physical issue with the overall running of the engine which remained smooth and even when under power. It appeared to be more to ... ...

AMD 64 Build 24 Sep 06
compton

The AMD 64 comes in two primary types, the standard AMD 64, and the AMD 64 FX. The former uses a socket 754 connection, while the latter uses 940 (which is the same as the Opteron, AMD's 64-bit server CPU). The 64 FX is designed with high-end 3D games in mind. Early nForce3 boards had issues, which may or may not be resolved now. VIA also made an early AMD 64 chipset, the K8T800, which did not suffer from such drawbacks.

The different pin count of the two Hammer CPUs is due to the ... ...

The First G3D Example 22 Dec 05
compton

Right, so now I've checked everything is set up correctly, I've decided to take a look at the examples that come with the G3D library.

There are seemingly eight, described on the G3D web site; it's not clear if there's any natural progression through them.

  • ArticulatedModel
  • loads models from files in 3DS, IFS, and PLY2 formats. Creates a scene graph, uses 'Pixel Shader 2.0' and 'fixed function' pipelines, ... ...
The Other G3D Examples 28 Dec 05
compton
The example I'd like to look at next is the ArticulatedDemo. It does a whole load of things, like loading a variety of models and placing them in a scene graph. It's this scene graph thing that I think I need to understand properly.

Unfortunately, I can't get ArticulatedDemo to run - it compiles and links ok, but fails an assertion, then crashes.

The next most interesting demo is Collision_Demo, which has a set of static objects in a box, then drops a load of different sized balls in, which bounce around the place.

It compiles and runs fine.
The IFS Modeller 22 Jan 06
compton

This little program allows you to create IFS models suitable for use in G3D programs. An IFS model can be built from an array of vertices with an associated array of indicies. The indices refer to offsets in the vertex array, and are grouped in sets of three - representing the triangular faces of the model.

So far, my program allows you to:

  • Add a new vertex at the origin
  • Select a vertex with the TAB key
  • Move the selected vertex with the numpad ... ...
CD or not CD 21 Nov 05
compton
So my new DVD burner should arrive today. I hope I'll finally be able to just put a DVD in and play the damn thing. I have always had problems with CD and DVD drives. They seem to be much more sensitive on my computer than anyone else's! The slightest dirt or tiniest scratch renders disks useless.

The drive coming today is an LG - the reviews I've read of it seem to suggest it'll pretty much play (and burn) most disks. A Microsoft mouse arrives as well - allegedly. I'm looking forward to trying it out anyway. The other thing is a SIM card for Sheryl's phone, very cheap at £3.50.
First 3D Game 31 Dec 05
compton

I now feel I'm ready to have a go at creating my first simple OpenGL game. It's going to be pretty simple - there'll be no scene graph, just a simple array for storing objects in the world. I won't implement frustum culling either, at least not in the first instance.

My game will be based on space flight, so I will start with the player's ship. It should appear just in front and below of the camera, i.e. third person. It should turn and dive/climb in response to keyboard input, and ... ...

The G3D Library 18 Dec 05
compton
G3D is an open source graphics engine that can be used from VC++ 7. This means G3D projects can be developed in VS.NET, and make use of Intellisense and its debugger.

It requires the SDL library, which I've installed OK. G3D is also installed, but the test program isn't as simple as the SDL one, so I have not yet confirmed it is installed and available to VS.NET.
About This Page