Author Archive

Graphical = good and command line = bad?

It is not uncommon to hear (mostly from Windows users berating Linux and its “useless console”) that one of the benefits of Windows is that everything can be done through a GUI. After all, clicking on icons and finding stuff in menus is more intuitive, and everything is easier that way. In contrast, with Linux you have to “type an awful lot of things, which is boring, slow, and difficult. And ugly”.

Now, don’t get me wrong, GUIs are great. I quite like them. What annoys me is the lack of command-line interface for some tasks. Both GUIs and CLIs have their place in computer use, and the wise should use each when appropriate. In this post I will try to illustrate a case where the automation allowed by using the CLI and some scripting is largely missed. The user (me) is forced to use an “intuitive” GUI, with the result that my patience takes a direct hit below the flotation line.

The first task I faced was to plot some orbitals of a molecule. The data for each orbital is saved in one file, and I am running a program that can read them and plot the given orbital (Molekel).

The following YouTube video, made by myself, shows the process of plotting 2 orbitals (I had to plot 17). Notice that, due to the program running so slow, the process takes around 1 minute per orbital!

Notice also that all the previous work has been done: choosing the colors of the background, atoms and orbitals, choosing the orientation, opening the atomic geometry… The comprehensive list of what to do for each orbital follows, with each line preceded by the point in time (seconds) when it happens:

  1. 00.00 – Click on “Delete surface” to remove previous orbital
  2. 07.80 – Click on “Load” to load a new orbital
  3. 12.67 – Choose a file from the dialog window, and click on “Accept” to load it
  4. 30.27 – Click on “Both signs”, because we want both positive and negative part of the orbital
  5. 31.33 – Introduce a value for the isosurface (0.05) in the “cutoff” box
  6. 33.13 – Click on “Create surface” to have Molekel render the isosurface
  7. 37.33 – Isosurface appears
  8. 37.93 – From a drop-down menu (called with right-click of the mouse), choose Snapshot -> RGB
  9. 52.66 – “Save as” dialog box appears
  10. 62.73 – Introduce filename for snapshot, and click “Accept”
  11. 65.00 – We’re done, and can repeat the process for the next orbital

One can’t help but notice that 65 seconds are needed to make eight clicks and introduce a short text in two boxes! The issue is that human attention is necessary during the whole 65 seconds, because the time between actions is too short to do something else in between (although long enough to get on your nerves, like the full 15 seconds to have the “Save as” dialog appear).

Another obvious point is that from the two short texts introduced by the user, one (the value of the isosurface) is always the same, and only the other (the name of the file to save the snapshot as) varies. Also, only one click of the 8 we do is ever different (the choice of orbital file to read). It would be nice to have a robot do this task, the only data we would have to feed it being a list of orbitals (to read, and then to save a snapshot). But we can’t. We are stuck with this sluggish process!

In contrast, I will next show a case where some automation was made. The process is that of cropping the snapshots taken in the previous step (the Molekel thing). Sure, we could use GIMP, or some other GUI tool, but applying exactly the same process to a list of 17 images (and this is a short list, it could have been 1000) is the kind of thing that cringes for automation.

The following video shows the process:

Recall that it takes 4 minutes to process ALL the images. This may not sound like a huge improvement over the 18:25 that it (in principle) took the process above (17 x 65 sec). However, the time spent with Molekel scales linearly with the number of orbitals. 100 orbitals would need almost 2h. The automated cropping process would have taken more than 4 minutes, but only slightly more: maybe 5 or 6.

Also notice that the 4 minutes are full of decisions, and there is no repetitive, unnecessary task (except the fact of committing errors). Let’s take a look at the actions taken during the 4 minutes:

  1. 00:11.00 – Open a Perl script I had half-done (another benefit of automation: you can reuse old stuff)
  2. 00:17.87 – Shade window to take a look at the number and name of files to process
  3. 00:21.33 – Change script accordingly
  4. 00:47.93 – Save changes
  5. 00:51.60 – Back to the CLI, and run the script
  6. 00:55.00 – Ups, nothing happened!
  7. 00:58.27 – Reopen the script, and look for the error
  8. 01:05.53 – Found it. Fix it.
  9. 01:07.33 – Save and execute
  10. 01:06.87 – It works!
  11. 01:13.00 – Finished running (0.36 sec per picture)
  12. 01:21.73 – Open a cropped image in viewer
  13. 01:22.93 – Realized the crop is wrong!
  14. 01:30.73 – Alt-Tab to script file, to modify it
  15. 01:55.67 – Save and execute again
  16. 02:11.73 – Open the cropped images. The first one seems to be OK!
  17. 02:29.80 – We reach one that is wrong
  18. 02:34.20 – Back to the script, and fix it
  19. 02:45.07 – Save, and back to CLI to re-run
  20. 02:53.00 – Reopen in image viewer
  21. 02:56.00 – Cropped part is not centered!
  22. 03:02.00 – Back to the script, and fix it
  23. 03:12.33 – Save and re-run
  24. 03:19.73 – Reopen in image viewer
  25. 03:27.87 – Yet another error: an image could have been cropped more, to hide an unwanted part
  26. 03:32.40 – Back to the script
  27. 03:40.80 – Rerun
  28. 03:47.13 – Reopen images
  29. 03:59.93 – See that all of them are correct. Stop and rest

Recall also that if I were to repeat both processes tomorrow, the image cropping would simply require to run the script again (0.36 seconds per image, and you can do something else in between, if you have 1000 images and don’t want to waste time waiting). The creation of the orbitals, on the other hand, would require to repeat the whole process again!! (65 seconds per orbital, plus you have to spend that time paying attention to the process. You can not run something and go away). And the whole problem with the creation of the orbitals is that there is no command-line way of doing it, to be able to automate it.

Comments (3)

Re-partitioning a disk infected with Vista to dual-boot with Linux

Some time ago I helped a friend to install Linux into a Vista laptop (incidentally, another friend asked me about the subject today). The only aspect I’m covering in this post is the re-partitioning of the disk, which is a wee bit trickier than with XP and previous Windows versions.

With my laptop (one with XP preinstalled), I just inserted my favorite Linux CD, rebooted, and used the built-in partition utility that all Linux installation CDs have to downsize the Windows partition, and then make the Linux partitions in the remaining disk space. With Vista this is not the case. You have to be very careful, because Linux can not resize the Vista partitions (at least at the time of writing these lines). The problem is that Vista uses a modified NTFS format, and Linux can not cope with it yet (read more at my source for this info: pronetworks.org).

You can also find at pronetworks.org a detailed HowTo for making the resizing of a partition. In summary (e.g., for shrinking a partition to make room for Linux):

  1. Go to Control Panel -> Administrative Tools -> Computer Management
  2. Click on Disk Management (under Storage in left hand panel)
  3. Locate partition to shrink, right click on it, and from the context menu choose Shrink Volume
  4. Fill in the self-explanatory dialog box. Basically, enter amount of MB you want the partition to be reduced by.

You will thus end up with a smaller Vista partition, and some empty space. Now, you can insert the Linux CD, reboot, and install Linux in that empty space, without touching the Vista partition.

Comments

Extracting audio from a YouTube video

This HowTo really has two parts:

1 – How to download a video from YouTube
2 – How to extract audio from any video

The second step is not limited to videos obtained in the first step, and the first step can obviously be made for the sake of it.

How to download a video from YouTube

When you play a video on YouTube, the contents of a FLV file are streamed to your screen. Downloading this FLV file is a bit more tricky than it should be, because there is no direct indication of the URL of this file in the code of the page of the video.

Apparently some guys got over it, and they made the software I use to do the job: a Firefox extension called DownloadHelper. Using it is so easy: a three-sphere icon appears to the right of the URL bar of Firefox. When a page contains material that can be downloaded with DownloadHelper (such as a YouTube video), the spheres in the icon are colorful and move (otherwise they are grayed-out, and still). You can then click on the icon to see a list of items to download, and choose the one you want (usually the .flv file).

How to extract audio from any video

It is so easy to do from the command line. First we use MPlayer to extract the audio in PCM/WAV format:

% mplayer filename.flv -vo null -ao pcm:fast:file=filename.wav

Then, we make use of oggenc to encode the WAV into Ogg Vorbis. For example, to encode with quality level 7 (a reasonable tradeoff between quality and size):

% oggenc filename.wav -q 7 -o filename.ogg

And that’s all to it!

Comments (2)

Flash: better without Flash

Remember my previous post about a problem with Flash in Firefox/Iceweasel? Now the second part.

After following my own instructions, I ended up with a Flash instalation that could play YouTube videos correctly, but some other Flash animations would not work. By chance, my computer at work would reproduce any Flash animation just fine, so… why would that be?

To find out the reason, I have compared what Flash-related packages I have installed in Homer (my computer at work) and Heracles (the one at home). The result is quite surprising:

Homer[~]: aptitude search flash
p   flashplayer-mozilla       - Macromedia Flash Player
p   flashrom                  - Universal flash programming utility
p   flashybrid                - automates use of a flash disk as the root filesystem
p   libflash-dev              - GPL Flash (SWF) Library - development files
p   libflash-mozplugin        - GPL Flash (SWF) Library - Mozilla-compatible plugin
p   libflash-swfplayer        - GPL Flash (SWF) Library - stand-alone player
p   libflash0c2               - GPL Flash (SWF) Library - shared library
p   libroxen-flash2           - Flash2 module for the Roxen Challenger web server
p   m16c-flash                - Flash programmer for Renesas M16C and R8C microcontrollers
p   vrflash                   - tool to flash kernels and romdisks to Agenda VR
Homer[~]: aptitude search swf
p   libflash-swfplayer        - GPL Flash (SWF) Library - stand-alone player
p   libswf-perl               - Ming (SWF) module for Perl
p   libswfdec-0.5-4           - SWF (Macromedia Flash) decoder library
p   libswfdec-0.5-4-dbg       - SWF (Macromedia Flash) decoder library
p   libswfdec-0.5-dev         - SWF (Macromedia Flash) decoder library
v   libswfdec-dev             -
p   pyvnc2swf                 - screen recording tool to SWF movie
v   swf-player                -
p   swfdec-mozilla            - Mozilla plugin for SWF files (Macromedia Flash)
p   swfmill                   - xml2swf and swf2xml processor

Yes, Flash works perfectly at Homer because it has no package installed with swf or flash in their name! And I don’t have any Gnash package installed, either. I removed all swf/flash-related packages on Heracles, and now Flash works perfectly in my home computer too.

Comments (11)

Ignoring some file in a Subversion working copy

Sometimes you have files littering a svn working copy, but you don’t want to put them under version management. Often times it is impossible, or plain painful, to delete them, and having them appear in all svn status calls is uncomfortable. This can happen, for example, if you keep a repository of Python files. When a Python script is called from another script (a module, for example), a .pyc file is generated (a “compiled” version of the called .py module, that is just faster to load next time).

Clearly, you don’t want to put the .pyc files in the repository, but deleting them everytime you manage the working copy is painful. For that, you can make svn ignore some files, like e.g. .pyc files. You can do that in at least two ways: specifically for a directory, or as a general preference.

Setting ignore property on a single directory

You can set a property on any directory of a working copy, so that the chosen files in that directory will be ignored by svn. For example:

% svn propset 'svn:ignore' '*.pyc' pythonfiles/

will make svn ignore all .pyc files in the directory “pythonfiles”, but not those in other directories.

Setting ignore patterns globally

You can edit the ~/.subversion/config file, and add “*.pyc” in the line starting with "global-ignores =". For example, my such line is:

global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store *.pyc *.swp

It works immediately, and for all the calls to svn status you do in any working copy on that machine.

Comments

Flash player problem in Debian Lenny: “This SWF file is known to trigger bugs in the swfdec decoder.”

[Update: read a more recent post]

I have recently come accross this problem, and I am posting the solution I just found. The problem is the following: when trying to watch any online flash animation with Iceweasel on my Debian Lenny (e.g. in YouTube), instead of the video, I got a grey window, with the following black letters on it:

This SWF file is known to trigger bugs in the swfdec decoder. Playback is cancelled.

This bug can be followed in this August 2007 thread at donarmstrong.com. I am amazed why it didn’t affect me sooner than this week, but oh well…

The steps that fixed the issue for me where to install two packages. I am not 100% sure the first one was needed, though. I first installed the package flashplayer-mozilla, which uninstalled flashplugin-nonfree as a side effect. This step alone fixed nothing.

The second step was to actually read the donarmstrong.com bug report, and see that it says that “This is fixed in swfdec-0.4.2 […]”. Great! I did a aptitude search swf, and found out that Lenny has libswfdec-0.5-4, and a swfdec-mozilla that depends on it. I installed the latter, which obviously also installed the former, plus it removed swf-player and libswfdec0.3.

After that, I opened Iceweasel again, and now flash works!

Comments (2)

rip2ogg released

I have released (how pretentious!) rip2ogg.py, the wonderful CD ripper everyone was waiting for. You can check its “home page” at isilanes.org.

Why did I do it? Well, one of the wonderful tools GNU/Linux provides to rip CDs is KAudioCreator, which is very neat. However, it has some shortcomings I wanted to overcome (again, how pretentious!):

  1. It’s slow. It rips the CD to WAV and encodes the ripped WAVs to Ogg in parallel, while rip2ogg.py does both things sequentially. Yet rip2ogg.py is 40% faster! I have ripped a whole CD in 14 minutes with KAC, and in 10 minutes with r2o.
  2. You can not have arbitrary character substitution, just one, and the interface for that is horrible. For example, with KAC it’s very simple to substitute every blank in the track name with an underscore. BUT I have found no way to provide KAC with two lists, so that it substitutes every character in the first list with the corresponding character(s) in the second list.
  3. You can change the track title to get a “nice” filename for the Ogg, but the change is also reflected in the “track tile” tag. You can not tell KAC to substitute a “ñ” in the title for a “n” in the filename, but to keep the “ñ” in the “tag title” tag.
  4. KAC is not able to rip all CDs. It sometimes chokes on DRM‘d CDs, and copes horribly with scratched surfaces. In contrast, the programs rip2ogg.py uses to rip have never failed for me. More than once command-line was my only way of ripping some rogue CDs. KAC simply couldn’t.

In the end, it all boils down to be able to control what the ripper is doing. To do so, I decided to make this simple script.

Obviously it is FLOSS (GPLv2), so use, modify and redistribute to your heart’s content!

Comments

Interesting TeX tricks

Simply a page with some interesting TeX tricks: volkerschatz.com.

Comments

Labeled breaks in Python

I am a recent fan of Python, a very neat scripting language.

One thing I miss from Perl is the availability of labeled breaks. What are those? Suppose you have two nested loops. When a condition is met in the inner loop, you want to exit both loops. With Python there is not straightforward way of doing it. Imagine we are reading an array of data, line by line and column by column, and we want to exit when meeting the first zero value. With Perl:

LINELOOP: foreach my $i (0..$lines)
{
  COLLOOP: foreach my $j (0..$columns)
  {
     break LINELOOP unless $val[$i][$j];
  };
};

A simple “break” will exit the innermost loop, but we can use a label to exit a specific loop. However, in Python there is no such a thing as a labeled loop, as explained in this PEP.

My rant is with the explanations given by van Rossum himself in Python mailing list to reject the change:

1. The complexity added to the language, permanently.
2. My expectation that the feature will be abused more than it will be used right.

Wow! Incredible reasons!

The first one is silly: other languages have it, and it has worked fine. Adding complexity to a tool for the sake of it is really stupid, I agree. But the fact is labeled breaks would be tremendously useful, so the increase in complexity would be justified. Surely a language that can only print “Hello world” would be less complex, yet of little use.

The second reason is absolutely over-the-shoulder-of-the-users. So now good old Guido must guide his sheep along the “correct” path, lest we get lost! He is punishing the good programmers by not giving them a useful tool, so that bad programmers are protected from their stupidity. It’s like not selling cars at all because some people drive while drunk.

Just my 2 cents…

Comments (3)

Homemade Minority Report-like finger tracker with a Wiimote

When I see videos like the following, I always think two things:

  1. There are always freaks out there that will do anything with anything. They keep this world spinning, and I thank them for that.
  2. There are sooo many things that can be done with nowadays technology and a little bit of wit. Why don’t we see all that in stores? Nintendo, or anybody else, can’t do it? Or they don’t want to do it? In both cases… why? Obviously for marketing reasons, and because they want to maximize their benefit, not users’. The reader should think twice on that before assuming it’s natural.

[youtube=http://www.youtube.com/watch?v=0awjPUkBXOU]

You can page where I found it (actually somebody who found it told me) at Johnny Chung Lee’s page.

Comments (1)

« Previous Page« Previous entries « Previous Page · Next Page » Next entries »Next Page »