Friday, 13 June 2014

Javascript MapReduce tips and tricks

Recently I was using map and reduce functions in javascript for my project. both of them are absolutely amazing. You can use them for different kind of array manipulations. Here I am listing out various use cases with code.
1. Finding unique elements in an Array
var cities = ["bombay", "delhi", "bombay", "delhi", "delhi", "chennai"];

var uniqueCities = cities.reduce(function(p, c){
         if(p.indexOf(c)<0) p.push(c);
            return p;
         },[]);
console.log(uniqueCities); // ["bombay", "delhi", "chennai"]
2. Sum up array of numbers
var foo = [1,2,3,4,5];
var bar = foo.reduce(function(sum, a) { return sum + a; }, 0)
var barOne = foo.reduce( function(sum, a) { return sum + a; }, 1)
console.log(bar, barOne) // 16
here, the second argument of reduce is initial value of sum. If you don't give the second argument at all, it will work here but it may not work in case of complex objects.

...more use case coming soon.

Sunday, 8 June 2014

Zeal : Offline API documentation browser for Linux

Quoted from zealdocs.org "Zeal is a simple offline API documentation browser inspired by Dash (OS X app), available Linux and Windows".

Zeal gives you offline API documentation for most of the Libraries out there like Angular, Backbone, Django and many more. You can check the list on Dash's website

You can easily install on Ubuntu 14.04 by following steps
1. Run following in terminal
   sudo add-apt-repository ppa:jerzy-kozera/zeal-ppa

2. then do  sudo apt-get update

3. and install with sudo apt-get install zeal

After installing Zeal it can be started from terminal by running zeal and add it to to Startup Application.

Right now only version supported is for Ubuntu Linux Trusty (14.04). Zeal is available for previous version but are not supported officially.

Issues and Solutions
  • I faced a minor issue after installing Zeal. I was not able to see main menu on top of it from where you can I found solution at zeal issues . I tried removing appmenu-qt5 package which worked from me. 
  • Every time starting Zeal will show a popup that it's Hotkey is confliting with system's. So I changed it's default Hotkey from Alt + Space to Ctrl + Shift + Space (Synapse is already using Ctrl + Space)

Installing Synapse launcher in Ubuntu 14.04

I recently upgraded from Ubuntu 12.04 LTS to 14.04. I was quite used to of the Awesome Synapse launcher on Ubuntu 12.04. Just press Ctrl + Space and synapse is there to serve you.

Unfortunately Synapse is not directly available through Software Centre in 14.04. But you can install through testing PPA. just follow this steps

1. Open terminal and add the ppa and press Enter

sudo apt-add-repository ppa:synapse-core/testing
 
2. Now update the Software Repository and after that install synapse

sudo apt-get update
sudo apt-get install synapse 
 
That's it. Now enjoy the awesomeness of Synapse.