<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: saadnoor salehin</title>
    <description>The latest articles on DEV Community by saadnoor salehin (@saadnoorsalehin).</description>
    <link>https://dev.to/saadnoorsalehin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F271643%2Ffb04760b-fb82-458b-9996-5ef3fba7efbd.jpg</url>
      <title>DEV Community: saadnoor salehin</title>
      <link>https://dev.to/saadnoorsalehin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saadnoorsalehin"/>
    <language>en</language>
    <item>
      <title>I Wore the Same Outfit for 1 year and Here is What I’ve Learned</title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Sun, 23 Aug 2020 13:31:35 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/i-wore-the-same-outfit-for-1-year-and-here-is-what-i-ve-learned-2cp4</link>
      <guid>https://dev.to/saadnoorsalehin/i-wore-the-same-outfit-for-1-year-and-here-is-what-i-ve-learned-2cp4</guid>
      <description>&lt;p&gt;It started 365 days ago when I was maintaining a full-time job at Jeeon, a part-time job at Digitruck and another contractual job offered by Lex, who is a professor at Columbia University.&lt;/p&gt;

&lt;p&gt;At Jeeon, I was doing a software engineering job, at digitruck, I was leading a team and taking care of their software infrastructure by doing the devOps related tasks and with Lex, I was helping him in his research on arsenic detection in Tube-wells, by developing some software tools and android app. And yes, I maintained all 3 jobs concurrently.&lt;/p&gt;

&lt;p&gt;To be honest, it was very stressful for me. But I needed that, I was exploring myself, to maintain these 3 responsibilities properly, I needed to be efficient and productive. And at the top of that, I needed happiness. Soft and simple happiness.&lt;/p&gt;

&lt;p&gt;I took one week break from all of my responsibilities and started to learn and seek happiness. I studied many theories, many stories. Among those, one simple concept has blown my mind, and that is minimalism. I will write details about my version of minimalism later, but today I want to focus on my outfit choice.&lt;/p&gt;

&lt;p&gt;Some of the minimalism blogs I followed, almost everyone has this common. Wearing the same dress every day. At first, I found this funny. Funny and lame. Lame and pointless.&lt;/p&gt;

&lt;p&gt;But still, so many people are following this, there can be a reason. So I decided to give it a try. I bought 13 different grey t-shirts, 5 black pants and 2 black shoes, initially I committed to a 30-day experiment.&lt;/p&gt;

&lt;p&gt;I am writing this post after 365 days of this experiment, and I am still wearing the same dress every day. Here's why.&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation to be consistent
&lt;/h2&gt;

&lt;p&gt;Consistency is key to achieve something, we know that. But being consistent isn’t so easy. At least for me. Wearing the same dress every day is a consistent process. By wearing the same dress, I can start my day by ‘being consistent’. It motivates me throughout the day to maintain the other consistent tasks I am doing to achieve my goals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comfort in decision making
&lt;/h2&gt;

&lt;p&gt;It is the most popular theory. I read it before this experiment and didn’t give a shit back then. But after this experiment, I really felt that. At the end of 150 days, I made at least 300 fewer decisions. I didn’t have to bother about what I would wear for office and what for a date. It’s a simple grey shirt and a black pant, that’s it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Less stress
&lt;/h2&gt;

&lt;p&gt;I remember, during my first days of this experiment, I had to give a presentation at a conference at IUB. I was very confused at first - what to wear? Am I becoming more formal? or more casual? Do I look okay? Etc etc. Later I decided to give the presentation with my iconic dress and I didn’t feel anything about it at all. Having said that, the same outfit every day definitely reduces your stress because you are confident enough about this.&lt;/p&gt;

&lt;h2&gt;
  
  
  People actually don’t care
&lt;/h2&gt;

&lt;p&gt;It was my greatest misconception, “people are thinking about my dress”. To be honest, everyone has their own problem to solve, as long as your dress is decent, people won’t notice this at all. And even if someone cares, I don’t have to impress him by my dress 😛&lt;br&gt;
Not spending unnecessary money on clothing&lt;br&gt;
   Well, I didn’t think about this benefit at the beginning, but I found the discounts in the brand shops don’t attract me anymore. I don’t feel tempted to buy clothes anymore. That helps me practice minimalism easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Being More Organised
&lt;/h2&gt;

&lt;p&gt;Before this experiment, I used to wear whatever I found in front of me. And most of the time I couldn’t get anything. It was too unorganised and messy back then. But now, I know where my 13 t-shirts are, I wash them in every 2 weeks, and keep them clean and organised. It adds a layer of satisfaction in my daily life.&lt;/p&gt;

&lt;p&gt;There are many more benefits actually, I couldn’t express properly how this simple lifestyle added happiness and efficiency in my life. This is something you won’t understand unless you try it for at least 30 days.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>GCC vs. Clang: How to use bits/stdc++ header in MacOS</title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Tue, 18 Aug 2020 14:43:01 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/gcc-vs-clang-how-to-use-bits-stdc-header-in-macos-1gd6</link>
      <guid>https://dev.to/saadnoorsalehin/gcc-vs-clang-how-to-use-bits-stdc-header-in-macos-1gd6</guid>
      <description>&lt;h1&gt;
  
  
  GCC vs CLANG: how to include bits/stdc++.h
&lt;/h1&gt;

&lt;p&gt;For compiling c++, there are many compilers in the market, but 3 of them are very popular. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visual C++&lt;/li&gt;
&lt;li&gt;GNU Compiler Collection (GCC)&lt;/li&gt;
&lt;li&gt;Clang&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Among them, Visual C++ was developed by Microsoft, and they don’t support other platforms like Linux. (Typical Microsoft 😛). &lt;/p&gt;

&lt;p&gt;GNU was a project, started by Richard Stallman in 1984, which eventually produced many popular open-source software tools like  Make, Sed, Emacs. GCC was one of them. GCC was used by all UNIX based OS. Apple also used it for macOS. But over time, Apple wanted to add many features to C++ for their own requirements which weren’t accepted well by GNU developers. So Apple engineers made a separate branch for their own version of c++ compiler, which is eventually called CLANG.&lt;/p&gt;

&lt;p&gt;And that’s why some features we get GCC but not in CLANG. Most competitive programmers, use &lt;code&gt;include&amp;lt;bits/stdc++.h&lt;/code&gt; to include all possible header files that might be needed for writing that program. But if we are using macOS, it can’t recognise &lt;code&gt;include&amp;lt;bits/stdc++.h&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To solve this problem, &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;open finder then click &lt;code&gt;Go to folder&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fyEPAyHr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ho9iwejl5n229fkny2yo.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;paste this address &lt;code&gt;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I1FP4sth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g3y03cf7pb0mw5b4f499.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Create a new folder name &lt;code&gt;bits&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;inside &lt;code&gt;bits&lt;/code&gt; create a new file named &lt;code&gt;stdc++.h&lt;/code&gt;. To create a file open terminal and inside that folder and type &lt;code&gt;touch stdc++.h&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;paste the code written below inside that file.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
  */&lt;/span&gt;


&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


  &lt;span class="c1"&gt;// 17.4.1.2 Headers&lt;/span&gt;

  &lt;span class="c1"&gt;// C&lt;/span&gt;
  &lt;span class="cp"&gt;#ifndef _GLIBCXX_NO_ASSERT
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cassert&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#endif
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cctype&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cerrno&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cfloat&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;ciso646&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;climits&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;clocale&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cmath&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;csetjmp&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;csignal&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cstdarg&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cstddef&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cstdio&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cstdlib&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cstring&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;ctime&amp;gt;
&lt;/span&gt;
  &lt;span class="cp"&gt;#if __cplusplus &amp;gt;= 201103L
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;ccomplex&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cfenv&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cinttypes&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cstdbool&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cstdint&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;ctgmath&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cwchar&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;cwctype&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#endif
&lt;/span&gt;
  &lt;span class="c1"&gt;// C++&lt;/span&gt;
  &lt;span class="cp"&gt;#include &amp;lt;algorithm&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;bitset&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;complex&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;deque&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;exception&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;fstream&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;functional&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;iomanip&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;ios&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;iosfwd&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;iostream&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;istream&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;iterator&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;limits&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;list&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;locale&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;map&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;memory&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;new&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;numeric&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;ostream&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;queue&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;set&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;sstream&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;stack&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;stdexcept&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;streambuf&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;string&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;typeinfo&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;utility&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;valarray&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;vector&amp;gt;
&lt;/span&gt;
  &lt;span class="cp"&gt;#if __cplusplus &amp;gt;= 201103L
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;array&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;atomic&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;chrono&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;condition_variable&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;forward_list&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;future&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;initializer_list&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;mutex&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;random&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;ratio&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;regex&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;scoped_allocator&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;system_error&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;thread&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;tuple&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;typeindex&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;type_traits&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;unordered_map&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#include &amp;lt;unordered_set&amp;gt;
&lt;/span&gt;  &lt;span class="cp"&gt;#endif
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;save and exit. After that it will work fine. &lt;/p&gt;

&lt;p&gt;originally published in &lt;a href="https://saadnoor.com/gcc-vs-clang-how-to-include-bitsstdc-in-mac/"&gt;https://saadnoor.com/gcc-vs-clang-how-to-include-bitsstdc-in-mac/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>compiler</category>
      <category>macos</category>
    </item>
    <item>
      <title>Coding Interview Question: Kadane algorithm(maximum subarray sum) explained in 3 min </title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Tue, 11 Aug 2020 20:33:53 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/coding-interview-question-kadane-algorithm-maximum-subarray-sum-explained-in-2-min-lap</link>
      <guid>https://dev.to/saadnoorsalehin/coding-interview-question-kadane-algorithm-maximum-subarray-sum-explained-in-2-min-lap</guid>
      <description>&lt;p&gt;Problem: &lt;strong&gt;&lt;em&gt;We have to find the maximum subarray sum.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Eg: Lets consider this array ⇒ [-10, 5, -9, 1, 3, -2, 3, 4, 7, 2, -9, 6, 3, 1, -5, -4], the answer for maximum subarray sum is 19. (1, 3, -2, 3, 4, 7, 2, -9, 6, 3, 1)&lt;/p&gt;

&lt;p&gt;Solution ⇒ Naive approach, brute-force. Generate all the arrays and get the maximum sum.&lt;/p&gt;

&lt;p&gt;From this, we can generate subarrays like, &lt;/p&gt;

&lt;p&gt;-10&lt;/p&gt;

&lt;p&gt;-10, 5&lt;/p&gt;

&lt;p&gt;-10, 5, 9&lt;/p&gt;

&lt;p&gt;-10, 5, 9, 1 &lt;/p&gt;

&lt;p&gt;-10, 5, 9, 1 , 3 &lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;5&lt;/p&gt;

&lt;p&gt;5, 9&lt;/p&gt;

&lt;p&gt;5, 9, 1&lt;/p&gt;

&lt;p&gt;5, 9, 1, 3&lt;/p&gt;

&lt;p&gt;5, 9, 1, 3, 2&lt;/p&gt;

&lt;p&gt;..&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;We can generate all the subarrays and take the maximum sum, in that case, our code will look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// n*n solution&lt;/span&gt;
&lt;span class="cp"&gt;#include &amp;lt;vector&amp;gt;
&lt;/span&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;notKadanesAlgorithm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;INT_MIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;//Cumulative Sum&lt;/span&gt;
    &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="c1"&gt;// Generate every pair and take maximum.&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But this has a complexity of O(n^2) we can reduce it to O(n)  if we use Kadane's algorithm.  Which uses dynamic programming.  While traversing the array, we can keep track of what was the maximum number, if the array was ended here.&lt;/p&gt;

&lt;p&gt;for example, if our array is [-1, 2, 3, -4], we can generate another array which ith position will hold the maximum value if the array was ended here. We'll get [-1, 2, 5, 1 ]&lt;br&gt;
. Let me explain how. &lt;/p&gt;

&lt;p&gt;In any place, we have either 2 choices. Either we can add the current array item in our sum, or we can start a new array from here. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rG7DiO4w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u338lfpw1eezsn720biv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rG7DiO4w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u338lfpw1eezsn720biv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When i = 0, our &lt;code&gt;maxEndingHere[0] = -1&lt;/code&gt; ⇒ we don't have any option but taking the first element.&lt;/p&gt;

&lt;p&gt;then i = 1, we get 2 as the current value of the array.  Now we have 2 choices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We can consider the subarray ends here (index 1, having value 2). The subarray is  [-1, 2], in that case, we can get our maximum subarray sum -1+2=-1&lt;/li&gt;
&lt;li&gt;We can consider a new subarray starts from here. The subarray is [2], resulting in maximum subarray sum =  2&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;as the second option results maximum value, we will go with it. So, &lt;code&gt;maxEndingHere[1] = 2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After that when i = 2, we get the maximum subarray sum if we take 3, is 5, or we can start a subarray from here, which will give us 3. So our &lt;code&gt;maxEndingHere[2] = 5&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and finally, in the same procedure, we can get &lt;code&gt;maxEndingHere[3] = 1&lt;/code&gt;( max( (5 -4), -4)))&lt;/p&gt;

&lt;p&gt;So our resulted maxEndingHere array is ⇒  [-1, 2, 5, 1 ]&lt;/p&gt;

&lt;p&gt;we can find the maximum number of this array, which is the result, for this example, 5.&lt;/p&gt;

&lt;p&gt;Our code will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;vector&amp;gt;
&lt;/span&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;kadanesAlgorithm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;maxEndHere&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;maxEndHere&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxEndHere&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
        &lt;span class="n"&gt;maxEndHere&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;   &lt;span class="n"&gt;here&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Finding the maximum array in this vector &lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;max_element&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxEndHere&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;maxEndHere&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now it runs on O(n)  but space complexity is still  O(n)  which we can reduce to  O(1)  but not storing the whole array into &lt;code&gt;maxEndHere.&lt;/code&gt; We can just declare an integer and keep the maximum value in it while traversing the array. But this task is for you to do. 😇&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>cpp</category>
      <category>problem</category>
    </item>
    <item>
      <title>Server Side Rendering Visualized</title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Tue, 28 Jul 2020 15:09:34 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/server-side-rendering-visualized-50hf</link>
      <guid>https://dev.to/saadnoorsalehin/server-side-rendering-visualized-50hf</guid>
      <description>&lt;p&gt;Lets take a look, nowadays, how a modern web app is displayed in browser. A typical response sent by an Angular app looks like this,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A bare , poor and sad HTML file
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="na"&gt;doctype&lt;/span&gt; &lt;span class="na"&gt;html&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;title&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Angular&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;title&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;base&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;app&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;app&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"inline.f481c2f5e1589433c6b6.bundle.js"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"polyfills.8135eb80f6191ae1578b.bundle.js"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"main.7dd036568b70b6284d5d.bundle.js"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;    

&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;A rich &lt;code&gt;main.js&lt;/code&gt; file, which is the life for that app.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Browsers take this &lt;code&gt;main.js&lt;/code&gt; file and parse and render our app, it makes that bare HTML meaningful. But what if, user disables Javascript on his browser?&lt;/p&gt;

&lt;p&gt;Well, he will see this - an empty and dead page -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fscxadukqai0lijzzv81v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fscxadukqai0lijzzv81v.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;but wait? Seriously? Somebody will disable Javascript in their browser at 2020? Who is that dumb?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;well, search engine crawlers are dumb. They will. When they want to index our webpage for search results, they will find a plain old HTML file who has nothing, and a big &lt;code&gt;main.js&lt;/code&gt; file for which they don't have any time or respect. When they see that javascript file is too big to parse, they will ignore it. So our Angular app perform poorly in terms of SEO.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What's the solution?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;we can use a quick 3rd party-based solution, &lt;a href="http://prerender.io/" rel="noopener noreferrer"&gt;prerender.io&lt;/a&gt; . It checks the person who requested your webpage, is a bot or human? If it's a human, it sends the regular response - a plain HTML with a main.js file. But if it's a bot, prerender.io opens a browser in itself, renders the app there and then sends the contentful html files.&lt;/p&gt;

&lt;p&gt;So the SEO problem can be solved. But-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It's not a good way&lt;/li&gt;
&lt;li&gt;There are more problems to solve, &lt;em&gt;the first meaningful&lt;/em&gt; paint problem&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First meaningful paint measures when the primary content of a page is visible to the user. In the picture bellow we can see user had to wait for 8 seconds to see anything meaningful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F48i6rna5y4qrw6tt3e51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F48i6rna5y4qrw6tt3e51.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A big portion of this 8 seconds time used to -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download that &lt;code&gt;main.js&lt;/code&gt; file, if the user's internet is slow - this time will increase.&lt;/li&gt;
&lt;li&gt;Parse and render that &lt;code&gt;main.js&lt;/code&gt; file.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And the user didn't see anything meaningful in the screen, recent study shows that user leaves any webpage that takes more than 3 seconds to load.&lt;/p&gt;

&lt;p&gt;Server-side rendering solves both problems. Instead of sending the dead blank HTML file, it renders our app in the server ( blessings of Node.js) and sends the HTML to the browser. Now the user doesn't have to wait for downloading that big &lt;code&gt;main.js&lt;/code&gt; file. It can show the server-rendered HTML immediately. So the user will able see some meaningful content very fast.&lt;/p&gt;

&lt;p&gt;Now let's see how this SSR works:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbpawuysz3zdwbxiqknr9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbpawuysz3zdwbxiqknr9.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The client makes a GET request to the server for the webpage&lt;/li&gt;
&lt;li&gt;The server parses and renders a HTML file immediately&lt;/li&gt;
&lt;li&gt;The client shows this HTML to the user, the user sees a meaningful content but app isn't ready yet&lt;/li&gt;
&lt;li&gt;The server also sends the angular/react app (that &lt;code&gt;main.js&lt;/code&gt; file)&lt;/li&gt;
&lt;li&gt;Client downloads that file in and loads our app background&lt;/li&gt;
&lt;li&gt;Once everything is ready client-side, it seamlessly switches from showing the server-rendered pages to the client-side app. The server gives control to the client when it's ready.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As meaningful HTML is served to the user immediately, So first meaningful paint time improves significantly with SSR.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2gxclzarop21w82vsrko.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2gxclzarop21w82vsrko.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next post, we will learn how to implement Server Side Rendering with Angular, stay tuned.&lt;/p&gt;

&lt;p&gt;(This post was originally published at &lt;a href="https://saadnoor.com/server-side-rendering-visualized/" rel="noopener noreferrer"&gt;https://saadnoor.com/server-side-rendering-visualized/&lt;/a&gt; )&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>serversiderendering</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Introduction To Unit Test in .NET Core Applications By Xunit And Moq</title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Wed, 20 May 2020 05:40:10 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/introduction-to-unit-test-in-net-core-applications-by-xunit-and-moq-3337</link>
      <guid>https://dev.to/saadnoorsalehin/introduction-to-unit-test-in-net-core-applications-by-xunit-and-moq-3337</guid>
      <description>&lt;p&gt;Let’s assume, I have written some introductory sentences about what is unit testing and why it’s important. Let’s jump into main topic directly.&lt;/p&gt;

&lt;p&gt;For writing unit test in .NET core applications we have some libraries like MSTest, NUnit , Xunit. In this post, I will be discussing about Xunit. For getting started, open your IDE and create a solution named &lt;code&gt;HelloWorldUnitTest&lt;/code&gt; and add 2 projects, &lt;code&gt;PrimeDetector&lt;/code&gt; and &lt;code&gt;PrimeDetectorTest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o6LbvVCS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8hynkip354bo6ol6p68p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o6LbvVCS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8hynkip354bo6ol6p68p.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we’ll write a function first, and then write unit test by using xunit. Lets start by writing the function, Lets add a class in &lt;code&gt;PrimeDetector&lt;/code&gt; project named &lt;code&gt;PrimeDetectorModel.cs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public class PrimeDetectorModel
    {
        public bool IsPrime(int n)
        {
            var isPrime = true;

            for (int i = 2; i &amp;lt; Math.Sqrt(n); i++)
            {
                if (n % i == 0) isPrime = false;
            }

            return isPrime;
        }

    }

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we'll write unit test for the &lt;code&gt;isPrime()&lt;/code&gt;method. Let's add a class named &lt;code&gt;PrimeDetectorTest.cs&lt;/code&gt; in the &lt;code&gt;PrimeDetectorTest&lt;/code&gt; project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PrimeDetectorTest
{
    [Fact]
        public void Test_If_It_Can_Detect_A_Prime_Number()
        {
           // Arrange
            var primeDetector = new PrimeDetectorModel();

            // Act
            var isPrime = primeDetector.IsPrime(29);

            // Assert
            Assert.Equal(isPrime, true);
        } 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;What's happening here?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With the &lt;code&gt;[Fact]&lt;/code&gt;attribute, xUnit.net test runner identifies it's a unit test to execute. Here, we will test whether our isPrime() identify a prime number or not. &lt;br&gt;
Every unit test has 3 parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Arrange&lt;/strong&gt;: this portion will have code required to setup the test, in above example we need an instance of &lt;code&gt;PrimeDetectorModel&lt;/code&gt; to call our &lt;code&gt;isPrime()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Act&lt;/strong&gt;: In this portion, we'll call the function which we want to test. Eg: here we called &lt;code&gt;IsPrime()&lt;/code&gt; with a prime number&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assert&lt;/strong&gt;: this portion will responsible to judge whether our expectations were met or not. Eg: here, we checked value of &lt;code&gt;isPrime&lt;/code&gt; is true or not.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;How can we run this test multiple times with different input?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The above example tests whether our &lt;code&gt;isPrime()&lt;/code&gt;method works for 29 or not. Now we want to test it for more integers, let's say for 2, 5, 7, 19 and 23. Instead of copying and pasting the previous test function for 5 times, we can take advantage of &lt;code&gt;[Theory]&lt;/code&gt; attribute. Our test function will now look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [Theory]
        [InlineData(2)]
        [InlineData(5)]
        [InlineData(19)]
        [InlineData(23)]
        public void Test_If_It_Can_Detect_Non_Prime_Numbers(int n)
        {


            // Arrange
            var primeDetector = new PrimeDetectorModel();

            // Act
            var isPrime = primeDetector.IsPrime(n);

            // Assert
            Assert.Equal(isPrime, true);
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we run this test, we will see our test function ran 4 times with the values we have given with &lt;code&gt;[InlineData(n)]&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a0AHdzJy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wtrs825sgmawnvav0a0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a0AHdzJy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wtrs825sgmawnvav0a0k.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[Theory]&lt;/code&gt; attribute denotes a parameterised test, and by the help of the &lt;code&gt;[InlineData]&lt;/code&gt; we provide the values for the parameter.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Summary: When we need to run the test once, we don't need any parameter to be passed through the test function, we'll use &lt;code&gt;[Fact]&lt;/code&gt; attribute, otherwise we'll use &lt;code&gt;[Theory]&lt;/code&gt; attribute.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are some limitations with &lt;code&gt;[InlineData]&lt;/code&gt; attribute, it works with only constants. What if we need to send an object as a parameter?&lt;/p&gt;

&lt;p&gt;Let's add a &lt;code&gt;PersonModel&lt;/code&gt; Class in &lt;code&gt;PrimeDetector&lt;/code&gt; project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; public class PersonModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now add &lt;code&gt;HasPrimeId()&lt;/code&gt; method, bellow the &lt;code&gt;isPrime()&lt;/code&gt; method. It will take an object of PersonModel and check whether the &lt;code&gt;Id&lt;/code&gt; property is Prime or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        public bool HasPrimeId(PersonModel person)
        {
            return IsPrime(person.Id);
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, we'll write unit test for it. Go to the &lt;code&gt;PrimeDetectorTest&lt;/code&gt; file and add this chunk of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public static IEnumerable&amp;lt;object[]&amp;gt; GetTestData()
    {
        yield return new object[] { new PersonModel { Id = 5, Name = "Saadnoor" } };
        yield return new object[] { new PersonModel { Id = 7, Name = "Salehin" } };
    }

    [Theory]
    [MemberData(nameof(GetTestData))]
    public void Test_If_It_Can_Detect_Person_Has_Prime_Id_Or_Not(PersonModel person)
    {

        // Arrange
        var primeDetector = new PrimeDetectorModel();

        // Act
        var hasPrimeId = primeDetector.HasPrimeId(person);

        // Assert
        Assert.Equal(hasPrimeId, true);
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It will call the test function &lt;code&gt;Test_If_It_Can_Detect_Person_Has_Prime_Id_Or_Not()&lt;/code&gt; two times with 2 different &lt;code&gt;PersonModel&lt;/code&gt; object.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;{ Id = 5, Name = "Saadnoor" }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{ Id = 7, Name = "Salehin" }&lt;/code&gt;
Note that, we have to set the return type of the &lt;code&gt;GetTestData()&lt;/code&gt; method as &lt;code&gt;IEnumerable&amp;lt;object[]&amp;gt;&lt;/code&gt; otherwise xUnit will throw an error. If we need 2 or more parameters in our test function, we can do that by adding it to the &lt;code&gt;object[]&lt;/code&gt; array.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can provide data with &lt;code&gt;[ClassData]&lt;/code&gt; attribute also, but I'm skipping it in this post, to keep the post short and simple.&lt;/p&gt;

&lt;p&gt;Now what if we have some dependencies to initiate our &lt;code&gt;PrimeDetectorModel&lt;/code&gt;? How will we test it?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Moq&lt;/code&gt; will save us here. Let's assume, to initiate &lt;code&gt;PrimeDetectorModel&lt;/code&gt; we have a dependency of &lt;code&gt;PositiveDetectorModel&lt;/code&gt; (which helps us to determine whether a number is positive or not).&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;PrimeDetectorModel&lt;/code&gt; class will now look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public class PrimeDetectorModel
    {
        public PositiveDetector positiveDetector { get; set; }

        public PrimeDetectorModel(PositiveDetector positiveDetector)
        {
            this.positiveDetector = positiveDetector;
        }

        public bool IsPrime(int n)
        {
            if (!positiveDetector.IsNumberPositive(n)) throw new Exception("Invalid Input");

            var isPrime = true;

            for (int i = 2; i &amp;lt; Math.Sqrt(n); i++)
            {
                if (n % i == 0) isPrime = false;
            }

            return isPrime;
        }

        public bool HasPrimeId(PersonModel person)
        {
            return IsPrime(person.Id);
        }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now our &lt;code&gt;isPrime()&lt;/code&gt; function checks whether the given number is positive or not, if the number isn't positive, it throws an Exception.&lt;br&gt;
It takes help from &lt;code&gt;IsNumberPositive&lt;/code&gt; method, which comes from &lt;code&gt;PositiveDetector&lt;/code&gt; model.&lt;/p&gt;

&lt;p&gt;Now, while writing the test, we will create a mock of &lt;code&gt;PositiveDetectorModel&lt;/code&gt;, and we are not bothered with &lt;code&gt;isNumberPositive()&lt;/code&gt; method of this class, as we are writing unit test for &lt;code&gt;isPrime()&lt;/code&gt; method, we'll assume that, &lt;code&gt;isNumberPositive&lt;/code&gt; works properly, we'll mock it's result too. Our test function is now looks like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        [Theory]
        [InlineData(2)]
        [InlineData(5)]
        [InlineData(19)]
        [InlineData(23)]
        public void Test_If_It_Can_Detect_Non_Prime_Numbers(int n)
        {
            // Arrange
            var positiveDetectorMock = new Mock&amp;lt;PositiveDetector&amp;gt;();

            var primeDetector = new PrimeDetectorModel(
            positiveDetectorMock.Object
            );

            positiveDetectorMock
            .Setup(pd =&amp;gt; pd.IsNumberPositive(n)).Returns(true);

            // Act
            var isPrime = primeDetector.IsPrime(n);

            // Assert
            Assert.Equal(isPrime, true);
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here, all the inputs (2, 5, 19, 23) are positive numbers, so we are mocking the &lt;code&gt;isNumberPositive()&lt;/code&gt; function by returning true for these input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; positiveDetectorMock
            .Setup(pd =&amp;gt; pd.IsNumberPositive(n)).Returns(true);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's pretty much covers the basic of writing unit tests with xUnit and Moq, for more details you can go to the resources of the reference section, unfortunately xUnit's documentation sucks. Let me know if you have any feedback regarding this post by comments.&lt;/p&gt;

&lt;p&gt;All my codes used here will be found here - &lt;a href="https://github.com/saadnoor/UnitTestWithXunit"&gt;https://github.com/saadnoor/UnitTestWithXunit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://hamidmosalla.com/2017/02/25/xunit-theory-working-with-inlinedata-memberdata-classdata/"&gt;https://hamidmosalla.com/2017/02/25/xunit-theory-working-with-inlinedata-memberdata-classdata/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://andrewlock.net/creating-parameterised-tests-in-xunit-with-inlinedata-classdata-and-memberdata/"&gt;https://andrewlock.net/creating-parameterised-tests-in-xunit-with-inlinedata-classdata-and-memberdata/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://xunit.net/#documentation"&gt;https://xunit.net/#documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Moq/moq4/wiki/Quickstart"&gt;https://github.com/Moq/moq4/wiki/Quickstart&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>dotnet</category>
      <category>testing</category>
      <category>csharp</category>
    </item>
    <item>
      <title>All You Need to Know About Browser's User Agent String</title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Fri, 08 May 2020 04:45:31 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/all-you-need-to-know-about-browser-s-user-agent-string-5fe6</link>
      <guid>https://dev.to/saadnoorsalehin/all-you-need-to-know-about-browser-s-user-agent-string-5fe6</guid>
      <description>&lt;p&gt;At Cefalo, I needed to develop a feature which required me to detect browser first. I thought it was easy - I would get it from the user agent string. But from my current browser, Chrome, what I found was&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Wait wait wait. What the hell? I was expecting only &lt;code&gt;Chrome&lt;/code&gt; but why these extra confusing words with chrome?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mozilla:&lt;/strong&gt; Immediately comes &lt;em&gt;Mozilla Firefox&lt;/em&gt; on our mind. Mozilla is a software community that was founded by the members of Netscape, they now maintain &lt;em&gt;Mozilla Firefox&lt;/em&gt; which is one of most popular browsers. But why it's here?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WebKit:&lt;/strong&gt; The rendering engine which is used by Safari. Though Chrome started with Webkit, but they now uses Blink (which was built based on Webkit though), Where is &lt;code&gt;Blink&lt;/code&gt; in this string?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KHTML:&lt;/strong&gt; It was the rendering engine for &lt;em&gt;Konqueror&lt;/em&gt; browser. Webkit was based on KHTML. Why it is even here?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gecko:&lt;/strong&gt; The rendering engine for Firefox. But why they have to write &lt;code&gt;like Gecko&lt;/code&gt;? is it a joke?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chrome:&lt;/strong&gt; I can understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Safari:&lt;/strong&gt; Again, what the hell?&lt;/p&gt;

&lt;p&gt;To understand what's going on, lets start from what is browser's user agent?&lt;/p&gt;

&lt;p&gt;It's a string to identify which browser is being used by client, which OS it is, which version etc. Generally this string passed by HTTP headers. Many websites customize their experience based on that. &lt;em&gt;Eg: When you are going to download a software, based on your OS it gives you the correct software automatically.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Generally, it has a format like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;Mozilla&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;system&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt; &lt;span class="nx"&gt;information&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;platform&lt;/span&gt; &lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But at the early days, it was very simple, &lt;code&gt;Mosaic/0.9&lt;/code&gt;, it is the user agent string for Mosaic, which is the first web browser. After some time, Netscape Navigator came into the field, they designed their user agent like &lt;code&gt;Mozilla/2.02 [en] (WinNT; N)&lt;/code&gt; which means, Mozilla( interestingly the named it as "Mosaic Killer"!) version 2.02, having English language and Windows NT as a platform with No encryption.&lt;/p&gt;

&lt;p&gt;But things started getting dirty after Internet Explorer entered in the community. When IE came to the market, Netscape was the dominant browser. At that time, many servers checked whether it's &lt;code&gt;Netscape&lt;/code&gt; or not, before serving their contents. Most probably, they thought it would add some extra layer of security. But this created problem for Internet Explorer.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They are new to market, they have to compete with Netscape&lt;/li&gt;
&lt;li&gt;If they can't give support for some websites (who checks whether it is &lt;code&gt;Netscape&lt;/code&gt; or not first), then their adoption rate will be slower. Some people won't use it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So they decided to trick the server. They designed their user agent like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt; &lt;span class="nx"&gt;Mozilla&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;compatible&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;MSIE&lt;/span&gt; &lt;span class="nx"&gt;Version&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;Operating&lt;/span&gt; &lt;span class="nx"&gt;System&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Example&lt;/span&gt;
 &lt;span class="nx"&gt;Mozilla&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;compatible&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;MSIE&lt;/span&gt; &lt;span class="mf"&gt;3.03&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;Windows&lt;/span&gt; &lt;span class="mi"&gt;95&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Above example indicates, Mozilla 2.0 compatible Microsoft Internet Explorer of version 3.03 in windows 95 platform.&lt;/p&gt;

&lt;p&gt;So the websites that checked for Netscape (eg: Checking whether &lt;code&gt;Mozilla&lt;/code&gt; is included in User Agent string, will also serve contents to Internet Explorer now.  That's how keyword &lt;code&gt;Mozilla&lt;/code&gt; is now present most of the browsers' user agent string. &lt;/p&gt;

&lt;p&gt;And as new browsers came in the market, this dirty trick continued. That's why some user string has &lt;code&gt;like Gecko&lt;/code&gt; to substring in it. Just to bypass the filter some popular website was using to serve their content to Gecko engines. Google Chrome just uses all the string for apple's safari + extra string for chrome version. So the servers serve content to Safari, will also serve content to Chrome. &lt;/p&gt;

&lt;p&gt;Now how can we get the browser's user agent programmatically?&lt;/p&gt;

&lt;p&gt;In angular, you can get user agent by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userAgent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userAgent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userAgent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Prints Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now how to detect browser from this user agent? There is no clean way to do this. The bellow table collected from &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent"&gt;here&lt;/a&gt; gives us some idea how to do it with the help of regular expressions.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZQA2Av8H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5z2mfmmtkvu9fv1sy61i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZQA2Av8H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5z2mfmmtkvu9fv1sy61i.png" alt="Pattern Detection for UA Strings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But obviously we'll not reinventing the wheel. There is a beautiful library, &lt;a href="https://github.com/faisalman/ua-parser-js"&gt;UAParser.js&lt;/a&gt;, that does this tedious work for us. &lt;/p&gt;

&lt;p&gt;Just type &lt;code&gt;npm i ua-parser-js&lt;/code&gt; and you will get the browser by &lt;code&gt;getBrowser()&lt;/code&gt; method, as simple as that.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Does this post cover "all" about user agent string?&lt;/em&gt; Obviously no. &lt;strong&gt;I lied, just like Chrome lies to the servers.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Mozilla"&gt;https://en.wikipedia.org/wiki/Mozilla&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://humanwhocodes.com/blog/2010/01/12/history-of-the-user-agent-string/"&gt;https://humanwhocodes.com/blog/2010/01/12/history-of-the-user-agent-string/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.whatsmyua.info/"&gt;https://www.whatsmyua.info/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Netscape#Mozilla-based_releases"&gt;https://en.wikipedia.org/wiki/Netscape#Mozilla-based_releases&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>browser</category>
      <category>javascript</category>
      <category>npm</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Iterm2 Alternative for Windows</title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Sun, 26 Apr 2020 19:55:30 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/iterm2-alternative-for-windows-45bb</link>
      <guid>https://dev.to/saadnoorsalehin/iterm2-alternative-for-windows-45bb</guid>
      <description>&lt;p&gt;For a long time, I used macOS for software development. I used &lt;a href="https://www.iterm2.com/"&gt;Iterm2&lt;/a&gt; as my terminal. The most important use case was to split my screen with multiple terminal windows.&lt;/p&gt;

&lt;p&gt;But after shifting to windows again, I noticed that, split screen feature isn't available to windows terminal, powershell and git-bash. I started to use git-bash and was looking for other alternatives, which has this split screen feature. After some reseach I found Hyper and Cmder. Among them I liked Hyper more, because of it's interface design and more flexibility.&lt;/p&gt;

&lt;p&gt;By default, it will use default termnial, but if you want to use git bash -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download, Install and Open Hyper  (&lt;a href="https://hyper.is/"&gt;https://hyper.is/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;Ctrl + ,&lt;/code&gt;, a text file will be opened in your default text-editor.&lt;/li&gt;
&lt;li&gt;Update the value of &lt;code&gt;shell&lt;/code&gt; by &lt;code&gt;'C:\\Program Files\\Git\\git-cmd.exe'&lt;/code&gt; and &lt;code&gt;shellArgs&lt;/code&gt; by &lt;code&gt;['--command=usr/bin/bash.exe', '-l', '-i']&lt;/code&gt;
c
After that it will look like:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;shell: 'C:\\Program Files\\Git\\git-cmd.exe',
// for setting shell arguments (i.e. for using interactive shellArgs: `['-i']`)
// by default `['--login']` will be used
shellArgs: ['--command=usr/bin/bash.exe', '-l', '-i'],
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now save the configuration and open a new tab(Ctrl+Shift+D).  You will see, new tab opened vertically.&lt;/p&gt;

&lt;p&gt;DONE!&lt;/p&gt;

&lt;p&gt;Enjoy your terminal!&lt;/p&gt;

</description>
      <category>windows</category>
      <category>iterm2</category>
    </item>
    <item>
      <title>Groovy 101: How To Create Custom Gradle Tasks In Android Studio</title>
      <dc:creator>saadnoor salehin</dc:creator>
      <pubDate>Sat, 16 Nov 2019 18:41:31 +0000</pubDate>
      <link>https://dev.to/saadnoorsalehin/groovy-101-how-to-create-custom-gradle-tasks-in-android-studio-3lgl</link>
      <guid>https://dev.to/saadnoorsalehin/groovy-101-how-to-create-custom-gradle-tasks-in-android-studio-3lgl</guid>
      <description>&lt;p&gt;For automating the build process, Android Studio uses Gradle, which is a build tool. Gradle uses Groovy-based DSL (Domain Specific Language) and Groovy is a powerful scripting language for Java platform.  &lt;/p&gt;

&lt;p&gt;Well, in summary, we need a little bit of familiarity with Groovy to work with Gradle. In this blog post, we will learn some hello world type Groovy, and then we will learn how to write custom tasks in Gradle with Groovy. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variable Declaration:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;def str = "hello world"&lt;/code&gt;  yes, as simple as that.&lt;br&gt;
Similarly we can declare lists and maps also,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def nameOfList = []
def nameOfMap = [:]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Loops&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Loops are very interesting, &lt;code&gt;start.upto(end)&lt;/code&gt;, that’s it.&lt;/p&gt;

&lt;p&gt;Eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.upto(5) {
 println "$it"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For iterating through lists and map, we can use &lt;code&gt;every&lt;/code&gt; keyword.&lt;br&gt;
Eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nameOfList.each { item -&amp;gt;
    println element
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Closures&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
In simple term, a block of code that acts like a function. This function can be assigned to a variable.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A closure in Groovy is an open, anonymous, block of code that can take arguments, return a value and be assigned to a variable.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will understand closure by running an example. Lets open android studio to play with Groovy. After opening the android studio, go to tools -&amp;gt; groovy console.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkrrb5ptmc32adey39hok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkrrb5ptmc32adey39hok.png"&gt;&lt;/a&gt;&lt;br&gt;
Type this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void doSomething(Closure closure) {
    closure.call()
}

doSomething {
    print “DID SOMETHING”
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run it, for running it click the green run button &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqcux1atltlehbadvonpc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqcux1atltlehbadvonpc.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Are these codes seems familiar? Your &lt;code&gt;build.gradle&lt;/code&gt; file is full of these codes.  Eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;dataBinding&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;testOptions&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;animationsDisabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will write a task in our &lt;code&gt;build.gradle&lt;/code&gt; file, the task is to make a list of 10 numbers, (from 1 to 10), then print the list. &lt;/p&gt;

&lt;p&gt;At the end of your &lt;code&gt;app/build.gradle&lt;/code&gt; file, add this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="n"&gt;myFirstTask&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="kt"&gt;def&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt;
    &lt;span class="n"&gt;doFirst&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;upto&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;doLast&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;each&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="n"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code explains everything, still - &lt;code&gt;myFirstTask&lt;/code&gt; is the task name, and into that we are defining our task. &lt;br&gt;
&lt;code&gt;doFirst&lt;/code&gt; and &lt;code&gt;doLast&lt;/code&gt; is the syntax of Gradle to differentiate which portion will run first and which one will run last.&lt;/p&gt;

&lt;p&gt;Now for executing this, in the terminal navigate to the project folder. and type:&lt;br&gt;
&lt;code&gt;./gradlew myFirstTask&lt;/code&gt;&lt;br&gt;
If everything alright, you will see in your console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nl"&gt;app:&lt;/span&gt;&lt;span class="n"&gt;myFirstTask&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="n"&gt;BUILD&lt;/span&gt; &lt;span class="n"&gt;SUCCESSFUL&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;actionable&lt;/span&gt; &lt;span class="nl"&gt;task:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;executed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, pretty boring , right?&lt;br&gt;
Now let's​ do some interesting stuffs.  I don’t like the name “app-debug.apk" every-time I build the project, and I am too lazy to navigate some subfolders to get this apk file, I want it in my desktop folder.  Here is how, I will write the task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="nf"&gt;getDebugAppInDesktopFolder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;dependsOn:&lt;/span&gt; &lt;span class="s1"&gt;'assembleDebug'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;doLast&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;def&lt;/span&gt; &lt;span class="n"&gt;destination&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/Users/saadnoorsalehin/Desktop"&lt;/span&gt;
        &lt;span class="kt"&gt;def&lt;/span&gt; &lt;span class="n"&gt;desiredName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-given-name"&lt;/span&gt;
        &lt;span class="n"&gt;ext&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"build/outputs/apk/debug/app-debug.apk"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ext&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;exists&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;copy&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="n"&gt;ext&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;absolutePath&lt;/span&gt;
                &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;destination&lt;/span&gt;
                &lt;span class="n"&gt;rename&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="n"&gt;desiredName&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code,  the keyword &lt;code&gt;dependsOn&lt;/code&gt; specify the dependencies tasks,&lt;br&gt;
&lt;code&gt;getDebugAppInDesktopFolder&lt;/code&gt; will require the execution of  &lt;code&gt;assembleDebug&lt;/code&gt; (the default task which will generate our debug apk) .&lt;/p&gt;

&lt;p&gt;After running &lt;code&gt;./gradlew getDebugAppInDesktopFolder&lt;/code&gt;  you will see your desired apk file in your desktop folder. &lt;/p&gt;

&lt;p&gt;Thanks for reading, Groovy and Gradle both are very vast topic, it is impossible to make everything clear in a single blog post, but I hope you have gotten an idea how things work and how to play with them. If you have any query or feedback regarding this reach me at &lt;a href="mailto:saadnoors9@gmail.com"&gt;saadnoors9@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>groovy</category>
      <category>android</category>
      <category>gradle</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
