<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alif Abdullah on Medium]]></title>
        <description><![CDATA[Stories by Alif Abdullah on Medium]]></description>
        <link>https://medium.com/@alifabdullah?source=rss-3ed7faf46827------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1fCvHAPLLJnwCHC6.jpg</url>
            <title>Stories by Alif Abdullah on Medium</title>
            <link>https://medium.com/@alifabdullah?source=rss-3ed7faf46827------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 10:47:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alifabdullah/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[All About Whisker and Box Plot]]></title>
            <link>https://medium.com/@alifabdullah/all-about-whisker-and-box-plot-52eb7d444eb0?source=rss-3ed7faf46827------2</link>
            <guid isPermaLink="false">https://medium.com/p/52eb7d444eb0</guid>
            <category><![CDATA[whisker-boxplot]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[tableau-whisker-box-plot]]></category>
            <category><![CDATA[whisker]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Alif Abdullah]]></dc:creator>
            <pubDate>Wed, 26 Dec 2018 13:31:10 GMT</pubDate>
            <atom:updated>2018-12-26T13:31:10.620Z</atom:updated>
            <content:encoded><![CDATA[<p>(Noobs, I got your back!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*tn_p4LlLS_W4LMTQl35xtA.jpeg" /><figcaption>The picture was taken from Google</figcaption></figure><p>Whisker boxplot serves some sort of the same purpose as the <strong>standard deviation</strong>, but more visually. It lets us know the overall behavior or dispersion of the data without having to look into the dataset closely.</p><p>For understanding whisker boxplot, we need to be familiar with an important term widely used in statistics, that is 5-number-summary of a dataset. The 5 numbers include the minimum value, Quartiles (all 3 of them) and the Maximum value. I will explain all of them in the easiest way possible and lead you comfortably to our today’s agenda- Whisker boxplot.</p><p><strong>Maximum and Minimum value:</strong> Just the largest and the smallest value/data within a dataset.</p><p><strong>Quartiles:</strong> Quartiles have only three parts- Q1, Q2, Q3. Please note that Quarters and Quartiles are different things. Unlike Quarters, Quartiles have no Q4. However, Quartiles divide the data into four regions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*wMtClEuXUX23a9bbOviU3Q.png" /><figcaption>This picture will feel like very intimate once you complete reading the whole.</figcaption></figure><p>To plot a Whisker boxplot manually, finding all the quartiles is a must. Finding the quartiles are very easy. <strong>Q2</strong> is simply the <strong>median</strong> value of a dataset. I will demonstrate the whole process.</p><p>Finding quartiles for an <strong>ODD</strong> number of data within a dataset:</p><pre>Data: 8,9,2,10,3,5,7,12,15<br>Order: 2,3,5,7,<strong>8</strong>,9,10,12,15<br>So, <strong>Median 8 (Middle one). This is Q2. </strong></pre><pre><strong>Q1 is the median that comes from the lower half of the data.<br></strong>Now the lower half: 2,3,<strong>5</strong>,7,8<br>So, <strong>Q1 is 5</strong>.</pre><pre><strong>Q3 is the median that comes from the upper half of the data.<br></strong>Now, the upper half:<strong> </strong>8,9,<strong>10</strong>,12,15<br>So, <strong>Q3 is 10.</strong></pre><p>Finding quartiles for an <strong>EVEN</strong> number of data within a dataset:</p><pre>Data: 10,12,14,15,14,16,17,18,10,19,17,17<br>Order: 10,10,12,14,14,<strong>15,16</strong>,17,17,17,18,19</pre><pre>As the number of data is <strong>Even</strong>, so to find the median, we have to find the average of the middle two data.<br><strong>Average of 15 and 16 is 15.5. <br>So, Median is 15.5. This is Q2. </strong></pre><pre><strong>Q1 is the median that comes from the lower half of the data.<br></strong>Now the lower half: 10,10,<strong>12,14</strong>,14,15<br><strong>Average of 12 and 14 is 13. </strong><br>So, <strong>Q1 is 13</strong>.</pre><pre><strong>Q3 is the median that comes from the upper half of the data.<br></strong>Now, the upper half: 16,17,<strong>17,17</strong>,18,1<strong><br>Average of 17 and 17 is 17.</strong><br>So, <strong>Q3 is 17.</strong></pre><p>Now that we all understand 5-number-summary of data, let&#39;s go with a real-world challenge that can be easily solved and visualized with whisker boxplot using our 5-number-summary theory.</p><h3><strong>Example scenario:</strong></h3><p>Professor Jarvis took an exam on two sections (let us name them <strong>Section A</strong> and <strong>Section B</strong>) under his department with the exact same question paper. He wanted to determine which section does better in the exam than the other one. He is pretty wise, like us, wanted to visualize the performance through a <strong>whisker boxplot</strong>. Therefore, he has collected the<strong> 5-number-summary</strong> of both classes for that exam; <strong>the maximum</strong>, <strong>the quartile</strong>s and<strong> the minimum</strong> score in each class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*LIAHm725d1e1jG0WMjx8NA.png" /><figcaption>5-number-summary collected from both the classes</figcaption></figure><blockquote><strong>We need to find out which class has done better than the other, which is a very common sort of comparison we have to conduct in our daily life. We may not have to deal with the same example, but we do something very similar to this, I reckon it strongly.</strong></blockquote><p>However, to compare the overall performance of the two sections visually, we need to draw a whisker boxplot. Just plot the 5-number-summary of both classes A and B irrespective of any axes (I have chosen Y-axis here), just like the below one. Make a rectangle (or the <strong>BOX</strong>) with the quartiles, keeping the maximum and the minimum values outside of the box and join them with a straight line to Q3 and Q1 respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aTVVocHkJQ-zFs3OE-xIRA.jpeg" /></figure><p><em>(I didn’t have any arrangements while writing this story. So, tried in the simplest way possible, merely on a piece of white paper, Excuse me for that. Thanks to my beloved colleagues for managing at least a scale for me!)</em></p><h4>From the chart above, it is pretty clear that section B has done better, as the cluster is more congested and the majority of the marks (inside of the box) remains higher/at the upper side compared to section A, regardless of having the same maximum value. On the contrary, section A’s boxplot is more dispersed, which means some of the students have cut a poor figure in the exam (statistically, 25% of the students from section B scored below 24, whereas, 50% of the students in section A scored below 22).</h4><p>For the demonstration purpose, I have tried to draw it manually. However, this is a popular chart and almost all the BI tools (including Microsoft Excel) have built-in integration for whisker boxplot chart, which, to be honest, takes a few clicks to build the same chart digitally.</p><blockquote><strong>I hope all the words I have said above make sense and will help you understanding as well as utilizing the acquired knowledge for any purposes you might come across.</strong></blockquote><blockquote><strong>If you’ve liked it, please hit clap and follow me for further reads on statistics and Business Intelligence. I promise to produce better reads ahead. </strong>❤</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52eb7d444eb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Never confuse JSON and JavaScript Object ever again!]]></title>
            <link>https://medium.com/@alifabdullah/never-confuse-json-and-javascript-object-ever-again-7c32f4c071ad?source=rss-3ed7faf46827------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c32f4c071ad</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[objects]]></category>
            <dc:creator><![CDATA[Alif Abdullah]]></dc:creator>
            <pubDate>Mon, 29 Jan 2018 14:57:16 GMT</pubDate>
            <atom:updated>2018-01-29T14:57:16.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FCFP-c0vBBqpUvGfyiVesQ.jpeg" /></figure><h4>Preface</h4><p>JSON is a lightweight data-interchange format between clients, servers, and within programming languages. It is a subset of the JavaScript object and independent of any programming languages.</p><blockquote>I have seen people having troubles while parsing or working with JSON data. Often they find it difficult to distinguish JavaScript Object and JSON data. In this story, I really want to vanish all your confusions regarding these two. The literal difference is very less between this two, but it can cost you a lot if you cannot differentiate it whenever needed. I will describe step by step and precisely with proper examples.</blockquote><p>First of all, there’s nothing called JSON object, its either JSON string/text or JSON data. And yes, JavaScript Objects do exist.</p><h4>All About JavaScript Objects:</h4><p>Please give me some moments to talk about JavaScript Objects. It’s just a simple key-value pair. An example of an ideal JavaScript object is shown as follows:</p><pre>var person = {name: “Depp”, address: “earth”};</pre><pre>//<strong>Note that some key-value pairs are enclosed with curly braces</strong>. //<strong>Keys are not enclosed with quotation sign.</strong></pre><p>→ JavaScript objects <strong>do not</strong> contain single or double <strong>quote</strong> marks around the <strong>keys</strong> when <strong>no spacing</strong> is used in the key name. So, if there’s spacing in the key name, quotes are used. An Example is given below:</p><pre>var person= {first name: “Depp”, address: “earth”}; <strong>//invalid</strong></pre><pre>// <strong>To prevent this error:</strong><br>var person= {“first name”: “Depp”, &quot;address&quot;: “earth”};</pre><p>However, you cannot invoke any object’s values in a regular way if you have more than one word for the Key name. For example,</p><pre>person.first name; //This will give an error.</pre><pre>To get rid of it,<br>person[&quot;first name&quot;]; //This works fine.</pre><p>→ Added that, any language keywords, i.e. if, else, for cannot be used as JavaScript object Keys without single/double quotes too! Look below:</p><pre>var keywords= {if: “something”, for: “something1”}; <strong>//invalid     </strong>var keywords= {&quot;if&quot;: “something”, &quot;for&quot;: “something1”}; <strong>//good to go</strong></pre><p>→ Functions can be used inside JavaScript objects usually as values. It makes JS objects even more powerful.</p><pre>var person= {firstname: “Johnny”, lastname: &quot;Depp”, fullname : function(){<br>return (this.firstname+ ‘ ‘ + this.lastname);<br>}<br>};</pre><p>document.write (person.fullname()); //this is gonna work perfect.</p><h4>All About JSON</h4><p>This is the era of object-oriented programming. Objects are made with attributes. When we want to exchange the value of attributes between client-server or within languages, we must use any proper format to do so. XML has served this service for quite a long time but it had some drawbacks, i.e. overhead issues. An XML file, carrying the same amount of payload as JSON is comparatively heavier than JSON data. So, JSON is sort of preferred and widely used these days.</p><p>→ JSON is basically the “String” version of JavaScript Object. Its simply a text-based data format and single quote is not allowed for JSON.</p><p>→ 6 types of data types are allowed to contain in a JSON data/string/text.</p><ul><li>Number</li><li>String</li><li>Array</li><li>Boolean</li><li>Null</li><li>Object</li></ul><p>However, Functions cannot be included in JSON data, unlike JavaScript Objects.</p><p>→ If you just go through the following statement, you’ll get the visible differences between JSON and JavaScript Object.</p><pre>var person = {<br>&quot;name&quot;: “Depp”, <br>&quot;address&quot;: “earth”<br>};<br>//A simple JSON data where the keys are enclosed with double quotes</pre><p>→ This is so far the visible literal differences. Now I will introduce you to two methods which convert JavaScript objects into JSON string and vice versa.</p><ul><li><strong>JSON.parse();</strong> //Turns a JSON string into an JavaScript object.</li><li><strong>JSON.stringify();</strong> //Turns a JavaScript Object into JSON string/data</li></ul><p>→Please carefully follow the following statements. That’ll be all for today I believe.</p><pre>var log = { page: &quot;www.xyz.com&quot;, <br>        item: &quot;item1&quot;, <br>        action: &quot;action1&quot; };<br><br>log1 = JSON.stringify(log);<br><strong>console.log(log1);</strong></pre><pre>//Now we know, as per the JSON.stringify() function definition, it will simply turn the object log into a JSON string.</pre><pre><strong>//OUTPUT </strong><br>&#39;{ &quot;page&quot;: &quot;www.xyz.com&quot; ,&quot;item&quot;: &quot;item1&quot;,&quot;action&quot;: &quot;action1&quot; }&#39;</pre><pre>//Again,<br><strong>console.log(JSON.parse(log1));</strong></pre><pre>//This function will again turn the log1 string into a valid JavaScript object</pre><pre><strong>//OUTPUT</strong><br>Object {<br>page   : www.xyz.com,  <br>item   : &quot;item1&quot;,<br>action : &quot;action1&quot; }</pre><p>So far I have shown whatever may arise as a confusion or error while working with JSON data and JavaScript. I have illustrated with examples so that no one who is reading this, gets any trouble understanding it.</p><p><strong>If you have liked my story, please clap it and follow me to get advanced topics!</strong></p><p><strong>Have a good day :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c32f4c071ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easiest explanation of Abstract class and Interface]]></title>
            <link>https://medium.com/@alifabdullah/easiest-explanation-of-abstract-class-and-interface-280741bc2daf?source=rss-3ed7faf46827------2</link>
            <guid isPermaLink="false">https://medium.com/p/280741bc2daf</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[explain-abstract-class]]></category>
            <category><![CDATA[abstract]]></category>
            <dc:creator><![CDATA[Alif Abdullah]]></dc:creator>
            <pubDate>Mon, 22 Jan 2018 09:49:35 GMT</pubDate>
            <atom:updated>2018-01-22T12:45:59.266Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2V0XL1_yr4bvokBlg27QNA.jpeg" /></figure><blockquote>This is perhaps the most asked question in any interviews related to Software development or software quality assurance. I have seen from my experience that often many of us get confused or forget the definition and usage of abstract classes and interfaces. So, I want to make it the easiest so that no one’s having any troubles with it ever again.</blockquote><p>Abstract class and interfaces are two very vital pivots in the Object Oriented Programming concept.</p><p>At first, I will explain Abstract class and it’s usage, and later on we will move into Interfaces.</p><h3>Abstract Class:</h3><blockquote>Abstract class is nothing special to look at when you want to differentiate with a regular class. But it has got some methods which are unimplemented, or only declared, not defined. In that case, all those methods and the class itself are renamed with the “abstract” keyword.</blockquote><blockquote>An abstract class can have one or multiple number of unimplemented methods.</blockquote><blockquote>As an abstract class is not proper, or does not have ideally defined methods compared to a regular class, so abstract classes cannot be instantiated, that means we cannot create any direct objects of abstract classes.</blockquote><blockquote>The classes which Inherit/Extend this abstract class, have to implement/define <strong>all the abstract methods</strong> of the parent abstract class.</blockquote><blockquote>If any class fails to define any of the abstract methods, that class also becomes an abstract class.</blockquote><h4>Usage (An imaginary case study):</h4><p>Let us suppose, in 1995, you have designed a car class which had an additional feature-it could fly. You designed the car class very nicely, all your methods were very standard and efficient, but back then, you knew it was quite impossible to implement the carFlying() method. So, you just kept the carFlying() method blank, or unimplemented (Now you know that is an abstract method as well as class!).</p><p>Today, I want to implement that flying car that you have already designed and the technology is no longer impossible. The car I am gonna build has all the features similar to your car, and additionally it can fly. So, what can I do is I can just inherit (“extends”-for Java) your abstract class and must define/implement that carFlying() abstract method. here you go! our flying car is ready to roll.</p><p>So, whenever we have some common features or behavior among various objects, we can make a general abstract class with that feature as a method implemented. But those object might have distinct behaviors, in that case, we will declare an abstract method and will implement those abstract methods differently according to the object’s need.</p><h4>Example of Abstract Class:</h4><pre><strong>public abstract class </strong>Wrestler {<br><br>    <strong>public void </strong>paymentForWork (<strong>int </strong>hours) {<br>       System.<strong><em>out</em></strong>.println(<strong>&quot;The wrestler will make $&quot;</strong>+hours*250.00+);<br>    }<br>    <strong>public abstract void </strong>themeMusic();<br>    <strong>public abstract void </strong>finisher();<br>}</pre><p>Once again, let us consider an example, a bunch of wrestlers get the same amount of money per hour for playing. but they have different theme music and finishing fight strategy. So, we can keep the payment method same for all and have it implemented in a class named Wrestler. lets declare the themeMusic() and finisher() methods as abstract because these two have to be implemented differently for different objects in some other classes which inherits our Wrestler Abstract class.</p><pre><strong>public class </strong>Kane <strong>extends </strong>Wrestler{<br><br>    @Override<br>    <strong>public void </strong>themeMusic() {<br>        System.<strong><em>out</em></strong>.println(<strong>&quot;Kane&#39;s Intro music...&quot;</strong>);<br>    }<br>    @Override<br>    <strong>public void </strong>finisher() {<br>        System.<strong><em>out</em></strong>.println(<strong>&quot;Kane&#39;s finishing TombStone...&quot;</strong>);<br>    }<br>}</pre><p>and the main.java:</p><pre><strong>public class </strong>Main {<br>    <strong>public static void </strong>main (String [] args) {<br>        Wrestler wrestler1= <strong>new </strong>Kane();<br><br>        wrestler1.themeMusic();<br>        wrestler1.paymentForWork(5);<br>        wrestler1.finisher();<br>    }<br>}</pre><h3>Interface:</h3><blockquote>If you have gone through the upper part of this tutorial properly, understanding interface is going to be very easier for you.</blockquote><blockquote>Interface is not a class, its just interface. It has got some methods with no body inside it, just the method signature (they are basically abstract methods!), and may have some final and static variables. And, a typical class “implements” interfaces, not “extends”.</blockquote><blockquote>Multiple interfaces can be implemented (generally, inherited) at a time.</blockquote><blockquote>The classes which Inherit/implement the interfaces, must define <strong>all the abstract methods</strong> of the interface.</blockquote><blockquote>Methods inside interfaces are by default public, void and abstract.</blockquote><blockquote>interface is kind of multiple inheritance in Java programming language.</blockquote><blockquote>We cannot instantiate interfaces too just like abstract classes. Because they are incomplete entity, and should not be permitted to be realized. But sometimes an activity like instantiating can be applicable for it with the help of the anonymous inner class. That’s not our agenda here today.</blockquote><h4>Usage of Interface:</h4><p>Interfaces save coding time. It can contain some static and final variables which can be accessed globally. and some methods which are abstract and readily available for further use anytime to whoever implements the interface.</p><h4>Example of Interface:</h4><p>In the above example of Abstract class, we saw that one method was same for all which had a body inside the Abstract class and other methods were abstract. but for Interfaces, all the methods are now just signature. The class StoneCold implements Wrestler interface and define all three abstract methods of it according to its need.</p><p>This time, different wrestlers get different amount of money per hour. So, its the most convenient to put the same method as abstract and define it elsewhere according to object’s need.</p><pre><strong>public interface </strong>Wrestler {<br><br>    <strong>public  abstract void </strong>paymentForWork (<strong>int </strong>hours);<br>    <strong>public abstract void </strong>themeMusic();<br>    <strong>public abstract void </strong>finisher();<br>}</pre><p>and the following class implements the Wrestler interface.</p><pre><strong>public class </strong>StoneCold <strong>implements </strong>Wrestler {<br>    @Override<br>    <strong>public void </strong>paymentForWork(<strong>int </strong>hours) {<br>        System.<strong><em>out</em></strong>.println(<strong>&quot;Stone cold will make $&quot; </strong>+ hours*300.00);<br>    }<br>    @Override<br>    <strong>public void </strong>themeMusic() {       <br>        System.<strong><em>out</em></strong>.println(<strong>&quot;Stone cold&#39;s music playing...&quot;</strong>);<br>    }<br><br>    @Override<br>    <strong>public void </strong>finisher() {        <br>        System.<strong><em>out</em></strong>.println(<strong>&quot;Stone cold&#39;s finishing stunner...&quot;</strong>);<br>    }<br>}</pre><p>For the main.java:</p><pre><strong>public class </strong>Main {<br>    <strong>public static void </strong>main (String [] args) {<br>        Wrestler wrestler2= <strong>new </strong>StoneCold();<br><br>        wrestler2.themeMusic();<br>        wrestler2.paymentForWork(5);<br>        wrestler2.finisher();<br>    }<br>}</pre><p>For object initiating in case of Abstract class or interface, you can keep the following in mind,</p><pre>A obj= new B();<br>//where A is an interface/abstract class. B is the concrete(implements/extends “A”)class which gives it’s memory to A’s obj to have access into B class and utilize its defined methods.</pre><p>That was a lot of talk. I could not make it any shorter with proper explanation and examples. But I hope you have understood all of it and aren’t gonna forget at least in recent times! I do have all the references of information used here, knock me to get it.</p><h4>If you have liked it, Please clap it and follow me. I must come back with some more tutorials soon. Have a good day :)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=280741bc2daf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing codes / code snippets in Medium]]></title>
            <link>https://medium.com/@alifabdullah/writing-codes-code-snippets-in-medium-21799096b82b?source=rss-3ed7faf46827------2</link>
            <guid isPermaLink="false">https://medium.com/p/21799096b82b</guid>
            <category><![CDATA[writing-code]]></category>
            <category><![CDATA[code-media]]></category>
            <category><![CDATA[code-block]]></category>
            <category><![CDATA[code-snippet]]></category>
            <category><![CDATA[how-to]]></category>
            <dc:creator><![CDATA[Alif Abdullah]]></dc:creator>
            <pubDate>Wed, 10 Jan 2018 18:55:49 GMT</pubDate>
            <atom:updated>2018-01-10T18:55:49.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P7CAV7kEQ4aBBzozOCYGsA.jpeg" /></figure><p>When I started using medium for the first time, I was having the same problem that you’re going through now and reading this story.</p><p>Let us solve it together. :)</p><p>If you’re on a windows pc, just hit:</p><pre>ctrl+alt+6</pre><p>For Mac users:</p><pre>cmd+6</pre><p>If you’re on a new line and press those keys, you’ll be headed to a blank code block to write codes inside of it.</p><p>If your cursor is at the end of the line, the whole passage/line will be moved to a single code block.</p><p>However, Medium has got you some other useful keyboard shortcuts too. To see all the shortcuts in windows, press:</p><pre>ctrl+alt+?</pre><p>Again, for Mac users:</p><pre>cmd+?</pre><p><strong>Thank you for staying with me till the end. Clap, Follow, Share, and Suggest me if you have any information to make it better. Have a good day. :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21799096b82b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up private MQTT broker using Mosca in Node.js]]></title>
            <link>https://medium.com/@alifabdullah/setting-up-private-mqtt-broker-using-mosca-in-node-js-c61a3c74f952?source=rss-3ed7faf46827------2</link>
            <guid isPermaLink="false">https://medium.com/p/c61a3c74f952</guid>
            <category><![CDATA[broker]]></category>
            <category><![CDATA[private-broker]]></category>
            <category><![CDATA[npm-mosca]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mqtt]]></category>
            <dc:creator><![CDATA[Alif Abdullah]]></dc:creator>
            <pubDate>Wed, 10 Jan 2018 17:24:33 GMT</pubDate>
            <atom:updated>2018-01-10T17:24:33.749Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yEahfZkxop5pq5e2Vk3i2w.jpeg" /></figure><h3><strong>Preface</strong></h3><blockquote>Hey everyone, I welcome you all to my new tutorial on how you can set up a very basic private MQTT broker in windows PC using Node.js. The prerequisite for this lesson is you should at least be familiar with MQTT basics and Node.js. Node must be installed on your computer.</blockquote><p>While a public broker can be vulnerable to your important data or is often loaded with massive internet traffic, you can easily create your own MQTT broker in your PC. Currently, I am using Windows 10 and I am going to demonstrate how you can create a basic private MQTT broker using Node.js and npm’s Mosca API inside of your computer.</p><h3>Kernel</h3><blockquote>You must have node modules installed in your project directory. You also have to require mosca and mqtt packages globally or inside of your project folder.</blockquote><pre>#cmd inside project directory<br>npm init<br>npm install mosca --save</pre><p>which will results in creating node modules folder and package.json file inside the project directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*szmKcxPqsT50sEszG5HSFg.jpeg" /></figure><p>Just to get a glimpse of MQTT basics, a MQTT system is made of with a broker, subscribers, and publishers. So, we got to build a broker first which will relay the messages between the publishers and subscribers.</p><pre><strong>#broker.js</strong></pre><pre><strong>var</strong> mosca <strong>=</strong> require(&#39;mosca&#39;);<br><strong>var</strong> settings <strong>=</strong> {<br>		port<strong>:</strong>1883<br>		}<br><br><strong>var</strong> server <strong>=</strong> <strong>new</strong> mosca.Server(settings);<br><br>server.on(&#39;ready&#39;, <strong>function</strong>(){<br>console.log(&quot;ready&quot;);<br>});</pre><blockquote>You have to tell Mosca which port it’s going to occupy i.e. the default port 1883 is given here as a JavaScript object named <strong><em>settings,</em></strong><em> </em>and then pass this object inside the Server function to get it ready to work. Finally, the mosca server, aka, the broker is turned on with an event “ready”, followed by an anonymous callback function<em>.</em></blockquote><p>A broker is useless unless it’s listening to some publishers and rendering the messages to the subscribers. So, let’s create our publisher.js file.</p><pre><strong>#publisher.js</strong></pre><pre>var mqtt = require(&#39;mqtt&#39;);<br>var client  = mqtt.connect(&#39;mqtt://your_ip_address_of_pc&#39;);</pre><pre>client.on(&#39;connect&#39;, function () {</pre><pre>setInterval(function() {<br>client.publish(&#39;myTopic&#39;, &#39;Hello mqtt&#39;);<br>console.log(&#39;Message Sent&#39;);<br>}, 5000);</pre><pre>});</pre><blockquote>Both the publisher and subscriber have to require mqtt package in order to avail all the functions to get working with it. Connecting the broker needs a domain name or corresponding IP address (i.e. iot.eclipse.org- which is a free broker). In this case, we are using our pc as broker, so we have to put the IP address of our pc. To know your ip address, type as follows in cmd (windows), get it and put it right where ”your ip_address_of_pc” is written above:</blockquote><pre><strong>ipconfig</strong></pre><p>I suppose you already understand the latter part which demonstrates to publish a message on a particular topic. If you don’t, you can follow <a href="https://medium.com/@alifabdullah/using-mqtt-protocol-with-node-js-f0eb8065b5b6">this link </a>where I have explained the entire process in the most convenient way.</p><p>Here we go with our subscriber.js file.</p><pre><strong>#subscriber.js</strong></pre><pre>var mqtt = require(&#39;mqtt&#39;)<br>var client  = mqtt.connect(&#39;mqtt://your_ip_address_of_pc&#39;)</pre><pre>client.on(&#39;connect&#39;, function () {<br>    client.subscribe(&#39;myTopic&#39;)</pre><pre>})</pre><pre>client.on(&#39;message&#39;, function (topic, message) {</pre><pre>context = message.toString();<br>console.log(context)<br>})</pre><blockquote>There should be no ambiguity or confusion in the above code snippet. However, just because the data comes in the form of a buffer, to print it in the console as raw string, I used the <em>toString()</em> function.</blockquote><p>You can obviously put all three code snippets together in a single file, but there’s something called clean code you know! So, I ran the project in three separate files, and got a chanting output like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YZ8D4prcMA0HM-Gw4xvscg.jpeg" /></figure><p>Well, if you wish, you can now test your mqtt connection through other mqtt clients like android’s mqtt dashboard, chrome’s mqtt lens extension and so forth using your pc’s ip address as broker ip.</p><h4>I am ending it here. Feel free to ask me any queries regarding this project. If there’s any mistakes or suggestions, please let me know.</h4><h4>Have fun with your self-made private broker! :)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c61a3c74f952" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using MQTT Protocol with Node.js]]></title>
            <link>https://medium.com/@alifabdullah/using-mqtt-protocol-with-node-js-f0eb8065b5b6?source=rss-3ed7faf46827------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0eb8065b5b6</guid>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-frameworks]]></category>
            <dc:creator><![CDATA[Alif Abdullah]]></dc:creator>
            <pubDate>Mon, 08 Jan 2018 08:47:32 GMT</pubDate>
            <atom:updated>2018-01-30T14:26:15.609Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2man_pULyPGcWX9nWMk3Wg.jpeg" /></figure><p><strong>Message Queue Telemetry Transport</strong>, aka, MQTT is one of the most widely used lightweight protocol to carry minimal data overhead. It’s a hot cake for the developers who are specially working with Internet of Things (IoT).</p><p>As an IoT developer, I came across different projects or applications that need to send smaller chunks of data in a very fraction of time. This article is intended for the developers or users who have at least a minimum familiarity with MQTT (I wish to compose another story on the basics and evolution of MQTT!).</p><p>Using MQTT protocol in Node.js has been easier than ever due to the MQTT API provided by npm. Now we can easily implement MQTT protocol in our Node.js project. I am going to demonstrate a basic MQTT establishment in the following code with proper comments.</p><pre><strong>const</strong> mqtt <strong>=</strong> require (&#39;mqtt&#39;);<br><strong>var</strong> client  <strong>=</strong> mqtt.connect(&#39;mqtt://iot.eclipse.org&#39;);</pre><blockquote>In the code above, I have required the MQTT API in an object called mqtt. Using the mqtt object, I have called the connect function and passed the brokers’s URL as argument.</blockquote><p>It’s a good practice to use subscribe and publish functions separately.</p><pre>client.on(&#39;connect&#39;, <strong>function</strong> () {<br>  client.subscribe(&#39;Topic07&#39;);</pre><pre>  console.log(&#39;client has subscribed successfully&#39;);<br>});</pre><blockquote>We created a client object which invokes the on() method. The on method took two parameters, one is the connect event and another is a callback function to subscribe to a Topic. For our better understanding, I have asked for a console view on success.</blockquote><pre>client.on(&#39;connect&#39;, <strong>function</strong>(){<br>  setInterval(<strong>function</strong>(){client.publish(&#39;Topic07&#39;,&#39;cricket&#39;);},3000); <br>});</pre><p>This is pretty much similar to the (could be even same except the keyword “publish” only!) previous chuck of code, but you are clever enough now to understand that this is for the publishing purpose now. Yet, I am here to clarify! Please have a look to the below paragraph.</p><blockquote>The code above publishes a message, i.e. “cricket” to the topic “Topic07” at a 3 seconds time interval. I could use it without the setInterval method, but that would have stopped just after sending a single message for once.</blockquote><pre>client.on(&#39;message&#39;, <strong>function</strong> (topic, message){<br>  console.log(message.toString()); <em>//if toString is not given, the message comes as buffer</em><br>});</pre><blockquote>You are supposed to receive some messages published to the topics that you have subscribed to.</blockquote><blockquote>The message usually arrives as buffer, so I had to convert it to string data type.</blockquote><p>Well, this part is one of the most used parts in MQTT protocol. Basically, one has to spend most of the time in this part while working with MQTT.</p><p>Wherever the device might be subscribed to, all the received messages hit right in this section of program. You are the creator and you decide what you’re gonna do with the received messages, you may even start your car with a message, the same you can start your toaster to have your meal.</p><p><strong><em>You can very easily test and play with MQTT data transmission with Free mobile MQTT client or Google Chrome’s MQTT Lens client. That would be fun for newbies!</em></strong></p><p>Hereby, I finish this small and simplest section of basic MQTT connection in Node.js program. I hope this might be helpful for the beginners. Feel free to suggest any improvements. Have a good day :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0eb8065b5b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>