Skip to main content

Introducing kalliope personal assistant


This is just an introduction blog post for a series of post about the kalliope, a personal automation tool controlled by voice. The goal of Kalliope is as put on the doc page:

"Kalliope is a modular always-on voice controlled personal assistant designed for home_automation. Kalliope is based on audio input recognition, so it recognize an order pronounced by the user and then execute actions attached to the order."


Kalliope is an always on personal assistant, so you can use his service whenever it suits you. You just have to active a trigger that will wake up kalliope (eg: "kalliope" or "jarviss", or whatever you'd like). Once triggered, kalliope listen to your vocal order (eg: "what time is it?").

Then kalliope will use voice recognition engine (eg: google voice recognition) to translate your vocal order into a text order. This text will then be compared to the available brains.

Brains will then triggers neuron that will actually do something (eg: get the time, weather, a definition on wikipedia, call APIs, …) … As we say sky is the limit :)

I encourage you to read the documentation that explains all this in much more details.

If you understand french, I encourage you to watch this very cool demo video.

Get it now!

I let you read the good documentation on how to install here

You can reach out to the team also via a page

And now ?

In future blog post, I'll present what I'm doing with Kalliope and also introduce some neurons that I created to match my needs :).

All kalliope blog posts will be available on this page

Stay tuned !

Xrandr command when (un)plugging a screen

When I plug or un plug a screen on my laptop, I want my system to Automatically detect this change and switch from a single to dual screen setup (or the opposite when unplugging the screen). Here is how I do it:

Xrandr to switch screen layout

First, you need a script that automate the layout change based on the number of screens plugged in. Here is the script I use:

.. code:: bash

# Adapt it to your hdmi or output card
HDMI=`cat /sys/class/drm/card0-HDMI-A-1/status | grep -Ec "^connected"`
if [ "$HDMI" -eq 1   ]; then
  /bin/sleep 2s;
  # Adapt with the output name and your user name
  su -c "DISPLAY=:0.0 /usr/bin/xrandr --output HDMI1 --mode 1920x1080 --pos 1920x0 --rotate normal --output DP1 --off --output eDP1 --mode 1920x1080 --pos 0x0 --rotate normal --output VIRTUAL1 --off" "bacardi55"
  /bin/sleep 2s;
  # Adapt with the output name and your user name
  su -c "DISPLAY=:0.0 /usr/bin/xrandr --output HDMI1 --off --output VIRTUAL1 --off --output eDP1 --mode 1920x1080 --pos 0x0 --rotate normal" "bacardi55"

As you can see, commands are fired with my user and display specified in the command. This is because this script will be fired by the system and not within an X session so DISPLAY needs to be precised.

Launch the script when screen is (un)plugged

To achieve this, you'll need to create an udev rule. Create the file /etc/udev/rules.d/99-monitor-hotplug.rules and insert the following:

.. code:: bash

ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/path/to/xrandr/"

And here you go, script should be fired when monitor setup changes :)

Blog reopening !

Hello again!

I'm re-opening this blog as I have a few things to write on the internet as memo for me and other :)

I'm not going to make a long post for this first post but I wanted to open this blog again to:

  • Play with Drupal 8 and the lightning distribution
  • Put here some notes I found useful to run my workstation on linux
  • Talk about cool softwares (like Kalliope I started playing with a couple of weeks ago)
  • ...

I'm adapting the release early, release often attitude, so I'll update this blog in content and features/design quickly :)

Well, at least I'll try one more time to keep a blog alive (:

PS: some old blog post have been migrated as well as a souvenir of older blog versions...

Adding a default «vhost» to nginx

Today I wanted to install this blog on my new nginx server. As this site is simply static html file, I thought why not using it as well to try to learn how to use it.

So I created my server :

.. code:: nginx

{% raw %}
server {
  listen *:80;
  root /var/www/b-55-log/web;

  access_log  /var/log/nginx/blog_access.log;
  error_log   /var/log/nginx/blog_error.log;
{% endraw %}

Then, I wanted to add two other domain to redirect to this one:

.. code:: nginx

{% raw %}
server {
  listen *:80;
  server_name domaine2.tld domaine3.tld;
  access_log /var/log/nginx/other_domaine.access.log;

  rewrite        ^ permanent;
{% endraw %}

But It didn't work as I didn't have a default server. The redirection wasn't working as nginx considered my blog server the default. So the to 2 other vhost kept working and wasn't redirected. I didn't like that because I don't want this blog to be indexed 3 times by search engines.

So to correct this, I had to create a default server that redirect everything that didn't match any of my other server_name. This is what I put in my conf file:

.. code:: nginx

{% raw %}
server {
  listen *:80 default;
  server_name _;
  access_log /var/log/nginx/default.access.log;

  server_name_in_redirect off;

  root  /var/www/;
{% endraw %}

Be careful though, I followed the documentation and put

listen 80 default;

And there you go :)

But it didn't work. I actually had to put the IP:80 instead of just 80 as in the official doc.

I may have miss something in my nginx that make it doesn't work but if than can help someone other than me :).

PS: Thanks to my friend Rustx to advising me not to use the IP address but only *:80.

Sshfs cheatsheet

Mount a remote directory:

sshfs login@machine:/path/to/source/code /path/to/mountpoint


fusermount -u /path/to/mountpoint/

Force unmount (sudo or as root)

umount -l /path/to/mountpoint

Open html email and email attachment in mutt

Quick intro

I don't write a lot about it, but I use mutt to read my emails. You can easily guess why:

  • Less memory consuming than thunderbird or evolution;
  • Faster;
  • Managed by keyboard;
  • Used in a terminal :)

For those who know me, they know that I really don't like using my mouse. I find that each time I remove my hand from my keyboard to go on my mouse, I loose time. That's why I'm using vim (that and the fact that it's the best editor :p), or why I'm using a tiling Window Manager (i3) or why I'm using mainly application that run inside a terminal.

It's simply more consistent with the way I use my computer to work and code.

Using mutt might seems like a real nerdy thing to do in 2013 but if you configure it properly, it's as good as any (but less RAM consuming) :).

Html email

I have to admit, I also use mutt because in my opinion, email should only be text. I hate html email and I hate even more when people send html email without the text alternative.

But, we're in 2013 and I receive html email every day. When some of them don't have the text alternative, I can't always decide to throw it and ignore it (even if I often do). Sometime, even important email and not only spam can be in html only.

They are several options to handle this and I choose to use the ~/.mailcap file that contains a list of programs to use depending on the mime type of the file.

To read html email inside mutt, just add this in your ~/.mailcap:

.. code:: bash

text/html; links %s; nametemplate=%s.html
text/html; links -dump %s; nametemplate=%s.html; copiousoutput

You need to have links installed.

And now, you'll be able to click on the html attachment and see the content of the email easily :).

Open email attachment

Ok, so now that we have done this for the html email, I'm sure you understood how to be able to open other attachment files: You just need to add new lines in your mailcap file :).

Here is my mailcap file as an example:

.. code:: bash

text/html; links %s; nametemplate=%s.html
text/html; links -dump %s; nametemplate=%s.html; copiousoutput
text/*; less
image/*; gpicview %s
application/pdf; evince %s
application/msexcel; soffice %s
application/msword; soffice %s
application/; soffice %s
application/vnd.openxmlformats-officedocument.wordprocessingml.document; soffice %s

I'm using gpicview for all images, soffice for office document (libre office and MS office document), less for text and evince for pdf.

You can add more line here for other type of file (eg: video, sound, …).

All you have to do now is press « v » on a email that has attachment and then press enter on the attach file and it will be open by the right program.


If you don't know the mime type of a file, you can use ^e (ctrl+e) on a attached file in mutt to know the mime type. Then you just need to copy it and paste it in your mailcap file and choose which program will handle the files with this mime type :).

Hope this helped some of you :)

Saving a vim session before quitting

When you working on a project, you often have a lot of files open in your vim. I use split and tab a lot to open all I need to work on a feature.

I leave my vim open as much as possible to avoid the pain of reopening them all everyday. Obviously, this isn't enough as sometime you don't have other choice than closing it (restarting your computer for example).

I started using the mksession command:

!mksession (or without the ! if you don't want to override a previous session file).

This command let you save your vim session and then reopen it by launching vim like this:

vim -S /path/session/file

I was fed up of doing this -S stuff every time, so I changed for something a little bit more automatic. I mapped to SQ a command that create a vim session in the current directory so I just use SQ for quitting and I know that there will be a session file generated thanks to this command.

After that, I just added an «autoloading» configuration to load a session file in the current directory if any exist.

This is the stuff I added in my vimrc:

.. code:: bash

function! RestoreSession()
  if argc() == 0 "vim called without arguments
    let FILESESSION=expand("./session.vim")
    if filereadable(FILESESSION)
      execute 'source ./session.vim'

nmap SQ <ESC>:mksession! ./session.vim<CR>:wqa<CR>
autocmd VimEnter * call RestoreSession()

Now, I just need to open vim from the root directory of the project and think about leaving using SQ to generate the session file. The next time, I just need to go to root directory of the project and open vim without argument and the session will be loaded.

/!\ If you open a file directly (by using vim ./path/to/file), the session won't be open.

It makes sens for me to do this in the project root directory as I already have my ctags file there, as explain in this blog post.

As long as I open vim from the root directory of each project, my ctags and my session will be loaded :)

Isn't that beautiful ? :)

Alternate css classes easily in twig

Today, I wanted to style a little bit my project. The basic way in classic PHP project would be to use the iterator variable of your for loop with the use of modulo.

For example:

.. code:: php

{% raw %}<div class="<?php echo ($i % 2 == 0) 'odd' : 'even' ; ?>"></div>{% endraw %}

In twig, when you use a loop, there are several variables that you can use like loop.index, loop.first, loop.last. I won't copy/paste the official documentation here, you can read it here twig loop documentation.

To use the modulo function in twig, just use

.. code:: twig

{% raw %} {{ 10 % 2 }} {% endraw %}

And there you go, as simple as in PHP.

Then, using twig, you can do this:

.. code:: twig

{% raw %} {% if loop.index % 2 == 0 %} {% endraw %}

Or in my case I needed this :

.. code:: twig

{% raw %} {% if loop.parent.loop.index % 2 == 0 %} {% endraw %}

To be able to use the index of my parent loop :)

On this blog, I found the following tips :

.. code:: twig

{% raw %} {% if loop.index divisibleby(2) %} {% endraw %}

Isn't it beautiful ? But it gets even better!

.. code:: twig

{% raw %} {{ cycle(['odd', 'even'], loop.index) }} {% endraw %}

And there you go, thank you twig !

Switching quickly from 1 screen to 2

As I open to switch often between 1 and 2 screen (I use a laptop), I made a very little bash script based on xrandr to help me switch faster.

.. code:: bash


NB=`xrandr|grep " connected"|wc -l`

if [ "$NB" -eq 2 ]; then
  xrandr --output VGA-0 --auto --left-of LVDS
  if [ "$1" = "off" ]; then
    xrandr --output LVDS --off
  xrandr --auto

I named my script dualscreen.

Now, I you just have to run dualscreen in a term (or in a launcher like dmenu or your kde/gnome launcher). Then the script will the detect if 1 or 2 screen are plugged and do what it need to do.

If you want to plug a second screen and switch off the screen of the laptop, you can run dualscreen off and there you go !

Of course you need to adapt the output name depending on your hardware. Just run randr in a terminal.

For example, here is what I have running xrandr:

.. code:: bash

Screen 0: minimum 320 x 200, current 1366 x 768, maximum 16384 x 16384
LVDS connected 1366x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
1366x768       60.2*+
1280x720       59.9
1152x768       59.8
1024x768       59.9
800x600        59.9
848x480        59.7
720x480        59.7
640x480        59.4
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 disconnected (normal left inverted right x axis y axis)
VGA-0 disconnected (normal left inverted right x axis y axis)

This means that I have 4 outputs. The LVDS is my laptop output. Then, plug your screen and run the xrandr command again. You'll see another output connected. This is the one you should use in the script.


If you are lucky enough that your computer send an acpi signal or something to detect that a screen is plugged, you can do it automatically.

Unfortunatly it's not the case with my current laptop so I don't know more ^^. Maybe someone can send me an email with the procedure :).