Sponsored Link

Saturday, December 22, 2012

How to set environment variable in Ubuntu

If you just need to set an environment variable for the current session you can always use export ENV_VAR=VALUE command. But most of the cases you will need to persist that variable.

Ubuntu no longer recommends setting environment variables in ~/.profile file. Instead you have to set it in ~/.pam_environment. You need to re-login for this to take effect. The environment variables are read from ~/.pam_environment file and is set when a user logs in. Read Ubuntu documentation on Environment Variables here.

The file ~./pam_environment might not be already available depending upon your configuration. In that case you need to create a new file. Make sure you create it in the home directory.

touch ~/.pam_environment

This command will create a new empty .pam_environment file in your home directory. Note that this is a hidden file and won't be visible in the file browser unless you have selected to show hidden files.

Next thing you will do is to open the file and just write your environment variables as a key-value pair, like this NAME=VALUE, one per line. NAME should not have any spaces.

vi ~/.pam_environment

A sample .pam_environment file

#the hash(#) sign at the beginning of the line makes it a comment line.
DATABASE_URL=postgres://heroku:[email protected]/herokuappdb

Advanced configuration

There are two possible options for each of the environment variables - DEFAULT and OVERRIDE. The DEFAULT option, if provided, sets the default value of an environment variable, else "" is assumed. And this DEFAULT value can be overridden by using the OVERRIDE. Again if OVERRIDE is not given "" value is assumed.


You can read more and view some examples on your system by typing the following command on your terminal.

cat /etc/security/pam_env.conf

Some Ubuntu books you should check out:

Friday, December 7, 2012

Youtube Redesign 2012 - More focused on subscriptions

I don't know how many of you got the new design of Youtube. But I have been getting a new homepage on Youtube on and off for about a month and now it seems to be stable. Sometimes it was only available on Chrome, but now I have tested in both Firefox and Chrome.

Now it looks so much better. Youtube is making use of most of the unused space, better font, more visible links and features, easily accessible analytics and video manager and most importantly more focus on subscriptions.

Now the recommended videos is called What to watch, which I think is easy to understand even for a toddler. On the homepage you get popular videos and categories like Popular on Youtube, Music, Sport, Gaming, Films, TV Shows and Spot Light. From the order of the categories, it looks like Google is trying to prioritize Music than others. The Spot Light category shows you popular videos in your country.

The hidden menu on top, which opens up on clicking your name and the Google+ button is also tweaked a little. Space utilisation is better although there is a little unused space.

All in all Google is trying to propagate its new simple minimalistic design language across Youtube. This time you won't need any time at all to get adjusted to the new design, like the previous redesign.

Checkout the screen shots, if you haven't already got the new design.

New Youtube Homepage

Now with more videos and easily accessible links on the left hand side.

Redesigned Hompage after signing in

Here we get the recommended videos and social updates. And again all other options are easily accessible at the left hand side menu. We also have popular channels and recommended channels on the right hand side.

Analytics and video manager

This is handy for a Youtuber. Both Youtube analytics and video manager can be now reached with just one click.

Redesigned video screen

Have a look at the new like button and meta informations. The comment section seems to be now more focused on the comment text rather than on likes.

Overall I would give a 8/10 to the new Youtube design. How much will you give?

Monday, November 26, 2012

How to transfer files to Amazon EC2 instance using FileZilla

SFTP access to Amazon EC2 using FileZilla

When using cloud service like Amazon EC2, most trivial task will be to get your data/files up the cloud. Amazon offers secure ftp (SFTP) service and gives instructions how to use it on command line.

But if you have many files stored in separate locations, it will be easier to use a GUI application like FileZilla. And best thing about FileZilla is that it works on Mac, Linux and Windows. Ubuntu has also included FileZilla in their repository and you can install it on Ubuntu using:

sudo apt-get install FileZilla

Before using FileZilla to upload files, make sure you follow the steps given in EC2 documentation, activate SSH and test it on the shell/command prompt.

Amazon uses authentication using key file and does not accept username & password combination, unlike other SFTP services. When you add a new site to FileZilla site manager, you wont find option to use key-file.

You need to import the key file in another location. Go to Edit --> Settings, you will find the option to upload keyfile under the SFTP option.

FileZilla will convert *.pem file to .ppk file which is Putty Private Key format and save it in a location you specify.

Now you can use upload files to your EC2 instance without a glitch. FileZilla will automatically authenticate using the added key file. You may add other key files along with Amazon EC2 keyfile, it will still authenticate you.

Wednesday, November 21, 2012

Disable dashboard on startup in Spring Tool Suite

You can increase the startup speed of Spring Tool Suite by disabling the Dashboard which gives you a lot not so important new and updates at the startup. And yeah, if you disable it you don't have to close it every time you open STS.

Option to disable the dashboard is available in the preferences.

  1. Close the dashboard if it is already open
  2. Goto Window >> Preferences
  3. Locate SpringSource >> Dashboard
  4. Uncheck the option that says Show dashboard on startup.
Spring tool Suite disable dashboard
Spring tool Suite disable dashboard

Next time you open Spring Tool Suite, no more annoying dashboard.

By any chance if you want to enable it again, just enable the checkbox again.

Friday, November 16, 2012

jQuery:: Getting started with jQuery

This is a beginners guide and information to getting started with jQuery. As you might know jQuery is light weight and cross browser, and is a leading JavaScript library. It was created by John Resig, while he was working in Mozilla.

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

What is JavaScript library?

JavaScript libraries help you write more organised JavaScript code. These libraries are built on top of JavaScript and helps the programmer to write more maintainable cross-browser JavaScript.

Write less, do more

As it says on the home page, jQuery helps you to reduce your JavaScript code with clever, short and easy to understand syntax.

Why do we need jQuery? (or any other js framework)

In short, for faster development and better maintenance. If you have developed web application, you know the pain for writing vanilla JavaScript and hacking it to work as expected on all available browsers. The code base becomes huge and cluttered, which in turn effects the application maintenance. You could minimize it, by the clever use of JavaScript objects and prototyping. But a new developer may not be able to follow your code, unless it is properly documented and you are trying to re-invent the wheel.

If you are using a js framework like jQuery, then you can be sure that it is properly documented and there is a huge community out there to help you out.

Other JavaScript libraries?

There are lots of other js frameworks like Mootools, Dojo, Prototype, YUI and many more. Deciding which one to select depends on various factors like the project requirement, resource available, deadline etc.

What I liked about jQuery is that is easy to get started and get cracking. They say Mootools is great, I found their documentation poor. Mootools is a great choice if you are going to develop a complex application with lots of custom objects in it. jQuery is more focused on manipulating collections returned by the selectors.

For example jsFiddle is built on Mootools, building that on jQuery would have been harder.

How can jQuery help?

  • Its fast - Test JavaScript framework selectors speed at slickspeed
  • Cross browser - Forget about writing js hacks for IE, same code works everywhere.
  • Small size - just 55kb
  • Easy animations and CSS3 selectors.
  • Makes your REST client simple, with built in ajax support.
  • Extremely simple to get started

Onload event

Most javascript developers use the onload event either in the body tag or window.onload in javascript. But when using jQuery you don't do it like that.

Instead, you load the jQuery. file and use $(document).ready(); function available. Most jQuery functions allows callbacks. Callback functions are called up on an event.

$(document).ready(function () {

This will alert 'loaded', when the document is loaded. Here the callback function is defined as an anonymous JavaScript function, which jQuery calls on the event of 'document ready'. Read about the difference between onload & document ready here.


To get started with jQuery you should need an understanding of selectors. Selectors always return us a collection of jQuery objects, which we can manipulate. We may select an object using its id, class name, tag name or its combinations. The rules are similar to CSS rules. Id is referred using '#', class is referred using '.' and tags are selected using the tag name.

For example an element with id myelement is selected by


All elements with class myclass is selected by


And all p elements can be selected by


As you have figured out all p elements with class myclass is selected by

    $('p .myclass')

After selecting an element or group of element, you can manipulate is using various functions available in jQuery or in plugins. You may as well write your own jQuery plugins.

Now let us look at doing something with jQuery and JavaScript. We will try a simple example of changing the text content in an html element. Here is the content we want to change:

We will change the 'Old Text' to 'New Text'

Change html text using JavaScript

Fiddle here: http://jsfiddle.net/gh/gist/library/pure/3775927/

Now the same stuff in jQuery.

Change html text using jQuery

Fiddle here: http://jsfiddle.net/gh/gist/jquery/1.8/3776540/

In jQuery we did that in one line and the code is so much easy to understand. Also it processes fast as it doesn't wait for the complete all content to load, as soon as the DOM is available, jQuery starts it job.

Tuesday, November 6, 2012

How to unlock Samsung Galaxy Ace (for free) from a network

My phone was locked to 3 network here in UK and I badly needed to unlock it because my other phone got damaged and couldn't afford to get a new phone. You can get an unlock code from your service provider by making a payment of £15 (when writing this blog), in UK. I would rather spent my money on beer than on phone unlock codes. Any how, I got a solution for this and here I am sharing it with you.

This method is recommended for Samsung Galaxy Ace (GT-S5830) only and when I did this my phone was running on Gingerbread version 2.3.6. However, the developer claims it may work in the following models too.

  • Samsung 5 Europe (i5500)
  • Samsung 551 Callisto (i5510)
  • Samsung (i5700)
  • Samsung 3 (i5800)
  • Samsung Pro (i5510)
  • Samsung Galaxy mini (S5570)
  • Samsung Fit (S5670)
  • Samsung Ace (S5830)
  • Samsung Pro (B7510)

I would also add, that the paid method is definitely risk free and safer than this method.

Before proceeding check your phone lock status by dialing *#7465625#. The Network Lock should be [ON] now.

First you need to root your galaxy ace. Procedure for rooting the android device can be found in my previous post.


Secondly, you MUST install BusyBox and run it once. Running BusyBox will ask for super user permission, grant it. Otherwise unlock codes won't be visible. This step is important, else chances are you will get 'or or or' problem, as mentioned by many commenters. Thanks much to Asok, Ratty and Daniel Hamblett (commenters) for notifying this.

Once you have BusyBox ready with root access, download and install Galaxy Ace Unlock by Helroz


This app can be run only on a rooted device. There are only 3 steps to get your phone unlock code

Getting the unlock key

  1. Run the app
  2. Touch on the option given. Unlock. See your sim unlock code
  3. Confirm your choice by selecting Yes on the next screen.
  4. Wait till the app shows the unlock codes.

The app extracts the network unlock code from the phone and shows it for you. It may give upto 4 different unlock codes. In my case all the four unlock codes were same. Note down the unlock codes.

Once you have the unlock codes, switch off your phone and boot it with an unsupported sim card.

When the phone boots it will ask for the unlock code.

Key in the unlock code. Do not try the same unlock code more than once. Any one of the unlock code will have worked.

If the unlock is successful it will display this message. Network unlock successful

Now if you dial *#7465625#, the Network Lock will be [OFF].

That confirms you have successfully unlocked your phone from the network.

Here is a video for those who are too lazy to read... :P

Monday, November 5, 2012

How to root your Samsung Galaxy Ace

Rooting an Android device allows the access to root user in the operating system. I needed to get root access in order to unlock my phone from the network. It is pretty simple procedure and I followed the instructions given at androidforums. While rooting, my device was running Gingerbread 2.3.6

Step by step instructions for rooting the device is clearly given in the Android forum post by victors1995. My device had no issues after rooting. You will see a new launcher called super user in your software list, which can be used to grant or revoke super user capabilities to other apps. I went ahead and installed Busybox free and Root checker basic.

After rooting I also unlocked my phone from the network.

NB: Do this at your own risk. Rooting may void the warranty of your device.

If it helped share it with your friends. Feel free to comment about your experience.

Here is an instructional video on how to do this

Wednesday, October 10, 2012

js :: Count down timer in vanilla Javascript

In this article I will take you through creating a Timer object in javascript. We will create a javascript object that can be easily used to create multiple timers on a window.

A count down timer can be implemented in JavaScript using setTimeout or setInterval functions along with recursion. You may read this very good article on javascript timers with setTimeout and setInterval. The important difference is setTimeout sets an execution time for a given function and setInterval calls the same function on given interval. Both work on milliseconds range.

A simple example of count down timer using the setTimeout is shown in the jsfiddle below. Run the code from the Result tab.

All this above function does is to update the span content every 1000 milliseconds. As you can see here the setTimeout is applied to the window object. We also use a global variable to determine when to stop the timer. When the countDown() function is called timeout of 1000 milliseconds is set for countDown() function. If you repeatedly click on the start button, timeout of 1000 milliseconds is added at different times.

Now that we understand the simplest timer function, we will go ahead and make improvements to it.



  1. http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/
  2. http://ejohn.org/blog/how-javascript-timers-work/
  3. http://mckoss.com/jscript/object.htm
  4. http://helephant.com/2008/04/26/objects-event-handlers-and-this-in-javascript/

Wednesday, September 26, 2012

c++:: Paisa to Rupees converter

The following gist is a paisa to rupee converter written in C++. It is nothing important and does not do anything exciting. It was just an attempt of mine to write some C++ code after more than eight years. This was the simplest idea that came to my mind.

Objective was to use separate header files, pointers and class references, static member functions and polymorphism in a program.

Wednesday, August 29, 2012

HTTP Caching explained

HTTP caching is an important technique that can be utilized in modern web applications. Caching reduces latency and improves page load speed there by improving user experience.

Proper use of caching mechanisms can bring in serious performance gains. Caching reduces load on servers by bringing the resources close to client. It also reduces the latency of requests and amount traffic in the network, there by improving the performance for all network users and allows network to scale.
Both client and server can control what is being cached and when to enable caching and on what conditions to update the available cache. Caching becomes really effective in large organizations since users typically access common web addresses.

The goal of caching in HTTP/1.1 is to eliminate the need to send requests in many cases, and to eliminate the need to send full responses in many other cases1.

Caches serves as an intermediary between clients and server, by holding a copy of resources belonging to server. When a cache receives a request from a client, it can reply back directly without needing to contact the server. As the cache is "nearer" to the client than the server, client receives the response much faster. However, the before replying to the client, cache must be able to guarantee that server would provide identical response for that request. Cache must be able to check whether its copy of resource is valid or not.

How does it work?
An expiry mechanism is implemented to avoid sending requests for valid resources, thus avoiding round trip delays. Similarly a validation mechanism is used to avoid sending full responses, which saves the network bandwidth.

The server can associate an expiry time with each resource, and guarantee that the resource won't change before that time. Thus the cache knows, the expiry time of its copy of resources, and doesn't need to send the request to server.

To avoid sending full responses, cache can check validity of its copy by sending a conditional request to the server. The server only sends a full response, only if the resource has changed.

Web browsers like Firefox and Google Chrome often caches static resources like Cascading Style Sheets and Javascript files. Web developers utilize HTTP caching advantages by delivering content through popular Content Delivery Networks (CDN). For example Google hosts a number of common web development libraries like jQuery, Mootools and Dojo through their CDN. A typical CDN will have multiple copies of resources residing on servers spread across the globe. A request to a resource is served by the nearest server. But that is not caching, I'll explain this in the following section.

Advantages of caching comes when many web sites point to the same CDN. For example if 10 websites use jQuery delivered through Google's CDN, then the browser will send request for the resource file only once, as the identical resource will be already available in the cache in consecutive requests. This is serious network traffic gain when considering millions of websites. If the CDN implements expiry mechanisms, then the browser cache may serve the resource for a month or may be a year!

Friday, July 27, 2012

Maven:: Invalid CEN (bad signature) Invalid LOC (bad signature)

So, you are here, and I guess you are having a tough time trying to figure out what that error is. I'd spent almost three days trying to figure out what this crazy error is, but then decided to not waste time and deleted my Maven repository folder at ~/.m2/repository.

I assume that, this is some bug in maven, but this also pops up in several other projects like Apache Tomcat, Atlassian Confluence etc. The error comes up randomly and developers spent a great portion of their fruitful work time, just to figure out whats going wrong. And most of the time it is not their fault.

This error comes up randomly and means that one of the jar file in the project class path is corrupt. A practical solution is to replace the jar files with new ones freshly downloaded.

This crazy error show up when the JVM thinks that the jar file it is accessing is corrupt. So I assumed if I delete the dependency jar files and download them again, it might solve the problem.

#delete repository
rm -rf ~/.m2/repository/*

#use maven
mvn test

This deletes all files from ~/.m2/repository/ first and then, mvn test will download all dependent jar files before building the project and running junit tests. It took a while for Maven to download all my dependencies, but was worthwhile. The project is back in action!!!

If you are not using Maven or any other dependency management tool, you may try downloading the required jar files again, may be from a different source, if the file in that source is corrupted. This error may also come up when checking out from repository.

Monday, July 16, 2012

Ubuntu:: How to Change the Computer Name

Changing computer name in Ubuntu is easy.In Linux computer name is represented as 'hostname' and this name can be used to identify a Linux box in a network. To display current hostname on your linux machine

$ hostname

To change hostname for current session

$ hostname new_host_name.my_domain

To change hostname permanently

  1. Open /etc/hostname file as root
  2. $ sudo vi /etc/hostname
  3. Change the name and save the file
  4. New hostname will take effect after the reboot.
  5. You will also need to update the /etc/hosts file with the same computername

Note that, the new name will take effect after you restart the machine. If the same hostname is configured on any other machine in the network, system may fail to boot or won't be available in the network.

Tuesday, June 26, 2012

R:: Visualize your inbox using R

I just found an interesting R script that can visualize your email inbox.


Edit: The post has been moved to r-bloggers.com. http://www.r-bloggers.com/sna-visualising-an-email-box-with-r/ (Thanks to M Mouse for the updated link.)

The script creates a Graph using 'from' and 'to' addresses of the messages in your inbox. I din't have to do any modification in the script, it worked directly for me in my gmail.

This is how my inbox looks like!

Friday, June 22, 2012

c++:: Using namespace std; What does that mean?

Namespaces in C++ are used to define a scope and allows us to group global classes, functions and/or objects into one group.

When you use using namespace std; you are instructing C++ compiler to use the standard C++ library. If you don't give this instruction, then you will have to use std::, each time you use a standard C++ function/entity.

Have a look at the following example, which is very straight forward.

#include <iostream>

using namespace std;

class MyClass {
        public: void sayHello();

void MyClass::sayHello() {
     cout<<"Hello World!\n";

int main() {
       MyClass myClass;
       return 0;

If you are not using namespace in the above example, you will have to use std:: everywhere you use cout, like the following.

#include <iostream>

class MyClass {
        public: void sayHello();

void MyClass::sayHello() {
        std::cout<<"Hello World!\n";

int main() {
       MyClass myClass;
       return 0;

More about namespaces in C++

Namespaces allow you to group different entities together. You may create your own namespaces for grouping your entities, and access them the same way you did for 'std' namespace.

#include <iostream>

using namespace std;

namespace myAwesomeNamespace {
  int a=10, b;
namespace myAwesomerNamespace {
  int a=20, b;

int main() {
   cout<<"Awesome a = "<<myAwesomeNamespace::a;
   cout<<"Awesomer a = "<<myAwesomerNamespace::a;
   return 0;

You may also use using namespace with your custom namespces.

#include <iostream>

using namespace std;

namespace myAwesomeNamespace {
  int a=10, b;
namespace myAwesomerNamespace {
  int a=20, b;

int main() {
   using namespace myAwesomeNamespace;
   cout<<"Awesome a = "<<a;
   cout<<"Awesomer a = "<<myAwesomerNamespace::a;
   return 0;

Warning: If you use namepaces that have same entities grouped in it, then it will result in ambiguity error.

Related Posts Plugin for WordPress, Blogger...