Yearly Archives: 2007

C conundrum (below)

I've got a problem with C.

I'm trying to do something like the following:

#define FOOBAR 5
some_function_which_takes_an_integer (FOOBAR);
...
some_function_which_takes_a_string ("String literal with FOOBAR concatenated: "FOOBAR);

Which I want to expand to:

some_function_which_takes_an_integer (5);
...
some_function_which_takes_a_string ("String literal with FOOBAR concatenated: 5");

Unfortunately, I can't, and I can't see a way to do it. I'm basically looking for a way to stringise a preprocessor token's value so that it can be concatenated with other string literals before the compiler is allowed to molest it.

I've been talking with a friend, and seeing as there's a # preprocessor operator which stringises token names, it would make sense that there would be one for token values, but he can't think of one, or any other way to do it apart from using sprintf.

One other way of doing it would be to have two different versions of each preprocessor token – one an integer, and one a string – but that's ugly.

Anybody got any ideas?
Continue reading

Totem docs, go-karting and BIO

It's been a busy week, but things should now be winding down (or up) for Christmas.

To begin with, I've got an e-mail from Kirk Bridger sitting in my inbox with a usability review of Totem's Tracker plugin. I'm trying to find some time to go through it and deal with the five issues he brings up, since they're all problems on one level or another. I've just about missed the period before UI change announcement comes in, but I should be able to get it done before the UI freeze.

Another area Totem's getting some work done in is documentation. We've got two bugs open at the moment about it, and some other changes lying around in my local checkout. The current documentation for Totem ostensibly relates to version 1.6, but I suspect it's actually a mish-mash of documentation for several versions, with small areas changed as and when necessary. It might be an idea to set another GHOP task to update the documentation.

Away from GNOME, I went go-karting yesterday as an outing to celebrate my brother's birthday. Although it was freezing, we had fun, and my dad, brother and I all came very close together; if it wasn't for each others' mistakes, we wouldn't have got past anyone at all. The problem now is that I ache everywhere, due to the kart's seat being slightly too big, and the fuel tank being just a bit too wide to sit comfortably between my legs.

Moving back towards computing, I sat the British Informatics Olympiad again on Friday. I found it a lot easier this year than I previously have, as this year, VC++6 was available on the computers at school for me to use. In previous years I've been forced to use Visual Basic 6, and the lack of decent arrays makes taking the olympiad like swimming in treacle with your hands tied behind your back look easy.

Thanks to being able to use C, I managed to get complete solutions to the first two questions, and was half-way through a solution to the third (although I'm not sure I was taking the right approach) when the time ran out. Hopefully I'll have got more than half marks this year. :)

Laptop installations and aliens

Finally, my laptop's finished installing Fedora 8. I probably shouldn't have tried to install it, considering the laptop's an old Fujitsu Siemens Amilo M-6100, with a Celery processor and 128MiB of RAM.

I started the process on Saturday, first discounting using the install DVD, as the laptop doesn't have a DVD drive, then discounting the LiveCD since it has nowhere near enough RAM, and just times out when logging in. Talking with Bastien, he suggested I run it from the boot.iso file from the install disk, and then point that at the full DVD's ISO somewhere (either on an NFS or USB drive, or on the laptop's hard drive).

I duly started to try this on Sunday morning, but ran into some problems. The boot.iso kernel crashed when loading the drivers for the PCMCIA network card, so an NFS drive was out of the question. I handily don't have any USB drives large enough to contain the 3GiB of install DVD either, so that too was out of the question. The final option was to remove the laptop's hard drive, remove it from its caddy and connect it to my main computer using my Dad's Disk Jockey hardware, so that I could copy the ISO straight to the /home partition.

That worked surprisingly well, so I got the installation up and running about midday Sunday. However, since the laptop only has 128MiB of RAM, the whole package installation process only finished this morning, as I believe it had to seek to the DVD ISO to get the package, seek to the swap partition to cache it there, then seek all the way to the installation location and install it, for each package. Then there's the fact it's got less processing power than a reconstituted bacon sandwich…

Anyway, it's installed now, and I can now spend hours tweaking it so it doesn't use all the RAM just sitting on an empty desktop. Fun times!

In other news, I watched Alien on the TV. It was quite a disappointment really, I suppose due to its age, and how all children's cartoons are like that now, or something like that…

Totem YouTube plugin

Update (2011-08-27): A lot has happened to the Totem YouTube plugin since this blog post. It's been ported to C, extended to do HD videos, trimmed down to no longer do HD, and then moved to Grilo, where it now lives. It can be used in Totem from the Grilo plugin, which provides a unified UI for accessing video websites like YouTube from Totem. For more information on the history of the plugin, see my blog posts about Totem.

YouTube has come to Totem…

…in the form of a plugin I've written which allows you to browse YouTube from the comfort of everyone's favourite movie player. It allows searching for videos, and when you play a video, it displays its related videos.

The feature I'm most proud of though, is the fact that it automatically paginates when you scroll down the search results, loading more results as you go down. With a hint from Patrys in the comments in my blog post on it (and thanks to the other guys who left comments :)), it works by loading results immediately if you scroll 80% or more of the way down the treeview with the mouse or keyboard, or if you let go of the scrollbar handle more than 80% of the way down when moving it with the mouse. Query pages are loaded in a separate thread, and then the results are brought in with an idle function. This isn't quite as lag-free as I'd've wanted, but I can't see much more I can do to improve things.

Anyway, try things out by downloading and compiling SVN Totem, then enabling the "YouTube browser" plugin. You'll need the GData Python library (that's what the YouTube API uses, PyGTK 2.12 and Python 2.5. Before anyone asks, there's no way to sanely support video uploading yet, as Google unfortunately haven't yet exposed a public upload API. :(

Oh, and the cake is a lie.

17th birthday

It was my 17th birthday today. I wouldn't've classed this as such a big occasion, since the only new thing I'm now allowed to do is learn to drive, and all that'll do is drain my pockets.

In fact, it would've been quite an uneventful day, if it weren't for the ridiculous birthday card I got from everyone at school. I believe one of my friends (who was conspicuously absent today) was thrown underneath a car by everyone to delay me in the morning, while a birthday card was passed around a large number of people in the common room (including Michelle Pfeiffer and some other people I don't personally know).

It was given to me at break time, along with an impromptu chorus of "happy birthday", and various odd looks at us from people who didn't know what was going on. This would've been great, if it weren't for the actual content of the card, which is the greatest achievement in in-joke-mongering I've seen in my entire life. So here for your viewing (dis)pleasure it is…though it's not for the faint-of-heart.

OK; I think that's enough. They're gone. :)

I should remind people that it's all in-jokes, and the only real part of the image on the front is the head, and even that's a crap picture. :D

After school, I celebrated the event with my family by having home-made sushi. Considering this was the first time we'd had sushi, and the first time we'd made sushi, I think it went OK. It was certainly passable, if a little strong. I definitely won't be diving into a blob of wasabi paste again like I did today. ;)

Anyway, an enjoyable day, and even though my friends didn't buy me an Aston Martin, I'll forgive them, eventually. :)

Adding to a GtkTreeView as you scroll?

I'm writing something for Totem, and I want a GtkTreeView to have more rows added to it as you scroll down.

So far I've got it adding more rows nicely when you get to about 80% of the way down the GtkAdjustment, by listening to the adjustment's "changed" signal, but then it keeps on adding rows (ideally it should only add 20 at a time then stop), and the handle of the scrollbar screws up. I presume this is something to do with the fact that the handle is grabbed at the time, and so probably can't resize, or something.

Anyway, has anybody implemented anything similar before (or seen such a feature somewhere) so that I can see where I'm going wrong? I could've sworn I'd seen something similar before (I'm not original enough to think up such features myself :D), but I can't find it. Answers on a postcard, please. :)

Project announcement: Hitori

It's announcement time! I'd like to announce a little game I've been working on for a week or so (on and off), written because I found this amazing puzzle in a newspaper called Hitori.

A screenshot of Hitori.

Hitori is quite similar in style to Sudoku; probably because both are published by Nikoli. The objective is to remove cells from the grid so that only one of each digit remains in each column and row. However, you can't shade two touching cells, and all the unshaded cells must be connected.

I wrote an application to let you play Hitori on the computer, called – funnily enough – Hitori. At the moment, it supports board generation (algorithm courtesy of a mathematical friend of mine), full validation of solutions against the three rules, hint support, undo/redo, and two different ways of "tagging" cells as you work out the puzzle, to make it a little easier.

Version 0.1 is available as a source download, or you can pull the latest revision from the Bazaar repository at http://tecnocode.co.uk/hitori/ by executing the following commands:

mkdir hitori
cd hitori
bzr init --dirstate-tags
bzr pull http://tecnocode.co.uk/hitori

I've updated the commands to reflect the fact that the repository needs tag support.

If anybody's got any suggestions for features, the only things I'm thinking of adding at the moment are:

  • A shiny icon, if somebody could help me out with it!
  • Support for different board sizes.
  • Looking into themeable colours (or at least making sure the way they're done is HIG-compliant, because at the moment the RGB values are hardcoded).

That's it! If you've got any feedback, comment below, or contact me. :)

Hello Planet!

Hello Planet GNOME!

I'm Philip, 16-year-old programmer and GNOME user from England. Although I've been using GNOME for a while, I think it's only been a year I've been helping out. I've mostly been dealing with Totem bugs, and doing various other things to Totem; probably the most notable things I've done is adding Python and Vala support to Totem's plugin system, and convert the whole of Totem to use GtkBuilder, both of which are changes debuting in 2.20. :D

Some of you may have seen me at GUADEC; I was the lost-looking one without a laptop. ;) I was there for the full duration of the event, and enjoyed it a lot, even if I didn't manage to take full opportunity to make more friends.

As far as personal life goes, I do a lot of web development (probably evident if you look at my previous posts. I've just finished the compulsory part of my education, gaining these grades, and I've now got two more years in full-time education before I hopefully go off to university, probably to study computer science. Away from school and computers I'm into hockey and model making.

Finally, if anybody manages to break anything on this site, please tell me, as I've only just upgraded the site, so there are probably still a few kinks to work out (Jeff noticed my feeds were slightly broken when he added me to planet, for example). :)

Exam results

I got hold of my exam results for this year over the summer, both for all of my GCSEs, and for the three AS-levels I took early.

I'll cut to the chase: I got 8 A*s and 2 As at GCSE, and three As at AS-level. The two As at GCSE were in electronics and music; I was expecting a lower grade for music, but the one for electronics was a bit of a let-down. However, that isn't to say it isn't fair — while I don't agree with the exam (there was hardly any electronics in it), I think I chose a coursework project which was a bit too ambitious, and the grade reflects the fact that it didn't work.

Regardless, I'm pleased with my results, and happy for everyone else who did well. :)