Variable scope in Ruby

One big difference between Perl and Ruby is that Ruby has no lexical variables. This confuses me when programming Ruby, because I’m used to thinking ifwill create a new scope. It doesn’t. Variables defined inside if will be available outside, because they belong to the method scope. For example, in Ruby you can do this: def foo if true x = 2 end puts x end foo This prints 2. However, in Perl: sub foo { if (1) { my $x = 2; } print $x; } foo(); You get the warning Use of uninitialized value $x in print at lexical_test.pl line 5.. ...

April 14, 2014 · 2 min · Mike Cartmell

The Heartbleed bug

On reading about the Heartbleed bug bug, my first thoughts were: This sounds quite simple, is it really easy to spot? Why wasn’t this noticed during review? The bug is in the Heartbeat Extension for TLS, as described in this draft. Interestingly, this document does actually highlight the importance of checking the payload length: If payload_length is either shorter than expected and thus indicates padding in a HeartbeatResponse or exceeds the actual message length in any message type, an error Alert message using illegal_parameter as its AlertDescription MUST be sent in response ...

April 8, 2014 · 2 min · Mike Cartmell

10 Singlish phrases I would actually use in the UK

Possibly not everyone knows that English is an official language of Singapore (one of 4.) What’s more, there is an unofficial (and sometimes frowned upon) mini-language called Singlish, derived from bits of Hokkien, Teochew, Malay, English and Tamil. Most of these words exist either to express something that does not have an English equivalent, or to say something more succinctly. Either way, it does come in handy, and it’s fun to use language that would be unacceptable or confusing back home! So, here’s a list of my 10 favourite Singlish words and phrases, some of which I’d probably use when I visit the UK: ...

March 17, 2014 · 3 min · Mike Cartmell

Free tissue packs

This is a common sight at lunchtime in Singapore: tissue packs, often several next to each other, seemingly left behind on the table. One might, upon first encountering this phenomenon, assume this is the generous act of kind strangers. But it is not. You must not take the tissues. For they have an important message, and that message is this: Go away. Take your food and sit elsewhere, because this seat is taken. I have reserved it with my tissue pack. ...

September 30, 2013 · 1 min · Mike Cartmell

Settling in Singapore

So I’ve been in Singapore just over a week, and so far it’s going pretty great. It’s ridiculously easy to settle in here. Everything is crazily efficient and convenient. I think even if you’d never been here before and wandered around aimlessly for a whole day, you’d still find everything you needed. I kept my sim card from when I was here on holiday. I switched it over on the plane and it was working before I got off, including data. Brin kept my ez-link (transport) card, so I could start using the trains straight away. You’re never far from somewhere to eat (more on this later), and being a foreigner means my card works in practically any of the ATMs. Not that you need cash most of the time. ...

September 14, 2013 · 3 min · Mike Cartmell