<?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 Kevin Mavani on Medium]]></title>
        <description><![CDATA[Stories by Kevin Mavani on Medium]]></description>
        <link>https://medium.com/@kevinmavani?source=rss-bb7341995321------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yMW-grQccribaRtlUrbWKA.png</url>
            <title>Stories by Kevin Mavani on Medium</title>
            <link>https://medium.com/@kevinmavani?source=rss-bb7341995321------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:42:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kevinmavani/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[JavaScript ES6 Features]]></title>
            <link>https://medium.com/@kevinmavani/javascript-es6-features-fe24ebef8bed?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe24ebef8bed</guid>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[arrow-functions]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[spread-operator]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Wed, 27 Sep 2023 10:04:20 GMT</pubDate>
            <atom:updated>2023-10-16T07:34:44.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*laBJWEX0ZAua5L8KakA2uA.jpeg" /></figure><h3>What is ECMAScript 6 (or ES6)</h3><p>ECMAScript 6 (ES6), also known as ECMAScript 2015, is a crucial milestone in the evolution of the JavaScript programming language. ES6 introduced concepts like template literals for flexible string interpolation, destructuring assignment made it easier to extract values from objects and arrays, while the ‘let’ and ‘const’ keywords provided block-scoped variable declarations, spread/rest operator, arrow functions for concise function expressions.</p><h3>The let Keyword</h3><p>ES6 introduces the new let keyword for declaring variables. Prior to ES6, the only way to declare a variable in JavaScript was the var keyword. Let&#39;s see what&#39;s the difference between them is.</p><p>There are two critical differences between the var and let. Variables declared with the var keyword are function-scoped or globally scoped (if declared outside of a function) and hoisted at the top within its scope, whereas variables declared with let keyword are block-scoped ({}) and they are not hoisted.</p><p>Block scoping simply means that a new scope is created between a pair of curly brackets i.e. {}.</p><pre>// Variable declared with &#39;var&#39; in ES5<br>var name = &quot;John&quot;;<br><br>function sayHello() {<br>  if (true) {<br>    var name = &quot;Alice&quot;;<br>    console.log(&quot;Inside if block:&quot;, name); // Inside if block: Alice<br>  }<br><br>  console.log(&quot;Outside if block:&quot;, name); // Outside if block: Alice<br>}<br><br>sayHello();<br><br>console.log(&quot;Global scope:&quot;, name); // Global scope: John<br></pre><pre>// Variable declared with &#39;let&#39; in ES6<br>let name = &quot;John&quot;;<br><br>function sayHello() {<br>  if (true) {<br>    let name = &quot;Alice&quot;; <br>    console.log(&quot;Inside if block:&quot;, name); // Inside if block: Alice<br>  }<br><br>  console.log(&quot;Outside if block:&quot;, name); // Outside if block: John<br>}<br><br>sayHello();<br><br>console.log(&quot;Global scope:&quot;, name); // Global scope: John</pre><h3>The const Keyword</h3><p>The const keyword is used to declare variables that cannot be reassigned after their initial assignment. It provides a way to create constants in JavaScript, making code more robust and self-explanatory. They are also block-scoped like let.</p><pre>const PI = 3.14;<br>console.log(PI); // 3.14<br>PI = 10; // error</pre><h3>The for...of Loop</h3><p>The for...of loop is a modern iteration construct introduced in ES6 (ECMAScript 2015) for easily looping through iterable objects such as arrays, strings, maps, sets, and more. It simplifies the process of iterating over elements compared to traditional for or for...in loops. Here&#39;s how to use it:</p><pre>// Iterating over an array<br>const fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;];<br>for (const fruit of fruits) {<br>  console.log(fruit);<br>}<br><br>// Iterating over a string<br>const sentence = &quot;Hello, World!&quot;;<br>for (const char of sentence) {<br>  console.log(char);<br>}<br><br>// Iterating over a Map<br>const myMap = new Map([<br>  [&quot;key1&quot;, &quot;value1&quot;],<br>  [&quot;key2&quot;, &quot;value2&quot;],<br>]);<br>for (const [key, value] of myMap) {<br>  console.log(`${key}: ${value}`);<br>}<br><br>// Iterating over a Set<br>const mySet = new Set([1, 2, 3, 2, 1]);<br>for (const number of mySet) {<br>  console.log(number);<br>}</pre><p>The for...of loop is particularly useful when working with collections of data and is preferred over traditional for loops when you need to iterate over the elements themselves rather than their indices or keys.</p><p>It doesn’t work for iterating over the properties of a plain JavaScript object. For iterating over object properties, you can use other techniques such as for...in or Object.keys(), Object.values(), or Object.entries() methods.</p><h3>Template Literals</h3><p>Template literals provide an easy and clean way create multi-line strings and perform string interpolation. Now we can embed variables or expressions into a string at any spot without any hassle.</p><p>Template literals are created using back-tick (` `) character instead of the usual double or single quotes. Variables or expressions can be placed inside the string using the ${...} syntax. Compare the following examples and see how much useful it is:</p><pre>// Simple multi-line string<br>let str = `The quick brown fox<br>    jumps over the lazy dog.`;<br><br>// String with embedded variables and expression<br>let a = 10;<br>let b = 20;<br>let result = `The sum of ${a} and ${b} is ${a+b}.`;<br>console.log(result); // The sum of 10 and 20 is 30.</pre><p>While in ES5, to achieve the same we had to write something like this:</p><pre>// Multi-line string<br>var str = &#39;The quick brown fox\n\t&#39;<br>    + &#39;jumps over the lazy dog.&#39;;<br><br>// Creating string using variables and expression<br>var a = 10;<br>var b = 20;<br>var result = &#39;The sum of &#39; + a + &#39; and &#39; + b + &#39; is &#39; + (a+b) + &#39;.&#39;;<br>console.log(result); // The sum of 10 and 20 is 30.</pre><h3>Default Values for Function Parameters</h3><p>In ES6 (ECMAScript 2015), you can set default values for function parameters, which allows you to specify a default value that will be used if an argument is not provided when calling the function. This feature makes it more convenient to handle optional parameters or provide fallback values. Here’s how to define default values for function parameters:</p><pre>function sayHello(name=&#39;World&#39;) {<br>    return `Hello ${name}!`;<br>}<br><br>console.log(sayHello()); // Hello World!<br>console.log(sayHello(&#39;John&#39;)); // Hello John!</pre><p>While in ES5, to achieve the same we had to write something like this:</p><pre>function sayHello(name) {<br>    var name = name || &#39;World&#39;; <br>    return &#39;Hello &#39; +  name + &#39;!&#39;;<br>}<br>console.log(sayHello()); // Hello World!<br>console.log(sayHello(&#39;John&#39;)); // Hello John!</pre><h3>Arrow Functions</h3><p>Arrow Functions are another interesting feature in ES6. It provide a concise and more readable way to write functions in JavaScript. They are particularly useful for defining functions that are short and don’t require complex logic.</p><p>Arrow functions are defined using a new syntax, the fat arrow (=&gt;) notation. Let&#39;s see how it looks:</p><pre>// Function Expression<br>const sum = function(a, b) {<br>    return a + b;<br>}<br>console.log(sum(2, 3)); // 5<br><br>// Arrow function<br>const sum = (a, b) =&gt; a + b;<br>console.log(sum(2, 3)); // 5</pre><p>As you can see there is no function and return keyword in arrow function declaration.</p><p>You can also skip the parentheses i.e. () in case when there is exactly one parameter, but you will always need to use it when you have zero or more than one parameter.</p><p>Additionally, if there’s more than one expression in the function body, you need to wrap it braces ({}). In this case you also need to use the return statement to return a value.</p><p>There are several variations of how you can write arrow functions. Here are the most commonly used:</p><pre>// Single parameter, single statement<br>var greet = name =&gt; console.log(&quot;Hi &quot; + name + &quot;!&quot;);<br>greet(&quot;Peter&quot;); // Hi Peter!<br><br>// Multiple arguments, single statement<br>var multiply = (x, y) =&gt; x * y;<br>console.log(multiply(2, 3)); // 6<br><br>// Single parameter, multiple statements<br>var test = age =&gt; {<br>    if(age &gt; 18) {<br>        console.log(&quot;Adult&quot;);<br>    } else {<br>        console.log(&quot;Teenager&quot;);<br>    }<br>}<br>test(21); // Adult<br>// Multiple parameters, multiple statements<br>var divide = (x, y) =&gt; {<br>    if(y != 0) {<br>        return x / y;<br>    }<br>}<br>console.log(divide(10, 2)); // 5<br>// No parameter, single statement<br>var hello = () =&gt; console.log(&#39;Hello World!&#39;);<br>hello(); // Hello World!</pre><h4>this with Arrow Function</h4><p>In normal functions, a this variable is created which references the objects that call them.</p><p>However, this is not associated with arrow functions. Arrow function does not have its own this. So whenever you call this, it refers to its parent scope. For example,</p><p><strong>Inside a regular function</strong></p><pre>const obj = {<br>  name: &#39;deeecode&#39;,<br>  age: 200,<br>  print: function() {<br>    console.log(this)<br>  }<br>}<br><br>obj.print()<br>// {<br>//   name: &#39;deeecode&#39;,<br>//   age: 200,<br>//   print: [Function: print]<br>// }</pre><p>As you can see here, the this in the print method points to obj, which is the object that calls the method.</p><p>Here’s another example:</p><pre>const obj = {<br>  name: &#39;deeecode&#39;,<br>  age: 200,<br>  print: function() {<br>    function print2() {<br>      console.log(this)<br>    }<br>    <br>    print2()<br>  }<br>}<br>obj.print()<br>// Window</pre><p>Here, we have two functions. The first one is print which is a method of the obj object. The second is print2 which is a function declared inside print. print2() is also called directly.</p><p>In this case, print is called by obj (obj.print()) but no object calls print2 (print2()). So the this in print2 would reference the window object by default.</p><p>Now let’s see what happens with an <strong>arrow function.</strong></p><pre>const obj = {<br>  name: &#39;deeecode&#39;,<br>  age: 200,<br>  print: () =&gt; {<br>    console.log(this)<br>  }<br>}<br>obj.print()<br>// Window</pre><p>By using an arrow function for print, this function does not automatically create a this variable. As a result, any reference to this would point to what this was before the function was created.</p><p>As you see in the result, this was pointing to the Window object before print was created.</p><p>Let’s see another example:</p><pre>const obj = {<br>  name: &#39;deeecode&#39;,<br>  age: 200,<br>  print: function() {<br>    const print2 = () =&gt; {<br>      console.log(this)<br>    }<br>    <br>    print2()<br>  }<br>}<br>obj.print()<br>// {<br>//   name: &#39;deeecode&#39;,<br>//   age: 200,<br>//   print: [Function: print]<br>// }</pre><p>Here, we have print as a normal function which means a this variable is automatically created in it. Then we have print2 which is an arrow function.</p><p>Because obj is calling print (as in obj.print()), the this in print would point to obj.</p><p>Since print2 is an arrow function, it doesn&#39;t create its own this variable. Therefore, any reference to this would point to what the value of this was before the function was created. In this case where obj calls print, this was pointing to obj before print2 was created. As you can see in the results, by logging this from print2, obj is the result.</p><h3>Modules</h3><p>Prior to ES6, there were no native support for modules in JavaScript. Everything inside a JavaScript application.</p><p>ES6 introduces file based module, in which each module is represented by a separate .js file. Now, you can use the export or import statement in a module to export or import variables, functions, classes or any other entity to/from other modules or files.</p><p>Let’s create a module i.e. a JavaScript file “main.js” and place the following code in it:</p><pre>let greet = &quot;Hello World!&quot;;<br>const PI = 3.14; <br><br>function multiplyNumbers(a, b) {<br>    return a * b;<br>}<br>// Exporting variables and functions<br>export { greet, PI, multiplyNumbers };</pre><p>Now create another JavaScript file “app.js” with the following code:</p><pre>import { greet, PI, multiplyNumbers } from &#39;./main.js&#39;;<br><br>console.log(greet); // Hello World!<br>console.log(PI); // 3.14<br>console.log(multiplyNumbers(6, 15)); // 90</pre><h3>The Rest Parameters</h3><p>ES6 introduces rest parameters that allow us to pass an arbitrary number of parameters to a function in the form of an array. This is particularly helpful in situations when you want to pass parameters to a function but you have no idea how many you will need.</p><p>To declare a rest parameter, you use three dots (...) followed by the parameter name. Rest parameters collect any additional arguments passed to the function into an array. Take a look at the following example, to see how it works:</p><pre>function sum(...numbers) {<br>  let result = 0;<br>  for (const num of numbers) {<br>    result += num;<br>  }<br>  return result;<br>}<br><br>console.log(sum(1, 2, 3, 4, 5)); // Output: 15</pre><p>When the rest parameter is the only parameter in a function, it gets all the arguments passed to the function, otherwise it gets the rest of the arguments that exceeds the number of named parameters.</p><pre>function myFunction(a, b, ...args) {<br>    return args;<br>}<br>console.log(myFunction(1, 2, 3, 4, 5)); // 3,4,5<br>console.log(myFunction(-7, 5, 0, -2, 4.5, 1, 3)); // 0,-2,4.5,1,3</pre><p><strong>Key Points:</strong></p><ol><li>Rest parameters must come after regular parameters in the function’s parameter list.</li><li>You can only have one rest parameter in a function.</li><li>Rest parameters are real arrays, so you can use array methods like map, filter, or forEach on them.</li><li>Rest parameters are useful when you want to accept an arbitrary number of arguments without having to specify each argument individually.</li></ol><h3>The Spread Operator</h3><p>The spread operator, which is also denoted by (...), performs the exact opposite function of the rest operator. The spread operator spreads out (i.e. splits up) an array and passes the values into the specified function, as shown in the following example:</p><pre>function addNumbers(a, b, c) {<br>    return a + b + c;<br>}<br><br>let numbers = [5, 12, 8];<br>// ES6 spread operator<br>console.log(addNumbers(...numbers)); // 25</pre><p>The spread operator can also be used to insert the elements of an array into another array without using the array methods like push(), unshift() concat(), etc.</p><pre>let pets = [&quot;Cat&quot;, &quot;Dog&quot;, &quot;Parrot&quot;];<br>let bugs = [&quot;Ant&quot;, &quot;Bee&quot;];<br><br>// Creating an array by inserting elements from other arrays<br>let animals = [...pets, &quot;Tiger&quot;, &quot;Wolf&quot;, &quot;Zebra&quot;, ...bugs];<br>console.log(animals); // Cat,Dog,Parrot,Tiger,Wolf,Zebra,Ant,Bee</pre><h3>Destructuring Assignment</h3><p>The destructuring assignment is an expression that makes it easy to extract values from arrays, or properties from objects, into distinct variables by providing a shorter syntax.</p><p>There are two kinds of destructuring assignment expressions — the <em>array</em> and <em>object</em> destructuring assignment. Well, let’s see how each of them exactly works:</p><h4>The array destructuring assignment</h4><p>Prior to ES6, to get an individual value of an array we need to write something like this:</p><pre>// ES5 syntax<br>var fruits = [&quot;Apple&quot;, &quot;Banana&quot;];<br>var a = fruits[0];<br>var b = fruits[1];<br>console.log(a); // Apple<br>console.log(b); // Banana</pre><p>In ES6, we can do the same thing in just one line using the array destructuring assignment:</p><pre>// ES6 syntax<br>let fruits = [&quot;Apple&quot;, &quot;Banana&quot;];<br>let [a, b] = fruits; // Array destructuring assignment<br>console.log(a); // Apple<br>console.log(b); // Banana</pre><p>You can also use rest operator in the array destructuring assignment, as shown here:</p><pre>// ES6 syntax<br>let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Mango&quot;];<br>let [a, ...r] = fruits;<br>console.log(a); // Apple<br>console.log(r); // Banana,Mango<br>console.log(Array.isArray(r)); // true</pre><h4>The object destructuring assignment</h4><p>In ES5 to extract the property values of an object we need to write something like this:</p><pre>// ES5 syntax<br>var person = {name: &quot;Peter&quot;, age: 28};<br>var name = person.name;<br>var age = person.age;<br>console.log(name); // Peter<br>console.log(age); // 28</pre><p>But in ES6, you can extract object’s property values and assign them to the variables easily like this:</p><pre>// ES6 syntax<br>let person = {name: &quot;Peter&quot;, age: 28};<br>let {name, age} = person; // Object destructuring assignment<br>console.log(name); // Peter<br>console.log(age); // 28</pre><h3>Conclusion:</h3><p>In conclusion, ES6, with its array of powerful features like arrow functions, template literals, and block-scoped variables, has fundamentally transformed JavaScript development. This evolution has empowered developers to write cleaner, more efficient, and maintainable code, contributing to the ongoing success and adaptability of JavaScript in the ever-evolving landscape of web development.</p><p>If you’ve made it till here, thanks for giving this a read, have a great day! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe24ebef8bed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sonarqube]]></title>
            <link>https://medium.com/@kevinmavani/sonarqube-cf2ff705d144?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf2ff705d144</guid>
            <category><![CDATA[sonarscanner]]></category>
            <category><![CDATA[code-analysis]]></category>
            <category><![CDATA[sonarqube]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Wed, 26 Jul 2023 18:06:00 GMT</pubDate>
            <atom:updated>2023-07-27T08:47:47.616Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*R2sUeks6r-6nhtGUej7Xbw.png" /></figure><p>SonarQube is an open-source platform developed by SonarSource for continuous inspection of code quality. It is primarily used for static code analysis to detect and manage code smells, bugs, vulnerabilities, and security vulnerabilities in software projects.</p><p>SonarQube integrates into the software development process and can be used during the development phase to ensure that code quality is maintained and improved over time. It provides developers and teams with feedback on their code, helping them identify potential issues early in the development cycle, which ultimately leads to higher-quality and more secure software.</p><p>Integrating SonarQube into an Angular project can bring several benefits to the development process and overall code quality. Here are some reasons why you should consider using SonarQube with your Angular project:</p><ul><li><strong>Code Quality Analysis:</strong> SonarQube performs static code analysis and identifies various issues, including code smells, bugs, security vulnerabilities, and more. By integrating it into your Angular project, you can receive detailed reports on the code quality and potential problems in your codebase. This helps you maintain high code quality and improve overall software reliability.</li><li><strong>Early Detection of Issues:</strong> SonarQube can be set up to run automatically as part of your continuous integration (CI) process. This means that code analysis will be performed with every code commit or pull request. By catching issues early in the development process, developers can address them sooner, reducing the cost and effort required to fix them later.</li><li><strong>Security Vulnerability Detection:</strong> Security is crucial in any software project. SonarQube includes security-focused rules to identify potential vulnerabilities in your Angular code. This helps you find and fix security weaknesses before they become serious threats.</li><li><strong>Maintainable Codebase:</strong> Sonarqube’s code analysis provides insights into code duplication and maintainability issues. By addressing these concerns, your Angular project can become more maintainable and easier to work with for the development team.</li><li><strong>Team Collaboration:</strong> SonarQube generates comprehensive reports that are easy to understand. These reports can be shared with the entire development team, encouraging collaboration and collective ownership of code quality.</li><li><strong>Continuous Improvement:</strong> SonarQube keeps track of historical data, allowing you to monitor code quality over time. By tracking improvements and regressions, your team can set goals for continuous improvement and measure progress.</li><li><strong>Customizable Rules:</strong> SonarQube allows you to customize rules to match your project’s specific requirements. This flexibility enables you to enforce coding standards and best practices that are tailored to your team and project.</li><li><strong>Integration with CI/CD:</strong> SonarQube can seamlessly integrate with your CI/CD pipeline, making it easy to automate code analysis as part of your development workflow. This ensures that code quality checks are consistently applied in the development process.</li></ul><p>Overall, integrating SonarQube into your Angular project can enhance the development process, reduce technical debt, and improve the overall quality and security of your software. It provides valuable feedback to developers, enabling them to create robust and reliable Angular applications.</p><h3><strong>Steps to integrate sonarqube in angular project</strong></h3><h4>Step 1: Install Sonarqube</h4><p>For installing Sonarqube first download the Sonarqube from <a href="https://www.sonarqube.org/downloads/">the official website</a></p><h4>Step 2: Configure Sonarqube with your Angular Project</h4><p>Run the following command</p><pre>npm i sonarqube-scanner --save-dev</pre><h4>Step 3: Configure the SonarQube properties file on the Angular project</h4><p>Create a file called sonar-project.properties in your Angular root directory and add the below attributes in the same file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e48e84fd2aa9bd6256d906922863b8f5/href">https://medium.com/media/e48e84fd2aa9bd6256d906922863b8f5/href</a></iframe><p>Now you want to run code coverage on the Angular project.</p><h4>Step 4: Integrate the Angular project’s code coverage with Sonarqube</h4><p>Add a script called sonar to your package.json, You can give any key name!</p><pre>&quot;scripts&quot;: {<br>    &quot;sonar&quot;: &quot;sonar-scanner&quot;<br>}</pre><p>Finally, run the below command to integrate the coverage with the Sonar server,</p><pre>npm run sonar</pre><h4>Step 5: Configure the project from the SonarQube server and start an analysis</h4><p>Once your sonar is started using the above command, hit this URL in your browser:</p><pre>http://localhost:9000/</pre><p><strong>How SonarQube Scanner communicates with the SonarQube server</strong></p><p>The SonarQube Scanner communicates with the SonarQube server through HTTP(S) requests using the SonarQube Web API. The communication follows a specific protocol defined by the SonarQube platform.</p><p>Here’s an overview of how the SonarQube Scanner communicates with the SonarQube server:</p><ol><li>Analysis Start: When you execute the SonarQube Scanner, it reads the configuration from the sonar-project.properties file and initiates the analysis process.</li><li>HTTP(S) Requests: As the analysis progresses, the SonarQube Scanner sends HTTP(S) requests to the SonarQube server’s API endpoints. These requests carry information about the analyzed code, such as source files, issues, metrics, and other relevant data.</li><li>SonarQube Server: The SonarQube server receives the HTTP(S) requests from the SonarQube Scanner and processes the incoming data.</li><li>Code Analysis: The SonarQube server performs the code analysis based on the received data and applies various static code analysis rules to identify code smells, bugs, security vulnerabilities, and other issues in the codebase.</li><li>Results Storage: The SonarQube server stores the analysis results, including code metrics, issues, and other relevant information, in its database.</li><li>Analysis Report: Once the analysis is complete, the SonarQube server generates an analysis report based on the stored data.</li><li>Response to Scanner: The SonarQube server sends a response back to the SonarQube Scanner, indicating the success or failure of the analysis and providing any relevant analysis details, such as the URL to view the analysis report.</li><li>View Analysis Results: If the analysis is successful, you can access the analysis report on the SonarQube server’s web interface to view the code quality metrics, identified issues, and other insights about your codebase.</li></ol><p>The communication between the SonarQube Scanner and the SonarQube server is essential for code quality analysis and reporting. It enables developers to identify and address code issues, improve code quality, and maintain high standards in their projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf2ff705d144" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to CSS]]></title>
            <link>https://medium.com/@kevinmavani/introduction-to-css-ebdece85539?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebdece85539</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 07:15:34 GMT</pubDate>
            <atom:updated>2023-07-04T06:08:17.497Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3W6xvur-ytMI6MKf" /><figcaption>Photo by <a href="https://unsplash.com/@pankajpatel?utm_source=medium&amp;utm_medium=referral">Pankaj Patel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>CSS (Cascading Style Sheets) is a stylesheet language used for describing the look and formatting of a document written in HTML. It provides a way to separate the content of a web page from its presentation, allowing you to control the layout, colors, fonts, and other visual aspects of your website.</p><p>The word <em>cascading</em> means that multiple style rules can be applied to the same HTML element. The browser follows a certain <em>cascading order </em>which is mostly from parent to child, in finalizing a style to format the HTML element in a predictable fashion.</p><p>The precedence order in CSS determines how conflicting styles are resolved when multiple rules target the same element. The following is the order of precedence, from highest to lowest:</p><ul><li>!important rule: Styles marked with the !important keyword override all other styles, regardless of their specificity or source order. However, it is generally recommended to use !important sparingly to avoid potential conflicts and maintainable code.</li></ul><p>Example:</p><pre>p {<br>  color: blue !important;<br>}</pre><ul><li>Inline styles: Styles defined directly within an HTML element using the style attribute have the highest precedence. Inline styles override all other styles for that specific element.</li></ul><p>Example:</p><pre>&lt;p style=&quot;color: red;&quot;&gt;This paragraph has inline style.&lt;/p&gt;</pre><ul><li>ID selectors: Styles defined using an ID selector have a higher precedence than element selectors and class selectors. An ID selector is prefixed with a hash (#) and targets a specific element with a unique ID.</li></ul><p>Example:</p><pre>#my-id {<br>  color: green;<br>}</pre><ul><li>Class selectors, attribute selectors, and pseudo-classes: Styles defined using class selectors (prefixed with a dot .), attribute selectors (e.g., [type=&quot;text&quot;]), or pseudo-classes (e.g., :hover, :nth-child()) have a lower precedence than ID selectors but higher than element selectors.</li></ul><p>Example:</p><pre>.my-class {<br>  color: purple;<br>}</pre><ul><li>Element selectors: Styles defined using element selectors (e.g., p, h1, div) have the lowest precedence. They apply to all elements of that type on the page unless overridden by more specific selectors.</li></ul><p>Example:</p><pre>p {<br>  color: orange;<br>}</pre><ul><li>Source order: When styles have equal precedence and specificity, the last rule defined in the CSS file or the latest imported stylesheet takes precedence. This rule is also known as the “cascading” aspect of CSS.</li></ul><p>Example:</p><pre>p {<br>  color: yellow;<br>}<br><br>p {<br>  color: brown;<br>}</pre><p>Example:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;CSS Precedence Example&lt;/title&gt;<br>    &lt;style&gt;<br>        /* Internal Styles */<br>        h1 {<br>            color: blue;<br>        }<br><br>        /* ID Selector */<br>        #heading {<br>            color: red;<br>        }<br><br>        /* Class Selector */<br>        .text {<br>            color: green;<br>        }<br><br>        /* Element Selector */<br>        p {<br>            color: yellow;<br>        }<br><br>        /* Specificity */<br>        #heading.text {<br>            color: purple;<br>        }<br><br>        /* Importance */<br>        .text {<br>            color: orange !important;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1 id=&quot;heading&quot; class=&quot;text&quot;&gt;Hello, World!&lt;/h1&gt;<br>    &lt;p class=&quot;text&quot;&gt;This is a paragraph.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In general, it is best to use specific selectors and avoid relying heavily on !important to maintain a clear and predictable style hierarchy. By understanding the precedence order, you can effectively manage conflicting styles and create consistent and maintainable CSS code.</p><p><strong>CSS Syntax</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*nKS7EAvrLL6W94Y4hRrD7Q.png" /></figure><p>The selector points to the HTML element you want to style.<br>The declaration block contains one or more declarations separated by semicolons.<br>Each declaration includes a CSS property name and a value, separated by a colon.<br>Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded by curly braces.</p><p><strong>How to add CSS<br></strong>There are three places where you can define style rules:</p><ol><li>Inline Style: Included inside a particular HTML opening tag’s via attribute style=&quot;<em>style-rules</em>&quot;. The rules are applicable to that particular HTML element only.</li><li>Internal (Embedded) Style Sheet: Embedded inside the &lt;style&gt;...&lt;/style&gt; tags in the HEAD section of the HTML document. The styles are applicable to that entire document.</li><li>External Style Sheet (Recommended): Stored in an external file, which is then linked to HTML documents via a &lt;link&gt; element in the HEAD section. The same external style sheet can be applied to all HTML pages in your website to ensure uniformity in appearance.</li></ol><p><strong>Note:</strong> Do not add a space between the property value (20) and the unit (px):<br>Incorrect (space): margin-left: 20 px;<br>Correct (no space): margin-left: 20px;</p><p><strong>Inline Style Sheet</strong></p><p>To apply inline style to an HTML element, include the list of style properties in the style attribute of the opening tag. For example,</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;body&gt;<br>  &lt;p style=&quot;font-size: 16px; font-family: monospace&quot;&gt;This paragraph uses 16px monospace font.&lt;/p&gt;<br>  &lt;p&gt;This paragraph uses default font.&lt;/p&gt;<br>  &lt;p&gt;This paragraph uses &lt;span style=&quot;font-size: 12px&quot;&gt;12px inside this span&lt;/span&gt;<br>  but default font size here.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*459rmltpRYbOIUcevXGl0Q.png" /></figure><p>Take note that the name and value are separated by colon &#39;:&#39;, and the name:value pair are separated by semicolon &#39;;&#39;, as specified in the CSS syntax.</p><p>The scope of an inline style is limited to that particular element. Inline style defeats the stated goal of style sheets, which is to separate the document’s content and presentation. Hence, inline style should be avoided and only be used sparsely for <em>touching up a document</em>, e.g., setting the column width of a particular table.</p><p><strong>Internal (Embedded) Style Sheet</strong></p><p>Embedded styles are defined within the &lt;style&gt;...&lt;/style&gt; tags in the HEAD section. For example,</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;style&gt;<br>    body {<br>      background-color: cyan;<br>    }<br>    h2 {<br>      color:white;<br>      background-color: black;<br>    }<br>    p.monospace {<br>      font-size: 16px;<br>      font-family: monospace;<br>    }<br>    p.f20px {<br>      font-size: 20px;<br>    }<br>  &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h2&gt;H2 is white on black&lt;/h2&gt;<br>  &lt;p&gt;This paragraph is normal.&lt;/p&gt;<br>  &lt;p class=&quot;monospace&quot;&gt;This paragraph uses 16-px monospace font.&lt;/p&gt;<br>  &lt;p class=&quot;f20px&quot;&gt;This paragraph uses 20-px font.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-AMr1cXqxlYkerAQRzpvEg.png" /></figure><ul><li>The scope of the embedded styles is the current HTML document.</li><li>Embedded styles separate the presentation and content (in the HEAD and BODY sections) and can be used if page-to-page uniformity is not required. That is, this set of styles is used for only one single page.</li></ul><p><strong>External Style Sheet</strong></p><p>The style rules are defined in an external file, and referenced in an HTML document via the &lt;link&gt; element in the HEAD section.</p><p>For example, we define these style rules in a file called “external.css&quot;:</p><pre>/* external.css */<br>body {<br>  background-color: cyan; <br>  color: red;<br>}<br>h2 {<br>  background-color: black;<br>  color: white;<br>  text-align: center;<br>}<br>p {<br>  font-size: 16px;<br>  font-variant: small-caps;<br>}<br>p.f24px {<br>  font-style: italic;<br>  font-size: 24px;<br>  text-indent: 1cm;<br>}<br>#green {<br>  color: green;<br>}</pre><p>This HTML document references the external style sheet via the &lt;link&gt; element in the HEAD section:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot;&gt;<br>  &lt;link href=&quot;external.css&quot; rel=&quot;stylesheet&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h2&gt;H2 is white on black&lt;/h2&gt;<br>  &lt;h2 id=&quot;green&quot;&gt;This H2 is green on black&lt;/h2&gt;<br>  &lt;p&gt;The default paragraph uses 16-px small-cap font.&lt;/p&gt;<br>  &lt;p class=&quot;f24px&quot;&gt;This paragraph uses 24-px, italics font with text-indent of 1cm.<br>  It inherits the small-cap property from the default paragraph selector.&lt;/p&gt;<br>&lt;/body&gt;&lt;/html&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQEp2oPPj52kfuWq_cUYkA.png" /></figure><p>You can use multiple &lt;link&gt; elements to include multiple CSS files.</p><p>The main advantage of external style sheets is that the same set of styles can be applied to all HTML pages in your website to ensure <em>uniformity</em> in presentation. External style sheet is the now-preferred approach.</p><p><strong>Linking to External Style Sheet using CSS </strong><strong>@import Directive</strong></p><p>Besides the HTML &lt;link&gt; element, you can also use CSS&#39;s @import directive to link to an external style sheet under the HTML &lt;style&gt; tags, as follows:</p><pre>&lt;!-- in HTML file --&gt;<br>&lt;style&gt;<br>  @import url(https://medium.com/&quot;cssURL1.css&quot;);<br>  @import url(https://medium.com/&quot;cssURL2.css&quot;);<br>&lt;/style&gt;</pre><p>@import is a CSS directive (part of CSS language). It can also be used in one CSS file to include rules from another CSS file, for example,</p><pre>/* in CSS fie */<br>@import &#39;/css/more-styles.css&#39;;<br><br>/* Import an external Google font */<br>@import &#39;https://fonts.googleapis.com/css?family=Open+Sans&#39;;</pre><p><a href="https://www.w3schools.com/cssref/css_selectors.php"><strong><em>CSS Selectors</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*yBK6MGcf3jz93CyIobwVAw.png" /></figure><h3><strong><em>Pseudo Class</em></strong>es</h3><p>Pseudo-classes (:) are primarily used to style an element that&#39;s under various states. When referring to state, this includes the condition or user behavior, for example hover, active, focus, or disabled. States generally involve user interaction.<br>For example, we can target all links to have a text color of lavender when the user hovers over the link.</p><pre>a:hover {<br>  color: lavender;<br>}</pre><ol><li>:not(selector)</li></ol><ul><li>Description: Selects elements that do not match the specified selector.</li><li>Example: p:not(.highlight) selects all &lt;p&gt; elements that do not have the class &quot;highlight&quot;.</li></ul><p>2. :is(selector1, selector2, …)</p><ul><li>Description: Selects elements that match any of the specified selectors.</li><li>Example: button:is(.primary, .secondary) selects all &lt;button&gt; elements with either the class &quot;primary&quot; or &quot;secondary&quot;.<br>Note: The :is() pseudo-class is well-supported in modern browsers. However, it was previously known as :matches(), so you might encounter code using the old name.</li></ul><p>3. :where()</p><ul><li>Description: :where() acts as a parent selector, it means that you can use :where() to group and apply styles to elements based on their parent elements.</li></ul><pre>div:where(:has(p)) {<br>  background-color: yellow;<br>}</pre><p>In this example, div:where(:has(p)) selects all &lt;div&gt; elements that have at least one &lt;p&gt; element as their child. The :has(p) part is a selector inside the :where() pseudo-class, indicating that the &lt;div&gt; elements should be styled if they contain a &lt;p&gt; element.</p><p>4. :has(selector)</p><ul><li>Description: Selects elements that contain at least one element matching the specified selector.</li><li>Example: div:has(p) selects all &lt;div&gt; elements that contain at least one &lt;p&gt; element.</li></ul><p>5. :empty</p><ul><li>Description: Selects elements that have no child nodes or text content.</li><li>Example: span:empty selects all &lt;span&gt; elements that have no content inside.</li></ul><p>6. :lang(language)</p><ul><li>Description: Selects elements with a specified language attribute.</li><li>Example: p:lang(fr) selects all &lt;p&gt; elements with the language attribute set to &quot;fr&quot; (French).</li></ul><p>7. :disabled</p><ul><li>Description: Selects form elements that are disabled.</li><li>Example: input:disabled selects all disabled &lt;input&gt; elements.</li></ul><p>8. :enabled</p><ul><li>Description: Selects form elements that are enabled.</li><li>Example: input:enabled selects all enabled &lt;input&gt; elements.</li></ul><p>9. :checked</p><ul><li>Description: Selects input elements that are checked (e.g., checkboxes or radio buttons).</li><li>Example: input:checked selects all checked &lt;input&gt; elements.</li></ul><p>10. :required</p><ul><li>Description: Selects input elements that are required.</li><li>Example: input:required selects all required &lt;input&gt; elements.</li></ul><h3><strong><em>Pseudo Elements</em></strong></h3><p>Pseudo-elements are used to style specific parts of an element’s content or structure, and they are denoted by a double colon (::) notation in CSS.<br>List of commonly used pseudo-elements:</p><ol><li>::before</li></ol><ul><li>Description: Inserts content before the selected element.</li><li>Example: p::before allows you to insert content before every &lt;p&gt; element.</li></ul><p>2. ::after</p><ul><li>Description: Inserts content after the selected element.</li><li>Example: a::after allows you to insert content after every &lt;a&gt; element.</li></ul><p>3. ::first-line</p><ul><li>Description: Selects the first line of text within an element.</li><li>Example: p::first-line allows you to style the first line of text within every &lt;p&gt; element.</li></ul><p>4. ::first-letter</p><ul><li>Description: Selects the first letter of text within an element.</li><li>Example: h1::first-letter allows you to style the first letter of text within every &lt;h1&gt; element.</li></ul><p>5. ::selection</p><ul><li>Description: Applies styles to a portion of text selected by the user.</li><li>Example: ::selection allows you to apply styles to the selected text within an element.</li></ul><p>6. ::placeholder</p><ul><li>Description: Styles the placeholder text within an input or textarea element.</li><li>Example: input::placeholder allows you to style the placeholder text within an &lt;input&gt; element.</li></ul><p>7. ::marker</p><ul><li>Description: Styles the marker of a list item (e.g., bullet or number).</li><li>Example: li::marker allows you to style the marker of every &lt;li&gt; element.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebdece85539" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML tags]]></title>
            <link>https://medium.com/@kevinmavani/html-tags-6fff2bdcc19b?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fff2bdcc19b</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-design]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 07:34:49 GMT</pubDate>
            <atom:updated>2023-06-16T07:34:49.456Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XMM7ygXiFTK1ThLW" /><figcaption>Photo by <a href="https://unsplash.com/de/@jacksonsophat?utm_source=medium&amp;utm_medium=referral">Jackson Sophat</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Table:</strong></p><p>The &lt;table&gt; tag is used to create a tabular structure in HTML. It represents a set of data organized into rows and columns. The table consists of several elements that define its structure, including &lt;tr&gt; (table row), &lt;th&gt; (table header cell), and &lt;td&gt; (table data cell).</p><ol><li>Table Structure:</li></ol><ul><li>The &lt;table&gt; tag is the main container for creating a table in HTML.</li><li>It is a block-level element that encloses the entire table structure.</li><li>Inside the &lt;table&gt; element, you define the rows and cells that make up the table.</li></ul><p>2. Table Rows:</p><ul><li>Rows are created using the &lt;tr&gt; (table row) element.</li><li>Each &lt;tr&gt; element represents a single row within the table.</li><li>Multiple &lt;tr&gt; elements can be used to create multiple rows in the table.</li></ul><p>3. Table Cells:</p><ul><li>Cells are defined using the &lt;th&gt; (table header cell) or &lt;td&gt; (table data cell) elements.</li><li>&lt;th&gt; elements are typically used in the first row (&lt;tr&gt;) to define the header cells of the table.</li><li>&lt;td&gt; elements are used in subsequent rows to hold the data cells of the table.</li></ul><p>4. Table Header and Data Cells:</p><ul><li>The &lt;th&gt; element is used to create header cells that provide column headings or titles.</li><li>The &lt;td&gt; element is used to create data cells that hold the actual data within the table.</li></ul><p>5. Table Caption:</p><ul><li>You can optionally include a caption for the table using the &lt;caption&gt; element.</li><li>The &lt;caption&gt; element is placed immediately after the opening &lt;table&gt; tag and before the first &lt;tr&gt; tag.</li><li>The caption provides a brief description or title for the table.</li></ul><p>6. Table Structure Elements:</p><ul><li>Additional elements can be used to define the structure and formatting of the table.</li><li>&lt;thead&gt;, &lt;tbody&gt;, and &lt;tfoot&gt; elements can be used to group rows into header, body, and footer sections, respectively.</li><li>The &lt;colgroup&gt; and &lt;col&gt; elements allow you to define column-specific properties, such as width or formatting.</li></ul><p>Here’s an expanded example that includes a caption and the use of the &lt;thead&gt;, &lt;tbody&gt;, and &lt;tfoot&gt; elements:</p><pre>&lt;table&gt;<br>  &lt;caption&gt;Product Prices&lt;/caption&gt;<br>  &lt;thead&gt;<br>    &lt;tr&gt;<br>      &lt;th&gt;Product&lt;/th&gt;<br>      &lt;th&gt;Price&lt;/th&gt;<br>      &lt;th&gt;Quantity&lt;/th&gt;<br>    &lt;/tr&gt;<br>  &lt;/thead&gt;<br>  &lt;tbody&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Apple&lt;/td&gt;<br>      &lt;td&gt;$1.00&lt;/td&gt;<br>      &lt;td&gt;10&lt;/td&gt;<br>    &lt;/tr&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Orange&lt;/td&gt;<br>      &lt;td&gt;$0.80&lt;/td&gt;<br>      &lt;td&gt;8&lt;/td&gt;<br>    &lt;/tr&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Banana&lt;/td&gt;<br>      &lt;td&gt;$0.50&lt;/td&gt;<br>      &lt;td&gt;15&lt;/td&gt;<br>    &lt;/tr&gt;<br>  &lt;/tbody&gt;<br>  &lt;tfoot&gt;<br>    &lt;tr&gt;<br>      &lt;td colspan=&quot;2&quot;&gt;Total&lt;/td&gt;<br>      &lt;td&gt;33&lt;/td&gt;<br>    &lt;/tr&gt;<br>  &lt;/tfoot&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*10g49aTAs4AtOzn30BFgAg.png" /></figure><p>Here’s an example of <strong>&lt;colgroup&gt;</strong> and <strong>&lt;col&gt;</strong> elements:</p><p>&lt;colgroup&gt;:</p><ul><li>The &lt;colgroup&gt; element is used to group together and define properties for one or more columns in a table.</li><li>It is placed inside the &lt;table&gt; element but typically before the &lt;thead&gt;, &lt;tbody&gt;, and &lt;tfoot&gt; sections.</li><li>The &lt;colgroup&gt; element can contain one or more &lt;col&gt; elements to specify properties for each column.</li><li>Attributes such as span, style, and class can be applied to the &lt;colgroup&gt; element to control the appearance and behavior of the grouped columns.</li></ul><p>&lt;col&gt;:</p><ul><li>The &lt;col&gt; element is used within the &lt;colgroup&gt; element to define properties for individual columns.</li><li>It allows you to apply styles or attributes to specific columns, such as width, background color, or other CSS properties.</li><li>Each &lt;col&gt; element corresponds to a column in the table.</li><li>Attributes such as span, style, and class can be applied to the &lt;col&gt; element to specify properties for the column.</li></ul><pre>&lt;table&gt;<br>  &lt;colgroup&gt;<br>    &lt;col span=&quot;2&quot; style=&quot;background-color: lightblue;&quot;&gt;<br>    &lt;col style=&quot;background-color: lightgreen;&quot;&gt;<br>  &lt;/colgroup&gt;<br>  &lt;thead&gt;<br>    &lt;tr&gt;<br>      &lt;th&gt;Product&lt;/th&gt;<br>      &lt;th&gt;Price&lt;/th&gt;<br>      &lt;th&gt;Quantity&lt;/th&gt;<br>    &lt;/tr&gt;<br>  &lt;/thead&gt;<br>  &lt;tbody&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Apple&lt;/td&gt;<br>      &lt;td&gt;$1.00&lt;/td&gt;<br>      &lt;td&gt;10&lt;/td&gt;<br>    &lt;/tr&gt;<br>    &lt;tr&gt;<br>      &lt;td&gt;Orange&lt;/td&gt;<br>      &lt;td&gt;$0.80&lt;/td&gt;<br>      &lt;td&gt;8&lt;/td&gt;<br>    &lt;/tr&gt;<br>  &lt;/tbody&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*-uM9EJtd5OaTt30r9fTK9g.png" /></figure><p>Here are the <strong><em>attributes</em></strong> commonly used with the &lt;table&gt; tag in HTML and their descriptions:</p><ol><li>border: Specifies the width of the border around the table and its cells. This attribute is deprecated in HTML5, and it&#39;s recommended to use CSS for styling borders instead.</li><li>align: Specifies the horizontal alignment of the table in relation to the surrounding content. Possible values are left, center, or right.</li><li>bgcolor: Sets the background color of the table. It accepts color values in various formats, such as color names (e.g., red, blue), hexadecimal codes (e.g., #FF0000), or RGB values (e.g., rgb(255, 0, 0)).</li><li>bordercolor: Sets the color of the table&#39;s border. It accepts color values in the same formats as the bgcolor attribute.</li><li>cellpadding: Specifies the padding (space) within each cell. It defines a uniform amount of space inside all cells of the table.</li><li>cellspacing: Specifies the spacing between cells. It defines the space between adjacent cells in the table.</li><li>summary: Provides a summary or description of the table&#39;s purpose and structure. It is used for accessibility purposes to provide additional information to assistive technologies.</li><li>width: Specifies the width of the table. It can be specified in pixels (px) or as a percentage (%) of the available width.</li></ol><p>Note that the following attributes are typically used with child elements (&lt;th&gt; and &lt;td&gt;) within the table rather than directly on the &lt;table&gt; tag itself:</p><ol><li>colspan: Specifies the number of columns a cell should span. It allows a cell to stretch across multiple columns horizontally.</li><li>rowspan: Specifies the number of rows a cell should span. It allows a cell to stretch across multiple rows vertically.</li></ol><p>These attributes provide control over the structure, appearance, and accessibility of the table. It’s important to note that some attributes, such as border and many more have been deprecated in HTML5, and it&#39;s recommended to use CSS for styling instead.</p><p>Here’s an example that demonstrates the use of some of these attributes:</p><pre>&lt;table border=&quot;1&quot; cellpadding=&quot;10&quot; cellspacing=&quot;5&quot; summary=&quot;Product prices&quot;&gt;<br>  &lt;tr&gt;<br>    &lt;th colspan=&quot;2&quot;&gt;Product&lt;/th&gt;<br>    &lt;th&gt;Price&lt;/th&gt;<br>    &lt;th&gt;Quantity&lt;/th&gt;<br>  &lt;/tr&gt;<br>  &lt;tr&gt;<br>    &lt;td rowspan=&quot;2&quot;&gt;Apple&lt;/td&gt;<br>    &lt;td&gt;Red&lt;/td&gt;<br>    &lt;td&gt;$1.00&lt;/td&gt;<br>    &lt;td&gt;10&lt;/td&gt;<br>  &lt;/tr&gt;<br>  &lt;tr&gt;<br>    &lt;td&gt;Green&lt;/td&gt;<br>    &lt;td&gt;$0.80&lt;/td&gt;<br>    &lt;td&gt;8&lt;/td&gt;<br>  &lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yApDgNJfI8liUAMZXHRHg.png" /></figure><p><strong>List:</strong></p><ol><li>&lt;ul&gt; (Unordered List):</li></ol><ul><li>Description: The &lt;ul&gt; tag represents an unordered list, which is a list of items that are not sequentially ordered. By default, each item in the list is preceded by a bullet point.</li><li>Attributes:<br>type: Specifies the type of bullet used for list items. Possible values are disc, circle, or square.<br>start: Specifies the starting number of the first item in the list.</li></ul><p>2. &lt;ol&gt; (Ordered List):</p><ul><li>Description: The &lt;ol&gt; tag represents an ordered list, which is a list of items that are sequentially ordered. By default, each item in the list is numbered.</li><li>Attributes:<br>type: Specifies the type of numbering used for list items. Possible values are 1, A, a, I, or i.<br>start: Specifies the starting number of the first item in the list.</li></ul><p>3. &lt;li&gt; (List Item):</p><ul><li>Description: The &lt;li&gt; tag represents an individual item in a list. It must be nested within either &lt;ul&gt; or &lt;ol&gt; tags to create an unordered or ordered list, respectively.</li><li>Attributes: None.</li></ul><pre>&lt;h3&gt;Unordered list&lt;/h3&gt;<br>  &lt;ul type=&quot;square&quot;&gt;<br>    &lt;li&gt;Item 1&lt;/li&gt;<br>    &lt;li&gt;Item 2&lt;/li&gt;<br>    &lt;li&gt;Item 3&lt;/li&gt;<br>  &lt;/ul&gt;<br><br>  &lt;h3&gt;Ordered list&lt;/h3&gt;<br>  &lt;ol type=&quot;I&quot;&gt;<br>    &lt;li&gt;First item&lt;/li&gt;<br>    &lt;li&gt;Second item&lt;/li&gt;<br>    &lt;li&gt;Third item&lt;/li&gt;<br>  &lt;/ol&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*ZG5U-iA0k16kA_g_6bQqGg.png" /></figure><p>4. &lt;dl&gt; (Definition List):</p><ul><li>Description: The &lt;dl&gt; tag represents a definition list, which consists of terms and their corresponding definitions. Each term is represented by a &lt;dt&gt; (Definition Term) tag, and each definition is represented by a &lt;dd&gt; (Definition Description) tag.</li><li>Attributes: None</li></ul><pre>&lt;dl&gt;<br>  &lt;dt&gt;HTML&lt;/dt&gt;<br>  &lt;dd&gt;The markup language used for creating web pages.&lt;/dd&gt;<br>  &lt;dt&gt;CSS&lt;/dt&gt;<br>  &lt;dd&gt;The language used for styling web pages.&lt;/dd&gt;<br>&lt;/dl&gt;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*GP_TVmpXjVJsoOIiZTZlRA.png" /></figure><p>These list-related tags provide semantic structure to your content, allowing you to present information in a well-organized manner. Whether you need an unordered list with bullet points, an ordered list with numbers, or a definition list with term-description pairs, these tags enable you to present your content in a clear and organized manner.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fff2bdcc19b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML head section]]></title>
            <link>https://medium.com/@kevinmavani/html-head-section-1874563ae939?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/1874563ae939</guid>
            <category><![CDATA[open-graph]]></category>
            <category><![CDATA[head]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[meta]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Fri, 26 May 2023 06:19:08 GMT</pubDate>
            <atom:updated>2023-05-26T09:28:49.268Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*77oCc0qUrD0kIRq8" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The HTML header (or &lt;head&gt;) section is an essential part of an HTML document. It is located between the opening &lt;html&gt; tag and the opening &lt;body&gt; tag. The header contains metadata and other information about the HTML document, which is not directly displayed on the web page but provides instructions and details to the browser and search engines.</p><p>Here are some key elements commonly found in the HTML header:</p><p><strong>1. &lt;title&gt;</strong>: The title tag is your main and most important anchor and it defines the title of the HTML document, which appears in the title bar of the browser window or in the tab for that page. The &lt;title&gt; element typically appears as a clickable headline in the Search Engine Result Page(SERPs).</p><pre>&lt;title&gt;10 Most Important Meta Tags for SEO&lt;/title&gt;</pre><p>Title tags are placed in the &lt;head&gt; of your webpage and are meant to provide a clear and comprehensive idea of what the page is all about.</p><p><strong>2. &lt;meta&gt;</strong>:<br>Meta tags also resides in the &lt;head&gt; of a webpage and is commonly displayed in a SERP snippet along with a title and page URL.</p><p>The &lt;meta&gt; tag is used to provide metadata or additional information about an HTML document. It is placed within the &lt;head&gt; section of the HTML document. Here are some commonly used attributes within the &lt;meta&gt; tag:</p><ul><li>charset: Specifies the character encoding for the HTML document, such as UTF-8.</li></ul><pre>&lt;meta charset=&quot;UTF-8&quot;&gt;</pre><p>The charset=utf-8 attribute/value pair in the &lt;meta&gt; tag is used to specify the character encoding for the HTML document. It indicates that the document should be interpreted and displayed using the UTF-8 character encoding scheme.</p><ul><li>name and content: These attributes are used together to provide specific metadata information. The name attribute defines the type or name of the metadata, and the content attribute provides the corresponding value. Some commonly used combinations include:</li><li>description: Specifies a brief description of the webpage. It is often used by search engines to display a summary of the page in search results. For example:</li></ul><pre>&lt;meta name=&quot;description&quot; content=&quot;Some tags are vital for SEO. Others have little or no impact on rankings. Here&#39;s every type of meta tag you need to know about.The purpose of a meta description is to reflect the essence of a page, but with more details and context.&quot;/&gt;</pre><ul><li>keywords: Specifies a comma-separated list of relevant keywords. The meta-keyword tag is not used by Google Search, and it has no effect on indexing and ranking at all. For example:</li></ul><pre>&lt;meta name=&quot;keywords&quot; content=&quot;gardening, tips, plants, flowers, vegetables&quot;&gt;</pre><ul><li>viewport: viewport meta tag allows you to configure how a page would be scaled and displayed on any device. Helps to control the layout and behavior of the webpage on different devices and screen sizes.</li></ul><pre>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;/&gt;</pre><p>Where “width=device-width” will make the page match the screen’s width in device-independent pixels, and “initial scale=1” will establish a 1:1 relationship between CSS pixels and device-independent pixels, taking screen orientation into account.</p><ul><li>author: Indicates the author of the document.</li></ul><pre>&lt;meta name=&quot;author&quot; content=&quot;Kevin&quot;&gt;</pre><ul><li>robots: A robots meta tag which instructs the search engine crawler not to index a page, or follow any links on it</li></ul><pre>&lt;meta name=&quot;robots&quot; content=&quot;noindex,nofollow&quot;&gt;</pre><p>If you don’t add a robots meta tag, the default for crawlers is to index and follow your page.</p><p>Why would you need to use this meta tag? It might be that you have some pages on your site which are necessary, but quite thin content-wise. You don’t necessarily want them to be indexed in search, but they’re still important to the site, so you can use a <a href="https://www.searchenginewatch.com/2019/07/17/the-most-common-seo-errors-research-infographics/"><strong>noindex</strong></a> tag to prevent them from appearing in the SERPs.</p><p><strong>http-equiv</strong>:</p><pre>&lt;meta http-equiv=&quot;refresh&quot; content=&quot;delay_time; URL=new_website_url&quot; /&gt;</pre><ul><li>http-equiv=&quot;refresh&quot;: The &lt;meta&gt; tag contains two attributes, http-equiv and content. The value of http-equiv is always <strong>refresh</strong> — this tells the browser that you want to automatically refresh the page.</li></ul><p>Next, the content attribute takes two values:</p><ul><li>delay_time is a numeric value that sets the delay before the browser loads the new web page. For instance, a value of 3 would make the browser wait three seconds on the old page before redirecting.</li><li>new_website_url is the URL of the web page you want to redirect to.</li></ul><p>Be sure to place these two values for content inside one pair of double quotes, separated by a semicolon. Otherwise, the redirect will not work.</p><p><strong>3. &lt;link&gt;</strong>: This tag is used to include external resources, such as CSS stylesheets, favicons. The rel attribute specifies the relationship between the current document and the linked resource.</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt;<br>&lt;link rel=&quot;preconnect&quot; href=&quot;https://www.google.com&quot;&gt;</pre><p><strong>4. &lt;style&gt;</strong>: This tag is used to define CSS styles directly within the HTML document. It can be used to modify the appearance and layout of elements on the page.</p><p><strong>5. &lt;script&gt;</strong>: The &lt;script&gt; tag is used to embed or reference JavaScript code within the HTML document. It can be placed in the header or the body section, depending on the specific requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*WdYxien-TBZTcNgVErT-cw.png" /></figure><p><strong>6. &lt;base&gt;</strong>:</p><pre>&lt;base href=&quot;https://www.example.com/&quot;&gt;</pre><p>For instance, if you have an image with the source &lt;img src=&quot;images/pic.jpg&quot;&gt;, the browser will resolve the URL relative to the base URL specified in the &lt;base&gt; tag. In this example, the image would be loaded from <a href="https://www.example.com/images/pic.jpg.">https://www.example.com/images/pic.jpg.</a></p><p>By setting the base URL using the &lt;base&gt; tag, you establish a common reference point for all relative URLs within the HTML document. This simplifies the process of linking to resources and ensures consistent behavior across the webpage.</p><p>It’s important to note that there should be only one &lt;base&gt; tag per HTML document, and it should be placed within the &lt;head&gt; section. Additionally, the &lt;base&gt; tag is optional, and if it is not included, the base URL for relative URLs is typically the URL of the current webpage.</p><h3>Social Media Meta Tags</h3><p>Open Graph was initially introduced by Facebook to let you control how a page would look when shared on social media.</p><p>Here are the main Open Graph tags:</p><ul><li><strong>og:title</strong> — here you put the title which you want to be displayed when your page is linked to.</li><li><strong>og:url</strong> — your page’s URL.</li><li><strong>og:description</strong> — your page’s description. Remember that Facebook will display only about 300 characters of description.</li><li><strong>og:image</strong> — here you can put the URL of an image you want to be shown when your page is linked to.</li></ul><p>Use the specific social media meta tags in order to boost how your links look to your following.</p><p>It doesn’t influence your rankings on the search engines. However, by configuring how the links to your pages look, you can greatly boost your CTR.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1874563ae939" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Component in Angular]]></title>
            <link>https://medium.com/bitsrc/web-component-in-angular-8678989f4892?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/8678989f4892</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[html-import]]></category>
            <category><![CDATA[angular-bootstrap]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[gulp]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Wed, 24 May 2023 18:47:45 GMT</pubDate>
            <atom:updated>2023-06-16T08:44:27.186Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I6ehIOT7seMOJFbdgGYI0w.png" /></figure><h3>Web Components in Angular</h3><p>Web components are analogous to plugins. As we all know plugins are useful to provide a subset of features that extends the original application. Similar to that web components are used when we want to provide a subset of our application as embedded functionality to third-party applications.</p><p>For example, you might have seen some news sites that use embedded tweets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQ8YUAer50P6bW4_YSXrng.png" /><figcaption><a href="https://timesofindia.indiatimes.com/gadgets-news/top-twitter-moments-of-2021-these-tweets-of-pm-narendra-modi-ratan-tata-and-virat-kohli-top-the-list/articleshow/88184203.cms">Top Twitter Moments of 2021</a></figcaption></figure><p>To understand how web component works let us dive into how angular application bootstrap on the client browser.</p><ol><li>As every web application angular too have an entry point which is index.html. which is loaded into the browser first.</li><li>when the browser parses index.html it finds link to below scripts to load<br>polyfills.js – Polyfill scripts for supporting the variety of the latest modern browsers<br>styles.css – This file contains the global style rules bundled as a css file.<br>scripts.js – This file contains the global script rules bundled as a javascript file.<br>main.js – code of the application.<br>runtime.js: Webpack runtime file</li><li>When all the js and css are loaded, angular core initializes services, routes and finds main.ts and bootstrap the application with the component that is suggested by main.ts which is typically app.component.ts.</li></ol><p>Now when web components are used similar procedure is followed except in 3rd step angular bootstrap only with the component selector used in third-party application.</p><p><strong>Steps to integrate web component in angular</strong></p><ol><li>First of all, we need to create web-component.html as entry point to our web component and add it to assets in angular.json file so it’s copied to dist.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*ZAR-6Tm7iLzGW_DuCyu4VA.png" /></figure><p>web-component.html file contains the below snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3952eae0be67c66e6325a6d9323677a0/href">https://medium.com/media/3952eae0be67c66e6325a6d9323677a0/href</a></iframe><p>2. When we build an angular application, build process modifies index.html and inserts scripts and styles tags in it. To do the similar for our web-component.html file we use gulp which is a build task automation tool.</p><p>you can find more about gulp <a href="https://www.npmjs.com/package/gulp"><strong>here</strong></a><strong>.</strong></p><p>create gulpfile.js at the root and add the below snippet in it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88727597435b598aac55f9118cf534db/href">https://medium.com/media/88727597435b598aac55f9118cf534db/href</a></iframe><p>3. In package.json add the below scripts to run gulp task after the build.</p><pre>&quot;scripts&quot;: {<br>    &quot;gulp-add-pre-compiled-scripts&quot;: &quot;echo \&quot;Executing gulp command to add pre compiled scripts into web-component.html ...\&quot; &amp;&amp; gulp --color add-compiled-scripts-to-web-component-html&quot;,<br>    &quot;build&quot;: &quot;echo \&quot;Building app\&quot; &amp;&amp; ng build &amp;&amp; npm run gulp-add-pre-compiled-scripts&quot;,<br>}</pre><p>After the gulp task is successfully completed web-component.html file will look like below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3068ad7d215f58c7e46fc7a904acc767/href">https://medium.com/media/3068ad7d215f58c7e46fc7a904acc767/href</a></iframe><p>4. Now in order to use in third-party application, we need to inject our web-component.html file into another webpage we use html imports to parse our html file and load necessary js and css files.</p><p>create html-imports.min.js inside assets/js and the below I have attach the gist link of html-import js library code for reference. So copy the snippet inside it and paste it in the above created html-imports.min.js file.</p><p><a href="https://gist.github.com/vc-kevin/c4bcdb20140b2378855618ecbd0ef7bc"><strong>html-imports.min.js</strong></a></p><p>5. Our web component is ready to be embedded in any web application We just need to include a link to our web-component.html, html-imports, and put selected our component in a third-party web page at the desired place.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32d595781c02a2d5bab7106d8736fa7a/href">https://medium.com/media/32d595781c02a2d5bab7106d8736fa7a/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8678989f4892" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/web-component-in-angular-8678989f4892">Web Component in Angular</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular HttpClient]]></title>
            <link>https://medium.com/@kevinmavani/angular-httpclient-1f4eb6ff3785?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f4eb6ff3785</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[http-client]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[http-headers]]></category>
            <category><![CDATA[interceptors]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 09:46:45 GMT</pubDate>
            <atom:updated>2023-05-26T06:51:02.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XmX4L7_uzZYdER_d" /><figcaption>Photo by <a href="https://unsplash.com/@dynamicwang?utm_source=medium&amp;utm_medium=referral">Dynamic Wang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Why Do We Need HttpClient?</h3><p>The front-end of applications communicates with back-end services to get or send the data over HTTP protocol using either XMLHttpRequest interface or fetch API. This communication is done in Angular with the help of HttpClient.</p><h3>What Is HttpClient?</h3><p>HttpClient is a built-in service class available in the @angular/common/http package. It has multiple signatures and returns types for each request. It uses the RxJS observable-based APIs, which means it returns the observable and what we need to subscribe to it. This API was developed based on XMLHttpRequest the interface exposed by browsers.</p><p>Here are some key things to bear in mind regarding this particular type of Observables returned by the HTTP module:</p><ul><li>if we don’t subscribe to these observables, nothing will happen</li><li>if we subscribe multiple times to these observables, multiple HTTP requests will be triggered</li><li>This particular type of Observable are single-value stream: If the HTTP request is successful, these observables will emit only one value and then complete</li><li>these observables will emit an error if the HTTP request fails.</li></ul><h3>Features of HttpClient</h3><ul><li>Provides typed request and response objects</li><li>Intercepts request and response</li><li>Supports RxJS observable-based APIs</li><li>Supports streamlined error handling</li><li>Performs the GET, POST, PUT, and DELETE operations</li></ul><h3>Making HttpClient Available In The Project</h3><p>To be able to use the <em>HttpClient</em> service within your components we first need to include the <em>HttpClientModule</em> in the Angular application. First, we need to import the <em>HttpClient</em> module in the application’s root module in the file <em>app.module.ts</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04e3c76ad60d1407fd7088f7b8efb2fc/href">https://medium.com/media/04e3c76ad60d1407fd7088f7b8efb2fc/href</a></iframe><p>Once imported you can make use of <em>HttpClient</em> in your components. To make <em>HttpClient</em> available in the component class you need to inject it into the class constructor as you can see in the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dd6d651bb086f127ab616d7a6b7d0eb/href">https://medium.com/media/2dd6d651bb086f127ab616d7a6b7d0eb/href</a></iframe><h3>HTTP GET Request</h3><p>HttpClient.get() method is an asynchronous method that performs an HTTP get request in Angular applications and returns an Observable. And that Observable emits the requested data when the response is received from the server.</p><p>Let’s implement a simple example that uses GitHub’s REST API to request user data. Insert the following code in the file <em>app.component.ts</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5c5d9de8db3240651bf2e58907f0742/href">https://medium.com/media/b5c5d9de8db3240651bf2e58907f0742/href</a></iframe><p>The output which is displayed in the browser console should look like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXcjdr5zaFpSC56FcbK4lg.png" /></figure><p>The results show that it’s possible to directly access the JSON response by subscribing to the Observable which is returned from the <em>get</em> method.</p><h3>Typed Response</h3><p>From the console output, you can see that the returned JSON object has a lot of properties. If you now try to access one of those properties by using the dot notation you’ll get back an error:</p><p>console.log(data.login);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TAewhHvzqXyTvE9-Nkclg.png" /></figure><p>The error message is saying: <em>“Property &#39;login&#39; does not exist on type &#39;Object&#39;”</em>. As data is of type Object you can not access properties directly. However, we&#39;re able to cast the response Object to a type which is containing the corresponding properties. Let&#39;s define an interface type which is containing some of the properties which are part of the response:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c182d72dcd35a83a83b3c2151e3b581/href">https://medium.com/media/8c182d72dcd35a83a83b3c2151e3b581/href</a></iframe><p>Next, let’s make use of <em>UserResponse</em> to cast the return type of the <em>get</em> call:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7229d3cda549e384244c4fa3ef9fffed/href">https://medium.com/media/7229d3cda549e384244c4fa3ef9fffed/href</a></iframe><p>Accessing the values by using <em>data.login</em>, <em>data.bio</em> and <em>data.company</em> is possible now. The output in the browser console should now deliver the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*Aqg9AVFhFjNBFK4syBjFkg.png" /></figure><h3>HTTP Request Parameters</h3><p>The HTTP GET can also receive parameters, that correspond to the parameters in the HTTP URL. Let’s take for example the following URL with id parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*fQtn619GBOfA-oIf1DTw2w.png" /></figure><p>This above query returns the same result as before. This is how we would do this query using the Angular HTTP Client:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7190058847c8db2a58b680a34a40e8e/href">https://medium.com/media/c7190058847c8db2a58b680a34a40e8e/href</a></iframe><p>Notice that we are building the HTTPParams object by chaining successive set() methods. This is because HTTPParams is immutable, and its API methods do not cause object mutation.</p><h3>HTTP Headers</h3><p>Almost every HTTP request including headers. Sometimes, REST API servers required additional header parameters on every request. For example, the secured REST API endpoint is only accessible with an Authorization header token, the specific REST API request uses a different type of response by determining the type from the HTTP headers.</p><p>If we want to add custom HTTP Headers to our HTTP request, in addition to the headers the browser already attaches automatically we can do so using the HttpHeaders class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e655750ec56b345c4cc2a33cab7d122b/href">https://medium.com/media/e655750ec56b345c4cc2a33cab7d122b/href</a></iframe><p>HttpHeaders are also immutable i.e every method on HttpHeaders object does not modify it but returns a new HttpHeaders object.</p><h4>HTTP headers are immutable</h4><p>The HTTP headers are immutable. The following example does not work as each set method returns a new header and does not update the original header.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d061456f4a89e48c36c2c1e80af65401/href">https://medium.com/media/d061456f4a89e48c36c2c1e80af65401/href</a></iframe><p>To workaround, you can use the code as follows</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a3f350ac4a9c9da1bcee628e055e767/href">https://medium.com/media/8a3f350ac4a9c9da1bcee628e055e767/href</a></iframe><h3>HTTP POST Request</h3><p>Next, let’s see how data can be sent via <em>HttpClient</em>. For sending data we’ll be using the post method of the <em>HttpClient</em> object. Of course, we need a backend that offers a REST API that accepts POST HTTP requests. To avoid setting up our own backend API we can instead make use of JSONPlaceholder which is a fake online REST API for testing and prototyping (<a href="https://jsonplaceholder.typicode.com/">https://jsonplaceholder.typicode.com/</a>).</p><p>The endpoint <a href="http://jsonplaceholder.typicode.com/posts">http://jsonplaceholder.typicode.com/posts</a> is support POST HTTP requests. Let’s use that endpoint to create a new post record:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccd368070d52323c7c8970ca7263e73f/href">https://medium.com/media/ccd368070d52323c7c8970ca7263e73f/href</a></iframe><p>Here you can see that the data of the post request are passed to the <em>post</em> method as the second parameter in JSON format. We’re getting back a response which is confirming that the object has been created successfully:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*cc0R5U-O2zFgdt0NoBUHgg.png" /></figure><h3>HTTP Interceptors</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pous9FJ6IAlScy190p1UEQ.png" /></figure><p>One of the new features of the new HttpClient module is the availability of interceptors. Interceptors are sitting in between your application and the backend. By using interceptors you can transform a request coming from the application before it is actually submitted to the backend. The same is possible for responses. If a response arrives from the backend the interceptor can transform that response before it arrives in your application.</p><p>The best way to discover how interceptors work is to implement a simple example. Create a new file <em>auth-headers.interceptor.ts</em> and insert the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/180ffd70f972ce9871660e8f4da9e527/href">https://medium.com/media/180ffd70f972ce9871660e8f4da9e527/href</a></iframe><p>The interceptor class AuthHeadersInterceptor implements the interface HttpInterceptor which is part of the @angular/common/http library. Implementing this interface requires us to add the intercept method to the class. This method is doing the main work of the interceptor. The method is expected to get two parameters. The first parameter is containing the original request. The second parameter is the next HTTP handler to which the request needs to be passed on for further processing.</p><p>In this first example, the intercepts method is just passing on the original request to the next handler. Having understood the interceptor approach we can now move on and manipulate the request in the intercept method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93eaf24b680f4d1e21a8fd6c96433bea/href">https://medium.com/media/93eaf24b680f4d1e21a8fd6c96433bea/href</a></iframe><p>First, we’re creating a new request by using the <em>clone</em> method. At the same time, we’re passing in a JSON object containing the headers property. We’re using the <em>req.headers.set</em> method to create a new header entry for the <em>Authorization</em> property. This property is used to submit the access token.</p><p>Finally, the newly created request object (with the header included) is passed on for further processing by using the <em>next.handle</em> method.</p><h3>Providing The Interceptor</h3><p>In order to activate the interceptor for our application we need to provide it to the main application module <em>AppModule</em> in file <em>app.module.ts</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/087714e445cd8c6fda467f28b42e30b8/href">https://medium.com/media/087714e445cd8c6fda467f28b42e30b8/href</a></iframe><p>we’re inserting a new object to the array which is assigned to the providers property of <em>@NgModule</em>. This object is containing three properties:</p><ul><li><em>provide</em>: needs to be set to HTTP_INTERCEPTORS in order to specify that an HTTP interceptor is provided</li><li>useClass: needs to be set to our interceptor class type</li><li>multi: needs to be set to multi to tell Angular that HTTP_INTERCEPTORS is an array of values, rather than a single value</li></ul><p>Now the Interceptor is active and the Authorization header is added to every request which is sent out automatically.</p><p><strong>Conclusion</strong></p><ul><li>HttpClient is a Service that comes with the Angular framework and enables you to make your app communicate with an A.P.I.</li><li>HTTP interceptors are a very powerful tool that helps us to customize HTTP requests and make any logic before the requests send out/get into our angular application.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f4eb6ff3785" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction To Angular Modules]]></title>
            <link>https://medium.com/@kevinmavani/an-introduction-to-angular-modules-db75c3ebf842?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/db75c3ebf842</guid>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[ngmodule]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 07:22:20 GMT</pubDate>
            <atom:updated>2023-05-09T16:50:16.292Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MvxlnyUiWSvXvb_2FS3YOA.png" /></figure><h3>What are Angular modules?</h3><p>Angular is a Modular framework. Modularity is the property which measures the amount to which components connected together within a system can be separated as an individual unit and can function by themselves without depending on each other. Here in Angular, Module is a unit that groups Components, Pipes, Directives, and Services. An angular application can contain several modules. There is minimum one module present in every angular application, which is NgModule. The default NgModule is AppModule and is present in app.module.ts file. When you launch the application, this is the module that gets bootstrapped. You can also import and export functionalities from one module to the other for efficient and clean programming.</p><h3>Common Types of Modules</h3><h3>App Module</h3><p>The app (also referred to as root) module is the entry point module. Because of this, you want to keep this to the bare essentials needed to <a href="https://angular.io/guide/bootstrapping#the-bootstrap-array">bootstrap</a> your app. In this module, you will bring in entry-level components and other app-level modules. See</p><h3>Core Module</h3><p>The core module is used to provide your singleton services and any high-level functionality. Any component, directive, or pipe that isn’t feature specific and is only used once in the app should end up in the core module. An example of this could be a navbar or footer component that is called once in your app component. This module should be imported once in the App module.</p><h3>Shared Module</h3><p>The shared module holds common UI components, directives, and pipes that are going to be used in many — if not every — feature module. This can include common Material UI modules, such as MatButtonModule or MatSelectModule. If you notice you are importing a module into every feature module, you should refactor it to live in the shared module instead.</p><h3>Feature Modules</h3><p>Feature modules will depend heavily on your application but ultimately this allows you to break up your app into small, single-purpose, chunks. In a feature module, you can import other modules, services, components, pipes, and directives that will be used in this feature.</p><h3>Routing Module</h3><p>The routing module is used when your application needs to have multiple <em>pages. </em>For example, a shopping app might need a route to /shopping-cart and /inventory. You can have multiple routing modules within your application, typically these will correlate to a feature module.</p><h3>Defining a Module</h3><p>You can define a module by importing NgModule decorator from @angular/core and passing a config with components, directives, pipes, and services that you want to use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/063fcb0cf87bdc9351f58e75107145f3/href">https://medium.com/media/063fcb0cf87bdc9351f58e75107145f3/href</a></iframe><p>The config used above holds the most commonly used fields when defining a module.</p><ul><li><strong>Declarations</strong>: This one contains the name of components, pipes, and directives which are present in the NgModule.</li><li><strong>Imports</strong>: This contains the names of other modules whose functionalities are required by the components of this particular module.</li><li><strong>Exports</strong>: This is responsible for making the component template visible to other modules that can import functionalities from this Module.</li><li><strong>Providers</strong>: When NgModule runs, its main function is to provide the application with services. The provider is responsible for creating Services that the NgModule requires. The services are accessible from all parts of the App.</li><li><strong>Bootstrap</strong>: This is the Property of Root Module. Bootstrapping is the process which initializes the root module. The root module is responsible for initializing all the other modules.</li></ul><h3>Bootstrapping in Angular</h3><p>Bootstrapping is the first process that comes into play when you start your application. This process is responsible for initializing the root module. When the root module initializes, then all the other modules initialize via the root module. To bootstrap the Module, we need to mention it in our main.ts file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2456651fd2435302883eb04422413b24/href">https://medium.com/media/2456651fd2435302883eb04422413b24/href</a></iframe><h3>What is Lazy Loading?</h3><p>Lazy loading is the process of loading components, modules, or other assets of a website as they’re required. Lazy loading modules helps us decrease the startup time. With lazy loading our application does not need to load everything at once, it only needs to load what the user expects to see when the app first loads. Modules that are lazily loaded will only be loaded when the user navigates to their routes.</p><p>Since Angular creates a <a href="https://en.wikipedia.org/wiki/Single-page_application#:~:text=From%20Wikipedia%2C%20the%20free%20encyclopedia,browser%20loading%20entire%20new%20pages.">SPA (Single Page Application)</a>, all of its components are loaded at once. This means that a lot of unnecessary libraries or modules might be loaded as well.</p><p>For a small application this would be okay. But as the application grows the load time will increase if everything is loaded at once. Lazy loading allows Angular to load components and modules as and when they’re needed.</p><p>To lazy load modules, In your main routing configuration, you will want to do something like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b866c3d28f670954f4db773942ff4b8e/href">https://medium.com/media/b866c3d28f670954f4db773942ff4b8e/href</a></iframe><h3>How to Preload Angular Lazy Loaded Modules in the Background</h3><p>When working with the Angular lazy-loaded modules, have you ever been in a situation where it takes so much time to load. It gets worse If your lazy module is much larger than the main module. Now it might take more time to load compared to applications initial load. Here, we gonna discuss how to load the lazy modules asynchronously in the background instead of on-demand so at the time user interact with the lazy-loaded modules, it’s already preloaded.</p><p>Let’s say you have an application with a button that redirects you to a lazy-loaded module. In a typical scenario, the lazy-loaded module starts to get loaded when the user clicks on that button. But with the preload mechanism, the lazy module starts to load soon after the main module gets loaded. So, at the time user interact with the lazy module, it’s already there. Pretty cool right.</p><p><strong>What is preloading?</strong></p><p>Preloading is similar to lazy-loading. In lazy-loading, modules are loaded on demand from the user. but what happens in preloading is all the feature modules which are assigned to be lazy-loaded are loaded asynchronously right after the eager loaded modules are done loading. Which simply means when a preloading strategy is used feature modules won’t have to wait to get load until the user navigate to them.</p><p><strong>Preloading strategies in angular</strong></p><p>Angular has a abstract class called PreloadingStrategy, by default it provides two sub classes. which are;</p><ul><li><em>NoPreloading</em>: Default strategy in angular, which provide no preloading for any module.</li><li><em>PreloadAllModule</em>s: Preload all the lazy-loading module as quickly as possible.</li></ul><p>To use any of the above strategies what you have to do is add the strategy in your app-routing.module.ts as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4340d6a040f35f0b2b5febd8d0a6f380/href">https://medium.com/media/4340d6a040f35f0b2b5febd8d0a6f380/href</a></iframe><p>Now, this looks all good. Although someone might ask “what if I only want to preload one lazy module instead of all”. Well, that’s a good question. If your application has more than one lazy loaded modules then loading all of it might be resource consuming. But don’t worry. As always Angular has the answer.</p><p>Angular provides a custom preloading strategy so that developers can explicitly specify which lazy modules they need to preload. All you need to do is set the <strong>data.preload </strong>flag to true in the lazy-loaded module route and angular take care of the rest.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b01fa71eaca0a513cd9e5f28d15bf92/href">https://medium.com/media/4b01fa71eaca0a513cd9e5f28d15bf92/href</a></iframe><p><strong>Custom Pre-loading strategy</strong></p><p>Custom preloading strategies allow to preload selective modules. We can also customize to preload modules after a certain delay after application starts. To create a custom preloading strategy, Angular provides PreloadingStrategy class with a preload method. We need to create a service by implementing PreloadingStrategy and overriding its preload method. To enable custom preloading strategies, we need to configure our preloading strategy service with RouterModule.forRoot using preloadingStrategy property.</p><p><strong>Custom strategies are very useful when you only want to preload certain modules, or you want to conditionally preload a module or add a delay.</strong></p><p>CustomPreloading strategies are written as services which implement the PreloadingStrategy interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a50fd0aad825bdc2bf4658979ad446af/href">https://medium.com/media/a50fd0aad825bdc2bf4658979ad446af/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4c35416de2c263690f5fa9f579c7495/href">https://medium.com/media/c4c35416de2c263690f5fa9f579c7495/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db5220491373a0dfc14d59e6dc6be371/href">https://medium.com/media/db5220491373a0dfc14d59e6dc6be371/href</a></iframe><h3>Conclusion</h3><p>Angular modules are a fundamental building block to any Angular application. The purpose of NgModule is to organize the application, extend functionality from external libraries, and configure the compiler and injector. The structure of an NgModule contains declarations, imports, providers, and bootstrapping. When an application gets larger, it can be separated into different modules — the root module along with feature modules.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db75c3ebf842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Red Black Tree]]></title>
            <link>https://medium.com/swlh/red-black-tree-47e3249cf17?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/47e3249cf17</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[binary-search-tree]]></category>
            <category><![CDATA[trees]]></category>
            <category><![CDATA[red-black-tree]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Thu, 01 Oct 2020 13:02:36 GMT</pubDate>
            <atom:updated>2023-05-26T07:35:02.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUnMmWRNJ0DSPSX9V7ZF3Q.jpeg" /></figure><h3><strong>What is Red Black Tree?</strong></h3><p><strong>Red-Black Tree</strong> is a Self-balanced binary search tree with one extra bit of storage per node: its color which can be either Red or Black.</p><p>Each node of the tree contains the attributes <strong>color, key, left pointer, right pointer, and parent(except root node)</strong>.</p><p>If a child of a node does not exist, the corresponding pointer attribute of the node contains the value <strong>NIL</strong>.</p><h3><strong>Why is a Red Black Tree needed?</strong></h3><p><strong>Comparison with</strong><a href="https://www.geeksforgeeks.org/avl-tree-set-1-insertion/"><strong> Binary Search Tree</strong></a></p><p>A BST may have a height of n( n being the total number of nodes) in the <em>worst case</em> if the elements are in <em>increasing</em> or <em>decreasing</em> order. This would relegate it to <strong>O(n)</strong> time for searches, insertions and deletions. This is why we require a red-black tree. It keeps the BST balanced with a <em>height logn</em>.</p><p><strong>Comparison with</strong><a href="https://www.geeksforgeeks.org/avl-tree-set-1-insertion/"><strong> AVL Tree</strong></a><br>The AVL trees are more balanced compared to Red-Black Trees, but they may cause more rotations during insertion and deletion. So if your application involves many frequent insertions and deletions, then Red Black trees should be preferred. And if the insertions and deletions are less frequent and search is a more frequent operation, then AVL tree should be preferred over Red-Black Tree.</p><h3><strong>Properties of Red Black Tree</strong></h3><p>A red-black tree is a binary tree that satisfies the following red-black properties:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*6Wt4t2ZHC5U7PEwYOV1Wrg.png" /></figure><ol><li>Every node is either red or black.</li><li>The root is black.</li><li>Every leaf which is nil is black.</li><li>If a node is red, then both its children are black.</li><li>For each node, all simple paths from the node to descendant leaves contain the same number of black nodes.</li></ol><h3><strong>How to insert newNode in Red Black Tree</strong></h3><h4><strong>Pseudo Code</strong>.</h4><ol><li>Check whether tree is Empty.</li><li>If tree is Empty then insert the newNode as Root node with color Black .</li><li>If tree is not Empty then insert the newNode as leaf node with color Red.</li><li>If the parent of newNode is Black then exit from the operation.</li><li>If the parent of newNode is Red then check the color of parentnode’s sibling of newNode.</li><li>If it is colored Black or NULL then make suitable Rotation and Recolor it.</li><li>If it is colored Red then perform Recolor and also check parent’s parent of new node if its not root node than recolor it. Repeat the same until tree becomes Red Black Tree.</li></ol><h3><strong>Create Red Black Tree by Inserting following number.<br> 8, 18, 5, 15, 17, 25</strong></h3><h3>Insert(8)</h3><p>So first we check tree is empty or not. here tree is empty so enter a newNode as root node with color Black.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/89/1*4kzY_qhjyoaqRtllnWd1tA.png" /></figure><h3>Insert(18)</h3><p>Here Tree is not Empty so insert the newNode as leaf node with color Red.(RBT is self balanced binary search tree so we have to follow rule of Binary Search Tree also during Insertion a node in Tree.)</p><ol><li>Left Subtree contain value <strong>lesser</strong> than the root node.</li><li>Right Subtree contain value <strong>grater</strong> than the root node.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/164/1*scHdpBq6LUWExyATuurLoQ.png" /></figure><h3><strong>Insert(5)</strong></h3><p>Tree is not Empty so insert newNode with Red color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*ZxjnijUekvK372zBs2RcEQ.png" /></figure><h3><strong>Insert(15)</strong></h3><p>Tree is not Empty so insert newNode with Red color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*lG3kfWUERM5HnW7wKf2F3g.png" /></figure><pre>Here there are two consecutive red nodes(18 &amp; 15).The color of parent’s sibling(uncle(5)) of newNode is Red and Parent’s parent is root node. so we use Recolor and make it Red Black Tree.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*aFB39MkqYGIM6BK1LzMMeQ.png" /></figure><h3><strong>Insert(17)</strong></h3><p>Tree is not Empty so insert newNode with Red color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*XAWFcwrJeo_Jp3qJYtpHnw.png" /></figure><pre>Here there are two consecutive red nodes(15 &amp; 17).The parent’s sibling of newNode NULL. So we need Rotation.<br>Here We need LR Rotation and Recolor.</pre><pre>After <strong>Left Rotation</strong> node whose value is 17 it become parent node of 15.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*vfTADe8Y-OT9y-nH9F3KSw.png" /></figure><pre>After <strong>Right Rotation and Recoloring</strong> node whose value is 17 it becomes the parent node of 15 and 18.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*qZrJBgZVVyA0UfjCyvQr8w.png" /></figure><h3><strong>Insert(25)</strong></h3><p>Tree is not Empty so insert newNode with Red color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*0rO9UElkcoTtnMuQjj__8w.png" /></figure><pre>Here there are two consecutive red nodes(18 &amp; 25).The color of parent’s sibling(uncle(15)) of newNode is Red and Parent’s parent is also not a root node. so we use Recolor and Recheck.</pre><pre>After<strong> Recoloring</strong>, The tree is satisfying all the Red Black Tree Properties.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*6Wt4t2ZHC5U7PEwYOV1Wrg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47e3249cf17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/red-black-tree-47e3249cf17">Red Black Tree</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Longest Common Subsequence using Dynamic Programming]]></title>
            <link>https://medium.com/@kevinmavani/longest-common-subsequence-using-dynamic-programming-641eed90dab1?source=rss-bb7341995321------2</link>
            <guid isPermaLink="false">https://medium.com/p/641eed90dab1</guid>
            <category><![CDATA[esport]]></category>
            <dc:creator><![CDATA[Kevin Mavani]]></dc:creator>
            <pubDate>Tue, 03 Sep 2019 19:30:42 GMT</pubDate>
            <atom:updated>2020-10-02T09:10:09.950Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Let’s see first, what is longest common subsequence problem?</em></strong></p><p><strong>Longest common subsequence </strong>problem is the problem of finding the longest common subsequence that is present in given sequence in same order. i.e. find longest sequence which can be obtained from the first original sequence by deleting some items, and from the second original sequence by deleting other items.</p><p><strong>Example :</strong></p><p>Given two sequence say “ABACCD” and “ACDF”</p><p>Find Longest Common Subsequence or LCS</p><pre>Given two sequences:</pre><pre>ABACCD      ACDF<br>^           ^<br>SAME (so we mark them and move to next letters)</pre><pre>[A]BACCD    [A]CDF<br>   ^           ^<br>DIFFERENT (so move to next letter)</pre><pre>[A]BACCD    [A]CDF<br>    ^          ^<br>DIFFERENT (so move to next letter)</pre><pre>[A]BACCD    [A]CDF<br>     ^         ^<br>SAME (so we mark them and move to next letters)</pre><pre>[A]BA[C]CD  [A][C]DF<br>        ^         ^<br>DIFFERENT (so move to next letter)</pre><pre>[A]BA[C]CD  [A][C]DF<br>         ^        ^<br>SAME (so we mark them)</pre><pre>[A]BA[C]C[D]    [A][C][D]F</pre><p>So, the LCS is “ACD”.</p><p><strong>Now We Solve the LCS problem using Dynamic Programming.</strong></p><p><strong>Algorithm :</strong></p><pre>if(i == 0 || j == 0)<br>     LCS[i][j]=0;<br>else if(x[i] == y[j])<br>     LCS[i][j] = 1 + LCS[i-1][j-1];<br>else<br>     LCS[i][j] = max(LCS[i-1][j] , LCS[i][j-1]);</pre><ol><li>First we initialize first row and column as zero because if we compare null string with any string it would give us count of matching character is zero.</li><li>Then we will take first character of vertical align string in dynamic table and compare with first character of horizontally align string if we get match then take a previous diagonal value and add one to it.</li><li>if there is no match then we take the maximum either in previous row or previous column.</li><li>we will repeat the step from two for every vertically and horizontally aligned strings.</li></ol><p><strong><em>Let us calculate LCS using dynamic programming.</em></strong></p><p>For example take two strings “LONGEST” and “STONE”. Let’s get to work.</p><p>First construct LCS dynamic table using algorithm specified above.You should get table like given below.</p><p>Now lets track back the LCS from given table.</p><p>Start journey from last column and last row. If we find similar value in previous row we discard character of that tab and go to the value we have find as similar.</p><p>if we don’t find similar value in previous row we go diagonally and add character of that column in our LCS.</p><p>Repeat the procedure until the value of tab becomes zero.</p><p>Invert the LCS we find and that’s the answer to our problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*7OjFu_O--zZL6PvRR-8cxQ.jpeg" /></figure><p><strong>Application of LCS problem :</strong></p><p>The longest common subsequence problem forms the basis of data comparison programs such as the different utility.</p><p>It is also used by revision control systems such as Git.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=641eed90dab1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>