Wednesday 30 January 2013

See where your disk space is being wasted

One piece of software I'm having tremendous fun with lately is Filelight. It displays a sunburst chart of folder and file sizes. It was originally written for KDE 3, but there is a KDE 4 version as well. Look it up in your distro's repos and reclaim your disk space!




Friday 11 January 2013

Automating torrent downloads

I'm a big fan of the Dakar Rally. This year's Dakar is particulary interesting to me, because, not only my favourite rider Cyril Despres is looking to an easy win now that his long time rival Marc Coma didn't start the rally due to a shoulder injury, but also because after a looong reign of KTM bikes, YAMAHA IS LEADING! (YAMAHA is my favourite brand of everything.) Since I don't have Eurosport to watch the Dakar on TV, I'm "forced" to download torrents of the coverage. This means checking The Pirate Bay all the time for new torrents and downloading them as soon as they appear. This doesn't sound too difficult. But what if you're not home? Or what if you're doing something else more important? Or what if you just can't be bothered? What then? What do you do?

You write a shell script.

Shouldn't be too difficult. This way, you can put it in CRON and it will do all the checking and downloading for you. Without stalling any further, let's get to the business.

The result page on The Pirate Bay already contains magnet links for every result. That's good. We can just strip these links from curl output and feed them to KTorrent. This is how it happens:

The magnet links are extracted and written to magnets.txt.tmp. They look like this:

magnet:?xt=urn:btih:8854f42ef801cb9c0f69caea1ca51a0a6c77c815

These are then compared to a list of existing magnets, to skip over the ones that we're already downloading. If a new magnet link is found, it is fed to KTorrent and written to the list of existing magnets for future reference.

Put that in CRON to run every 15 minutes and redirect its output to a file for debugging, like so:

This is it, more or less. If all goes well, you should have new torrents downloading and a growing list of magnets. And most important of all, you will have all the latest Dakar coverage at no fuss at all, and you'll help other fans as well by seeding torrents early. Can't stop smiling!

Update

Later I learned you can use KTorrent RSS plugin with filters to the same effect. Well, not exactly same effect. I set up the RSS feed and a filter and got exactly one successful start of a torrent. The very next one failed. "Ambitious, but rubbish." (Clarkson)

But my script still works well!

Saturday 5 January 2013

External display hotplug (on linux, with xrandr)

Every morning when I would come to the office, I would place my laptop on the desk and connect the power, network cable and the external display. And every time I'd have to go through the same external display configuration dialog. And that's just annoying. So I decided to automate. Isn't that a thrilling word? Automate.

A friend helped me write a shell script to enable or disable a twin display configuration using xrandr, and I set it up to be triggered by UDEV when an external display is hotplugged on the VGA port.

This is the script:

The two things you will probably want to change are the constants EXTERNAL_POSITION and BUILTIN_BASE. If you want the external display to show a mirror of your primary display, use setting EXTERNAL_POSITION="same-as".

I placed the script in /usr/local/lib/ and set up an UDEV rule that triggers it when an external display is connected.

This is my UDEV rule, in /etc/udev/rules.d/:

When you add the UDEV rule, you must reload rules for the changes to take effect. You do it by saying

$ sudo udevadm control --reload-rules

And that's it. Enjoy!



Friday 4 January 2013

Disabling the optical drive tray button

I use a ThinkPad T420. A great machine. The shit. I love it. But, there's a tiny annoyance. These laptops' optical drives have a protruding eject button, that's very easy to press accidentally when you grab the laptop to move it, or even just bump against it when moving your mouse. It happens quite often, too often in fact. Imagine your optical tray popping open every now and again at the most unexpected moments. Now this is really annoying. Something has to be done.

The easiest way to disable the eject button is to use the eject utility (on linux, of course). Simply saying

$ eject

will - eject the tray, you guessed it. Using it with the -i option however, will disable or enable the eject button, depending on the option argument.

Usage:

$ eject -i on

disables the device button, and

$ eject -i off

enables it. If on and off aren't recognised as valid arguments, use 0 and 1.

If I recall correctly, this worked flawlessly on openSUSE 11.4. When I switched to Chakra Linux, it didn't anymore. After extensive research I found there was an UDEV rule overriding (or working around, shall I say) the eject utility. What the solution took, was simply commenting out the conflicting UDEV rule. In my case the rule was in /lib/udev/rules.d/60-cdrom_id.rules.

I commented out the line


and reloaded UDEV rules with

$ sudo udevadm control --reload-rules.

It worked. It also works on Kubuntu 12.04 LTS, which I'm currently using, after getting too annoyed with Chakra's updates constantly breaking my system.

To lock the tray automatically (magical word) on system boot, put eject -i on in one of the startup scripts; a good place would be in /etc/rc.local. This way your optical drive will be locked on startup, and if/when you want to use it, you can unlock it saying $ eject -i off.

There you go. Another annoyance eliminated.