Human vs Artificial Intelligence – Quick Insight

Screen Shot 2017-12-27 at 1.31.33 AM

What makes your life easier than a technical secretary who says, “What can I do for you Anonymous? I can help you solve real-life problems, and I can also help you with things that I don’t understand by connecting you to a human”.

chat-bots

This is how a life of new-born bot starts. As a kid getting trained on real-world problems via Natural Language Processing- Artificial Intelligence Based Human Language Interpretation to invoke technical callbacks. Callbacks that invoke functions like triggering ON and OFF event for a switch in case of Smart Homes like Home,  wake me up at 7 AM tomorrow in case of smartphones virtual assistants like Siri & Google Assistant.

revolutionizing-procurement-with-artificial-intelligence-and-machine-learning-5-638

Artificial intelligence is in competition with humans by automating human work and reducing the human workforce. There are a lot of discussions around fact that there is a segment of humans who don’t like bots and technology, they just don’t want to lose their job to a bot.

F8111284-01.jpg

But for those who understand that we should rather try to automate things than doing everything by ourselves just to feel ownership, “We are not the owner of anything in our life. We cannot control mind and body”.  People were using landlines before they started using mobile phones, and with time they started learning about social media websites like Facebook, mobile messengers like WhatsApp and traveling with Uber.

If you are here and trying to understand IoT- any device that is connected to internet/ network and can be controlled over same using apps on mobile phones, smart watches or web apps is an IoT device. An IoT device can be a light, air conditioner, speakers, music system in your car, energy monitors etc. If you are techie you can buy one of RaspberryPi starter kit and unleash your creativity.

Merry Christmas!

Advertisements

Creating API documentation from source code comments in JavaScript, C#, PHP & JAVA

From past 5 years I have been working with lot of technical teams struggling to version APIs and create API documentation as per spec change. After boom of version control tools like Github & SVN teams are able to track source code but updating API specs for every minor change is still something that developers forget or don’t really care to update on time. It doesn’t matter much if nobody else is consuming their APIs but if APIs are exposed as REST- developer/app should know at same time that something was changed in API.

Teams are still able to track major API version releases but minor spec change in APIs are untracked most of the time, sometimes cause of communication gap and sometimes cause of improper documentation, leading to frustration within teams and products. As developers, how do we version our APIs without giving this responsibility to one more person who has to coordinate with each and every developer of team trying to figure out what was updated and manually updating documentation at end of the day?

Recently, I came across a tool that made my life as a product developer plain sailing. Now the developer who is working on server side API needs to add comments in his code in proper format and anyone from team will be able to generate API document out of it. Whenever server team works on any functionality they update comments in their own code giving it a minor release number if required and team will be able to generate documentation if they have access to latest updated server code without knowing server code language on my local. Take below example for instance


/**
 * @api {POST} /route/api/ Login
 * @apiName Login
 * @apiGroup Authentication
 *

 * @apiParam {Username} Username
 * @apiParam {Password} Password
 *
 * @apiParamExample {json} Request-Example:
*{
* "Username": "test",
* "Password": "Test123",
*}
 * @apiSuccessExample Success-Response:
 *{
 * "Code": 1,
 * "Message": "Signed in Successfully",
 *}
 *
 * @apiError User Id/Password Is Incorrect.
 *
 * @apiErrorExample Error-Response:
 *{
 * "Code": 1,
 * "Message": "User Id password is incorrect",
 *}
 */

/**
 * @api {POST} /route/api/ Signup
 * @apiName Signup
 * @apiGroup Authentication
 *

 * @apiParam {Username} Username
 * @apiParam {Password} Password
 * @apiParam {Email} Email
 * @apiParam {FirstName} FirstName
 * @apiParam {LastName} LastName
 *
 * @apiParamExample {json} Request-Example:
*{
* "Username": "test",
* "Password": "Password",
* "Email": "Email",
* "FirstName": "FirstName",
* "LastName": "test",
*}
 * @apiSuccessExample Success-Response:
 *{
 * "Code": 1,
 * "Message": "Signed up Successfully",
 *}
 *
 * @apiError User Id/Password Is Incorrect.
 *
 * @apiErrorExample Error-Response:
 *{
 * "Code": 1,
 * "Message": "Please check details again",
 *}
 */

The above code in your own JavaScript/C#/PHP will generate an API documentation for you with an awesome left menu and standard parallax style API documentation.

Install apidoc using npm

npm install apidoc -g

Create apidoctemplate directory in root of your project

apidoc -i js/ -o apidoc/ -t mytemplate/

Create apidoc.json

vi apidoc.json

Configure your apidoc.json

{
"name": "My REST API documentation",
"version": "0.1.0",
"description": "My REST API documentation",
"title": "Detailed REST API documentation",
"url" : "https://yourdomain.com"
}

Run apidoc

apidoc

You can find your documentation here.


/doc/index.html

Now each time your server-side developer friend updates any spec ask him to edit the comment in code and your updated REST API documentation is ready.

Saturday, April…

Saturday, April 14th, 2012

Its 2:24am in the morning and I thought to share some experience about my feelings at a job with all you folks. ‘CONTENT’, a word used in a very ‘inspiring’ way, by someone I adore, to boost me up. It means you are happy, and while you may not think things are perfect, you can be happy despite that. Am sitting in my cubicle in my workplace.

I live with room partners. One of them is DBA and other is Software Tester working in the same company, which I work for. One of them is television(Sas Bahu) fan, and the other is afraid of future at age of 21. They are my good friends. Most of the Indian software ‘PROFESSIONALS’ are like this.

I have a manager who thinks, that employees are known by hard-work, not by ‘SMART-WORK’. My IT architect adores smart work, but he’s always busy. I can understand his hectic schedule. My room partner works for the same team, which I work for.

I am kind of person who loves his work. If I have something to do, I don’t care who I work for, my aim aims to love it, and make the best out of it. I love having ‘FUN’. Let me tell you not a person with very high IQ.

Recently, I met few guys from who started up a new company in Bangalore. They had a small workplace, with around 20 people(guess), compared to my medium sized office with around 150 employees and, my office is air-cooled. People, out there were inspiring, full of ideas, living their own lives. There was a feeling of ‘FREEDOM’ in them. India got free on August 15, 1947. My office has its own dress code, timing restrictions, project deadlines, access cards, rules, and regulations.

I don’t know if you noticed the words I have highlighted. ‘CONTENT’,  ‘PROFESSIONALS’, ‘SMART-WORK’, ‘FUN’, ‘FREEDOM’. These are the words, which can describe, any software engineers or any other professional.

Confused? Don’t scratch your brains too much, listen to this.

High-Hopes(Pink Floyd)

JS code snippets- Preloading images using JavaScript

There are cases when you want your JavaScript to save all the images in browser cache so as to avoid loading them required. Let’s say you have a select box where you select something and the corresponding image changes somehow. You can use the following code snippet to store and cache all images returned from an array in your browser cache

function preloadImages(array) {
    if (!preloadImages.list) {
        preloadImages.list = [];
    }
    var list = preloadImages.list;
    for (var i = 0; i < array.length; i++) {
        var img = new Image();
        img.onload = function() {
            var index = list.indexOf(this);
            if (index !== -1) {
                // remove image from the array once it's loaded
                // for memory consumption reasons
                list.splice(index, 1);
            }
        }
        list.push(img);
        img.src = array[i];
    }
}

The rise of ECMAScript – Goodbye 2015

What is ECMAScript?

toptal-blog-image-1435169544237-7137138c9b6badce17ca1e6094598255

As per Wiki-  ECMAScript(European Computer Manufacturers Association) is a trademarked [1] scripting language specification standardized by Ecma International in ECMA-262 and ISO/IEC 16262. We use various implementations of ECMAScript for client side scripting on web. Examples are JavaScript, ActionScript and Jscript.

ECMAScript was developed by Brendan Eich- Father of JavaScript. It was named Mocha, then Livescript and finally JavaScript.

ECMAScript7: The rise of compilers

babel

After ES6 (2015), there was huge rise in number of developers switching from traditional way of writing JavaScript to start using compiled code generators. Compiled code generators compiles code written in other languages to JavaScript. Our favourite JS code compiler is Babel(https://babeljs.io/) as it is actively supporting ES7 (ECMAScript 2016). For example Babel compiles following code:

const input = [1, 2, 3];
console.log(input.map(item => item + 1)); // [2, 3, 4]

to

var input = [1, 2, 3];
console.log(input.map(function (item) {
return item + 1;
})); // [2, 3, 4]

which will run in any JavaScript environment.

 

Some more examples are Opal(http://opalrb.org/) for Ruby, Pyjamas(http://pyjs.org/) for Python, Perlito(https://github.com/fglock/Perlito) for Perl, j2js(https://github.com/decatur/j2js-compiler) for Java, Blade(https://github.com/vannatech/blade) for C# and so on.

Gulp and Grunt: Automate your workflows

gulp-grunt

Measuring programming progress by lines of code is like measuring aircraft building progress by weight. – Bill Gates

With active usage of tools like Gulp and Grunt companies and developers started automating workflows for JavaScript applications. These tools helped developers in doing lot of automated tasks like library upgrade, automated testing, folder structure creation and so on. If you didn’t use Gulp and Grunt in your projects till now and make a New Year resolution to automate your build process and automate JavaScript tasks for an easier life.

The incredible Node.JS

node

Node.js foundation grew to more than 3 million users. Companies like Intel, IBM and Joyent used Node.js to create software architectures, real-time location tracking services and IoT. With npm lives of developers became lot easier as they could do a lot of heavy architecture creation using CLI. Also I heard companies switching from traditional Java/PHP technology stack to next gen Node.js for their active products.

How rise of ECMAScript revolutionized cross-platform apps

This year we saw a lot of people moving from native to cross-platform and vice versa. Keeping same codebase across all platforms helped companies and developers to launch their products in really less time when compared to writing code in different languages for each platform. With tools like npm creating a Cordova application became one liner.

</pre>
$ cordova create hello2016 com.example.hello2016 Hello2016
<pre>

We can’t wait to see what ECMAScript7 will bring in for developers working on IoT and next generation apps in 2016. Wishing all readers Techie-Happy New Year.

Video Advertising: Tips, how to play and pause YouTube videos on scroll and story behind Adele’s Hello

A lot of start-up advertisers and enthusiasts ask me about importance of video advertising. Recently, I met one friend who wanted to embed video ads in his app and website, the kind of ads you see on Gaana.com or auto play videos on Facebook which auto start and pause when you scroll.

Businesses also ask what kind of videos will work for their business. Here are few tips.

  1. Shorter is better – watch trailer before you go for movie

    length-matters-2
    Video length significantly determines how many people are going to watch your video. Just like you prefer to watch movie’s trailer before planning to spend 2 hours to watch entire movie, people prefer to watch 30 seconds trailer about your business, if they like the trailer they will definitely watch 30 mins video about your business and maybe turn to your loyal customers.

  2. Quality of video – short creative motivating story

    After length its quality of video that you are putting on your website or app. A short creative story that motivates customers to go for your business rather than other players in market is the key.
    online-video-marketing

  3. Viral – market your video using various channels

    This is one term that is viral over internet. I remember when people used to share videos over email, when YouTube was not there. “The Spirit of Christmas” was distributed over email and it led to creation of adult comedy animation series “South Park”. Now you have got lot of channels like YouTube, Facebook, Twitter and other social media platforms. Utilize them well.
    going-viral007

I feel, video advertising is in huge demand right now but there is no inventory. There are a lot of online tools that you can use to create good videos for your business. I am pasting small list here.

Now let’s go core technical and play and pause a YouTube video on scroll.

  1. In your script tag load the iframe Player API code asynchronously
    var tag = document.createElement('script');
    tag.src = "https://www.youtube.com/iframe_api";
    var &lt;span class="mceItemHidden" data-mce-bogus="1"&gt;&lt;span class="hiddenSpellError" pre="var " data-mce-bogus="1"&gt;firstScriptTag&lt;/span&gt;&lt;/span&gt; = document.getElementsByTagName('script')[0];

    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  2. after the API code downloads, create a YouTube Player
    var player;
    function &lt;span class="mceItemHidden" data-mce-bogus="1"&gt;&lt;span class="hiddenSpellError" pre="function " data-mce-bogus="1"&gt;onYouTubeIframeAPIReady&lt;/span&gt;&lt;/span&gt;() {
    player = new YT.Player('player', {
    height: '390',
    width: '640',
    &lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;videoId&lt;/span&gt;: '&lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;769SeL9QiFw&lt;/span&gt;',
    events: {
    '&lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;onReady&lt;/span&gt;': &lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;onPlayerReady&lt;/span&gt;,
    '&lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;onStateChange&lt;/span&gt;': &lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;onPlayerStateChange&lt;/span&gt;
    }
    });
    }
  3. On player ready set window.onscroll to check for video position on scroll
    function &lt;span class="mceItemHidden" data-mce-bogus="1"&gt;&lt;span class="hiddenSpellError" pre="function " data-mce-bogus="1"&gt;onPlayerReady&lt;/span&gt;&lt;/span&gt;(event) {
    window.onscroll = function() {&lt;span class="hiddenSpellError" pre="function " data-mce-bogus="1"&gt;checkIfToPlayVideo&lt;/span&gt;()};
    }
  4. Check scroll position and play pause video
    function &lt;span class="mceItemHidden" data-mce-bogus="1"&gt;&lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;checkIfToPlayVideo&lt;/span&gt;&lt;/span&gt;(){
    if(window.pageYOffset&amp;amp;amp;gt;200){
    player.playVideo();
    }
    else if(window.pageYOffset&amp;amp;amp;lt;200){
    player.pauseVideo();
    }
    //console.log(window.screenY);
    }
  5. Add div that will get replaced by YouTube iframe
    
    
    &amp;lt;div style="height:&lt;span class="mceItemHidden" data-mce-bogus="1"&gt;&lt;span class="hiddenSpellError" pre="" data-mce-bogus="1"&gt;800px</span></span>;position:relative;"&gt;&amp;<span class="hiddenSpellError" pre="" data-mce-bogus="1">nbsp</span>;
    <h1>Scroll down to play Video</h1>
    
    
    
    <div id="player"></div>
    
    
    <div style="height:800px;position:relative;">&nbsp;
    <h1>Scroll to top to pause Video</h1>
    </div>
    
    
    

    Great, you created Facebook like video experience. You can manipulate viewport based on your requirements. You can also check live demo here.

    Story behind Adele’s latest hit ‘Hello’

    There were rumours that Adele wrote this song after her breakup. As per her official interview if she would have written ‘Hello’ for her lost love it would be full of pain. But this video was not intended to be on ‘dark side’. The other side is not dark. There was a girl in her 20’s going through bad phase and people called her immature, emotionally stable on social media and compared her to Taylor Swift and there is a mature lady writing from a place out of her comfort zone and singing ‘Hello from the other side’.

    Happy Advertising and Coding! Enjoy ‘Hello’ in demo.

Image copyrights
http://wistia.com/
http://emarketingblog.nl
http://crispvideo.com

Advanced JavaScript: Environment Setup, DB integration and Securing Client in MeteorJS

This tutorial is in continuation with previous tutorial. If you are new here, read first chapter of this series Advanced JavaScript: Introduction To Server Side JavaScript Using Meteor before reading this tutorial.

I will be skipping traditional TO DO app tutorial here, as you can find it anywhere on web. Rather, I will try to explain few scenarios that developers come across while developing apps using JavaScript frameworks in real-time.

In this tutorial we will be covering

  • Setting up development environment for Meteor?
  • How to integrate your Meteor application with Mongo DB?
  • How to secure your Meteor application?

Setting up development environment for Meteor
Most popular IDEs like Sublime, Webstorm and on-cloud IDE- Cloud 9 integrates seamlessly with Meteor. I am a fan of Sublime so I will explain how to set up autocomplete engine into Sublime Text 3. You can visit Meteor website and setup your own IDE.
Open Sublime Text-

  1. From menu bar select preferences-> Settings -Users
  2. If you have not made any changes from time you installed Sublime replace contents of file with following code-
  3. {
    	"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
    	"font_size": 12,
    	"ignored_packages":
    	[
    	], 
    	"auto_complete_triggers": [ { "characters": "<", "selector": "text.html" }, { "characters": ".", "selector": "source.js" } ]
    }
    
  4. Now press Cmd/Ctrl+Shift+P and type Install. You will see ‘Package Control: Install Package’ in menu. Select it and press Enter. Now search for TernJS and click on it. Package will install automatically. Restart Sublime and you will see your Sublime just got smarter and it can autocomplete Meteor code for you.

loading-library-sublime

How to integrate your Meteor application with Mongo DB?
We already have Meteor code running on local server. Now let’s add DB support. Meteor comes bundled with MongoDB so you don’t need to include it again, still if you wish you can do custom setup but let’s not discuss it in this tutorial as pre bundle itself is self-sufficient to create end-end application.

  1. Lets create Fishes collection.
    Fishes = new Mongo.Collection("fishes");
    

    It creates a MongoDB collection called Fishes and creates a cache connected to server.

  2. Replace if (Meteor.isClient) with this code
    if (Meteor.isClient) {
      // This code only runs on the client
      Template.body.helpers({
        fishes: function () {
          return Fishes.find({});
        }
      });
    }
    }
  3. From terminal type
    meteor mongo
  4. meteor-mongo-terminal

  5. Now write this insert query to add a new fish

    db.fishes.insert({ text: "pygmy angelfish",imageurl:"http://www.seascapestudio.net/reference/fishes/centropyge_argi.jpg", createdAt: new Date() });
  6. check-db-for-fishes
    mongo-insert-singleton

  7. Now go to http://localhost:3000 and check if you are can see live fish coming from live data. If yes, you just added DB connectivity to your meteor application.

Now add some more blue fishes to grow your list-

db.fishes.insert({ text: "pygmy angelfish",imageurl:"http://www.seascapestudio.net/reference/fishes/centropyge_argi.jpg", createdAt: new Date() });
db.fishes.insert({ text: "blue dot grouper",imageurl:"http://www.richard-seaman.com/Underwater/Egypt/Highlights/PeacockGrouper.jpg", createdAt: new Date() });
db.fishes.insert({ text: "blue line grouper",imageurl:"http://www.aquariumdomain.com/images/fish_marine/grouper_blueline2.jpg", createdAt: new Date() });
db.fishes.insert({ text: "teira batfish",imageurl:"http://www.aquariumdomain.com/images/fish_marine/tieraBatfish8.jpg", createdAt: new Date() });
db.fishes.insert({ text: "convict blenny",imageurl:"http://www.roslyndakin.com/wp-content/uploads/2011/01/convictadult.jpg", createdAt: new Date() });

How to secure your application?
One of main concern while using JavaScript for both server and client side code is security. Try running following code from console:

Fishes.insert({ text: "Fighter",imageurl:"http://bongotimes.com/wp-content/uploads/2014/11/beautiful-fish.png", createdAt: new Date() });

From MongoDB console run

db.fishes.find()

and you will see both client and server have a new beautiful red fighter fish. If you noticed, you were able to alter DB using Javascript without authenticating with server which is a security breach. This is beacause Meteor has insecure package selected by default.

  1. To remove insecure package navigate to your project folder in Command Line /Terminal and run-
  2. meteor remove insecure
    

    meteor-remove-unsecure

  3. Now enable the accounts system and UI using following command from root directory of project-
  4. meteor add accounts-ui accounts-password

    accounts-addition
    I find package control really useful. They make your life lot easier by taking care of entire setup for useful technical modules, as in this example entire user management. Few years back implementing secured login module was estimated around 100 hours which came down to 1 minute with recent advancement in web technologies.

  5. Now add login buttons to your app. Paste following blaze template anywhere in code. I will paste it in header.
  6. {{> loginButtons}}
    
  7. Now signup for new account and run this command from console-
  8. if (! Meteor.userId()) {
          throw new Meteor.Error("not-authorized");
        }
    Fishes.insert({ text: "Fighter",imageurl:"http://bongotimes.com/wp-content/uploads/2014/11/beautiful-fish.png", createdAt: new Date() });
    

    meteor-not-authenticated

    You will notice you are not able to insert data any more. Meteor.user() will return user data to you.

We will discuss security, Blaze templates and routing in detail in next chapter of this tutorial. Till then Happy Coding!

Now you can follow this tutorial on GitHub.

References-
https://github.com/Slava/tern-meteor-sublime

Images credits-
http://bongotimes.com/