« August 2005 | Main | October 2005 »

September 30, 2005

Commenting Perl regular expressions

Do you sometimes find Perl regular expressions hard to follow? If you do, remember that you can use the "x" modifier which allows you to space them out; with the "x" modifier, white spaces in the regular expression are ignored.

You can go further; once you've specified the "x" modifier, you can embed comments in your regular expression - for example:

@cliad = ($log =~ /^    # line starts with
        .*              # any characters
        cliad           # then literally look for "cliad"
        .*              # then look for any characters
        $               # up to a line end
        /xmg);

See our regular expression course and resources to learn more about regular expressions.

Posted by gje at 08:49 AM

More about Graham Ellis of Well House Consultants
Useful link: Perl training

September 27, 2005

Is enough enough?

At what point does bandwidth cease to become an issue? Our training centre currently has a 4 Mbit connection ... and our service provider is upping that to a 10 Mbit connection in the near future. Fabulous - thank you - especially as the price actually drops. And on past form, we'll truly get this connectivity / most of our uses will be constrained at the far end not near.

5 p.m. yesterday, course of 4 trainees plus two staff working. Everyone checks email / catches up with work as the Perl training finishes for the day. Near Instant reaction on all the machines - displays coming up faster than they can be read; perhaps this is the turning point at which bandwidth is ceasing to be an issue. Or perhaps we'll start video streaming now ;-)

Posted by gje at 08:27 AM

September 26, 2005

Accessing a page via POST from within a PHP script

In PHP, you can use a file function to read the whole contents of a file into an array, and you've got a whole variety of other functions to open and read files in other ways too. If you want to read from a web page (a URL) via the GET method, that's easy too - simply put the URL in instead of the file name and PHP will work it out for you.

But what if you want to access a page from your server via the POST method? That's a little more complex, but it can be done; I had cause yesterday, and I wrote a sample posting script ... see full source code.

If you're into this sort of thing, you'll notice I've used the more complex HTTP 1.1 protocol to ensure that my script will work even on virtual hosts sharing a single IP address, and that I've checked for the existance of a robots.txt file. To some extent, the script I've written is an automaton or robot, and so this chsck should be made. It runs very nicely and it's quite a useful tool for learning how HTTP 1.1 and POST protocols work.

Posted by gje at 12:03 AM


Useful link: PHP training

September 25, 2005

Wheelchair access - can do!

I'm pleased to announce that we now have access to additional facilities in Melksham, within a mile of our current training centre. These facilities offer us a choice of two training rooms on the level with wide door access, toilet, tea, coffee and lunch facilities too. There are numerous parking spaces reserved for wheelchair users right by the access door.

If you're interested in attending a public Perl, PHP, Python, MySQL, Linux, Tcl/Tk or Tomcat course and you require flat access (e.g. if you describe yourself as disabled or if you're in a wheelchair), please let us know of your requirements as early as you can; we share the level access rooms and need to book them in good time.

Our regular training centre is in a listed building ... and informal discussions with local planners concerning access ramps, lifts, and widened doors lead us to understand that any planning application to enable wheel chair access to our regular training facilities would be met with not only a firm "no", but more of a "hell, no!". I can understand this view; really, we wouldn't WANT to alter a building of great historic significance and yet we do wish to provide training for all comers. Thus the solution outlined above.

Posted by gje at 10:33 AM

September 24, 2005

Matching in MySQL

"I want to find all records that look like ...". Such is a common sayingwhen searching a database table (or a text file or other data source come to that), but the words "look like" are very woolly and can mean different things to different people. So when you're writing code to find matching records, you've got a choice of techniques available to you.

Let's say, for example, that you want to match a British postcode that's contained in a field called postcode in a table. Here are three options.

First, an exact match:
SELECT * FROM contacts WHERE postcode = "SN12 6QL"
will match just the one postcode.

Second, using the LIKE operator will let you specify a simple pattern to match using _ to represent any one character and % to represent any string. So:
SELECT * FROM contacts WHERE postcode LIKE "SN12 %"
will match any postcode that starts with SN12

Finally, if you use the RLIKE or REGEXP operator you can specify a regular expression that you want to match. For example:
SELECT * FROM contacts WHERE postcode REGEXP "^[A-Z][A-Z]?[1-9][0-9]? "
will match any row with a postcode field staring with one or two letters, followed by one or two digits, followed by a space. In other words, this example is looking for the valid format for a postcode, even though we can't be sure exactly what any of the letters or digits involved will be!

Posted by gje at 09:54 AM

September 23, 2005

Out of the norm.

It's been a mad week ... I know I'm usually busy, but this has been "beyond". . I had expected that Tuesday evening - when we hosted a meeting to discuss cuts in rail services to / through / from Melksham - would attract a handful of people. I had never done anything like that before, started from nothing, and likely to be treading on other's toes anyway. Cutting a long story short, we ended up clearing the conference room and filling it with borrowed collapsible chairs. Well House Consultants as you've never seen us before - the picture will look a little different to "the norm" to those who've been to us before.

Successful meeting but something to build on rather than an end in its own right, but I need to turn my hand to MySQL today!

Posted by gje at 06:32 AM

September 19, 2005

Tomorrow's meeting.

"Graham - this is Melksham - it would be a miracle to get 20 people to a meeting". So say the doubters, but we'll see! This weekend gone and all non-work hours around, I'm preparing for tomorrow's "Save the train" meeting that we're hosting.

It looks like we are headed for a miracle - I have over the 20 acceptances, and in addition there's a number of probables, possibles .... and it's an open meeting so Joe Public's invited and, if he's a train user, may very well put in an appearance. Then all we need is another miracle ... to be able to decide what we feel the future should be for Melksham's rail service, and work with a united resolve to achieve it.

Posted by gje at 06:46 PM

September 16, 2005

Up early

Posting at 06:30 or so ... but I've already been up for an hour, and down to the station. Today is the day that I'm doing a survey of train usage through Melksham and I'm going to meet and greet every one of the 10 trains that call here and the first was at 05:53

"It's just an empty stock working really - don't bother" I had been told. Wrong. Three through passengers. Another joined. So that's four more than I expected, and four people for whom there is no alternative public transport at this time of day.

Link All about the train service to Melksham station

Posted by gje at 06:20 AM

September 15, 2005

Sticky news

In a Tk appllication, you'll define a number of widgets (components) that you want in your GUI - your "Graphic User Interface". That's all very well and good, but you'll also want to arrange them neatly and you'll do this with a geometry manager. of which there are three.

The pack geometry manager adds widgets to your window from either side, or from the top and bottom, one at a time - so they form a single row or column. The place geometry manager places widgets at a specific offset within the frame and is the least commonly used of the three by a long way. The grid geometry manager allows you to place whole rows and columns of components in a grid.

With the grid geometry manager, all the cells in a row have to be the same height and all the cells in a column have to be the same width. Otherwise it just wouldn't BE a grid. So how does Tk handle individual component size variation?

By default, each column is made as wide as the widest component in it, and each row is made as tall as the tallest component. Smaller components are then centred in their cells, with the space (padding) distributed equally around all four sides.

If you don't want the space evenly distributed, you can use the -sticky option on your grid command to stick the component to the various sides ...
N - Stick to the top (North)
S - Stick to the bottom (South)
E - Stick to the right (East)
W -Stisck to the left (West).
For example -sticky NW will place the widget in the top right corner of its cell.

To stretch a widget, you may specify that it's to stick to two opposite sides, and to stretch it to fill the cell you can stick it to all four sides - thus -sticky news

Posted by gje at 07:21 AM

September 13, 2005

Database or Progamming - which to learn first?

Q I'm going to be writing a database application, but I don't know much about programming of about databases. Should I learn Python before MySQL, or MySQL before Python?

A As far as our training is concerned, the order in which you learn the two technologies isn't especially important. They're like two large but well fitting jigsaw pieces - you need them both, but the order that you put them into the puzzle doesn't really matter. And in terms of connecting them together, there's just the tiniest drop of "glue" to go between them which we do cover on the Python course.

Footnote Although I've answered this question in relation to python and MySQL, the answer would equally apply to other programming languages such as Perl and PHP. In the case of PHP, some prior knowledge of HTML and web site structure is required before the PHP course - we can help with that on our technology for PHP day ... but that's the subject for another day's entry!

Posted by gje at 07:14 AM

September 12, 2005

Server side scripting of styles to suit the browser

I'm updating our web site and, naturally, I want to use current standards for my HTML, and some of the newer features such as style sheets to make the web site cleaner and easier to navigate. But I was faced with a conflict - I want to be able to support customers who are browsing to our site with older browsers, AND I want to be able to make full use of style sheets and other newer facilities for those users with recent client software.

A first approach of attempting to come up with a set of style sheets to work with all our target browsers turned ino something of a complex exercise. It's pretty disheartening to spend a lot of time applying a fix to "kludge" one browser just to find that you've upset another. and the resulting file gets twice as hard to maintain each time a new set of browser support is added. Quite simply, it's not practical to come up with a single set of HTML and CSS that will well on all the older browsers AND will support the facilities of the newer ones that we wish to use

Our solution is to add PHP code into the style sheet ... and to tell the web server that .css files are to be parsed through the PHP module. It works a treat, and we set a header line to ensure the browser is told it's actually getting .css data. We can even pass parameters into the style sheet - in this example, to tell it to use a larger base font size to suit the accessability requirements of the disability discrimination act if need be.

<?php
header("content-type: text/css");
$mencolour = "#ffffcc";
$texcolour = "#000000";
$bfsize = 10;
if ($_REQUEST[fsize] == 1) $bfsize = 16;
?>

body {
font: normal <?= $bfsize ?>px verdana;
color: <?= $texcolour ?>;
}

Posted by gje at 02:54 PM

September 10, 2005

How far away is that server?

Ever wondered how far away a server is? You can get a clue from the ping time taken as internet traffic is fast but not instantaneous. No doubt someone can up with some scientific figures and speed here ... but seated in England, I've found today:

375ms to a server in Australia
170ms to a server on the West Coast of the USA
26ms to a server that I think is in Franfurt
less than 1ms to a server on my own LAN.

Posted by gje at 03:35 PM

September 09, 2005

Upgrade!

Is it ...

a) A piece of pure luck
or b) Something about my looks / manner
or c) A very clever database app

that lead me to be upgraded when I check in to the Radisson in Glasgow last night?

The Radisson is a modern hotel in the heart of Glasgow - just a couple of streets from where I'm running an Apache httpd and Tomcat course. A little up market from my norm, but convenient for the location, and heck why not for one night? But, yes I was suprised to be upgraded and found myself wondering "why". I'm going to put it down to a trained checkin operator, seeing a business credit card offered and finding from the database that I had never stayed with the chain before.

Link - Pictures of Glasgow
Link - Apache hpptd and Tomcat courses

Posted by gje at 06:51 AM

September 08, 2005

You cant

"You can't bring that in here". My greeting this morning in Glasgow as I wheeled my trolley of laptops into the builing I'm training in. OK - so where should I take them? It's very rare to get turned away or have other difficulties getting to my customers, but when it does happen I just smile and think "well - they're paying for my time" and follow whatever instructions. This morning, that was a case of 100 yards up the road, down a side alley and round to the back of the building from where I *was* able to bring in my equipment. Ironically, I've ended up in a very nice room overlooking the lobby from where I was denied access. So - let me see - around 200 yards round to cover about 30 feet!

I'm doing an Apache httpd and Tomcat course. I bring all my own kit, which I network together with my own hubs and cables; I connect in only for power. "You can't network those". Hmmm ... they're a right negative lot here ;-) ... and how am I supposed to do a network / server training course without connecting my systems into a LAN? Compromised reached ... their "no networking of outside laptops" rule is designed to keep outside equipment off their LAN and I have been allowed to network the machines to each other which ... is actually all I wanted in the first place.

These things go in threes ... "You can't run that cable across the floor". We're getting used to finding solutions here by now, and I picked up a cable guard lying on one corner. "OK with this" I ask, and I can complete my setup.

Moral of story? We set up in sorts of different places and can cope with just about anything. The time I was in a US Army base in Germany and - because the right paperwork hadn't been filled in - took two hours to get onto base on the second morning, including having a young squaddie young enough to be my daughter waving her automatic rifle at me, and a visit to the Military Police's holding unit (but NOT into a cell) - is memorable. That was before I started writing "The Horse's Mouth" though and I've never found the need to trawl back to find things to say.

Posted by gje at 06:22 PM

September 07, 2005

Fair system for travel and accommodation expenses

As I drove home through Marlborough yesterday evening, petrol was priced at 1.03 per litre, and diesel at 1.08; the one garage in the town is always expensive (read "Monopoly") but this perhaps just the cutting edge of a trend.

The hotel I stayed at in Central London was carefully selected to be reachable by car and with adequate parking - when taking equipment, I have to drive, alas. Their prices went up by 3 pounds per room on Monday night.

I'm back home in Melksham this morning, but setting off just after lunch for Glasgow. The room I'll be staying at tonight - just past Gretna is going to cost me a pound more than it did just a few weeks ago.

And on to Glasgow where I was ... shocked ... that the recommended hotel charges 140 pounds per night. It's another somewhat awkward City Centre venue, so I'm "going with it" ... but all these high and rising expense prices bring me to look carefully at what we charge our customers and consider whether a similar upwards revision would be in order.

Since we started running courses and invoicing "on our own account" some five years ago, we've quoted for (and charged) travel and overnight expenses based on the distance travelled to the part of the country concerned - by postcode area - and a fixed overnight rate for each night that we stay away. That fixed overnight rate of 95 pounds is to include incidentals such as parking, evening meal, breakfast, and any extra communication costs (i.e. Internet access) while away. And it's way below what the actual costs will be in Glasgow; we'll be subsidising the expenses from the course charges.

So - time for a change? No, I don't think so. The mechanism is a good one; it means that we can quote our clients a fixed price ahead of time; sometimes we "win" and sometimes we "loose" and provided that it's broadly in balance, and the system is fair so that we don't have one group of customers providing a heavy subsidy to another group, I think the mechanism should remain in place.

It's our intent that the expenses we charge should cover our actual expenses. We don't pay ourselves for the time we spend travelling (we do that out of "love" in our own time) and we don't look to making a profit nor taking a loss on them. As we come up towards the end of the year, if prices continue to rise we'll probably need to apply a gentle, perhaps slightly upwards, hand on the tiller for orders received in 2006 with a careful look at motoring, hotel, and ferry costs which are the three elements on which each expenses quote is based.

We remain committed to only charging for our time for the days that we're actually with you, and to providing you with a fabulous course where you just have to provide a room and the students ... no matter where you are in the British Isles or beyond. One week (this week!) it's Vauxhall Bridge Road in London and Argyle Street in Glasgow ... next week, it could be a quiet suburban street in Cambridge, or an office unit tucked away on a Channel Island.

Posted by gje at 07:58 AM

September 06, 2005

Outside of the box

It sometimes pays to look "outside of the box" and it sometimes needs someone else to see that there IS a box there in the first place.

We live on the outskirts of Melksham, near the site of the former RAF Melksham base which has now been developed into the Bowerhill part of the town; the former training station for new RAF recruits being, we were told being replaced with little trace. So when Lisa came to help produce the Bowerhill Calendar for 2006, she started with something of a dearth of information. Unsuprisingly, there aren't a lot of pictures of what was a military establishment, and as it was a training school and not a more "romantic" operational station, little was written or saved.

And yet. Start looking around and you'll see that there are some traces of the old RAF ... odd huts remain in the industrial area that was developed piecemeal, and the Christie Miller sports centre is (I understand) the old base Cinema. And walking around with some of the people who've lived on Bowerhill since its conversion, they point out a number of things. And they remember / comment on pictures they have from the earlier post RAF days when there were more remnants, and come up with new contacts and leads to follow.

Yes, Lisa IS still researching and looking for material but it's no longer a case of filling in white space; now, it's a question of improving what she has, and packing / adding in extras. The material's out there - it's just a question of looking beyond you see. I've put some more pictures from Bowerhill on our Wiki.

Posted by gje at 07:26 PM

September 05, 2005

Linking Apache httpd to Apache Tomcat

Current connectors are jk and proxy; jserv, warp and jk2 are deprecated. As well as httpd and Tomcat downloads, you'll need mod_jk and then you'll need to configure it. I've seen some long explanations ... so here's a "bare bones" for the configuration files:

Onto the end of httpd.conf:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile /usr/local/tomcat/conf/jk/workers.properties
JkMount /*.jsp catkin

Into the workers property file mentioned

worker.list=catkin
worker.catkin.type=ajp13
worker.catkin.host=localhost
worker.catkin.port=8009

Full Story, including why you need to make the link, in our solutions centre. Training in installing and configuring Apache httpd and Apache Tomcat, and on using both the jk and proxy connectors on our Deploying Apache httpd and Tomcat course

Update - 10th December 2005. The story's updated again. With the new Apache 2.2 httpd server, the jk support is provided as part of the download and no longer has to be sourced separately - a good move that removes at least one loop from the process.

Posted by gje at 06:47 PM

September 04, 2005

Expect for Windows

I've just noticed on the Activestate site that "the ActiveTcl distribution now includes Expect for Windows. A license is no longer required ....". At face value, that looks like excellent news!

One of the big uses of Tcl and Tcl/Tk is in the automation of processes / programs that are designed to work from the command line and don't have an easy interface for other automata to use them. For example, if you run a regular ssh or telnet session every day, you can automate it with relative ease through Expect, where you choreograph the session in a series of "I say this" and "you say that" type statements.

Expect was written originally for Unix and works well on Linux and OS X. Up until a year or two back, only older and somewhat unsupported / unstable releases were available on Windows due, I understand, to the underlying operating system making it quite an issue to implement the multiprocess environment expect requires. Then Activestate brought out a commercial, license-only expect extenstion to ActiveTcl. This has always felt a bit - unfortunate - that a piece of software that started as Open Source became commercial-only in this guise and I'll be off to look at the licensing agreement when I get the odd spare moment to see if it's now - as I hope - free at the point of distribution and on a license under which that distribution can be used in perpituity. With a confirmation of the latter, you'll find me grinning from ear to ear!

Added, 10th September ... I AM grinning from ear to ear. I had a chance to download and test Expect for Windows and it ran nicely, without any problems. See full source code of my example

Posted by gje at 06:53 AM

September 02, 2005

Through public transport connection, Chippenham to Salisbury, to cease

Chippenham lost its train service to Oxford in 2003, and now the service to Salisbury and Southampton is threatened too. That would leave just the London to Bristol service calling there, plus a single train each rush-hour to Westbury.

The threatened service runs through our town of Melksham and we've started an awareness campaign here, encouraging people to write the their MP, to the train operators, to the SRA (or rather - now - the Department of Transport, Rail) and others to express their views. We're also encouraging people to use the service for the next 18 months.

Illustration - the threatened train service to Trowbridge, Salisbury and Southampton pauses at Chippenham on a Sunday afternoon

But with a bigger town like Chippenham, how on earth do we find the right people to alert to the threat? It's not just "The Melksham Train". It's the train that lets you get from Chippenham to Westbury in 25 minutes, whereas the bus alternative would take 90 minutes. It's the train that will get you to Salisbury in just over an hour .... the best bus journey takes nearly twice as long, and involves at least one change.

Regular readers here may have seen my previous "Save the train" posts here; I'me now starting to raise awareness in Chippenham (first link) and I'll be doing so later on for Swindon, Trowbridge and Westbury. If you're from one of these towns and you feel that service should be retained, please contact me by email or through our support or petiton pages. Many Thanks!

Posted by gje at 12:24 PM

September 01, 2005

FTP - how to make the right transfers

If you're transferring files from one computer to another, you'll probably use an FTP client program - either something with a GUI or the FTP command itself on your local machine, and that will talk to an FTP daemon on the server.

It's important to note that you need to navigate to the right directory on your local system AND the right directory on the remote system before you transfer the file, and that you know what the file to be transferred is named at the source AND what it will be named at the destination. Many an error has been made by getting it wrong at one end of the other, or by "put"ting when you meant to get, or "get"ting when you meant to put.

If you're a newcomer or rare user, here the scheme we use to FTP transfer files that keeps it as easy as possible ...

1. Use commands on your LOCAL workstation to navigate to the directory from / to which you wish to transfer

2. Establish an ftp connection to the remote machine

3. Use cd and ls to move and look around on the REMOTE machine and navigate to the directory from / to which you want to transfer there.

4. Use the put command to transfer file(s) to the remote machine, and / or the get command to transfer files from the remote machine

5. Leave ftp using the quit command.

Example of the commands you might enter:

1.
cd backups

2.
ftp 192.168.200.66
trainee
abc123

3.
cd /etc/httpd/conf
ls

4.
get httpd.conf

5.
quit

Other things to remember ....

a) If your transferring files between Linux (or Unix) and Windows systems, you MUST ensure that you're in Binary mode if you're transferring binary files and ASCII mode if you're transferring text files. The easiest way to do this is to type ascii or binary before you do your put or get.

b) File names are case sensitive on Unix and Linux systems, but case insensitive on Windows.

Posted by gje at 06:12 PM

New print centre for our manuals

A product has been a great hit if you go out and buy another of the same. Our workhorse Xerox N40 printer has printed all our manuals since we moved to Melksham and opened our own training centre ... it's survived the building works going on all around but, alas, with old age the toner cartridges and spare parts are getting hard to source and it's running warm.

So we've retired the N40 from active daily life and purchased a more recent (faster, higher capacity) model from the same stable. Here's our new Xerox N4525 print centre - it'll print up to 45 pages per minute, double sided, on paper up to A3 in size. The bulk sheet feeders hold up to 2500 sheets each.

Do we really need such a workhorse? Yes, absolutely! A typical set of course notes is more like a book - around 70 to 80 pages per day ensuring that our trainees can concentrate on what they're being taught rather than having to scribble notes all day with aching arms. And the fact that we do our own printing in house means that we can update our notes frequently and produce tailored manuals quickly and easily. I think the "in term" is print on demand

Posted by gje at 06:58 AM