Sunday, December 9, 2012

Iris: more HTML5 Canvas pixel manipulation fun

After I wrote the plasma effect quite some time ago, I wanted to give it a shot at improving the performance of such a pixel manipulation demo. And so I wrote a similar demo called Iris that will generate a random sequence of patterns and effects each time you run it.

The result is quite impressive when running in Chrome on my Ubuntu laptop with full HD resolution, where I get 60 FPS consistently. Unfortunately, Firefox achieves only just above 30 FPS, while Opera gets just under 30 FPS. Enjoy the Iris live demo yourself.

Wednesday, August 15, 2012

Auto-synchronized development environment with Dropbox

Every now and then, I'm forced to work on a brand new machine. Be it a new laptop at home, a new build farm in the office, or just some temporary workstation of any kind. Since I'm lazy and fond of having computers do stuff for me automatically whenever possible, I found myself thinking why I had to reconfigure Bash, Vim, QtCreator and all sorts of tools I use for work over and over again. Every time you make a change in one of your workstations, you'll have to copy entire files or text sections around in order to get the same configuration in the office, at home and everywhere you wish. By configuration I mean shell aliases and environment variables, editor settings, and also my ~/bin folder that contains loads of useful scripts.

Surely, this can be achieved with a version control system like git, but I wanted something even easier, more automatic and straightforward. Since the cloud is the word of the day, wouldn't it be cool to have all my settings and scripts synchronized automatically with some cloud service? I happen to prefer Dropbox by far for a variety of reasons. So I gave it a try and found out it's trivial to reach the goal. Let's assume for the sake of simplicity that all you want to have available in all your machines, always up-to-date, is ~/.bash_aliases. These are the only required steps to get it done:

  • Install Dropbox. Let's assume the default target directory ~/Dropbox.
  • Create a folder inside it, say home, that relates to your user home directory:
mkdir ~/Dropbox/home
  • Make sure Dropbox is set up to synchronize ~/Dropbox/home
  • Move your Bash configuration to the synchronizable space (i.e. your private cloud). You probably want to rename it so that it doesn't contain the initial dot and stays hidden:
mv ~/.bash_aliases ~/Dropbox/home/bash_aliases
  • Create a symbolic link to this new file from your home directory, and have Bash think it's fetching the configuration from its usual place:
ln -s ~/Dropbox/home/bash_aliases ~/.bash_aliases
That's it. To make it even cooler, I've created a script that performs all the moving and symbolic linking for all files I wish to have synchronized at all times, everywhere. Then, the only task I need to manually repeat every time I add a new machine to my context is the very first one, the installation of Dropbox, making sure that the folder home will be synchronized. All that is missing is running the said script in the end. The script is obviously in the cloud too, in my synchronized ~/bin -> ~/Dropbox/home/bin folder. This works wonderfully for me, I hope you find it useful too.

Thursday, July 26, 2012

Automatic recursive photo renaming by EXIF Date

I had a problem to solve: rename my entire photo collection using the EXIF Date info contained in the files. I wanted a solution that was both quick to come up with and write, and that performed just fast enough.

I keep all my pictures in a structured folder hierarchy. For instance, I can have a folder just for Person X, Home or Family. Over time, I can add more and more files to that directory. The problem with this is that photo taking devices (cameras, phones, etc) usually adopt some kind of sequential numbering to name the files. This means that whenever you erase the device's memory or reach the max photo count, you're back to the beginning of the sequence.

The result of this strategy is that when you look at, say, Person X's folder, you are not seeing them in chronological order. Sure, there are file managers that allow the user to sort the list by EXIF Date or something else, but I wanted a system that would sort the images correctly no matter where.

The obvious way to do this is to rename the files with the time stamp of the moment they were taken. To ensure that there's no collisions, a precision to the seconds magnitude should be enough. So you end up with something like YYYYMMDDhhmmss.jpg.

I ended up writing a Bash script that used ImageMagick's convert tool, but I found the renaming process to be extremely and unnecessarily slow. While I was starting to consider writing a good old C/C++ or even Qt program, I got acquainted with libexif/exif (readily available for installation on Ubuntu). A quick test proved it would be a much faster option.

The final result is pictime. At the time of writing, it offers the user the choice of verbosity, simulation, and recursivity. It won't rename pictures it finds that do not contain a valid EXIF Date. It searches for all files ending in .jpg or .jpeg (case insensitive). When I was confident enough about its stability, I finally ran it through my entire collection of photos that I store on an external USD hard drive, without the simulation flag. It went through dozens of thousands of pictures and renamed them, in place, in just a few minutes.

It suits all my needs - at least for now - but if you find it useful and realize you need to add more behavior to it, your contribution is more than welcome. Enjoy!