Docker containers memory troubleshooting

I’ve been playing around with docker for about a week now to figure out if its the right tool for what we’re planning to do. I’ll briefly describe the setup and dive into the issue. The sandbox environment is setup in a vagrant box(referred to as the ‘host machine’ from now on) running Ubuntu 13.04(updated the default kernel). Memory assigned to the host machine is 512. The base image is available on docker index and is about 2.

Read more

Share Comments

Hosting woes end

So, it was about an year ago I started having problems with my hosting provider. The first one was Znet(http://www.znetlive.com/) . The problems were (biggest) long load times, frequent “maintenance” shutdowns and other accessibility issues. After living with this for some time I decided to move to a different host and this time chose Brainpulse(http://www.brainpulse.com/). The primary reason for choosing these was location preferences. Brainpulse hosting was going good for a while before their screwed up (and completely lost) tech and customer support managed to make sure this site was down for about a week.

Read more

Share Comments

Backbonejs tutorial

So I stumbled around for some time before figuring out the ‘hello world’ tutorial for backbonejs but since it took me more time than expected, I decided to write one myself. The docs are great but are too mind-boggling for a newbie, especially ones who rarely venture into client side frameworks. As I mentioned, this tutorial wont show you much apart from getting a very very basic backbonejs example working. The code is available on github HERE.

Read more

Share Comments

Node.js(Part-5)Login-Logout Flow

In this tutorial, I will be making a simple authentication flow using the technologies that we have already discussed. By the end  of this tutorial, you would have made a flow similar to the one indicated by the diagram below. This will also help you see how you can make your views more intelligent, readable and easy to build.

In the PREVIOUS POST we build the application views. To give some intelligence to those views

we are going to use some of the amazing features of JADE. I recommend you go through the

documentation of JADE to get an idea how decision making can be done in the views only.

This will be required, for example, while rendering a ‘Logout’ button. This button should only be shown if the user is logged in. So, instead of checking on each render call, we will put the logic to check and then render the appropriate view in the views(topbar.jade, in this case) only.

Lets go one step at a time here. We are assuming here that the user credentials are already present in the database. If you are referring to the project’s CODE, then just run the file named ‘insertUser’ in the ‘/scripts’ folder. This will insert an user in db with username : test1 and password : test1.

For this example, this can even be hard coded.

Step 1 : User Authentication

This step will involve a simple form POST which sends user credentials to the server where the user login and password can be authenticated the usual way. We will be using mongodb for storing user information and the stored data will be used to authentication.  The following snippet shows the route for handling login POST request. This is submitted when the user enters the login and password in form provided on the topbar. We set a handler on the ‘Login’ button so that basic input validation can be done on the values that the user has entered.  The following code will POST the data to server.

If the credentials are incorrect, then simply redirect the user back to home page.

On the server side, we do a simple user validation and return the appropriate response.

Read more

Share Comments

Node.js(Part-4) Some more Jade + Bootstrap

Welcome to yet another tutorial in the series. HERE is a reference to the previous tutorial in case you might want to revisit anything there. This tutorial will guide you through some of the advanced features of Jade and Bootstrap. This will also give you a brief idea as to how your views/html code should be structured.

First things first. Right now we have all the view code in ‘views/index.jade’  that is inserted into the ‘views/layout.jade’ and then rendered. This is only feasible(and practical) if the views are less in number and hence easily manageable- a situation you are very less likely to end up in. Ideally you would want to have separate components for each module/functionality and have their separate views. So we will refactor this code first and move each functionality in a separate places(files).

First, Tell express that you don’t want to use layouts anymore.

In the app.js, add the following line to the configuration.

now this will make sure that you are responsible for rendering each and every view(page) of your application and linking them to one another. To begin with, you have already specified which directory is going to be your views directory in ‘app.js’ by mentioning the following line

express will, by default, look for the file named ‘index.jade’ in this directory(/views) as the first lookup.  We will put our javascript and stylesheet includes in it. The path that is specified here will be with respect to “public” folder from document root. So, for example, if you want to include a javascript file called ‘test.js’ which is in folder ‘public/js/test.js’ then you would specify only the path from ‘public’ folder, i.e. “link(href=”/js/test.js”)”. Following is a snipped of ‘views/index.jade’ that shows our script includes.

Read more

Share Comments

Node.js(Part-3) Jade + Bootstrap

Moving on with the next part of this series of tutorial, today I will give an introduction about the Jade template engine for Nodejs and Bootstrap tookit provided by twitter. In the PREVIOUS post, I have described about the basic layout of a nodejs application based on express engine and we have till now run a very basic(and mostly useless) server. By the end of this tutorial, we would’ve made a nice looking container that will hold the various parts of our application.

What I have in mind is basically something like following diagram.

This is the most simplistic layout and we will work with it for some time before changing it.

Lets start with Jade first.

Jade :

According to Jade’s github page : Jade is a high performance template engine heavily influenced by Haml and implemented with JavaScript for node.

For an extensive list of jade features, visit the jade github page.

What jade does basically is clean up the HTML content of the page and hence improves the readability.  It provides a lot of functionalities on top of that like ‘partials’ and easily mix javascript and HTML code. We will see how that happens in the course of making the design just described.

So we dont use Jade instead of  plain old HTML. How does that help? Well, it helps people like me who get intimidated easily by all the HTML code they see and who also want to add lots of javascript to it. Plus, as just mentioned, while doing that, the readability of the page is maintained.

For example, if we had a simple username form written in html, it would look something like following.

Now if Jade were used in place of this, the same form would look something like following.

Read more

Share Comments

Node.js(Part-2) Application Layout

Continuing from the last post  , this tutorial will give a short description of Jade, using partials with Jade and Twitter Bootstrap.

If you have looked at the directory structure of the application that express has automatically created, you will notice a structure similar to something like this:

/

|—- app.js

|—- package.json

|—- public

|        |—- stylesheets

|                |—- style.css

|—- routes

|       |—- index.js

|—- views

|       |—- index.jade

|       |—- layout.jade

|—- node_modules/…

1. app.js :

the main configuration and boot file for the application. This will describe the global includes, the server configurations(deployment/test/production, etc), the available routes and any other data that is required by the application for initial bootstrap. The current app.js file only includes ‘express’ (huh).

After this we create a server by issuing the following statement

This creates a new server object for us and also makes it available outside this file by exporting it.

Read more

Share Comments

Node.js(Part -1) : Getting started

As promised, I now begin the series of tutorials on the amazing new technology called Node.js which I have started working on some time back. Though I don’t promise that the methods I suggest are the best way to achieve the required goal, but I can guarantee that they work.

To start with, I assume that the reader at least knows what node.js is about. To quote the official node website Node.js – Node is an “Event-driven I/O server-side JavaScript environment based on V8.”

There… thats it. In its entirety, node has a minimalistic core which provides it the amazing flexibility to be extended. There are many amazing features in node that you can read about in its official documentation.

Before you proceed, I strongly recommend you read THIS tutorial and TRY all the examples given in it to get the idea of how node works with asynchronous callbacks. Though it would be better if you did the whole thing step by step yourself, below is the link to my github profile where you can download the completed example 😛 .

https://github.com/ric03uec/nodejsTest

In this series, I will be emphasizing on building a full fledged web-application with following features:

  1. Basic design of an application

  2. Creating an MVC architecture using Express framework

  3. Using Twitter Bootstrap to get better looking widgets with JADE templating engine

  4. User authentication, both custom and using services like twitter, facebook, google etc.

  5. Sending emails from the node application

… and anything I think I found some difficulty looking up and is worth mentioning.

Without further ado, lets get to it.

To proceed further you should have Node and NPM (Node Package Manager) installed. All the examples have been tested on Ubuntu 11.10.

– Using npm, install expressjs globally by issuing following command

After this is installed, you can create an example application called ‘myblog’ by just punching in following command

Express will create a directory called ‘myblog’ and a bunch of files in it. You dont need to know what exactly those are there for right now. I will be explaining that later.

Now navigate into the ‘myblog’ folder and type in

You will find some error saying – ‘Cannot find module ‘express’. Right. But you just did create this very folder by using express only. Turns out that this application requires express locally and hence you have to install express locally for this module also. This is true for any node module. The dependencies have to be satisfied locally.  Ok, so what do you do now? Take a look at ‘package.json’ file.

This file contains all the dependencies that your application requires and it will have two entries – express and jade. Now just type in:

Read more

Share Comments

GWT Event Bus

This tutorial is inspired by the screen-cast HERE and is a more basic version than shown there.

Basics: GWT event-bus, as the name suggests is used for passing events between panels and other widgets so that they can communicate with each other. For this, a widget specifies what event it is going to fire and any widget or class that is interested in receiving that event registers themselves with that particular event.  The event bus is the entity that facilitates this. It can be thought of as a common stream that broadcasts events as they are fired and anyone who is attached to it receiving the events which they specified they were interested in at the time of registering themselves with the bus.

With this short introduction,I will proceed to give an example.

  1. Create a project in Eclipse: File -> New -> Project -> Google -> Web Development Project. It is assumed that the user has GWT plugins installed for eclipse. This example was made using Gwt 2.2. Give the Project Name as ‘GwtEventBus’ and package name as ‘com.dev’. Leave the rest of the settings as they are and create the project.

  2. Test this example: The project creates a Hello World example that works out of box. All you have to do is run and see if it works. In the Package Explorer window in eclipse, right click on the ‘GwtEventBu’s project, go to ‘Run As…’ and click ‘Run as Web Application’. This runs the project and you can play around with it before proceeding.

  3. Remove redundant code: Since we do not need most of the code of this example, we remove everything inside the ‘onModuleLoad()’ method of the GWT entry point class ‘GwtEventBus’.

  4. Add a button to the root panel: Now create a button in the ‘onModuleLoad()’ method. Add this button to the Root panel and attach a handler to it.

  1. Create Packages: Create two packages within the ‘com.dev.client’ package with the names ‘com.dev.client.events’ and ‘com.dev.client.events.handlers’. These will house the Event objects and their handlers respectively.

The aim here is to create two events Ping and Pong. Ping event will be fired through the event bus when we click the button on the screen and start the ‘simulation’. Ping event handler will be registered with the event bus and will be called when the Ping event is fired. This will, in turn, fire Pong event and Pong event’s handler, after receiving Pong event, will fire Ping event. We will introduce a delay between event receiving and event firing and output appropriate message on the console to make the working more clear.

Read more

Share Comments

D3vf3st and more

A great weekend after a long time. Well, call it weird but my definition of ‘great’ here does include spending full Saturday on google devfest(D3vf3st, as they decided to call it) and then the  night on a party whose duration overlapped with the wee hours.

The dev-fest was something I was looking forward to intently since the very moment I received the confirmation mail, which was about a couple of weeks back. The conference was divided into sections ranging from Android, Google Apps, HTML5, Chrome, GAE aspects and few more. As for me, I was primarily interested in Android and GAE. After the keynote lecture on UI patterns of HoneyComb and some amazing features(read powers) of HTML5, the lectures began.

The first one was on the Android Market by Tony Chan who delved into the factors that can make or break an application in the Market and what are the various tools developers can utilize to get maximum benefits out of their application. Since I already have deployed an application on the market (:smug smirk), I knew about most of the stuff being talked about. But at the same time, there were many tips he suggested that one should pay attention to while deploying the app. For example, I did not know that once an app has been released as free, it cannot be made paid whereas the reverse option is available. Also it is a good idea to explain in the app description as to why a particular permission is being asked by the app.  Rest was more of the usual stuff which everyone knows but choses to ignore, especially when developing just for the pleasure of it. Tips in this category include the likes of, yes you guessed it, making a good UI, building relationships with user and monitoring user comments. All in all a good set of useful pointers on what to do and what not to.

Read more

Share Comments