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.
 

Monday, 26 May 2014

Add Reindent keyboard shortcut to Sublime-Text 3

I like my code to be always properly formatted, which makes it easier to read and understand. I use Sublime-text for coding and it has Reindent feature which can be found at Edit>>Line>>Reindent ,but everybody wants a keyboard shortcut.

Here is how you can add this shortcut in sublime

Go to Preferences>>Key Bindings - User>>

Now add below key value pair to existing json array (mostly it would be empty previously)

{ "keys": ["ctrl+shift+r"], "command": "reindent"} 

My file contents looks like this

[
    { "keys": ["ctrl+shift+r"], "command": "reindent"} 
]

Instead of ctrl+shift+r you can have any other shortcut you like eg. f12, ctrl+r ...

And remember, To make this shortcut work , you need to have syntax highlighter plugin already installed for the programming language you are using.

Thats it guys. Enjoy the beautiful code.

Monday, 24 February 2014

Accessing Guest (VirtualBox) Node.js Application from Windows/Ubuntu Host

If you are running a Node.js Application inside a Ubuntu VirtualBox machine and want to test the same application in any browser inside your Windows/Ubuntu Host OS, then follow this small tutorial. You can even test the application on any other device in same wifi or lan network as your Host/Guest Machine.
The main reasons I wanted this kind of hack is
  • The Guest machine becomes slow and laggy if you start any browser in it to test your applications.
  • Sometime you just want to use CLI 1.
  • Test the Web Application in mobile or tablet device.
I am explaining here the steps to make it work.

Thursday, 20 February 2014

Test WCF Service with WCF Test Client without installing Visual Studio

There are various tools to test WCF services. Visual studio installation comes with default tool called WCF Test Client, which can be run from Visual Studio Command Prompt by typing wcftestclient. Alternatively for VS 2010 you can navigate to C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ where you can find and open WcfTestClient.exe



Convert Ember.js online guide using Gimli for PDF generation

There are numerous online sources for learning Ember.js but the best one is their guide on official site. Recently I was learning this framework and headed to the guide page. I just wanted to read it first on my mobile or tablet, But the guide is neither mobile friendly nor any PDFs available. But they have full source of their website on github in Markdown.