Converting Microsoft Word Files (doc, docx) to reStructuredText (rst)

This article describes how to convert Microsoft Word documents to reStructuredText. Everything should be done within a temporary directory with simplified filenames. So let’s assume you want to convert ‘am.docx’ to reStructuredText. The Word document can contain images.
You need:
A few simple steps:
  1. On the command line (either the old cmd or the PowerShell) go to the temporary directory that contains the Word document (e.g. C:\temp):
    cd c:\temp
  2. Convert ‘am.docx’ to ‘am.rst’ using pandoc
    pandoc.exe -f docx am.docx -t rst -o am.rst
  3. Extract the media files (e.g. images) from the Word document
    unzip .\am.docx

    and move it to current working directory

    mv .\word\media .
  4. All image files should be in the same file format, so convert eml and gif files to png.
    cd media

    to jump into the directory

    dir (to list all files)

    a) Either by hand:

    convert .\image2.gif .\image2.png
    convert .\image1.emf .\image1.png

    b) Or automatically by using mogrify (also part of ImageMagick):

    mogrify.exe -format png *.emf
    mogrify.exe -format png *.gif

    And clean up:

  5. rm *.gif
    rm *.emf
  6. Do not forget to search and replace .emf and .gif with .png in the .rst file with the editor of your choice (gvim or notepad++)
  7. Check the build by creating a quick Sphinx:
    run sphinx-quickstart (and follow the instructions)
    copy the file over the main doc in the source dir
    copy the media folder to source
    run “make.bat html” to create the a website and check the result.

Boosting OwnCloud’s Performance with APCU on Ubuntu with Plesk

Memcaching boosts the performance of OwnCloud dramatically. Read about this here. My server is running Ubuntu 12.04 LTS. PHP 5.6 and 7.0 is handled by Plesk. In my experience 5.6 is the most stable running with OwnCloud. APCU is supported by OwnCloud but was not present as a module in PHP (Only on the Sytem providing PHP 5.4). So here’s how you install it.

This is a follow up to my previous post on installing custom modules for PHP handled by Plesk. So I assume that all required software to build the modules is installed.

No ACPU module available
No ACPU module available

For PHP 7.0 simply run:

$ /opt/plesk/php/7.0/bin/pecl install apcu

PHP 5.6 is a bit more stable for running OwnCloud. However you will get an error that you need at least PHP 7.0 for installing ACPU. This is true for the current release (>5.0). So simply install the stable 4.x release:

$ /opt/plesk/php/5.6/bin/pecl install apcu-4.0.10

Register the module with PHP:

For PHP 7.0.x:

$ echo "" > /opt/plesk/php/7.0/etc/php.d/apcu.ini

For PHP 5.6.x:

$ echo "" > /opt/plesk/php/5.6/etc/php.d/apcu.ini

Reread the config:

$ plesk bin php_handler --reread
ACPU module available
ACPU module available

Now the only thing left is to add

'memcache.local' => '\OC\Memcache\APCu',

to your configuration file of OwnCloud (e.g. /var/www/owncloud/config/config.php).


Running Custom PHP Modules in Plesk on an Ubuntu Server: MemCached

This article is inspired by It was written for CentOs/Fedora/RedHat servers having yum instead of apt. I run Ubuntu 12.04 LTS on a virtual server. Among other applications I host WordPress and OwnCloud here. Plesk allows to use newer PHP versions (5.6.x and 7.0.x) instead of the dated one (5.4.x) that comes with my old Ubuntu.
No MemCached module available
No MemCached module available
Here are the necessary steps:
  1. Install required packages to compile modules for PHP
    $ apt-get install gcc build-essential plesk-php56-dev plesk-php70-dev libmemcached-dev libmemcache0 zlib1g-dev

    Be aware that there may be some other packages that you need to install that I did not list here since they probably were already installed on my server. If you run into missing headers this might be an indicator for that.

  1. Install the memcached module:
    $ /opt/plesk/php/5.6/bin/pecl install memcached
  2.  You will be asked for the “libmemcached directory [no] :”
    The default is “no”. If you have no need for sasl answer:

    no --disable-memcached-sasl

    If you need memcached with sasl2 support you can install it manually following this advice.

  3. After the installation is finished you need to register the module with Plesk:
    $ echo "" > /opt/plesk/php/5.6/etc/php.d/memcached.ini
    $ plesk bin php_handler --reread
MemCached module available
MemCached module available

Hiking & board games @Yosemite

Last weekend we visited Yosemite National Park. What a great place to hike. Of course we brought some board games. I just wanted to share some advice and impressions.

  • If you drive to Yosemite from San Francisco International Airport, a great place to stay is Yosemite Gold Country Lodge in Coulterville. This place is run by Ken, a really nice guy who invited us to his farm. The rooms are spacious, feature a fireplace (gas) and a fridge. Outside there is a grill. So you can get some meat from the store and have a BBQ at night.
    20151107_085418 20151107_085423 20151106_181636 20151109_110347 20151109_111625
  • From there it only takes about one hour to get to the entrance of Yosemite and about two hours to get to the trails. Probably longer due to taking pictures along the road.
    DSC_0093-002 DSC_0131-002 DSC_0127-002  DSC_0188-002
  • Hotels inside the park are expensive. But you can get a heated tent at a reasonable price at Camp Curry. But be prepared: It can be quite cold in November! But you wake up to an amazing view.
    DSC_0785 DSC_0714 DSC_0709 20151109_070719 20151109_065112 20151109_065108
  • Just right outside the park, at El Portal, there are a few Hotels where one can get a deal through Expedia. We stayed at the Cedar Lodge. But: No free Wifi, , no coffee, etc. But the rooms are ok. However, the food at this place is supposed to be pretty bad if you believe TripAdvisor ratings. It was supposed to be better at next to the hotel Yosemite View Lodge: The River Restaurant & Lounge. So this is where we went. The salad bar was great. Lynns Burger was burned (really totally black) at their first try, but she sent it back and got a good one quickly.
  • Getting food (some cheese, bread, juice and milk) for the hike at a local grocery store is probably the best option.
    DSC_0344-001 DSC_0348-001 20151108_094334 20151108_094326
  • Some of the hiking trails are paved with asphalt to be accessible for everybody. Some are a bit more difficult and go into the wilderness. The best way to select one that suits your skills is the Chimani Yosemite App. It is available for Android and iOS. They also have an app that features all National Parks in the USA. I really recommend getting it! The links point to the Android version in the Google Play Store since I do not have any iOS devices.DSC_0251-001 DSC_0270-002
    DSC_0255-002 DSC_0327-002
  • Wildlife in Yosemite Valley is not so wild anymore.
    DSC_0166-001 DSC_0763 DSC_0778 DSC_0801
  • Bringing some games along is a must for every board game fanatic! It is just a lot of fun playing in such a great environment. This time we brought Tash Kalar: Arena of Legends by Vlaada Chvátil (Czech Games Edition), Tiny Epic Galaxies by Scott Almes (Gamelyn Games) and Star Realms by Robert Dougherty and Darwin Kastle (White Wizard Games). All of theses games are very portable. For Tash Kalar I just carry the game board, cards and chips. Tiny Epic is tiny anyway and Star Realms is just a deck of cards.
    DSC_0536 DSC_0543 DSC_0564 DSC_0572 DSC_0567 DSC_0577 DSC_0292-002 DSC_0560 DSC_0556 DSC_0421-001 DSC_0418-001 DSC_0416-001 DSC_0407-001 DSC_0401-001
  • On the way back to San Francisco we stayed at Ken’s Motel again. Tiny Epic in the hotel room…
    DSC_0932 DSC_0931 DSC_0930  DSC_0928
  • Enjoy!
    DSC_0382-001 DSC_0376-001

The DFT Song

Years ago I attended a summer school in Denmark on Density Functional Theory (DFT) and the use of the Atomic Simulation Environment (ASE) and the GPAW code. Kieron Burke (for those of you who don’t have a clue: he’s the “B” in PBE) was one of the invited speakers. He’s a great scientist but also a fantastic entertainer.
Towards the end of the poster session, he announced another lecture taking place immediately. And he said it was mandatory to attend! So everybody went back to the lecture hall and sat down. While stating that you have to “sing along if you want any more beer” he started a presentation with the lyrics of the DFT song (which he had written together with Volker Blum) and everybody sang along to the tunes of “Let it be” by The Beatles.
I pulled out my smartphone and took pictures of the slides. So here are the lyrics… get a karaoke version of the song and sing along!
Feel free to add new verses in the comments!

The DFT Song

Written by Volker Blum and Kieron Burke

To the tune of “Let It Be” (with apologies to John and Paul)

When I find my model’s unpredictive,
Walter Kohn just comes to me,
speaking words of wisdom,
And in my hour of code-debugging,
he stands right in front of meee,
saying “you just gotta learn
your chemistree”.
B3LYP, hee-hee-hee.
Which approximation should I use,
in my DFT?
And when I find my state’s degenerate,
I turn next to Mel Levy
Constrained searches work the best
for formality.
In LDA I have some faith,
if my system’s running free
But LDA can never give
A dis-Cont-inuit-eee.
DFT, convexity,
Not Thomas-Fermi, nor Hartree-ee
Exact conditions tell the truth,
no fitting need there be.
And in my hour of darkness,
with van-der-Waals in front of meee,
my graphene comes out bad,
with stupid PBEee.
But now there’s Langreth-Lundqvist,
doing even ATPee,
let’s all go to medical conferences,
running DFTee.
I can always find a functional,
to make it all agree.
But when my band gap’s tiny,
far to small to see,
I don’t like your answer,
For though it may be parted
with hybrid E-X-Cee,
Can I trust my answer,
in realitee?
I thought you were first principles,
And when the broken-hearted gap,
opens up to full degree,
How’ll I get the answer,
tell me DFTee?
For though the band gap may be parted,
there’s a chance that you will see:
GW is the answer,
thank you Rex Godbee!
Many bod-eee, not DFT,
Many bod-eee, no densitee,
this must be the answer,
on which we’ll all agree!
And when I’ve found the structure,
there’s still a light that shines on me,
So Walter wont let me use,
ground-state DFTee.
To find the optical spectrum,
while staying p’rameter-free,
We must ask a little Gross,
the one called Hardeee.
DFT, 123,
now TD-, DFT
Let’s get excitations,
with more skulduggeree.
It’s the weirdest physics,
but makes great chemistreee!

Building a Custom Kernel (3.14) on Ubuntu (Raring, Saucy, Trusty)

Kernel 3.14 was released yesterday. I use this as an opportunity to show you how to build a custom Linux kernel on debian based distributions. It should not really matter which version or distribution one you are running as long as it is based on Debian (I am running the beta version of Ubuntu Trusty Tahr).
The important point is that you use a method that directly creates .deb packages, so that you do not have to worry about uninstalling manually.
But why should you upgrade the kernel anyway you might ask. Well, maybe you shouldn’t, except if you really need one of the new features (like the new scheduler in this release). Or just because you can.
You have to do all steps as root or you can just type “sudo bash” or “sudo zsh” to open a bash or zshell with superuser privileges.
First you need to install the dependencies. Please let me know in the comment section if I forgot something. This step is not shown in the screenshot since I have all the stuff on my system anyway.
apt-get install wget bzip2 kernel-package build-essential
Then go to the system source directory, download and extract the latest release. The wget link in the example refers to version 3.14, but you can simply replace the link to any desired version. Then change into the directory that was created.


cd /usr/src
wget --no-check-certificate
tar xf linux-3.14.tar.xz
cd linux-3.14


Take over the configuration from the kernel which is currently installed on your system.

make oldconfig


The new features and settings have to be adjusted manually. So you will be asked about them. If you have no idea what it is about it is just safe to take the default by pressing enter.


You can adjust the settings afterwards by typing “make menuconfig”. This will bring you to a ncurses based menu where you can change all kernel settings. The default for almost all modules of the kernel is to build them, but load only the necessary modules.  I recommend disabling kernel modules that you do not use at all. This will speed up the compilation. For example I do not use a remote control (IrDA module) on my desktop or amateur radio, so I just disable the building of the modules (changing <M> to < >).

Then it is time to build the kernel and create deb packages for the image itself, the headers and the source.

make-kpkg --initrd --append-to-version=-custom 
kernel_image kernel_headers kernel_source


This will take some time. After the compilation is finished .deb files are automatically created (located at /usr/src). Install them and you’re done 🙂


cd ..
dpkg -i *.deb


On the next boot Linux automatically uses that kernel image as default. You can always check for the kernel version by typing “uname -a”.
Cheers, Michael


Awesome window manager: Missing icons in Control Center

If you’re running the awesome window manager and are using the gnome-session or gnome-settings-daemon as well as the gnome-control-center you might have noticed it is missing some icons (see screenshot on the right).
This is due to an entry in the “gnome*panel*.desktop” files located in “/usr/share/applications”: 


You can quickly fix this by changing it to:


Of course you do not have to do this by hand. Simply use this handy command:

sudo find /usr/share/applications/ -name "gnome*panel*desktop" -print 
 | xargs sudo sed -i 's/OnlyShowIn=GNOME;/OnlyShowIn=GNOME;Awesome;/g'

Python 3.4 and Django on Ubuntu 13.10

Why bother about Python versions? 

I recently started a new project creating a web application. As I have a lot of Python programming experience I chose Python with Django over Ruby on Rails. At the beginning of a new project I prefer using the latest versions of the frameworks the application will depend on. Starting now with Python 2.7 would mean that sooner or later there would be additional work porting the codebase to Python 3. Yesterday, Python 3.4 was released. One of the biggest improvements is that it has pip already included which makes handling virtual environments and installing the latest release of Django really easy.

Building Python from source

The downside is, that Linux distributions do not include the latest Python release yet. Most of them still ship with Python 2.7 as default version. The next Fedora and Ubuntu releases might change that, but for now you need to compile it from source. Luckily that is not a hard task. Go to the download page and grab the latest Python release (recommended if you read the post later and a newer version was released) or past the following command into a terminal.

First make sure you have everything installed to compile Python from source.

sudo apt-get install build-essential

Before downloading create a temporary directory to make the cleanup easier. At the end you can just delete “tmpPython”.

mkdir tmpPython
cd tmpPython
wget --no-check-certificate
tar xvf Python-3.4.0.tgz

After the archive is extracted, cd into the source directory. Create a directory to install to, then run configure, build and install.

cd Python-3.4.0
sudo mkdir /opt/Python34
./configure --prefix=/opt/Python34 && make -j4
sudo make install

Now you have Python 3.4 installed on your system.
Add the the path containing the executable to your environment.

export PATH=/opt/Python34/bin:$PATH

Also make sure to add this line to your .bashrc file (or .zshrc if you’re using zsh).

echo "export PATH=/opt/Python3.4/bin:$PATH" >> $HOME/.bashrc

Creating a virtual environment

Go to the directory where you want to create the virtual environment. I recommend /opt if you collaborate with others within the environment (you have to create everything with sudo) or your home directory if you work alone. Then run pyvenv to create it.
pyvenv-3.4 djangoEnv
source djangoEnv/bin/activate

The bash prompt changes to

(djangoEnv) mpei@earth /opt

and that means that you are now within this virtual environment.
This command shows you what you have installed:

pip freeze

Installing Django

Just use pip to install the latest version of Django and its extension:
sudo pip install django django-extensions

And you’re done! You can check the installed versions by running “pip freeze” again. Maybe another blog post on Django and databases? Or the first steps in Django? We’ll see… bye bye!

Organizing C/C++ includes

After starting my new job programming in a big software project I spent some thought on organizing includes and give a recommendation. Here’s what I’ve come up with. As always, some things are obvious, some are not…

  1. You should only include what is necessary to compile the source code. Adding unnecessary
    includes means a longer compilation time, especially in large projects.
  2. Each header and corresponding source file should compile cleanly on its own. That
    means, if you have a source file that includes only the corresponding header, it
    should compile without errors. The header file should include not more
    than what is necessary for that.
  3. Try to use forward declarations as much as possible. If you’re using a
    class, but the header file only deals with pointers/references to
    objects of that class, then there’s no need to include the definition of
    the class. That is what forward declarations are designed for!

    // Forward declaration

    class MyClass;

  4. Note that some system headers might include others. But apart from a few
    exceptions, there is no requirement. So if you need both
    <iostream> and <string> include both, even if you can
    compile only with one of them.
  5. To prevent multiple-inclusions, with loops and all such attendant horrors is having an #ifndef guard.

    #ifndef _FOO_H
    #define _FOO_H
      …contents of header file…

  6. The order in which the includes appear (system includes and user includes) is up to the coding standard you follow.
  7. If you have the choice of picking a coding standard regarding the order at the beginning of a new project, I recommend to go from local to global, each
    subsection in alphabetical order. That way you can avoid introducing
    hidden dependencies. If you reverse the order and i.e. myclass.cpp
    includes <string> then <myclass.h>, there is no way to catch
    at build time that myclass.h may itself depend on string. So if later someone includes myclass.h but does not need string, he’ll
    get an error that needs to be fixed either in the cpp or in the header
  8. So the recommended order would be:
    • header file corresponding to its .cpp file
    • headers from the same component
    • headers from other components
    • system headers

If you use the Eclipse IDE (which I highly recommend), you can use a very nice feature that helps you organizing includes (“Source -> Organize Includes”).