Artisan Développeur

Qualité, amélioration continue, agilité.

Install open Jarvis on OSMC (raspbian 9.6)

Just for fun, I want to test openjarvis.

I have a Raspberry Pi with OSMC running my media center, and I use it often to try things, so this time is the turn of openjarvis.

But OSMC does not have all the needed package, and the how to install is old for openjarvis some of the package have changed.

I have not saved all my step, I think there are all here, but if you follow this and you have some issue, tell me in the comment.

Installation https://www.openjarvis.com/content/installation

sudo apt-get install -y git # install git if you don't have it already - needed with OSMC
git clone https://github.com/alexylem/jarvis.git
cd jarvis/
./jarvis.sh

To use snowboy without needed to build it for your system, you can do this dirty hack, it’s just for testing and fun, at your own risk 🙂

In the stt_engines/snowboy/main.sh file, you delete ligne 14 and 17 (you delete the IF condition on the debian_version)

Before:

elif [ "$jv_os_name" == "osmc" ]; then #628
            if [[ "$(cat /etc/debian_version)" -ge 8 ]]; then
                sb_supported_os=true
                binaries="rpi-arm-raspbian-8.0-1.1.0"
            fi

After:

elif [ "$jv_os_name" == "osmc" ]; then #628
            
                sb_supported_os=true
                binaries="rpi-arm-raspbian-8.0-1.1.0"

Before launching ./jarvis.sh you need to install alsa-utils, and libttspico-utils

sudo apt-get install alsa-utils libttspico-utils

If I have forget nothing, you can launch ./jarvis.sh and the installation will succeed 🙂

Mochajs locally in your symfony project

How to install node and mocha locally to unit test you javascript code

I will install packages in the require-dev section of my composer.json file, because in this case, I only use nodejs and mocha in the dev, preprod and test environments and they use the requierdev.
I don’t want to install that on my production environment.

To do that, I use two composer packages:

mouf/nodejs-installer

Packagist: https://packagist.org/packages/mouf/nodejs-installer
Github: https://github.com/thecodingmachine/nodejs-installer

koala-framework/composer-extra-assets

Packagist: https://packagist.org/packages/koala-framework/composer-extra-assets
Github: https://github.com/koala-framework/composer-extra-assets

Here the installation

You have to add this to composer.json file:

"require": {
    "mouf/nodejs-installer": "^1.0",
    "koala-framework/composer-extra-assets": "~1.1"
},
"extra": {
    "require-dev-npm": {
        "mocha": "*"
    }
}

To use mocha locally you have to add one file to the bin directory of your symfony project

In the script section, both in « post_install_cmd » and « post_update_cmd »

"touch bin/mocha && chmod +x bin/mocha && echo '#!/bin/bash \n DIR=$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd ) \n export PATH=$DIR/../vendor/nodejs/nodejs//bin:$PATH \n ../node_modules/.bin/mocha \"$@\"' > bin/mocha"

Example:

],
    "scripts": {
        "post-root-package-install": [
            "SymfonyStandard\\Composer::hookRootPackageInstall"
        ],
        "post-install-cmd": [
            [...] //do not copy/paste, it's just an example !
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
            "touch bin/mocha && chmod +x bin/mocha && echo '#!/bin/bash \n DIR=$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd ) \n export PATH=$DIR/../vendor/nodejs/nodejs//bin:$PATH \n ../node_modules/.bin/mocha \"$@\"' > bin/mocha"
        ],
        "post-update-cmd": [
            [...]  //do not copy/paste, it's just an example !
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
            "touch bin/mocha && chmod +x bin/mocha && echo '#!/bin/bash \n DIR=$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd ) \n export PATH=$DIR/../vendor/nodejs/nodejs//bin:$PATH \n ../node_modules/.bin/mocha \"$@\"' > bin/mocha"
        ]
    },

This line will create the mocha file and set the execution permission.

To actually install these:

composer install

Create a js directory src/Tests

With you IDE, or

mkdir src/Tests/Js

Finally use it just like that

Run all tests files:

bin/mocha src/Tests/Js/*

Or specific one:

bin/mocha src/Tests/Js/file.js

That’s it ! You can now unit test easily your javascript code !

As always, if you have question,  better practice, suggestion comment !

symfony, composer, clear:cache issue with vagrant and virtualbox

Quick tip today,

I have just finished to setup a new development environment with vagrant for my Symfony project, I have struggled with the clear:cache command, every time this command is failing.

Virtualbox seems to be the one to blame, below some relevant links:

The solution I have chosen is to change the directories of logs and cache:

[pastacode lang= »php » manual= »%20%20%20%20public%20function%20getCacheDir()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20if%20(in_array(%24this-%3Eenvironment%2C%20%5B’dev’%2C%20’test’%5D))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20’%2Ftmp%2Fcache%2F’%20.%20%20%24this-%3Eenvironment%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20return%20parent%3A%3AgetCacheDir()%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20function%20getLogDir()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20if%20(in_array(%24this-%3Eenvironment%2C%20%5B’dev’%2C%20’test’%5D))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20’%2Fvar%2Flog%2Fsymfony%2Flogs’%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20return%20parent%3A%3AgetLogDir()%3B%0A%20%20%20%20%7D » message= » » highlight= » » provider= »manual »/]

And all is fine with Symfony and vagrant after that, composer run, do is clear:cache, and nothing is broken anymore !