Tuesday, 13 July 2010

Calling Python from R

The new R package, rJython, permits calling Python from R. It is not on CRAN yet, but it will be soon. Details about the package (installation from r-forge, architectural details, etc.) can be found here.

Sunday, 4 July 2010

Passing arguments to Python functions

I found a good reference on how to pass arguments to Python functions using the star (or star-star) notation. You can find it here. Here goes a summary.

If you want to pass unnamed arguments, you can do as follows:

>>> a = (1,5)
>>> range( *a )
[1, 2, 3, 4]


If you want to pass named arguments, you need dictionaries:

>>> a = range( 1, 4 )
>>> b = range( 4, 8 )
>>> def concat( a, b ): return a + b
...
>>> concat( **dict( a = a, b = b ) )
[1, 2, 3, 4, 5, 6, 7]


You can mix named and unnamed arguments thus:

my_foo( *a, **b )

where a and b are a list and a dictionary. Caution needs to be taken to pass a single unnamed argument, though. Details can be found in the reference above.

Passing arguments to Python functions

I found a good discussion on how to pass vectors and dictionaries as arguments to Python functions. It can be found here.

In summary, for unnamed arguments:

>>> a = (1,4)
>>> range( *a )
[1, 2, 3]


And for named arguments:

>>> def concat(a,b): return a + b
...
>>> a = [1,2,3]
>>> b = range( 4,7)
>>> b
[4, 5, 6]
>>> concat(**dict( a = a, b = b ) )
[1, 2, 3, 4, 5, 6]


Named and unnamed arguments can be mixed:

my_foo( *a, **b )

There is only one caveat with functions requiring a single, unnamed argument. See the link above for details.

Wednesday, 30 June 2010

Certificate problem trying to access Google Analytics

I upgraded my Firefox browser to version 3.6.6 yesterday. And I got errors when trying to access my Google Analtics account. A warning indicated me that I got something like a "ssl.gstatic.com:443 uses an invalid certificate".

Unwilling to learn about certificates by myself, I asked Google. And one hour later I found a page with a hint to solve the problem: download this
file (from the same server that issues the certificate) and just accept it.

From that point on, you will be able to navigate your Google Analytics account as usual.

Friday, 18 June 2010

SVG to PS using inkscape

If you want to change the format of your SVG file into PS format, you can use inkscape thus:

inkscape my_graphic.svg --export-eps=my_graphic.eps --export-text-to-path

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!