Thursday, December 25, 2008

Ruby Ternary Search Tree

Simple Ruby Ternary Search Tree Implementation.

Currently supports:

  • Insertion (insert)

  • Search (search, node)

  • Printing (to_s)

git clone at:

Wednesday, December 10, 2008

Ruby 1.9 C Api Extensions Guide

I am writing a guide on the Ruby (SVN) C API. You can see it here:

Expect more stuff to be added later.

New Mirror Blog and Theme

I have created a wordpress blog in my own server which will eventually replace this site. The blog is at

This new blog has a better format and will implement new features in the future.

Friday, November 21, 2008

Embed Fonts in HTML document using PHP and Javascript

I wrote a php + js script to replace HTML markup with formatted text in the form of images. The script is called PHPJSFont and it is available at

What it does is simple: the Javascript code replaces the text inside HTML tags with an image generated by the PHP script.

Currently it depends on JQuery and PHP 4+ compiled with the GD extension and TTF support.

It should be fairly simple to use, as in:

PJF.replace("#topmenu UL > LI");
PJF.replace("h1", { size: 20, color: [255, 0, 0] });

Saturday, November 15, 2008

Install Intel Compiler(icc) in Ubuntu 8.10

To install icc in Ubuntu:

  1. Download icc from Intel website

  2. tar -zxvf the file.

  3. Run ''.

  4. Follow the installer instructions.

  5. When it is done add this line to your ~/.bashrc (or initialization script):
    source /opt/intel/Compiler/11.0/069/bin/ ia32
    Replace ia32 with your platform: (ia32, intel64, ia64)

  6. Log off and log in and that is it. You can test it with icc -v

  7. To use icc with a configure script use ./configure CC=icc

NOTE: If you get a error like "file does not exists" while using sudo, you will need to write a bash script adding "source /opt/intel/Compiler/11.0/069/bin/" and the program you are trying to run.

Wednesday, October 1, 2008

Ruby 1.9 Blocks Notes

  • Every function can accept a block.

  • Kernel.block_given? will tell you if a block was passed.

  • def test
    a = 42
    yield(a) if block_given?

  • To assign the block to an argument, you add an ampersand (&) in front of the last argument of your function. This will affect performance.

  • You can call the block inside the function using yield or like this:

  • def test(&block)
    a = 42
    yield(a) # or,b)

  • yield calls and passes the arguments to the block.

  • block.arity will tell you the number of arguments a block can accept

  • If you have a recursive function accepting a block, you can pass the block to it using '&'.

  • def recursive_function(&block)
    # Do stuff
    # pass to other functions accepting blocks
    10.times &block # will run block 10 times

  • If you use the return keyword inside a block, it will return the value and exit the function binded to the block, which is the one that created it.

  • def bl(&block)

    def test
    bl { return }
    puts "Hello" # this will not be executed.

  • You can use break to return a value inside a block and stop iterating.

  • def bl(&block)
    (0..10).each &block

    def test
    # This block will stop iterating at 5 and return true.
    bl { |x| (break true) if (x == 5); false }

Thursday, September 4, 2008

Using SyntaxHighlighter with Blogger or Blogspot

I added Syntax Highlighting capabilities to this blog and here it is how i did it. You might need another server where to put your files:

  1. Download SyntaxHighlighter from

  2. Add this to your Edit HTML code in Layout:

  3. <script language='javascript' src=''></script>
    <script language='javascript'>
    window.onload = function() {
    dp.SyntaxHighlighter.ClipboardSwf = '';
    <link href='' rel='stylesheet' type='text/css'/>

  4. Put the code you want to highlight inside a <pre> tag like this:

  5. <pre name='code' class='language'>

  6. Make sure you replace the url and also '<' with &lt; if you are using HTML code

  7. Add this to the top of your post:

  8. <script language='javascript' src=''></script>

  9. Replace the script name with the one used for your language.

For more information and language list visit