Hooray for plasma fractals!

August 23rd, 2009

Everybody loves fractals. If you don’t know what a fractal is, find out so that you can discover their infinite awesomness. They may be incredibly pretty and mind-boggling, but can fractals actually do anything useful? Thanks to plasma fractals, the answer is ‘yes’.

Read the rest of this entry »

How to strip all non-alphanumeric characters from a string.

August 3rd, 2009

Using the regular expression [\W_], we can match all non-alphanumeric characters and remove them. Why not just use \W to match these? \W still leaves underscores behind because it matches a-z, A-Z, 0-9 and _. Here’s the appropriate Ruby code for substituting all instances of [\W_] with nothing:

"&3_Doors-Down".gsub(/[\W_]/, '')    # => "3DoorsDown"

How to detect multimedia key presses from Ruby.

July 30th, 2009

Ever wondered how programs such as Rhythmbox manage to handle key presses from multimedia keyboards, such as “Play”, “Previous” and “Stop”? The secret (in GNOME) is to make use of D-Bus. There is a RubyGem available called ‘rbus’ which provides the required functionality.

Read the rest of this entry »

How to handle missing libraries in Ruby.

July 21st, 2009

Ruby programmers are spoilt by the vast collection of libraries available in a central place – RubyForge, packaged as RubyGems. When creating your own project you can simply reference a few Gems as dependencies for your Gem, and everything will be installed when a user types `gem install myproject`.

This is all very well, but what if something is missing? It doesn’t seem like very robust coding to have a whole media player crash if support for an obscure, unused audio format is missing on the user’s computer. Here is a short technique which should be a part of every Ruby coder’s toolbox.

Read the rest of this entry »

I hate HTML.

June 25th, 2009

I’m sure that the creators of HTML had the best of intentions, but over the years this markup language has become something truly monstrous. If you browse to most websites and take a glance at it source, the chances are that you will immediately feel the sudden urge to murder a kitten. Why is HTML so yuck? One reason is that it contains excessive junk which does not actually do anything, such as the inclusion of entire tag names in closing tags.  Another reason is that web developers have taken it upon themselves to abuse HTML in every way imaginable, usually in a hopeless quest to achieve the fabled “cross-browser compatibility”. Finally, HTML is simply not an easily readable language – a simple paragraph of text quickly becomes clogged with <a> tags for links and assorted inline styling tags. If you are thinking “yes, HTML sucks, but I don’t have a choice”, read on to discover the wonders of lightweight markup languages!

Read the rest of this entry »