Archive for August, 2007

Action Cache Issue Rails

August 30th, 2007 by pyrat

hmm-interesting

Ran into an interesting caching issue today which has been hiding in my web application oentries for quite some time. It all comes down to the locations that you serve your application from.

Previously (up to 10 minutes ago) I would serve it from both www.oentries.com and oentries.com. Recently I have been noticing a weird behaviour of the cached entry lists not getting updated. I have started using oentries.com for this recently. I then checked the equivalent URL on www.oentries.com and all was well.

Essentially, when the expire_action call is made, it uses something similar to url_for which generates the url from the headers to expire. Since all the users use www.oentries.com this cache is cleared out all the time when people enter for orienteering events, and since nobody is using oentries.com this isn’t getting cleared out.

The solution was to change the nginx config to put a global url rewrite to force www on urls. So now oentries.com gets redirected to www.oentries.com

I could have also improved the cache expiry code to expire the cache for both domains but as this is also an issue for SEO when you are serving the same app of different domains I decided that the URL rewrite was both a quicker fix (thanks to the nginx config generator now with SSL support thanks to me) and the right thing to do.

Conditional Validations in Rails

August 28th, 2007 by pyrat

The single table inheritance feature of rails is really useful. Today I needed to turn off validations in the extended model that were implemented in the base class.

I scratched my head for a while then realised its actually very simple.

class Page < ActiveRecord::Base

validates_presence_of :title, :slug,
:description, :if => :is_a_page?

private

def is_a_page?
self.class == ‘Page’
end

end

The above validation only takes place for the base class and not for classes that extend this. The beauty of STI being that the database stays pretty clean.

Ruby Code Beautify Textmate

August 25th, 2007 by pyrat

Ruby code beautification bundle item

Also my modification to the Amazon S3Sync ruby library was accepted. Now everyone can enjoy a YAML config file rather than using environment variables.

Also my modification the Nginx config generator to add SSL support was also accepted. Get in.

Cycling in North Scotland

August 25th, 2007 by pyrat

Ewan Cape Wrath

Last week I went on a cycle trip with some friends throughout the north of Scotland. What follows is a report of what we got up to etc.

Day 1 – Carbisdale -> Tongue

This started about mid day you can see the route we took below.


ebay image

About half way we stopped at the legendary pub called the Crask Inn. This is a truly amazing place in he middle of nowhere which is still powered by generator! Its really a blast from the past and a great place to party I think. I will definitely go back. We met some geordies who were on holiday and talked top gear.

near tongue

Around this time I kept falling off my bike. I had new pedals for my bike and kept trying to be in my new front brake pads. In doing so, I forgot I was clipped in and fell onto my side in front of everyone!

This earned me numpty of the day you can see how happy about it I was…

numpty of the day

Unfortunately the south african warden of tongue syha was a bit of a spoil sport and not Ewan’s favourite man so a few of the group had to camp rough. It was great fun after a few beers and game of killer sprinting along the road to get to the hostel in the pitch dark. Was definitely a top feeling just being able to make out the white lines whilst cycling about 30mph!

Day 2 – Tongue -> Durness

After weeks of rain this day was a jewel. Everywhere in Britain was getting rained on apart from the far north of Scotland. We really were the winners in the UK that day!


ebay image

As you can see the route was fairly short and involved a nice circuit of a sea loch and some nice beaches. We were in Durness by early afternoon and had planned to go to Cape Wrath. Unfortunately we had missed the last ferry and had to just chill out at the beach instead.

We went to balnakeil sands and took a swim in the sea. Surpisingly for me it wasnt that cold and we had run swim surfing the waves.

Ewan Balnakeil


ebay image

At this point the idea of a barbeque came to us and we got all stocked up from the local spar and headed down to sango sands. The cleanest beach around apparently.

Barby

Numpty of the day was Adam for leaving food at the hostel and chewing up Jenny’s bike with elastic.

Day 3 – Durness -> Achininver

This was the real beast of the trip. 75 miles with some really hilly terrain.


ebay image

We set off at 8am via the spar for some tasty breakfast. And then it was off up the slimy misty glen for the first col ascent of the day. A long drag right up the valley, I was powered by some really tasty fudge.

We all agreed to go at our own pace and meet at a cafe in Unapool 40 miles into the day. I decided to settle into a routine of one hour effort and ten minutes break. 2.5 hours of this and then and I was at the cafe. Happy to see Oleg and Ewan who were already then we ate food and dried off until Ross, Adam and eventually Jenny arrived.

The next stage of the day was onto Lochinver over the Col de Assynt. This was a big mountain ascent followed by a very speedy descent down to Loch Assynt. This was pretty beastly and fun to do, even in the rain.

Then into the wind which for me was the hardest section of the trip. This took us into Lochinver which has a very famous pie shop. The steak and ale pie was award winning so I got me one of these after seeing what Oleg’s venison and cranberry pie looked like.

After warming up and buying food for dinner we all headed off on the super crazy road to achiltibuie. This is a tiny single track road with loads of big ascents and descents. Really mad country. Ross and I worked together to conquer this terrain we ended up having a snus stop with Oleg and Ewan who were further up the road.

Then when we all got together we rode the final stretch into Achiltibuie peloton style. We then had a well nice meal of curry which Ewan cooked for us. We were very grateful and shaked his hand.

Day 4 – Achininver -> Carbisdale

All started nicely on time and we had a 35mph wind behind us after we turned northeast.


ebay image

All was well cyling along the loch until there was a slight mishap. Jenny the legend that she is, decided to go right instead of left and head towards Ullapool. This was properly the wrong way.

Jenny Cycling

We all realised this at the meeting point about 8 miles the other way and by this time we were too cold an unable to follow her. Oleg went all the way to Caribsdale Castle on his own. And the remaining four of us went to Elphin for soup and tea. Its really good to be in the warmth when its wet and cold.

I put on all my dry clothes for the final stretch. Remember to always have a spare base layer with you because when it rains or you work hard it gets soaked and makes you well cold when you stop.

The final stretch was obscene. The tail wind was so powerful I was in the top few gears all the way. Ewan and I clocked up average speeds of over 20mph which is pretty sweet considering there were a few hills and I stopped to piss twice and once to get wine gums. I maxed out the gears on my Kona Dr Dew for the first time ever. I think excess of 45 but cant be sure.

After we all got back Carbisdale (apart for the Ullapool Maiden) three people and three bikes all got packed into Oleg’s car. Madness.

Olegs car

All was well a few hours later when Jenny rolled into Carbisdale. Surprisingly with a pretty big smile on her face. All in all the trip was great fun despite some borderline weather. Jenny got to keep the Numpty of the Day top.

Next plan is some famous mountain ascents in the Alps. Watch this space.

Free WIFI in Glasgow and Edinburgh

August 21st, 2007 by pyrat

List of free wifi spots in Edinburgh and Glasgow:

Free wifi in scotland

Update: The free wifi in Firebird is great. The cost of food a little high though.

Install Old Capistrano 1.4.1

August 20th, 2007 by pyrat

sudo gem install -v 1.4.1 capistrano

In case you dont have the time to update your recipe and are setting up a new machine.

Away again to Cape Wrath

August 12th, 2007 by pyrat

Just back from a wee holiday at the Scottish 6 Days of Orienteering! I also completed 30 days of orienteering in a row culminating yesterday at the legendary Anagach wood.

Tomorrow I leave with a crew of 5 people for a 4 day bike trip. Im looking forward to it and should be able to come up with some good stories I hope. Legends like Ewan Mcarthy and Oleg Chepelin are going.

In other news I now have a macbook for rails development so should hopefully be able to start posting stuff related to this.

Time to go back underground for a while. Bye bye internet.

Update: Edit testing using xmlrpc via textmate.

Simple DNS Report Tool

August 1st, 2007 by pyrat

I have been doing a lot of systems administration and dns work recently.

To make my life easier I have created a simple DNS Report Tool

If you are constantly checking dns setup this might help you.