Dec 2, 2012

Calling C functions from Python

Python is capable of calling functions from a C library. Say, we have the following C code which needs to be used in a python script. I'm using Ubuntu 12.04 with python 2.7.
int add(int a, int b) { return (a+b) ; }
First the C code has to be compiled as a shared library.
$ gcc -fpic -c c_code.c $ gcc -shared -o c_code.o
Then the shared library has to be copied to /lib/x86_64-linux-gnu/
$ sudo cp /lib/x86_64-linux-gnu/
The following python script imports the shared library and invokes functions from it.
from ctypes import cdll,c_int lib = "" dll = cdll.LoadLibrary(lib) add = (lambda x,y: dll.add(c_int(x), c_int(y))) print(add(1,1)) print(add(2,3))

Nov 30, 2012

Fixing broken merge list in Ubuntu

Sometime broken merge list poses a barricade on the path of further updates. To fix this problem, the old (flawed) merge list has to be removed first, then a new one has to be created. In Ubuntu 12.04, the following worked for me.
sudo rm /var/lib/apt/lists/* -vf sudo apt-get update

Nov 7, 2012

Opening a Terminal Anywhere in Ubuntu

Being able to open a terminal from any location on the file system tree (even when you're logged in on a remote server) is a very useful feature. Installing nautilus-open-terminal provides this option in the context menu. To install,
$ sudo apt-get install nautilus-open-terminal
Natuilus file system needs to be reset after installation. To do so,
$ nautilus -q
Right click to bring up the context menu and be happy to see the 'Opne in terminal' option :)

Oct 13, 2012


Quoting from the Matplotlib website,

matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell (ala MATLAB®* or Mathematica®), web application servers, and six graphical user interface toolkits.
It allows generation of publication ready plots and charts from a python script. Just started using this in one of my current projects and finding it satisfactory so far. The matplotlib figures can also be exported to a number of bitmap formats and vector formats like PDF. A definite advantage compared to MATLAB.

I'm using Ubuntu these days, to install Matplotlib in your Ubuntu box:

1. Ubuntu software centre,
2. Install it using apt
$ sudo apt-get install python-matplotlib

Oct 3, 2012

Python in Ubuntu

My favorite development environment for Python in Ubuntu is Eclipse. The following steps describe how to get an up and running development environment on your Ubuntu box.

1. Python

Python usually comes with the bundle but just in case:
$ sudo apt-get install python

2. Eclipse

Eclipse is available from the Ubuntu Software Center, I usually install it from there that. Another option is to install it manually, which I never tried myself.
$ sudo apt-get install eclipse sun-java6-jdk $ sudo udate-java-alternatives -s java-6-sun

3. Pydev

  1. Run Eclipse
  2. Help -> Install New Software
  3. Type in "Work with":, name should be Python
  4. Select Pydev from the list of available options, then click Next
  5. Select the Python module that needs to be installed, click Next
  6. Let the downloading finish, then restart Eclipse

Ubuntu Installer for Windows

Ubuntu 12.04 (the latest version at the time of writing this) has an installer for windows which can be downloaded from here. It allows you to download the installer as a windows executable (.exe) and perform the installation like installing many other windows applications. Thanks, Ubuntu.

Mar 31, 2012

Using LaTeX in Windows 7

Despite being a supporter and believer of software freedom, often times I've to compromise and use proprietary software. Since many of the people I have to collaborate and communicate with are completely running on proprietary or mixed platform like me, its a good idea to have a list of open source and proprietary software combinations of choice.

My favorite combination of software tools for using LaTeX in Windos 7 is MikTex, LEd. MikTex is the core LaTeX engine, can be downloaded for free from the miktex project's website. MikTex comes with it's own editor, but I prefer LEd since it allows arranging source files into projects. LEd can be downloaded from here.

For the MikTeX+LEd combination, MikTeX must be downloaded and installed before LEd since it uses the MikTex engine for compiling documents.

Mar 27, 2012

Matlab Cell Array

Cell arrays is a tabular data structure in Matlab, useful for storing heterogeneous objects whereas arrays can hold only homogeneous objects. Elements in cell array can have different dimensions as well. Elements of cell array, called cells, can contain
  • numeric arrays
  • strings
  • structures
  • cell arrays
Following example code creates and populates a cell array :

A = {['1st element'] [2 3] [8 9 7; 1 2 3] ['a' 'b']};

Index is written within curly braces e.g. A{1} to access the elements of a cell array. To recursively display the contents of a cell array, celldisp function can be used. For example, celldisp(A) produces the following result

A{1} =

1st element

A{2} =

2 3

A{3} =

8 9 7
1 2 3

A{4} =


The contents of a cell array can be visualized with cellplot function, cellplot(A) would produce the following visualization.

This entry on mathworks blog can be consulted for farther information.

Mar 17, 2012

Useful keyboard shortcuts for Sciplore Mindmapping

This post will be expanded / edited as I find more and more useful keyboard shortcuts

Graphical link : Crtl + L
Select two nodes in the order (source, destination)

Move a node : Crtl + Arrow
Moves the node one higher/lower along the tree or shifts it in the ordered list of nodes in same level

New sibling node after selected one : Enter

New sibling node before selected one : Shift + Enter

New child node : Insert

Feb 13, 2012

Sciplore MindMapping

Sciplore MindMapping is an excellent software tool for researchers. Besides the ability to create mind maps of your brainstorming sessions, it allows linking nodes of the mind map with PDF files in your computer, import book-marks and references stored in BibTex format. Recommended for researchers in all scientific disciplines.

What started as a research project by the PhD students Bela Gipp and Jöran Beel at the University of Magdeburg, Germany in 2008 is a full fledged and still growing software tool and platform assisting research in many fields. Here is a little introductory video from their website.