Friday, 18 December 2009

Connecting R and Postgres via JDBC

I need to make a note of this for reference:

library( RJDBC ) 
postgres <- JDBC( "org.postgresql.Driver", "/path/to/postgresql-8.3-604.jdbc4.jar")
con <- dbConnect(postgres, "jdbc:postgresql://localhost:5432/mydbname", user = "myusername", password = "xxx" )

From here on, I can read

my.r.df <- dbReadTable( con, "myschema.mytablename" )

and save

dbWriteTable( con, "myschema.mytablename", my.r.df )

Thursday, 17 December 2009

Left padding of string field in Kettle

I had to left pad a field using Kettle. It was a postal code mistakenly coded as a double in an Access database and it had to be transformed. In my country, postal codes consist of 5 digits, the first of which could be "0".

Mapping the field to "string" was not good enough: blanks were used for padding. In order to use "0", I had to use the JavaScript node in Kettle. The following graphic contains my little code snippet:

For some reason, the code did not "validate" in the node (there is a "validation" button), but the data flow worked as a charm.

Sunday, 29 November 2009

Attach a projector to Xubuntu with Nvidia cards

The other day I faced a problem just before my talk in the first meeting of R users in Spain: I could not project to the big screen. The usual Settings > Display menu was of no help.

What you need to do is to run

sudo nvidia-settings

in your terminal and then go to X Server Display Configuration.

There, after pluging in the video cable for the projector, you should click on the Detect Displays button for the video card to detect the new screen. The Configuration: Separate X Screen button allows you to decide where to project your X, locally, on the projector or in both displays.

Tuesday, 17 November 2009

Restrict ssh access to Linux server to members of a group

You may want to restrict ssh access to a server to members of a group. I faced this problem when I only wanted members in the "consultants" group to be able to log into our CentOS server.

In order to achieve this, you need only edit the file sshd_config (in CentOS, it is located in /etc/ssh, but this may be distribution-dependent) and add the following line to it:

AllowGroups consultants

Mind that this line, contrary to intuition, does not grant members of the "consultants" group the right to log in, but restricts this right to any other member in any other group. So, perhaps you may want to use

AllowGroups consultants root

instead so as to allow root logins (just in case).

Sunday, 18 October 2009

Notepad-compatibility for copy and paste in vim and gvim

Unfortunately, even us, Linux die-hards, get used to other OS conventions, such as copy-pasting with Control-C and Control-V. Maybe because in some other OS, by design, you need to spend hours copying and pasting.

In any case, if you want your Vim and GVim on your Linux box responding to Control-C and Control-V for these operations you need to map these key combinations to their internal counterparts, "+y and "+gP respectively.

In order to achieve this, you need just go to your home directory and add to the .vimrc file there the following three lines:

nmap <C-V> "+gP
imap <C-V> <ESC><C-V>i
vmap <C-C> "+y

A final piece of advice: use it with care! Copy/paste operations do not increase the amount of information but increase its size.

Friday, 2 October 2009

Five levels of purpose

I copy from another source because I want to keep them handy. Here are the five levels of purpose:

  1. Check present position
  2. Set goals
  3. Affirm priorities
  4. Forecast future position
  5. Create change

Too many open files in Alfresco

Recently, my Alfresco installation on Centos 5.3 started to behave randomly and some functionalities became suddenly unavailable. A quick view in the error logs showed a pattern, a string of "too many open file" complaints.

The reason is that there is a limit on the maximum number of open files a user may keep open. The user running Alfresco had just 1024 of them, too few, it seems, for its normal operations. You can check the number of open files allowed per user with the command

cat /proc/sys/fs/file-max

Increasing this value is simple: first, edit the file /etc/sysctl.conf adding a row such as

fs.file-max = 4096

Then, run 

sysctl -p

to make the changes in the file available. Then, finally, you will need to restart your Alfresco installation.