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 http://packages.ubuntu.com 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/libproxychains.so
user@lab:~/proxy$ ./proxychains /usr/bin/firefox
ERROR: ld.so: object '/usr/lib/libproxychains.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/usr/lib/libproxychains.so' from LD_PRELOAD cannot be preloaded: ignored.
user@lab:~/proxy$
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/libproxychains.so", that we're going to change in a local path (with the same length like "././/lib/libproxychains.so" or "./tmplib/libproxychains.so".

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:
#!/bin/bash
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)

Rumours

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$ ./md5fract.sh 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$ ./md5fract.sh Gatc.avi &> Gatc.avi.md5f
eu@aer:/d/progetti/md5fract$ ./md5fract.sh --check Gatc.avi.md5f
Gatc.avi: OK (10)
eu@aer:/d/progetti/md5fract$

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

eu@aer:/d/progetti/md5fract$ ./md5fract.sh --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
eu@aer:/d/progetti/md5fract$

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 ./md5fract.sh 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
eu@aer:/d/progetti/md5fract$

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:

<?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 http://binaryunit.blogspot.com
by Eugenio Rustico */
.code{
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;
 margin-right:
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.