Dan’s Dingbats Challenge III

It’s back! Dan’s Dingbat Challenge III!

If you’ve not played Dan’s Dingbat Challenge before, you’d better go back and look at the first and second ones, and Andy’s one. Or just go look at the answers to my first and second ones. Or just give it a go.

I’ve made a few changes since last time:

  • There’s a nifty little JavaScript to automatically put your cursor into the box you have to type into, to save you having to click in it. You should now be able to play the whole game without touching the mouse.
  • I’m using incremental graphics, so even if you’re on a slow connection you should be able to make out (mostly) what the picture is, even before it’s loaded.
  • The penalty for wrong answers and skipped questions has been increased to 50 seconds, so it’s really worth your while to look at every one for a few seconds before giving up. As usual, there’ll be “half-marks” available for very close-but-not-quite-right answers.
Play “Dan’s Dingbat Challenge III”!

3 Brazilian Soldiers

Donald Rumsfeld was giving the president his daily briefing.

He concluded by saying: “Yesterday, 3 Brazilian soldiers were killed.”

“OH NO!” the President yells. “That’s terrible….just terrible!”

His staff watches as he buries his head in his hands and saying, “This is bad; bad for the coalition.”

His staff sits stunned at this display since he had never shown much interest when other reports came in of American casualties.

Finally, the President looks up and asks to no one in particular, “So exactly how many is a brazillian?”

Black & White 2 Installer

I’ve just been installing Black & White 2, and was quite impressed by the following screenshot:

'everything.stuff' file

Guess nobody told Lionhead about using meaningful file names, eh?

The Way Lunch Should Be

There’s a right way to go for lunch during your break at work, and, if you’re in Aberystwyth, this is it.

Starter
I started in Scholars, where Matt (in the Hat) is spending the entire day as a birthday celebration. I treated Matt to a pint of Guinness, and had a half myself, thereby giving myself probably a full lunch’s worth of calories. But never mind. Matt was trying to teach his friend Dave to play cribbage, with moderate success dulled only by the alcohol both had consumed. Matt’ll be in Scholars until they close, I don’t doubt, so if you haven’t wished him a happy birthday yet, that’s where you’ll find him.

Main Course
Morgan's ButchersI’ve recently discovered the sandwiches of Morgan’s, the butchers opposite Barclays on Great Darkgate Street. You go in there and mutter “beef” to the chap, who then slices a generous bun and fills it with roast beef, a Yorkshire pudding, fried onions, and thick gravy. It’s a roast beef dinner… in a sandwich! Genius! Apart from the obvious mess it makes to eat it, it’s fantastic.

Dessert
And to finish: back to The Hot Bread Shop on the corner of Cambrian Place and Chalybeate Street for a slice of orange cake. And now I’m very full. Marvellous.

Abbey National’s Rebranding

Is is just me who sees Abbey National‘s new logo – the result, inevitabley, of thousands of pounds worth of rebranding as part of their “new appeal”, as looking like some kind of symbolic steaming turd?

Abbey National's new "baked bean in a cape" logo.

Perhaps it’s just me, but when I first saw it in Aber high street the other day, that’s the first thing I thought of.

×

Writing A Calendar App In Rails Vs. PHP

Some time ago, I wrote a web-based calendar application in PHP, one of my favourite programming languages. This tool would produce a HTML tabular calendar for a four week period, Monday to Sunday, in which the current date (or a user-specified date) fell in the second week (so you’re looking at this week, last week, and two weeks in the future). The user-specified date, for various reasons, would be provided as the number of seconds since the epoch (1970). In addition, the user must be able to flick forwards and backwards through the calendar, “shifting” by one or four weeks each time.

Part of this algorithm, of course, was responsible for finding the timestamp (seconds since the epoch) of the beginning of “a week last Monday”, GMT. It went something like this (pseudocode):

1. Get a handle on the beginning of "today" with [specified time] modulus [number of seconds in day]
2. Go back in time a week by deducting [number of seconds in day] multiplied by [number of days in week] (you can see I'm a real programmer, because I set "number of days in week" as a constant, in case it ever gets changed)
3. Find the previous Monday by determining what day of the week this date is on (clever functions in PHP do this for me), then take [number of seconds in day] multiplied by [number of days after Monday we are] from this to get "a week last Monday"
4. Jump forwards or backwards a number of weeks specified by the user, if necessary. Easy.
5. Of course, this isn't perfect, because this "shift backwards a week and a few days" might have put us in to "last month", in which case the calendar needs to know to deduct one month and add [number of days in last month]
6. And if we just went "back in time" beyond January, we also need to deduct a year and add 11 months. Joy.

So; not the nicest bit of code in the world.

I’ve recently been learning to program in Ruby On Rails. Ruby is a comparatively young language which has become quite popular in Japan but has only had reasonable amounts of Westernised documentation for the last four years or so. I started looking into it early this year after reading an article that compared it to Python. Rails is a web application development framework that sits on top of Ruby and promises to be “quick and structured”, becoming the “best of both worlds” between web engineering in PHP (quick and sloppy) and in Java (slow and structured). Ruby is a properly object-oriented language – even your literals are objects – and Rails takes full advantage of this.

For example, here’s my interpretation in Rails of the same bit of code as above:

@week_last_monday = 7.days.ago.gmtime.monday + params[:weeks].to_i.weeks

An explanation:

  • @week_last_monday is just a variable in which I’m keeping the result of my operation.
  • 7.days might fool you. Yes, what I’m doing there is instantiating an Integer (7, actually a Fixint, but who cares), then calling the “days” function on it, which returns me an instance of Time which represents 7 days of time.
  • Calling the ago method on my Time object, which returns me another Time object, this time one which is equal to Time.now (the time right now) minus the amount of Time I already had (7 days). Basically, I now have a handle on “7 days ago”.
  • The only thing PHP had up on me here is that it’s gmdate() function had ensured I already had my date/time in GMT; here, I have to explicitly call gmtime to do the same thing.
  • And then I simply call monday on my resulting Time object to get a handle on the beginning of the previous Monday. That simple. 24 characters of fun.
  • + params[:weeks].to_i.weeks simply increments (or decrements) the Time I have by a number of weeks specified by the user (params[:weeks] gets the number of weeks specified, to_i converts it to an integer, and weeks, like days, creates a Time object from this. In Ruby, object definitions can even override operators like +, -, <, >, etc., as if they were methods (because they are), and so the author of the Time class made it simple to perform arithmetic upon times and dates.

This was the very point at which I feel in love with Ruby on Rails.

The Flat Is Tidy

Thanks to JTA for his help. Huge thanks to Matt (temporarily minus his hat) for his help: feed the guy oatcakes and rum and he’ll mop your floor! Winnage!

This is, of course, a result of the anticipated sale of the building we live in. The owners of MG’s cafe, below us, and – in fact – the whole building, are selling up and leaving. I’m not sure if this is what they’d planned all along – to buy the building, renovate the café, and sell it at a profit – but it’s at least a little bit inconvenient for those of us who live there and don’t know if and when we’ll have new landlords and whether or not they’ll want tenants (for instance, one of the prospective buyers when the building last came up for sale would have wanted to turn The Flat into a home for themselves).

But hey; The Flat is clean. Come see.