« March 2008 | Main | May 2008 »
April 29, 2008
Box from end to end
My picture of a train bursting out of the West portal of Box Tunnel - taken a year or two back - come up as one of the top hits on Google.
But Box tunnel has two ends ... and this morning when I visited my dentist who practises there (Corsham), I drove over the road near to it and stopped. A little in the distance - but see the train in the tunnel, and indeed you can see right through!
It is said that on Brunel's Birthday, the rising sun shines right through .. I don't know about that, but the story's a nice one.
See more recent images here and here
Posted by gje at 04:28 PM | Comments (0)
More about Graham Ellis of Well House ConsultantsApril 27, 2008
From Freddie the fallow

Hi, I'm Freddie the fallow deer and I would like to introduce you to my home at Dyrham Park.

Some of the older trees in the park have fallen and newer trees have been planted ... and there's plenty of grass for me and my friends to eat!

Avenues of new trees disappear over the horizon and there's plenty of grass for me and my friends to eat - I repeat that because it's important to us!

The quiet winter is over, the summer season is coming, and the stalkers are out. But we feel safe here as they only shoot us with cameras!
Posted by gje at 09:32 PM | Comments (0)
April 26, 2008
PHP Techniques - a workshop
So many people know the basis of PHP - the language constructs themselves and how they work individually - but could really benefit from learning how to make the best of those elements. And these techniques for putting the elements together are so important that they should not be crammed onto the end of a "PHP Programming" course, but rather should be tackled afresh, with time, after you've had a little practise with the basics.
If you can already code PHP but you're looking to make good use of databases (and get the joins right), to make secure code, to write applications which recognise the country your visitor is from (or whether your page is being visited by a spider), to write code which is easy to modify as your customer's needs change, to handle uploaded images, or which can have a new look-and-feel applied without reprogramming, our PHP Techniques Workshop will be what you're looking for.
Why a Workshop? Because for this type of learning, a small group is ideal. Interaction with other delegates and the tutor, working on projects that are relevant to you so you go away with a practical experience and not just the result of book-learned theory.
We describe this as a two day workshop - but it's a full two days and we encourage you to arrive the evening before at our Melksham, Wiltshire hotel and training centre. On that lead in evening, you'll get a chance to get on line (we provide server and client laptops, but you are welcome to bring your own and connect them in), to meet your fellow delegates, and to be prepared for a fresh start early the following morning.
This year (2008) arrive on Wednesday, 14th May ... on Sunday, 20th July, on Sunday 14th September or on Wednesday, 5th November, for the following two days. The £720.00 + VAT rate includes 2 evening meals, 2 breakfasts, 2 lunches, and two nights accommodation, high quality rooms. Let us know if you'll be arriving in Melksham by train and we'll meet you at the station too. And, yes, we have plenty of free parking.
| The Arrival Evening | |
|---|---|
| up to 21:00 | Arrive (any time from mid-afternoon), settle in, get on line |
| 20:00 | Buffet available |
| First Full Day | |
| 07:00 | Breakfast |
| 07:30 - 09:00 | PHP Revision - the basics [details] |
| 09:15 - 12:30 | Sticky Fields and Sessions [details] MVC, 4 Layer Model and templating [details] |
| 12:45 | light lunch |
| 13:30 - 17:15 | Long and short term cookies and security [details] DDA, Style, image handling (inc capture) [details] |
| Evening | Tips and Techniques Clinic [details] |
| 20:00 | evening meal |
| Second Full Day | |
| 07:00 | Breakfast |
| 07:30 - 09:00 | mod rewrite techniques, Recognising browsers, countries and referers [details] |
| 09:15 - 12:30 | Web2 and caching, [details] Searches, 404s and Search Engines, [details] Maps, Graphics and Geographics [details] |
| 12:45 | light lunch |
| 13:30 - 17:15 | Putting it Together [details] |
We'll offer you a lift back to the station at the end of the second day, or if you prefer to stay a further evening you're welcome to book your room for just £60.00 + VAT and check out the next morning.
Posted by gje at 09:10 PM | Comments (0)
Useful link: PHP training
April 25, 2008
An extra step - victory from defeat
No-one can get everything they do 100% right every time - things will go wrong, even in the most carefully assessed circumstances where all practical steps have been taken to reduce the risk. I feel secure, and fully knowledgeable of the line below which the quality of service that I get at the particular hotel chain that I've been staying at this week. And for the first time that I can recall, I was let down by one particular, but serious, error and subsequent security lapse. I am not, by nature, one to go marching over to the front desk ... but in this case I did.
Of course, I have one leg in either camp - customer and hotelier.
Top marks to the reception staff for their handling of this livid man - and confirmation to me that our policy at Well House Manor of going "one step beyond" is the right one. I was looking for an explanation, duly given. I was anticipating (for what it was worth) an apology, which I got. I was hoping for a step or two to be taken to avoid the same thing happening to another guest. That was promised and probably followed through. I wasn't anticipating the complimentary tray, delivered to my room as I had an evening of work to do.
I try never to turn away from a well-liked supplier based on one unfortunate incident, so it's unlikely I would have given this chain a miss in the future even if I had been given a "don't care" type brushoff. But actually the whole has cemented by brand loyalty - victory from the jaws of potential defeat, if you like. Someone - please remind me to tell this story at our next staff meeting, and to remind our team (who know it anyway) to go that extra step.
Posted by gje at 01:37 AM | Comments (0)
April 24, 2008
Linux and Java Course in London
There are certain locations which used to fill me with horror as to how I was going to work out the logistics of getting my equipment in and out for a course. And today's was one of those for which I would have looked on a map and shuddered. Take Liverpool Street, Aldgate and Bank (in the City of London) and my location is right in the middle of them. In fact it has turned out to be next door but one to "The Gherkin", and up an narrow alley, black tarmac with decorative yellow lines painted down both sides.
But these days .. such locations aren't a big problem; they're even easier than a typical science park or trading estate. For all courses within London's congestion zone these days, I stay at a hotel a short way out, and grab a cab to get in; the equipment and my trolley comes "with" and I arrive on the doorstep, no car to park, and chauffeured-fresh on the first morning.
The evening, and subsequent mornings? I make good use of the local public transport to and from my hotel if it's not in walking distance.
Result? A fresh tutor and a really great Deploying Java Applications course given in the heart of the City of London.
Posted by gje at 07:44 PM | Comments (0)
Useful links: Linux training, Java training
April 23, 2008
Norwich and London
Here's a picture taken on Sunday evening on he bridge over the river Wensum in Norwich; it's a fast moving week - I'm writing from Beckton in East London this morning, and I'll be in the City in just over an hour!
I have updated my Norwich pictures too!
Posted by gje at 07:22 AM | Comments (0)
April 22, 2008
User and Group settings for Apache httpd web server
When you're running an Apache httpd web server, you should run it using a separate daemon user account and group set up for the purpose and not run it as either root (a horrific thing to do, as it would lead to all sorts of security holes) or nobody (another very bad idea, as the "nobody" applications can club together and become a somebody, as the Tsars discovered some 90 years ago).
Under Redhat (Fedora) you'll find both user and group numbers 48 set up as "apache" and you should use them. Under SuSE the equivalent is "www" and "wwwrun". Simply put the names or numbers into the httpd.conf file under teh user and group directive. On other versions of *nix, you may need to set up the account yourself.
Once you have set up your web server in this way, you can create your developer/deployer's account and the web area to be owned by that developer/deployer, in the same group as the web server. Then use the user permissions to control what the developer can read and write, and the group permissions to control what the web server can read and write.
Posted by gje at 11:27 PM | Comments (0)
April 21, 2008
A small picture does not always cut it!
There are certain pictures which look fabulous full-screen, but are rather weak when sized down. The picture on the left - of the heath lands near Elveden in Norfolk, in the fog yesterday morning is one such. If you click here, you'll see it larger and in a new window.
Posted by gje at 06:41 AM | Comments (0)
April 20, 2008
Steam Engines at Bressingham
I think the copy of "Steam Engines at Bressingham" - written by Alan Bloom - is still on my shelves at home. It was certainly a book the I read, and reread as I struggled with English which was my weakest vital academic subject. It told of a man running a horticultural business with a passion for steam, who branched out into old traction engines just after their twilight, when a few had been preserved, most cut up, and a few abandoned as rusting hulks.
In the book, I read how Alan and many helpers restored Boxer and Bodicea and Bella and Bertha with a patience I have never had and could only admire. And Alan went on to add narrow gauge railways (yes, plural!) to his collection and then, on the withdrawal of steam from British Railways in 1968, two locomotives from the National Collection - Thundersley, and Oliver Cromwell, which drew the very last steam train, were placed with him on loan.
A Tomcat Course coming up this week in Norwich, a desire to take a day's break, and Lisa and I had a chance to see something in Norfolk on our way - and what better than Bressingham Gardens, at Diss.
As you see, Bertha and Boxer are still there (and a search in last few minutes reminded me that the book was published 38 years ago) which I suppose I should find remarkable, and in a way I do. But Alan passed away, aged 99, last year and the place frankly disappointed. You could see the love, but you could also see the slight gone-to-seed. But perhaps my expectations were unreasonable; I had built the place onto a pedestal such that it was bound to disappoint. I'll leave you with some pictures to you can make your own judgement. And - for all my comments - do drop in to the place for an hour or two is you're passing and have a look.




Posted by gje at 09:13 PM | Comments (0)
April 19, 2008
Not daring to be an anorak

It's two class 20 locomotives on the front of a rake of early Mark 2 coaches, with some later mark 2 coaches and a class 57 on the rear, passing through Melksham this morning on an Oxford to Weymouth excursion train. It was only just on time as the single line at Thingley was cleared 5 late by the 143 on the scheduled service
Now here's the sad part. If I admit to knowing all of that to certain of my contacts with whom we're working for an improved train service, they'll take everything I say with a pinch of salt and discount my suggestions because I'm then classified as an "enthusiast" or "anorak". Curious, isn't it? What other business would so water down the comments and suggestions of its most faithful customers so that they feel restrained in the support they offer?
Let me rephrase my initial statement.
Here is a long train of a type I don't think I've seen before going through Melksham. It was a long train and well loaded, and going quite fast as the track is in good condition. The platform behind the train serves the town of Melksham Wiltshire which has a population or around 24000, but very few trains call there for reasons that seem very hard for a sane person like me to fathom - it's certanly not lack of demand for people to travel around these parts!
If you would like to learn more about our campaign for an appropriate service stopping here - and we DO have a good chance - please visit this page. Thank you.
Posted by gje at 09:26 PM | Comments (0)
April 18, 2008
PHP training courses every month
Due to increased demand, we have increased the frequency of our PHP courses and we're now running at least one course on the subject every month.
* If you've never programmed before or written any HTML, start with a one day "Technology for PHP" the follow on to "PHP Programming".
* If you're familiar with setting up web sites and / or you've programmed a bit, start with "PHP Programming"
* If you already know how to program in PHP, but you want to make the very best of use of the techniques used in the language to write robust, reliable, easy to use and maintain applications ... come along on PHP Techniques.
Here is the PHP related course schedule for the rest of this year:
From 15 May 2008 - PHP Techniques, 2 days
On 13 June 2008 - Regular Expressions, 1 day
From 16 June 2008 - PHP Programming, 4 days
On 20 June 2008 - Object Oriented PHP, 1 day
From 17 July 2008 - MySQL, 2 days
From 21 July 2008 - PHP Techniques, 2 days
On 10 August 2008 - Technology for PHP, 1 day
From 11 August 2008 - PHP Programming, 4 days
On 15 August 2008 - Object Oriented PHP, 1 day
From 15 September 2008 - PHP Techniques, 2 days
On 26 September 2008 - Regular Expressions, 1 day
From 29 September 2008 - PHP Programming, 4 days
On 3 October 2008 - Object Oriented PHP, 1 day
On 27 October 2008 - Technology for PHP, 1 day
From 28 October 2008 - PHP Programming, 4 days
From 6 November 2008 - PHP Techniques, 2 days
From 13 November 2008 - MySQL, 2 days
From 1 December 2008 - PHP Programming, 4 days
On 5 December 2008 - Object Oriented PHP, 1 day
On 12 December 2008 - Regular Expressions, 1 day
Posted by gje at 12:25 PM | Comments (0)
Useful link: PHP training
April 17, 2008
When an array is not an array
An array, I was taught, is a sequential series of memory locations in which values of some type are stored. In an array, each of the memory locations is the same size (number of bytes). And so, as I was taught, arrays can be used very efficiently using pointer arithmetic, BUT they need to:
a) Be defined in advance
b) Have each element given enough memory to allow for the biggest content
and
c) They cannot be lengthened later
d) Taking an element out in the middle calls for a lot of shuffling up.
Arrays in PHP and in Tcl are NOT arrays! The word "array" is used more loosely to define a collection object which is (in computer science terms) either a link list or a hash. And that means ...
i) You can define PHP or Tcl arrays as you need them
ii) Elements can have different sizes
iii) Arrays in Tcl of PHP can be expanded as need be
iv) Elements can be deleted easily from the middle
v) Elements can be named (PHP's "associative arrays, all Tcl arrays) rather than numbered
You gain all that flexibility ... what do you loose? For a few applications - the intense dataprocessing / calculation ones - your application may slow down a bit. Since PHP is a web server language where you aren't typically doing such calculations, that turns out to be no loss at all!
Posted by gje at 06:40 AM | Comments (0)
April 16, 2008
Regular expression for 6 digits OR 25 digits
I can write a regular expression to match ANY number of digits between 6 and 25 ...
^[[:digit:]]{6,25}$
but how would I write a regular expression to match either 6 digits or 25 digits, but no number in between?
^([[:digit:]]{6}|[[:digit:]]{25})$
(The regular expressions in this example are Tcl and PHP/ereg types. use \d instead of [[:digit:]] for PHP/preg and Perl.)
You may wonder why I want this. A client with 6 digit or 25 digit part numbers, a year number that can be 2 or 4 digits ...
Posted by gje at 07:06 PM | Comments (0)
April 15, 2008
Comfy Chair - Floating Harbour, Bristol
Just occasionally, I get a few minutes to sit and relax ... and just occasionally I hand my camera to someone else to use so that I can appear in front of the camera rather than behind it. Here - it's rare - is one of those occasions where both happened at the same time.
Posted by gje at 08:13 AM | Comments (0)
April 14, 2008
Gauging point at entrance to Bristols Floating Harbour
What is a "GAUGE POINT"? This curious contraption is set on the point where the River Avon forks as it comes up into Bristol from Avonmouth - to the left is the true course of the river and to the right is the entrance lock at Cumberland Basin to the floating harbour.
There are two gauge point devices - one either side of the river, and I'm guessing that they're used with a cable between them when a boat passes over to see how deep the boat is below the waterline, but if anyone has any other guesses, please do email me
As an interesting aside, the rise and fall of the tides on the Bristol Avon are enormous - said to be the second highest in the world, and as we stood for a few minutes the waterline which was level with one line of mortar in the stone blocks of the lock fell noticeably by half a block.
Posted by gje at 08:00 AM | Comments (0)
April 13, 2008
PHP course dot co, dot uk
"www.wellho.net". It's the natural domain for us to use - we provide Internet training services, and we'll provide those training services in whatever countries it's safe and legal for us to do so, and where we can be understood.
Except ... search for us, and specify that you're looking for "UK pages only and we don't pop up. A poorly ranked mirror at "www.wellho.co.uk" does come up but I'm not thrilled ... and I'm not thrilled at the idea of shifting all of our activity to a county based domain when the world is more and more one country, nor on moving my hosting to the UK just in case that makes us look like a UK site.
I have no solution (and I am open to ideas - email me via graham@wellho.net) but as an interim action it struck me that what I've had described to me as a "microsite" might not be a bad idea. So please have a look at http://www.phpcourse.co.uk where I am providing unique, and specific, information about our PHP courses in the UK.
Posted by gje at 09:48 PM | Comments (0)
Useful link: PHP training
Chew Valley Lakes
| |
| |
| |
| |
Bird Watching at Chew Valley Lakes ... Canada Goose, Coot, Great Crested Grebe, Mallard, Whooper Swan, Tufted Duck. On the A368, Weston-super-Mare to Bath Road.
And yet ... where ARE all these birds when you look at the wider view?


Posted by gje at 06:41 AM | Comments (0)
April 12, 2008
Underlining in Perl and Python - the x and * operator in use
Perl's x operator - yes, that is the letter x - is used to replicate the string on the left the number of times given to the right. "What use is THAT" I have been asked in the past, by delegates feeling that it's a solution looking for a problem. Well - as an example, it's a great way to output just enough "-" characters - or anything else in a fixed with font - to underline a title.
print "Your name? " ;
chop ($name = <STDIN>);
print $name,"\n";
print "-" x length($name),"\n";
And here I am testing that ...
Dorothy:qc2 grahamellis$ perl titlit
Your name? Graham
Graham
------
Dorothy:qc2 grahamellis$ perl titlit
Your name? Graham Ellis
Graham Ellis
------------
Dorothy:qc2 grahamellis$
In Python, the * operator on a string object will achieve the same goal:
line = raw_input("your name ")
print line
print "-" * len(line)
And running that ...
Dorothy:qc2 grahamellis$ python pytit
your name Python Trainer
Python Trainer
--------------
Dorothy:qc2 grahamellis$ python pytit
your name Perl Trainer
Perl Trainer
------------
Dorothy:qc2 grahamellis$
Posted by gje at 04:59 AM | Comments (0)
Useful links: Python training, Perl training
April 11, 2008
Learning to program in Perl
For the last few days, I've been teaching Learning to Program in Perl. Unlike a conventional course style, for this one I had been asked to assume no prior programming knowledge, and covered first principles such as variables, conditionals, and loops.
Here is one of the examples I wrote during the course ...
# The bit you do at the start
print "Please enter first number ";
$entry = <STDIN>;
$sofar = 0;
$howmany = 0;
# The bit you keep repeating
while ($entry > 0) {
$sofar += $entry;
$howmany++;
print "Please enter next number (0 to end) ";
$entry =
}
# The bit you do at the end
print "The total was $sofar in $howmany entries\n";
You'll note how I have divided a straightforward little application into "the bit that's done once, first", "the bit that's repeated", and "the bit that's done at the end. And you'll note too how important the comments are!
Given a couple of days, we moved on from examples like the one above to a program that was reading and analysing a log file ... and coming out with results. Perl is, after all, the Practical Extraction and Reporting Language
Posted by gje at 01:43 PM | Comments (0)
Useful link: Perl training
April 09, 2008
Sheep Shearers, Marathon Runners and Ocean Sailors
We have a wide wide range of customers. And I never know what I'm going to learn about from week to week. Now of course privacy is paramount so I won't talk about a customer without his prior permission, nor will I apply and pressure at all to obtain such permission. But there are times when it suits - mutual advertising if you like - to make comments.
I have written on one or two occasions in the past about sponsored events that delegates were about to undertake - running is popular - although I'm not sure whether or not I specifically mentioned marathons. It always surprises me to have a marathon runner on my course, yet it's not THAT unusual - which when you see the thousands who start does make sense - there's a lot of "them" (or "you") out there. A little more unusual was the delegate who had to leave sharply one day to shear his sheep ... or was it someone else's sheep under contract?
Here, today, is as a link to the web site of Ocean Mist - Andy was on my course last week and we were chatting about the joys of sailing; very different to the narrow boating I used to do, and perhaps again will some time. Andy comments about the link "I am of course happy to reciprocate on the off chance that there's someone looking at sailing pages who happens to also be interested in Tcl..." (but personally I would be happy if people link to us from his site to learn PHP or Perl or Python as well.
Actually, Andy, it's a small world. One of the sites you link to on your page is written by customers of ours, in PHP that we taught them!
Posted by gje at 07:24 AM | Comments (0)
April 08, 2008
Learning and understanding scripting programming techniques
Can you have a book about programming that's not about a specific programming language? A course that covers useful techniques across the board? That applies right across languages, with tips and techniques and things to bear in mind? Now there's a challenge, and I think the answer would be "yes." And the book/course could cover so many valuable topics ...
There are techniques that every programmer needs to know, over and above and beyond the basics of any one language. And they're rarely taught on any programming course, but would make such a huge difference, I know, to so many of our delegates. I'll give you some subject headlines - not sorted into any particular order.
Constants and config files and options
Programming with fixed values, and values that are changed at installation
Equality, looks like, min and max
Does 7 equal 7.0? Does SN12 7NY look like a postcode?
Comparing - old, older, oldest
Getting a value, comparing data, comparing collections of data
Cardinal Values
Numbers that are used as markers, and some cautions about their use
Letting it finish
Terminating processes and file handling neatly, avoiding garbage
Intermediate reports
How can I ask "how is my program doing" while it's running?
User inputs
Taking care of nasty values. Validation.
Efficiency
Technique "a" may take 3 days - and technique "b" 3 minutes.
Usability
Providing a consistent and understandable user interface
Merging data
Taking multiple data sets and combining them
Reusability and support
Writing code that can be reused, and easily supported
Test and Debug
Techniques for checking your code before it gets to the users
Singular v plural
"is" and "are". "child" or "children". It makes sense to report in good English
reporting zero answers
Should you just leave a blank, or say "no match?"
Interactive inputs?
You need to prompt the user if you're interactive, yet prompting when reading data from a file will make for a messy output display
Error Handling
How to provide good, consistent, useful error messages
Injection attack.
What about malicious users running your script.
Strings - upper and lower, rude words
Users who SHOUT, or who don't know how to capitalise!
Dynamic v static
When are variables created and lost? How are they shared between blocks of code?
Declare v initialise v Assume
What are the advantages / disadvantages of declaring variables, initialising them, v assuming an initial value
Overriding code
Conditionally loading code, and replacing code already loaded
Scope and Name spaces
variables which are local to a piece of code, which are shared between a number of pieces of code, and are shared throughout an application
OO approaches
Is it a good idea to use objects for xxxx job?
Hashes / Dictionaries
Data that is keyed by a unique value. But what if that value is not unique?
Sorting
How sorting works and used defined sorting. Sorting (or not!) hashes
Caching
Avoiding repetition by caching, and how to ensure that your caches are up to date.
Graphics and graphing techniques
World and screen co-ordinates, choosing your axes, watermarking pictures and more.
Specifying an API that can be extended
Providing an interface to your functions that works well and is easily supported now,and can be extended compatibly when new requirements are added
Web and Database
Accessing your scripts via a web front end, and saving the data in a database
Threaded Programming
Running process in parallel
Queues and Recursion
Making notes of places you need to come back to, and saving where you are when you need to go off to more code.
Security issues
Capture, Passwords.
Can it all be done without reference to language then? No - I don't think it can; examples will be needed and there are nuances in each of the languages. And with my knowledge / use of Perl, PHP, Python, Tcl/Tk/Expect, C/C++, Ruby, Bash/Ksh, and Java, I'm well placed to show how the techniques can be implemented in each of them.
If you're interested in having a day or two of "techniques" training - please let me know. And, yes, I would illustrate and have you practice in whichever of the language(s) from my list that's appropriate to you! Email - graham@wellho.net - and refer to this item!
Posted by gje at 07:39 AM | Comments (0)
April 07, 2008
M25 / South Mimms Service Area
Pat, behind the counter, was picking at the ventilation hole in the lid of the coffee cup she was about to give that lady in front of me at South Mimms Services at 6:30 this morning. "It could hurt a child" she said as she worried the little bits of plastic that were sticking up, before handing it over. And this delay and explanation even though the customer looked middle ages, was on her own and in something of a hurry.
I was left alone to talk to Pat after the lady had gone; even a service area is quiet that early on. I asked if it wasn't equally dangerous to serve boiling black coffee to a child, and wasn't the slight sprig of plastic minor by comparison? She agreed, and said she would refuse to serve anyone under 16 with coffee, "especially espresso", before going on to tell me that the shop just across the way WOULD make such a sale, and "Red Bull" too.
Pat served me without questioning my age, and I asked if I was clearly over 16. "You look at least seventeen and a half" she said with a smile.
Posted by gje at 06:53 PM | Comments (0)
April 06, 2008
Do not SHOUT and do not whisper
"Your Name" says a box on a form on our web page, and visitors who want to sign up duely enter their name. Some of the names are shouted - "GRAHAM ELLIS" - and others are whispered - "graham ellis" when really we would like them all nice and consistent and in regular case - for we're publishing a list of people who have signed up to support a cause.
It's tempting to convert all of the names to lower case and then capitalise the first letter of each word, but that would upset the MacGreggors and daVincis of this world (and Peter Rabbit learned not to get on the wrong side of Mr MacGreggor, I recall).
So ... if the web site visitor uses both upper case and lower case in his name, we'll assume he's got it right. But if he shouts or whispers, we'll convert it as I was originally tempted to do.
Here's the code for that, in PHP.
if (ereg('[A-Z][a-z]',$row[name])) {
$names .= "$row[name]<br>";
} else {
$names .= ucwords(strtolower($row[name]))."<br>";
}
And if you want to see some output from that, have a look here; to learn how to do it, have a look at our PHP course pages.
Posted by gje at 02:33 AM | Comments (0)
April 05, 2008
Automating processes through Expect
What is Expect? Let me give you an example of how it's used to help answer that question.
I want to connect to a remote host that I can access through FTP, and have a look at all the files with "top", "sql" and "txt" in their names in my home directory. And that's something I need to do on a regular basis - perhaps checking logs on a web server.
I could type in the instructions longhand - but that would get monotonous on a regular basis - so I would prefer to run FTP controlling it like a puppet on a string - and that string in Expect.
Firstly, I do the job manually, once, and note down the exact prompts that I get, and the exact strings I type in. You noted, I hope, that I say "exact", didn't you - I must get spaces, carriage returns, line feeds right.
Then I write my code. The spawn command is used to trigger FTP. The expect command is used to await a prompt. And the send command is used to answer those prompts. Finally, I can use the variable called expect_out(buffer) which stores the complete response received prior to each "expect" to look at my results.
Here's a working example.
log_user 0
# Expect is a Tcl extension
# So all the Tcl commands are available too
puts "yes I am tickling"
spawn ftp 192.168.200.67
expect "): "
send "trainee\r"
expect "sword: "
send "abc123\r"
expect "ftp> "
send "ls\r"
expect "ftp> "
# The response we just got will have included
# the lines we want (and much more!) so that we
# can now use regular Tcl commands to extract it
set parts [split $expect_out(buffer) \n]
foreach line $parts {
if {[regexp top|sql|txt $line]} {puts $line}
}
# Close out cleanly
send "quit\r"
expect "eof"
That's very much a "spike" solution - a demonstration of principles; the expect command can wait for a whole series of alternatives (including error conditions) and the application above could be extended to handle them as appropriate, for example. And you can even run multiple spawned processes in parallel.
As well as Tcl commands, you can use Tk commands with Expect - that means that you can put a graphic front end onto it. One of the things I need to do from time to time is to check whether my servers are up and running, and an Expect and Tk tool is ideal for the purpose. You can see my source code here.
Expect, and Tcl are covered on our Tcl and Expect course. We cover Tk on our Tk course
Posted by gje at 08:03 AM | Comments (0)
April 04, 2008
Replacing the last comma with an and
If I have a list, I'm likely to want to present it comma separated for the most part, but with the word "and" between the last two elements.
"Cambridge, the M11, the M25, the M4, the A361 and Melksham" for example.
Lists or arrays can be joined in almost any language with a function called join or implode, and a parameter will allow you to specify that comma. But what about the "and"? A regular expression looking for a comma and replacing it with an "and" would just replace the FIRST comma. Solution - use a greedy "match anything" element at the start of the regular expression, thus matching the last comma. You can refer to $1 or \1 in your replacement string.
Want to see an example of that in use? Here is the algorithm coded in Tcl
set codez {SWI CPM MKM TRO WSB DMH WAR SAL}
puts $codez
set togo [join $codez ", "]
regsub {(.*),} $togo {\1 and} togo
puts $togo
And here is how it runs
Dorothy:mt2 grahamellis$ tclsh fbl
SWI CPM MKM TRO WSB DMH WAR SAL
SWI, CPM, MKM, TRO, WSB, DMH, WAR and SAL
Dorothy:mt2
Example written as a demonstration for delegates on the Tcl and Expect course I am running at the moment.
Posted by gje at 07:18 AM | Comments (0)
Cambidge - Tcl, Expect and Perl courses
By an amazing co-incidence, I'm in Cambridge this week ... running two 2.5 day Tcl and Expect courses, then back just across the road next week running two 2 day Perl introduction courses of the bootcamp style.

As ever, there's not there's not too much time to sightsee (that is NOT what my clients pay me to do!) but I can grab the odd evening walk - as seen above down by the river Cam. More Cambridge picures from previous trips
Posted by gje at 06:57 AM | Comments (0)
Useful links: Perl training, Tcl training
April 03, 2008
Fresher tutor, better course
Our favourite airline has gotten itself into trouble in the last few days by handing it letters to passengers it has failed to carry telling them it will pick up to hotel bills for them ... "up to 100 pounds" ... if they have to stay overnight in the area. "You can't stay overnight for that!" was a comment I heard. Well - I'm not so sure but I do know that hotel prices have rocketed in the past four years; a £60 room has become a £90 room.
Four years ago, petrol was 76p per litre, and it's now risen to around 108p - that's another leap. And much of that leap since the start of the year.
Can you believe that our Well House Consultants travel and overnight subsistence rates are no higher now that they were four years ago? The increasing costs have been met, to a very large part, by my going "down market" in where I stay - you'll see where I am at the moment in yesterday's blog. But it's becoming an issue; I do need to have space to work in the evening (and tonight I really haven't), and I do need good light, and power points in sensible places. I can get away without a clock (though I overslept yesterday morning), with a misleading sign that tells me to put my towel on the towel rail if I want to reuse it (there IS NO towel rail), and with a shower that should be called a dribble. And I just laugh off the peeling paint, the peeling wood chip paper and the MFI furniture that seem prevalent in so many hotels.
And so - a modest rise in our travel expenses and overnight subsistence rate for all new quotations. Very modest, actually - I've taken a 10 student course 165 miles from our base as an example, and see that it adds less than a fiver per delegate per day. And is this just for the tutor? No - it's for the customer too who will get a more refreshed, better prepared presenter. "You get what you pay for" they say, after all.
Posted by gje at 07:20 AM | Comments (0)
April 02, 2008
Every link has two ends - fixing 404s at the recipient
"They have printed the wrong link." Thus starts a frustrated post on the Save the Train web site, worried that a link in the local newspaper to our support pledge page ends up at a "404". And, yes, they have dropped the newspaper a line too, hoping to catch them before the online edition goes "printed".
But every link has two ends ... and since the error in the URL still leaves the URL pointing to our server, and just the wrong place on it, a very short mod_rewrite request means that the paper's site is now pointing at the correct place - in addition to the URL that everyone else is using.
-bash-2.05b$ cat .htaccess
RewriteEngine On
RewriteRule pledge$ pledge.html
-bash-2.05b$
So that's /pledge linked to /pledge.html
It's not the first time I've done this "trick" and indeed, given a substantial number of erroneous follows, I can sometimes spot such things in our log analyses. In this case we caught it very early, though!
Posted by gje at 06:33 AM | Comments (0)
April 01, 2008
Comparing hotels - as a guest and from the proprietors view
I'm in Cambridge and trying another hotel ...
![]() If you're making a room into a bedroom, it should be a double if you can possibly get a double in! Hospitality tray can go above the bed head, and you don't need to provide any power point for the customer except the same one as the kettle uses. | ![]() If your car park is round that back, you don't need a back door - send the customers around the side passage under the emergency staircase. Put safety tape on the staircase if it's a bit low and people keep knocking their heads and if you STILL have an issue replace some of the black and yellow with red and yellow. |
![]() Access to car park is along this back track that's doubling up as a building site at the moment. The unsigned cutoff into the car park itself leads to a series of white vans, with parking on the "First in, last out" principle. | ![]() You'll have a lot of bedding coming in and out. Always make sure that you leave space in the corridors for the guests to get past it. |
I won't put a link in to their site, as their web site and the actuality on the ground have helped me to understand the shock of some of our hotel guests when they find the rooms ARE as good as the web site suggest!
Posted by gje at 07:59 PM | Comments (0)



