Multiple chef environments

Well, this is a little bit strange, but in opscode website, it’s not really clear how to configure your chef client to access multiple servers.

Not only that this is possible and more then just nice to have, in many cases, it’s essential:

  1. You might manage multiple servers
  2. You don’t want to create a knife file in a privileged directory
  3. You want to test a client configuration

To make it happen:

In any folder that you wish to create chef access, just create a .chef sub folder. ingredients for this folder are:

  1. knife.rb file.
  2. public and private key files (you get these from the chef server).

note that you need to set your permissions in the server, and most likely to have an admin access if you want the new user to be able to create/delete nodes.


Static constructor in NodeJS objects

It's not hard to create an object in JavaScript and therefore in NodeJS. However, if you're an advanced user, you probably devil a little with static objects (Factories will be the definite example). Since JavaScript doesn't really comes with static constructors, we need to take advantage of NodeJS require feature.

About require

require is a nodejs specific. The cool thing about it, is that it is only called once. so, every code that executed there, is executed only once, what's making it a perfect place for static initialization.  Lets take a look at some code:

function Counter()

What we have here is a simple increase of the number of objects created. However, since Counter.__counters is not defined, we will get an error. sure, we can check that this variable exists in the object constructor, and currently this is not a big issue, but if the test is a timely manner or a costly one, we have a problem. Using NodeJS feature, we can solve it easily:


function Counter() 

The first line will be called only once, and thus make it a static constructor. This line can be replace in a function call, if we wish to make it neater, and the effect will remain the same.

Installing chef gems

This might sounds strange, but your regular gem location is not the location that chef is using. This is important in case you are trying to install any knife plugins, where regular gem just won’t work.

The usual location is:/opt/chef/embedded/bin/gem , but you might have it some place else. Generally, look for gem|chef|more, and this should do the trick.

Add menu entry in ubuntu

Sometimes, you might want to download a program without installing it system wide. Or, you might not have an installer, but still, you would like to have a shortcut in the application menu.

To achieve that, here is what needed to be done:

  1. Create a desktop entry of the application you want to insert
  2. Copy this entry to ~/.local/share/applications.

The second part is pretty simple. but how to create a desktop entry file? Here:

Desktop entries are actually simple text file that follow some guidelines.

  1. The file postfix is "desktop" (same as txt for text file and so on)
  2. The file contains several key-value pairs, most important are Exec, Terminal and probably Icon.
  3. You don't have to create it from scratch. Here is a desktop entry for robomongo I've created. Note that you need to remove the txt postfix part for it to work. You should change the other parameters as well (Name for example or comment).

If you wish to copy a shortcut that  was installed through a debian package to your desktop, these are usually located in /usr/share/applications.




  1. robomongo.desktop

using mongoDB with C++

While it is very easy to connect to mongo via node.js, I wanted to write an article about using C++  to connect to this great DB. This is done under ubuntu.

Ingredients (using apt-get here will do)

  1. git
  2. scons
  3. build-utils
  4. openssl
  5. libboost1.54-all-dev (or 55, or whatever going to be the version when you read it)
Compile the driver

Don't install from repo; Drivers should be compiled and it's actually pretty easy.

  1. create the directory in which you want the driver to reside.
  2. clone this repository: git clone
  3. get into the folder created by git
  4. run scons --prefix=$HOME/mongo-client-install --ssl install  to build the target. (if you are getting scons error, you are not in the folder, or you didn't install the entire list above). Let me clear this command as you run it: it will build and install from wherever you are now, to a new location, which is your home/mongo-client-install. You might wanna change that later on, but for now, this is fine.
  5. You can now use your favorite IDE to create a project to use with mongo. in your IDE, make sure you don't have any residues of old installations. If you do, remove them.
  6. make sure you are using paths to the include folder, path to the library and the library you created.
  7. more libraries you will need (you might need to adjust the names/path, under ubuntu64 this should be fine):

    1. /usr/lib/x86_64-linux-gnu/
    2. /usr/lib/x86_64-linux-gnu/
    3. /usr/lib/x86_64-linux-gnu/
  8. That's all! You are now ready to write your first program.

Test program can be found here:



On ubuntu 1604, you'll have gcc 5.x. the scons command should be :scons –ssl –prefix=/programs/mongocpp –c++11=on CCFLAGS="-Wno-unused-variable -Wno-maybe-uninitialized"

where prefix is where you want to driver files to be.