Mostly technical stuff

Hibernate/Suspend with Nvidia Drivers on Gentoo

The proprietary Nvidia drivers from x11-drivers/nvidia-drivers contain the closed-sources drivers from Nvidia for Linux. On my laptop, the current version show problems when hibernating/suspending. Several people found that the resume operations do not properly bring up the X-sessions. The same problem occurs on my GTX 1060 laptop. None of the helpful tips found on the Internet would allow me to hibernate/resume when the drivers are loaded.

The only solution that worked for me, is to unload the drivers before going into hibernate and to load them after the resume operation is completed. If you configured your hibernate using this tutorial, and are using sys-power/pm-utils and sys-power/upower-pm-utils, then you can place the following script in /etc/pm/sleep.d/ to unload and load the drivers:

# 01nvidia_drivers: unloads and loads nvidia drivers before and after suspend operations

function unload_if_loaded() {
    if lsmod | grep "$MODULE" &>/dev/null; then
        rmmod $MODULE

case "$1" in
       unload_if_loaded nvidia_drm
       unload_if_loaded nvidia_modeset
       unload_if_loaded nvidia
       modprobe nvidia_drm
   *) exit $NA

You can place the script to /etc/pm/sleep.d/01nvidia_drivers and make sure it is executable.

chmod +x /etc/pm/sleep.d/01nvidia_drivers

Afterwards, you should be able to hibernate/resume properly.

Silent startup failure for MongoDB on Raspberry Pi (and other systems)

Yesterday I tried to install mongodb on my Raspberry Pi. Raspbian Jessie ships with a default mongo 2.4 package, so the installation should be pretty straightforward:

apt-get install mongodb

However, after the installation finished, the service did not start:

service mongodb start

did not result in a started mongod process. No log files in /var/log/mongodb were produced, indicating that the process stops before the logging is initialized. If the mongodb server is started manually, a very early crash can be observed:

sudo -u mongodb /usr/bin/mongod  --config /etc/mongodb.conf
Sun Mar 27 07:48:45.296 terminate() called, printing stack (if implemented for platform):
 0x664160 0x16d954 0x767ea9a0
 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x1c) [0x664160]
 /usr/bin/mongod(_ZN5mongo11myterminateEv+0x54) [0x16d954]
 /usr/lib/arm-linux-gnueabihf/ [0x767ea9a0]
Sun Mar 27 07:48:45.299 Got signal: 6 (Aborted).
Sun Mar 27 07:48:45.302 Backtrace:
0x664160 0x16e370 0x765be180 0x765bcf70
 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x1c) [0x664160]
 /usr/bin/mongod(_ZN5mongo10abruptQuitEi+0x2a0) [0x16e370]
 /lib/arm-linux-gnueabihf/ [0x765be180]
 /lib/arm-linux-gnueabihf/ [0x765bcf70]

Stracing the syscalls shows that the error is generated shortly after mongod tries to load locales:

munmap(0x76f24000, 4096)                = 0
open("/usr/lib/locale/en_GB.UTF-8/LC_NUMERIC", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_GB.utf8/LC_NUMERIC", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_GB/LC_NUMERIC", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en.UTF-8/LC_NUMERIC", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en.utf8/LC_NUMERIC", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en/LC_NUMERIC", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
gettimeofday({1459065376, 950211}, NULL) = 0
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=118, ...}) = 0
fstat64(4, {st_mode=S_IFREG|0644, st_size=118, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x76f24000
read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0"..., 4096) = 118
_llseek(4, -6, [112], SEEK_CUR)         = 0
read(4, "\nUTC0\n", 4096)               = 6
close(4)                                = 0
munmap(0x76f24000, 4096)                = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x76f24000
write(1, "Sun Mar 27 07:56:16.950 ", 24Sun Mar 27 07:56:16.950 ) = 24
write(1, "terminate() called, printing sta"..., 65terminate() called, printing stack (if implemented for platform):) = 65
write(1, "\n", 1
)                       = 1
futex(0x7667e5d8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
write(1, "0x664160 0x16d954 0x7679a9a0 \n", 300x664160 0x16d954 0x7679a9a0
) = 30
write(1, " /usr/bin/mongod(_ZN5mongo15prin"..., 65 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x1c) [0x664160]
) = 65
write(1, " /usr/bin/mongod(_ZN5mongo11myte"..., 59 /usr/bin/mongod(_ZN5mongo11myterminateEv+0x54) [0x16d954]
) = 59
write(1, " /usr/lib/arm-linux-gnueabihf/li"..., 68 /usr/lib/arm-linux-gnueabihf/ [0x7679a9a0]
) = 68

It turns out that I did not change the default locale on my installation (which was en_GB.UTF-8), and did not make sure a proper locale was generated for this setting.

To fix the error, first make sure you pick the right locale. This can be changed by running

dpkg-reconfigure locales

There, you can first pick the locales that should be generated:

Afterwards, you can pick the locale that should be used on the system:

dpkg-reconfigure will then generate the locales that are supported. The changes will be applied after the next reboot. Make sure they are actually used in your current session by running


Afterwards, mongodb should start just fine.

If you are not on a debian system, you can make sure that the proper locales are generated by editing


and uncommenting all locales that you need. Afterwards you need to generate


which will generate the locale files. Setting the LANG environment variable is something that is distribution specific. Check your manual on where you can find the proper place to configure the locale. On debian-based systems, you can find it in


on Gentoo, check your


ELPY Cheat Sheet

ELPY is a python programming environment. The features are documented here.

The following table summarises the default key bindings for the functions of version 1.11.0:

Key Binding Function
C-down Forward one indentation block
C-up Backward one indentation block
C-left Backward one indentation level
C-right Forward one indentation level
M-down Move line or region down
M-up Move line or region up
M-left Move line or indentation block left
M-right Move line or indentation block right
M-x elpy-set-project-root Set the root directory of the python project
C-c C-f Find file in project
C-c C-s Regular expression match in project
M-TAB Complete current statement
M-. Goto defition
M-* Return to position from last definition lookup
C-c C-z Switch to python shell
C-c C-c Send python code to shell (active region or complete buffer)
C-c RET Send current line to python shell
C-M-x Sends code of current top level function to python shell
C-c C-v Syntax check with flake8
C-c C-n Next flake8 error
C-c C-p Previous flake8 error
C-c C-t Start tests
C-c C-e Edit all occurrences of the symbol at point at once
C-c C-r f Format code using the available formatter
C-c C-r i Query for new imports of unresolved symbols, and remove unreferenced imports
C-c C-r r Run the Elpy refactoring interface for Python code

Python PIP Package Updates on Mac OS X

Updating all python packages that are installed via pip is often referred to as running something like the commands

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

However, some problems can occur on Mac OS X, as certain default packages are included into the base python installation.

Packages that rely on new versions of pre-installed packages will throw errors as the default python search path prefers the pre-installed packages. An example is matplotlib: Version 1.5 of matplotlib requires a newer version of the six package than version 1.4.1 that is shipped on El Capitan and errors out with the following message:

/Library/Python/2.7/site-packages/dateutil/ in <module>()
 15 from six import advance_iterator, integer_types
---> 16 from six.moves import _thread
 18 __all__ = ["rrule", "rruleset", "rrulestr",

ImportError: cannot import name _thread

You can fix this problem by properly setting your python path environment to prefer the python pip installed packages. The path can for example be set in the ~/.bashrc to point to

export PYTHONPATH="/Library/Python/2.7/site-packages:$PYTHONPATH"

PEP8 for vim using flake8

In order to auto format your python code according to the guidelines defined by PEP8, you can use some sane default for editing python files and flake8 to check and fix possible errors in your scripts.

Default indentation rules for python files

The default indentation rules do not comply with PEP8. In order to change them for python files, create a new file in ~/.vim/ftplugin/python.vim and place the following content in this file:

setlocal tabstop=4
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal smarttab
setlocal expandtab
setlocal shiftround
setlocal autoindent

PEP8 recommends that code should have a maximum line length of 79 characters. You can enforce this by adding the following line to the file:

setlocal textwidth=79

However, it can be a good idea to have longer lines, I prefer to not have a hard wrap at 79. You can therefore opt to show a marker that helps you to avoid the character line limit by setting:

setlocal colorcolumn=80
Install flake8

flake8 is a python module that you can install using your favourite package manager, e.g. using pip:

sudo pip install flake
Install vim-pathogen and vim-flake8

vim-pathogen is a vim script that helps with managing the runtimepath to simplify the vim plugin management. You can install it by running the following command:

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim

then add the following to your .vimrc

execute pathogen#infect()

Afterwards, install vim-flake8:

cd ~/.vim/bundle
git clone

This is everything you need to do. Afterwards, you can open vim on a python file and press < F7 > to start flake and obtain information on your formatting.

Newer Posts Older Posts