Tuesday, 13 July 2010
Calling Python from R
Sunday, 4 July 2010
Passing arguments to Python functions
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
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
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_domaincd 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_domaincd /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 masterTuesday, 25 May 2010
Permalink issue in Wordpress
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!