This simple code is part of another code I wrote for my own research purposes. It is a good solution for using it in other projects. The code is distributed under the MIT license, but if you decide to use it in your project, then do not forget to write a modest thanks in the code itself, it would be nice.
E-mail: leonidshabaev@gmail.com