How To Repair A Nintendo GameCube

For the last few months, Claire and my GameCube has been broken. It broke at one point, which I attributed to the drive motor being jammed up with dust and hair and crap, so I opened the lid and wiggled a knife-blade around inside it for awhile, which seemed to fix it… but a couple of weeks later, it was dead again. I decided to have another look into this, yesterday, and a little bit of research online revealed that the problem was probably that the strength of the laser had degraded, rendering it unable to read any discs. This is, apparently, one of the most common causes of death for the GameCube (and I’ve seen a good number of ‘cubes go on eBay which would appear to have exactly this problem). Thankfully, there’s a really well-written guide on lens calibration for the gamecube, which helped a lot. However, the thing that’s lacking online is a photographic guide: so, as part of this ‘blog entry, I’ve written one.

Usual disclaimer: following this guide will void your warranty. Plus, if you do it the way I did it, you risk electrocution, exposure to laser radiation, and worse yet, you may break your GameCube beyond repair.

I recommend that you read the guide to lens calibration for the gamecube – it’s far more in-depth than this blog entry. However, this blog entry has prettier pictures.

Symptoms

  • GameCube fails to load games – it claims that the disc is missing or unreadable, and will only load up as far as the “configuration cube” screen with the funky ambient noises.
  • Open the lid and detach the clips under the lid to release the circular plastic Nintendo-branded thing that sits on top of the lid: this will allow you to watch the disc spinning while the ‘Cube is running, even with the lid closed. Try again – the disc will start to spin (so, it’s not a broken drive motor) but then stop (when the system finds it can’t read the disc).

Problem

The power output of the laser which is used to read the surface of the disc has reduced with age. This is a common problem in GameCubes, apparently, between two and five years old. It can be repaired by a Nintendo engineer, but the price is prohibitive (you might as well buy a working second-hand one). However, we can fix it ourselves. [if you can’t see the rest of this article, read it here]

Tools

I didn’t have all the tools to hand that the author of the guide I followed had, but I made do. Here are my tools:

 Screwdriver and ball-point pen
  1. Screwdriver – this is a standard “size 0” (small, but not really small) Phillips-head screwdriver. This particular one cost me 45p from my local hardware store.
  2. Ball-point pen – mine was a WHSmiths-branded one with blue ink.

Method

First step is to prepare the tools as you’ll need them. The four main case screws that prevent you from taking a GameCube apart are a strange custom design deeply recessed within deep holes on the underside of the device. You can apparently buy a specialist tool for manipulating these screws, but I couldn’t be bothered, so I made one: remove the ink tube and nib from the pen, so you’re left with a long plastic tube. Then, using a hot flame (I used a gas ring) melt/ignite the end of the tube you’d normally write with (where the nib was, before you removed it). It will probably catch fire, but just blow it out while trying not to breathe in too much of the toxic black smoke you’re producing. It needs to be molten enough to be malleable. Then, once it’s hot, put it down into one of the four deep holes on the underside of your upside-down GameCube.

 Upside-down GameCube with holes highlighted

Push it down firmly but evenly so that it points directly up, and hold it there for a minute or so while it begins to take shape. What you’re doing is moulding the shape of the screw head into the molten plastic of the pen, so that when the plastic sets you will have a tool that exactly fits them. Of course, if then pen snaps, you’ve buggered any chance you had of ever getting into your GameCube, so be careful! Once it’s standing upright by itself, leave it for four or five minutes to finish cooling. Now’s a good opportunity to read the rest of this guide, if you haven’t already.

 The strange-headed screws that you need to remove

You should now be able to use your new tool to unscrew the four screws that hold your GameCube together. That’s the hard bit over with. Flip your GameCube the right way up again, put your hands on it’s sides, and pull upwards to remove the cover. If there isn’t one already, put a GameCube disc onto the spindle. This will serve two purposes: it will allow you to test the GameCube without reassembling it, later, but more importantly it will help to protect the laser lens from damage when you turn the drive mechanism upside-down, later. Next you need to remove the front and rear panels. These are attached by small plastic clips in the corners of the cube, as shown below.

 Howo to remove the front panel from a GameCube

Be careful not to detach the cables that connect the front panel to the rest of the GameCube, as these ribbon cables are very difficult to re-attach without damaging them! Now you’re ready to start removing the chassis screws (which are holding the fan in place and preventing you from getting at the underside of the disc drive. There are 14 screws to remove, in the areas shown below, but 3 of these are concealed underneath the fan and the 2 holding the fan in place will need to be removed to reveal them. Why did Nintendo see fit to use 14 screws where 6 would have done is beyond me.

 The 14 screws

By now you should have something that looks a lot like this:

 The 14 screws

A GameCube with the top, sides, and fan laid bare, and the screws removed from the main chassis. Now’d be a good time to have a closer look at what goes on when your ‘Cube turns on. This is optional, but I think it’s interesting. If you look near the back of the GameCube, on the right-hand side, you’ll see two plastic forks. This is the switch that detects whether or not the lid is closed (as a safety precaution, the disc will not spin and the laser will not turn on if the lid is opened).

 The switch that makes the lid work

Danger: laser radiation – do not do this! Connect the GameCube’s power (it connects to the back of the fan module) and output (where it normally is, albeit without the faceplace), to test it. Hold the “lid switch” (above) backwards to tell the GameCube that the lid is closed and press the power switch (it’s on the fan module). You should see the following happen:
  1. The power LED will turn on.
  2. The disc will start to spin.
  3. The laser, under the disc, will turn on. You should be able to see it shining through the disc. Now stop looking at it; you’re irradiating your eyes.
  4. The laser will move back and forth to try to “read” the disc.
  5. At this point, the laser will probably turn off and the disc will stop spinning – this is because the GameCube you’re using is broken. If it was working, the game would load. You can use this test later on to see if you’ve successfully fixed the device without having to re-assemble the entire thing!
  6. Don’t leave it running too long, because by this point the fan will be in the wrong place to help cool the unit.

Next, you need to remove the four long screws behind the ports (above the memory card slots).

 Four earthing screws need to be removed

 

This will also release two strange bits of metal which are held in place by these screws. I don’t know what they do, but I’m sure they’re probably important, so make sure you put them back after you’re done! Right; time to detach the disc drive. Lift the entire upper part of the system up and away from the base: there’ll be a little resistance as a plug becomes detached, but if you find you’re having to pull hard, you’ve probably left a screw in somewhere. The whole metal plate with the drive on top will come away in one piece. This is the bit we’ll be working with. Flip it over. Now, you’ve got to remove six small screws, highlighted in red on the photo below. I’ve also highlighted (in blue) the connector that links the drive to the bottom half of the console.

 Underneath the upper chassis

Removing the screws allows you to detach the metal plate and gain access to the circuitboard underneath. This is what we’re looking for. Again, I’ve highlighted the connector port in blue to help you navigate.

 Circuitboard

What you need to do is to turn the screw (highlighted in red) about 3 or 4 degrees anti-clockwise. This will increase the power given to the laser and fix your problem. If you turn it too much, your laser will overheat and burn out. If you turn it too little, the problem won’t be fixed. I recommend that you turn it a little at a time to find how short a distance you can turn it (anti-clockwise) to have the console begin to work again (i.e. so it “barely” works)… then turn it an extra 2 degrees or so to be sure. Be gentle!!! When you’ve made the adjustments you want to, re-assemble the thing so far as you need to to test it. You don’t need to put any screws in or even put the fan or panels back on – just hook it up to the TV and try not to look directly at the laser lens. If it still doesn’t work, go back and turn the screw a little more anti-clockwise (to boost the power some more). Hope that helps you get your GameCube back up-and-running again: it did mine! Feedback is welcome, but if you need more information I still highly recommend Lens Calibration For The Nintendo GameCube, which also has pointers on some of the other things that could be wrong (if this fix fails), what tools you need to do it without melting pens, and tips from somebody more-experienced on how far to turn the circuitboard screw. Good luck!

Abnib, Version 3.0

Abnib Version 1.0 was a funny little beast. It was built to accomodate for about half a dozen bloggers, but ended up with about nine or ten. It worked, though, and the principle of aggregating the blog entries of our friends and our friends’ friends took off. Abnib 1.0 had a few major flaws: firstly, it only showed a summary of the post. This was partially because all but two of the bloggers thereon were using free LiveJournal accounts, and a limitation of free accounts at that time was that you could only get the first couple of hundred characters of a post at once. Another limitation was that the site design was columnular – each person had a column of their own, which dramatically reduced the space available and made in-post images impossible. Furthermore, Abnib 1.0, which updated itself wholly or partially every time it was visited, was as slow as a dog.

Abnib died when I accidently deleted a few key files for which I didn’t have backups, and that was the end of that. However, with Gareth‘s help, it was reborn in August 2004 as Abnib 2.0. This was powered by Planet, a Python-driven flexible feed aggregator which is used in all kinds of places for just the kinds of purposes we use it for. Jon went a step further and added an interesting new style to it, and we added the Abnib Gallery (Abnib 2.1), a place for all things Abnib to share photos. Abnib became a real “centre” for our fun little crowd, gathering information on Troma Night and the RockMonkey wiki, as well as the usual weblogs. The release of Abnib 2.2 brought extra abilities much-requested by users, such as the ability to “hide” the community feeds. That’s where we are now.

However, all is not well. There are a few key things I’d like to see improved in Abnib:

  • Several LiveJournal users have commented (Paul comments, Matt comments) that sometimes, when they make multiple posts in quick succession, Abnib only picks up on the most recent of them. I’m not sure what’s causing this, so it’s probably Planet.
  • Some people like to make lots of “friends only” posts (a LiveJournal feature whereby you can restrict visability of your posts to specific other LiveJournal users). As more and more people use Abnib as their “quick window” onto Aber blogs, people are finding the need to make superficially-pointless posts (like this one) in order to ensure that people realise that they have made a “friends only” post that might otherwise be overlooked.
  • Abnib 2.2 still isn’t quite doing so much for the community as I’d like it to be; it isn’t as interactive or as inspiring as I feel a weblog aggregation portal should be.

So, in order to fix these problems (among others) and implement some new features, I’ve begun work on Abnib 3.0. This new version of Abnib will:

  • Correctly deal with multiple posts in quick succession from LiveJournal users.
  • Better integrate with Abnib Gallery.
  • If permitted (by individual bloggers – either overall or on a case-by-case basis), advertise when you have made a “friends only” post, and how to go about reading it if you have permission.
  • Load faster by holding content back until requested (for example, only the 20 most recent posts are shown by default, but more can be displayed without a page refresh: up to 80!).
  • Hold meta-information on members such as a short description, which can be updated by that member only.
  • Allow readers to ‘hide’ any or all feeds, in order to focus on the things that matter to them.

It’s all powered by a new weblog aggregation engine called Phatnet, which I’ve been building for the last few weeks specifically for this purpose. And it’s pretty damn gorgeous. But that’s not all. Experimental features which might end up part of it now or later include:

  • Tighter integration with RockMonkey – see what pages other people are reading.
  • Ajax-powered “keep me posted” features, such as a checkbox that, when checked, automatically adds new posts to Abnib as they are written – right in front of your eyes.
  • Comment counting: know how many comments have been made on standards-compliant blog posts.
  • A couple of other things I’ve been playing with.

Hopefully, I can get Abnib 3.0 finished and released later in December. If you want to see what’s been done so far and how it all fits together, take a peep at the Abnib 3.0 Preview (it updates every few days, so it’s no good for actually reading blog posts on, but it should give you an idea about some of the features: try clicking the “More Posts…” link at the bottom or on people’s names in the sidebar). It’s ugly as sin, but hey. Feedback appreciated.

Chef

Those who found themselves confused by my programming recipe the day before yesterday can now be a little less confused (hopefully): here’s the explanation.

The program is written in an esoteric programming language called Chef, who’s sole purpose is to be able to write computer programs that look like recipes. There are even competitions to write programs in it that can also be cooked as real dishes. It’s a strange world. Each of the ingredients is a primitive kind of variable (for the non-programmers: a named entity [eggs, penne pasta, etc.] that can contain a value). The values that these variables can be instantiated with are numbers, and the numbers are given at the start of the line. Therefore, at the start of the program, eggs=3 and penne pasta=56.

These are “put” into the mixing bowl one at a time. The mixing bowl is a stack – the things put in to it first appear at the bottom, with other things on top of it (for the non-programmers: stacks are immensely useful in almost all programming languages, so programmers tend to have no trouble with being told “the mixing bowl is a stack”). So, when the first item (penne pasta) is put into the mixing bowl, it (and it’s associated value, 76) sits at the bottom of the bowl, ready for other things to be “put” on top of it.

However, we do some more complicated things, such as “adding” a birds-eye chilli. “Adding” is not the same as “putting”. When something is “added” to the mixing bowl, the value of it’s ingredient is added, mathematically, to the value of the thing at the top of the bowl. So, for example, when we add “1” birds-eye chilli to the mixing bowl which contains only “76” grams of penne pasta, we end up with a mixing bowl containing just “77” grams of penne pasta.

“Combining” is another Chef operation. After we’ve put the fresh ginger (17) in, we combine it with the cinammon (5), which results in a multiplication of the top item in the bowl, resulting in 85. “Removing” the birds-eye chilli (1) reduces this number by 1, because the “remove” operation means “reduce the value of the ingredient from the value of the ingredient in the top of the mixing bowl”. Later, we “stir”, the mixture, which moves some of the values in the stack around (read the spec if you care). And eventually, we “liquefy” the contents of the mixing bowl, which turns the numbers into their Unicode equivilent (typically letters): N, A, M, T, A, C, and S.

The baking tray is the output buffer (buffet?) in which things must be placed to be output to the screen, and the “serves” directive indicates which baking tray (we only have one in my recipe, but the language specification allows for multiple bowls, trays, and even delegation of sauces and other side dishes to other chefs – see the recipe for Fibonacci Numbers with Caramel Sauce [and notice the recursion – “caramel sauce should be served with caramel sauce”]) we output to the screen.

Jon earns himself a pint from working through the program, the mad fool that he is. There was a flaw in his logic, though, that made him come up with “NAMTACS” as the answer: he forgot that the baking tray, too, is a stack, and that the order of the ingredients is not changed in the transfer from the mixing bowl to the baking tray (check the spec!)… when popping ingredients out of the baking tray, they come out in reverse order. A pint to Paul for spotting his mistake. The correct output is “SCATMAN”.

Thanks to David Morgan-Mar for this fantastic programming language. He’s also the man behind LenPEG, an image compression algorithm which, for selected images, can achieve lossless compression at a ratio of 6,291,456:1, and HQ9++, an object-oriented language which provides the most code-efficient possible method ever to write test programs such as Hello World, 99 Bottles Of Beer, and the Quine program, although nobody has ever successfully written a Fibonacci generator or a Towers of Hanoi solver in it.

A Challenge For My Programmer Friends

So you think you’re a dab hand at learning new and unusual programming languages: even the most bizarre of them. You can get your head around Perl, and you might have even looked at LISP. Well, let’s see who’s first to correctly tell me what the output of the following computer program is. It’s unique (I’ve just written it, and you won’t find it elsewhere on the ‘net), so you’ll have to first work out what the programming language is. At that point, you’ll need to either find a platform on which you can run it, or “whitebox” decipher it by hand.

A pint, and my respect, to the first person to solve it. If nobody solves it, the pint’ll go to whoever seemed to be most on the right track.

Scatman Dans Pasta Bake.

A quick and tasty meal for programmers everywhere: baked pasta with a spicy
kick. Cook and drain the pasta first, and pre-heat oven to 175 degrees Celcius
(gas mark 4).

Ingredients.
76 g penne pasta
75 g fusilli pasta
65 g grated cheddar cheese
64 ml vegetable stock
21 g courgette
17 g fresh ginger
11 g crushed garlic
8 teaspoons olive oil
7 g parsley
5 level teaspoons cinnamon
3 eggs
2 sliced new potatoes
1 birds eye chilli
1 pinch hot chilli powder

Cooking time: 30 minutes.

Method.
Put penne pasta into the mixing bowl. Add birds eye chilli. Add hot chilli
powder. Put crushed garlic into the mixing bowl. Combine parsley. Put fresh
ginger into the mixing bowl. Combine cinnamon. Remove birds eye chilli. Put eggs
into the mixing bowl. Combine courgette into the mixing bowl. Add sliced new
potatoes. Put vegetable stock into the mixing bowl. Add eggs. Put fusilli pasta
into the mixing bowl. Add olive oil. Put grated cheddar cheese into the mixing
bowl. Stir for 5 minutes. Liquify contents of the mixing bowl. Pour contents of
the mixing bowl into the baking dish.

Serves 1.

Warning: do not try to cook this dish as if it were a genuine recipe!

The Rails Cafe

This Rails Cafe article made me smile. Rails really is a lot of fun. If SmartData gets the upcoming project I hope it does, I’ll be pushing for Rails to be the development platform: the project would lend itself very well to it. Perhaps I’ll hammer out a hundred lines or so in advance, in order to demonstrate my point when the discussion comes. Again, assuming the client takes our quote.

I’m limping a lot better today, almost up to a normal walking pace, and my foot hurts a lot less (except when I walk for more than ten minutes on end).

Claire‘s made a great start on looking for a new place for us to live, finding a few possible places already and arranging for us to visit one this evening. This possible new place sounds fantastic, but might be a little beyond our budget. We’ll have to do the maths this evening.

Not Quite Where We Planned To Be

Claire and I are in Preston. Let me explain how this came about.

As I mentioned, we spent Friday night and most of Saturday in Gregynog, a beautiful stately home owned by the University of Wales and used as a conference venue. Every year, the Computer Science department ships almost the entirety of the second year out there to learn how better to get a job, in anticipation of hopefully getting an industry year placement the following year. Claire, as a department staff member, was invited along to help organise a group of students. I was invited along as an representative of the computer industry, there to give mock interviews to students of the kind that they might expect when applying for computer science related jobs for their industry year or for graduate positions.

It was a lot of fun. I met some interesting people and, with their help, got to grill students. Perhaps my favourite part was successfully catching out students who had… how shall we say it… exaggerated a little on their CVs. One fellow, I remember, had, while boasting about his web development proficiency, stated that he was familiar with HTTP. So I asked him what the fundamental differences between a GET and a POST method were. I’d have accepted something about request parameters being visible on the address bar, but no: no such luck. It was also good to be pleasantly surprised, such as by the database-proficient claimant I met who successfully, with a pause, disassembled the huge database relationship diagram I gave to him. My co-interviewer says I’m evil. I replied that I was merely thorough.

On Saturday night, in accordance with our plans, we continued on to Warrington to visit Gareth and Liz‘s new place. Gareth didn’t seem quite ‘with it’. But the food was good and I regretted eating so well at Gregynog that I couldn’t guzzle more, and the company was even better. After the party came to a quiet end, we dropped off Jimmy at his home in Runcorn, and decided to move on up to Preston to say “hi” to my folks.

Needless to say, my mum was at least a little surprised when Claire and I waltzed into her bedroom. We didn’t waltz, mind. More of a polka. But she was surprised, regardless. My dad returns from Vietnam today, so we’re hoping to catch him and have lunch before we return to Aber.

Paul: I bet, despite her trying to remind herself on several occasions, Claire’s still forgotten to call you to tell you that we’re unlikely to make the 2:30 screening of Howl’s Moving Castle at the Arts Centre, so I hope you read this before then.

Ah; Friday…

In the words of Bender, “…another pointless day where I accomplish nothing.” It’s feeling a little that way. Last night’s brownout knocked computers offline, and this morning BT severed a cable, depriving us of phones and internet access. It’s an hour and a half into the day already and I’ve got nothing done so far.

The worst bit is, having been told that the phones were down already: when I discovered that the outbound fibre optic link was down, I picked up the phone to call the facilities manager. Whoops! In an age when everything is connected and digitial, it’s easy to forget that things don’t always work as they should.

Add to this the fact that I’ll be leaving early today, and you’ve got a recipe for underproductivity. Which is a word, now, thank you very much. I’m off this evening to Gregynog, a University of Wales conference centre, as a guest interviewer, to give mock interviews to second-year Computer Science students. These interviews are supposed to be reflective of those given in the industry, in order to better prepare them for ‘real’ interviews and give them feedback… so I’ve been devising a list of some of the nastiest Comp. Sci.-centric interview questions ever devised. Here’s some of my favourites:

  • How would you explain a database to a 10-year-old child?
  • When choosing between programming languages with which to implement a specific project, what are the most important factors and why?
  • Pseudocode me an algorithm to detect whether two rectangles (with known top, left, bottom and right) overlap one another.
  • What is bytecode? Can it be reverse-engineered?
  • What is the sum of all numbers from 1 to 1000?
  • Do you make mistakes? Tell me about one of them.
  • Are you smart? Why do you think that?

I can’t write too many of the really nice fun ones here, because (a) there’s at least one person I’ll be interviewing who I know reads my weblog and (b) I’ve got some questions which depend on demonstratable code samples, which I can’t be arsed to upload anywhere.

Anyway; things look like they’re all booted up now, so I’d better get on with some work.

Duality

Duality, my main desktop PC at home, has been misbehaving, and I’ve had to take it to pieces, both virtually (tracing driver DLL calls – yum!) and physically (computer components littering the floor, etc.). It’s been two years since it’s last reformat/reinstall, which is a pretty long time for a Windows XP box treated the way I’ve treated it, so it’s definately time for a rebuild.

Shame I couldn’t have done it sooner/later, as it’s put a dent both in my NaNoWriMo writing and in my ability to investigate some code for a client I’m dealing with “on the side”. It’s going to be a busy little weekend.

In other news, I’ve been playing with Gosu, a sprite animation/drawing layer module for Ruby. Ruby’s execution speed (within an object-oriented paradigm) lends itself well to 2D animation and games. Here’s a Flash animation showing a recording of what I came up with:



Yes, that really is the sprite for Dan in the Dan & Alex comic.

If you’re really sad (and using Windows – I haven’t tested it under other operating systems and can’t be arsed packaging up the C-layer stuff for them, yet), you can actually have a play. Just install Ruby 1.8.2-15 For Windows (15MB) and the game itself (740K).

If I get really bored or suddenly find a lot more free time, I might actually finish making a game out of the engine I’ve put together.

Edit: The download link for the game has now been fixed. If you downloaded it and just got error messages when you tried to run it, try again now.

E-Mail Server Configuration For Dummies

Well; I feel like a wally.

SmartData‘s taking on a new client for a content-managed web site, web and e-mail hosting. In anticipation of the domain transfer going through without a hitch, I reconfigured our web and e-mail servers to already be ready to accept connections to their “new” web site and for e-mails to come through. This is a wise move, because not all of the computers on the internet appreciate moving domains at the same time, and so for a day or so, e-mails will be going to both the old e-mail server and the new one: the new one needs to be ready to catch these before the first computers start sending e-mail to it.

Unfortunatley, I underestimated the intelligence of the configuration tools and the anti-spam mechanisms of our e-mail server software.

So, I send an e-mail to our client, who we’ll call bob@our-new-client.com, from my @smartdata.co.uk address. It goes out through our mail server. This is where it all goes wrong. Normally what our mail server would do would be to look up where on the internet our-new-client.com’s e-mail is kept, connect to there, and deliver it, but our mail server is a little bit lazier than that. It thought to itself, “Hey, I am the e-mail server for our-new-client.com: I know this, because I’ve been configured to accept mail for them,” and so it happily filed all my mail to bob@our-new-client.com… on their new mail server.

And then the news came through that there were complications in the domain name transfer, and it would be a few more days before they could easily pick up said mail. So, I’ve happily e-mailed them a request for their deposit on their hosting package with us, and they’re wondering why we haven’t asked for it yet, so they e-mail us. Here’s what happens:

Their e-mail server contacts our e-mail server and says “I am our-new-client.com, and I have an e-mail for dans-real-address-goes-here@smartdata.co.uk.”
And our mail server thinks “Hang on, this server is pretending to be our-new-client.com, but I know that I am responsible for our-new-client.com’s e-mail. This must be a filthy spammer trick.”
But our mail server was configured by me, so it’s a little devious. It responds (to the real our-new-client.com mail server): “Okay, I believe you, give the the e-mail.” (so those filthy spammers have no idea whether their mail got through or not) Then it shreds the e-mail and buries it in virtual concrete.

And so, for the latter half of this week, neither our newest client or us have been able to e-mail one another, and it’s only today that I’ve noticed.

Bugger.

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?

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.

Magic Story

Inspired by Andy‘s PassThePageGame on the RockMonkey wiki – a collaborative storytelling game based on that silly game you used to play at school, I’ve written my own tool:

MagicStory is a collaborative wiki storytelling tool designed to be harder to “run away” with than normal wikifiction. Having read the story, participants can write a suggested “next sentence”, and after three suggestions have been collected a fourth person will be able to choose which one is used. Give it a go!

You’ll need a RockMonkey account, of course, but they’re free and simple to set up.

Rock Exchange

This weekend I hope to release Rock Exchange, my latest WikiGame on the RockMonkey wiki. I’m just finishing performing some tests and fine-tuning on it now. Here’s a screenshot:

Rock Exchange game on the RockMonkey Wiki

In Rock Exchange, players will be able to invest their hard-earned Rocks (a unit of currency) in shares in the various pages on the RockMonkey wiki. The value of these shares will fluctuate based on several characteristics, and players will have to play the odds in order to know when to buy and when to sell to gain a return on their investment. A page’s shares fluctuate based on:

  1. Popularity: so if a new page seems likely to attract the attention of a lot of passing Googlers, it’s worth investing in, whereas an “in joke” that’s died out is not. Similarly, players can manipulate wiki page links in order to attract interest. The most valuable indicator of popularity is how many people come to the site for the first time, entering on a given page.
  2. Investment: investment in pages will put positive pressure on their value, but selling shares damages this value by flooding the market – who’ll be first to pull out of a high-flying page, thereby forcing other shareholders to suffer?
  3. Interference: there will be several methods for people to drastically interfere with the value of their shares and the shares of the other traders, but these won’t necessarily be immediately apparent.
  4. Random factors: the rock market, like the stock market, is an unpredictable animal, and there’ll be a small amount of luck in any investment.

The game’s pretty much “ready-to-play” in it’s most basic form right now, but I want to run it alone awhile longer and see if I can improve the balancing factors in it.

×