Thursday, January 28, 2010

I want an iPad

Apple have done it again, leapt ahead of the competition with the new iPad. Now I just have to find a business reason to justify buying one.

I can see a whole new market with the oldies and the computer phobes. This isn't a computer, just a simple of doing the essentials.

Want, want, want...

Wednesday, January 27, 2010

Dr Seuss and Copenhagen

Thanks to Tin Harper who started it and Bruce Darrell who forwarded it!

Monday, January 25, 2010

Using Pyparsing to extract dates from text block

This is very much work in progress, but I thought I'd post in case it helps anyone.

I'm currently using two bits of code, one to handle relative dates like "today", "2 days ago" and the other to handle specific dates like "3rd November 2009". These bits of code are building on work already done by others. I've tweeked them and added tests for parsing using parseString - expecting whole text to be a date, eg. "13th December 2009" and scanning using scanString where the date or dates is buried in the text, eg. "projects starts on 12th Nov 09 and finishes 3/2/10".

Relative dates:

Original code is in the Examples - In development on the pyparsing site:

Actual dates:

Sunday, January 24, 2010

Can you read this ok?

A good day for the terrsitros tadoy, wohse gaol atefr all is not to klil ppolee, but to sreapd trroer. The ppear and tv are flul of reotprs of the lteast inrasece in toerrr alret and all the mnay pisbosle rsaoens for it. And all the treisrort had to do was fial to klil a panle laod of peolpe and feed the mdeia. Are tehy vrey sarmt or are we vrey giulblle?

Stumbled across this blog and had to have a go myself

Our brains are so smart that we only need the first and last letters in the correct order to be able to make a very accurate guess at the word.

For a bigger challenge, read Iain M Banks, Feersum Endjinn, much of which is written phonetically, for example:

Woak up. Got dresd. Had brekfast. Spoke wif Ergates thi ant who sed itz juss been wurk wurk wurk 4 u lately master Bascule, Y dont u ½ a holiday? & I agr.

Have a go jumbling your text:

Saturday, January 23, 2010

Getting started with Pyparsing

Pyparsing is especially useful for those of us who don't use regexp enough to get any good at it! It is a deceptively simple parser for all kinds of text.

Here are a few resources and tutorials I found useful.

And here is my first program. The requirement is to decode an instruction into two chunks. An opening "o" or "-", followed by a mix of "?", "!", "&","^".

from pyparsing import *

def matching(list1, list2):

if len(list1) != len(list2):
return False

for key in list1.keys():
if (not list2.has_key(key)) or (list2.has_key(key) and list2[key] != list1[key]):
return False
return True

tests = [
('o?',{'status':'o', 'stype':'?'}),
('-!',{'status':'-', 'stype':'!'}),
('-!!!',{'status':'-', 'stype':'!'}),
('o?!',{'status':'o', 'stype':'?'}),

def handleStuff(string, location, tokens):

print 'string',string
print 'tokens', tokens, tokens[0][0]
return tokens[0][0]

status = Word("-o")
stype = Word("!?&^").setParseAction(handleStuff)

search = ZeroOrMore(status("status"))+ZeroOrMore(stype("stype"))

for (test, result) in tests:
print '---------------'
parsed = search.parseString(test,parseAll=True)
return_value = {'status':parsed.status, 'stype':parsed.stype}
print test, return_value, result, matching(return_value, result)

The bits I had to google a while for:

How to return named tokens.

If you did:

search = ZeroOrMore(status("myvar"))

and this is recommended above using setResultsName I believe.

then to get the return value:

parsed = search.parseString("My test string")
print parsed.myvar

The other question was what does setParseAction return and the answer is an updated token. See example above which returns the first character in the first token.

Results of the program are:

string o?
tokens ['?'] ?
o? {'status': 'o', 'stype': '?'} {'status': 'o', 'stype': '?'} True
string -!
tokens ['!'] !
-! {'status': '-', 'stype': '!'} {'status': '-', 'stype': '!'} True
string -!!!
tokens ['!!!'] !
-!!! {'status': '-', 'stype': '!'} {'status': '-', 'stype': '!'} True
string o?!
tokens ['?!'] ?
o?! {'status': 'o', 'stype': '?'} {'status': 'o', 'stype': '?'} True

Sunday, January 17, 2010

Freeze, Flood, Rollkur and Riding

Yesterday, for the first time in nearly a month, the arena was not either frozen or flooded and three hairy, unfit horse got exercised by an unfit rider. This is a first for most people in Ireland. We understand wet, all to0 well, but frozen! Accident and Emergency have been clogged with broken bones, meetings cancelled, hunting a distant memory, water shortages because of people leaving their taps on to prevent freezing (again).

Anyway, a month of not riding has left me with time to think and get some of my ideas down on paper. Everyone has a book in their head apparently, and mine from an early age, was one on training horses. The problem is, I always feel I'm only just starting to get the hang of it, and that's after a more than 30 years!

One of the questions I've been pondering since a recent conversation is what is a good rider? With the hoo-ha going on in dressage around Rollkur (see for video), there are clearly very very different opinions out there. To summarise the Rollkur issue, as I see it. Rollkur is the practice of riding the horse with his chin nearly touching his
chest, which is supposed to stretch his back and encourage submission. The Epona site shows an interesting video of riders of both dressage and show jumping horses warming up for competition and initially I could see nothing wrong. This is the way the pros warm up it's not the way I would ride my horses, but what do I know. Then I looked again and saw something I recognised but did not like. That feeling of power you get from putting a big powerful horse in a position of total submission, head arched, moving wherever you choose. I know that feeling of power, and I'm afraid it is called being a bully, and just because it's not only accepted, but encouraged by many in the horse world, does not make it ok.

To be clear what I mean by bullying, it's forcing a person or a horse to do something totally unnecessary just because you can. It's showing no respect for the person/horse and respect, I'm coming to find, is one of the keys to successful training. So coming back to what makes a good rider? First, what makes a competent rider?

The competent rider achieves three things: Firstly, a competent rider has a respectful relationship with their horse - they show respect for their horse and they expect, and get, respect in return. Respect is a bit out of fashion, it's a good deal harder than showing "Who's boss" or showing love and affection for our horses. Respect requires that I ask, not demand, that I listen carefully, not just assume any show of resistance is naughtiness. To my shame only today, I found Fred's reluctance to pick up his foot for the farrier was because he had a stone in the one he was expected to stand on, not a dislike of the farrier. Respect requires that I am consistent in where I draw the line. It's not fair to accept the yearling bouncing around on the end of the headcollar today because she is feeling fresh and I'm tired, only expect her to walk quietly beside me tomorrow. If I want respect I have to set a standard and stick by it.

Secondly, a competent rider does not get in the way of the horse. They stay in balance, not throwing themselves up the horses neck just as he tries to take off, or catching them in the mouth as they land, or hanging on to the reins to help them balance.

Thirdly, a competent rider gives clear aids to their horse, so he knows what is expected of him.

And that's all. The competent rider may not look that great, may not be successful in competition but their horses will be confident, relaxed and a pleasure to handle and ride.

A good rider, goes an extra step. They understand when a horse is having a problem and can help them with a slight shift in weight, increased leg pressure at just the right moment. They know from some kind of natural instinct and/or years of experience, when to put more pressure on a horse and when to easy off. They are like the perfect host at a party who puts everyone at their ease and keeps the conversation going, food and drink flowing all with without apparent effort.

The inexperienced rider does a lot to little effect, the competent rider learns to do less and achieves more, and the good rider does very little, but just the right thing and at just the right time.