Sunday, 30 May 2010

Using git to deploy code to remote server

I am developing a web application locally (at my laptop). I am using git to version my code. Now, I wish to deploy it to my virtual server (obviously, at a remote location).

Suppose I start from scratch. I usually keep my webpage code in /var/www/my_domain and at the same location in my web server.

The first thing I have to do is to create a bare git repo in my remote machine. Usually, in my home directory. I log into your remote machine and do (thanks to Caius) as follows:

mkdir git_my_domain
cd git_my_domain
git init --bare
git --bare update-server-info
git config core.worktree /var/www/my_domain
git config core.bare false
git config receive.denycurrentbranch ignore
cat > hooks/post-receive
#!/bin/sh
git checkout -f
^D
chmod +x hooks/post-receive

Then, at my local machine, I go to /var/www/my_domain and create a local git repository and add the remote repository I created before as a remote git repository:

mkdir /var/www/my_domain
cd /var/www/my_domain
git init
git remote add vps ssh://username@12.12.12.12[:port]/path/to/git_my_domain

Now I can add files to /var/www/my_domain, commit changes and then deploy automatically typing

git push vps master

Tuesday, 25 May 2010

Permalink issue in Wordpress

As I tried to activate permalinks in Wordpress on Apache, I got 404 errors (page not found) after following the instructions. The problem was related to my default Apache configuration file.

Wordpress relies on Apache's mod_rewrite module for the URL conversion. As you define your conversion rules, it creates a custom .htaccess file that indicates Apache how to rewrite your URLs.

But there is a directive at the Apache configuration file that prevents Apache from reading your .htaccess file explicitly: AllowOverride.

In particular, within my directory section, I had: 

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all


Changed it to

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all


and rocked!

Saturday, 13 March 2010

Annoying error message from startxfce4

Whilst trying to understand errors and warnings in logs from my brand new Xubuntu 10.04, I came accross some annoying error messages on my .xsession-error file:
<stdin>:1:3: error: invalid preprocessing directive #Those
<stdin>:2:3: error: invalid preprocessing directive #or
<stdin>:3:3: error: invalid preprocessing directive #Xft
<stdin>:4:3: error: invalid preprocessing directive #Xft
xrdb: "Xft.hinting" on line 9 overrides entry on line 6
xrdb: "Xft.hintstyle" on line 11 overrides entry on line 7
Not critical, it seems, not serious, just annoying. I guessed that xrdb was the culprit and searched for its configuration files:

carlos@molotov:~$ locate xrdb | egrep etc
/etc/xdg/xfce4/Xft.xrdb

There I had lines starting with "# Those", etc. A look at the man page for xrdb indicated that the Xft.xrdb file is passes through the C preprocessor, (whose directives are preceded by #). It clearly states that comments should be preceded by!rather than #.

So edit the conf file, replace # by!and the annoyance is gone!

Tuesday, 29 December 2009

The best R tricks

This time, the post has been written by others. The community has chosen the best R tricks and made a poll whose results can be browsed at

http://stackoverflow.com/questions/1295955/what-is-the-most-useful-r-trick

Friday, 18 December 2009

Running BOINC on a Centos 5.4 server through command line

I wanted to install BOINC on a Centos 5.4 server with no GUI. I could not find BOINC on any Centos RPM repositories and the newest Linux version did not seem to work.

So I went to the BOINC download page and chose the older 6.6.41 version for x86 Linux with CLI only, and downloaded it with wget to my server. 

The downloaded file was a Bash executable script that expanded a whole directory with a number of programs inside, among which, boinc and boinccmd.

To have BOINC running, you need just do

nohup boinc &

However, the process is not attached to any BOINC project. I wanted to attach to Ibercivis, so I used the following command:

boinccmd --project_attach http://registro.ibercivis.es d44xxxxxxxxxxxx7c3

Of course, I have masked my authorization string, d44xxxxxxxxxxxx7c3. I got it from the file account_registro.ibercivis.es.xml in another installation I had on another machine.

In a matter of seconds, the command 

boinccmd --get_state

indicated that BOINC was already running on my machine. The boinccmd command also allows you to configure plenty of other parameters, but that is way another topic.

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.