2009-12-15

Getting NetBeans to do Anti-Aliasing

I changed desktop environment from KDE to none when Gentoo marked KDE 4 as stable. Don't get me wrong: it has nothing to do with KDE 4 itself. The problem is that my computer is rather old and it was already getting a little slow with KDE 3.5. KDE 4 is heavier and slower bringing me to the tipping point. No, GNOME is not the answer: I switched from GNOME to KDE when GNOME got too bloated and don't get me started with mono...

Now I'm using openbox, considering wmii or enlightenment but not a full desktop. I added adesklets to the mix, conky, tint2 and yeahconsole and I'm ready to work.

A couple of days ago a colleague had issues with NetBeans on Gentoo, specifically the fonts had no anti-aliasing, hinting, whatever you want to call it. I tried it today because I was using NetBeans to do some PHP coding. Well, I had the same problem.

After some investigation I finally found a way to get it back to work without running KDE or GNOME and I though of sharing it here hopping the next guy can find it easier.

According to Sun's JDK documentation you can defined a "_JAVA_OPTIONS" environment variable with the options that the VM should use when starting. You can also force AWT to use a given fixed AA Font Settings and ignore the non existing desktop. In the end you have to make "_JAVA_OPTIONS" have the value "-Dawt.useSystemAAFontSettings=lcd" or any of the values defined in the JDK docs.

2009-11-17

CMake Cross-Compiling

I don't know if I already mentioned, but I'm writing and ODBC driver at work. A colleague of mine proposed that the driver is open sourced since it is not our main business. I hope it is, but I'm keeping my hopes high. In the mean time I can share what I have learnt.

The driver is an ODBC-RESTful bridge, that is, ODBC requests are transformed into HTTP Restful requests. Although the initial goal of the driver was to be Linux only we had to change it because of the wonderful reporting tool chosen. So I had to port it to Windows. I wont go on the tiny details on how to write portable C code (basically using #ifdefs) but on using CMake and cross-compiling. You see I went and tried to use Microsoft Visual Studio Express, the latest version, but the compiler was so slow, the IDE was, well, horrible and the Operating System is a stone in my shoe, even if executed in a virtual machine. So I decided to put MinGW to a good use and cross compile, that is, to compile on linux a windows executable. Well, in this case a DLL, since ODBC drivers are DLLs.

I'm liking CMake more everyday and cross-compilation is one of the things I liked. So, this is how you can do it. The instructions here are really boring because I'm using kubuntu at work. I need to allocate some time to get gentoo into the company's laptop. Gentoo rules in cross-compilation, not to mention a lot more things - I still have a 9 year old lappy with gentoo that I use for my private work. The crazy thing is that I always upgraded it: never reinstalled it. But back to cross-compilation.
In kubuntu (and I suppose all debian derivatives) if you want to build a windows executable you have to install mingw32. It is composed of 3 packages: mingw32, mingw32-binutils and mingw32-runtime. This will setup a /usr/i586-mingw32msvc/ folder with all the tools.

The solution I found to get CMake to use these tools is to create a toolchain file. This CMake file will contain all the definitions for the new platform. Here is small sample of a Toolchain-windows.cmake file.
SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_C_COMPILER   i586-mingw32msvc-gcc)

SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)

# Define paths to search for libraries
SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc/)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# Don't search in native paths, just the specified root paths
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Now to get a windows build what I do is create a folder side by side with the projects folder. For instance, if the project is in the folder A with all the CMake and source files I create a A-Windows, go into it and run:
cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-windows.cmake ..
make
And I get my windows version of the software. Of course you will have to port your code to windows. Remeber the #ifdef WIN32 and, if you need to add more libraries to your executable do something like this on the CMakeLists.txt file:
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" )
        set (LIBS ${LIBS}wsock32)
endif ( "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" )
And try to have fun. At least you can do most of your development on a decent platform with decent tools.

2009-10-13

Back to C: CMake and CUnit

I'm back at programming in C. I proposed something 8 months ago at work that was totally ignore. Now my boss wants me to do it because the other alternatives have totally failed. The idea is to implement an ODBC Driver. If I have the time I'll put a tutorial here on how to do that on Linux. But back to the point of this entry.

This small guide will help you create a simple project using CMake to build it and cunit to test it. Yes, I believe in test driven development, no matter the language.

Let's imagine a simple project that produces an executable that prints the result of 2 + 3 (I know, lame but sufficient for this example). To make it easier to test I split the application. The functions will go into a library and there will be a source file that starts the program. The library header file is called "lib.h" (extra points for originality). Here are its contents:
int add(int a, int b);

The implementation is on the lib.c file as follows:
int add(int a, int b) {
return a + b;
}

As you can see it is a very complicated function. The adder.c file contain the main function and starts the program as follows:
#include <stdio.h> 
#include "lib.h"

int main (int argc, char** argv) {
printf("2+3=%d\n", add(2, 3));
return 0;
}

The unit test is a little more complicated as cunit requires some boiler plate code in order to run tests. Here is the source code of the test_lib.c file:
#include "CUnit/Basic.h" 
#include "lib.h"

void simpleTest(void) {
CU_ASSERT(2 == add(1, 1));
}

int main (int argc, char** argv) {

CU_pSuite pSuite = NULL;

/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();

/* add a suite to the registry */
pSuite = CU_add_suite("Suite_1", NULL, NULL);
if (NULL == pSuite) {
CU_cleanup_registry();
return CU_get_error();
}

/* add the tests to the suite */
if (NULL == CU_add_test(pSuite, "Simple Addition Test", simpleTest)) {
CU_cleanup_registry();
return CU_get_error();
}

/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}

To make all this build with CMake you have to create a CMakeLists.txt file with the following content:
cmake_minimum_required (VERSION 2.6)
project (Adder)

set (SOURCES lib.c)

add_executable (adder adder.c ${SOURCES})

enable_testing ()

add_executable (test_lib test_lib.c ${SOURCES})

set_target_properties (test_lib PROPERTIES LINK_FLAGS -Wl,-lcunit)

add_test (test_lib ${EXECUTABLE_OUTPUT_PATH}/test_lib)


And that is it. Now you can make a directory called "build", go into to it and type "cmake .." to generate all the necessary build files. To build the project you type "make", to run the tests you can type "make test" and to clean the output you can run "make clean". If you prefer to do it all in one pass just do "make clean all test".

Just in case you are wondering: I used c2html to generate the html formated version of the C files and VIMs convert-to-html script for the CMake file.

Happy coding!!!

2009-09-29

LOL - "Server Too Busy"

This just happened to me today. What is more interesting is that this is an unhandled exception. So, the server being to busy is not something that they should predict and allow the application to handle, they just make you wait and then throw this at you. Don't you just love these products.

2009-08-19

The Plan

It has been some time since I last posted here but I cam across this gem that I had to share. The tile is "The Plan":


In the beginning was The Plan.
And then came The Assumptions.
And The Assumptions were without form.
And The Plan was without substance.
And a terrible darkness fell upon the face of the Workers. And they
spoke among themselves, saying "It is a crock of shit, and it stinks."
And the Workers went unto their Supervisors and said loudly "It is a
bucket of dung, and we cannot live with the smell."
Whereupon the Supervisors went unto their Managers and didst say "It is
a container of excrement, and it is very strong, such that none may
abide by it."
The Managers went quickly up into the temple and seeing there the
Directors of the company, went unto them, saying in pious voices "It is
a vessel of fertiliser, and none may abide its strength."
After much feasting and lewd revellry, the Directors spoke among
themselves, saying to one and other "It contains that which aids plant
growth, and it is very strong."
And together the Directors went up onto the mount and finding there the
Vice President, said gravely "It promotes growth, and it is very
powerful."
Seizing upon this information the Vice President, went unto the
President, saying, "This new Plan will actively promote the growth and
vigour of the company with very powerful effects."
The President looked upon The Plan and saw that it was good.
And The Plan became Policy.
And this is how Shit Happens.

Company Confidential

2009-01-08

Helping out OpenStreeMap

It has been a while since I have last posted but I hope to do it more often. Don't ask me why. I guess that if you are in the bottom you loose all will to do anything. But a two weeks vacation and a few changes in both my personal and professional life and I'm starting to see the light at the end of tunnel.
But that is enough drama, on to the goal of this entry.
I made my very first contribution to the OpenStreetMap. Think of it like a Wiki that is a map of the whole world. Since my country doesn't have a nice coverage I decided to hack my GPS to track my trips and share them. Then I edited my first roads (two fully and a part of one) and they are already appearing on the site. Next step is to add more roads.
Want to help out? You don't even have to edit the roads. Just trace your trips and upload them they will help others since the more information the more accurate the map will be.