Author Archives: Thomas Cokelaer

nosetests: setup and teardown methods

nosetests is a tool used to build unit tests in python. Here below, I show an example on how to write a class that will perform some tests (test that a directory that has been created exists indeed). One issue … Continue reading

Posted in Python | Tagged , | Leave a comment

graphviz plot without graphviz…

Graphviz is a standard tools that is used to create images of graphs (see http://www.graphviz.org/). The graph are described thanks to a language. For instance the graph represented in the following image would be represented as A -> B B … Continue reading

Posted in Computer Science | Tagged | Leave a comment

How to plot left and right axis with matplotlib

Sometimes, it is convenient to plot 2 data sets that have not the same range within the same plots. One will use the left y-axes and the other will use the right y-axis. With matplotlib, you need to create subplots … Continue reading

Posted in Python | Tagged , | 4 Comments

How to call R plotting function from python using rpy2

Python has already very good librairies from plotting (e.g., matplotlib, mayavi), however, it is sometimes useful to use some of the plotting functionalities offered by R. Thanks to the rp2 package, it is quite easy. Let us try to use … Continue reading

Posted in Python | Tagged , , | Leave a comment

ipython

If you start to use python, just install ipython to ease your life by having a more interactive python shell. http://ipython.org/ A nice feature in the ability to embed matplotlib plot. Start with this option: ipython qtconsole -pylab inlineipython qtconsole … Continue reading

Posted in Python | 2 Comments

linux: How do I know the number of memory cards

The dmidecode command dumps lots of information about your system. The option memory gives you details about your memory card. In particular how many are installed (e.g., 2x2Gb or 1x 4Gb) sudo dmidecode -t memorysudo dmidecode -t memory

Posted in Linux | Leave a comment

VIM: switch all text to lower case

You can change the case of a character by typing ~ , however, if you want to change all text to the same case (let us say lower case here), then you should enter the visual mode. Go to the … Continue reading

Posted in Linux | Tagged | Leave a comment

How to embedded data files in python using setuptools

Within a Python package, it is useful to provide data files. These files are not python modules so you do not want to place same together with your module. Let us put them in a directory share/data. Suppose you have … Continue reading

Posted in Python | Tagged , | 8 Comments

HTML: How to redirect to another page

  <meta HTTP-EQUIV="REFRESH" content="0; url=http://whatever"> <meta HTTP-EQUIV="REFRESH" content="0; url=http://whatever"> Note the syntax where content=”0; is not a typo. The content field contains both the URL to be redirect to and the delay (in seconds). In general, you may want to … Continue reading

Posted in Computer Science | Tagged | Leave a comment

installing rpy2 with different R version already installed

The easiest way to install a python package is to use easy_install (or pip), so to install rpy2, type: easy_install rpy2 To test that it is properly installed, type: import rpy2; from rpy2 import robjects; robjects.r(“version”) If this code works, … Continue reading

Posted in Computer Science, Linux, Python | Tagged , , , , | 8 Comments