« October 2007 | Main | December 2007 »

November 30, 2007

Easy selection of multiple SQL conditions from PHP

Are you automating an SQL query in a web page, wanting to select records to display only where they match a whole series of criteria from what could be a long list of options - for example looking for houses:

* Only in Melksham
* Less that 200k
* With a large garden

and other criteria that perhaps are required by other users might include:

* Near a good school
* Near public transport
* Ground floor
* Parking

If all that data is in your database - good, you can do it. But how do you build up the complex query? One useful trick is to have an array of possible queries, then push all the ones that you actually want into a further array and link them together with an implode putting an " and" between each element ..

$selectors = array(
  "cheap" => "asking < 200000",
  "local" => 'locate = "Melksham"',
  "bathphone" => 'phone like "01225%"');
$cwant = array();
foreach (array_keys($selectors) as $cdi) {
  if ($_GET[$cdi]) {
    array_push($cwant, $selectors[$cdi]);
  }
}
$restrict = implode (" and ",$cwant);

Demo here
Full source code here

Posted by gje at 08:41 AM | Comments (0)


Related topics: via article database
More about Graham Ellis of Well House Consultants
Useful link: PHP training

November 29, 2007

Upgrade Mac OSX to Leopard, Web Server Apache httpd config lost

We upgraded one of our Systems to OS X 10.5 (Mac, Leopard) recently and I have just enabled "Web Sharing" ... that's the Apache httpd daemon.

To my horror I saw this ...

... rather than this ...

• The httpd.conf file has MOVED from the /private/etc/httpd to the /private/etc/apache2 directory
and do not just copy the file as the old 38k (Apache 1.3?) file has been replaced by a new file of just 17k, and a subdirectory called extra which contains a series of files each of which contains the configuration for a feature.

In order to fix the problem, I'm re-implementing all the configuration changes made on the previous releases in the new release - and I know I may come across some further issues. Watch this space - I'll follow up here if I find any more dramatic heart-stoppers!

Posted by gje at 03:59 AM | Comments (0)


Related topics: via article database

November 28, 2007

Question on division (Java) - Also Perl, PHP, Python ...

Q:

What's the difference between % and /?

A:

/ returns the result of a division
% returns the remainder when you do a division.

Divide 18 by 7 you get 2, with a remainder of 4 (i.e. 4 left over).

so 18/7 give 2, and 18%7 gives 4.


And from Tcl/Tk and Expect... you can see the float v integer considerations of a division!

% expr 18 / 7
2
% expr 18. / 7
2.57142857143
% expr 18 % 7
4
%

Posted by gje at 02:47 PM | Comments (0)


Related topics: via article database

Useful links: Python training, Perl training, PHP training, Java training

Refa Tandoori Indian Restaurant, Melksham

I've always admired how the "Indian" restaurants in our town compete, and yet work together for the common good of charity causes. And they're doing so again. Each of them is holding an evening on behalf of the Bangladesh Cyclone Disaster (I used the term "Indian" because really they're from Bangladesh!). So

<advert> ... for them.

The Refa Tandoori (nearest and dearest to us ;-) ). 11th December 2007. All the proceeds from the meal you buy goes straight to the Cyclone appeal. The restaurant keeps none of the money. And, yes, you are encouraged to pay over the odds that night.

The food is always EXCELLENT and the restaurant usually busy - so book a table on 01225 705680. And get in NOW before it hits the local press

</advert>

If you've found the archive of this page ... the Refa Tandoori is open 7 nights a week, and lunchtimes except Friday and I can utterly recommend their food.

Posted by gje at 08:13 AM | Comments (0)


Related topics: via article database

November 27, 2007

An answer to a student asking 'Help'

I've got time - a lot of time - to help people who are learning; it's really rewarding to teach the subjects that we do, and the most rewarding students are those who take the time to go above and beyond the norm in asking questions. So why, when I get an email out of the blue asking for help with a learning project, am I often very reluctant to muck in directly? Here's why - in the form of an answer sent out in the last few minutes ....

I'm always very reluctant to give students advise on their assignments as I don't know what you have been taught so far and what the intent of the assignment was. It would be too easy for my to start using elements of Java that you haven't been taught about yet, and to spoil the way you're learning - that would be very unhelpful in the longer run. If you're having trouble with the assignment, then your teacher or his assistant or your school/college help desk really should be the ones who know how best to help you (and good on you for asking for help).

In particular, I look at your use of switch in the first enclosure and see that you have it go 52 ways - once for each card in the deck. There's a programming paradigm that says "if you find yourself repeating something, there MUST be an easier way of doing it" and indeed that is the case - your code is 10 times longer than it should be BUT ONLY IF you have already been taught things like the loops and arrays you would need to make it shorter .... (and in a real practical solution it should be shorter to cut down on the maintainance issues of a live system)

I would, though, agree that if you feel your teacher doesn't know enough about the subject to be comfortable as he/she teaches it and has no support, you're in a bit of a problem area. Have a look at
http://www.wellho.net/resources/ex.php4?item=j707/ransbury.java

and the other examples in that area of the site as a starter. and that may help you.

Finally, and slightly reluctantly, I have to decline to offer free ongoing support via email to students who ask me for help - especially where I'm given a time limit. It feels a bit like having a gun held to my head. I just don't have the time, the answers to be good are all "one off", and so it's inefficient for me in terms of writing for a bulk of readers, and I'm often off line for a period and couldn't be relied on anyway. I suggest that you follow up your Java through the examples on our site that I have pointed you towards, through the resources that should be provided for your course, and (if you need) through forums such as ours at http://www.wellho.net/cgi-bin/opentalk/YaBB.pl

And all the best in your studies of Java!

Graham

Posted by gje at 07:08 AM | Comments (0)


Related topics: via article database

November 26, 2007

Looking after you Christmas Customer Crowds

A Christmas shopping trip to Swindon yesterday ... and so many chances to see how others do the "customer service" thing, with more lessons learnt on what to avoid than what to emulate!

Our initial stop in a big chain of computer stores, where we have a business account; just a few odds and ends needed, but what a struggle to work the system which involved noting down information from one screen on a piece of paper, and re-entering it on another screen. Then the system (or rather one of them) exited unexpectedly and the whole thing had to be done again ... except that the crash had locked access to the stock saying it was "already allocated". Moral - if you must have a system this complex, set it up so that you can handle customers efficiently and deal with issues when they're done

The shoe store - the one who advertises that they've done away with "Shoe Rage" - have an excellent stock up to size 8. And it gets weaker at size 9. So if the 8's don't quite fit ... you can see the new shoe rage as the ones you want aren't available in your size. Select second best, and stand in a long line at the till for one checkout assistant, while another till is being used, it appears, for data entry by the supervisor who is chatting with one of the other staff. Moral - If it's beneath you as a manager to serve your ordinary customers, at least don't antagonize them by blocking a till - do your data entry and staff interviews in your office.

The Hamburger joint - service much more efficient. But I do wonder about their play area, with the sign that says "we have strived to give you the safest possible play area" ... around a depressing high-fenced area just outside the store, with a rubber floor but not one single piece of play equipment. Moral - you can take safety just one step too far and look very silly by doing so.

The buzz of Swindon's town center was a pre-Christmas crowd and an Italian Market on Canal Walk (walk where the canal used to be!) gave a great atmosphere. A gift, card and party store showed us that "New Shoe rage" isn't limited just to shoes - one assistant serving, others doing what were admin tasks being on the tills which, surely, could have been left until the queue that snaked up the aisle had been cleared.

And so on to Hawkin's Bazaar - a real "scrum" where we we buying around a hundred pounds worth of stocking fillers. Tripping over others, steering around the checkout queues, but I have to admit it was fun. Some items previously selected on line couldn't be found, so not all a "bed of roses" but I noted that the young and cheerful staff work working the tills, then when the queue had been busted were stocking shelves and helping customers. I felt a little guilty about asking one of them about a two pound pack of pencils, and a couple of other things, but she happily took the queries and had them fixed (a couple of "out of stock"s and a couple of "online only"s) and a couple of "they're here" items to help us. And at checkout with a LONG ribbon of a checkout role ... took only a half the time of our 3 items at the PC place. Moral - a cheerful and efficient staff who put themselves in the customer's shoes and deal with issues can be ruddy magic!

We're back in Swindon on the Santa Special next Saturday. Now - can I find an excuse to visit Hawkin's?

Posted by gje at 01:15 PM | Comments (0)


Related topics: via article database

November 25, 2007

Using English can slow you right down!

When you're programming and you assign a variable, that's usually a single result. For example (we're talking Perl in these examples)
$position = $record % $pagelength;

However, there are often side effects of an action which you might want to make later use of too. For example:
$postcode = ($pc =~ /^[A_Z]{1,2}\d[A-Z0-9]?\s/);
will return a true of false result into $postcode indicating whether the string in $pc starts in the correct format for the first part of a UK postcode ...but you might also want to know what the actual string that matched was, and what was left of the incoming string that's not matched by the regular expression. Perl makes this easy for you - if you know what they're called, you can refer to other special variables in your program that contain these resultant side effects.

These "side effects" are a feature of real life too. If I tidy up my office it results in a neat desk. And the side effects include a full rubbish bin and also a box for recycling!

Three of the special variables used in regular expression matching are $`, $' and $& (yes, not the normal rules for variable names). They provide the bit that matched, the bit before the match, and the bit after the match. There are a whole host of others too - both on regular expression matching and many other aspects of what happens when Perl runs - you have $. telling you how many lines yoiu have read since tou opened a file ... $$ telling you your process ID, $^O for your operating system's name and so on.

You can get mighty confused as to what's what if you're new to Perl so there's an additional module supplied with the standard distribution called English and you can call it in with
use English;
giving you extra variable names such as $MATCH and $POSTMATCH and $OSNAME which make you code much more readable.

There is, though, a sting in the tail. If your program is going to use $' $` or $& anywhere in the code, then Perl has to save out the extra variables for every regular expression match it does - even those which are nowhere near the use of those special variables. And that means that if you are matching repeatedly against a very long string, it can have a serious effect on performance to use them. The English module provides aliases to $` $' and $& and in doing so it makes reference to them - thus triggering any Perl program that includes a use English; to evaluate them at every match with this potentially huge loss of efficiency at run time

It's a bit of an "old wives's tale" that English slows you down, so I've written a very short benchmark to show what happens:

$sample = "abcdefghij" x 1000;
$longer = ($sample . "12345") x 1000;
$evenlonger = ($longer . "zzz") x 10;
print (length ($longer),"\n");
@taken = times();
print ("@taken\n");
 
for ($k=0; $k<100; $k++) {
   if ($evenlonger =~ /5z/) { $lc++;}
   print "$lc\n" unless ($lc % 25);
}
@taken = times();
print ("@taken\n");

And that took about 7 seconds of cpu time:

earth-wind-and-fire:~/nov07 grahamellis$ perl tidemo
10005000
0.88 0.7 0 0
25
50
75
100
6.54 0.71 0 0
earth-wind-and-fire:~/nov07 grahamellis$

Adding in a single extra use English; at the top, without even making any other changes like using the names at all in my own code, I got:

earth-wind-and-fire:~/nov07 grahamellis$ perl tidemo
10005000
0.89 0.73 0 0
25
50
75
100
25.8 28.2 0 0
earth-wind-and-fire:~/nov07 grahamellis$

So that's around 53 seconds of cpu time rather than the previous 7.

I always wondered why English seems such a slow way of communicating ;-)


Posted by gje at 08:06 AM | Comments (0)


Related topics: via article database

November 24, 2007

Christmas is coming very early

It's that time of the year when Melksham's Spa Houses appear from behind the trees where they've been hiding all the year ...

... and thoughts turn to Christmas presents ...

... although not actually for us. "We have 33 children" says Lisa - not words I expect to come from her mouth, but rather we're helping Santa choose gifts for the children who are coming on the Santa Special train next Saturday.

Actually some of those presents look rather like fun.

Posted by gje at 09:55 PM | Comments (0)


Related topics: via article database

November 23, 2007

Reading a file multiple times - file pointers

When you open a file for read, you create a "file pointer" which knows where in the file you are, and each time you read from the file this advances so that you get the next piece of data each time you do a read. Usually you don't see the file pointer at all - it's internal - and you think nothing of it as it behaves in a natural way.

There are, however, times that you want to manipulate the file pointer differently. For example, you may want to re-read the file a number of times from the beginning, or even randomly jump around the file. Closing and re-opening the file will let you start again at the beginning, and most languages offer a functions such as seek which will let you move around with more control.

Here's an example in Perl - I have two files to read and I want to take each line in turn from the first file as a heading, then report on each line in the second file that has the same number of space separated fields in it. Here's my first (incorrect) attempt:


open (FHA,"f1");
open (FHB,"f2");
#
while ($line = <FHA>) {
@fldsin = split(/\s+/,$line);
$count = scalar(@fldsin);
print "\n=======$line";
#
while ($line2 = <FHB>) {
@fldsin2 = split(/\s+/,$line2);
$count2 = scalar(@fldsin2);
print $line2 if ($count == $count2);
}
}

And that's incorrect because it only reads the second file once. If, however, I move my second open statement within the first loop, I'm resetting my file pointer each time and get the results I want:


open (FHA,"f1");
#
while ($line = <FHA>) {
open (FHB,"f2");
@fldsin = split(/\s+/,$line);
$count = scalar(@fldsin);
print "\n=======$line";
#
while ($line2 = <FHB>) {
@fldsin2 = split(/\s+/,$line2);
$count2 = scalar(@fldsin2);
print $line2 if ($count == $count2);
}
}

Here are the results:

earth-wind-and-fire:~/nov07 grahamellis$ perl lls
 
=======First line
Perl Programming
Ruby Programming
Python Programming
 
=======This is the second line
 
=======Third line
 
=======A fourth line
earth-wind-and-fire:~/nov07 grahamellis$ perl lls2
 
=======First line
Perl Programming
Ruby Programming
Python Programming
 
=======This is the second line
Learning to Program in Perl
 
=======Third line
Perl Programming
Ruby Programming
Python Programming
 
=======A fourth line
Object Oriented Perl
earth-wind-and-fire:~/nov07 grahamellis$


The purists will point out three things to me about this code ;-)

Firstly, they'll say I should have closed my files each time I had finished with them.

Secondly, they'll say that I should have checked the return status from my file opens to ensure that they really worked

Thirdly, they'll say that I should have read the whole of the second file into a list just once and processed it from there.

For a running program ... they're right, right and usually right ... but for a spike solution / demonstration of the principles of file pointers, I think my example makes a short and elegant example!

Posted by gje at 11:33 PM | Comments (2)


Related topics: via article database

November 22, 2007

On cancellations, rebooking, and pricing schemes

Lisa forwarded me an email describing how travelers are booking their hotel rooms well in advance, then canceling them at the last week or so if they see a special deal or suspect one from a major chain, and rebooking at the lower price. The article went on to say how the bigger hotel chains are less worried than the smaller independents, who resent the practice.

There is a need for differential pricing at times - to fill facilities in the lower season / quiet times of day, and to maximize revenue at other times so that the books as a whole balance or make an acceptable level of profit. But my experience of many systems is that they create anomalies, they get out of hand .... and they should only be set up with extreme care. Otherwise, they end up "turning off" the customer, cause the provider to give a lower quality service to his cheaper customers, and leave the full price payers feeling very hard done by.

I've no big solution to offer. I can offer a principle which we apply that says "keep it simple, consistent, fair and easily justified" but my goodness - even in our business - there are times that it's hard to stick to your guns on such an approach.

Posted by gje at 11:25 PM | Comments (0)


Related topics: via article database

November 21, 2007

Useful command or messy screen?

I was writing a file the other day - a "Perl Object Oriented" course specification. Only when I looked back at my screen having cut and pasted it various times did I notice that my screen was covered in

cat poo

Posted by gje at 06:09 PM | Comments (1)


Related topics: via article database

November 20, 2007

Linux / Unix - layout of operating system files

At the top level ..

Typically "read only"
bin - binaries - executable programs
sbin - system admin binaries - programs for the system / admin
lib - library files (needed by binaries and shared between them)
usr - the bulk of the operating system (the bit that is not needed to boot)

Typically "read write" by admin or system
dev - device files (how devices are handled)
etc - config files, startup files, etc
proc - "everything is a file" in 'nix - these are the current processes
var - read/write area for OS utilities / daemons

Open Season!
home - User's home directories and typically data areas
mnt - Mounts of discs from other computers (also media)
tmp - scratch area for anyone / everyone

In /usr - this is where parts that are NOT needed at boot up time are kept
bin - binaries - executable programs
sbin - system admin binaries - programs for the system / admin
lib - library files (needed by binaries and shared between them)
include - "Programmer's header files"
share - things common between architectures
etc - config files, startup files, etc
src - source
man - manual
local - local enhancements to OS - i.e. extra software you load (also /opt)

In /usr/local - this is where your own local additions are kept
bin - binaries - executable programs
sbin - system admin binaries - programs for the system / admin
lib - library files (needed by binaries and shared between them)
include - "Programmer's header files"
share - things common between architectures
etc - config files, startup files, etc
and others which are complete apps

In /usr/local/apache2 (for example) - this is within a particular open source product
bin - binaries - executable programs
lib - library files (needed by binaries and shared between them)
logs - log files
man - unix man pages
modules - extra code modules (similar to lib)
conf - configuration stuff
in this case ... web site at htdocs, icons, cgi-bin, manual etc

Ever wondered why the executables are mixed /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/apache2/bin, /usr/local/java/bin and so on ... perhaps the table above helps explain it a bit!

Posted by gje at 12:12 PM | Comments (0)


Related topics: via article database

Useful link: Linux training

Copy and paste / cut and paste and other vi techniques

* If you want to duplicate a line, you can yank it with Y into the default yank buffer, then move your cursor and push it out with p or P to push it after or before the current line.

* To move a line, delete it with dd which puts it into the yank buffer, then push it with p or P.

* The number of lines to be yanked or deleted can by typed in before you Y or dd and vi will yank or delete that number of lines.

* If you want to remember whereabouts in your text you are so that you can come back later, you can drop a marker - ma will set a marker "a" and you can return to that marked line later using 'a - that's a quote followed by the marker name.

* The %command will jump the cursor to a matching bracket

* J joins 2 lines together

* and :e![cr] says "I made a right mess of that - abandon my changes and re-read the input file

Posted by gje at 01:11 AM | Comments (2)


Related topics: via article database

November 19, 2007

Above the fold with First Great Western

"Do you realise that people aren't finding you on Google and the other search engines." I get a lot of emails like this, which go on to tell me how Well House Manor only turned up on the fourth page when the person writing searched for "Comfortable beds" or how Well House Consultants only turned up after number 99 when searching for "listed florists". Position and placement is important ... but only for the correct search terms which these are not. The fact that we come up in the top couple of pages for Birth Notice is almost a joke and I'm quite happy for us to drop further on that (we were once top!).

But it IS important to be Above the Fold for the search terms that people will enter when you want them to find you. And by "Above the Fold", I mean that your URL should be visible on the first page, and without scrolling. So that's in the first 6 to 8 results ... and it can be a never ending task to ensure that you're going to stay there. On some searches we succeed, on others I'm not thrilled with our placement. But I was happy to see that even away from the very specialist areas we're in we can make some high rankings with other pages

We're above the fold for "First Great Western" with our First Great Western Customer Forum site.

Posted by gje at 07:38 PM | Comments (0)


Related topics: via article database

November 18, 2007

A little touring help during a business trip to England

Helping visitors to Melksham who are staying with us to see a little bit of the surrounding area ... we're encouraging people to ask, as we love to help - and to help people see what they want and stay in their comfort zone too.

"Many guests at Well House Manor are in the town on business, and are often on their first visit to the UK - so it's no surprise that they'll want good advise and guidance on what to see and how to get around while in the area.

We are very happy to offer you suggestions for evenings out, for half day trips, and for longer excursions too - and with a little prior notice we arrange bookings and/or an escort for some of your trips. Our team includes members from North America, Africa and mainland Europe as well as from the UK, and we all love the area and want you to enjoy it to its fullest while you're here.

Please ask any of our team for initial information, and that team member will pass you on the most appropriate person for your individual needs."

Want to know where they are? I've been labeling up pictures ... here and here and here and here and here and here!

Posted by gje at 03:24 PM | Comments (0)


Related topics: via article database

Object Oriented Programming in Perl - Course

Perl Review (module P251)
Subroutines in Perl (module P209)
More than Simple Lists and Hashes! (module P217)
Object Orientation: Individual Objects (module Q906)
Creating your own Classes (module P213)
Object Orientation: Composite Objects (module Q909)
More Objects (module P218)
Object Orientation: Design Techniques (module Q907)
Using SQL Databases from Perl (module P308)
Handling XML in Perl (module P668)
Perl 6 Look Ahead (module P256)

2 days for experienced Perl Programmers who are new to Object Orientation ...

Venue - Well House Manor, Melksham, Wiltshire

With our modular system of courses, and with all of our courses being based on our own material, it's very easy for us to provide a tailor made agenda to meet your requirements. Very often, these special requirements are so "one off" that they're really only meaningful for a single client, but sometimes they're of much more general interest - such as this one described above

"Object Oriented Programming in Perl" is likely to run on 13th and 14th December - if you already know Perl quite well, but aren't really into the Object Oriented side of programming, it would be a great opportunity to learn for a couple of days at £350.00 + VAT per day. If you come across this description in the archive - after 13th December 2007 - please email me (graham@wellho.net) to ask on the current status and you may find it's running again!

Posted by gje at 01:22 PM | Comments (0)


Related topics: via article database

Useful link: Perl training

November 17, 2007

Market survey - to learn, to prove a point, or to sell your product?

You can do a market survey to learn about your market ... or a market survey to prove your point ... or a market survey to generate interest in the issue on which you're doing your survey. And unless you're totally disinterested in the subject on which you're surveying, it's all too easy to bias your survey design and implementation towards producing the results that you want, whatever your intentions.

We lunched yesterday in a cafe in Melksham. It's a regular haunt; works well for us because of a wide range of light meals available, and the chance of a five minutes walk on a nice day rather than staying at one spot throughout the whole course. And a gentleman was going around tables, asking questions of the customers; as each new customer group arrived and ordered, he spoke with them. And clearly welcomed officially by the people running the place. Yet he carefully avoided approaching our group of four men, and another group of working aged men while concentrating on the pensioners and mums with young kids who formed the rest of the clientèle.

I know the staff a little, and I asked the lady whom I paid what the survey was about - "we're talking to our customers and seeing if we provide what they're looking for - seeing how we can improve things". A noble objective, and something we strive to do to. But a lesson also in how to tell one of your regular customers that he and the people he's with don't fit in - that the requirements and thoughts of the working age male don't actually matter, as they're not really a part of the business plan.

So I'm going to suggest that the survey may reveal some interesting ideas. It will probably prove what it was intended to prove in the first place (due to poor sampling methods), and that it has also effected the market that it was asking about by marginalizing some of the customer base.

It's all too easy for me to look and criticize, and also all too easy for us to make the same errors when we take note of customer inputs or run surveys. Yet we're perhaps just as guilty at times - looking at inputs from our customers with rather more care than inputs from those who inquire but who don't book because of the lack of a facilities for children, or of a full cooked breakfast, perhaps. But then we have only limited rooms and can't be all things to all men and women. We should concentrate on doing a really excellent job in our chosen market and not in trying to serve all the markets. Perhaps our local cafe is telling us, truthfully but unintentionally, that they don't really want our business and we should go elsewhere?

Posted by gje at 11:38 AM | Comments (0)


Related topics: via article database

November 16, 2007

Linux, PHP, Tcl, Ruby, C, C++ - last minute training course availability

Here's a schedule of our public courses from now until Christmas.

Linux Basics - 19th November
Linux Administration - 20th November
Linux Web Server - 22nd and 23rd November
Technology for PHP - 26th November
PHP Programming - 27th to 30th November
Tcl - 10th to 12th December
Ruby - 13th and 14th December
C Programming - 17th and 18th December
C++ Programming - 19th and 20th December

Perl, Java, Python and Apache httpd/Tomcat start next in the new year.

This is the time of year when bookings are at their quietest and the diary tends to get moved around to make sure that people get the training they want when they want it - so you may see a few changes in the list above from the original schedule we published.

If this last minute notice of courses for 2007 tempts you, let me know ... I can take bookings for the tail of this year's program at 250.00 plus VAT per day's training, or 300.00 plus VAT to include accommodation too.

Posted by gje at 07:48 AM | Comments (0)


Related topics: via article database

Useful links: Linux training, Ruby training, PHP training, Tcl training

November 15, 2007

Wiltshire County Council - Budget Consultation

Last night, I attended a Wiltshire County Council Budget Consultation meeting hosted by the Wessex Association of Chambers of Commerce.

The meeting was billed as "an opportunity to meet the leader of Wiltshire Council [Jane Scott], the Chief Executive [Keith Robinson] and the county's chief financial officer. You will hear about the council's plans and have an opportunity to say what you think should be priorities for the council."

Sadly, Jane Scott who was the only one of the group who is an elected representative pulled out and there wasn't an alternative cabinet member there, so we were left with the paid employees of the county - a great shame, as they were very very much in a "we will tell you how it is" mode. Truly, there was an opportunity to state the case of what we thought should be given more prominence, but judging by the way old hands at this annual meeting were commenting ("we have brought this up for each of the past two years and yet you still come along to the meeting not properly prepared to talk about it properly / no further forward than last year") that's the limit - a chance to say what we think the priorities should be, but it will go no further than that.

What were the big subjects from the floor?

Firstly, there was waste disposal, and in particular business recycling where the system is set up in such a way that it makes it very hard indeed for small businesses to get things like cardboard into the recycling path. The county's officers were telling us that they can't help because of refuse limits / landfill taxes etc, but I remain puzzled as to how they think landfill tax is a problem on material that is for recycling.

Secondly, there's a business rate precept coming in in a year or two's time, the idea being that the local council can charge their own extra to get some money to help develop business. However, the extra money is not ring-fenced in any way and there's a concern that it will form a useful slush fund - perhaps it could help fill the county's shortfall in its pension fund (15% underfunded) or help fund the SAP system they're about to buy / implement across the new Unitary authority?

Thirdly, Transport. And, no, I was not the first one to raise this! Major concerns at Corsham as to the access to major new employment areas. Major concerns about removal of X4 / X5 bus services, and concerning the virtual elimination of bus services to Mere. And, yes, I did ask about practical services to and from Melksham, and linking Chippenham to Trowbridge and Salisbury for those who don't have cars or who (more and more) prefer the greener alternative but don't have the time to spend on the remaining buses.

The (proposed?) budget for public transport for the next year is 17 million pounds. According to Sandra Schofield, the chief financial officer, that amount is a political decision. The lion's share of that budget is for getting school children to and from school; most of the rest is bus projects / support. The rail support budget is zero. "You know that already" says Dr Robinson rather testily; actually, I didn't - I know it was zero this year.

"No doubt I will read about this on your blog" said Dr Robinson. Dr R, I'm delighted that you're reading this and perhaps taking note and being aware of what's being said. It's one of the good signs from last night as it shows a degree of local input being noticed.

And it was good to listen to some of the background behind the county's 620 million pounds per year spend / 100 million per annum wage bill and to know a little more as to where it goes. To realise that it costs 53000 per annum for each school place for a child with learning disabilities, and how modern medicine is increasing the numbers of such children year on year; the budget rises from covering somewhat under 300 last year to 314 this.

I took the opportunity to pick up copies of the annual report and corporate plan which I'll be reading through in more detail; although there are limits as to what the council can and can't do, there are some areas / things that I wasn't aware of, and I suspect that the typical resident whom they serve doesn't realise either. It may be that such things are properly delegated by the residents to the council ... or it could be that the council is acting in spite of what the residents want in some situations. Certainly from my own (transport) experience, and listening to the others in the audience last night, there's a question to be answered there.

Please, WC, a movement of the transport budget towards encouraging an integrated system that lets people travel practically if they have no car or no desire to use a car. It's not really a big deal - just an adaption to meet changing needs and times. Petrol is a pound a liter now, and I've seen suggestions it may double in the not too distant future. In these new circumstances, pulling back just a few or those millions from road building and getting people traveling quicker and greener instead makes such huge sense.

"We want to invest to save" said Sandra Schofield. Yes, please.

Posted by gje at 07:46 AM | Comments (0)


Related topics: via article database

November 13, 2007

Getting the community on line - some basics

We're very much involved at the high-tech end of internet programming and web site development and training. But it's really good for me good to see the other end of the spectrum, from time to time, and an hour's seminar at Chippenham Library last night, run by the local community web team, was an ideal opportunity. And always being one to make double and treble re-use of time, it's also a chance for me to see the background of how we should be putting our own community pages together ;-) - Community page for Save the Train

It comes as a useful reminder to me ... when putting HTML / pages together to tell people ...
• that an <h1> tag is a big headline and an <h6> is small, not the other way
• that color is spelt WITHOUT a u (groans when our presenter said "must spell it the American way")
• that once you've uploaded an image to your web site, you can turn your computer off and even disconnect as people don't have to get it from you each time
• that the <font> tag is deprecated.

I'm also reminded
• that you can put a W3C logo on a site even if the pages are not W3C compliant
• that even community lead, local authority sponsored web sites don't necessarily conform to the DDA act or the laws on having mailing lists that offer users an unsubscribe option
• that every site with a login for "Joe Public" needs a forgotten password script
• that projectors should be adjusted (angle and keystone and focus) before a presentation.
• that people want to be able to upload pictures, video clips, and soundtracks.

Actually, our presenter did a good job of showing us around the Wiltshire Community Web site as potential content providers.

Posted by gje at 10:54 AM | Comments (0)


Related topics: via article database

November 12, 2007

Integer v float - Python

If you had f failures in s samples, what proportion failed? .6666666666 you might correctly say - but Python might not come up with that answer if you have two integer counts

>>> s = 6
>>> f = 4

And that gives:

>>> f/s
0

Will that be better if we turn it into percentages?

>>> f*100/s
66

Yes - somewhat better but still inaccurate - the real solution is to convert one of the operands into a float:


>>> f*100/float(s)
66.666666666666671

Posted by gje at 04:26 PM | Comments (0)


Related topics: via article database

Useful link: Python training

November 11, 2007

Remembrance day - inside a church and inside the day

I remember how bored I got at school at the end of term Church service - we all shuffled across the road to St Nic's and listened to Rev Ogilvie - who was a nice and earnest man, and great in a pastoral role. But listening to him and to the head have us sing songs with words I found - even in those days - difficult to identify with left me longing for the end of the service. Yet it taught me patience - the ability to bite a task or time into a series of shorter and more acceptable pieces, and to see patterns and beauty in the mundane such as how a hymn is laid out and how things come back to the same chorus.

As a parent, attending the Minster church in Warminster for similar service clearly had even less impact. Every term, thanks was given to the school founder who was - I have no doubt - a pious and wonderful old boy, but it was done in such a way that it passed me by completely and I found it hard to understand the services - starting to see them, in some ways, as a form of indoctrination where if the same thing was said and sung, with the same melody and in a larger group of peers and seniors, that the younger / junior members might come to accept and believe it even if it stretched patience and credulity. But of course, that's just my opinion and I'm sure others wouldn't share such a view ... or would they.

We were in St Michaels and All Saints in Melksham today - packed for the remembrance day service, and being slightly late arrivals (with the official group to represent the local Chamber of Commerce), we were far forward (yikes! front row!). And around us a number of old soldiers - gentlemen who have done brave things that I would not be brave enough to do, seen things I would never wish to see, and done it with all of their hearts believing in a cause. I admire them; and I was yet further heartened to hear their spirit as they questioned the prayer for the president of the USA, and encouraged the vicar (who was thinking carefully about each word before uttering it) to accelerate a little. "Get ON with it" were the words, I think!

The mixing of State and Church on such a day has also become less comfortable to me over the years. I regret that prayers imply the support for only the British troops fighting the British cause - leaving out the Poles and the New Zealanders and the Americans who were beside us in the last World War and other wars, leaving out any words for the soldiers fighting with equal earnestness for the opposing cause. I confess to being, frankly, shocked when the vicar raised the subject of the atomic bombs dropped on Japan, and used it to lead in to berate the Japanese for not offering a full apology for the atrocities THEY committed against prisoners in Burma. I wasn't around at that time, but from what I know some regret should also be expressed at the dreadful loss of civilian life cause by our side at Hiroshima and Nagasaki.

But I can live with that shock and discomfort on a day like today. Lisa and I were honored to be able to lay a wreath at the war memorial - in respectful memory of all the people who died for their cause in wartime or as a result of war. And their sacrifice, let us remember, was not in vain. Just Friday night, I took a phone call concerning the best way to press forward with the development of the train campaign and my contact commented that "we wouldn't have been able to work like this in times gone by". Actually, his words were stronger and the implication much stronger yet; and that freedom that we have, though sometimes we don't notice it, was nurtured and survived because of the sacrifices of so many that we remembered today.

Posted by gje at 09:28 PM | Comments (0)


Related topics: via article database

Travel Across Wiltshire - the game

What better way to learn about efficient public transport than to play a game to get you around from one place to another? And what better way to generate a new Tk canvas example, and a new PHP page too, than to prepare such a game on our web site.

The board looks like this:

If you select this link you'll get a full board, the rules, and your selected start, end and via points all on a single web page.

Other links Wiltshire Resources - PHP source for the web page and Tcl/Tk Canvas creation cose

Posted by gje at 09:34 AM | Comments (0)


Related topics: via article database

November 10, 2007

Arrays in Tcl - a demonstration

# Array in Tcl
 
set town(Wycombe) 120000
set town(Marlow) 32567
set town(Amersham) 17000
set town(Melksham) 24000
set town(1) xxxxxx
set town(1.) yyyyyyy
 
# Note that you CAN use numbers as subscripts but you
# must be careful because element "1" is different to
# element "1." ... or element "1.0"
 
set place Oxford
set town($place) 140000
 
# Note - need to be careful as to whether to put a $ in
# front of the array name, the subscript, both, or neither
# as all rour options are valid in the right circumstance
 
puts "Please choose a town "
set said [gets stdin]
 
if {[info exists town($said)]} {
puts "$said has a population of $town($said)"
} else {
puts "dunno"
}
 
set keylist [lsort [array names town]]
foreach said $keylist {
puts "$said has a population of $town($said)"
}

Posted by gje at 08:14 AM | Comments (0)


Related topics: via article database

Useful link: Tcl training

Buffering up in Tcl - the empty coke can comparison

A comment on buffering in Tcl ....

if {1 == 0} {
When you finish drinking a can of Coke, you don't call
your local recycling plant up straight away and have them
send a truck around to collect the empty - that would be
inefficient to put it mildly. And in the same way,
a computer doesn't always save its output character by
character to the disc or screen - rather it buffers it up.
In most languages a clever strategy controls when the buffer
really is written (flushed) so that it's not very common for
the programmer to have to add an explicit flush request.
 
With Tcl, the default is that the output buffer flushes
each time it receives a new line character, which works
well enough most of the time. However, there are occasions
that you'll want to use the -nonewline option to puts to
allow you to generate a prompt and leave the cursor hanging
on the same line awaiting input from the user, and in such
cases you'll need an extra flush command.
}
 
puts -nonewline "How old are you "
flush stdout
set age [gets stdin]
puts "You are $age years old then"
 
if {1 == 0} {
Where you have multiple user inputs, you may prefer to
use a proc to read inputs and encapsulate the flush within
it, or you may prefer to run
 
fconfigure stdout -buffering none
 
which (technically) turns autoflush mode on rather than
turning buffering off!
}

If you want to comment a whole block of code .... you might like to use my little trick of testing for the impossible - "1 == 0" in the above - which lets you put code aside neatly, cleanly and nested. You'll see that I've even used it to provide documentation for today's entry ...

Posted by gje at 06:33 AM | Comments (0)


Related topics: via article database

Useful link: Tcl training

November 09, 2007

Melksham v Ely

From Ely last weekend - some things that we could learn for our town? Some of these things are being talked about already, some may be longer term, but I suspect that all are practical.

* A train service that's vibrant even though the station is on the edge of town and in amongst some industry

* Free car parking

* Premises that back onto the town's car parks as well as the main streets

* A lively water front

* Pedestrianized areas

* Historic Vistas

It struck me that there's far more of a valid comparison possible than I would have expected. In Ely, although it's technically a City, you're looking at a SMALLER place than Melksham. Melksham is in a tourist area but has not pushed its tourist credentials ... Ely is very much "tourist" because of the Cathedral BUT there were hardly any tourists around last Saturday when it was thriving an busy.

Posted by gje at 09:19 PM | Comments (0)


Related topics: via article database

November 08, 2007

Closer than you think - the next step

"What's the next step in your campaign?" asked the lady from the local paper when she called to check up on a [train] story last night. "I'm meeting the Labour Party candidate for the new Chippenham seat in about an hour and 20 minutes" was my reply ... and I suspect that she was expecting a less immediate answer!

I'm getting to feel something of an old hand at this campaigning business - when I started, Wessex Trains were in charge and then First Great Western, headed by Alison Forster, were the people who run our service. Now First Great Western is headed by Andrew Haines, with John Curley as the route director, and I understand that those appointments are regarded as medium rather than long term. On the political side, Derek Twigg has given way to Tom Harris, and Alistair Darling to Douglas Alexander to Ruth Kelly. Our own constituency boundaries have been redrawn, and from a solidly blue Michael Ancram (who is, however, still our representative in parliament), we're now looking at (in alphabetic order)Wilfred Emmanuel-Jones, Duncan Hames and Nicklaus Thomas-Symonds as our prospecitive candidates for the Conservative, Labour and Liberal Democrat parties. Our West Wilts District coucillors were "all change" in May, and the government has decided that the whole district council tier is to be abolished in Wiltshire in the next year or two ... at which point we'll have fresh elections for Wiltshire Council ... with a new set of wards to be contested, doubling the number of representatives.

It can be frustrating! To establish a case / a rapport with one contact / come to understand one organisation, just to have it replace by another. And be back, to a great extent, to ground zero and having to explain, once again, that Melksham is no small village but actually a sizeable town from which people commute to Swindon and really want to work an 8 hour day like the rest of the population ...

I've grown to be a bit of a cynic at times, and I find myself wondering if one of the reasons that First have put in a new management team is to toughen the stance to people who are looking for appropriate standards of service rather that the minimal level that First's customer, the Department for Transport, has requested. Change is an opportunity for the new Andrews and Johns to test the waters previously tested by the Alisons and Glendas, and see if reductions and changes that brought howls of protest still bring those same howls, or can now be quietly eased in with the change.

But along with this cynicism comes a realisation that there's an opportunity at change too. Last weekend up in Ely, I listened to xxxx talk about the successes of the Cotswold and Malvern line group, and to Robert Stripe talk about the Fen line to King's Lynn in East Anglia. Goodness - he's been involved with that group for a long time, but you can see a town with a 57,000 population and a train service that has risen from 5 a day to 23 and that's an object lesson to us all.

New he may be, but I enjoyed talking with Nick last night; like Duncan and Wilfred, he's very much in favour of pushing for the return of an appropriate service, and he is planning to make representations on our behalf. Much appreciated. And it turns out that he's very much a customer of First Great Western, travelling up through Swindon to Didcot where he changes for Oxford on a regular basis. Ah - it's a small world and there are some of the apsects / players who needed little introduction.

Posted by gje at 06:11 PM | Comments (0)


Related topics: via article database

November 06, 2007

MySQL - table design and initial testing example

"Examples are either simple as to be trivial, or too complex to understand" said a delegate - so this afternoon I accepted his challenge to come up with some thing in between. And the example is for some MySQL table design and design testing, with a Perl program to access and tabulate the data.

Scenario - A table of CUSTOMERS each of whom has a number of order REQUESTS each of which includes a number of line ITEMS. (3 tables so far!) A table of STORES each of which has a number of AISLES, each of which has a number of different PRODUCTS on it. That's six tables now. The items table contains a product id column, so that all the tables can be linked together.


Customer, request, item tables


Store, aisle, product tables

# Note - all fields start with same letter in each table
# Note - all tables have a unique id field
# Note - all tables first letter in unique
# Note - all table names are singular
# Note - sample data includes 2 records at each level so
# that we can test the dynamics but keep it as simple as poss
(Don't you love comments - those come from the test file!)

Here are the results of various reports:

Here is the "base" query behind all the joins and reports:

select c_name,p_name,i_count,p_price,a_name,s_name from
((store
join aisle on sid = a_sid)
join product on aid = p_aid)
join
((customer
join request on cid = r_cid )
join item on rid=i_rid)
on pid = i_pid ;

and you can see all the code used here. The output is here.

Finally - the Perl program's source is here.

Posted by gje at 04:35 PM | Comments (0)


Related topics: via article database

Useful link: MySQL training

November 05, 2007

Wiltshire - speaker / after dinner talker offer

Looking for a speaker? If you are an organizer of talks and lectures for groups such as
* Rotary, Round Table, Probus
* Federation of Small Businesses, Chamber of Commerce, CBI
* Women's Institute or Townswomen's Guild
* Parish and town councils, senior schools and colleges
* Access groups and specialist interest groups?
* After Dinner talks
I may be able to help you - and you help me raise the cause of the "TransWilts" train service linking Southampton and Salisbury, via Warminster, Westbury, Trowbridge and Melksham to Chippenham and Swindon.

On Saturday, I spoke to an audience of over 120 people at a National Conference, and here is a review ...

Dear Graham,

Just a short note to express the considerable thanks of our organising committee for your superb contribution to the proceedings at the Maltings yesterday. My memories of Railfuture events is of generally lack luster, content-light delivery. Not so yesterday. You were yet another enthusiastic, dynamic speaker who delivered substance...and to time! For this we are immensely grateful. It was also wonderfully encouraging to have a speaker who understood rather more than me about computers....and had the good taste to operate one of those beautiful AppleMac laptops.

Even from the initial feedback, it is pretty obvious that most people felt very enthused and positive about the proceedings. So,again, my thanks for your immensely valuable contribution to the proceedings.

With best wishes (especially for the persuasion of FGW into better behavior!)

Chris

The issues are of immense local interest, with the proposed Westbury bypass in it s current form likely to relieve Westbury at considerable expense but lead to traffic jams at other locations up and down the corridor, while at the same time the parallel railway has just two passenger trains a day.

Please email - graham@wellho.net or phone - 01225 708225 - to inquire.

My day job is lecturing / training, by the way - so I can assure you of an interesting talk tailored to your group!

Posted by gje at 08:22 AM | Comments (0)


Related topics: via article database

November 04, 2007

Castle Lodge Hotel, Ely, Cambridgeshire

I couldn't quite place the accent ... but it turned out that Leon came from Groningen, the largest town in northern Holland. In the UK for six months, his day job as a student is to be working on some sadly neglected clay pits / or natural water area just north of the town on Ely - that's where I am writing from. They're catching up on a backlog of work where trees have become so lopsided that they're dangerous, encouraging other wildlife such as otters, which already live nearby, to extend their territory into the place, and put in a few moorings for visiting narrow boats. But they have run into the NIMBYs, and the people who feel that conservation means "do nothing and leave it as it is". All the more heated as their place is an SSSI (Sight of Special Scientific Interest) with the only Kimmeridge Clay cliff in the area - a falling face with dinosaur bones being exposed that causes great interest.

There are always two sides to a story, and of course I only heard the one last night, seated at the bar of the quirky "Castle Lodge Hotel". But I can sympathise so much with Leon. It appears that the owner of the pits also owns the big marina in the town, and when asked to make a size estimate by the local press said "the space is the equivalent in size of a marina of 1000 boats". Which, alas, was read as meaning "We want to build a marina with 1000 boats ....". Leon assures me that actually they want to keep the place as is, and prevent anyone else building a marina on that scale - but it seems that they haven't convinced their opposition who it seems can't even be bothered to come along and learn about the plans, and are basing their case that shows heavy use already on a 3 day survey they did just after the place had a lot of TV coverage, counting some chap who says he comes to fish twice a day as 730 visitors per year as they reach their 90,000.

You could tell me that for the guy to compare the size to "A Marina for 1000" was foolish, and you could tell me that it must have been in the back of his mind when he chose that particular measurement. Maybe - or maybe a comment was taken out of context, and that's simply the units he thinks of.


I was comparing Melksham to Ely a week or two back as I prepared my train talk for today; this is being written wirelessless so I don't know when it will be posted - but I wasn't surprised to find this other comparison last night. After all, human nature is human nature, and you've got a town of around 16000 (Ely) and a town of around 24000 (Melksham).

"How many cars can you park without them blocking each other?" asked our planning application for No. 404 - our HQ and also home. "Twelve" we answered because - well, it was the truth if we used the grassy area, and it had been stressed to us that the highways folks would be concerned at any plans which left cars parked in the street. We never - not in a month of Sundays - intended to use all that space for cars but somehow we got read as "We will regularly have 12 cars here". How little did the protesters, the people who raised a petition against our plans and obstructed us at even step, realise just how small our footprint would be. At the peak of training at 404 it was rare to see more that 4 vehicles there and indeed there's so much space that we were able to replace the grass with more formal gardens that you certainly can't park on without a second thought.

Funnily enough (a humorless sort of "funny" though - "funny peculiar") the main protagonist against us is now firmly on side with our activities - anywhere from "null" on the hotel to protesting on our side in the case of the train service. I'm flattered but only half happy, fearing any statistical distortions which are used in our name.


As one does around the bar as it approaches closing time, we moved on to other topics with Leon - to the ebb and flow of guests in and out of the bar as they need a smoke, and to comparisons with smokey bars in the Netherlands. An excellent host for the evening, turning a strange place in a strange town to a night we won't forget it a while. It's the staff who make the memories of a place, and the customers who treasure those memories

Posted by gje at 05:32 PM | Comments (0)


Related topics: via article database

November 03, 2007

The Learning Perl crew, October 2007

All of our delegates are special, and 99% of them are a pleasure to teach - but I'll look back on last week's group with a particular fondness.

We've been open and running as a hotel now for a year, and - more and more - our public courses aren't just 9 to 5 events. Rather they're a chance to share code, and experiences and sit down together with a number of your peers in the evening too.

You may have noticed from the picture that Henry was in a wheelchair - and this lead us to provide evening meals at Well House Manor throughout the week; that's very much where we headed anyway for the business visitor who's perhaps had a hard day and really can't be bothered to go out, or the delegate who needs to grab a quick bite and get on with his day to day work in the evening.

Posted by gje at 02:12 AM | Comments (2)


Related topics: via article database

Useful link: Perl training

November 02, 2007

National Speaker - now to get the talk ready

A bit of a rush job as I prepare for a talk to over one hundred people on our "Train Campaign" tomorrow up in Ely - a National Conference. So please forgive just a brief post that points you to three URLs this morning.

The full talk
Summary sheet
Campaigner's Summary

Posted by gje at 09:25 AM | Comments (0)


Related topics: via article database

November 01, 2007

A Golf Club Decision - Perl to Java

There are times that Java is the right language for an application and Perl is the wrong one - to the extent that investment in a rewrite is correct. But they are pretty rare.

I was very disappointed to learn this week of a major company that is switching - not for technical reasons, but because of what one of my delegates described as a "golf club decision". Which was defined to me as a decision taken on commercial rather than technical grounds so that the big boss of company "A" - our new Java user - can play rounds of golf with the big boss of company "B" who are behind Java.

We'll teach you either!
Perl Programming
Java Bootcamp

Posted by gje at 10:13 PM | Comments (0)


Related topics: via article database

Useful links: Perl training, Java training