How to generate random numbers in C++11

C++11 makes it easier to write simple random number generation code. This was quite a bit convoluted in C++03 as explained in this older post. With some new classes and syntactic sugar, C++11 is much easier.

Here is an example which generates 10 random int8_t and float values:

About these ads

MOC error on insecure configuration file


I added a configuration file for the MOC music player in my home directory: ~/.moc/config. On running mocp, it threw this error:

FATAL_ERROR: Configuration file is not secure: /home/joe/.moc/config


MOC requires that this configuration file be only writable by root or current user and nobody else. However, this file had write permissions for the users belonging to its group. MOC started without error once I removed the write permission for group:

$ chmod g-w ~/.moc/config

Tried with: MOC 2.5.0 and Ubuntu 14.04

Y PPA Manager

Y PPA Manager is a simple GUI tool to manage your PPAs and the packages installed from them. You can list PPAs, delete or purge PPAs, install or remove packages from PPAs.

To install Y PPA Manager:

$ sudo add-apt-repository ppa:webupd8team/y-ppa-manager
$ sudo apt-get update
$ sudo apt-get install y-ppa-manager

Tried with: Y PPA Manager 2014.08.18 and Ubuntu 14.04

How to split line in Vim

To split a line at the cursor position you can use the usual sequence of i, Enter and Esc. This enters insert mode, adds a new line and then escapes from insert mode.

If your cursor is at a space in English text then you are in luck. You can insert a newline here by replacing the space with a newline character. To do that in Vim, press r and Enter. No need to escape insert mode!

Tried with: Vim 7.4


Pogo is probably the simplest music player you can find on Linux. It has two panes: on the left is the filesystem view where you can pick files to add and on the right is the playlist where the added files appear. That is it! The player is so simple that is no shuffle or repeat mode.

To install Pogo use its PPA:

$ sudo add-apt-repository ppa:pogo-dev/stable
$ sudo apt-get update
$ sudo apt install pogo

Tried with: Pogo 0.8.3 and Ubuntu 14.04

How to handle Bluetooth devices from shell

Bluetooth devices can be listed, connected and disconnected by clicking the Bluetooth icon in the top Panel in the Ubuntu Unity desktop. If you prefer to do these simple operations from the commandline, that can be done too.

To do this, we need the tools from the bluez-tools package:

$ sudo apt install bluez-tools

To list all the devices that have paired in the past:

$ bt-device --list

This lists each device with its name and UUID. The UUID of a device can be used to connect or disconnect from it.

To connect an audio device using its UUID, say 00:02:3C:2F:F1:D4:

$ bt-audio --connect 00:02:3C:2F:F1:D4

To disconnect the same audio device:

$ bt-audio --disconnect 00:02:3C:2F:F1:D4

Tried with: Bluez-tools 0.1.38 and Ubuntu 14.04


CMUS is a popular music player for the console. The reason I turned to it is because it uses the familiar Vi key bindings for most of its operations.

To install cmus:

$ sudo apt install cmus

The CMUS interface can be quite confusing to understand at first. It is highly recommended to read the short tutorial before using it:

$ man cmus-tutorial

For more information about its operation:

$ man cmus

Some common operations I use in CMUS:

  • 5: Browser view, used to add music files to library.
  • a: Add music files under cursor to library in Browser view.
  • 2: Library view, shows the music files added.
  • Enter: Play music file under cursor
  • c: Toggle pause-unpause
  • b: Play next song
  • C: Set songs in Library to play one after another
  • r: Set songs in Library to repeat
  • s: Set songs in Library to play in shuffle order
  • :clear: Clear files in Library
  • :q: Quit CMUS

One feature from MOC that I miss in CMUS is I would like it to keep playing in the background after I quit it. This is not possible in CMUS. Instead, what I do is that I launch CMUS in real terminal Ctrl + Alt + F1 and switch back to Ctrl + Alt + F7 for my work.

Tried with: CMUS 2.5.0 and Ubuntu 14.04