Providing Message Pack Support to an ExpressJS Node App

Recently, the extended body-parser that added support for message pack by extending the standard body-parser was released in Mobiltron’s github page.

The module aims to replace the basic body-parser module, in order to decrease complexities for the app programmers. You just need to add the require to body-parser-with-msgpack. An example project is published in Github that exhibits the module’s usage.

var express = require('express');
var bodyParser = require('body-parser-with-msgpack');
var app = express();

// Enable mime-types: application/json, form-data and message pack!
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.msgpack());

app.post('/data', function (req, res) {
  res.status(200).json({
  	message: 'success',
  	data: req.body
  });
});

app.listen(8080, function () {
  // Server started! [...]
});

The above example creates a POST route /data that accepts application/json, application/x-www-form-urlencoded, and application/x-msgpack mime types. The result is always returned as a Javascript object in req.body.

You can try it for yourself by cloning the Github repository.

Enjoy!

Domain-Specific Languages: A Small Introduction

Domain-specific languages (DSLs), also known as micro- languages or little languages, are programming languages designed to focus on a particular domain. Well-known DSLs include regular expressions, markdown, extensible markup language (XML), and structured query language (SQL). General-purpose languages (GPLs) have a wider scope. They provide a set of processing capabilities applicable to different problem domains. Mainstream GPLs are Java, C/C++, Python, and Scala.

To better understand the differences between DSLs and GPLs, consider the following example. The C program- ming language is a GPL. It provides the basic forms for abstractions and computation. What happens if someone wants to define a matrix of integers in C? An array of pointers must be declared like the following:

int **matrix;

To access the values of the matrix, the programmer will have to write complex pointer arithmetic statements. If one attempts to implement an algorithm for the multiplication of matrices, a function must be defined that accepts the two matrices as parameters and returns the result.

int **multiply(int **m_first, int **m_sec);

More advanced languages such as C++ and Java pro- vide more advanced methods to create abstractions; thus there are classes and interfaces. A typical implementation of the matrix multiplication algorithm would have created a class named Matrix with a method called multiply. For example, in Java, the code would look like the following:

public class Matrix {
   public void mupltiply(Matrix m) { ... }
}

This approach has many benefits if compared to the C version. The domain abstraction, which is the matrix, is declared directly as a type. In addition, it also contains the method multiply, which is closer to the reality of the mathematical domain.

With modern programming languages, it is easy to create complex libraries that declare and implement the abstractions of specific domains, but there is a barrier; the syntax of the language must be always used.

Consider now octave or mathematica, a language created specifically to deal with this algorithm implementation. These DSLs are used massively for simulations and mathematical modelling. Does anyone consider mathematica’s language to develop a web server or a database management system? Those languages focus on the mathematical domain only. Outside it, they have no meaning. The languages of mathematica and octave are DSLs.

The rest of this entry is structured as follows; first, a brief glimpse on DSL advantages and disadvantages is presented, along with a basic terminology. Three popular DSLs are also presented, with small practical examples of their use. The next section emphasizes on DSL design and implementation patterns. Finally, the entry concludes with the analysis of various works on programming language embeddings and the basic elements on how all these meth- ods can be combined to enhance the overall DSL design and implementation process.

Rest of the entry can be found in the latest volume (2016) of Encyclopedia of Computer Science and Technology (Taylor & Francis)

Chatbots: The Revenge of Command-Line

Recently I began hearing terms like “conversational marketing”, “chatbots” etv. and I was thinking that should be a joke or something. It was during my university years (around 1995) that windows 95 were released and the GUI paradigm won the competition against the command-line, which was more popular on unix-based system at the time.

I even remember students among several others, expressing their disappointment for the command-line of unix, and how in windows one can administer the services and the apps more efficiently. I was thinking back then that it was lack of experience, you know, it is like Leon said: “first you begin with the sniper rifle, as far as you can be from your victim, then you end up with the knife”. So, it was typical for inexperienced users to begin with the UI that had all the options exposed and the most experienced to end up with command-line that provided rapid configuration and automation.

Time has passed since then, and GUI won the war obviously. My kin (aka people that liked command-line) ended up with OS X, that has excellent apps and stability, backed by a unix-based system.

But as it seems, revenge is a dish served cold. Chatbots, which are the latest trend are backed up by artificial intelligence and provide automation through a chat interface, like slack. But the chat interface is like command-line right. So you have to memorize commands in order to receive specific functionality or information. So, all these people that hated the command-line, now through chat, they love it. And they will be very happy to use it! Cool huh.

Either way, things are very interesting these days and the progress has been real significant in applications and hardware. Now that I think about it, maybe the bash should be a chatbot right? Put a little AI in the traditional shell (and NLP). Who knows?

.bashrc generator

Today I was just browsing on the web (slow Sunday thing). Just discovered this .bashrc autogenerator :), which is super cool for those who do not have spare time to dig through man pages.

I have also using some custom scripting to automatically get current git branch, among other things …