Archive for March, 2007

I guess it’s not “Rugby Time” any more

Saturday, March 31st, 2007

For years and years (actually, since the 1920s), Rugy has been the home of a radio broadcast used to set clocks within the UK and parts of Western Europe. From today (it’s today in the UK already, yesterday here on the US East Coast), that signal moves to Anthorn. A sign of the times means the contract finally went to $random_company.

I’ll still call it Rugby time :-)

Jon.

Anti-plagiarism service sued by straight-A students

Friday, March 30th, 2007

I was extremely happy to read about this lawsuit over anti-plagiarism software over at the Washington Post. Why? How can I think this is a good thing? Because I’ve been in a school that used such a service and relied on it utterly, and pointlessly, to the detriment of many.

The real way to catch cheats is to have sufficient staff working with students, to get to know them, to understand them, to offer quality education. When a good educational environment is created, there is no need for automated software because the teacher knows his/her students well enough to make the call. That’s my opinion, anyway. In my opinion, introducing software to do the job of quality teachers only serves to pander to those who would have 1000 students in a class and a teacher so overworked they struggle to name even a handful of the students they’re seeing on a daily basis. And I’ve seen that kind of situation, too.

Jon.

Spring in Cambridge

Monday, March 26th, 2007

Photo: Walking along the banks of the Charles.

If I ever had to rethink my decision to choose Cambridge to live in, I should think that I would regret living anywhere else. Cambridge is truly a wonderful place, filled with so many interesting things to do and great for the people watchers in all of us. And then, there’s the Charles (an old foe of the British, but we don’t talk about that…), which has finally thawed and gives off a shimmer and glow in the mornings as one strolls along its banks. And I’ve been doing a lot of that lately. At least a couple of times a day, over the past few days, I’ve taken to doing a 5-10km walk, latte in hand (more than 15 shots some days at the moment), with only the most powerfully depressing of power ballads as my companion along the way…yes, I’m even listening to Roxette. Indeed. Yes, I know.

My favorite route at the moment is to head down Mass. Ave from Central, toward Boston (over Harvard Bridge), then make a left and head down toward the Charles MGH T-stop. Then, turn onto Charles St. and wind up at the Public Gardens. A quick walk and you’re on the Common, and then at the T-stop. One can either take a T back to Central or walk back via the Museum of Science and take another bridge, toward Kendall, and then onto Central. Either way, this is a very enjoyable morning/evening stroll. Even if you’re down in the dumps and feeling rotten about your inability to understand the most complex problem there is in this life. As with anything else one wants more than anything else in the world, one can but try :-)

Jon.

HOWTO: Spend a Sunday afternoon

Sunday, March 25th, 2007

So I decided moping around the apartment listening to super depressing music was only going to be so useful and headed outside for some thinking time between me, myself, my latte and the Charles. $500 of impulsive purchases later and I can report feeling no happier, but I did manage to waste an afternoon. Oh and I discovered my iPod is currently incompatible with Nike+iPod (after buying it). I guess that’s something at least.

Track du jour: The Corrs – What Can I Do?

Jon.

Update: After faffing around (read: converting said iPod to HFS+, screw you, Apple, for not supporting VFAT formatted iPods under OSX – an obvious failing and also obviously intentional – I’m switching it back to VFAT when I get time, via dd/mkfs) and reflashing to firmware 1.3 I now have a working Nike+iPod. I don’t like Nike one bit but I needed cheering up, and so far (aside from problems with the sensor detection in areas of obvious interference) I’m reasonably happy with it.

Turkey, India, who do we pander to next?

Tuesday, March 13th, 2007

I was disturbed to read a story just now that Google will be handing over the IP addresses of people expressing opinions negative to some arbitrary standard held by the Mumbai police. Just like Turkey and their “offending Turkishness”, these folks want to go after people expressing negative views about India on social networking sites.

We live in such a free world.

Jon.

Uncle jcm…I’m now officially old

Thursday, March 8th, 2007

So my sister finally gave birth last night to my nephew. Oscar Wrigley weighed in at around 8lbs, 8 ounces (if I heard that right over the phone – I’m sure there will be photos, and other updates from the new parents themselves). I’m very happy for them.

Anyway. This makes me officially old now. I can see it now – “crazy uncle Jon, who lives in America” – perhaps with a few interjections about me being a “traitorous dog” from my father. Still, I’ve got a bit of time to work on the “cool uncle” aspect.

Jon.

Playing with Python

Thursday, March 8th, 2007

So I like nothing more than to spend the early hours of every morning looking at anaconda source[0] in the hopes of learning more about some of the more fun things one could to do with Python, if one felt so inclined. Actually, that’s partly true – I am trawling through the anaconda source at the moment of my own volition – everything from figuring out the pipe communication startup hacks in mini-wm/Anaconda to the isys library. Why? Because I work at a company that has heavy reliance on Python and feel I should better understand the language, and use it more in my own work as a result. Besides, I’m not a perl weenie, I should write fewer shell scripts, and I’m not particularly desperate to go near a Java compiler, having been subjected to that more than quite enough in college.

I actually quite like Python. I’ve written a bunch of scripts using it, but nothing huge and I tend to write very C-like imperative code in “OO” languages – even when I’ve played with pygtk in the past. Still, that’s just fine. One of the things I have been doing is reading up on the more interesting features of the language, best practices, and the like. I’m using the two standard O’Reilly books as a reference and the online p.o documentation. The point of the exercise being that I’m reasonably keen to know how I “should” approach writing Python code, as opposed to my hackish approach in the past. I want to understand the intricacies of classes in Python, pickling, the internal differences between pyc and pyo “optimised” bytecode and some of the more funky APIs – like the HAL/gtk bindings I’m going to be playing with some more.

Anyway. That’s all fairly boring. Not having looked at Python’s more funky features in a while, I wanted to dive right in and write some simple C/API plugin to play with Python Objects. This turns out to be a little harder these days than the (normally excellent, but in this case not so much) python documentation would have you believe. Here’s a simple test “library” I wrote to figure it out:

/*
 * pytest - playing with Python's C API.
 */

#include <python .h>

static PyObject *list_set(PyObject *list, PyObject *item);
void initpytest(void);

static PyMethodDef pytestModuleMethods[] = {
        { "list_set", (PyCFunction) list_set, METH_VARARGS, NULL },
        { NULL, NULL, 0, NULL }
};

void initpytest(void)
{
        PyObject *m;

        m = Py_InitModule("pytest", pytestModuleMethods);

}

static PyObject *list_set(PyObject *self, PyObject *args)
{
        PyObject *list, *value;
        int item;

        if (!PyArg_ParseTuple(args, "OiO", &list, &item, &value))
                return NULL;

        if (!PyList_Check(list))
                goto error;

        if (PyList_SetItem(list, item, value))
                goto error;

        Py_DECREF(value);
        return Py_None;

error:
        Py_XDECREF(value);
        return NULL;

}

You can compile this into a dynamically loadable (read: Python can use it) library on most Linux systems by driving the gcc front end, thus:

gcc -o pytest.so -g -shared -fPIC -Lpython -I/usr/include/python2.4 pytest.c

(this enables debugging, “-g”, and assumes a default 2.4 python installation, such as that on my Fedora Core 6 desktop box that I’m using today).

Once built, such libraries can be used very simply:

[jcm@perihelion pytest]$ python
Python 2.4.3 (#1, Oct  1 2006, 18:00:19)
[GCC 4.1.1 20060928 (Red Hat 4.1.1-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytest
>>> foo=[1,2,3]
>>> print foo
[1, 2, 3]
>>> pytest.list_set(foo,0,2)
>>> print foo
[2, 2, 3]

It’s a simple example, pytest provides a single function that changes values in Python lists. Everything in Python is an object, and there is a need to be aware of reference-counting that’s happening underneath (well, sometimes you need to worry about it). Every C/API extension needs to define an init function, which educates the Python runtime about those functions it provides – in this case, the list_set function. These are defined in a NULL-terminated PyMethodDef array, and usually defined to require METH_VARARGS argument passing (I’m sure this was once different).

Actual functions, such as list_set work in PyObjects (everything’s an object) too, using PyArg_ParseTuple to pull out C-style arguments, according to a format string. They also need to use occasional calls to Py_DECREF (and it’s NULL-friendly wrapper counterpart, Py_XDECREF). Though this varies – for example, in the above, PyList_SetItem “steals” a reference to “list” and so I don’t need to worry about freeing that particular reference. The documentation tries to explain what needs tracking.

Anyway. This has been a random post. For those of you who are already die-hard Python programmers, I’m sure this is old-hat – and that’s appropriate to us now-officially-old uncle-types (my sister just gave birth last night). For me, it’s stuff I looked at too long ago but didn’t have a need for. Now that I’m looking at writing more funky stuff using Python, I’m working on becoming a Python nut, just like you :-)

Jon.

[0] The installer that was originally written by Red Hat (and used by a metric fucktonne of other people and projects needing a graphical Linux* installer not based YaST, Debian, or their own custom code). The thing that I (blindly, thanks to my previous Debianiteness/Ubuntu craziness that I’m recovering from over time) used to criticize because it wasn’t the d-i du jour. Actually, anaconda is a very powerful Linux installer that gets a lot of things right. And when you stop blindly agreeing with Debian rhetoric, this becomes abundantly more apparent (this isn’t an anti-Debian rant).

Anaconda’s source can probably best be described as something that seems to have evolved over time. There are top level classes (like Anaconda) and some OO concepts in there, but it’s still largely a tangled mess of functions/function pointers (method object references, whatever) that works out in the end. Not that I’m being critical – I’m sure I couldn’t do it any better – but it’s certainly useful to pick at :-)

* I think some people have used anaconda for non-RPM distros, but I’m not aware of anyone trying to install weird stuff like Open Slowaris with it. Random aside: Sun seem to have stopped holding up a new edition of Slowaris Internals. There’s a new edition in Borders, covering Open Solaris and Solaris 10. It’s a shame it’s a bazillion years too late (the last edition was on Solaris 7, and like, totally ruled, dude) but then, I expected nothing less than to have to wait almost a decade for an updated edition. At least they now give out source code to the OS – unlike the many times I asked for it as a student and was told the programme was temporarily suspended…a million years ago.