<?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 Rahul on Medium]]></title>
        <description><![CDATA[Stories by Rahul on Medium]]></description>
        <link>https://medium.com/@lethalbrains?source=rss-a05b36627641------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*a50DziYaU3tfJ6kuapFAzg.jpeg</url>
            <title>Stories by Rahul on Medium</title>
            <link>https://medium.com/@lethalbrains?source=rss-a05b36627641------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 15:38:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lethalbrains/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[Learn ML Algorithms by coding: Decision Trees]]></title>
            <link>https://medium.com/lethal-brains/learn-ml-algorithms-by-coding-decision-trees-439ac503c9a4?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/439ac503c9a4</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Wed, 08 Aug 2018 10:35:36 GMT</pubDate>
            <atom:updated>2018-08-08T14:38:45.618Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7aMn7NRr0PhbW6f3O6SRPQ.png" /></figure><h4>Introduction</h4><p>The intention of this series, <em>Learn ML Algorithms by coding, is to understand the </em>intricacies of popular machine learning algorithms by coding them from scratch. You may wonder why am I doing this, when I can write the most popular 3 lines from <a href="http://scikit-learn.org/stable/">Scikit-learn</a> - instantiate, fit and predict for any ML algorithm.</p><p>The idea here is not to create a competing implementation, rather to understand the building blocks behind each machine learning algorithm.</p><blockquote><strong>Since the focus is on learning the algorithms, efficiency is not given priority. At places, I have even traded off efficiency for explainability</strong></blockquote><p><em>In a galaxy far far away….</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*E4KzSbJiT2T7of2weOU9xw.gif" /><figcaption>Groot: I am Groot</figcaption></figure><blockquote><strong>Me</strong>: Hello Groot. Yes, been a long time. How are you?<br><strong>Groot</strong>: I am Groot. <br><strong>Me</strong>: I had been very busy, been working on multiple projects. <br><strong>Groot</strong>: I am Groot.<br><strong>Me</strong>: How do you know that I was working on Machine Learning projects? It was supposed to be top secret. <br><strong>Groot</strong>: I am Groot.<br><strong>Me</strong>: Damn you Star Lord! Such a blabbermouth. <br><strong>Groot</strong>: I am Groot.<br><strong>Me</strong>: Oh! We implemented multiple algorithms. Logistic Regression, Light GBM, XGBoost, Decision Trees, Random Fore…<br><strong>Groot</strong>: I AM GROOT. I AM GROOT.<br><strong>Me</strong>: Come on! Just because it says decision <strong>trees</strong>, doesn’t mean it has any relation with you. And you want me to teach you Decision trees? No way!!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*CAxzGxh0cLkswoIEe6n5Fg.gif" /><figcaption>Groot: I am Groot</figcaption></figure><blockquote><strong>Me</strong>: Oh no! Not that face. Ok. I will do it but lets learn by building our own decision tree. <br><strong>Me</strong>: I hope you know the basic data pre processing and feature engineering, if not, read through <a href="https://www.kaggle.com/startupsci/titanic-data-science-solutions"><strong>this kernel</strong></a>. Its very extensive.</blockquote><h4>Dataset</h4><p>Let us use the famous titanic dataset from kaggle. As I mentioned, we are not going to discuss on pre processing and feature engineering. So I have uploaded a preprocessed dataset <a href="https://github.com/lethalbrains/learn_ml_by_coding/tree/master/data">here</a>.</p><p>We will be implementing the decision tree for a binary classification problem(i.e. the target attribute is a category of two classes). Titanic dataset is a classic example, the Survived column is 1 for people who survived, 0 otherwise. Now let us build us a Decision Tree.</p><h4>The Crude way</h4><p>Let us build a crude decision tree which predicts the outcome in probabilities (In Scikit learn, predict method returns the predicted classes while the predict_proba method returns the predicted probabilities. Lets implement the later). What do you think would be most simple and easy way to predict the probabilities?</p><blockquote><strong>Groot</strong>: I am Groot<br><strong>Me</strong>: Exactly, the probabilities based on the frequencies of the classes (i.e. in a dataset with 100 rows, if 0 occurs 70 times and 1 occurs 30 times, the respective probability would be 0.7 and 0.3 respectively)</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c649fe4877dd9b986d59efd89a2031c/href">https://medium.com/media/9c649fe4877dd9b986d59efd89a2031c/href</a></iframe><p>I have touched it up a little bit. The fit method accepts a dataframe(data) and a string for the target attribute(target). Both of the them are then assigned to the object. The independent attribute names are derived and assigned to the object.</p><p>The predict method iterates though the test data that is passed and returns the probability based on frequency, Hence at this point, the output of all the rows will have the same values. __flow_data_thru_tree achieves the above on a row level. Lets execute this code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*UC-s-sTce71Xzy8ooL2SrA.png" /></figure><p>As expected, we get the probabilities as 0.62 and 0.38. But this prediction is not of much use. In order to evolve our implementation, we need to understand what a decision tree is.</p><h4>What is a Decision Tree?</h4><blockquote>Decision Tree is a tree based algorithm providing a multi-level conditional architecture for predictive analysis by evaluating the incremental information gain.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*MN7J7uKSgYs5i5G_jOQ7MQ.gif" /></figure><p>Ok, relax. Let me dial it down. Think of the decision tree as a tree filled with if-else conditions. Most efficient condition on the top and it gradually downgrades as we descend(in most cases). Let us see an example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*h36eNCdykNQlgaksjloVcQ.png" /></figure><p>In this tree, the top node has a condition to check whether the sex of the passenger is male. So the condition on the root node of the tree is sex = male, if yes, the tree traversal is to the left else we slide to the right.</p><p>In the next level, a different criteria on a different feature is established to distinguish the data. Lets look at the tree from an implementation aspect. List down the components of a tree.</p><blockquote><strong>Groot</strong>: I am Groot<br><em>(Translation below)</em></blockquote><ul><li>A tree has a root node.</li><li>A node can have left branch and right branch.</li><li>Lowest layer nodes do not have any branches</li></ul><p>Good observation! The nodes with no branches are called as <strong>leaf nodes </strong>and <em>the leaf nodes are decisive</em>. Programmatically, we will not be implementing branches as a separate data structure, since the branches can be represented as trees themselves, we can recursively build Decision trees. The image below represents a branch taken from the larger tree shown above but, when isolated, it is a tree of its own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*aLCBlOK6GFIQtmTQDGWxlA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/653be0c275a90a1f9f4dbd78da2489cc/href">https://medium.com/media/653be0c275a90a1f9f4dbd78da2489cc/href</a></iframe><p>To implement branches, we begin by adding a constructor to the class and initialize the left and right branches to None. We are not intentionally initializing them with a Decision tree object because the decision of having branches for a node can be determined only by a split which brings us to the most important question in a decision tree</p><blockquote>How is an optimal split made in the Decision Tree?</blockquote><h4>Finding the optimal split</h4><p>Now would be the right time to introduce two important concepts in Decision Trees - <strong>Impurity</strong> and <strong>Information Gain</strong>. In a binary classification problem, an ideal split is the condition which can divide the data such that the branches are homogeneous.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*I9iLHhQT4GXJjRR6WGIPWA.png" /></figure><p>In the example on the left, the ideal split on the root node can be done with the criteria Independent&lt;=5. With this condition, the left branch would have all the 0s and the right branch would have all the 1s. Our leaf nodes would be pure. But in a realistic use case, it is not as straight forward as this. The dataset is filled with features and each feature can generate n number of criteria.</p><p>Hence a split should be capable of decreasing the impurity in the child node with respect to the parent node and the quantitative decrease of impurity in the child node is called the Information Gain.</p><p>We need to have a unit of measure to quantify the impurity and in the information gain at each level. Common measures of impurity are</p><ul><li>Gini</li><li>Cross Entropy</li><li>Misclassification</li></ul><p>For our implementation, lets us pick up <strong>Gini</strong>. Following are the formula for impurity and information gain when using Gini index</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*2bI1Uxv3bBzR9Nkg_PLiaw.png" /></figure><p>where k is number of classes in the target attribute and pis the probability of the class at the node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*kvIc3ZwDyYab3GOOKY5lHw.png" /></figure><p>where k is number of classes in the target attribute, r is the number of rows in the node and n is the number of rows in the dataset.</p><p>Lets dive in and implement Impurity and Information Gain</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf1ca79014c563a3087638fef5ced48e/href">https://medium.com/media/cf1ca79014c563a3087638fef5ced48e/href</a></iframe><p>Given a feature(target) or a section of it, this method finds the probability of multiple classes. Since we are working on a Binary classification problem, we would get only two probabilities and since their summation is 1. So p_i * (1 — p_i) would be the same for both classes, hence the * 2.</p><p>In order to find the best split, we need to get the best split in each features and use the one with the most information gain. First let us see the implementation for a single feature</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6c8bc6fdc58d520f604d8a3a15f7fca/href">https://medium.com/media/a6c8bc6fdc58d520f604d8a3a15f7fca/href</a></iframe><p>Here, given a feature, all the unique values are separated and for each of those values, a split is made in such a way the data is either less than or equal to the value or greater than the value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*I9iLHhQT4GXJjRR6WGIPWA.png" /></figure><p>In this scenario, if I make a split on independent &lt;= 5, all the rows with value less than 5 in the independent feature would become “left” branch and others would go to the “right” branch.</p><p>Then we can calculate the impurity for the left branch and the right branch. Once we have both, we can calculate the information gain by using __calculate_information_gain method which is a straight forward implementation of the formula above.</p><p>This is done for all the unique values in the feature and split with highest information is returned by the method.</p><p>We must then repeat this for all the features, to find the best split across all of them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc553e1f855345ee4d79a5478406f380/href">https://medium.com/media/cc553e1f855345ee4d79a5478406f380/href</a></iframe><p>Now that we have identified the split, let us create the branches.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a54285916cd5abea0eaecb38d66c664e/href">https://medium.com/media/a54285916cd5abea0eaecb38d66c664e/href</a></iframe><p>In this method, we have instantiated a decision tree for both the left and the right branch. We pass in the rows with values less than the criteria to the left branch and greater than the criteria to the right branch. Invoking this method from fit would recursively create the branches and with that we have built the tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*bLcakFeTDosnqMHXzBUx0w.gif" /><figcaption>Groot: I am Groot</figcaption></figure><p>Not so fast, Groot. We are not done yet. Now we come to the point where we must ask the second most important question in a decision tree.</p><blockquote>When do we stop splitting?</blockquote><p>Before understanding “when”, let us discuss on “why”. The logical reason to stop splitting would be when the data at the node is homogeneous. Another point to note is that Decision Trees have a major disadvantage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*3piQmezx-m3sbdVlZPONPA.gif" /></figure><blockquote>Decision trees are likely to overfit noisy data. The probability of overfitting on noise increases as a tree gets deeper.</blockquote><p>One way to avoid this is by predefining the maximum depth of the tree when initializing the Decision tree. There are also other ways of preventing overfitting but for this implementation we can work on just the max depth. We can add max_depth attribute to our class and we can increment the depth as we create branches as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2021076e6ff78841928c902b81e60475/href">https://medium.com/media/2021076e6ff78841928c902b81e60475/href</a></iframe><p>We have finally created our decision tree, now let us try and fit our training data. Hope its not a bumpy ride.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*RLFBu6q50k78VLr8ZREKXA.gif" /><figcaption>Groot: I am Groot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*IAahiTSoUEAkQUbQBgVXgQ.png" /></figure><p>We are able to successfully fit our training data. Now the next step is to predict the probabilities for the test data.</p><p>I am adding two more methods is_leaf_node and probability which can be accessed as properties using the property decorator. You can read more about it <a href="https://www.programiz.com/python-programming/property">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46de0fbd8b64d48b5b783b18c4d17075/href">https://medium.com/media/46de0fbd8b64d48b5b783b18c4d17075/href</a></iframe><p>In order to predict the probabilities of the test data, let us create two function, one to iterate through each row while the other to traverse the tree for a row and find the prediction. The latter method invokes iteratively till it reaches a leaf node.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3f7232f8834e782b30076558829135e/href">https://medium.com/media/f3f7232f8834e782b30076558829135e/href</a></iframe><p>Now for the judgement time, lets try to predict the probabilities of survival in our test data by traversing through the tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*YI_HgyxIlLZ3prTVAFcYpg.png" /></figure><p>After converting the probabilities into actual classes, following is the prediction outcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*h_V0Vs-eQzoID4L-DUyy8w.png" /></figure><p>Lets plug them all together</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*3M28hAXVBRppfXXF-lEMVg.gif" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83478808947f15671e35d5341a711a27/href">https://medium.com/media/83478808947f15671e35d5341a711a27/href</a></iframe><blockquote><strong>Me</strong>: Not a bad start to Machine learning, what do you say, Groot.<br><strong>Groot</strong>: I am Groot.<br><strong>Me</strong>: I am not exactly sure what you mean.<br><strong>Groot</strong>: I am GROOT.<br><strong>Me</strong>: Still nothing. Hey Rocket, could you help me out with the translation.<br><strong>Groot</strong>: I am GROOT.<br><strong>Rocket</strong>: He says ‘That was frickin Good’</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*rzzjzu0yKn06FiS1WCDpkg.gif" /></figure><p>There are lot of improvements that are required to this implementation to make it real time usable but I am not planning on doing that.</p><p>I have added few validations and have uploaded the <a href="https://github.com/lethalbrains/learn_ml_by_coding">code in github</a>. Feel free to send in pull requests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=439ac503c9a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/learn-ml-algorithms-by-coding-decision-trees-439ac503c9a4">Learn ML Algorithms by coding: Decision Trees</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dial D for Docker: Part 3 - Interacting with the containers]]></title>
            <link>https://medium.com/lethal-brains/https-lethalbrains-com-dial-d-for-docker-part-3-interacting-with-the-containers-e3afff3fc58?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3afff3fc58</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Thu, 10 Aug 2017 19:02:26 GMT</pubDate>
            <atom:updated>2017-08-11T07:28:48.183Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*ujNcjtv_swH8_Q_jsc3iVA.jpeg" /></figure><p>In the <a href="https://lethalbrains.com/dial-d-for-docker-part-2-1c8dc21cbce4">last blog on Dial D for Docker</a>, we understood what are docker images and containers, how to pull, run, publish, start, stop, inspect and remove them. This time lets invest our time in interacting with the containers.</p><p>Running a nginx server with default page at port 80 or a mongo server without possible CLI shell is not something that would prove productive to any docker user. Unless we find ways to ssh or a way to interact with the containers, these running containers are like a broken watch showing the right time twice a day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*lUkF1qIM6LtQcGotDyY9Ug.gif" /><figcaption>a non interactive container</figcaption></figure><p>We do not need to ssh into the containers as docker provides multiple ways to interact with them.</p><h4>Running a container in an interactive mode</h4><p>To run a container in an interactive mode we need to take a closer look into options that docker provides for run</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U8PMI1VKAnYXhiII08C3FQ.jpeg" /></figure><p>Ooooo! Thats a lot of options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*bW8hSvICKM8KpPbqExGnKQ.gif" /></figure><p>Understandable! Take a look at options -i and -t , option i provides an open STDIN connection while option t provides a pseudo TTY.</p><p>Let us use these to run an ubuntu container</p><blockquote>docker container run --name local_ubuntu -it ubuntu</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tnNjTjCAO962YcCjmsFZvA.png" /></figure><p>There is quite a lot happening here. Lets take one at a time. Executing the above command, gets us into a shell with the prompt root@990a2085f4a4.You are not the root of the host machine but root of the container and unique id following that is the container id.</p><p>After that as you can see, I created a folder area51 in the home folder and checked the processes that were running before exiting the interactive mode. Immediately after that, if you do a docker container ls , the container named local_ubuntu will not be listed down but an -a listing will provide you that.</p><p>This is because, when you run a docker container, you ask it to run a particular command(in our case though we did not mention it explicitly, ubuntu ran bash command by default. You can see the command in the ls output). Once that process corresponding to the command is stopped, the container is also stopped. In our case, when we exited the bash, we stopped the container.</p><p>So you might wonder how do I restart the same container, will running the above command do it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*dg-YqM_tP8HsvJC-OZqqTA.gif" /></figure><p>No. It wont. Running the command would create a new container from the image. But lets confirm it(make sure you change the container name else you will end up getting an error).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CnNGrWR8-dtWSyiVVem8cw.png" /></figure><p>As you can notice, the container has a different id and our area51 folder is missing.</p><p>So in order to start an existing container in interactive mode, we can use the following command</p><blockquote>docker container start -ai local_ubuntu</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLIE9SHIQ6Z7bf_fAI4Opg.png" /></figure><p>We were able to successfully run the same container(area51 exists), but once again the container is stopped as soon as we exit the bash. So how can we interact with a running container?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*t2yin79vHyc8AGdshNjSug.gif" /></figure><h4>Interacting with a running container</h4><p>We can interact with a running container using the exec command and our sweet little -it options. Lets see this with an example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M_iSD8TixhnZCKwKuKuMPA.png" /></figure><p>So we start our ubuntu container using the docker start command and the ls lists the local_ubuntu as a running container. Then comes our magical command</p><blockquote>docker container exec -it local_ubuntu bash</blockquote><p><em>This command executes the bash command with interactive tty options in the local_ubuntu container</em>. Area51 still exists. I also play around with python a little bit. <em>By the way, I love this line in The Zen of Python</em></p><blockquote>Special cases aren’t special enough to break the rules.</blockquote><p>Then I exit python and the bash. But our container is still running unlike the run command because the exec command creates a separate process for the interactive mode which is terminated on exiting while the actual process is still running.</p><p>With this, I am wrapping up this part. Play around with the interactive mode. Try running a nginx container after modifying the nginx.conf file, you can run a database container(mysql, mongo) and use exec to access the shell.</p><p>In the coming segments, I will focus more on docker networks, docker images and docker hub.</p><p>This article is a part of docker series <strong>Dial D for Docker</strong>. You can find the previous article in the following link</p><ul><li><a href="https://lethalbrains.com/dial-d-for-docker-part-2-1c8dc21cbce4">Dial D for Docker: Part 2 - Images and Containers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3afff3fc58" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/https-lethalbrains-com-dial-d-for-docker-part-3-interacting-with-the-containers-e3afff3fc58">Dial D for Docker: Part 3 - Interacting with the containers</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dial D for Docker: Part 2 - Images and Containers]]></title>
            <link>https://medium.com/lethal-brains/dial-d-for-docker-part-2-1c8dc21cbce4?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c8dc21cbce4</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Thu, 03 Aug 2017 17:18:50 GMT</pubDate>
            <atom:updated>2017-08-10T19:04:54.792Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lu5prM28fxIlbHmjPT8VIg.jpeg" /></figure><p>In the last segment on <a href="https://lethalbrains.com/dial-d-for-docker-part-1-235079a61e35">Dial D for Docker</a>, we had a small introduction about docker and we saw about the installations and command structures. In this part, lets look in depth into docker images and containers.</p><h4><strong>What are docker images and containers</strong></h4><p>If you are a programmer, I can provide you a straight forward analogy. An image is comparable to a <em>class</em> while a container to an <em>object</em>. You can instantiate n number of objects from your class similarly you can run n number of containers from your image.</p><p>If you are a dev-ops personnel or a non programmer, you can associate an image to a <em>blueprint </em>or a <em>recipe</em> and the container as the <em>buildings </em>built from the blueprint or the delicious pizza prepared from the recipe. Once you have your blueprint or recipe you can built as many buildings as you want from your blueprint or you can cook pizza for an entire party from the recipe. Likewise, you can run a number of containers from an image.</p><h4>Breaking down the Nginx installation</h4><p>We installed and ran nginx in the <a href="https://lethalbrains.com/dial-d-for-docker-part-1-235079a61e35">last part of the blog</a> using the command docker container run --publish 80:80 --detach nginx<em>. </em>This command downloaded an image, invoked a container from the image, ran the image in the background while associating port 80 of the machine with the port 80 of the container.</p><p>Now lets do it an other way. As we discussed, containers are invoked from an image. So in order to run an nginx container, we require the Nginx image. So pull one from the dockerhub(<em>more about dockerhub later</em>) using the command</p><blockquote>docker image pull nginx</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1YysfQHp1J3j-h8hiG3hw.png" /></figure><p>Once it is downloaded, you can check the downloaded docker-image using the command</p><blockquote>docker image ls</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Htzozxslru_GUTKw9j8aAw.png" /></figure><p>As you can see in the console(<em>Using default tag: latest</em>), by default docker downloads the latest version of the image. If you want to download an older version of the image, you can add the appropriate tag to the command as such</p><blockquote>docker image pull nginx:1.12.1</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RRxv6rYOz5K_oEBhzbvenQ.png" /></figure><p>Now you can see that there exists two nginx images, one with the tag - latest and another with the tag - 1.12.1</p><p>Now that we have downloaded our image, we can run the container using our same old command</p><blockquote><em>docker container run --publish 80:80 -- detach nginx</em></blockquote><p>The difference in both the cases while running this command is that first time it downloaded the nginx from dockerhub but this time it used the already downloaded image.</p><h4>Options: publish and detach</h4><p>In our execution we saw 2 options passed to the run command, publish and detach. Publish binds the port within the container to the port of machine running container. Lets see what happens if we run without the publish option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FawWFZKGfQAM8PvGGglrHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FroIxLXPECTqNk-YsT21Gw.png" /></figure><p>As you can see from the images, though the container is created and its running, the ports are not bound and hence we are not able to access the nginx. In the pics below, you can notice the newly invoked container’s port 80 is bound to port 7777 of my machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5chwYjblfJ-WKL00aRXJQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1-CUcO6xmDD-YvLqiu2DkA.png" /></figure><p>Detach option on the other hand helps us to run the container in the background.</p><h4>Commands: ls and ls -a</h4><p>Docker has used unix nomenclature for listing the containers and images. So use the following command to list all the containers that are running on the maching</p><blockquote>docker container ls</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eks_f1H6tAw1XemcgnDJ_w.png" /></figure><p>You can add the option `<strong>a`</strong> to the same command to also list the containers were created but are not currently running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oaJi8D8eB_29csEv_O7eDg.png" /></figure><h4>Providing names to the containers</h4><p>If you had noticed in the above pictures, each container is given a random name (youthful_jones and blissful_benz in our case). If a container is created without a name, docker creates a name by concatenating a random adjective with surname of famous scientists.</p><p>You can find the entire list of adjectives and the Scientist’s names <a href="https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go">here</a>.</p><p>We can also add our own names to the containers by using the option name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_3cF8oAuXvvPsNBg8dYEQ.png" /></figure><h4>Commands: start, stop and restart</h4><p>As the name suggests you can start, stop and restart a container using the respective commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mEPkY6OOhHy2OTEey-Lang.png" /></figure><h4>Commands: inspect, stats &amp; top</h4><p>Docker inspect command provides an detailed inspection report about the container</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f1c5dcgZ2QGpnB-SBGvzGw.png" /></figure><p>stats command provides a live stats about the container. This includes CPU usage, Memory usage, IO, process ID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_qD2NnBAO7y-MNASfFRzg.png" /></figure><p>top command lists the processes running in the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2E88IdsreJH4wPBv6-j8og.png" /></figure><p>With this let us end this part of Dial D for Docker. <em>Play around with the commands</em>. Pull and run various kinds of containers(Node.js, MongoDB, MySql, Ubuntu, etc).</p><p>In the next segment, lets see how to interact within the docker container from the CLI.</p><p>This article is a part of docker series <strong>Dial D for Docker</strong>. You can find the previous and next articles in the following links</p><ul><li><a href="https://lethalbrains.com/dial-d-for-docker-part-1-235079a61e35">Dial D for Docker: Part 1 - Installation and commands</a></li><li><a href="https://lethalbrains.com/https-lethalbrains-com-dial-d-for-docker-part-3-interacting-with-the-containers-e3afff3fc58">Dial D for Docker: Part 3 - Interacting with the containers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c8dc21cbce4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/dial-d-for-docker-part-2-1c8dc21cbce4">Dial D for Docker: Part 2 - Images and Containers</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Node.js and MongoDB application in SAP Cloud Platform]]></title>
            <link>https://medium.com/lethal-brains/deploying-a-node-js-and-mongodb-application-in-sap-cloud-platform-6920ad3ca98a?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/6920ad3ca98a</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cloud-foundry]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Thu, 13 Jul 2017 22:20:59 GMT</pubDate>
            <atom:updated>2019-01-17T05:25:25.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5x8oZkR_z8wTfTUnI5gLoQ.png" /></figure><p>SAP has been lately very interested and invested in cloud game with the introduction of SAP Cloud Platform - SCP(earlier called as HANA Cloud Platform - HCP). With the likes of Google, Amazon, Microsoft battling in the cloud services/platform arena, it isn’t going to be a cakewalk for anyone stepping into it but SAP is up for it.</p><p>SAP is known for their proprietary softwares but over the past few years they are proactively embracing open source technologies and softwares. Once such effort is to invest heavily on building platforms to run applications built in Go, Node.js, Python, Ruby supported by various open source backends like PostgreSQL, MongoDB, Redis.</p><p>You might be wondering what is Cloud Foundry and how does it fits into this?</p><h4>What is Cloud Foundry?</h4><p>As per the official docs</p><blockquote>It is an open source platform that you can deploy to run your apps on your own computing infrastructure, or deploy on an IaaS like AWS, vSphere, or OpenStack. You can also use a PaaS deployed by a <strong>commercial CF</strong> <strong>cloud</strong> <strong>provider</strong>. A broad community contributes to and supports Cloud Foundry.</blockquote><p>SAP is one such “commercial CF cloud provider”. Let us take a small history lessons to understand this. Initially all the software companies had their own servers. This means the onus of hardware, storage, virtualization, operating system maintenance, scaling, availability, durability etc was with the internal IT team.</p><p>The world started moving towards the cloud and IAAS providers like AWS shared the burden with the companies by taking the responsibility of hardware, storage, virtualization, scaling, availability on them.</p><p>Then came IAAS providers like Heroku who told us - we will take care of everything while you can focus on your core application. All dependencies and monitoring can be fulfilled using services and add-ons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uRe-S0bawivAnx0dioeFpA.png" /></figure><p>Lets say, you want to provide all the members of your organization with a controlled environment like Heroku. How can do that? Thats where Cloud foundry comes in. Cloud foundry provides you with the platform that can be installed in your local machines, local data centers or even in IAAS providers like AWS and provide access to your employees who can deploy the application they want.</p><p>This is what SAP does to provide a platform for open source technologies using Cloud Foundry in SCP.</p><p>Enough with all the theory, let us start with SCP and deploy our Node.js application with MongoDB backend on SCP.</p><h4>Registration, Cockpit and Environments</h4><p><a href="https://account.hanatrial.ondemand.com/">Register</a> a trial account in SCP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZT2OGUllbZ03VLuM0e2Pyg.png" /></figure><p>Once registered, you will be taken to the landing page of the cockpit containing the environments. SCP has two different types of environments</p><ul><li>Neo Environment</li><li>Cloud Foundry Environment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BpAnZaX3pxq9rtcsPR_e3Q.png" /></figure><p>Neo environments are SAP owned infrastructure and is inclined towards SAP technologies. You have access to tonnes of SCP components like SCI, IOT, Hana DB, Machine learning, Streaming services, YAAS etc</p><p>Meanwhile, Cloud Foundry environments are hosted in AWS and Azure(N. Virginia and Frankfurt - AWS and California - Azure)</p><p>Click on the “Start Cloud Foundry Trail” button. It would take a few minutes to set up the account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UhCSNe2IWVedcXRXmnuKPw.png" /></figure><p>Once completed click on the “Go to Space” button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*Bs7c6TWLufHJpidWpBrBWA.png" /></figure><h4>Creating MongoDB service</h4><p>There would be a space with name dev created with 1GB of memory ready for consumption. Go into the dev space. Now on the left menu bar, go to Services &gt; Service Marketplace. There you can find the services accessible to you and one of them is MongoDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xd1FXpZ1g6eVNXutOjqSYQ.png" /></figure><p>Click on MongoDB and and click on “New Instance”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xp7fIrtJgYFr5jaEEQC1DQ.png" /></figure><p>Keep clicking next till the final screen and in the final screen enter a name for the MongoDB instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BgKCdwb8T07TzgCUHsNChQ.png" /></figure><p>Once created, click on the dashboard button(first in the actions tab) to view the dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zATkLuvT9MRHPc4Z6VpQgA.png" /></figure><p>The dashboard consists of service, container details along with credentials, endpoints, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OEPhjrr6-IBjfLrWih9gHg.png" /></figure><p><strong>Installing Cloud Foundry Command Line Interface (CLI):</strong></p><p>Now that your database is created, lets install Cloud Foundry CLI in your machine. Install Cloud Foundry on your respective OS as mentioned in this <a href="https://docs.cloudfoundry.org/cf-cli/install-go-cli.html">url</a>. Once installed type cf command to check the installation.</p><p>You need to set an API endpoint for the Cloud Foundry CLI. Select your endpoint based on your datacenter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GM6FxMjj8T-9tjp78IFWbQ.png" /></figure><p>Once selected, use the following commands to register the endpoint locally and login to your account from the CLI.</p><pre>cf api &lt;api_endpoint&gt;<br>cf login</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1oSc9u6miCesN4KIk2Myvg.png" /></figure><p>Now that we have logged in, lets check the services and buildpacks that are available for us using the commands</p><pre>cf buildpacks<br>cf services</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIdbEu9hJiawnwznMYKwSg.png" /></figure><p>In the services, we can see the mongoDB service that was created by us earlier.</p><h4>Node.js Application and manifest.yml file</h4><p>Lets create a very simple Node.js application. Its an express app which logs the process.env details in the log. Following is the code for the Node.js application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PrKLUMF_ePwbt918uf3avg.png" /></figure><p>Apart from the default index.js and package.json files, you can see a manifest.yml file. This file consists of application configuration like name, memory allocated, instances count and a lot more. You can find more about it <a href="https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html">here</a>.</p><h4>Pushing and logging</h4><p>Once all the files are created, we are ready to deploy the application. Deployment and logging can be performed by the following commands respectively</p><pre>cf push <br>cf log &lt;application name mentioned in the manifest file&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJZaVDHFNuejDBYW6SLhog.png" /></figure><p>As mentioned earlier, cloud foundry lets you focus on just your application. The idea behind cf push is that when you execute the command, the entire code in the current folder is pushed to cloud foundry(internally, the code is stored in git repositories). Once the code is pushed, the platform determines the type of project and installs the necessary buildpack, processes the manifest file for application configuration, services and deploys the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sZRpfXxmeBFwtvY_IPkf8A.png" /></figure><p>I ran my push and log command side by side. Though the application was build successfully, cf failed to start the application. If you check the log file, it prompts “missing script: start”. Cloud foundry expects a start script in the package.json file for node.js applications. Lets add the following to the package.json’s script attribute</p><pre>&quot;start&quot;: &quot;node index.js&quot;</pre><p>Execute the cf push command in the repository folder again and now you can see the application successfully deployed and we have the environment variables printed out in the logs. Lets take it and beautify it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUWbCCGAI_fx7FnjXXzxew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OVmoQ17m22ukBYOl-d7EbQ.png" /></figure><h4>MongoDB Integration</h4><p>Now that our application is running, lets integrate it with the MongoDB instance we created. In order to make the MongoDB instance accessible to the Node.js environment, add the following lines to the manifest.yml file.</p><pre>services:<br>  - Test_DB</pre><p>Test_DB is the name that was provided to the MongoDB instance when it was created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GZE3VTQq4X9bX2gr6pMsuQ.png" /></figure><p>Any services from the list earlier can be created and added here to have it accessible to the Node.js environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDWCx15Vzy2pFIE7EsnmAw.png" /></figure><p>Check the environment variables to see a new attribute “VCAP_SERVICES” added since the last time. This contains MongoDB credential details that can be used by the Node.js application.</p><h4>Final Application</h4><p>To test the integration, I have written a small application which captures each visiting IP address and stores it in the database(using the above credentials) and displays the visitors list to the end user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*38G_SP1NDs8aLv5ThHo6AA.png" /></figure><p>Tada! We have successfully deployed a Node.js and MongoDB application in SAP Cloud Platform with Cloud Foundry.</p><p>I have just scratched the surface wrt Cloud Foundry. It has a plethora of features and capabilities. I am planning to explore more and will keep everyone posted when I find something interesting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6920ad3ca98a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/deploying-a-node-js-and-mongodb-application-in-sap-cloud-platform-6920ad3ca98a">Deploying a Node.js and MongoDB application in SAP Cloud Platform</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New features of ECMAScript 2017]]></title>
            <link>https://medium.com/lethal-brains/new-features-of-ecmascript-2017-c25a9db5f5e0?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/c25a9db5f5e0</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Wed, 12 Jul 2017 11:35:10 GMT</pubDate>
            <atom:updated>2017-07-12T13:16:09.059Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OF0xEMkWBv-69zvmNs6RDQ.gif" /></figure><p>Recently, the specifications of ECMAScript 2017 was released. Yes, it is called <em>ECMAScript 2017 </em>and not <em>ES8</em>. The naming convention started with ES1 and went through 1, 2, 3, 5, 5.1, 6 but ES6 was later renamed to ECMAScript 2015. Subsequent releases are called ECMAScript 2016 and 2017.</p><p>Enough with the nomenclature, lets get into the new features that are supported with this specifications.</p><ul><li>Object.entries</li><li>Object.values</li><li>String padding</li><li>Object.getOwnPropertyDescriptors</li><li>Trailing commas in function parameter lists and calls</li><li>Async functions</li><li>Exponentiation Operator</li><li>Array.prototype.includes</li></ul><p>Let us look at some detailed explanation for each of these</p><h4>Object.entries</h4><p>A new <em>entries</em> method has been included to the Object. When a JavaScript datatype with key value pairs is passed to the entries method, the return value is a two dimensional array of keys and values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc85566b628efcdca11b21dce29cbf8b/href">https://medium.com/media/fc85566b628efcdca11b21dce29cbf8b/href</a></iframe><h4>Object.values</h4><p>The <em>values </em>method works similar to its predecessor but instead of returning both the keys and values, it returns a single dimension array of the values</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25b847abddf79f2c1c5438f71256f6b7/href">https://medium.com/media/25b847abddf79f2c1c5438f71256f6b7/href</a></iframe><h4>String padding</h4><p>Two methods padStart and padEnd has been added to String to support the padding at the beginning and the end of the string. Following are the definition and the examples of the methods</p><p><strong>Def: </strong><em>String.prototype.padStart( maxLength [ , fillString ] )</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac087bbd81fe255b337b873643ac335c/href">https://medium.com/media/ac087bbd81fe255b337b873643ac335c/href</a></iframe><p><strong>Def: </strong><em>String.prototype.padEnd( maxLength [ , fillString ] )</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad84128ae1053f45891297555603f883/href">https://medium.com/media/ad84128ae1053f45891297555603f883/href</a></iframe><h4>Object.getOwnPropertyDescriptors</h4><p><em>Object.getOwnPropertyDescriptors</em>(obj) accepts an object obj and returns the property descriptors describing the <em>attributes</em> of a property (its value, whether it is writable, etc.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69cb22bb8a0c8bf57c5e2bee82cfa14a/href">https://medium.com/media/69cb22bb8a0c8bf57c5e2bee82cfa14a/href</a></iframe><p>In the above example, obj has a integer value assigned to id and a getter method with the name bar. So the getOwnPropertyDescriptors returns the value along with other properties like writable, enumerable, configurable, getter, setter.</p><h4>Trailing commas in function parameter lists and calls</h4><p>Going forward object literals, array literals and function parameters allow a trailing comma</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ff3497e1902734dba74799444d42fd9/href">https://medium.com/media/0ff3497e1902734dba74799444d42fd9/href</a></iframe><p>Why is this important? This solves problems like multi line commits to add a new parameter, rearranging items is simpler, because you don’t have to add and remove commas if the last item changes its position.</p><h4>Async functions:</h4><p>The usage of promises and generators has gained popularity. Though our code has been revived from the callback hell, the <em>multiple then clusters</em> can be simplified more and the code can be much more beautiful and legible.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd7fa7206d9d94db54396af30f9b911c/href">https://medium.com/media/bd7fa7206d9d94db54396af30f9b911c/href</a></iframe><h4>Exponentiation Operator</h4><p>Gone are the days when you had to depend on JavaScript’s Math object to perform exponential operation. ECMAScript 2017 introduces <strong>**</strong> operator for the same</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ee6c7db443c143e40e2497a78c99ec5/href">https://medium.com/media/1ee6c7db443c143e40e2497a78c99ec5/href</a></iframe><p>You can also perform x **= y for directly assigning the value to the variable x</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd86a33dd93571d7d52cc8ec9e0284f1/href">https://medium.com/media/dd86a33dd93571d7d52cc8ec9e0284f1/href</a></iframe><h4>Array.prototype.includes</h4><p>This is a feature which must have been included in JavaScript years ago since validations like array.indexOf(element) !== -1 , array.indexOf(element) &gt;0 , ~array.indexOf(element) has been haunting every JS codebase. Instead of checking whether the element exists in the array, we are checking for the index of the first occurrence of the element in the array. Additionally, this would fail for NaN (eg: [NaN].indexOf(NaN) === -1)</p><p>To overcome this, ECMAScript 2017 has introduced <em>includes</em> method to the Array to check whether an element is present in the Array. Henceforth to check the existence of an element, you can use the following</p><pre>array.includes(element)</pre><p>These are some of the majorly accepted proposals but there are tonnes of interesting proposals in Stage 2 and 3 assuring promising releases ahead.</p><h4>Availability:</h4><p>The spec is available by default in <em>Chrome </em>and<em> Edge 16(Chakra)</em> while firefox will be following them very soon.</p><p>**<strong>EDIT</strong>**</p><p><em>Exponentiation Operator and Array.prototype.includes have been a part of ECMAScript 2016 specification itself.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c25a9db5f5e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/new-features-of-ecmascript-2017-c25a9db5f5e0">New features of ECMAScript 2017</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dial D for Docker: Part 1 — Installation and commands]]></title>
            <link>https://medium.com/lethal-brains/dial-d-for-docker-part-1-235079a61e35?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/235079a61e35</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Tue, 20 Jun 2017 23:10:21 GMT</pubDate>
            <atom:updated>2017-08-03T18:20:57.022Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dial D for Docker: Part 1 — Installation and commands</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_NQN6_YnxS29m8vFzWYlEg.png" /></figure><h4>Intro to this series</h4><p>I was first introduced to docker at an AWS DevDay technical event few years back. I have been learning and using docker since then and have found out immense material out here in the web but was never satisfied with a single material source. With latest changes in the docker community, I thought I can create a blog series explaining all that I have learnt about docker.</p><p>I will be covering the basics of docker from installation, deep diving into containers and images, digging into docker compose, service &amp; swarm, deployment as EC2 container service, how to deploy microservices using Docker and a lot more.</p><h4>What is docker and how is it different from a VM</h4><blockquote><strong>Me</strong>: Hello Tom. Whats up! <br><strong>Tom</strong>: Hi Rahul. I have been reading about Docker. Do you know what is it about and how is it different from a VM? <br><strong>Me</strong>: Sure. Docker is a software [..spits out the typical wiki description..]. <br><strong>Tom</strong>: <em>(With an annoyed look)</em> I read that in wikipedia. Got anything else? Probably with an example.<br><strong>Me</strong>: Okay. How about this. David and Goliath were chefs residing next to each other at an apartment. They decided to throw a party and each one wanted to better the other. Both were good at cooking but had no sense of decorations. So Goliath decided to call VM1 party decorators but to his dismay, VM1 decorators came with their own fake walls and ceiling to create a separate party room in Goliath’s living room. Once setup, it occupied most of Goliath’s living room space. Though the decorations were nice, Goliath found it laborious to move the food in and out of the party room. VM1’s drinks and cups decoration was very dull, so Goliath decided to call VM2 decorators for this purpose. VM2 came with their own walls and ceiling to Goliath’s horror. Somehow, they did setup another party room but it occupied the rest of the living room and a part of the kitchen. Communication between the rooms had become horrendous and food distribution had become disastrous. So Goliath instead on focusing on what he does the best(cooking), he spent time on organizing everything else.</blockquote><blockquote><strong>Me</strong>: David on the other hand, dialed up Docker1 decorators who used David’s living room for decoration and items within the house to make a nice theme. Docker1 guys were nice enough to call Docker2 and Docker3 for decorating cups and ice creams and all three were easily accommodating. David’s cooking was worldly and the party was a blast. So on the technical terms, Docker engine runs on top of the host’s Kernel making the docker container fast and lightweight with shared components(binaries, libraries) while the Virtual machines run their own unique operator system with its own memory management installed with the associated overhead of virtual device drivers and have individual binaries, libraries and applications making them gigabytes in size.</blockquote><p>The above conversation would have given you a basic idea about Docker and how it is different from a VM. Instead of providing you with a definition of Docker, I prefer we go along with the tutorial and understand what Docker is and what it is capable of.</p><h4>Installation</h4><p><strong>OSX</strong>: <br> You can install Docker using <a href="https://www.docker.com/docker-mac">Docker for Mac</a></p><p><strong>Linux</strong>:<br> You can use Docker’s automated script to add their repository and install all dependencies: <em>curl -sSL https://get.docker.com/ | sh</em></p><p><strong>Windows 10(Pro and Enterprise editions):</strong><br> You can install <a href="https://www.docker.com/docker-windows">Docker for Windows</a> from the Docker Store</p><p><strong>Windows 7, 8, or 10 Home Edition:</strong><br> you’ll need to install the <a href="https://www.docker.com/products/docker-toolbox">Docker Toolbox</a></p><p>Docker Toolbox is a slightly different approach to using Docker with a VirtualBox VM. This means Docker will be running in a Virtual Machine that sits behind the IP of your OS, and uses NAT to access the internet.</p><h4>Docker Versioning and new changes:</h4><p>On Feb 8th 2017, version 1.13.1 of Docker was released and the release of Docker on Mar 1st 2017 had version <strong>17.03</strong>. This change was to provide Docker with a <strong>YY.MM</strong> versioning scheme.</p><ul><li>Their release also has <strong>Stable</strong>(read as: <em>slower</em>) and <strong>Edge</strong>(read as: <em>faster</em>) options.</li><li><strong>Docker Engine</strong> (the free one) is now <strong>Docker CE</strong> (Community Edition)</li><li><strong>Docker Data Center </strong>is now<strong> Docker EE</strong> (Enterprise Edition)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lR9SAZ7s8IL7UuMzhQGXtg.png" /><figcaption>Docker lifecycle released by the docker team</figcaption></figure><h4>Docker Commands:</h4><p>Once Docker is installed you would have access to the docker command in your cli. Type <em>docker</em> in your cli tool to verify the same. Then lets check what version of docker we have installed using the command <em>docker version. </em>You can also try out <em>docker info</em> for more details. We will analyze the content in a later blog. For now just play around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6A0mM5XUg26-_y_l8XTF_A.gif" /></figure><p>When you hit <em>docker </em>in the cli, you would notice 3 segments</p><ol><li>Options</li><li>Management Commands</li><li>Commands</li></ol><p>These three segments combine to form the actual docker commands. A typical docker command line structure would be</p><blockquote>docker &lt;management command&gt;&lt;command&gt;(options)</blockquote><p>Lets get our hands dirty and try out few commands. Lets run an <strong>nginx</strong> container in our local machine. Use the following command</p><blockquote>docker container run --publish 80:80 --detach nginx</blockquote><p>Since this is your first time running this command, it might take around a minute. Once its done, goto <em>localhost </em>in your browser and you will notice nginx running in port 80. You can also find the container status by running the following command</p><blockquote>docker container ls</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMHLqMMceSbvgY8K11Df4A.gif" /></figure><p>In the following segment, I will explain what these commands are. What does a container mean? What is an image? How are they related and we can play around more with containers and images.</p><p>Guys, if you are looking for any particular topic to be covered, let me know in the comments, I will add it part of the series.</p><p>This article is a part of docker series <strong>Dial D for Docker</strong>. You can find the next article in the following link</p><ul><li><a href="https://lethalbrains.com/dial-d-for-docker-part-2-1c8dc21cbce4">Dial D for Docker: Part 2 - Images and Containers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=235079a61e35" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/dial-d-for-docker-part-1-235079a61e35">Dial D for Docker: Part 1 — Installation and commands</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conquering the Himalayas]]></title>
            <link>https://medium.com/lethal-brains/conquering-the-himalayas-8c55cb072e8f?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c55cb072e8f</guid>
            <category><![CDATA[life]]></category>
            <category><![CDATA[photography]]></category>
            <category><![CDATA[trekking]]></category>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[inspiration]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Sun, 08 Jan 2017 18:45:45 GMT</pubDate>
            <atom:updated>2017-01-15T19:35:23.085Z</atom:updated>
            <content:encoded><![CDATA[<h3>Conquering the Himalayas: A Journey that redefined Nature</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfEdI5piXXGDKzloXQjNDg.jpeg" /></figure><p>It was an early Saturday morning, I received a mail from Sachin(CEO of my company) asking if anyone is interested in joining him and his family on a Himalayan trek.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*GeC-lQ3opV414stE9C4WhQ.gif" /></figure><p>I have never trekked in my life. The closest I have come near trekking was walking over the steep speed breaker near Mcdonalds. Hence when I decided to do the <a href="https://indiahikes.com/deoriatal-chandrashila-peak/">Deoriatal-Chandrashila Trek</a> with just less than month ahead, I had no idea what I am signing for but I was excited.</p><p><strong>The Preparation Phase</strong></p><p>Along with me, I made my friends Prem and Murali to sign up for the trek. Once registered, we received a list of items that we would need for the trek</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Vi97iEfrJ6ZW_IEPIx7FPg.gif" /><figcaption>MRW I saw the list</figcaption></figure><p>I had none of the items in the list. <em>Wait,</em> <em>Did I have anything??? </em>No, Nothing. I knew its time for a shopping spree. We decided to hit Decathlon for chucking through the checklist. Lucky us, we picked a Sunday and it was more crowded than Times Square on New year’s. After a hard toiled day amidst the shopping zombies, we realized that we still need to do more shopping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TDAMkba-CmjhJMcBDRxuxA.jpeg" /><figcaption>Things we purchased during our first shopping trip</figcaption></figure><p>After multiple trips to decathlon and daily visits from Amazon courier, we thought we are done with all the things that were needed for the trek. We booked our flight tickets, bus tickets and accommodations.</p><p><strong>The Travel begins</strong></p><p>We were supposed to begin our journey on the night of Dec24th and both of my friends joined me at my place to checkout the travel checklist and begin the journey but to our surprise we missed out so many items and were scrambling around to pack our trekking bags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*odKv0vB1cP2p-eU8wy0nhg.gif" /></figure><p>We rushed to the airport and our flight was late. Gave us time to grab a quick bite and time for me to buy a book(<em>J.K.Rowling’s Career of Evil</em>). Personally, any holiday is incomplete without a mystery novel. We then hopped on to the flight taking us from <em>Bangalore</em> to <em>New</em> <em>Delhi</em>.</p><p>We reached Delhi airport by 12 am and our bus to <em>Haridwar</em> was not until 8 in the morning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*JSYu27v9ZCfE6jLwTYFW4w.gif" /></figure><p>After an exhaustive 8 hours wait at Costa Coffee at the airport and eyes looking at us warily, we boarded our bus to Haridwar. All 3 of us slept even before the bus was out of the bus stand, reached Haridwar post noon and spent the evening there.</p><p>Following day, a cab was arranged for us to travel to our basecamp at <a href="https://www.google.co.in/maps/place/Sari,+Uttarakhand/@30.5211847,79.1459802,15z/data=!3m1!4b1!4m5!3m4!1s0x390833cd4ae2688f:0x2503c3a8bc1915d7!8m2!3d30.5180599!4d79.1534422?hl=en"><em>Sari, Uttarakhand</em></a><em>. </em>It was a beautiful 6 hours drive along the banks of river Alakananda with the mesmerizing view of that greenish water tunneling through the majestic mountainous landscape of Uttarakhand, making us forget our altitude raising to 6,600 ft.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*DjdiLhH85WHUM6tTLb3B-w.png" /></figure><p>At the base camp, we met Sachin and his family and the other trekkers. Our trek leader Jude, for the zillionth time in his life, provided us with the trek’s basic instructions as the sun setting on one side and the cold pricking the life out of me on the other.</p><p><strong>Houston, We have a take off</strong></p><p>On the delightful morning of the 27th, while everyone were judiciously packing their trekking bags, I, as foolish and over ambitious as I could ever be, was testing the potential of my 60 litres trekking bag by filling it so full , I had to wrestle to zip it up. Adding 2 litres of water bottles to the side was not helpful either. The trek was supposed to be a short one for the day but carrying a mountain on my back made me think otherwise.</p><p>As we started ascending, the delightful greenish wrap on top of Sari smiled at us along with the cheerful grassy mountains and the soothing sky adding themselves to this beauty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfFAEjUj6JL3hgyvY6jvBA.jpeg" /><figcaption>Sari, Uttarakhand</figcaption></figure><p>As we started ascending more, the beauty of the place started unfolding itself while my backpack started making me unhinge myself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G11qYg4Moc4M2hsuQ39rpw.jpeg" /></figure><p>To add to my misery and to remind me that I am getting old, a bunch of school children climbed beside us, jumping and hopping along the trail while I felt like Frodo on Mount Doom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z3mwfD6yUfaUJ2ireindPA.jpeg" /></figure><p>After little more than an hour, we reached our camp at Deoriatal. The campsite was overlooking a lake which dressed itself with the reflections of the lustrous snowy mountains surrounding it on all directions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d6fETRR-aQ5GNZW7d9Gs0A.jpeg" /><figcaption>This image was shamelessly taken from the Indiahikes website :|</figcaption></figure><p>Deoriatal was the best camp site of the trek. I was spellbound at the never-ending trail of snow capped mountains. Each peak had its own story to tell and you can watch them for hours, mesmerized it them</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VShpoB3sphQ3dt91BjsgBg.jpeg" /></figure><p>As a cherry on top of everything, the sunset washed the sky with the longer wavelength of visible spectrum(i.e. <em>yellow, orange </em>and <em>red</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VO9Oy-ttIspL6DcL3UBMAw.jpeg" /><figcaption>Frankly, this picture does not do justice to what my eye was blessed to</figcaption></figure><p>And then came the darkness, rallying down with coldness bringing down the temperature each minute and with our headlights failing to work we were soon engulfed by the darkside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*nR434a-ftlJ3D1ezgSQxcw.gif" /></figure><p><strong>Deoriatal to Rohini Bugyal</strong></p><p>I tucked myself into the sleeping bag as Luke used warmth of his dead <a href="https://en.wikipedia.org/wiki/Tauntaun">tauntaun</a> but we lost Murali to the darkside during the night. He was sick as we started the trek for the day. Both Murali and I offloaded our backpacks making the journey much more amiable. Prem, as usual, was atleast few hundred metres ahead of the group.</p><p>This was the trek I enjoyed the most. It had everything, steep climbs, gradual ascend, ever so calm flat surfaces, gentle descends and tricky slopes. We went through ridges, meadows, grass lands, forest. At every step I was awed by the magnanimous beauty surrounding me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfEdI5piXXGDKzloXQjNDg.jpeg" /><figcaption>Is it Pandora?</figcaption></figure><p>The sun started peeking at us as we moved into the depths of the definition of beauty. He made every single step we took picture perfect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_i_riXqofb2VkIEUFIrpw.jpeg" /></figure><p>Another astounding aspect of the day was the variety of hills and mountains brushing shoulders with us. The tall snow capped mountains tearing the vast blue sky with its lustrous peaks, the greenish hills covering themselves with plethora of rhododendron and maple trees and the brownish barren hills boasting its nakedness challenging the exquisiteness around it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F5y_hL6P9pa1Lu4YjlOs6Q.jpeg" /></figure><p>The more we walked, the more colourful it got. The scenic elegance surrounding me made me wonder how much more I can enjoy this if I had more colour receptive cones like the Mantis Shrimp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoswVsInX7LaAZNxN9zJXw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tb5jZlH5pS2QiEp-a3nfww.jpeg" /><figcaption>Murali, looking heroic even when sick</figcaption></figure><p>To stand on the top of each hill we crossed and to look over the never ending horizon was breath-taking. I was speechless looking at the view below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7utuAMBx4uAJ2U3eQjLFMA.jpeg" /><figcaption>Heavenly beauty</figcaption></figure><p>Each picture I took, I felt I was not doing justice to what I was looking at. A different angle told a different story and I wished I could hear them all</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jqnRI16uWecMXlLvkR6Smg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2O08FWPcCpaNPhWbDB-bg.jpeg" /></figure><p>Juggling between forests, meadows and mountains we kept going forward breaking each time when we saw a picturesque view. The forests were most welcoming with its rustic ground and its vibrant trees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6bFM_2nJ6-HUeBV6HgZqA.jpeg" /></figure><p>At around 3 in the evening we reached our campsite at <em>Rohini Bugyal. </em>My body was oxymoronic, both refreshing and tired. Part of me wanted more, part of me was happy to be rested. The campsite was entirely isolated and civilization seemed far away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*thyJ5lIna7LWXyeZGyVigQ.jpeg" /></figure><p>Murali would have been a happier as seemed more tired than I have ever seen him. Prem was as inhuman as he could be, seemed like he had not taken a step, wanted more. As the sun shied itself into the mountains, we found ourself midst our old enemies, darkness and cold seemingly powerful than the previous day as we were more than a thousand feet above than the previous day.</p><p><strong>Rohini Bughyal to Chopta</strong></p><p>Shockingly, I found myself wide awake at 5 am. I swam though the darkness to find Prem standing alone enjoying the cold breeze making us breath like a kettle in the stove. I have never smoked in my life but that day I was making smoke rings with my mouth.</p><p>We started our day early, with Murali claiming to be better than the previous day and Prem bolting ahead of everyone. Jude, the trek leader, promised the trek is going to be similar to the previous day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j5eFYa4GDmC7ozps9Cer2g.jpeg" /><figcaption>A majestic tree near the campsite</figcaption></figure><p>We went through thicker forests and risky slopes. I was aware of the fact that I was loosing my camera battery faster than I expected and hence I planned on limiting the photos for the day, so I will be left with something for my summit climb. But the moment, I saw the skull of this, this, whatever this was, I was snapping pictures within seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHDdM9gbRXKAhGCCbtmlug.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjKMDCWufhS7DIoBgEUWjg.jpeg" /><figcaption>Murali having a romantic vintage moment</figcaption></figure><p>The Sun made me snap a few more pictures during the walk that was quite similar to the previous day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K9QQBy7suNlhcXMdAtGbmw.jpeg" /></figure><p>We then stopped at a bridge on top of a brook sprayed upon by snow and brown leaves, the deciduous remaining of the surrounding trees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k9CXSxXb7drrdgO8aeX4dA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qr8UexC08U834ytQ1ZGsPw.jpeg" /><figcaption>Snow sparkling through my lens</figcaption></figure><p>After lunch, we continued our journey towards Chopta. We turned up one after the other to end of the forest to be welcomed by the flawless mountain peaks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lDPcTfFsXuvvnl4hEhzt9Q.jpeg" /></figure><p>Soon, we reached Chopta campsite and settled faster than the other day. We were instructed about the trek starting at 3 am the next day, so we went down paralleling the sun.</p><p><strong>Judgement day</strong></p><p>Prem and I woke up at 1 am with Murali joining us at 2. The whole group was ready by 3 and we began our 3000 ft ascend for the day. The plan was to reach Tungnath temple(which was around 4 km from Chopta) before sunrise and walk all the way to Chandrashila peak(1.5 km from Tungnath) around sunrise. It was a steep climb and to make things worse, certain section of the climb were ice covered making it slippery and difficult for us.</p><p>It was dark and I had no idea where I was going. It got more difficult as we started going up. At least thats what I felt. The oxygen level started dropping down and I was very skeptical about reaching the summit. Prem realized I was struggling and offered to help as I started questioning myself about trying to proceed further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*SX2A-SPnCqpVjRfJzR7hQg.gif" /></figure><p>As we reached Tungnath, glimpse of light started unwrapping the darkness around us. Water in my bottle soon became ORS mixture as I found myself cramping but Prem made sure we both pushed forward.</p><p>The path from Tungnath to Chandrashila was just a human trail amongst the millions of rocks girthing the mountain. It was not altogether dangerous but there were places, where a wrong step can take you to your last breath.</p><p>As I was breathing heavily, we stopped at each turn with Prem constantly making sure we are about to reach the summit. But at the same time, both of us enjoyed the clouds crawling beneath us. Clouds looked cotton like and I wanted to jump over it to feel the softness. I also fought my inner self to prevent myself taking any pictures there since I was mindful of the fact that I have very few snaps left in my camera.</p><p>Finally, both of us reached the summit to be greeted by our guide for the achievement. We were both teary but for different reason. Him for the alternate universe around him and I for reaching the summit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*bK9neQG4fUetapCjwBl2EQ.gif" /></figure><p>The view cannot be described with all the adjectives for beauty put together. A sense of calmness arouse in me. I felt happy, which is a rare occurrence for me.</p><p>Chandrashila summit looked like a portal to a different universe. The world beneath us was covered by clouds. We could only see magnificent peaks slicing through the clouds and the sun sparkling on everything it can set foot on. I took out my camera, snapped a few shots of the surroundings and a shot with Sachin &amp; Prem and my camera died on me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UCEChQABcDOYgI7zv_TBaA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lQE2OJ0GRMn3o4xHB2BmUA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2fcZt5k29FkeHTnN6Wetdw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B-QEA0txMVMC-OG0DpCFaA.jpeg" /><figcaption>Me, Sachin and Prem</figcaption></figure><p>As we descended, I was envious of everyone who were taking pictures and cursed my battery. The serenity within me made me realize what I achieved that day and I was proud of that.</p><p>After a couple of hours, we reached the campsite. I had a moment alone in the tent. I made sure I struck off climbing the Himalayas from my bucket list.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c55cb072e8f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/conquering-the-himalayas-8c55cb072e8f">Conquering the Himalayas</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Node.js? An explanation too late]]></title>
            <link>https://medium.com/lethal-brains/what-is-node-js-an-explanation-too-late-477c10778dea?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/477c10778dea</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[v8]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[ecmascript-6]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Mon, 19 Dec 2016 22:33:57 GMT</pubDate>
            <atom:updated>2016-12-20T15:12:54.840Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7iVDc2YQT9yBuuYM08E1w.png" /></figure><p>You may wonder “<em>Dude! What the hell? Node.js has been around for 7 years and now you are writing a blog on What is Node.js</em>”. I do agree with you but too often I have a conversation like this in my office</p><blockquote>Tom: Hey Rahul, I need your help. I wanna take over the world.<br>Me: Sure Tom. I can do that in Node.js. I think I recently saw a node module for that. <br>Tom: Cool! I will setup the application server for you to deploy this. <br>Me: I wouldn’t need that. Node.js, dude!<br>Tom: Oh! So Node.js is an application server? I thought Node.js is a programming language. <br>Me: No No! Javascript is the language we code. Since its script based I don’t need a containerized application server.<br>Tom: Is it? So is Node.js is a JS library? <br>Me: Not exactlyyyy…<br>Tom: Then it must be that JS Framework from Facebook everyone talks about these days. <br>Me: Tom, thats React.js and I wouldn’t categorize Node.js as a framework.<br>Tom: What else do I have, huh, Is it a webserver like Apache Tomcat? <br>Me: No, but Node.js has inbuild modules that helps me to create to a webserver.<br>Tom: So what the **** is Node.js?<br>Me: Basically, Node.js is a ……</blockquote><p>I work in an ecosystem of <em>autobots </em>and <em>decepticons</em>(i.e) one team living in the open source world while the other teams endorse typical enterprise tool based development culture. As we converge too often these days, I thought of writing this to take a deep dive into what exactly is Node.js</p><p><strong>V8 Javascript Engine — Under the Hood</strong></p><p>Let me teach you some basics of computers. Our computers consists of processors, which when given a command, executes it. But in order to talk to a processor, we need a language</p><blockquote>Tom: Oh! Ok I get it now. So Node.js is that language which talks to the processors</blockquote><p>No. It isn’t. Processors do not understand high level languages rather you have to provide them with <strong>Instruction Sets</strong>(Machine Code). But writing machine code isn’t easy. Lets just take a peek</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*g0hojT6Rf93wElgHno33RA.jpeg" /></figure><p>Understood anything? Me neither. There are <a href="https://en.wikipedia.org/wiki/List_of_instruction_sets">different types of instruction sets</a> for different types of processors. So the code we write must be converted into these instruction sets for the processor to execute. This conversion must be performed by some process and this is where Javascript engines make their entrance.</p><p>A J<em>avascript engine</em> is a program that converts Javascript code into instruction sets that the machine can understand. There are <a href="https://en.wikipedia.org/wiki/JavaScript_engine#JavaScript_engines">many JS engines</a> created and maintained by technology leaders of the world and the most popular among them is the <a href="https://developers.google.com/v8/"><strong>V8 Javascript Engine </strong>developed by <strong>Google</strong></a>. World’s famous browser, <strong>Google Chrome,</strong> runs on top of V8 Javascript engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzTmTKLbKyk5YNjp1oHXaQ.gif" /><figcaption>All Hail Our Robot Overloads</figcaption></figure><p><strong>ECMAScript</strong></p><blockquote>Tom: How does V8 or any other Javascript engine know how to convert javascript to machine code? Are there any standards defining what any piece of javascript code must contain?</blockquote><p>Yes, there is. Everybody puts your hands together for <strong>ECMAScript</strong>. ECMAScript defines the language specification for javascript describing each and every components of javascript,<strong> </strong>their functionalities, etc. All the javascript engines use ECMAScript specifications to convert javascript code to Machine code.</p><p><strong>C++</strong></p><blockquote>Tom: Rahul, Weren’t we talking about Javascript? Why are we jumping to C++ now?</blockquote><p>Tom, V8 engine is written in C++ and before you question me why is that important, take a look at the screenshot of V8 homepage shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gbgmhvcwGO2Ng6RJy0-PEw.png" /></figure><p>As highlighted, V8 can run standalone or can be embedded into any C++ application. So if I write a C++ program, I can embed V8 and process any js code that I write.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*FKbIr8JTiJAblBeUG2kulA.png" /></figure><p>V8 also has hooks that I can use in my C++ program to add addition features to Javascript and can expose multiple features for people to code to. Since I am writing C++ code, I can add hell a lot of feature. Javascript was supposed to be browser based language and now with the plethora of library that exists with C++, I can add a lot of new functionality(access file system, db connection, etc) to Javascript.</p><p><strong><em>This is exactly what Node.js does. </em></strong>But in a very larger scale adding features to Javascript which were never expected to be a part of Javascript community.</p><blockquote>Tom: Does that mean Node.js is also written in C++</blockquote><p>Spot on Tom!!! Node.js is written in C++ and it embeds V8 to convert js to machine code and introduces innumerable features into the Javascript ecosystem.</p><p>Henceforth, if asked what is Node.js, reply</p><blockquote><em>Node.js is a program that converts javascript to machine code by embedding V8 engine in its C++ code and provides humongous capabilities to Javascript and monstrous power to Javascript developers</em>”</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=477c10778dea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/what-is-node-js-an-explanation-too-late-477c10778dea">What is Node.js? An explanation too late</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Jenkins with Github, Node.js and Slack]]></title>
            <link>https://medium.com/lethal-brains/integrating-jenkins-with-github-node-js-and-slack-e8fc4d2271b5?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8fc4d2271b5</guid>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Wed, 14 Dec 2016 20:56:42 GMT</pubDate>
            <atom:updated>2016-12-16T07:07:38.496Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JevAfETU-Fa7hfGkchdxMQ.png" /></figure><p>Having an automated environment to run builds every time a code push happens on the source code repository and broadcasting the status of the build to the team members will ensure code base sanity and help the development team avoid having cat fights over whose commit caused the nightly build to fail.</p><p>This blog will help you setup a continuous integration environment using <a href="https://jenkins.io/">Jenkins</a> for a <a href="https://nodejs.org/en/">Node.js</a> project hosted in a private <a href="https://github.com/">Github</a> repository with integrated <a href="https://slack.com/">Slack</a> notifications.</p><p><strong>Assumptions</strong></p><ul><li>You have basic understanding of how git and Github works.</li><li>Atleast rudimentary Node.js skills. If not the code is shared <a href="https://github.com/lethalbrains/ci-sample">here</a> and the steps to integrate it with the environment is provided below.</li><li>Basic Ubuntu knowledge since I am installing Jenkins in an AWS ubuntu instance.</li></ul><p><em>We have set the agenda, lets dive in</em></p><p><strong>Installing Jenkins</strong></p><p>In order to install and setup a Jenkins server integrated with Github, we need a linux instance(<em>Sorry! I am not a window’s fanboy</em>) with a public IP. So I am setting up an AWS instance running Ubuntu 14.04 LTS operating system. You can also use any VPS providers or in-house servers but just make sure you have an public ip</p><blockquote>Note: The setup can also be done locally without a public ip but in that case instead of Github intimating Jenkins on new code pushes, Jenkins must poll Github for changes which is not efficient and has API limitations.</blockquote><p>To begin with, ssh into the server and install the basic essential libraries and Java jdk and jre.</p><pre>sudo apt-get update<br>sudo apt-get install build-essential<br>sudo apt-get install python-software-properties <br>sudo apt-get install default-jre<br>sudo apt-get install default-jdk</pre><p>After installing the basic libraries, lets install Jenkins by executing the following commands</p><pre>wget -q -O — <a href="https://pkg.jenkins.io/debian/jenkins-ci.org.key">https://pkg.jenkins.io/debian/jenkins-ci.org.key</a> | sudo apt-key add -<br>sudo sh -c ‘echo deb <a href="http://pkg.jenkins.io/debian-stable">http://pkg.jenkins.io/debian-stable</a> binary/ &gt; /etc/apt/sources.list.d/jenkins.list’<br>sudo apt-get update<br>sudo apt-get install jenkins</pre><p>The above commands, along with installing Jenkins, also creates a user with the name jenkins which executes the automated services, launches Jenkins service as a daemon up on start.</p><p>Now Jenkins server is listening on port 8080and it can accessed through &lt;server IP&gt;:8080. If you want to change the port number to which Jenkins is listening, edit the /etc/default/jenkins to replace the line HTTP_PORT=8080<em> to </em>HTTP_PORT=&lt;preferred port number&gt;</p><p><strong>Setting up Jenkins</strong></p><p>There are a few steps to follow for setting up Jenkins for the first time. Access the Jenkins server url from your favourite browser(<em>read as chrome</em>) and you will be asked to provide an admin password to unlock Jenkins and this password can be found in the following location</p><blockquote>/var/lib/jenkins/secrets/initialAdminPassword</blockquote><p>Once you provide the password, you will asked to create the first admin user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5PEF-Za_UzlJzgME0OwRzQ.png" /></figure><p>After the admin creation, Jenkins will prompt you to install the plugins. You can either opt to install suggested plugins or select the list of plugins you need to be installed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7OfirwzOkEJBfKM928Y1w.png" /></figure><p>Once the plugins are installed, we are all set to create a new Job in Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SCzGE5PMOK3x1sjR8wh9iw.png" /><figcaption><em>Tada!! </em>Jenkins is ready</figcaption></figure><p><strong>Setting up Node.js codebase</strong></p><p>The Node.js code consists of a simple express.js application listening to a port 3000<em> </em>and supporting tests to validate the same. The code is shown below and can be cloned from <a href="https://github.com/lethalbrains/ci-sample">this repo</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYc1p47YC9as0gEz7PZh9A.png" /></figure><p>Commit and push the code to Github. Now we can install Node.js in the same server that is running Jenkins using these commands</p><pre>curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -<br>sudo apt-get install -y nodejs</pre><p>Alternatively, you can also setup url to the version you require. Since we will running mocha to execute the test suites, install mocha globally</p><pre>sudo apt-get install -g mocha</pre><p><strong>Integrating Jenkins with Github</strong></p><p>Our Jenkins server has been sitting idle for a while now. Prior to setting up a new job in Jenkins, let us install Github plugin for Jenkins. From the home page, click on <strong>Manage Jenkins </strong>on the left side menu. Then click on <strong>Manage Plugins</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5ZpZmL_bJmW6tSPBJlQ9g.png" /></figure><p>On the available tab, search for Github and install the plugin. Once the plugin installation is complete, lets create a new job</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUiD5uMYwTSNwMCkhfktcA.png" /></figure><p>Click on the create new jobs link and on the subsequent screen select Freestyle project and enter a desired project name and click Ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ljjC2Lb2tQvdtGIN1erC4w.png" /></figure><p>On the next screen we must configure the project details. As this is a Github project, mark the check box GitHub project beneath the project name and provide the project url. In the <strong>Source Code Management</strong> section provide the git url . In case of private git repositories, it is necessary to provide permissions to Jenkins to clone your private repo. You can provide username and password or preferably create Personal Access Token in Github and provide the details here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4zUT-a0pS_PqFyj2vP_jQ.png" /></figure><p>Then check the Build when a change is pushed to Github checkbox in the Build Triggers section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7U_YfmSpR_9HT9VTJcrFQ.png" /></figure><p>In order to configure the build functionalities, select the Add build step dropbox in the Build section of the configuration page. Select Execute shell and in the command text area below add the linenpm install . Lets first test the integration before running the actual test suite.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uz2ejdtzDs_SK0Ydy8Ow9g.png" /></figure><p>Click save and we are good to go. Now lets test if the handshake between our Jenkins server and Github is successful. On the left menu for the project, select the Build Now option and Jenkins schedules a build to run immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DKGetQP6gjr5t2SK109E7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*wMVrO2ub2Qn0XAV8PQpe1A.png" /></figure><p>Now that we have successfully communication with Github, lets run the test cases(remember we only added npm install in our execute script earlier). Just add mocha to the Execute Shell command box(You can do that from the configure link on the left menu of the project) and run a build. If it fails, check the Jenkins logs. To find the logs, click on Manage Jenkins from the left menu in the home page and select System log url</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*7G2cYVznRm59ZEXw_8ePrQ.png" /></figure><p>If the issue is that Jenkins could not find mocha, change the mocha command in the Execute Shell command box to the mocha installed in the local build folder (i.e.)</p><pre>./node_modules/mocha/bin/mocha</pre><p>As suggested by <a href="https://medium.com/u/8814e9953b31">Simon RENOULT</a>, it is better to run the binaries using npm rather than executing using the relative path of the executable. So you can add npm test to the build step rather than the mocha path. Also add the following in the package.json file</p><pre>&quot;scripts&quot;: {<br> &quot;test&quot;: &quot;mocha&quot;<br> }</pre><p>Run the build and once the build is successful, you can also check the logs for the confirmation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BndyZvqL5hH602DryI8MlQ.png" /></figure><p><strong>Automating builds on new git pushes</strong></p><p>Now we have successfully integrated Github with Jenkins and have run our test cases. But our goal is to run automated builds every time a push is made and not to run the builds manually. This also can be done by 2 ways</p><ul><li>Creating a web hook in Github and github pings the Jenkins server when a code push is done</li><li>Configure Jenkins to constantly poll from Github and schedule a build when it detects a push</li></ul><p><em>Annnnnnd</em> <em>you have guessed it right</em>, it is better and optimal to go with the web hook option. Lets see how that can be done.</p><p>Click on the settings link on the Github repository and click on the Webhooks link from the side menu. In the webhooks page, add the Payload URL which by default is</p><pre>http://&lt;jenkins ip&gt;:&lt;jenkins port&gt;/github-webhooks/<br><em>Don&#39;t forget to add the trailing slash</em></pre><p>Select Just the push events radio button and add the webhook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIgw-yUxaoczRxeXcv66aQ.png" /></figure><p>Immediately once the webhook is created, Github pings the appropriate server to check for the connectivity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fCIFtLQzvvHk3hf2zlFZSw.png" /></figure><p>If the ping is successful, we are ready to rock. Now to test this, lets make a change to the code and push the same. Once pushed, you can immediately see one more request in the webhooks page and you can notice a build being scheduled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2npIwOeI-cu3ePjIA67lJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*t6nI5CNGh16bD0DXr73kNw.png" /></figure><p>We have successfully scheduled a build when a push is made to repository. Our next stop is receiving slack notification with the build status.</p><p><strong>Integrating Jenkins with Slack</strong></p><p>For Jenkins to notify slack, we need to install Slack Notifications plugin in Jenkins. By now, you must know how to do this, so go ahead and install the plugin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SRvcoatAtcahhJPkNatsCw.png" /></figure><p>On the Slack end, install the Jenkins CI app in your Slack account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eH6S4klubSWieWn3JQJsew.png" /></figure><p>Once Jenkins CI app is installed, select the channel in which you wanted the notifications to be posted and then add Jenkins integration which is facilitated by the token generated by Slack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RAN77k7DLVj0u0RcANj3Q.png" /></figure><p>Once you have completed the set up at the Slack end, you need to configure Jenkins. Goto Manage Jenkins in the left menu and click on Configure System. In that page look for Global Slack Notifier Settings and add the team domain and the integration token generated by Slack in the earlier step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdzbzSs1AEF_BLov2l_bFA.png" /></figure><p>Once the handshake is successful between slack and Jenkins, you can see a notification in the slack channel</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZClY09bfmZkdpyOcpV7DQ.png" /></figure><p>The last piece of work to fit everything together is configuring our job in Jenkins for Post Build slack notification. Go to configure section the left menu within the Job page. In the configuration screen, select the Add post build action drop down in the Build section. You can now see a Slack Notifications option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ti7c4JpbzEFsxuWdj3V9nw.png" /></figure><p>Select all the build notification options that you think will be useful for you and in the advanced options select send repeated failure notifications, if you notification for consecutive build failures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJ2oM3CyCEWwtLw3pUmnWg.png" /></figure><p>Finally all the gazillion set up steps are done. Its time to test our continuous integration environment. Make a change to the code and push it to Github and you must see a build being initiated successfully in Jenkins and once the build is complete, you must get a notification in your Slack channel</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHbWXM2qk01Jj4kaExTWDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZB_RHi5CJwvtey26pP2_ig.png" /></figure><p>Optionally you can modify the message that is seen in the notification. You can also use various environment variables provided by Jenkins and its various plugins to make the notifications more eventful .</p><p>If you have a code review process using Github’s pull request mechanism, it will be more resourceful to run the build for every submitted pull requests along with the commits reducing the effort of the reviewers. Jenkins provides another plugins, which makes the above to be configured conveniently. I will write a segment on this in my subsequent blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8fc4d2271b5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/integrating-jenkins-with-github-node-js-and-slack-e8fc4d2271b5">Integrating Jenkins with Github, Node.js and Slack</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scala: For loop version 2.0]]></title>
            <link>https://medium.com/lethal-brains/scala-for-loop-version-2-0-1f4a37d1e353?source=rss-a05b36627641------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f4a37d1e353</guid>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Rahul]]></dc:creator>
            <pubDate>Wed, 21 Oct 2015 09:26:24 GMT</pubDate>
            <atom:updated>2015-10-21T09:26:24.111Z</atom:updated>
            <content:encoded><![CDATA[<p>Most programmers would have introduced to the iteration world through the <em>for loop</em>. It has been simple and straight forward though these years. But lately our requirements out of this iterative control structure bas been increasing(<em>functional paradigm, cartesian product</em>, etc). Scala’s for loop has evolved to a next level to quench our thirst.</p><p><strong>Basic</strong></p><p>The basic functionality of a for loop is to iterate. Here is how you iterate from 1 to 10 using Scala’s for loop</p><pre>scala&gt; for(i &lt;- 1 to 3)<br>     |   println(i)<br>1<br>2<br>3</pre><p>The left-arrow <strong>&lt;-</strong> operator is called a <em>generator</em> as it generates individual values for the range or the collection on the right hand side. For loop can also be used to iterate over collections</p><pre>scala&gt; for(i &lt;- List(&quot;world&quot;, &quot;galaxy&quot;, &quot;universe&quot;))<br> | println(&quot;hello &quot;+ i + &quot;!!&quot;)<br>hello world!!<br>hello galaxy!!<br>hello universe!!</pre><p><strong>Multiple generators</strong></p><p>Scala lets you have multiple generators in your for loop. When you have multiple generators, the loop iterators for both the generators.</p><pre>scala&gt; val starks = List(&quot;Robb&quot;, &quot;Sansa&quot;, &quot;Arya&quot;)<br>starks: List[String] = List(Robb, Sansa, Arya)</pre><pre>scala&gt; val lannisters = List(&quot;Cersei&quot;, &quot;Jaime&quot;,&quot;Tywin&quot;)<br>lannisters: List[String] = List(Cersei, Jaime, Tywin)</pre><pre>scala&gt; for(stark &lt;- starks; lannister &lt;- lannisters)<br>     |   println(stark + &quot; Stark hates &quot; + lannister + &quot; Lannister&quot;)<br>Robb Stark hates Cersei Lannister<br>Robb Stark hates Jaime Lannister<br>Robb Stark hates Tywin Lannister<br>Sansa Stark hates Cersei Lannister<br>Sansa Stark hates Jaime Lannister<br>Sansa Stark hates Tywin Lannister<br>Arya Stark hates Cersei Lannister<br>Arya Stark hates Jaime Lannister<br>Arya Stark hates Tywin Lannister</pre><p>Think of the previous example as a double for loop. The output is the cartesian product of both the collections.</p><p><strong>Guards (Filtering)</strong></p><p>Scala also lets you to have guards for your iteration i.e. you can filter your collection prior to the iteration</p><pre>scala&gt; for{stark &lt;- starks; lannister &lt;- lannisters;<br>     |     if stark.startsWith(&quot;R&quot;)<br>     | }<br>     |   println(stark + &quot; Stark hates &quot; + lannister + &quot; Lannister&quot;)<br>Robb Stark hates Cersei Lannister<br>Robb Stark hates Jaime Lannister<br>Robb Stark hates Tywin Lannister</pre><blockquote><em>As seen above both {} and () can be used interchangeably but the convention is to use {} for multi lines and () for single line.</em></blockquote><h3>Yield</h3><p>By using <em>yield</em> keyword, you can return the values from a for loop. This was the functional paradigm, that I was talking about earlier. This helps us to separate the computation which makes our code much more reusable.</p><pre>val multipledByThree = for(i &lt;- List(1,2,3)) yield i * 3<br>multipledByThree: List[Int] = List(3, 6, 9)</pre><p>If you want to have a side effect along with your yield, you can do the following</p><pre>scala&gt; val multipledByThree = for(i &lt;- List(1,2,3)) yield {<br>     |   println(i)<br>     |   i * 3<br>     | }<br>1<br>2<br>3<br>multipledByThree: List[Int] = List(3, 6, 9)</pre><pre>scala&gt; println(multipledByThree)<br>List(3, 6, 9)</pre><p>Variables declared inside a for loop are of type val, hence reassignment will throw an error</p><pre>scala&gt; for {i &lt;- 1 to 5}{<br>     |   i= i + 1<br>     |   print(i)<br>     | }<br>&lt;console&gt;:13: error: reassignment to val<br>         i= i + 1<br>          ^</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f4a37d1e353" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lethal-brains/scala-for-loop-version-2-0-1f4a37d1e353">Scala: For loop version 2.0</a> was originally published in <a href="https://medium.com/lethal-brains">Lethal Brains</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>