Setting up a git submodule for Bitbucket’s wikis

One of the great features offered by Bitbucket is having a wiki for your projects.

Bitbucket’s wikis use Markdown and are themselves git repositories; wikis use however in a separate git repository than the main project’s one.

To manage my projects wiki and keep it in sync with my main repository I use a git feature called submodule.
Git submodules are explained very well in the “Pro Git Book” by Scott Chacon –Chacon’s book is a recommended reading to get a good knowledge of git–.

As explained in the section dedicated to submodules:

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

and are therefore ideal to manage the wiki for your project.

To setup one is quite straightforward and can be easily done in a shell:

cd /your/project/path/
git submodule add wiki
# note: the wiki subfolder must not be present in your project main directory

This will create a subfolder wiki in your project path and add a “.gitsubmodules” file.

The wiki folder behaves as an indipendent git repository and you have to commit your changes manually by going in the
directory and use the standard git commands.

When you clone a repository that has submodules, the directory structure is created manually; you have, however, to manually init the submodules and pulling the content.

You do this with the git submodule init and git submodule update commands.

For further information on git submodules check Scott Chacon’s book

Reduce pdf size from command line

Ensure to have ghostscript installed.

Open a terminal and use the following command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=COMPRESSED_DOC.pdf DOC_TO_COMPRESS.pdf

PDFSETTINGS can be one of these values:

/screen selects low-resolution output similar to the Acrobat Distiller “Screen Optimized” setting.
/ebook selects medium-resolution output similar to the Acrobat Distiller “eBook” setting.
/printer selects output similar to the Acrobat Distiller “Print Optimized” setting.
/prepress selects output similar to Acrobat Distiller “Prepress Optimized” setting.
/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.


Fix PyDev not working in Eclipse after update (Ubuntu 12.04)

Fix PyDev not working in Eclipse after update

If PyDev stopped working after updating it, it is probably because your Ubuntu is not using Java 7 VM.

To fix this, first remove the plugins from Eclipse.

Next install Java 7 in Ubuntu

sudo apt-get install openjdk-7-jdk

and configure it as the default JAVA VM using

sudo update-alternatives --config java

After these steps open Eclipse and reinstall PyDev again.
Everything should now work as before.

Creating named shortcuts to long paths in Ubuntu

I often browse through folder that have very long path names in bash.
I have decided to enable shortcuts for this folders and reduce the amount of typing.

To get this I created a directory .symlinks in my home directory:

mkdir ~/.symlinks

Next I created symbolic links to my project folders in .symlinks, for example:

cd ~/.symlinks
ln -s /full/path/to/my/very/long/project project

Continue reading

Installing pyqt4 and sip in a virtual environment – Ubuntu 12.04

When you create a virtual environment using the --no-site-packages option, you might experience some difficulties in installing PyQt and SIP in it (I certanly did!).

In this post I will explain how you can install PyQt and SIP in your virtual environment. All the steps require working in a terminal, so open one (CTRL+ALT+T).

First of all you want to be sure that all the necessary dependencies are installed on your system:

sudo apt-get install python-dev python-qt4 python-qt4-dev python-sip python-sip-dev build-essential gfortran libqt4-dev qt4-qmake libpq-dev libsqlite3-dev qt4-dev-tools qt4-doc unixodbc-dev pyqt4-dev-tools

**NOTE: there might be some redundancy, however I found that installing these packages makes things work**

Activate your virtual environment and create a subdirectory build/SIP in it:

mkdir -p full/virtualenv/path/build/SIP

(here and in the following substitute full/virtualenv/path with the full path of your virtual environment.
Download the latest stable source code from here and extract the source code in build/SIP.

From this directory run these commands:

sudo make install #it needs to remove a file from the /usr/lib python directory..

Note that the make step might take some time.

We can now install PyQt4.
First of all we need to make some libraries available in our virtual environment.

cd /full/virtualenv/path/include
ln -s /usr/lib/qt4 .

Download the PyQt4 source code from here
and extract it in full/virtualenv/path/build/PyQt4 (create it if it doesn’t exist).

Go in the directory where you have extracted the source code:

cd full/virtualenv/path/build/PyQt4

In this directory type the following commands:

make #this can take a very long time
make install

You might see a message like make: [install_pyuic4] Error 1 (ignored). This is not an error, but rather a warning that can be safely ignored (as explained in this page: this happens when attempting to strip a file that is not a binary but a script, as is the case of pyuic4).

Now you should be able to use PyQt4 in your virtual environment!

Change bash prompt in a virtual environment

I like to have visual clues when I am working on my python code in a virtual environment. Virtualenv has an option
(--prompt) to add a prefix to your default prompt, but the final result is quite ugly.

What I find more pleasant is substituting the name vename of the virtual environment to the user name in my bash shell prompt; I also like to have vename coloured, so that I immediately know when the virtual environment has been activated.

This can be achieved pretty easily by modifying the definition of $PS1 in the file


contained in your virtual environment folder. For example setting:

PS1="\[\e[1;31m\]vename\[\e[0m\]@\h:\w\$ "

produces the prompt to be displayed like:


To customize your prompt with more advanced features check the official bash documentation.

– EDIT 08/08/2013 –

Setting the variable as explained above prevents the title of a terminal to be updated when changing folder.

To fix this one can set the PS1 variable as:

PS1="\[\e]0;vename@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\e[1;31m\]vename\[\033[0m\]@\h:\w\$ "