Readable Riddle in Ruby!

One of the main things that attracted me to the ruby language was how readable my code was, while at the same time retaining a tight structure and, most importantly, still being very fast. I decided to put this to the test by creating a piece of code that literally read like a passage of English text. The focus of this experiment was the “As I was going to St Ives” riddle. I’ll go into a bit more detail on the riddle itself in a second if you’re not familiar with it. The challenge here was not only to create “literally” readable code, but also to follow ruby best practices. Of course, the code would actually need to solve the riddle too 🙂

If you haven’t heard this riddle before, take a look at this and mull it over.

As I was going to St Ives
I met a man with seven wives
Every wife had seven sacks
Every sack had seven cats
Every cat had seven kits
Kits, cats, sacks, wives
How many were going to St Ives?

So exactly how readable was I able to get the code? Well, in a word, very.

And, check it out, it solves the riddle when run too!

Now, this is the point where the pedantic among you will point out that are multiple solutions to the riddle. I did not know about these other solutions when i first embarked on this experiment, basically growing up and hearing this riddle I always thought it was just a smartarse way of getting people to do maths for no reason, and that the answer was “one person, me”!

It turns out that there are actually a whole bunch of solutions based on the inherant grammatical ambiguity of the problem itself. For example, you could assume that all items and people encountered were also going to st ives. You might infer that “how many” applies only to sentient beings. You might also assume that the dude you met who had seven wives was alone, and just “told you about his wives” when you met him.

I filled my “some-facts” file with all sorts of superfluous code, almost parodying the amount of superfluous facts that are inherrent in the riddle itself if you assume that the correct answer is “one”. My personal favourite method was this one;

def as_i_was_going_to(place)
  @people_and_where_they_were_going[:me] = place

Having said that, I believe that it is possible to leave the “stives” file above completely untouched, and with only minimal changes to “the-facts” you could get the code figuring out whichever solution you wanted to interpret. In fact, I’m putting that out there as an open challenge to any bored coders or rubyists that fancy having a crack at it – code is available in the following git repo;

Inspiring masonry.js Site

I have recently become interested in the idea of creating e-commerce websites that “inspire” purchases. My reasoning went something like this: I have always created sites which cater for people who generally have some kind of idea of what they want. Sure, I have tools in there for people to also “browse” the products, but they’re just lists of prices and product names with dinky little images. Hardly inspiring.

The most inspiring part of any product page is the image. Especially in the industry I work in (travel) it is so important that customers understand exactly what it is they are purchasing and what it’s going to be like when they get there. Sure, you’d be a fool to book tickets to a show without doing any research, but nevertheless the image is usually the initial catalyst to perform that research in the first place, not the price and not the name.

So this got me thinking that if we were to lead a search with images, rather than prices, we could inspire the research which would in turn inspire the price. The part I was struggling with was how this would work in practice. Then I found this site;

Cutest Paw is absolutely incredible. It’s basically powered by a combination of JQuery, masonry and an infinite scroll plugin, and it just works so well! Imagine that this wall, instead of being cute fuzzy animals (which I will admit is awesome) was actually just a steady stream of image content about, say, Paris. The user keeps scrolling until they find one that appeals (possibly filtering a bit), they find one, hit it, and then the research can begin!

The tactile nature of these types of interface port incredibly well to tablets, and are already well into the realms of being “trendy”, but I have never seen it used as well as the above before.

ICO gave me a cookie without asking!

I have made a previous entry registering my disgust at the ignorant, uninformed implementation that the EU is imposing on the use of cookies. Rather than re-covering old ground, let me sum it up for you in two words: utter crap.

“We’re supposed to warn people before giving them cookies?!”, I thought, “How the heck would that work? I’m going to scare away all of my customers.” I waited anxiously for someone to actually implement such a feature to give me a better idea of what is expected.

I was therefore very interested when I heard that the ICO website actually has one of these warnings on it! Fantastic, this’ll be implementation straight from the horses mouth! So let’s head over and see what they’ve done…

You can play along at home by visiting their site at, which presently looks like this;

Yes! We have wording! Let’s see what we have here…

The ICO would like to use cookies to store information on your computer, to improve our website. One of the cookies we use is essential for parts of the site to operate and has already been set. You may delete and block all cookies from this site, but parts of the site will not work. To find out more about the cookies we use and how to delete them, see our privacy notice.

Followed by a check box asking me if I agree.

What’s this!? “one of the cookies we use is essential and has already been set”!? I headed straight to the browser settings to see what it was. After clearing all cookies and refreshing the page, I discover it’s the cookie that holds your session ID, deposited on my PC without me giving my permission.

So we are allowed to deposit essential cookies? What the heck counts as essential?! Ironically, under (which they’re using) the session cookie is actually quite easy to get rid of by using the URL to achieve a cookieless-session. This means that the one “essential” cookie they give you is actually the easiest to avoid using! Admittadly you do sacrifice oodles of security using your querystring as a session tracker, as well as a lot of usability, so we’re back to the question of what “essential” actually means. You could argue that analytics tools are essential to the running of any succesful e-commerce business, for example.

Let me save you the time: The guidelines DO NOT MENTION this clause currently, and as such the ICO presently does not comply with it’s own standards!

I am seriously considering drafting a letter of complaint!

By the way those guidelines, whilst not really worth the paper they’re written on, are worth a look if you want a giggle. I can almost hear the twisted lament of web designers all across Europe at some of the design recommendations contained within;

One possible solution might be to place some text in the footer or header of the web page which is highlighted or which turns into a scrolling piece of text when you want to set a cookie on the user’s device.

Yeah, marquees are back baby!!!!1!!!

^^ that would be scrolling if this wasn’t wordpress 😦 anyway, please share if you care x

EU Anti Cookie Laws – Utter Nonsense

So I woke up yesterday, like many web developers, to the news that the often threatened European anti cookie law is finally upon us after three years and will be coming into force on the 25th of May. The radio 4 show I was actually listening to delivered this news in the form of an interview with a typically uninformed governmental type who appeared to think that this law would be a massive pain in the backside to developers but that we “had no choice”.

Even the BBC article I just linked to doesn’t get all the facts right! Our own minister of culture takes a bit of a smarmy attitude (quote “we should not see any delay in action as a ‘get out of jail free card'”). It’s very clear that whichever bunch of suited monkeys came up with this ridiculous ruling also weren’t in possession of all the facts before making the decision. The UK, unfortunately, is bound as part of their EU agreement to enforce this law otherwise they’ll be in quite a lot of trouble, so all eyes at the moment should be on the interpretation that our government implements in order to comply. Given the level of competence they’ve shown in recent years, confidence certainly isn’t high. It should be of absolutely no surpise to anyone that the industry is simply not prepared because nobody with half a brain would ever think something this ridiculous would ever come to fruition.

Well, I’m here to just clarify that the “Pain” that this will apparently cause developers is absolutely MINUTE compared to the pain this will cause users. If you’re a developer, you’ll already know the scale of what we’re dealing with. We’re a resourceful bunch and will be able to handle whatever these cretins throw at us (heck, we do that at work every day right?).

Users, on the other hand, are stuck with this forever. Fortunately regular web users are also pretty resourceful and I dare say some kind of loophole will be discovered to get around whatever we end up with. The people that will probably be hit hardest will be the most vulnerable web users (i.e. the thickies that don’t even know what a browser is). So what have those users got to look forward to?

Well, contrary to what all these articles tell you, cookies are not evil things that infect your computers and steal personal information. They are tiny key-value pairs that store information to give you persistant state accross the otherwise stateless web. They’re also used to power many commonly used web framework concepts such as the session (where a little encrypted session-key cookie is placed on the clients browser to give them a persistant session for 30 minutes or so). Decline cookies and it’s bye bye “being logged in” and bye bye “shopping cart”.

Web analytics software that companies use to track website performance and improve usability / conversions are mostly also cookie powered (including google’s own solution and analytics-leaders omniture). Yes, this software will certainly be used to track user behaviour in order to improve a websites conversion rate, but this is no more unscrupulous than the “nectar card” system which people use every day. Will be pretty interested to see how those companies deal with whatever happens.

To take this one step further – it is actually scientifically impossible for this not to be annoying for users. If the site itself needs to get permission to plant a cookie, and the user says no, then it’s going to have to ask again on every single page because without planting a cookie there’s no way for the site to know that it already asked you! Actually that isn’ strictly true – in the absence of cookies, the last bastion of maintaining state therefore becomes the utterly insecure and easily by-passable query-string.

And it’s worth pointing out as well that the querystring can be used to track user behaviour just as easily as a cookie can, and is far less private ( developers – you can achieve this functionality by adding the “cookieless” attribute to your Session settings in web.config). In fact, banning cookies will only really “wound” the beast they are trying to kill. Pretty much the only thing that cookies give you uniquely is the ability to tell whether someone has visited your site before (and all associated data that you might have given them last time they did).

It’s also scientifically impossible to actually get the users permission in a bulletproof way! Most browsers already have a “prompt me about cookies” setting but apparently just turning this on won’t be enough (already stated). They can’t really use javascript because people might not necessarily have that turned on, and they can’t use a DOM element because those can just be manipulated away. Placing the responsibility to ask permission for cookies in the laps of web developers has basically ensured that there is no bullet proof way of making sure the user gives that permission. Nice one!

If we’re lucky, the ban will be restricted to uses of cookies for certain things rather than just being a blanket ban, but unfortunately this is also scientifically impossible. There is absolutely no way for anyone monitoring cookie usage to tell what a particular cookie does without seeing the accompanying server side code (unless it’s obvious from the name). Unless it’s a blanket ban then, this will be an un-enforceable law.

Speaking of those organizations who will be enforcing this… how are they going to prove that a website didn’t ask users permission? Will we all now be expected to keep databases proving our innocence? And how on earth would we actually obtain this proof to begin with? It’s not like we can match a web request to an actual person (you certainly can’t get that sort of information from the IP address of your average web user).

I don’t mind going out on a limb here and saying that I personally think that this law will never happen or if it does happen it will be implemented in such a way that nothing will actually change for the most part. I will also put my hand up and admit that I have probably jumped straight to the “worst case scenario” when going through the implications. With any luck it’ll end up just being a mandatory note in the footer.

To all the privacy lobbies out there campaigning for this: Listen up. If you don’t want people knowing your IP address, don’t use the internet (your IP address is included in every request you make and there’s nothing you can do to stop it being there). If you don’t want people knowing your personal details, don’t type them into the internet. If you don’t want people knowing what you’re buying online, don’t buy things on the internet. Quit trying to wreck it for the rest of us. Focus your energies on campaigning against specific abuses of privacy, such as people selling your details to advertising firms or other such actions.

So I stand by my initial point: This is an unenforcable law dreamed up by a ridiculous group of people. If attempts are made to enforce it then I predict european web-wide rebellion! To agree to these laws would be to hand a whopping great e-commerce victory to the rest of the world. The only people ultimately harmed by the decision would be users and I’ll be damned if I’m going to give my own users a rubbish web experience just for this.