Basic NodeJS installation for Ubuntu

NodeJS installation for Ubuntu 14.04

Some packages needed for binary builds:

sudo apt-get update
sudo apt-get install build-essential libssl-dev

First install NVM (Node Version Manager) for your OS. Mine is Ubuntu so:

curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh

Now install node last version (today is v0.12.0):

nvm install -s v0.12.0
nvm alias default v0.12.0

This will take a while because you are compiling sources (-s option)

Installing Bower

Bower allows you to install and manage the dependencies of a lot of JS libraries found in its marketplace:

npm install -g bower

Why fixed-price does not work for Web Projects

Since I became a Freelancer Web Developer, I established that the Mission in my Strategic plan was “to provide high Quality customized web apps to my customers”. Just notice that the main word is QUALITY.

The best approach I know to explain the concept of Quality in a Web Project is the Broken Iron Triangle:

  • Scope: are features and functionality expected
  • Resources: Cost
  • Schedule: time to implement these features

ironTriangle

 

Here explains how a project is broken when you fix this three features. And how Agile methodologies (with sprints and communication) maintain the triangle flexible in order to have successful experiences.

“In many ways, we really need to question the ethics of “fixed-price” IT projects.” Scott W. Ambler. All project risks are moved from the Customer to Developer. Driving to a bad experience for at least one side of this relationship.

In my opinion, you could fix costs if you can fix Scope (features) from the beginning. But this never happens because:

  • Features are often subjective or poorly defined. i.e.: While Developer is thinking in a button to remove a message, Owner is thinking on Drag&Drop feature compatible with mobiles.
  • New features appears in the process of development
  • Feature can be underestimate or overestimate. Depends on the quality of code under the hood, the developed libraries or if you have to make it from scratch.

Sometimes the Owner (customer) gives you a set of features, and ask for an ‘estimation’. Where you fix features, cost (fix price) and number of hours that this will take. You are frozen the triangle!! . Under this ‘estimation’ document starts a Developer/Customer relationship which will finish in a failing project.

Scope is never fixed from the beginning (never), this makes impossible fix cost/time without an impact in the QUALITY of the project.

I cannot deliver poor Quality projects, due to my business strategy. This is the reason why I do not work fixed-price, instead, I work on hourly basis (N hours worked, N hours paid).

When a Customer asks me for an “estimation” (cost, fixed-price), I send a plan: features and time to implement them. And I warn them that ‘this is not a budget, it is just a work plan for your project, and schedule could vary’.

Push Notifications for Mobile Apps

Sometimes we need to send push messages from our Web App to Mobile App subscribers.

Main Mobile OS providers offer their own services:

  1. Apple: APN (Apple Push Notifications): for Iphone
  2. Google: GCM (Google Cloud Messages): for Android and Iphone

If you have only an Iphone App you can use only APN. But if you will have both Iphone and Android Apps, it could be a good idea to talk with the iOS Developers about to use GCM, in order to simplify the final System (need to talk, maybe they have great arguments to use APN).

I found this great schema at androidhive.info:

gcm-a-modr

 

APN works similar. Our Rails server will need to:

  • (3) Create an API end-point which stores the registration_id
  • (a) Send push messages from our app

Our API can be ‘/v1/push_registration’ receiving a messages like:

{"apn_id" : "191434a07d17cad3446597e5ad7f1588"}
{"gcm_id" : "191434a07d17cad3446597e5ad7f1588"}

The second point can be resolved with a gem. Below we will analyze some solutions for that point.

Bot apn_on_rails and gcm_on_rails seems outdated, as the last commit happened in 2012, and there were many changes in Rails and in the APN/GCM services themselves.

gem gcm

This gem only supports the GCM service. But there is no problem with Iphone Apps because this service supports them.
Implementation:

  • Initialize object:
    require 'gcm'
    gcm = GCM.new("my_api_key")
  • Send a message:
    registration_ids= ["12", "13"] # an array of one or more client registration IDs
    options = {data: {message: "Hello World"}, collapse_key: "updated_score"}
    response = gcm.send(registration_ids, options)

gem push-core

This gem supports both services: GCM and APN.
Implementation:

  • We can initialize both services with their API keys:
    Push::ConfigurationApns.create(app: 'app_name', connections: 2, enabled: true,
        certificate: File.read('certificate.pem'),
        feedback_poll: 60,
        sandbox: false)
    Push::ConfigurationGcm.create(app: 'app_name', connections: 2, enabled: true,
        key: '')
  • Send a message:
    Push::MessageApns.create(
        app: 'app_name',
        device: '',
        alert: 'Hello World',
        sound: '1.aiff',
        badge: 1,
        expiry: 1.day.to_i,
        attributes_for_device: {key: 'MSG'})
    Push::MessageGcm.create(
        app: 'app_name',
        device: '',
        payload: { message: 'Hello World' },
        collapse_key: 'MSG')

gem rpush

This gem supports all push services we find in the market: APN, GCM, Windows and Amazon. And it is by far the most active, so seems the facto gem to deal with the current Push Notification feature in ruby world.
Implementation:

  • We can initialize both services with their API keys:
    app = Rpush::Gcm::App.new
    app.name = "android_app"
    app.auth_key = "..."
    app.connections = 1
    app.save!
  • Send a message:
    n = Rpush::Gcm::Notification.new
    n.app = Rpush::Gcm::App.find_by_name("android_app")
    n.registration_ids = ["..."]
    n.data = { message: "Hello World" }
    n.save!

 Conclusion

Rpush gem seems the best option because it supports all Push services, and is the most active gem in this area.

For your Rails App we will need (for our config file) the Application name and the auth_key.