How to configure USBMount

USBMount is a useful program and daemon that can be used to automount disk drives and flash drives plugged into USB ports. I use it with Raspbian for this purpose.

All the settings of USBMount can be changed from its configuration file /etc/usbmount/usbmount.conf

The parameters that can be modified from this file:

  • ENABLED: 1 to enable, 0 to disable USBMount.

  • MOUNTPOINTS: String of space-delimited mount points that should be used.

  • FILESYSTEMS: String of space-delimited filesystems that should be mounted.

  • MOUNTOPTIONS: String of comma-delimited mount options that will be used with the mount program to mount all the filesystems.

  • FS_MOUNTOPTIONS: Mount options that are specific to particular filesystem.

  • VERBOSE: no is no logging, yes is logged to /var/syslog

Tried with: USBMount 0.0.22 and Raspbian 7

How to export from Anobii and import to Goodreads

Anobii is a fairly popular book community, that sadly is losing out to Goodreads. When most of your bookworm friends are on Goodreads, you might want to move your book shelf, ratings, reviews and other info to Goodreads. This is fairly easy to achieve.

Export from Anobii

  • Login to Anobii. Go to Settings -> Export Data. Select the format as CSV and Submit.

  • You will receive an email in a few minutes with a CSV file attached. Download this file and rename it as anobii.csv.

Convert from Anobii to Goodreads

  • To convert between the export format of Anobii and import format of Goodreads, we use the Anobii2Goodreads script. Git clone it or download the code.

  • Place the anobii.csv in the directory containing the anobii-to-goodreads.py script.

  • Perform the conversion, the output is written to import_to_goodreads.csv file:

$ python anobii-to-goodreads.py

Import to Goodreads

  • Login to Goodreads. Go to its import page and import the import_to_goodreads.csv file.

  • Refresh this page to see the import progress. I found that a few books from India, which had ISBN, could not be imported.

  • Go to your own update stream, you should be able to see all the imports. Do not worry, Goodreads only shows a few of these updates on your friends’ stream. I also found that the book status (unfinished or reading) was not entered correctly. This I had to batch edit to fix them.

Tried with: Python 2.7.6 and Ubuntu 14.04

MKVMerge Error: Demultiplexer failed to initialize

Problem

I tried to merge a subtitle SRT file with a video MP4 file using MKVMerge as explained here. It failed with this error:

$ mkvmerge -o out.mp4 foo.mp4 foo.srt 
mkvmerge v5.6.0 ('Kenya Kane') built on Jun  7 2012 15:57:56
'foo.mp4': Using the demultiplexer for the format 'QuickTime/MP4'.
Error: The demultiplexer for the file 'foo.mp4' failed to initialize:
The file could not be opened for reading, or there was not enough data to parse its headers.

Solution

Googling for this error message did not provide any solution.

I updated MKVMerge to the newer version 6.7.0. The same command on the same files worked successfully! :-)

Max, min and lowest in C++

The limits header provides the template methods that can be called to obtain the maximum and minimum values of any numeric type in C++. For example, max() returns the maximum value. For int, this is equivalent to obtaining the value of INT_MAX in C.

Similarly, min() returns the minimum value. Note that for float and double, this returns the smallest positive value for that type. FLT_MIN and DBL_MIN return the same in C. This is necessary in many programs where you might want to know the smallest granularity of the float or double type.

However, in most applications using float or double, you actually want to know the lowest value, such that there is no other value in this type that is lesser. This is typically needed to assign a starting value when looking for the biggest value in some sequence.

Thankfully, C++11 now has lowest() that can be used for this. This is equivalent to -FLT_MAX and -DBL_MAX.

Tried with: GCC 4.9.2 and Ubuntu 14.04

Multihead display using Xdmx

The Xdmx server allows your X server to extend its display to include other displays that are held by other X server across a network. Hence, the name Distributed Multihead X.

As a simple example, consider two computers with one display each, up and running their own versions of Ubuntu. Let us call one the master and the other slave. If they are connected to each other by a network, can ping each other, then the master can extend its display by grabbing the display of slave. Once this is done, the master computer X server believes it has two displays. So, while working on the master computer you can now throw windows into the second display as if it were connected to the master computer itself.

This is theory that Xdmx is supposed to make practical, however it did not work for my setup! :-(

The steps I followed:

  • Installed Xdmx server on both master and slave computers:
$ sudo apt install xdmx
  • Installed OpenSSH server on master computer:
$ sudo apt install openssh-server
  • On the slave, SSH into master computer with X11 forwarding:
$ ssh -X joe@master
  • Note down the DISPLAY string allocated to this SSH X session:
$ export | grep DISPLAY
declare -x DISPLAY="localhost:10.0"
  • Run the Xdmx server to fuse the two displays together for master:
$ startx -- /usr/bin/Xdmx :1 +xinerama -display :0.0 -display localhost:10.0 -norender -noglxproxy

The two displays blanked out for a while and then I got this error at the end:

xinit: XFree86_VT property unexpectedly has 0 items instead of 1
xinit: connection to X server lost

waiting for X server to shut down

Suggestions from this page indicate that the best chance of this multihead display working is if both computers are running an extremely minimal X session. Since I am running the complex Unity desktop on both, this may not work.

Tried with: Xdmx 1.15.1 and Ubuntu 14.04

Enhanced syntax highlighting for C++ using Vim Syntax Extra

Vim ships with the syntax highlighting rules for C and C++. This is a curse in disguise, because those rules are extremely old and they only highlight the keywords. This means that any C or C++ source file looks pretty much like plain text, no matter which color scheme you apply.

Vim Syntax Extra is a plugin that fixes this by adding more syntax rules for C and C++. There is a visible difference only in the syntax highlighting once this plugin is installed. Add its Github URL using any of your favorite Vim plugin manager and restart Vim to enjoy it :-)

Tried with: Vim 7.4 and Ubuntu 14.04

IPython Notebook error: Unsupported JSON nbformat

20150701_ipython_error

Problem

I ran the IPython Notebook server in a directory containing a .ipynb notebook file:

$ ipython notebook

It opened the URL http://127.0.0.1:8888 in my browser. The notebook file was listed in the webpage. I clicked it to load it and got this error:

Error loading notebook

Unreadable Notebook: Unsupported JSON
nbformat version 4 (supported version: 3)

Solution

This error is caused due to opening a notebook created with a newer IPython on a computer with an older IPython. On my computer, I was using IPython installed from Ubuntu repositories, which is ancient.

I first uninstalled it:

$ sudo apt remove ipython

I installed the latest IPython from the Python Package Index:

$ sudo pip install ipython

The installation was successful, but on running IPython it complained about many other programs. I installed the libraries it complained about:

$ sudo apt install python-zmq python-jinja2 python-jsonschema

IPython Notebook ran correctly and I was able to open the notebook after this! :-)

Tried with: IPython 3.2 and Ubuntu 14.04