Web development

How to add parameters or variables to a BackboneJS view

It’s very easy to add parameters or variables to any BackboneJS view but being aware of what BackboneJS version are you using because it changed. Let’s see:

Before 1.1.0 version

Any parameter in the constructors went to the options variable of the view::


var userView = new UserView({
  mode: "add"


render: function() {
    // Use example in any function
    var mode = this.options.mode; // mode="add"

Now (version >= 1.1.0)

Just like above but adding this to the Controller:

initialize : function (options) {
  this.options = options || {};

You can check the BackboneJS changelog

Dev Ops

How to install or upgrade NodeJS to any version


When you work in a few NodeJS projects, you may need an easy and fast way to install, switch or upgrade the NodeJS version. With NVM is possible.


curl https://raw.github.com/creationix/nvm/master/install.sh | sh


Install a NodeJS version

nvm install 0.10.26

Switch or upgrade

nvm use 0.10.26

Use by default

nvm alias default 0.10.26

List the versions installed

nvm ls

By the way, if you get nvm: command not found check this solution

More info about NVM


Lost connection to Mysql server at ‘reading initial communication packet’, system error:0


Lost connection to Mysql server at ‘reading initial communication packet’, system error:0

This error appears when you try to connect to a MySQL or MariaDB database and it is unavailable. The fix depends on your situation:

If you have MySQL/MariaDB installed on the server where you are trying to connect

  • Edit the configuration file located on /etc/mysql/my.cnf
  • Set:
    bind_adress =
  • Restart:
    service mysql restart

If the server is just a proxy, like a HAProxy server:

  • Remember to grant access permissions on all database servers, check my guide about it on how to deploy a MariaDb Cluster:
    INSERT INTO USER (Host,USER) VALUES ('','haproxy');

    Repeat it for each db server, changing IP and proxy user.


Host ‘host_name’ is blocked because of many connection errors. Unblock with ‘mysqladmin flush-hosts


Host ‘host_name’ is blocked because of many connection errors. Unblock with ‘mysqladmin flush-hosts

I got this error message when I was setting up a MariaDb Cluster and I don’t finish it properly. But don’t worry, for fix this error just run the next command on your database server:

mysqladmin flush-hosts -u root -p

Source http://cmanios.wordpress.com/2013/04/19/mysql-connect-error-1129/


How to setup the load balancer HAProxy in front of MariaDb Cluster



In my previous post I showed you How to deploy a MariaDb Cluster and now let’s see how to setup HAProxy in front of the cluster. But before, we should prepare the nodes.

Preparing the cluster

On each node, login to the database:

mysql -u root -p

Enter your password and press enter.

Now create the HAProxy user. The load balancer will use this user in order to check the availability of the nodes.

  • NODE 1 – Example IP
INSERT INTO USER (Host,USER) VALUES ('','haproxy');
  • NODE 2 – Example IP
INSERT INTO USER (Host,USER) VALUES ('','haproxy');
  • NODE 3 – Example IP
INSERT INTO USER (Host,USER) VALUES ('','haproxy');

 Setting up HAProxy

Installing HAProxy

Now install the packages on the load balancer server

sudo apt-get install mysql-client haproxy

Configuring HAProxy

Create and edit the configuration file:

sudo nano /etc/haproxy/haproxy.cfg

Paste a full example:

    log local0
    log local1 notice
    maxconn 1024
    user haproxy
    group haproxy
    log global
    mode http
    option tcplog
    option dontlognull
    retries 3
    option redispatch
    timeout connect 5000
    timeout client 10000
    timeout server 10000
listen workerhaproxy
    mode tcp
    balance source
    option tcpka
    option mysql-check user haproxy
    server db1 check weight 1
    server db2 check weight 1
    server db3 check weight 1

Some notes on this example:

  • Remember to change your databases IP.
  • HAProxy will listeting on 6000 port.
  • Uses source balance option, what means each user will try to connect to the same database server. There are more options, like round-robin.
  • Please check the documentation in order to understand the configuration.

Enable and start HAProxy

Edit the file /etc/default/haproxy

sudo nano /etc/default/haproxy

Change ENABLED to 1, save and exit.

Now start HAProxy

service haproxy start


Now in your app or database client, test it connecting to the HAPRoxy server, on port 6000.

You can use root user or whatever user you had created on database.