August 21, 2013

openSUSE 12.3

Here is a random recommendation for openSUSE 12.3.  It seems that, while we were all busy moaning about GNOME's recent-ish design decisions, KDE has gradually been becoming absolutely awesome.  Loads of features, fast, stable and looks beautiful.  Switching to openSUSE with KDE after using Fedora with LXDE (up to version 17) is like waking up from a horrible dream.  There were only a tiny number of things that I needed to tweak or fight against after installation.

To whichever programmer did the extra fiddling to make things such that the assignments of the other mouse buttons, no matter how weird, are preserved when you switch between right or left-handed mode: I noticed it and appreciate your work - thank you.

Fun with linking data files

Here's a neat trick that I recently discovered, from here.  Say you have a data file which is needed by your program, and you don't want to bother with installing it in /usr/share/somewhere and having to "make install" every time you want to test a tiny change.  You would also prefer to edit it as a separate file, not weave it into your other source code somehow.  You can achieve this by creating an object out of the file itself and linking it into your binary.  The procedure is quite simple:

$ ld -r -b binary -o myfile.o myfile.txt
$ gcc myprogram.o myfile.o -o myprogram

Then, in C:

extern void *_binary_myfile_txt_start;
extern void *_binary_myfile_txt_size;

void get_data()
size_t len;
char *v;

len = (size_t)&_binary_myfile_txt_size;
v = malloc(len+1);
memcpy(v, &_binary_myfile_txt_start, len);
v[len] = '\0';
printf("myfile.txt contains '%s'\n", v);

Contrary to what's implied by the original article, I don't think you can assume that the data is zero-terminated (why would it add a terminator?  It's binary data as far as the linker is concerned, not text).  This example code includes some extra faffing around to add the terminator.

This technique works quite nicely with automake as well.  In, I put something like this:

src/myfile.o: src/myfile.txt
ld -r -b binary -o src/myfile.o src/myfile.txt
LDADD += src/myfile.o

I use a single at the top level of my project, avoiding "recursive make" where possible, so everything is prefixed with "src/".  The symbols used to find the data in the program therefore look more like this:

extern void *_binary_src_myfile_txt_start;
extern void *_binary_src_myfile_txt_end;

Disadvantages of this technique?  "ld" is not the linker on all platforms supported by autotools, e.g. Mac OS X, so it's not very portable.

How much security is too much?

I've been discussing the recent controversy over mass surveillance with friends and colleagues.  I was struck by how many of them seem to be absolutely fine with it, because "it's to protect you" and "if you haven't done anything wrong, you have nothing to hide".  Perhaps needless to say, I completely object to this kind of mass surveillance for many different reasons.  At the time, I couldn't quite work out why I was so much more offended by the idea of mass surveillance than the people I was talking to, and we decided that it was "because I do so much more online than other people".

But having thought more about it, I can see that this isn't true.  If anything, my exposure to this kind of thing is less than many other people because I know how to take precautions.  Things like using SSL as much as possible, making careful decisions about where to store my data and knowing one end of a PGP key from the other.

The real reason is simpler.  Killing innocent people is such a heinous crime that almost any measure might be justified to prevent it.  It's very hard to look someone in the eye and say that you honestly believe that certain measures should not be taken if there's a chance - however miniscule - that it could prevent them or their child from being killed.  Try it - it's a really nasty thing to do!  But what measures are too much?  Different people have different opinions on what security measures are acceptable, and that's fine.  But many of the measures already taken are unacceptable to me personally, and I don't like that things are getting worse.

  • I draw the line at having all my personal and private communications rummaged through by people I don't know.
  • I draw the line at having absolutely no rights whatsoever if detained and questioned in the UK while in transit through an airport.
  • When I travel, I draw the line at being forced to have an X-ray beam shone directly into my eyes by a "security" scanning machine, especially when I'm not allowed to know anything about how the machine works [1], and having naked pictures taken of me and my (hypothetical) children at the airport [2].  Seriously, if this is acceptable under child pornography laws, then there's something wrong with those laws.

If we don't fight back, we'll get more and more of this kind of thing.  Where will you draw the line?

[1] I plan my itineraries to avoid Manchester airport, even though it's very often conveniently located for me, because it makes particularly extensive use of these scanners.  They recently switched from X-ray to millimetre wave machines, a big improvement, but they only did so because of an administrative issue.

[2] Yes, I realise that most scanners now use "automated threat detection", and I agree that it's a big improvement.  However, I have very little confidence that the machines don't have some kind of test mode which circumvents this, and that no mistakes will ever be made.  As for "the machine doesn't produce a naked picture" - well, it's an image taken using radiation which interacts strongly with your skin and very weakly with your clothes.  If I had to write a textbook definition of a naked picture, that would be precisely it.  And this looks like a naked picture to me.

July 28, 2013

GPG public key

Encrypted email is welcome to any of my addresses.
Key fingerprint = 4E1F C14D 0E0A A014 FE5D 3FC6 C628 75D1 D4CA 4C30

$ gpg --keyserver --recv-keys D4CA4C30

Version: GnuPG v2.0.19 (GNU/Linux)


March 3, 2013

Flame Challenge

I've entered the Flame Challenge.  The challenge, specifically, is to answer the following question, scientifically (i.e. not poetically), for an 11 year old, in 300 words or less or as a graphic or video entry.  The entries will be judged by 4th-6th graders in schools in the USA.  It was too much of a challenge for me to resist, and now that the deadline has passed I can reveal my answer:

What is time?

Imagine looking at every slice of a loaf of bread, one by one, starting with the crust at one end and progressing towards the other. First you'd see the crust, then you'd see all the slices from the middle of the bread. If the loaf had an air bubble inside, then you'd see a hole in some of the slices. The slice from right at the edge of the bubble would have a small hole, and the ones which were cut right through the middle of the bubble would have bigger holes. On your way through the slices, you'd see a small hole first, then a bigger one, then another smaller one, then no hole at all.

The passing of time from moment to moment is like moving from one slice to another. Many things stay the same, just like every slice of a loaf of bread looks roughly the same, but some things change --- like the sizes of the holes in the bread slices. Things that change quickly, like an explosion, look very different from one "slice" to the next. Things that aren't changing at all look exactly the same in every slice. Something that's moving, like a car, changes its position from one slice to another.

When you think of time this way, you see that the passage of time is quite similar to moving along in distance. This is actually how scientists often think about it, too. Have you heard of Einstein's Theory of Relativity? That's based on treating space and time as very similar things. The main difference is that we have no choice but to move forwards in time. You can choose to stop moving through the slices of bread and spend longer looking at a particular slice, but you can't stand still in time!

My approach was to make the link between the dimension of time and the dimensions of space by using a familiar household object.  There's so much more that I could've added with a longer word limit, like how things can be measured in time and space by creating an object that changes its appearance regularly along the dimension of interest.  A ruler is just a stick which looks slightly different as you move along its length (the numbers go up), and a clock is just an object which looks slightly different as you move through time (the hands go round).  You can even extend the concept of a crystal to dimensions of time as well, making a space-time crystal.  What I find most interesting of all is how our perception of time is linked to its physical reality: exactly why are we compelled to advance through time, while having apparent free will concerning our movements in other dimensions?  Is it all in our heads?  Perhaps somehow related to the second law of thermodynamics applied to the physical and chemical processes in our brains?

The winners will be announced at the World Science Festival in June this year.  In the unlikely event that I win a trip to NYC at that time, I'll be flying in a highly sleep-deprived state from an experiment at the Linac Coherent Light Source.

November 27, 2012

Ten years of Sylpheed

This came up on one of my mailing lists recently, and I realised that I've also been using Sylpheed as my email client for ten years.  Since shortly after I started using Linux, in fact.  It was the very first program I compiled and installed from source, and I remember being taken through the process of learning the difference between "libgtk+" and "libgtk+-dev" by a kind helper on IRC.

A whole decade later, I'm still using Sylpheed almost every single day.  In all that time, text editors, web browsers, version control systems, desktop environments, IRC clients, IM clients, window managers and even types of input device have all come and gone from my computing environment.  Sylpheed simply never gave me any reason to replace it.  In ten years, I think I can remember it crashing a single digit number of times.  It's always one of the first things I install on a new machine - and my current laptop is my third such new machine since then.  That's not including two work machines, where it was also the first thing I installed.

Discounting things like the kernel, SSH, the X server and so on, the only other program that's achieved this is GKrellM, and that's only because the Sylpheed email prompted me to think about and remember it.  In fact, not even the X server has survived these ten years: in 2002, it was XFree86.

An impressive feat, and a mark of true software quality.  If anything I produce lasts ten years on even one person's screen, I'll be very happy indeed!

Which programs, if any, survived the last ten years on your desktop?

August 9, 2012

Reproducible random ordering from "sort -R"

Random discovery for the day (actually yesterday, but never mind): "sort -R", which randomises the order of lines in its input, uses a crytographic random number generator seeded using numbers which include its PID and the time.  It's the same random number generator as used by "shred": ISAAC.

So, if you need to get the same random order of lines each time, as I did for a test script, you need to provide your own source of "random" numbers.  Any old binary file will do, for example:

$ sort -R --random-source=/bin/ls

March 2, 2012

Remote control repair

I repaired my DVD player by replacing the IR receiver for the remote control.  It hadn't worked since about 2005, but I'd been hesitating about actually sorting it out.  Admittedly, for a lot of that time I was convinced it was the remote control itself that was defective, and didn't want to give my credit card details to one of the many dodgy-looking replacement remote control websites.

Anyway, in case anyone's interested, the model was a Panasonic SC-HT520 and the replacement part I used was a Vishay TSOP 1838 (example , but the photo shows the wrong thing) which uses a 950 nm wavelength and a 38 kHz carrier.  The pin assignments are exactly the same as the original one from the player, so you just have do undo some screws (hint: take the grey panel off the front of the DVD tray before disconnecting the power), desolder the old one and solder the replacement. The tracks on the PCB are nice and large, so it's dead easy.  Total cost: €1.55, and about half an hour (plus many hours of research and figuring out what would be suitable, but that doesn't count).

I remember reading somewhere that the receivers on certain Panasonic units often seem to go bad, so if anyone is interested and needs more guidance than the above, post a comment here and I'll put some photos up.

October 4, 2011

Project X

I'm still here, and programming.  Work has been taking up most of my "programming brain" recently, but the results will hopefully be released as free and open source software very soon.

For the last few months I've been working on a new non-work project as well, which I'm not going to say too much about just yet - let's call it Project X for now.  It's a piece of major "itch scratching" for me, but I have a feeling that many other scientists who use Linux will love it.  Perhaps many other people besides.  Watch this space...

July 6, 2011

Command line weight loss

$ sudo setweight --bmi=21

It'd be nice if it were that simple.  But it almost is!

Scales of Truth
is a command line implementation of The Hacker's Diet.  The basic principle is to lose (or gain, I guess, theoretically at least) weight by taking an engineering approach to your body's energy requirements. There are quite a few implementations of this or similar things (e.g. The Hacker's Diet Online and Physics Diet), and an important feature is that the required day-to-day administration, i.e. typing in your weight, is not very time-consuming.  Less than five minutes a day?  Well opening a website, logging in, typing a value in and so on seems like a lot of work to me.  With Scales of Truth, you simply click over to one of the many terminals you no doubt have open, and type:

$ sot XXX

Where "XXX" is your current scale reading (in your choice of unit).  Scales of Truth does all the necessary calculations, backs up your readings using Git (because losing months of figures would really suck), and displays some interesting statistics:

Current mass estimate: XXX kg (instantaneous BMI XX.X kg/m^2)
7-day change: -.42 kg (-1757.2 kJ or -419.9 kcal per day)
30-day change: -2.77 kg (-2704.2 kJ or -646.3 kcal per day)

If you happen to miss a few readings, it interpolates the missing values automatically so your running average stays up to date.  For the average reader of this site, the whole procedure probably takes slightly less than two seconds.  That is, assuming you can resist taking a look at your progress using "sot --graph":

sot.pngThat's my own graph for the last few months, so I've taken the liberty of removing the actual numbers.  Suffice to say that each tick on the mass axis corresponds to two kilograms, and I'm rather pleased with progress so far...

You can download Scales of Truth right here.  Simply download the file, open it in a text editor, satisfy yourself that it's not going to do anything evil to your computer, then follow the instructions.

Recent Comments

  • Rahul: Excellent article. This is one of the few articles on read more
  • Tom: To answer the questions from "axizhe", the DRM module resides read more
  • SUMIT PANWAR: A good piece of information for some one like me, read more
  • axizhe: Hello, i find very interesting all this information: anyway i read more
  • Tom: Sure, I just never quite got round to installing it.. read more
  • Maurus Cuelenaere: Have you seen Rockbox? read more
  • JonB: Hi Tom, Michael Berry's work is deeply enchanting and one read more
  • uzi18: Nice, to consider why such SD Slot is not isolated read more
  • Graziano: Beware that most Ati video card, despite the free software read more
  • uzi18: Nice :) So waiting now for new code to test read more

Recent Assets

  • sot.png
  • after.png
  • during-2.png
  • during-1.png
  • before.png
  • p2100009 (Modified).jpg
  • pc170019.jpg
  • kms-fr-almost.jpg
  • tuxmessenger.png
  • openmoocow.png
OpenID accepted here Learn more about OpenID