Clearer active tab in Firefox

Firefox is great, and one of its coolest features is the use of CSS in combination with XUL to manage styles and themes.
My favourite theme is Mostly Crystal with small toolbar icons and some other hacks, which allow me to change many theme details. The only thing I still have to change manually is the tabs' aspect: extensions like Firefox-plus need ot overwrite other themes' settings and among Mostly Crystal hacks for tabs there's no one which just make current tab clearer (at least, no one platform-independent: on Win default o.s. tabs may be clear enough).
If you'd like to have clearer tabs with any theme, just append these lines to your userChrome.css:

/* userChrome.css mod for a clearer current tab
.tab-image-left[selected="true"] {
border-left: solid 1px #006 !important;

.tab-image-right[selected="true"] {
border-right: solid 1px #006 !important;

.tabbrowser-tab[selected="true"] > hbox,
.tabbrowser-tab[selected="true"] > .tab-close-button {
background-color: #FFF !important;
background-image: none !important;
color: #005 !important;
border-top: solid 1px #006 !important;

.tabbrowser-tab[selected="true"]:hover > hbox,
.tabbrowser-tab[selected="true"]:hover > .tab-close-button {
color: #009 !important;

.tabbrowser-tab[selected="false"]:hover > hbox,
.tabbrowser-tab[selected="false"]:hover > .tab-close-button {
padding-top: -2px !important;

.tabbrowser-tab[selected="false"] > hbox,
.tabbrowser-tab[selected="false"] > .tab-close-button {
background-color: #666 !important;
What these lines do in detail it's easy to understand. Suggestion: use ChromEdit to modify your userChrome.css.

By using Mostly Crystal and this mod, this (approximately) will be the result:

Organize your pictures by EXIF tags with bash

Just a simple script to order your thousands of pictures by putting them in subdirectories on the basis of EXIF shot date:

# BashButler 1.0 - 11/2007 by Eugenio Rustico
# Bash script to organize your pictures in folders by date
# GPL v3 license

ls -1 *.jpg | while read fn
export dt=`exiv2 "$fn" | grep timestamp | awk '{ print $4 }' | tr ":" "-"`
if test ! -e ./$dt
mkdir $dt
mv "$fn" ./$dt
echo File "$fn" moved in "$dt"

echo Good job!

I wrote it to setup 4.900 pictures which were all in the same directory, and it was really fast and useful. My unstoppable sense of humor conceived this amazing script name: Bash Butler. I'm very sorry for this. =)

  • Of course you need exiv2 package on your system, but you can use other cli exif tools by modifying only one row;
  • With very little changes, you can modify the script to organize your pictures by different EXIF tags (e.g. different folders for different digital cameras);
  • Filenames with spaces are treated correctly;
  • By default mv does'nt overwrite destination files: so all remaining files in current directory are copies, and can be deleted.
GPL license v.3, of course.

NVIDIA 1.0-9629 on Debian testing

Being on the testing branch of Debian is cool; you have recent software, fresh updates, and plenty of little problems to solve.

Some days (weeks?) ago, after an apt-get dist-upgrade, graphic acceleration on my laptop stopped working. I didn't play with 3D things for a long time, so I realized just some days ago that the nvidia driver was not loaded anymore.

Why? Well... Who could say? Probably something changed (gcc, kernel subversion, xorg) and nvidia driver got angry for that. So, again and again:

aer:/pozzo# sh ./

But xorg couldn't find any "nvidia" driver. Among my tries, there was:

aer:/pozzo# cp /usr/X11R6/lib/modules/drivers/* /usr/lib/xorg/modules/drivers/

Yeah, I know, it was rough: soft linking would have been much more efficient (and more elegant). Anyway, after this, all worked.

One day later I found out a new driver version was available (100.14.19), and this latter one didn't require any workaround. Too late...

FractalJ: java renderer for IFS fractals

If you want to render an IFS to a raster image, you can use the chaos game or a deterministic algorithm.
Most IFS rendering softwares use the first alternative (e.g. XaoS and Apophysis), because of its simplicity and speed; but if you prefer watching your IFS while it grows, step after step, or you don't need to get 1,000 steps while drawings, or simply you're interested in a very simple IFS rendering program for didactic purposes... FractalJ is for you.

FractalJ is a very simple Java application coded by me and C. Russo; to describe IFSs (called "seeds" by the program), a scripting language similar to Logo is used. When FractalJ implementation was finished, I met L-System grammars. Too late... But quite similar to the grammar I used.

There's an extra command-line parameter to render multiple images of an interpolation between two different seeds. Below on the right, there's an animation I made with FractalJ and MEncoder.

Here you can download an high resolution version (Xvid, 5.4Mb) of the same video.

In a nutshell:
Inside the compressed archive you'll find:
  • Java source code
  • Scripting language brief description
  • Several scripting examples
  • Readme.txt
As written inside the "readme" file:
Please note: this software was NOT ment to be distributed. So, code is not well commented; usability is low; there is almost no error checking. It's just for didactic purposes.

So, I don't need to be sorry because of its terrible interface =)

Universal algorithm

Ladies and gentleman, here is the only and original universal problem solver. Just one algorithm correct and complete for *all* kinds of problems you can run into.

Click on it to get the full resolution image - maybe you need it!
Merit (and shame) are not all for me: here's the orginal diagram I just translated.
Trust me: it works!

Out from the proxy in 60 seconds

So, in your university, you can surf internet only behind a proxy, within a limited surfing area. If your situation is like the following:

  • IP-level web proxy
  • Only educational domains accessible
  • Personal Linux account without any administrative privileges
then there could be a way to go out. I'll briefly explain how I did in my university, but most probably with a few adaptations the same procedure could work in very different environments. Please note that this is not a guide for dummies: I'll just list the necessary steps, without going deep in details (e.g. how to use a hex editor or how to set up a configuration file).

Have you ever heard about Planetlab platform and its proxy service Codeen? If not, please inform yourself through Wikipedia before continuing :) Let's just say there's a free http proxy service available in some educational domains (especially universities); most of them are accessible also from limited surfing proxies, so all we have to do is to configure our system so that a Codeen proxy is used to surf. How to reach that proxy? Through your ordinary proxy, of course; but how to use two proxies in a chain? Most of web browsers don't allow to set up a proxy chain, so we must use additional softwares like proxychains.

Most probably you can access at least the package mirrors of the distro you're using; for example, I could access and some of its download mirrors from behind my proxy, so I could download the package with the same computer. Otherwise, I would just have had to download the same package through another machine and then to copy it in the behind-proxy-machine.

Once we have a .deb (or .rpm or whatever) package, we can open it with an archive manager to unpack just the files we need: the executable(s), eventual local configuration files and the required libraries (tipically to be unpacked in a ./lib subdirectory). We cannot install new shared libraries because we don't have administrative privileges, but we know other ways to use non-installed libraries. For example:
user@lab:~/proxy$ export LD_LIBRARY_PATH=./lib
user@lab:~/proxy$ export LD_PRELOAD=`pwd`/lib/
user@lab:~/proxy$ ./proxychains /usr/bin/firefox
ERROR: object '/usr/lib/' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: object '/usr/lib/' from LD_PRELOAD cannot be preloaded: ignored.
Unfortunately, setting LD_LIBRARY_PATH or LD_PRELOAD doesn't work, because proxychains executable overwrites the latter one. Two choices: modifying proxychains source and compiling it again (but we may need other "dev" packages to install), or modifying the proxychains executable with a hexadecimal editor. We choose the second one, and if we don't have a hex editor on our machine, we can download also another app like hexedit; it allows us to modify the only text string we care about: "/usr/lib/", that we're going to change in a local path (with the same length like "././/lib/" or "./tmplib/".

At this point, we should have proxychains working. Let's choose from this list a Codeen proxy accessible from our usual proxy; from an italian university, a proxy ending with ".uni**.it" should be fine. On my machine, setting a 2-proxies chain doesn't work; for some reasons, the only way to make it work is to set up proxychains.conf with the "internal" proxy (the university proxy) and the browser (Firefox, of course) with the Codeen proxy. And the result is...

Google! Good job. But there's another point to consider: if you're not surfing from a Planetlab IP, as you probably aren't, HTTPS traffic is disabled. This means: no Gmail, Yahoo Mail, nor other SSL logins or transactions. Unfortunately, some forums are managed via https protocol; to reach these forums (e.g. your university forum), you have to disable the use of Codeen proxy and to change Firefox settings again. The fastest way to do this is probably to keep two separate profiles in Firefox with different settings; supposing you named the "special" profile freefox, a bash script to open a free Firefox will be like this:
cd ~/proxy
./proxychains /usr/bin/firefox -P freefox $* &
Other solutions to have HTTPS support:
  1. Finding an external, free proxy which supports HTTPS traffic tunneling, and adding this proxy to the chain;
  2. Setting up a machine with public or dynamic IP with SSH server in http tunneling (with -X extension enabled); but if you can do this, then you don't need to read this lousy "tutorial" ;)
In a nutshell:
  1. Download proxychains and a hexadecimal editor (from their website or from your favourite distro repository);
  2. Replace the absolute library path inside the proxychains executable with a (valid) local one;
  3. Find in the list a Codeen proxy you can reach from behind your proxy;
  4. Setup proxychains to use your usual proxy, and Firefox (or another program you need) to use the Codeen proxy;
  5. You're out!
60 seconds should be enough, once you know what to do and you have a little practive.

From great powers come great responsabilities... Spread this trick and you won't find a free place in your laboratory anymore. And, of course, all this is only intended to help you reaching external websites for educational purposes only... like The Unbearable Lightness of Bit.

Have a nice (didactic) free web browsing!

The safest boat in the world

Which is the safest boat in the world?
It's easy: SSL...

(I took this picture during my stay in Turku, Finland)


Do you know who will Sun Microsystems sponsor during next Formula 1 season?

J. Button...

MD5FRACT: partial md5 checksum proposal

Though BitTorrent is nowadays a preferred protocol to share and download big files like Linux distribution iso images, http:// and ftp:// protocols are definitely still alive and well used. Although they already have their integrity check algorithms, different kind of errors may occur at different levels of the protocol stack, resulting in corrupted data saved on your hard disk. Here come to help us MD5 and SHA1 algorithms: reasonably fast hash functions useful to check the integrity of the files we downloaded.

What happens if we detect a file is corrupted? We have to download it again. The whole file, despite its size. While this is not a problem for most high-speed connection users, we shouldn't forget that many people can't access yet the internet in a very fast way (or with a "flat" rate). Any way, for everyone (service providers, high and low speed connection users) a such situation leads to a waste of time, money and bandwidth.

What could we do to reduce the negative impact of these common situations?

A cheap and fast solution could be to use partial checksums, as most peer-to-peer protocols already do. If there's only one wrong byte in my file, why should I download the entire file again? Both http:// and ftp:// protocols support file download resuming with random access1, so that we can download again just the corrupted part.

To achieve this goal, my proposal is to use a replacement of the common md5sum *nix command allowing partial checksumming.
I wrote a possible replacement (a bash script) which uses dd and md5sum to checksum just file chunks, instead of the entire given file. The aim of the script is to be completely compatible with md5sum: the replacement should be almost transparent for system administrators, and should recognize "standard" .md5 files and pass them directly to the standard md5sum utility. New .md5 files would have .md5f extension, because informations on partial checksum can't be compatible with normal .md5 files.

The script version is 0.5, and it's just a demonstration script - not the final version. It's capable of checksumming partial chunks of the given file, and checking the correctness of a file given a .md5f checksum list. It's open source, you can take it and modify it and redistribute it; just cite me and/or this blog, please. See below for download link.

Its functioning is really simple: dd reads a chunk of the given files and passes it on a pipe to md5sum; the hash is written to stdout. Here's an example about how it works:

eu@aer:/d/progetti/md5fract$ ./ Gatc.avi
e54b1acf481f307ae22ac32bbc6ce5df 1:Gatc.avi
a04871e4362c38c1243b2dd165bcfa07 2:Gatc.avi
9f1721ff9bac5facb986cc0964e24a60 3:Gatc.avi
a8230976234a97a4e11465eb1bb850d6 4:Gatc.avi
e8f3ef6ffa56292dfae0dc50f06712b5 5:Gatc.avi
368f6d1ae0106c49b71e2d9c0ab05e96 6:Gatc.avi
66e3d9107c0cf40dbafa09bb6cac38a3 7:Gatc.avi
7f8fd01e16b6900661f8d4aac2cee7f5 8:Gatc.avi
1eb25dc5d3e239ba247c94f1614588fd 9:Gatc.avi
5f96e9f4e7fdf92172a8f36d265a5070 10:Gatc.avi
eu@aer:/d/progetti/md5fract$ ./ Gatc.avi &> Gatc.avi.md5f
eu@aer:/d/progetti/md5fract$ ./ --check Gatc.avi.md5f
Gatc.avi: OK (10)

If we modify one of the hashes, we get this error message:

eu@aer:/d/progetti/md5fract$ ./ --check Gatc.avi.md5f
Gatc.avi: FAILED
Wrong hash at line 8 for file Gatc.avi:
Chunk: 8 (146800640 ... 167772160)
Calculated hash: 7f8fd01e16b6900661f8d4aac2cee7f5
Found hash: 9f8fd01e16b6900661f8d4aac2cee7f5

I was first thinking that an executable file implementing its own md5sum routine would have had a better performance, because using dd for each chunk implies opening a file handle, seeking inside the file and starting a new md5sum process for each chunk; however, a quick performance comparison shows that, thanks quick random file access of modern filesystems, this bash script with redundant file opening is almost as fast as the traditional md5sum program launched with the same file:

eu@aer:/d/progetti/md5fract$ time ./ DevAdvocate.avi
49980c46641915c55252772dc4933090 1:DevAdvocate.avi
7bc34fa302d6fee588eb06421fd529c0 2:DevAdvocate.avi
7c521d571165f4224693396f378e5001 3:DevAdvocate.avi
34975d9be25a75d7e39cc882db9e0ca4 4:DevAdvocate.avi
76e5e56e8972656ef17f1b2c429b3695 5:DevAdvocate.avi
cc32be51ba083482bb4b3e9d2143eb00 6:DevAdvocate.avi
d5ce8ae2027288dfe182276ce2143a69 7:DevAdvocate.avi
5037475202e4ae2682434c612e11b6a8 8:DevAdvocate.avi
0dc569188a14c74c9e6807a05d9af1f6 9:DevAdvocate.avi
a9ecf0210a55e82349939c11d21272b4 10:DevAdvocate.avi

real 1m5.386s
user 0m5.256s
sys 0m6.536s
eu@aer:/d/progetti/md5fract$ time md5sum DevAdvocate.avi
c61c60414ba0042169d0caf0880c2610 DevAdvocate.avi

real 0m56.813s
user 0m5.260s
sys 0m1.912s

The user time is basically identical, but the system time (necessary to open file handles and new subprocesses more than once, I suppose) is more than doubled. Anyway, on my machine the time required for md5fract execution is always around 110%-115% of the time required by md5sum to checksum the same file (file "DevAdvocate.avi" is about 1.4 Gb). In conclusion, checksumming partial file chunks through a bash script seems to have not a bad performance. This test was done on ext3 filesystem, but would be useful to do more tests on different filesystems (that may have different file seeking speed).

The aim for version 1.0 would be to have the same script with:
  • Multiple files support (now it supports just one input file);
  • Total compatibilty with existent md5sum utility;
  • Non-bash shells compatibility;
  • Better error handling.
If you're tired of downloading the same files again and again, or if you simply like the concept, please spread this idea. I'll complete it sooner or later (sooner if I see some admins are interested in it), but of course anyone else could complete it ;). After completion, I'd like to propose it to several mirror services, and I hope someone will adopt it.

In a nutshell:
  • MD5 partial checksum utility (md5fract) for bash, version 0.5
  • Requires md5sum already installed
  • Download link (less than 6K)

1: Unfortunately, some FTP clients use just a signed 32 bit integer to seek remote files; as a consequence, they can't seek addresses higher than 2 Gb.

A CSS style to post code in your blog

So, you own a blog and you'd like to post some code. Is it HTML, CSS, PHP, Java, ...? You need to highlight and format it, somehow. For example, here is the code to enumerate an associative array in PHP:

echo " Array $arr:<br>\n";
foreach ($arr as $key => $value) {
echo " - Key: $key -&gt; $value<br>\n";

First of all you need a parser to highlight the code. Most of good editors (e.g. Kate, SciTE) have an "export as HTML" feature, and that's what you need. After exporting the code to HTML, you need to format the paragraph some how in a way you like (tipically with a monospaced font, and often with a special background color). Another good thing would be a horizontal scrollbar appearing only when needed, without the normal word-wrap which is a bit invasive for code quotes.
If you like the CSS style of the above paragraph, I can avoid you the effort to look for it in the source of this page; here's the exact same CSS I use in this blog (I just added some :hover border change):

 /* CSS for code quotes by
by Eugenio Rustico */
width: 60%;
background: #EEE;
border-width: 1px;
border-color: #CCC;
border-style: solid;
border-left-width: 4px;
border-left-color: #000066;

font-family: Courier, monospace;
line-height: 115%;
clip : auto;
overflow : auto;

padding: 1em;
padding-left: 1.5em;
margin: 1em;
margin-left: 2em;

/* white-space:nowrap; if you want DIV instead of PRE */

This class should be used in a <PRE> or in a <DIV> element, depending on your needs. If you don't have to format something else inside the same block with HTML code, just use a <PRE> tag; but remember that every space or tab inside the text will be "as is" in the output (the HTML page). License: just cite this blog in the comments or somewhere else, and you can use and abuse of it =)

Little note: due to Blogspot's buggy post editor, I had to add a non-breakable space ( ) at the beginning of the margin-right row. Unfortunately, every space in the end of a line in the code editor, even if the line is broken for word-wrap, is considered useless and is trimmed out... Without this addiction, the margin-right row is not aligned with the other rows.
Moreover, every time you write the " " string in the HTML editor, and you edit the post again with the wysiwyg editor, it magically disappears and you have to edit the HTML code again... Buggy, buggy Blogspot!

The icing on the cake: If your code is very long (e.g. over 50 lines) but you don't want a such high box in your blog, just add the CSS max-height property, preferably to a value expressed in em (e.g. to about 30em) and a vertical scroll bar will appear if needed.

Forcing video preview frame in YouTube

Many people noticed YouTube flash player is not so rich in options, and one of its the lacks is that it's not possible to choose the preview frame for an uploaded video; not a static image, neither a frame from the video itself. However, if you absolutely have the need to choose the preview frame, you should know YouTube takes as preview the frame at about the temporal half of the video. This is not an official information, but just the result of some observation: maybe for some videos the choosing "algorithm" is different.

In my expreriences (the most beautyful video I uploaded, that's nevertheless a poor one, is this), the frame at the exact half of total frames number is not the chosen preview; it seems that the algorithm is:

  1. Take the temporal length of the video;
  2. Divide by 2, and truncate to the shortest integer;
  3. Choose previous frame, or the current one if it's exactly the moment to change frame (if 1/framerate divides the length).
I made two videos to confirm this hypothesis, with labels in each frame indicating the current position:

As you can see, the choosen frame is not the exact half. 500 frames at 25 frames/second are 20 seconds, and 510 frames are 20.4 seconds. In both cases, frame number 251 (1-based) is choosen; 0.4 seconds more make no influence at all.
If you want to do more tests by yourself, you can use ImageMagick go generate the frames and MEncoder to merge them into a video. Here is the bash script I used to generate these videos.

Interlacing makes things more complicated, because there's no way to know in advance how YouTube converting engine will work; and, of course, we can not choose in advance useful video parameters (like deinterlacing method). So, try to upload an already deinterlaced video, if possible; Flash streams are progressive, and would be a good choice not to let YouTube decide how to deinterlace.

Update: by downloading again my same video, I noticed that its length has changed, though the original submission was already progressive. The conclusion is: I can't find out the algorithm YouTube uses to choose the preview, it would need more experiments and I don't have the time to do them.

But is this just a useless toy?
In my opinion, it's not just a toy, but a powerful trick. Consider, for example, this video:

The preview is absolutely arbitrary, and has *nothing* to do with the content of the video. During the first two hours after I uploaded it, 239 views were hit. Without this "special preview", the same video was viewed 2 times in a week... Tricks for cheating people apart, this technique can be used to set a decent preview to your videos; the default YouTube's algorithms produces lots of annoying previews, that just don't match well the real content of the videos. That was why I had the initial idea: in one of my videos, the chosen preview was a frame almost completely black, while the rest of the video was white.

As you probably noticed, poor seeking is another annoying fact in YouTube videos; this time, the injection of keyframes is related also to scene changes, so if you move the "preview frame" one or two or three position before, it's not the preview anymore but it's still a keyframe (I did this experiment). To do: upload a .flv video already encoded with many keyframes, to test if YouTube is going to delete some of them or not.

Now, if YouTube chose for your video an awful preview, you know how to force it to use a better one. Power to masses! But remember: from a great power, come great responsabilities... Try to imagine what spammers could do with this trick... Oouch!

Watching local flash .flv videos with your browser

You got it. You couldn't sleep thinking that your removed due to terms favourite video may have been violations or to some other very good reason. So, you just downloaded a video from YouTube (don't ask me how and ask the master!), and now you have a nice, little, harmless .flv file on your hd. But how to open it? You are thinking about downloading VLC player, or an unknown generic codec; or maybe you're so bright you already thought it's possible to transcode it with your favourite factotum: mplayer. Maybe you could even download a specific application that can only read .flv files! But there's a question silently crawling in your head... Why the hell my friends Firefox and Safari could open and play and even seek the .flv stream, while they don't know how to deal with the same stream coming from my local hd?
And you already know the answer, in the deep. They can. You just simply need to present the .flv under a different aspect; you need to wrap it in a Flash object (swf) you can compile by yourself, or you could ask an existent Flash reader to open the .flv file for you.

After a very long and difficult work period (two days)1, finally I made a html-knowdlege-independent and effortless-to-use-even-for-dumb-users page; it's a little .flv player written only in html (with a flash object). You can download it from WatchTube (another cool thing is coming soon on that website). This lilttle reader supports also .swf videos and other media files. Finally, we have our free, cross platform, light, fast .flv reader. We do not depend anymore on any specific codec or dedicated reader. Use your own browser and enjoy!

In a nutshell:

  • Lory Player 1.1 Flash player
  • Reads Flash videos (*.swf, *.flv) and other formats (*.mp3, *.jpg, *.png, *.gif, RTMP streams)
  • No installation required
  • For Linux, MacOsX, Windows (virtually any version)
  • Tested on Firefox, IE6, IE7, Safari, Camino (requires Flash plugin)
  • Creative Commons license (it's free)
  • Direct download link (~120 Kb)
An online version (not working with local files, it's just a layout preview) is available here.

1 Note added: when you say you had a "very long and difficult work period", and then you specify that the long period was just two days long, you can't be serious. Evidently it's a contradiction, or simply a (stupid) joke...


Narcolessico is the founder of this blog, and also a popular 70's rock icon.

He has a beautyful family and a Fender Stratocaster.

He likes playing chess and eating pizza.

He only uses Linux (EDIT: today Ubuntu).

Contact: jfrusciante at tiscali dot it.

The picture may not respond to reality.

Question time!

Beginning: the Bit

The Bit, matter and father of every digital information; center of deep phylosophic discussions, and basic element of every porn image.

Deep thoughts end here; now it's time to break into informatics and share knowdlege and scripts.

If you're wondering why this post, check the date: is the first of Unbearable Lightness of Bit!