Blog

Posts about technology and arts.

Strings transliteration in Java with Apache Commons Lang

Rosalind is a website with a curated set of exercices for bioinformatics, organized hierarchily. In some of these examples you are required to replace characters (nucleotides) by other characters. It is a rather common task for developers, like when you need to replace special characters in user’s names.

There are different ways of describing it, such as translate, replace, or transliterate. The latter being my favorite definition.

In Python I know that there are several different ways of transliterating strings [1][2]. But in Java I always ended up using a Map or a Enum and writing my own method in some Util class for that.

Turns out that Apache Commons Lang, which I use in most of my projects, provided this feature. What means that I will be able to reduce the length of my code, what also means less code to be tested (and one less place to look for bugs).

String s = StringUtils.replaceChars("ATGCATGC", "GTCA", "CAGT"); // "TACGTACG"
System.out.println(s);

What the code above does, is replace G by C, T by A, C by G and A by T. This process is part of finding the DNA reverse complement. But you can also use this for replacing special characters, spaces by _, and so it goes.

Happy hacking!

Treemapping Jenkins Extension Points with R

I have been playing with R and its packages for some time, and decided to study it a bit harder. Last week I started reading the Advanced R Programming by Hadley Wickham.

One of the first chapters talks about the basic data structures in R. In order to get my feet wet I thought about a simple example: treemapping Jenkins extension points.

Writing a custom SchemaSpy command for Laravel 4

This week I had to write my first custom command for Laravel 4. In Nestor-QA, Peter and I thought it would be useful to have the database schema being automatically generated with SchemaSpy in our Jenkins box.

Thanks to Artisan this task is much simpler than I thought. The following command creates the schemaspy command.

php artisan command:make SchemaSpyCommand --command=schemaspy

This will create the file app/commands/SchemaSpyCommand.php. And all I had to do was just fill in the options and write the exec command as the Laravel 4 docs explain.

$this->info('Creating SchemaSpy');

$jar = $this->option("jar");
$dbtype = $this->option("dbtype");
$output = $this->option("output");

$commandLine = sprintf("java -jar %s -u none -t %s -o %s", $jar, $dbtype, $output);

$this->info(sprintf("Command line: [%s]", $commandLine));

exec($commandLine);

That’s how my final command looks. Now the final step is integrate it into the application by adding the line below to app/start/artisan.php.

Artisan::add(new SchemaSpyCommand);

And that’s it, running php artisan schemaspy --jar=/opt/schemaspy/schemaSpy_5.0.0.jar --dbtype=app/database/sqlite.properties --output=database-schema creates the database schema docs in the database-schema directory.

Check this gist for the final code.

Happy coding!

Missing menus in new installation of TestLink 1.9.8

I recently installed TestLink 1.9.8 and noticed that the menus and some other parts of the UI we missing. Looking at /var/log/testlink/userlog1.log (the location may change depending on your settings) I realized that there was something wrong with my PHP installation. There were log messages like the below.

include_once(ADORecordSet_ext_empty.class.php): failed to open stream: No such file or directory - in /home/kinow/php/workspace/testlink-1.9.8/lib/functions/common.php - Line 92
[13/Sep/18 12:51:09][WARNING][2o0h173pdgg5fjqh1pukr83og2][GUI]
E_WARNING
include_once(): Failed opening 'ADORecordSet_ext_empty.class.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:.:/home/kinow/php/workspace/testlink-1.9.8/lib/functions/:/home/kinow/php/workspace/testlink-1.9.8/lib/issuet
...

I found a post in a forum (but unfortunately I forgot to save the link) that suggested these ADORecordSet were being caused by the module php5-adodb. Removing the module, and cleaning the templates cache directory ($TESTLINK_HOME/gui/templates_c/*) fixed the issue for me.

Hope that helps. Happy testing!

The Apache Way and on writing software reviews

The Apache Way is the philosophy behind Apache Software Foundation and is shared by all of its projects. It is composed by a set of principles:

  • Collaborative software development
  • Commercial-friendly standard license
  • Consistently high quality software
  • Respectful, honest, technical-based interaction
  • Faithful implementation of standards
  • Security as a mandatory feature

I have been part of Apache Commons for a while, and haven’t really contributed much yet. Maybe because I had lots of projects related to TupiLabs as well as my own wedding this year. But I can assure that respectful, honest, technical-based interaction is quite right (not to discredit the other items, of course).

Even though there are critics of the Apache Way (1, 2, 3), it still stands as an important pillar for the Apache Software Foundation, and its principles help to create stable and production ready software, such as Apache Hadoop, Apache Httpd, Apache Commons Lang, among others.

There are many reviews and comparisons on Apache software (as well as on other software, like JavaScript libraries, Java Web Frameworks, Ruby Web servers and so on). Sometimes, though, these reviews or comparisons can be biased or not well founded. In cases like this, the developers of the tools may be frustrated, or users can be misled and choose the software based on wrong assertions.

I have just returned from honey moon, ready to start writing code again, but first I had to read all the unread messages in my inbox. Some were e-mails from Apache mailing lists. One of these e-mails had Phil Steitz comments on a post by Daniel Wu.

Instead of publishing his performance benchmark results of Apache Commons Pool, Daniel posted his code to the commons-dev mailing list. Phil Steitz, one of Apache Commons Pool committers replied with questions and a few points that Daniel could use to enrich his benchmark tests.

This kind of behavior happens a lot within Apache (at least in the mailing lists that I follow), and it produces a lot of benefits for different parts.

  • The person writing a review or comparison can get the programmer opinion before actually publishing anything.
  • The programmer can see how other people were testing his/her code.
  • All other commons-pool committers and maintainers, the mailing list readers, and people that found the mailing list archives will be able to read the conversation history.
  • No misguided benchmark results were published (and lots of wrong decisions were avoided).

I keep loving the Apache Way and the resulting community and code around it. There are always lots of things to learn, the Open Source projects communities are healthy and you will always find people willing to share their experience and time teaching you.

♥ Open Source


1 http://www.infoworld.com/d/open-source-software/has-apache-lost-its-way-225267?page=0,2

2 http://footle.org/2011/11/23/apache-considered-harmful/

3 http://www.itworld.com/it-managementstrategy/227477/has-open-source-outgrown-apache-way

Subscribe