Category: Uncategorized

Moving to a Rails-based blog engine, Enki

Blog City, who used to host this blog, decided that they’d had enough but didn’t seem to tell anyone who had a subscription that was about to lapse. Thanks guys, I’ve been a customer of yours for over 7 years!

I was planning on moving to another site eventually, but not right now because I’ve got too much to do. I was concerned that I was going to lose all that effort, and potentially useful stuff. So went into panic stations mode (I suppose) because I just wanted to get it done and move on to something else.

In the end I did some Unix shell hacking and pulled all of the entries through into a format where I could load them into a Rails application of my choice. I decided to use Xavier Shay’s Enki – it’s minimalist, but there’s enough there to get up and running quickly and it does comments and pages out of the box, which is pretty damn cool. The old blog posts are all now pure HTML and the comments are missing, sorry.

Then the fun started. As it comes out of the box Enki won’t run on the Heroku servers because of some problem with the gems in the Gemfile. I messed about with this for ages and in the end went for the obvious solution.

  • Create an empty app with the latest Rails 2 (2.3.10) and see it deploys (tick)
  • Copy the migration and app files across and see it still runs (tick)
  • Copy in the plugins (tick)
  • Let ’er rip and see what gems she needs (tick)
  • Put those gems, and those gems only in the Gemfile (tick)

Thar’ she blows!

So I have a version of Enki that isn’t a fork, but a Heroku-friendly pulling across of the core files into 2.3.10. Good news is that moving from this to Rails 3 should be really easy, in fact it might even make sense to repeat the process but with a Rails 3 base. Bad news is that it isn’t a fork and I don’t know how to get it back into Xavier’s main code base.

Imported Comments:

Ruben Berenguel

Congratulations for your move. I have been watching it over twitter. I’m glad it worked out!

Cheers,

Ruben (from mostlymaths.net)

Debugging cucumber scripts, cucumber and devise authentication

Non Rails/Ruby people may as well ignore this one!
Sometimes you need to see what the web server is sending back, when I’m working on rspec scripts I can print things out (which messes up the pretty output) but then see where my assumptions are wrong. I needed to be able to see what was in the response so that I could work out what was wrong. It’s annoyingly easy when you work out how. You need to add a step that looks like this:

When /^I dumped the response$/ do
  puts response.body
  # capybara users puts body
end
Then, in the features that are giving trouble:
Scenario: creator restores fragment
  When fragment 1 exists
  And I am the fragment owner
  And I am on the fragment
  And I dumped the response
  # ...

This allows you to do some debugging on that error you can’t fathom out. It helped me greatly when I put in devise authentication and discovered that my code was looping back to the login screen because of a duff password.

Devise

I love this plugin – takes away a ton of work (Thanks Colin)

This should get you started with cucumber. Note that password is a helper method that just returns something like ‘test123’. My code has user roles (I do it differently from the way the devise guys do it) and I took it out, so it may not run straight away as it’s untested. Caveat emptor.

Bootnote Suggest you look at the devise test helpers before you do anything here.

def create_my_user(params)
  unless user = User.find_by_email(params[:email])
    params[:password_confirmation] = params[:password]
    user = User.create!(params)
    ## This makes the user look 'confirmed'
    user.update_attribute(:confirmation_token,nil)
    user.update_attribute(:confirmed_at,Time.now)
  end
  user
end

Given /^I am logged in as (.*)$/ do |email|
@current_user = create_my_user(:email => email, :password => password )
visit new_user_session_path
fill_in(“Email”, :with => email )
fill_in(“Password”, :with => password )
click_button(“Sign in”)
response.body.should =~ /My Lovely App/m
end

How I now do this in RSpec

  let(:customer) { Factory(:customer) }
 before :each do
    sign_in customer
  end

Also needs this in your spec helper file:

 RSpec.configure do |config|
    config.include Devise::TestHelpers, :type => :controller
  end

Imported Comments:

Kyle

Found this useful 🙂

James Ferguson

You can just do:
user.confirm!

Also you can put steps within your steps, since they’re generally clearer to read:

Given /^I am logged in as (.*)$/ do |email|
@current_user = create_my_user(:email => email, :password => password )
steps %Q{
Given I am on the new user session page
And I fill in “Email” with “#{email}”
And I fill in “Password” with “#{password}”
And I press “Sign in”
Then I should see “My Lovely App”
}
end

Comment left on review for Feeble Paradox

http://www.newstatesman.com/television/2009/11/high-drama-flint-king-paradox

This is the Beeb’s feeble response to Flash Forward – can’t be bother with that either, but at least they have writers who can write.

Best bit was trying to wake the sleeping tanker driver  by standing 50 metres away and shouting, instead of driving right up to the bridge and using the car’s horn like a normal person would. But then Tamzi’s hair might have got mussed and the cheesy special effect would have been harder to do.

The closing sequence with more photos sent from “the aliens”, including her lover looking pretty dead was so clichéd I burst out laughing.

Heroic Failure on the 13th of November

Had you down for Heroic Failure on the 13th of November
Could you oblige?
RSVP to me
We’ll have tiffin on the lawn, eat small tiger for tea
Measure nose to tail
Will be slightly longer than the other one you see?
Tasty tiger don’t eat me no more than necessary

Yeah, you said you’d be there one time I sighed
All my fault
Reciprocate the failure
Send card embossed with lillies
No sympathy
And a short doggerel by Minor Lakeland Poet

Tiffin on the lawn
Cucumber sandwiches

Do come to tea
Don’t confuse me with specifics
Or lectures on entropy
I’ll be your friend for now
And later sigh in memory

Do come to tea

Ok, I’m not perfect and I still get angry – but still try to deal with it

I suffered the misfortune of sitting next to an extremely inconsiderate man on the train on Sunday. I was subjected to 2 hours of having my leg felt and the paper snapped and wafted in my face by the most irritating elbow wielding person I’ve ever sat next to. I think he was trying to get me to move. He had his wife and child with him (at least I think it was his child, I don’t think I saw him make eye contact once).

When he started tapping the chair I meant to say “please stop tapping” but what came out was “for fuck’s sake” – whoops. Should have said something before I came to the boil. Me bad man. Me swear in front of the children of the inconsiderate and self righteous. I’m sure there’s a spiritual message there. I know there is. Maybe he has Tourette’s and I’m really in the wrong. It was like he was trying to pick a fight and was’t even aware of it. I hope that he’s not in any position of power or one day someone that works for him will pee in his coffee, or do something even worse!

Thing is, it’s two days later and I’m still feeling the karmic shock wave of my anger. Anger does this to me more often than I would like to admit. I did’t sleep properly on Sunday and had this boiling anger thing on Monday evening. I could’t believe that someone could be so selfish, and have so little self awareness, it was extraordinary. It was’t arrogance: he just did’t have a clue that invading a total stranger’s personal space and noisily flicking a newspaper every 15 seconds or so could be seen as an arrogant and aggressive, in fact downright rude. It was like sitting next to a toddler who needed a nappy change. Really bizarre.

So ok, I’m a Buddhist, by definition a pacifist and someone who will not follow (or at least try not to follow) emotionally destructive paths. So how do I work with this anger and the irrational wave of hatred (it was that strong) that kept creeping up on me? I finally worked out the shape of it on Tuesday morning. In the Tibetan tradition there is a meditation technique called Tong Len, that translates as “sending and taking” or “exchanging self and other”. I am not a qualified teacher and will not explain it here, but the essence of the practice is to imagine yourself into various people, usually starting with loved ones, and draw their suffering and pain into you as you breathe in and out – transforming it and taking it away from them. Then you gradually change the focus to people unknown to you and finally to your enemies or people who have hurt you. Go and get instruction from a qualified teacher if you want to try it – quite deliberately I have not given enough information here – you would’t give a child matches or let it play with electrical wires. My community’s website is here.

It’s important to stress that Buddhists see no difference between self and other; that all suffering comes from this fundamental misunderstanding (other being everything, not just people). You see something outside you, you start dividing things up into like/dislike/don’t care, you see yourself as separate from these things, and suffering follows from it because these “external” things apparently control how you feel and think (again this is simplified, but I hope correct). Ignorance makes us see the other; pushing and pulling makes us angry and confused, suffering is the result. For me meditation practice is about trying to relax the tightness of this spiritual knot and undo it by seeing and feeling the the world properly, viscerally, and without any sense of a barrier (because there is’t one). It can’t be forced – the more you push the more things push back.

(Yes, Star Wars fans, Yoda says it, kind of: Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to suffering. He misses out the beginning (for a Buddhist): Fear comes from ignorance, from the false concept of self and other – the split making you afraid).

So this bloke is just another process spinning in the empty void like I am, the result of an endless chain of causes and conditions that go back to beginningless time and result in another deluded self hiding in a frail human body. He has no intention of hurting me and my feelings should not be changed by what he does. He can’t help his spiritual ignorance, limited self awareness and narrow view that does’t encompass total strangers like me.

I did’t do the practice, just thought about exchanging myself – one process for another – with him. I thought myself into his head, but kept my critical facilities. Then I realised other people don’t exist for him, so why should he show them any courtesy? This is probably overgeneralising, but the nub of it feels right. The guy must be quite broken in his emotional life, and probably is’t even aware of it. So the arrogance is actually an inability to empathise or relate, a fear that feels like an electric shock, the poor sod. On consideration I feel sorry for him, deeply sad that I did’t find something constructive to say that might have shaken him out of his distorted world view and woken him a little. I’m also scared for him: if he carries on winding people up without even knowing it you know it can’t end well, it could end extremely badly, and he wo’t even know why. 

So what I learned (again) is that you can’t win because there is nothing to win. But maybe you can grow a little if you are’t afraid of the pain. And the guy who could’t look people in the eye and was scared of everything, who was afraid to be happy, and comes across as very arrogant when really he’s afraid? That was me about ten years ago. So I can’t be critical. Still is me when I’m tired or not being mindful.

Next time, I will try to overwhelm whoever it is with gentleness, kindness and a little humour before I come to the boil. At least I know I’m broken.

Oh, and move my seat, even if the train is full. If he wants both seats let him have them – there’s more difficult and useful battles to have. Stubbornness does’t help either, but that’s another essay all of its own.

Imported Comments:

maxxxmagician

🙂

TDD is effective if you look at the right things

http://theruntime.com/blogs/jacob/archive/2008/01/22/tdd-proven-effective-or-is-it.aspx

It’s nothing to do with the initial development. All about the long-term viability of the code. You can’t refactor or maintain something if you can’t prove your changes have’t broken it. I do believe that the code is better, as long as each test comes directly from the specification, it shows you have understood it.

The comment above about doing your own coverage using the debugger is naive. You can cover everything every time you make a change, or only the tiny bit when you make the next one? Then you start to have something really brittle. Not immediately, but soon (really soon) you will start to feel fear every time you change something. Then you’re in trouble.

This research is measuring the wrong thing. I don’t know how you’d measure the longevity of the code, but the initial build is only 10% of the effort in any large system. This is not taught at school and it should be. Writing maintainable code that has full tests is not a luxury. Far too many people think it is.

Ballmer not the darling of the stock market

Comment left here.

MS is a statistical outlier. A lot of its success was accidental and also built on allowing piracy in markets it could’t control in the early days. Ballmer/Gates so what?

You get one of these companies every generation or so and they hang around for a long time and Wall Street or the City of Lahndahn try to make everybody else be like them when that business model only works in a new market when no-one has any idea what to do next. It happens to be Microsoft because IBM’s leadership had no idea what they’d unleashed – it could have been IBM or any one of a number of other companies that have now gone to the wall because MS’s dominant position stifled them.

We have no idea who the next Microsoft even are. Ballmer’s just another guy managing a big company that succeeded despite itself. The market is changing and MS will do its best to protect its equivalent of the pianola until it disappears or is reinvented as a medium sized player in a different market. The idiom of the ice companies making sharper saws while ignoring developments in refrigeration comes to mind. None of the ice companies became refrigeration companies.

I think the next innovation will be in finding a way to consistently write large chunks of software that do useful things. MS are’t even trying to play that game, as their last disaster shows too clearly.

For and Against Test-Driven Development

Comment left here.

I’ve been training people on TDD and the first thing I said is you need to start from the functional spec and then (maybe) create a technical spec that is used to drive the tests. Understand the problem first – and then the tests are just part of writing the code as a whole, no biggie.

Writing small tests for small bits of code make you think small, with short well focussed methods that do stuff. Long linear honkin’ bits of procedural code are very hard to test properly. TDD has the accidental but very useful effect that you write stuff that is’t tightly coupled because it’s impossible to do efficient TDD with tight coupling, assuming you get how to do it well. That takes practice. I think you should give it another try from the beginning with something simple and notice how the structure of your code is better (IMHO anyway).

When I’m doing demos or quick tracer bullet things then I don’t bother, but then there are no consequences.

I agree that agilistas can be far too rigid – don’t substitute process for thought. Anyone who ever suffered under RUP (or any big MC company’s “method”) knows how painful this is.

Testers test functionality. Programmers test assumptions. Not the same.

Next life

These old teeth

When ground
Will be dust again

And how happy I will be

To shuck off this old form and its aches and pains
Things done wrong already and for always wrong
It can’t forget, just recycle and chew on the
Old bones of pain

To move on to something new
But the mistakes will still belong to this little me
This flotsam
This bubble on the edge of a wave

Lose particulars but not consequences

I can live with that

No choice

If death is sleep then why live at all
If death is sleep there are no consequences
If death is sleep do what you want

If death were sleep
I’d be asleep

Imported Comments:

Laurel Wingfield

You’re a talented poet, Francis. You manage to put across sorrow, regret, weariness and the feeling of being small and lost, very well. There is a lot of feeling in this. I liked especially, the verse that began, ‘To shuck off this old form, and its aches and pains…’ and ‘But the mistakes will still belong to this little me/This flotsam/This bubble on the edge of a wave.’