Author: francis

Just running RSpec on one thing while you fix it

This is like an Autotest script but you have to tell it what files to watch, also can be used for anything that waits for when a file changes (assumes the file is called mywatch, the echo sh … line is all one line):

#! /bin/sh
if [ “$#” -eq 0 ]
then echo Usage: $0 command files
  echo runs the command every time the files have changed
  echo put the command into quotes
  echo example:
  echo sh ./mywatch.sh ‘”ruby script/spec spec/models/article_spec.rb —format specdoc”’ spec/models/article_spec.rb app/models/article.rb
  echo ^C quits
else
  command=$1
  shift
  touch /tmp/old_ls.$$
  while :
  do
    ls -l $* > /tmp/new_ls.$$
    diff -q /tmp/new_ls.$$ /tmp/old_ls.$$ || eval $command
    mv /tmp/new_ls.$$ /tmp/old_ls.$$
    sleep 3
  done
fi

Footnote:

Found a Ruby way of doing this http://nubyonrails.com/articles/automation-with-rstakeout also added some code that will use the windows Snarl, rather than the Mac growl to send messages and a one line script  for people who are lazy enough to not want to type long commands, see this.

Railscon 2007 Berlin

I originally started a post about the conference but it got too old and Blog City deleted it. Never mind. Have another go.

The conference was fantastic and I enjoyed every minute of it. The presentations are here.

I went to the charity tutorial on testing, which was hard core but really good. If you want to see what it was like have a look at Ruby Hoedown and click through to the testing tutorial. I’ve watched all of the content from this conference – very good.

By far the worst talk of the whole show was the one by the inventor of REST Roy T. Fielding, Chief Scientist, Day Software, who just read his very dull powerpoint to us and did’t say anything new or useful in language I could understand. This was annoying because the ideas are really good – just expressed in a very closed, boring and inarticulate way.

The talk from Cyndi Mitchell of Thought Works was by far the most interesting visually, she presented using hand-drawn diagrams rather than the usual bullet point bullshit, and what she had to say was interesting and well thought out.

I was most moved by the Rails in Africa talk, and resolved to try and help them. Of course, one month or so later I’ve done nothing about it because I’ve been running around like a headless chicken. 

I met up with some of the guys from the North West Ruby User group, and also eventually got pointed to geekup (another North West England thing). I can recommend Sushi and German beer.

Need to post more on Geekup, the Manchester Ponto de Cultura , learning to use RSpec,  paddling the Washburn, using SVNRepository for my own projects  (only $4 a month for peace of mind – bargain) – just to name a few.

AND … getting into podcasts after being so sniffy about them. (list of good podcast sites to follow)

AND … Going to see my dharma teacher after several years (next week). But that’s pretty private.

Onward 

Diary entry

On 2nd week since the long holiday in August, came back last Tuesday.

We went up to Scotland and stayed near Dunbar. Cheated this time because the weather had been so bad so we stayed in a static caravan. I took Jon to see the Foo Fighters at the fringe in Edinburgh. Supported by a band who said their name too quick and Nine Inch Nails, who were very loud and impossible to understand the words. I enjoyed singing along with Dave G, but it did’t give me the excitement that I had hoped for. Jon found it a bit noisy.

We fitted in a day at North Berwick and walked around the headland at Dunbar golf course, which was really nice and the sun shone for once. Also bought Jon a skim board and he spent a lot of time falling off it.

Came back for just long enough to pack Deb off to Guide camp and go to Bala for a weekend with the Canoe Camping Club folks. Dan showed us is photos of his holiday in Norway. Said he was glad he had done it but did’t want to go back to somewhere where it rains 360 days a year!

Rosie spent both days on Bala lake, day 2 sailing back in Da’s canoe. I managed to get to the Tryweryn for one day and then took Jon to the beach at Barmouth, after spending over an hour failing to find anywhere to park we went about 2 miles north of the place and found a really nice public beach over some dunes. It was a bit of a slog to cart the gear but OK. Jon finally mastered his skim board (ish).

Tryweryn tired me out; still lacking the fitness I used to have. But never mind, it’s coming back slowly. 

Then back at work. The CEO has agreed that I can go to the Rails Europe conference in Berlin and I’m getting quite excited about it. I also feel like writing a white paper on how not to design an external interface because of some of the interfaces I’ve been working with over the last month or so. It begins with: Do not use SOAP to send XML – use it to send structured objects, goes by way of always return consistent outputs to your users and finishes with use the framework properly.

I wonder if their ears are burning?

Comment on BBC article about child molester’s “art”

Just give the proceeds to charity, like those from Mein Kampf are given to Jewish charities. It’s not hard. I also wonder if the books were written to get close to children, or simply because it is something he is good at and he wanted to make some money. It’s good that his awful, criminal life, has produced something of merit – the rest of us should take it from him and use it for what it is.

http://news.bbc.co.uk/1/hi/magazine/6979731.stm  

Extending/Mixin Ruby classes with Modules

module Mod
  def x
     puts “x”
  end
end

class C1
  extend Mod
end

class C2
  include Mod
end

C1.x – will work

C2.x – will not, but C2.new.x will

In essence:

  • extend – class level
  • include – instance level

None of the books explain this properly. They go into great detail with lots of pictures, but this simple thing is not explained anywhere, or is wrapped up in some stupid example that is really trying to make some other point. In the end I looked at the supplied code and worked out how to do it. Cost me a couple of hours and really very trivial.

You can also have private methods in your modules and they all go in nice ’n easy. 

Just a quick note about arrays of objects in a Rails web service server

If you want an array of something, e.g. past addresses:

class PersonWrapper < ActionWebService::Struct
member :title ,:integer
# … blah
member :addresses ,[AddressWrapper]
member :employers ,[EmployerWrapper]
end

This will give you an array of past addresses and one of employers. It’s one of those things that’s so obvious it is’t documented – so you can’t find it and don’t know it’s there … I will write a longer post/article/wiki about how easy it is to create a web service with complex objects whe I have time.

Response sent to Register Article about gmail

Here

It’s not free 

Cos you’re reading the ads which are generating cash. 

I don’t mind, because they’re text ads rather than really irritating Flash aminations (El Reg take note??).

I think Guy has a point – I also use MacMail, which is POP3, and it sends a mail when the mailbox starts to get full. It’s not rocket science.

By default POP3 does’t delete with gmail – but it does know that it’s been downloaded so you don’t get it again. That’s part of the point with it …

One thing that annoys me, as a developer, is that I can’t send and receive certain attachments but it’s not that big a deal, really.

My ruby on rails form select won’t work?

Got bit by this again. So, for the record …

If you’re selects are’t working (i.e. you’ve got and ID coming through but it is’t showing in a select box).

Check your types

I had:

 @admin.introducer_id = admin_args[:introducer_id]

and this in the rhtml:

 <% form_for(:admin, @admin, :url => admin_path(“index”), :id => ‘admi’ ) do |f| >
    <
= f.select :introducer_id, @introducer_list, {}, {:onChange => ‘go()’ }%>
<%end%>

The it just was’t working no matter what I did.

Then I noticed that a select that was a list of strings was … so … 

 @admin.introducer_id = admin_args[:introducer_id].to_i

and it started working. This has happened to me before – I had a lookup table that stored the lookup ID in a string (‘cos it could have been a string as well as an ID) and it did’t work then. Stupid, stupid boy. Ruby does’t coerce stuff.

Hope this helps the next person. 

Identity cards in the UK

I had hoped, with the change of government here, we might finally have someone with half a brain in charge of the home office. Nope. Strong believer in ID cards.

This is an interesting one. They’ve already coughed to £5.4 billion, the LSE estimated £10 billion and the Daily Mail (not a comic I take much notice of, to be fair) recons it may top £20 billion. I am glad that we now use the US version of a billion in this country, in the UK it used to mean a million million, rather than a thousand million. So at least that’s all right.

For some reason, after 9/11 and 7/7, the politicians decided that we all needed an ID card to “fight terrorism”. How? All of the individuals that perpetrated these crimes had valid ID. In the case of the deluded boys on 7/7 most were British citizens. How does a piece of plastic with some much-vaunted biometric nonsense on it make the slightest bit of difference? I’ve never heard an answer to this question that has anything coherent to say.

The only way it makes sense is to have something like an internal passport, like they did in Soviet Russia. You can’t travel anywhere without first clearing it with an official and there are checks and legal sanctions everywhere to make sure that you don’t break the rules. This would indeed help to fight terror, because the individuals tagged as not white or really British but we can’t execute them yet could be kept together in one place and be allowed to starve to death with dignity. Of course, once you have done this it’s really easy if you want to introduce prison camps and hurry the process up a bit.

I doubt they’re that sophisticated. In reality it’s another government database in lieu of attempting to engage the disaffected and actually taking responsibility for anything. A complete waste of money and talent. The politicians have to be seen to be doing something, and throwing billions of pounds down the toilet on some technological pipe dream fits the bill admirably. I think I might see if I can go to my MP’s surgery and see if he understands this nonsense. I certainly did’t vote for it.

Have a look here for more info. The database state is on its way, and it’ll be really crap. Can you imagine what it’ll be like? Have you ever worked on a large implementation of say, SAP or Oracle? Can you imagine how useless the system will be? Shiny though, very shiny, and biiiig. Oh yes. Very expensive. And broken. People will be denied health care because it says they are’t real people, jobs, bank accounts, all sorts of vital things. These idiots can’t even put in a medium sized system to manage something as trivial as passports. It scares me. I’m thinking of converting my spare cash to betel nuts.

Sigh. 

By the way, have a look here for a common-sense take on the attacks in the UK (‘al-Qaeda’ puts on big shoes, red nose, takes custard pie) over the last few days. We were attacked by incompetents who thought setting themselves on fire might somehow make the rest of us really scared. But of course it serves the securocrats. These clowns would all have had valid ID as well. Ha.