Tuesday, April 15, 2014

#javascript #nodejs grunt-http-server v0.0.5 released

Before I go on an one week holidays I've updated the 'grunt-http-server' NPM package to version 0.0.5. This new version allow dynamic configuration of the server port specified by a function.


    'http-server': {

        'dev': {

            // the server root directory
            root: ,

            port: 8282,
            // port: function() { return 8282; }

            host: "",

            cache: ,
            showDir : true,
            autoIndex: true,
            defaultExt: "html",

            // run in parallel with other tasks
            runInBackground: true|false



The idea and pull request came from bryanisimo which I thank.

If you got any ideas I'll be more than happy to merge them in the repository.

Holidays mode now turned on :) 3 hours from Cork to Dublin plus 2 hours flight.... Thank god I've got Linux Journal to read.


Monday, March 31, 2014

#nodejs opensubtitles-client / subtitler v1.1.4 #npm release #javascript

This weekend opensutitles-client and subtitler command line utility were updated to version 1.1.4. This release included the following features:

As usual, everyone is invited to use, suggest, fork and contribute to the repository.


npm i opensubtitles-client -g

Subtitler Example

// download subtitle for the movie
subtitler movie.avi

// download subtitle for the movie inside the directory
subtitler directory/

// download 10 subtitles
subtitler "Movie Name" --download -n 10



Sunday, March 16, 2014

#javascript Require.js vs CommonJS / AMD modules and #angularjs

I recently replied to the following twitter conversation about require.js vs browserify.

Angular.js and AMD

Recently I tried to integrate some AMD modules into an angularjs application. I did not spent much time on it, but I was under the impression that the integration was not straightforward.

On this twitter thread @tbranyen pointed to me that using the angular dependency injection annotations I can easily reuse my existing require.js modules. I must give it a try on my next project.

AMD vs CommonJS

First of all I must say that I can understand the arguments from the CommonJS supporters but the require.js configuration file gives me extra powers...

An awsome feature of requirejs is that you can create different execution context. This means that you can, for instance, load different versions of the same module into two different context executions. This can be very powerful.
I'm using this on my js-utils project to make it just a repository of modules without hard dependencies. This means that js-utils node_modules folder will have just a few references.

var requirejs = require('requirejs');

requirejs = requirejs.config({

    /// isolate this context
    context: 'context1',

    /// use local packages, located on node_modules
    nodeRequire: require,

    /// modules baseurl
    baseUrl: __dirname,

    /// the lookup paths
    paths: [ ... ]


I do not consider myself a fanboy of require.js because,
  • I now that its complexity demands a bigger learning curve that its not always required. 
  • I know that browserify is more easy and compatible with node modules.
  • I know that its syntax can be very verbose.
  • I know that r.js need a lot of improvements.
  • I know that r.js source maps are almost useless (the variables and functions are already minified).

But I also know that,
  • I can create complex dependencies on require.js config file
  • I can create friendly alias on require.js config file
  • I can easily change version of the dependencies just by changing the configuration file
  • I can use different execution contexts

If I said anything wrong please let me know because I really want to hear your thoughts on this matter!

Sunday, March 9, 2014

Creating your own #nodejs development server with a #raspberrypi running #jenkins

At home I almost only develop nodejs code and because of that I've been using grunt to run jshint, mocha, ... on my modules.

Because I'm always creating new project and experiments I've a dedicated raspberry pi model b for development purposes.  Until now that raspberry had support to:
  • SSH
  • GIT
  • ENCFS (backup to dropbox)
  • Nodejs 0.10.2
  • MongoDB ( compiled from https://github.com/skrabban/mongo-nonx86 )

This infrastructure is nice but I needed a CI server to test every push request. My previous experience installing Jenkins on a raspberry was not very positive but I decided to give it another try.

Some of the most important installation steps are described bellow:

I installed jenkins using:

sudo apt-get install jenkins jenkins-common

Then I updated the jenkins.war to the latest stable version.


To run jenkins you need to increase the system tmpfs values:

> sudo vim /etc/default/tmpfs

TMP_SIZE=1073741824 #1gb
RUN_SIZE=157286400 #150mb

Then configure Jenkins to use oracle arm java version:

> sudo vim /etc/default/jenkins


I've also enabled swap and configured a jenkins user on the machine.


Jenkins initialisation may take a couple of minutes on the first time is executed.


With this configuration I got a build machine to keep tracking my changes to the code. Jenkins is not very fast but it's usable.

Some figures of the machine resources with jenkins running follows:

> free -mh

             total       used       free     shared    buffers     cached
Mem:          485M       372M       112M         0B        20M       190M
-/+ buffers/cache:       161M       323M
Swap:         1.0G         0B       1.0G

> df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           150M   69M   82M  46% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           302M     0  302M   0% /run/shm

I hope this has given you some idea on how to build a low voltage server for your home development.


Monday, February 24, 2014

#Jenkins email-ext command stdout in email

If you're using email-ext plugin for Jenkins and you want to execute a command while your email notification is being processed, you can include into your groovy template something like:

 def cmd = "cmd /c cd " + build.getWorkspace() + " && svn diff -r HEAD"
 print cmd.execute().text

In this example I'm including the latest svn diff in the email. Don't forget that jenkins truncates the email content if its size is bigger than a certain value...

This type of things can be very handful to make your notifications more informative.

Monday, January 27, 2014

#linux #raspberrypi router with dynamic dns

One more article about controlling your home network with the raspberry pi router. This article is the sequel of "Creating a wireless router...".

In this "episode" I will walkthrough the configuration of the dynamic dns for an easier access to your home network when you are not there!

For this you need to create an account in http://freedns.afraid.org/ and then create an A record on the Dynamic DNS section of the site. After this, click on "Wget Script". On the downloaded file you will see something like this:

wget -q --read-timeout=0.0 --waitretry=5 --tries=400 --background http://freedns.afraid.org/dynamic/update.php?UPDATE_TOKEN

The dns update token is represented above as UPDATE_TOKEN.

Next step is:

sudo apt-get install inadyn

Edit the file "/etc/inadyn.conf" with the following content, replacing USER, PASSWORD, HOSTNAME, UPDATE_TOKEN.

--username USER
--password PASSWORD
--update_period 60000
--forced_update_period 320000
--dyndns_system default@freedns.afraid.org

Then add the update instruction to root crontab:

sudo crontab -e

*/10 * * * * /usr/sbin/inadyn

The last step is to configure your root to Forward the network traffic into your rooter ip. You can check "/var/log/syslog" for errors on the update.

Next step for me is configure the openvpn to allow full network access to the others raspberries.

If you like this Share it and will be like a bookmark for your future remembering.

Saturday, January 25, 2014

opensubtitles-client / subtitler v1.1.0 #npm release #javascript

Today the npm opensutitles-client package was updated. This release included the following features:

  • Removal of JAVA dependency to calculate the movie hash.
  • Language aliases were added. Thanks to @era for his contributions.


npm i opensubtitles-client -g

Subtitler Example

// download subtitle for the movie
subtitler movie.avi

// download subtitle for the movie inside the directory
subtitler directory/

// download 10 subtitles
subtitler "Movie Name" --download -n 10

Oscar Brito @aetheon

Sunday, January 19, 2014

Creating a wireless router / access point with #raspberrypi and #raspbian #linux

What about creating my own low powered development network infrastructure at home? Sounds like a good idea right? You can hack the router settings, creating vlans, control your network traffic, ...

Other reason is to create an abstraction layer between your ISP router and your physical network that can be moved when you move to your shinny new flat!

Let's get to business then. The router hardware is composed by a raspberry PI model A and a USB WiFi (802.11b/g/n) Module with Antenna for Raspberry. The raspberry was configured to boot from a 4gb USB pen drive with a swap partition and the /tmp size was increased ( instructions ).

My router is using network and my internal network

First of all install the software:

sudo apt-get install hostapd bind9 isc-dhcp-server ntpdate

This will install AP, DNS, DHCP and NTP support.

Now you need to configure the following files (click on each title to see the configuration!):


Configure the network interfaces.


Configure the firewall, NAT, and forwarding rules.


The dhcp server configuration allows the dynamic dns update, meaning that the hostname of the dhcp client is added to the dns.

You can also configure DHCP to only listen to the wireless device,

> sudo vim /etc/default/isc-dhcp-server

To enable logging, you also need to:

> sudo vim /etc/rsyslog.conf

# add the line

local7.* /var/log/dhcpd.log


Be sure you also run:

# Enable dynamic dns

> sudo chown bind /etc/bind/


Enables the wireless access point.

Sync Boot

Lastly you need to disable the services from boot. This is because the raspberry don't have a battery and then it doesn't save the system date which causes DNS and DHCP to fail.

We need to sync the initialisation of the raspberry to first get the date from NTP servers and then initialise the router services.

sudo update-rc.d hostapd remove
sudo update-rc.d bind remove
sudo update-rc.d isc-dhcp-server remove
sudo update-rc.d ntp remove

Now we create the boot script to initialise all:


sudo update-rc.d init-router defaults
sudo update-rc.d init-router enable


I'm very happy with the raspberry performance. I did not notice any significant decrease on network speed. My next step is to configure vlan support and dynamic dns support to be able to access when I'm away from home.

Also I'll fiddle a little around the iptables rules to have full network control.

If you have any troubles or suggesting you can always contact me.

Monday, December 16, 2013

Cordova 3 The Basics Presentation #cordova #phonegap #javascript #nodejs

Last week I prepared a presentation about the new Cordova 3 and how to work with it. This is just a quick and dirty summary on how to use cordova utilities and it's project structure.

The presentation is hosted on a github repository that you can fork. Who is your friend?

The presentation in fullscreen is available on:


Thursday, December 12, 2013

Using Swig Templates with Hapi.js #nodejs #javascript @hapijs

While migrating a node.js application from Express to Hapi.js I found the need to use Swig as template engine instead of handlebars.

I prefer Swig because it have hierarchy blocks (aka extends) that work way better than the handlebars partials.

Simply, to make it work you just have to:

          views: {
               path: "./views/",
               engines: {
                  html: "swig"


Be sure that you have included the the Swig dependency on package.json.

At last, be sure you check Hapi.js if you are thinking on a Server Framework for node.js ...