Monday, May 25, 2009

Running groovy scripts from command line

Groovy is another language for the Java Virtual Machine(JVM).
Further of the ubiquitous Java language programming, there are several alternative languages for JVM, such as Clojure, JRuby, Jython, Rhino and Scala, among others.
Groovy is a relative new language who incorporates features from widely adopted and accepted languages such as: Python, Smalltalk, Ruby, and of course Java, among others.

One catching feature is that Groovy allows rapid prototyping. As mentioned above, Groovy incorporates a lot of fancy features such as closures, implicit casting, powerful operators over data collections, etc.
In particular, I love the possibility to write a snippet of code and quickly check if it fulfills with my expectations.

Lets look a trivial example. You are a newbie Java programmer and you wish to know if you understand how a loop works. How do you that in Java:
  • Write a Java class
class Looping {
  public static void main(String args[]) {
    for (int i = 0; i < 10; i++) {
       System.out.println("i: " + i);
    }
  }
}
  • Save this file  as 'Looping.java', compile it 'javac Looping.java' and run it 'java Looping'
Now, lets see how this can be done in Groovy (I assume that you usually work in a real operating system like Linux):
  • Write a text file
#!/usr/bin/env groovy
for (int i = 0; i < 10; i++) {
  println("i: ${i}")
}
  • Save this file as 'example.groovy', change its permissions 'chmod +x example.groovy', run it './example.groovy'. That's it.
No 'main' methods were required, no compilation of source code in JVM machine code; just write your code and run it.
Groovy offers a lot of interesting features. I mentioned just one that I considered useful for rapid prototyping, but there are more serious, well-elaborated, and amusing features that this modern language can offer.
However, the Groovy  Achille's heel is its poor performance. However, when current releases are compared with earlier releases we can say that great achievements has been made. (However, more work is required)

Anyway, if you are a Java developer and are starting to test new Java features and don't want lose a lot of time writing testing classes but scripts to test snippet of code, Groovy is an option. (...and slowly you'll start loving it and adopt it for production releases not just for testing purposes, I'll assure you :-D.)

Good hack!

References

Thursday, March 26, 2009

Installing packages in R

R is an open source statistical tool which has received a lot of attention in recent days.
For some time, I have been an active user of that tool because my PhD research requires some kind of statistical analysis. I found an interesting article about fitting distributions with R in which the author employs some R libraries that don't come included with the R basic installation.
The easy way to install additional libraries is using your 'root' system account. Thus,  execute 'R' and invoke the 'install.packages()' command from the R prompt.
In my case, I  selected the required libraries ('vcd' and 'fBasics') and 'OK' button. However the compilation process failed. So, previous to install/compile any additional R package it is necessary to install the 'R-devel' package.
Afterward, I installed 'vcd' first and then 'fBasics'. Now, I got a succeeded installation.

Additional Resources


Tuesday, March 17, 2009

inserting hibernate_sequence and current date and time in PostgreSQL

Recently, I need to add a record in a table from a database instance created by Grails.
Grails relies on hibernate to make persistent all domain classes defined in an application. Thus, most of the Grails applications define a hibernate_sequence in their database model.
In particular, I'm working with grails 1.0.3 and PostgreSQL as my back-end.

Now, I needed to insert a new record in one table from my Grails application which also has an  attribute of type 'Date'.

For simplicity assume that my table exhibits the following structure:

Table 'demo'

id -> bigint
date -> timestamp
name -> character varying(255)

Indexes:
     "demo_pkey' PRIMARY KEY, btree(id)

In order to make a proper insertion of a new record, execute the following line:

insert into demo (id,date,name) values (nextval('hibernate_sequence'),now(),'John');

;-) (It works on PostgreSQL, may be possible that other back-ends require a slightly different syntax).


Resources



Friday, February 13, 2009

My experience deploying the new security scheme in PRAGMA

New year and new security scheme has been deployed on PRAGMA.
In order to enable your Grid resource for all the PRAGMA users is necessary to uncompress the content of the following files in the '/etc/grid-security/certificates' directory:

Now, assure that you have enable the 'vdt-update-certs' service. In my case, the 'vdt-control --on vdt-update-certs' command failed, so it was necessary, prior to enable this service, to execute the 'vdt-register-service --name vdt-update-certs --enable' command.
Then, I follow the instructions provided in this link.

Finally,
  • vdt-control --off
  • vdt-control --on
I tested the certificates submitting a couple of 'globus-job-run' commands toward two different grid resources (komolongmace.uprm.edu and rocks-153.sdsc.edu).

Good Hack!

Monday, January 26, 2009

too many files open... error

Today, while I was saving one chapter of my thesis, I got this 'venerable' error:

Too many open files.

As consequence, the last modifications were not possible to be saved. Promptly, I looked for an answer and I found two links that you can visit here and here. The former link talks about 'confluence' application, that my Linux box doesn't run, but provided a useful hint, confirmed later in the second link.

The solution for my FC10 Linux box was append the following lines:

josanabr soft nofile 2048
josanabr hard nofile 2048

to my  '/etc/security/limits.conf' file. In fact, my user had a limit equals 1024.

Now, I'm in the game, again :-D

Wednesday, January 21, 2009

Installing hfbright - error 'cannot open type 1 font hfbr10'

Recently, I installed FC10 distribution in my new laptop. I employed the live CD available from the Fedora site.
One benefit of installing Linux from a live CD distro is that it does a minimum installation, different from DVD-distros that install you a lot of packages that you will never use.
However, many times you require some exotic packages that don't come in compact distros.
For instance, I write my documents in LaTeX and compile them with pdflatex.
Now, when I tried to compile my source files to include special mathematical symbols, an error message containing words like 'cannot open type 1 font' and 'hfbr10' appears in my Kile's log message window.
I solved this problem following the manual installation procedure defined in this readme file.
Then, I downloaded all the pfb files located in the pfb web directory, and copy these files in my /usr/share/texmf/fonts/type1/public/hfbright/pfb/ directory.
The following files config.hfbright and hfbright.map were copied to the /usr/share/texmf/dvips/config/. Theser were downloaded from the dvips web directory.
Finally, the updmap program was executed and my error messages were blowed out :-D.


Thursday, January 8, 2009

Advice for buying a laptop

Nowadays it is possible to find diverse price reductions in multiple articles, due to the current economic crisis.
Technological gadgets don't scape from this kind of discounts and you can find a lot of these discounts via Internet or in a mall store.
My favorite sites is compusa.com, in particular I'm subscribed to its RSS.

OK, I'm highly interested in update my four years-old laptop. It is a Compaq Presario R3000. I don't have any complains again it but new software products demand edge technology (I'm not talking about games, I'm talking about compilers and virtualization tools, :-P).
So, I started to look into computer manufacturers web sites such as HP, Sony, and Dell (I did not consider Lenovo but you can ;-) ).

From these sites, I liked HP and Dell because they allow me to configure my laptop according to my needs. However, I have an additional requirement, the new laptop needs to be sent to Puerto Rico (does mean, America Latina).
Although, HP sells laptops to America Latina, it does not allow laptop customization for America Latina, instead, you have to choose from one of the predetermined models for the zone.
Then, I began my purchase process with Dell.

Dell has a free telephone line in which you can contact to a sales representative and you can star to customize your computer. There is support on English as well as Spanish.
It was great, though it took more time that I expected, however, the process worth that amount of time.
(Note aside: Dell offers three years of guarantee for $75. Very cheap ;-).)

A final tip, due to my computational requirements I found very useful this site processorfinder.intel.com. There, Intel provides a friendly interface where is possible to select the processor family that you require. Then, a new page containing multiple characteristics associated with the family processor that you selected will appear. Again, you'll select the characteristics that you wish in your new processor, press the 'filter' button and 'voila', you will get a list of processors with their corresponding code names to satisfy the search criteria.
Excellent page!

An non-required advice, create in your mind the kind of computer that you'll need for the next three or four years, look around, compare prices, don't be rush in your buy, consider this buy as an investment then you need to think very well what is the purpose of this buy and try to balance the relation cost vs benefit. Then, go ahead, buy your selected item and enjoy it.