<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Veeresh</title>
    <description>The latest articles on DEV Community by Veeresh (@veerreshr).</description>
    <link>https://dev.to/veerreshr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F432420%2F52798c00-ffd3-4159-98a6-0afc4d6cd09c.jpg</url>
      <title>DEV Community: Veeresh</title>
      <link>https://dev.to/veerreshr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/veerreshr"/>
    <language>en</language>
    <item>
      <title>Web Components: A Revolutionary Way to Build User Interfaces</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Sat, 04 Jun 2022 15:24:10 +0000</pubDate>
      <link>https://dev.to/veerreshr/web-components-a-revolutionary-way-to-build-user-interfaces-56jl</link>
      <guid>https://dev.to/veerreshr/web-components-a-revolutionary-way-to-build-user-interfaces-56jl</guid>
      <description>&lt;p&gt;Previously, coding frontend applications was more cluttered and there wasn't any modular approach to separating certain functionality from the rest of the code. Web components will allow developers to create reusable custom elements that can be used throughout their web applications. This will lead to a more modular approach to web development, making it easier to read, build and maintain complex web applications.&lt;/p&gt;

&lt;p&gt;Though we got external libraries/frameworks like react and angular which will ease our work, &lt;strong&gt;why do we need Web Components?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web components are standards-based. This means that they will be supported by all major browsers in the future. Check the current compatibility here at &lt;a href="https://caniuse.com/?search=web%20components" rel="noopener noreferrer"&gt;Can I Use Web Components&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Web components are self-contained. This means that they are easy to reuse and easy to maintain.&lt;/li&gt;
&lt;li&gt;Web components are easy to use. You don't need to learn a new library or framework to use them.&lt;/li&gt;
&lt;li&gt;Additionally, these are compatible with any framework. Write once use anywhere.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Creating a web component is simple. All you need is a basic understanding of HTML, CSS, and JavaScript. In this tutorial, we'll walk through a few of the basic standards of understanding and creating web components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Let's get started (Introduction)&lt;/li&gt;
&lt;li&gt;Custom Elements&lt;/li&gt;
&lt;li&gt;Shadow DOM&lt;/li&gt;
&lt;li&gt;HTML Templates&lt;/li&gt;
&lt;li&gt;Slots&lt;/li&gt;
&lt;li&gt;
HTML Imports

&lt;ol&gt;
&lt;li&gt;Deprecation of HTML Imports&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;/ol&gt;

&lt;h2&gt;
  
  
  Let's get started (Introduction):
&lt;/h2&gt;

&lt;p&gt;Web components are a set of W3C standards that allow developers to create reusable components for the web. By using web components, you can keep your code clean and maintainable, and create custom elements that can be used in any web page or web application. The four main standards are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Custom Elements: Allows developers to create their own HTML tags.&lt;/li&gt;
&lt;li&gt;Shadow DOM: Gives developers the ability to encapsulate DOM and CSS in a web component so that it is isolated from the rest of the document.&lt;/li&gt;
&lt;li&gt;HTML Templates: Allows developers to create reusable HTML templates.&lt;/li&gt;
&lt;li&gt;HTML Imports ( Deprecated ): Allows developers to import HTML documents into other HTML documents.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Custom Elements:
&lt;/h2&gt;

&lt;p&gt;The main need for custom elements is to provide a way for developers to create their own HTML tags. This is important because it allows developers to extend the HTML vocabulary, making it more expressive and powerful. Additionally, custom elements can help create more semantically meaningful markup, and they can make code more maintainable by encapsulating complex functionality into a single, reusable component. You could create custom elements like , etc.&lt;/p&gt;

&lt;p&gt;There are two types of Custom Elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Autonomous Custom Elements&lt;/strong&gt; are custom elements that are not based on any existing HTML element. They are created from scratch and can extend any other custom element or standard HTML element ( generally HTMLElement class ).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customized Built-in Elements&lt;/strong&gt; are custom elements that are based on existing HTML elements. They extend the functionality of the built-in element and can be used to customize the behavior or appearance of that element.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial, we will discuss Autonomous Custom Element. Creating a Autonomous Custom Element is simple. All you need to do is create a JavaScript class that extends HTMLElement. This class can then be registered with the browser as a custom element. This class can have many methods which are discussed below.&lt;/p&gt;

&lt;p&gt;Once you have your class created, you need to register it with the browser as a custom element. This is done using the customElements.define() method. This method takes two arguments: the name of the custom element, and the class that represents the custom element.&lt;/p&gt;

&lt;p&gt;After your custom element is registered, you can use it just like any other HTML element. That's all there is to it!&lt;/p&gt;

&lt;p&gt;Here's the schema of a simple custom element, where every method is optional :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note : custom element name should contain &lt;code&gt;-&lt;/code&gt;(hyphen) to ensure their wont be any conflicts between custom elements and normal HTML elements.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyElement extends HTMLElement {
  constructor() { super(); /* ... */ }
  connectedCallback() { /* ... */ }
  disconnectedCallback() { /* ... */ }
  static get observedAttributes() { return [/* ... */]; }
  attributeChangedCallback(name, oldValue, newValue) { /* ... */ }
  adoptedCallback() { /* ... */ }
}

customElements.define('my-element', MyElement);

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Functionalities of Above Methods :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;connectedCallback&lt;/strong&gt; : browser calls this method when the element is added to the document (can be called many times if an element is repeatedly added/removed)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;disconnectedCallback&lt;/strong&gt; : browser calls this method when the element is removed from the document&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;static get observedAttributes&lt;/strong&gt; : returns array of attribute names to monitor for changes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;attributeChangedCallback&lt;/strong&gt; : called when one of attributes listed above in observedAttributes method is modified&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;adoptedCallback&lt;/strong&gt; : called when the element is moved to a new document happens in document.adoptNode, very rarely used)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, lets take an example to create a greeting element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Greeting extends HTMLElement {
  constructor() { super(); }
  connectedCallback() { 
    this.innerHTML = `&amp;lt;p&amp;gt;
      Hello, ${this.getAttribute('name')}
    &amp;lt;/p&amp;gt;`;
 }
}

customElements.define('greet-element', Greeting);

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

&lt;/div&gt;



&lt;p&gt;And that's all there is to it! You've now created a reusable web component that can be used anywhere on your web page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;greet-element name="Arjun"&amp;gt;&amp;lt;/greet-element&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This is how the output looks like :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250589520%2FRDNh9nTui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250589520%2FRDNh9nTui.png" alt="HTML Output for Custom Element Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250860946%2FppYz5sMKk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250860946%2FppYz5sMKk.png" alt="Console Output for Custom Element Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Shadow DOM :
&lt;/h2&gt;

&lt;p&gt;Have you ever wondered how the browser handles complexity behind elements like input tag, select tag etc. The browser uses DOM/CSS to draw elements on the page. This DOM structure is normally hidden from us, but we can see it in developer tools. For example, in Chrome, we need to enable the "Show user agent shadow DOM" option in Dev Tools.&lt;/p&gt;

&lt;p&gt;This is how it looks when you enable that option and inspect the input element : &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654247232668%2FvnbQRObhC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654247232668%2FvnbQRObhC.png" alt="image.png"&gt;&lt;/a&gt;What you see under #shadow-root (user-agent) is called shadow DOM. Elements like input and select implement built-in shadow dom. We cant get built-in shadow DOM elements by regular JavaScript calls or selectors.&lt;/p&gt;

&lt;p&gt;This Shadow DOM will be completely isolated from Lighter DOM ( normal DOM). Has its own ids space, styles and is invisible to outer document (lighter dom selectors).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FWeb_Components%2FUsing_shadow_DOM%2Fshadowdom.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FWeb_Components%2FUsing_shadow_DOM%2Fshadowdom.svg" alt="Shadowdom Ilustration from MDN docs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Creating Shadow DOM is simple . First create a simple DOM element elem and then attach shadom dom using the syntax &lt;code&gt;shadowRoot = elem.attachShadow({mode: open|closed})&lt;/code&gt;. If mode="open", then its accessible as elem.shadowRoot property. If mode="closed", then elem.shadowRoot will be null. We can now populate this &lt;code&gt;shadowRoot&lt;/code&gt; element using methods like innerHTML or any other DOM methods.&lt;/p&gt;

&lt;p&gt;Custom Elements can use Shadow DOM to encapsulate component internals and apply component-local styles. Lets see an example using shadow dom for the above custom element &lt;code&gt;greet-element&lt;/code&gt; example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Greeting extends HTMLElement {
  constructor() { super(); }
  connectedCallback() { 
    const shadow = this.attachShadow({mode: 'open'});
    shadow.innerHTML = `&amp;lt;p&amp;gt;
      Hello, ${this.getAttribute('name')}
    &amp;lt;/p&amp;gt;`;
 }
}

customElements.define('greet-element', Greeting);

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

&lt;/div&gt;



&lt;p&gt;Now you can use this &lt;code&gt;greet-element&lt;/code&gt; in HTML as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;greet-element name="Arjun"&amp;gt;&amp;lt;/greet-element&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This is how the output looks like :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250589520%2FRDNh9nTui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250589520%2FRDNh9nTui.png" alt="HTML Output for Shadow DOM Example"&gt;&lt;/a&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250290141%2Fua-Y2air8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654250290141%2Fua-Y2air8.png" alt="Console Output for Shadow DOM Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML Templates :
&lt;/h2&gt;

&lt;p&gt;HTML templates are very powerful and useful when it comes to creating websites or web applications. They provide a great way to structure and organize your code, making it more readable and maintainable. And with the help of slots, you can further customize the behavior and appearance of your template.&lt;/p&gt;

&lt;p&gt;we can write Templates using &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tag, where the content can be any syntactically correct HTML. We can also put styles and scripts into &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;. The browser considers template content as out of document, due to which styles, scripts or any other content is not run until we attach template to some element of DOM.&lt;/p&gt;

&lt;p&gt;The content of the template is available as a DocumentFragment in its content property. This is a special type of DOM node that can be treated like any other DOM node, except for one special property: when it is inserted somewhere, its children are inserted instead. For example consider the following code :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template id="templateExample"&amp;gt;
  &amp;lt;script&amp;gt;
    alert("Hello");
  &amp;lt;/script&amp;gt;
  &amp;lt;style&amp;gt;
    .greet {
      color: red;
    }
  &amp;lt;/style&amp;gt;
  &amp;lt;div class="greet"&amp;gt;Hello, world!&amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&amp;lt;div id="output"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script&amp;gt;
   // Clone the template content to reuse it multiple times
   output.append(templateExample.content.cloneNode(true));
   // Now the script and styles from &amp;lt;template&amp;gt; runs
&amp;lt;/script&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Output looks like :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654254079031%2Fw81F2-jwc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654254079031%2Fw81F2-jwc.png" alt="Template Output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654254130566%2F37NKdgjiI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654254130566%2F37NKdgjiI.png" alt="Template DOM Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Slots
&lt;/h2&gt;

&lt;p&gt;Slots are like placeholder elements in a template that can be filled with different content. This flexibility gives you a lot of control over how your template is rendered. For example, you can use slots to create different versions of a template for different screen sizes. Or you can use them to change the order in which template elements are rendered.&lt;/p&gt;

&lt;p&gt;There are two types of slots: named slots and unnamed slots.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Named slots are used to specify a particular slot that you want to fill with content. &lt;code&gt;&amp;lt;slot name="X"&amp;gt;...&amp;lt;/slot&amp;gt;&lt;/code&gt; gets children with slot="X".&lt;/li&gt;
&lt;li&gt;Unnamed slots, on the other hand, are used when you don't need to specifically target a particular slot ( or you want all the remaining content to take this spot )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Slots are better used when combined with remaining Web Components, so let's combine all the above concepts (custom elements, shadow DOM, templates) and write a simple usage of slot&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template id="greetTemplate"&amp;gt;
  &amp;lt;style&amp;gt;
  .greet{
    color:red;
  }
  &amp;lt;/style&amp;gt;
  &amp;lt;div class="greet"&amp;gt;Hello, &amp;lt;slot name="user-name"&amp;gt;World!&amp;lt;/slot&amp;gt;&amp;lt;/div&amp;gt; &amp;lt;!-- #(1) --&amp;gt;
  &amp;lt;div&amp;gt;
    Remaining Content : &amp;lt;slot&amp;gt;&amp;lt;/slot&amp;gt; &amp;lt;!-- #(2) --&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;greet-element&amp;gt;
  &amp;lt;span slot="user-name"&amp;gt;Veeresh&amp;lt;/span&amp;gt;
  Some Remaining Content,&amp;lt;b&amp;gt; More content &amp;lt;/b&amp;gt;
&amp;lt;/greet-element&amp;gt;


class Greeting extends HTMLElement {
  constructor() { super(); }
  connectedCallback() { 
    const shadow = this.attachShadow({mode: 'open'});
    const template = document
        .getElementById('greetTemplate')
        .content;
    shadow.append(template.cloneNode(true));
 }
}

customElements.define('greet-element', Greeting);

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

&lt;/div&gt;



&lt;p&gt;You can see 2 types of slots being used here ( refer to #1, #2 comments in HTML code). The first slot takes user-name, if you dont get user-name from custom element, it uses &lt;strong&gt;world!&lt;/strong&gt; as default text. The second slot is the default slot ( i.e without a name ), which consumes all the remaining children. If there exists multiple default slots, only the first one is considered and all subsequent unnamed slots are ignored.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654256497561%2Fw0yJFtXeA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654256497561%2Fw0yJFtXeA.png" alt="HTML output of Slot example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654256573215%2FUbfO-tCdX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654256573215%2FUbfO-tCdX.png" alt="Console output of Slot example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;From the above output you can see that the slots are still at same position and haven't moved to shadow DOM, but still it renders on the browser DOM. This process of rendering slotted elements inside their slots is called composition. The result is called a flattened DOM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  HTML Imports :
&lt;/h2&gt;

&lt;p&gt;You know importing JS modules or CSS files right? How about importing HTML files? There comes HTML Imports. HTML Imports is a feature of the Web Components specification that allows you to include HTML documents inside other HTML documents.&lt;/p&gt;

&lt;p&gt;This is useful for creating reusable components that can be used across your website or web application. For example, you could create a component that contains a navigation menu, and then use the HTML Import to include that component on every page of your website.&lt;/p&gt;

&lt;p&gt;HTML Imports are also useful for loading external resources, such as CSS stylesheets or JavaScript libraries, that are required by your web components.&lt;/p&gt;

&lt;p&gt;Including an HTML Import is similar to using the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; element to load a CSS stylesheet, or the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; element to load a JavaScript file.&lt;/p&gt;

&lt;p&gt;To include an HTML Import, you use the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; element with a rel attribute value of "import":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="import" href="/path/to/import.html"&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The href attribute value is the URL of the HTML document that you want to import.&lt;/p&gt;

&lt;p&gt;Once an HTML Import is included in a document, the browser will fetch the imported document and process it.&lt;/p&gt;

&lt;p&gt;If the imported document contains any &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; elements, those resources will also be loaded and processed.&lt;/p&gt;

&lt;p&gt;When the imported document is processed, any elements will be processed and the contents will be added to the main document. Any &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; elements will be executed.&lt;/p&gt;

&lt;p&gt;After the HTML Import is processed, the resulting document will be updated to reflect any changes that were made.&lt;/p&gt;

&lt;p&gt;HTML Imports are a powerful way to create reusable components and load external resources. Though they are deprecated, you can still use them by including a polyfill for it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deprecation of HTML Imports
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654350918650%2FVkLOj0GKg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654350918650%2FVkLOj0GKg.png" alt="Support of HTML Imports"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTML Imports was really an exciting feature and it makes the web development truly modular. But most of the browsers rejected it. The common reason is HTML Imports were redundant, as you still need JavaScript to make the stuff run.&lt;/p&gt;

&lt;p&gt;But there exists a successor to this deprecated HTML Imports, that is HTML Modules. &lt;strong&gt;HTML Modules&lt;/strong&gt; are the new proposal for importing HTML files into a document. To know more about the proposal please have a loot at this &lt;a href="https://github.com/WICG/webcomponents/blob/gh-pages/proposals/html-modules-explainer.md" rel="noopener noreferrer"&gt;HTML Modules Explainer&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion :
&lt;/h2&gt;

&lt;p&gt;I hope you got to know the basics of Web Components and various concepts like Custom Elements, Shadow DOMs, Templates, Slots, HTML Imports, HTML Modules, etc. This is just a tip on top of an iceberg. To know more about the concepts please find the below references on each topic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements" rel="noopener noreferrer"&gt;Custom Elements&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM" rel="noopener noreferrer"&gt;Shadow DOM&lt;/a&gt;,&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots" rel="noopener noreferrer"&gt;Templates and Slots&lt;/a&gt;,&lt;a href="https://github.com/WICG/webcomponents/blob/gh-pages/proposals/html-modules-explainer.md" rel="noopener noreferrer"&gt;HTML Modules Explainer&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Also, check out the support of Web Components by different browsers here at &lt;a href="https://caniuse.com/?search=web%20components" rel="noopener noreferrer"&gt;Can I Use Web Components&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There also exist a few libraries that make developing web components easier, a few of the leading and my favorite libraries are &lt;a href="https://lit.dev/" rel="noopener noreferrer"&gt;Lit&lt;/a&gt; and &lt;a href="https://stenciljs.com/" rel="noopener noreferrer"&gt;Stencil&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You are awesome, you came this long. If you do like this post please let me know. &lt;a href="https://i.giphy.com/media/WV9Xx9itqEIu8GQloO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/WV9Xx9itqEIu8GQloO/giphy.gif" alt="You Rock"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>In the mist of the Big Data Hype, Let’s Discuss MySQL</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Mon, 20 Sep 2021 07:57:56 +0000</pubDate>
      <link>https://dev.to/veerreshr/in-the-mist-of-the-big-data-hype-let-s-discuss-mysql-dbm</link>
      <guid>https://dev.to/veerreshr/in-the-mist-of-the-big-data-hype-let-s-discuss-mysql-dbm</guid>
      <description>&lt;p&gt;Hey all 👋,&lt;/p&gt;

&lt;p&gt;Hope you all doing great and today we gonna discuss few MySQL topics that are often ignored or say it advanced. &lt;/p&gt;

&lt;p&gt;To whom this blog is intended for? Absolute beginners? Intermediates ? To say it is intended for someone between beginner to Intermediate level, A Basic SQL knowledge is sufficient to understand.&lt;/p&gt;

&lt;p&gt;Lets get started 🚀🚀 &lt;/p&gt;

&lt;h2&gt;
  
  
  Table of contents :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;CASE Statements&lt;/li&gt;
&lt;li&gt;IFNULL&lt;/li&gt;
&lt;li&gt;COALESCE&lt;/li&gt;
&lt;li&gt;Stored Procedure&lt;/li&gt;
&lt;li&gt;
Window Functions

&lt;ul&gt;
&lt;li&gt;RANK&lt;/li&gt;
&lt;li&gt;DENSE_RANK&lt;/li&gt;
&lt;li&gt;ROW_NUMBER&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  CASE Statements
&lt;/h2&gt;

&lt;p&gt;These are similar to if-else statements, The CASE statement goes through a list of conditions and returns the result corresponding to first condition that is true. If none of conditions are met it returns the result from else statement.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CASE&lt;/span&gt;
    &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="n"&gt;condition1&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="n"&gt;result1&lt;/span&gt;
    &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="n"&gt;condition2&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="n"&gt;result2&lt;/span&gt;
    &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="n"&gt;conditionN&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="n"&gt;resultN&lt;/span&gt;
    &lt;span class="k"&gt;ELSE&lt;/span&gt; &lt;span class="k"&gt;result&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;CASE&lt;/span&gt;
   &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="n"&gt;follower_count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="nv"&gt;"Celebrity"&lt;/span&gt;
   &lt;span class="k"&gt;ELSE&lt;/span&gt; &lt;span class="nv"&gt;"Poor Regular User"&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"User Type"&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;user_table&lt;/span&gt;

&lt;span class="cm"&gt;/* No Celebrities are harmed in making of this code */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above statement returns the user type based on his follower count. If it is more than 100 followers then returns "Celebrity" else returns as "Poor Regular User"&lt;/p&gt;

&lt;h2&gt;
  
  
  IFNULL
&lt;/h2&gt;

&lt;p&gt;This function takes 2 Arguments, if the first argument is NULL, it returns second argument. &lt;/p&gt;

&lt;p&gt;Usually used to replace a NULL value with a default value while displaying the data.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;IFNULL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;column_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alternate_value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;IFNULL&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;user_table&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If value from amount column is null then 0 is returned in place of null value&lt;/p&gt;

&lt;h2&gt;
  
  
  COALESCE
&lt;/h2&gt;

&lt;p&gt;This function takes 2 or more arguments and It works similar to IFNULL, but returns the first Non NULL argument among the list of arguments, if every argument is NULL then it returns NULL.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argument_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;argument_2&lt;/span&gt;&lt;span class="p"&gt;....,&lt;/span&gt; &lt;span class="n"&gt;argument_n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;phonenumber_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phonenumber_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt; &lt;span class="n"&gt;number_3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;user_table&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If phone number 1 is null then it checks for phone number 2, even if it is null then it returns phone number 3&lt;/p&gt;

&lt;h2&gt;
  
  
  Stored Procedure
&lt;/h2&gt;

&lt;p&gt;A stored procedure is a group of SQL statements that has been created and stored in the database.&lt;/p&gt;

&lt;p&gt;It accepts input parameters so that only one procedure can be used on the network by multiple clients using different input data.&lt;/p&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;--For creating procedure&lt;/span&gt;
&lt;span class="k"&gt;DELIMITER&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;PROCEDURE&lt;/span&gt; &lt;span class="n"&gt;procedure_name&lt;/span&gt; &lt;span class="p"&gt;([[&lt;/span&gt;&lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;OUT&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;INOUT&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;Parameter_name&lt;/span&gt; &lt;span class="n"&gt;datatype&lt;/span&gt; &lt;span class="p"&gt;]...&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt;
   &lt;span class="n"&gt;sql_statements&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="k"&gt;DELIMITER&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- The delimiter is used to differentiate between the end of the procedure and the sql statements.&lt;/span&gt;

&lt;span class="k"&gt;For&lt;/span&gt; &lt;span class="n"&gt;executing&lt;/span&gt; &lt;span class="k"&gt;procedure&lt;/span&gt;
&lt;span class="k"&gt;CALL&lt;/span&gt; &lt;span class="n"&gt;procedure_name&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;--Creating getvalues procedure which prints out data in users_table when called&lt;/span&gt;
&lt;span class="k"&gt;DELIMITER&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;PROCEDURE&lt;/span&gt; &lt;span class="n"&gt;getvalues&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;users_table&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="k"&gt;DELIMITER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- calling procedure&lt;/span&gt;
&lt;span class="k"&gt;CALL&lt;/span&gt; &lt;span class="n"&gt;getvalues&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Window Functions (Available only for MySQL 8 +)
&lt;/h2&gt;

&lt;p&gt;Window functions perform calculations on a set of rows that are related together. These related rows are termed as windows.&lt;/p&gt;

&lt;p&gt;They Do not merge the rows like GROUP BY, they preserve the existing data.&lt;/p&gt;

&lt;p&gt;Mainly there are 3 Categories of window functions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Aggregate Window Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SUM(), MAX(), MIN(), AVG(). COUNT()&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Ranking Window Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RANK(), DENSE_RANK(), ROW_NUMBER(), NTILE()&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Value Window Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LAG(), LEAD(), FIRST_VALUE(), LAST_VALUE()&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;window_function&lt;/span&gt; &lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;column1&lt;/span&gt;&lt;span class="p"&gt;....])&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;([&lt;/span&gt; &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;partition_list&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;order_list&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="c1"&gt;-- [] = contents inside square brackets are optional&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  RANK
&lt;/h3&gt;

&lt;p&gt;This function will assign rank to each row within a partition, if there is a tie between the values then they will be assigned same rank and the next rank will be ( previous rank + no of previous duplicates )&lt;/p&gt;

&lt;p&gt;Example rank sequence : 1 2 2 4 5 5 7&lt;/p&gt;

&lt;p&gt;Example :&lt;/p&gt;

&lt;p&gt;First, lets see what's there in the table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Now lets execute the RANK query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;marks&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"Rank"&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;You can now see the result is sorted and every person is given a rank value, though the rank is not continuous at row with name vikram&lt;/p&gt;

&lt;h3&gt;
  
  
  DENSE_RANK
&lt;/h3&gt;

&lt;p&gt;Did you notice discontinuity in rank values when using RANK? Dense Rank does the same thing as RANK but with no discontinuity in rank values.&lt;/p&gt;

&lt;p&gt;Considering the same above example, lets execute dense query and see the result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DENSE_RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;marks&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"Dense Rank"&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkhnmon0ja047h9j4u7sg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkhnmon0ja047h9j4u7sg.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
You can now observe no discontinuity of rank values at row with name as vikram&lt;/p&gt;
&lt;h3&gt;
  
  
  ROW_NUMBER
&lt;/h3&gt;

&lt;p&gt;This function is used to give sequential number for each row within its partition.&lt;/p&gt;

&lt;p&gt;Lets have a look at the table data before executing the ROW_NUMBER query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyiusqilg2q1vx2o47345.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyiusqilg2q1vx2o47345.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
You can see students from different departments, using ROW_NUMBER function we can assign each row a sequential number starting from 1 based on department( dept ) he is from.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;dept&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="nv"&gt;"row number"&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtnluvfwcx9f3qgwxlio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtnluvfwcx9f3qgwxlio.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
You can observe each row of a particular department is given a sequential row number, this is what ROW_NUMBER function can do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Good Bye👋
&lt;/h2&gt;

&lt;p&gt;That's it for the blog, these are my 2 cents about some tricky SQL concepts. For more information on concepts, you can refer to &lt;a href="https://www.javatpoint.com/mysql-tutorial" rel="noopener noreferrer"&gt;javapoint&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you got to learn something new and will be able to do better with MySQL. If there are any further questions please feel free to ask.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FtrGtPJai2xwI%2Fgiphy.gif%3Fcid%3Decf05e47kgg2oxwnr2o5nz95ypd3z8omx6r3u18p72ybvuo1%26rid%3Dgiphy.gif%26ct%3Dg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FtrGtPJai2xwI%2Fgiphy.gif%3Fcid%3Decf05e47kgg2oxwnr2o5nz95ypd3z8omx6r3u18p72ybvuo1%26rid%3Dgiphy.gif%26ct%3Dg" alt="Bye Bye"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>mysql</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Functors! Not functions</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Sun, 11 Jul 2021 22:37:44 +0000</pubDate>
      <link>https://dev.to/veerreshr/functors-not-functions-2b4f</link>
      <guid>https://dev.to/veerreshr/functors-not-functions-2b4f</guid>
      <description>&lt;p&gt;This is the topic that sounds scary on listening but once you understand the internal meaning, its as easy as an ice cake.&lt;/p&gt;

&lt;p&gt;In simple words, its a fancy way of saying '&lt;em&gt;overloading &lt;code&gt;()&lt;/code&gt; operator&lt;/em&gt;' as Functors or simply '&lt;em&gt;using objects as functions&lt;/em&gt;' . If you don't know what operator overloading is, don't worry we will go through it. If you already know what operator overloading is, skip to Functors .&lt;/p&gt;

&lt;h2&gt;
  
  
  Operator Overloading in C++
&lt;/h2&gt;

&lt;p&gt;Just like you add two numbers you can add 2 objects using this concept. It is simply overloading a operator to work with our user defined objects rather than just predefined objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="nf"&gt;objA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="nf"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="n"&gt;objC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;objA&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here as you add 2 integers to c, you are adding 2 object values and storing it in ObjC. If you directly compile the above code, that will give you an error, as we cannot add two objects directly. This is where we use + operator overloading concept to achieve such a operation. This is done by writing an operator function as the below syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;return_type&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;statements&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;....&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;op&lt;/code&gt; can be any operator you wish to overload. Example &lt;code&gt;+&lt;/code&gt; ,&lt;code&gt;-&lt;/code&gt;,&lt;code&gt;*&lt;/code&gt; etc., there are few exceptions for operators that can be overloaded.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;These are few operators which you cannot overload. &lt;code&gt;.&lt;/code&gt; Member access or dot operator,&lt;code&gt;? :&lt;/code&gt; Ternary or conditional operator,&lt;code&gt;::&lt;/code&gt; Scope resolution operator,&lt;code&gt;.*&lt;/code&gt; Pointer to member operator,&lt;code&gt;sizeof&lt;/code&gt; The object size operator,&lt;code&gt;typeid&lt;/code&gt; Object type operator.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Below is the class definition for implementing &lt;code&gt;+&lt;/code&gt; operator overloading along with some additional code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;private:&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;public:&lt;/span&gt;
        &lt;span class="n"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
        &lt;span class="n"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// +(plus) operator overloading&lt;/span&gt;
    &lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// function to print present value&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s"&gt;"value: "&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="n"&gt;objA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="n"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="n"&gt;objC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;objA&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//3rd line in main function&lt;/span&gt;
    &lt;span class="n"&gt;objC&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//prints : value: 30&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the third line of main function, what myObject class does is, first it detects objA is trying to overload &lt;code&gt;+&lt;/code&gt; operator, then once after detecting it sends objB as a parameter to objA's operator overloading function. Here in the function it creates a temporary &lt;code&gt;temp&lt;/code&gt; object of same class and assigns value by adding values of both current object value&lt;code&gt;_value&lt;/code&gt; and value in objB by &lt;code&gt;obj._value&lt;/code&gt;.It then returns this temp object, this returned object is assigned to objC. This is how objC gets its value.&lt;/p&gt;

&lt;p&gt;On printing the value of objC by using &lt;code&gt;objC.print()&lt;/code&gt; function we get output as &lt;code&gt;value: 30&lt;/code&gt; which indicates _value variable in objC is being assgined.&lt;/p&gt;

&lt;p&gt;This is how operator overloading is performed in c++ and this is how you can add value(or meaning) to specific operator when used with user defined objects.&lt;/p&gt;

&lt;p&gt;Now lets go exploring what functors are,&lt;/p&gt;

&lt;h2&gt;
  
  
  Functors
&lt;/h2&gt;

&lt;p&gt;Functors concept is nothting but making objects act like functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="nf"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//this will output 20, here you are trying to multiply obj value by 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the second line, the object &lt;code&gt;obj&lt;/code&gt; is acting like function, this is achieved by the concept &lt;strong&gt;Functors&lt;/strong&gt;. Here this function mutiplies the value of object obj &lt;code&gt;10&lt;/code&gt; by given parameter value &lt;code&gt;2&lt;/code&gt; and returns the multiplied value &lt;code&gt;20&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is achieved by overloading &lt;code&gt;()&lt;/code&gt; operator. Below is the class definition that implements this operator overloading.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;private:&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;public:&lt;/span&gt;
        &lt;span class="n"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
        &lt;span class="n"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt; &lt;span class="p"&gt;()(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As in above class definition, everytime an object is called as a function, it returns the value of object &lt;code&gt;_value&lt;/code&gt; multiplied by passed parameter. Complete code of above implementation :&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;private:&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;public:&lt;/span&gt;
        &lt;span class="n"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
        &lt;span class="n"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="k"&gt;operator&lt;/span&gt; &lt;span class="p"&gt;()(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="n"&gt;myObject&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//prints : 40&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt; for functors than just using functions could be, for suppose you are declaring an object with a value, so this value is preserved inside that object acting as a state, and every time you execute a functor(i.e, every time you call object as a function) you make changes to the existing state and you are not just excuting a function( as functions don't maintain a state ).&lt;/p&gt;

&lt;p&gt;So in the above code you are multiplying the number 4 to the value 10. Here the value 10 is not hardcoded, its the state maintained by object &lt;code&gt;obj&lt;/code&gt;.I could create another object with another state value and I can apply any changes to the value. Here I am applying changes to the state of an object not an hardcoded value, this is where functors are useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONCLUSION :
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;FUNCTORS ARE THE OBJECTS WHICH COULD BE USED LIKE A FUNCTION&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;em&gt;Thank you for spending your time reading my content. It means a lot to me.I like reading and listening to your comments. Your feedback motivates me to write more and more posts, please take a moment to leave your feedback ❤.&lt;/em&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/3oKIPdvh8ODxvgZ0Jy/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3oKIPdvh8ODxvgZ0Jy/giphy.gif" alt="Thank You" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>programming</category>
      <category>100daysofcode</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Native sensors that can be used within the web by default</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Tue, 08 Jun 2021 04:05:42 +0000</pubDate>
      <link>https://dev.to/veerreshr/native-sensors-that-can-be-used-within-the-web-by-default-4f1o</link>
      <guid>https://dev.to/veerreshr/native-sensors-that-can-be-used-within-the-web-by-default-4f1o</guid>
      <description>&lt;h2&gt;
  
  
  Final result preview:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fllb35stxwffzsd0w56ft.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fllb35stxwffzsd0w56ft.gif" alt="accelerometer reading"&gt;&lt;/a&gt;github link for the code given at end&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction :
&lt;/h2&gt;

&lt;p&gt;Now a days every smart device comes with few integrated sensors within them, which we can use them by writing specific native code. Isn't it hard when you want to write different native code for different devices, as Apple sensor integration could be different from Android and Android could be different from laptops. Here comes the use of Generic sensor API for web, which abstracts the internal work and gives us an API to work with sensors present in devices. Using this you can use sensors of all devices that has browser support( check the  &lt;a href="https://caniuse.com/mdn-api_sensor" rel="noopener noreferrer"&gt;caniuse&lt;/a&gt; site for which browsers support this API. ).It is most useful when you want to use specific sensors and don't want to complicate the implementation by writing different native codes for different platforms.&lt;/p&gt;

&lt;p&gt;In this section I will discuss about few sensors that are supported by  &lt;a href="https://www.w3.org/TR/generic-sensor/" rel="noopener noreferrer"&gt;Generic Sensor API&lt;/a&gt; and there implementation.&lt;br&gt;
Before directly going into knowing how to use certain sensor, I will go through high level overview or workflow of using a sensor.&lt;/p&gt;
&lt;h2&gt;
  
  
  Workflow :
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1623058499770%2FPSoG1qwHw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1623058499770%2FPSoG1qwHw.png" alt="Sensors in Web by Veeresh.jpg"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Sensors :
&lt;/h2&gt;

&lt;p&gt;The term device sensor refers to a device’s underlying physical sensor instance. Each sensor reading is composed of the values of the physical quantity measured by the device sensor at time tn which is called the reading timestamp. &lt;br&gt;
Here is the interface of a sensor (  these denotes the available methods to deal with sensor and its data. ).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[SecureContext, Exposed=(DedicatedWorker, Window)]
interface Sensor : EventTarget {
  readonly attribute boolean activated;
  readonly attribute boolean hasReading;
  readonly attribute DOMHighResTimeStamp? timestamp;
  void start();
  void stop();
  attribute EventHandler onreading;
  attribute EventHandler onactivate;
  attribute EventHandler onerror;
};

dictionary SensorOptions {
  double frequency;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So there is a frequency option which needs to be set by user before initializing a sensor. Few other methods like onreading, onacivate, onerror are used to access data and handle errors. Go through  &lt;a href="https://www.w3.org/TR/generic-sensor/#the-sensor-interface" rel="noopener noreferrer"&gt;sensor-interface&lt;/a&gt;  if you want to know more about it.&lt;/p&gt;

&lt;p&gt;Few of the available generic sensors include :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ambient-light&lt;/li&gt;
&lt;li&gt;accelerometer&lt;/li&gt;
&lt;li&gt;linear-acceleration&lt;/li&gt;
&lt;li&gt;gravity&lt;/li&gt;
&lt;li&gt;gyroscope&lt;/li&gt;
&lt;li&gt;magnetometer&lt;/li&gt;
&lt;li&gt;uncalibrated-magnetometer&lt;/li&gt;
&lt;li&gt;absolute-orientation&lt;/li&gt;
&lt;li&gt;relative-orientation&lt;/li&gt;
&lt;li&gt;geolocation&lt;/li&gt;
&lt;li&gt;proximity&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Let us consider using accelerometer sensor for this demonstration (any sensor can be used in place of accelerometer).&lt;/p&gt;

&lt;h3&gt;
  
  
  Check if your browser supports Generic API :
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if('Accelerometer' in window){
//code to be written if Accelerometer interface is supported by the browser.
}else{
//Your browser doesn't support sensors.
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we will not worry if 'Accelerometer' interface is not  supported by browser. However we can use pollyfill in this case. Using pollyfill you can import only relevant sensors and work with it . To know more about working with polyfill read  &lt;a href="https://github.com/kenchris/sensor-polyfills" rel="noopener noreferrer"&gt;sensor-polyfill&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Permissions
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;navigator.permissions.query({ name: "accelerometer" }).then(result =&amp;gt; {
    if (result.state != 'granted') {
        setGameText("Sorry, we're not allowed to access sensors on your device. ");
        return;
    }
}).catch(err =&amp;gt; {
    console.log("Integration with Permissions API is not enabled");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Currently there isnt any api to request for permission for generic sensors like accelerometer. If you wish to ask for other sensors like geoloaction there is method to request permission :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const permissionsToRequest = {
  permissions: ["geolocation", "storage"]
}
browser.permissions.request(permissionsToRequest)
    .then(onResponse)
    .then((currentPermissions) =&amp;gt; {
    console.log(`Current permissions:`, currentPermissions);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List of all keywords that can be used with permission api are present here at  &lt;a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#api_permissions" rel="noopener noreferrer"&gt;API Permissions&lt;/a&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading data
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let acl = new Accelerometer({frequency: 30});
acl.addEventListener('activate', () =&amp;gt; console.log('Ready to measure.'));
acl.addEventListener('error', error =&amp;gt; console.log(`Error: ${error.name}`));
acl.addEventListener('reading', () =&amp;gt; {
    console.log("Sensor values are : ");
    console.log("X: "+acl.x+" Y: "+acl.y+" Z: "+acl.z);
});
acl.start();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can change the frequency as you wish, but you are not guaranteed with same frequency as all the device sensors doesn't support given frequency.&lt;/p&gt;

&lt;p&gt;So here's the end , Now you are able to read the data from the generic sensor on the web. Below is the &lt;strong&gt;complete code&lt;/strong&gt; combining all three methods above and you can refer to the &lt;a href="https://www.w3.org/TR/generic-sensor/" rel="noopener noreferrer"&gt;generic sensor&lt;/a&gt; to learn more about it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ("Accelerometer" in window) {
  navigator.permissions
    .query({ name: "accelerometer" })
    .then((result) =&amp;gt; {
      if (result.state != "granted") {
        console.log(
          "Sorry, we're not allowed to access sensors on your device. "
        );
        return;
      }

      let acl = new Accelerometer({ frequency: 60 });
      acl.addEventListener("activate", () =&amp;gt; console.log("Ready to measure."));
      acl.addEventListener("error", (error) =&amp;gt;
        console.log(`Error: ${error.name}`)
      );
      acl.addEventListener("reading", () =&amp;gt; {
        console.log("Sensor values are : ");
        console.log("X: " + acl.x + " Y: " + acl.y + " Z: " + acl.z);
      });
      acl.start();
    })
    .catch((err) =&amp;gt; {
      console.log("Integration with Permissions API is not enabled");
    });
} else {
  console.log("Your browser doesn't support sensors.");
}


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

&lt;/div&gt;




&lt;p&gt;For Live Implementation you can visit this site : &lt;a href="https://accelerometer-demo.netlify.app" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://accelerometer-demo.netlify.app" rel="noopener noreferrer"&gt;https://accelerometer-demo.netlify.app&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
Code of this implementation is at : &lt;a href="https://github.com/veerreshr/accelerometer-demo/" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://github.com/veerreshr/accelerometer-demo/" rel="noopener noreferrer"&gt;https://github.com/veerreshr/accelerometer-demo/&lt;/a&gt; &lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;&lt;br&gt;
If you enjoyed the post, consider responding to the article with your feedback. ❤

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A Refresher on Encapsulation and Abstraction in OOPs</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Tue, 19 Jan 2021 12:18:45 +0000</pubDate>
      <link>https://dev.to/veerreshr/difference-between-abstraction-and-encapsulation-in-c-58op</link>
      <guid>https://dev.to/veerreshr/difference-between-abstraction-and-encapsulation-in-c-58op</guid>
      <description>&lt;p&gt;Computer Science students, programmers and newbies to Object Oriented Programming(OOPs) are always confused with two terms : Encapsulation and Abstraction. Usually when someone says that encapsulation is a type of abstraction, it creates more confusion. Coming across terms like Encapsulation and Abstraction in Object Oriented Programming is very stressful to those who are just starting out. The jargon that is used for the concepts of Encapsulation and Abstraction is confusing because it does not mean the same thing to any given person. Today we are going to understand these jargons in OOPs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let us first look at their definitions,
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt; is the method of hiding the unwanted information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt; involves combining data and functions in a single unit (called as a class) and restricts access to data by any object of the unit. This functionality caused by data restriction makes encapsulation also called &lt;strong&gt;data hiding&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For a common man, it sounds like the same thing as hiding data. For a programmer its different as implementation and information hiding.  Let's consider a typical example to figure this out. Let's say we use an Android phone, each mobile contains screen, camera, battery, etc., but the implementation of this functionality of phones can be different. Like one phone will be having an 108 MP camera and the other will be having a 12 MP camera. Here, the end user only knows about the cameras (abstract method or function) and not the way they are implemented internally for each device. &lt;strong&gt;This is referred to as abstraction&lt;/strong&gt;. In the abstraction we know the high level knowledge about system.&lt;br&gt;
Now about Encapsulation, consider a situation where you have 2 departments for your organization (sales, product). At some point and for some reason the product team wants to know about the sales of a product. Here the product team can't access the data of sales directly (as its restricted only for sales team access). First the product team needs to contact some sales officer and request him to get data they needs. &lt;strong&gt;This is what encapsulation meant&lt;/strong&gt;, here sales team comprises of data along with some officers(methods) who help other team people access data by getting in contact with them. So sales team data is only accessible by sales team persons, if some one apart from sales team wants to get the data, they contact sales officer (function or method) of sales team(class) and they can't access directly without help of sales team officer. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In short,&lt;br&gt;
These two things differ from each other from the perspective you see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Abstraction&lt;/strong&gt; is providing generalization (all the features are same for all devices, but their implementation is different) and hiding their implementation. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulation&lt;/strong&gt; is hiding of internal data from outsiders (hiding of all internal functionality of the code or APK).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abstarction&lt;/strong&gt; is Implementation hiding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulation&lt;/strong&gt; is Information hiding.&lt;/li&gt;
&lt;li&gt;Abstraction can be viewed as high level view of logic.&lt;/li&gt;
&lt;li&gt;Encapsulation also implements abstraction, as it restricts the data from others.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Still confused ? Lets understand with code
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;maths&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;private:&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
  &lt;span class="n"&gt;maths&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getA&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getB&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Internal representation of any object of &lt;code&gt;maths&lt;/code&gt; class is hidden outside the class. That is the variables &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; can not be accessed directly by other class objects. These variables are restricted to only maths class objects, if some other class object wants to access the variables &lt;code&gt;a&lt;/code&gt;,&lt;code&gt;b&lt;/code&gt; they need to contact some maths class object and get data through them. &lt;strong&gt;This restriction of data is called Encapsulation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are made private so that these can only be manipulated by set method, which is only accessible to objects of maths class. &lt;strong&gt;This binding of data and methods together is also called as encapsulation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now lets talk about abstraction,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;maths&lt;/span&gt; &lt;span class="n"&gt;math_object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;maths&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;math_object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//add function is abstracted&lt;/span&gt;
  &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the implementation of the &lt;code&gt;add&lt;/code&gt; function is known as Abstraction. Because, we know the necessary details (&lt;code&gt;add&lt;/code&gt; function) that we need and we don't know the unnecessary detail (internal working of &lt;code&gt;add&lt;/code&gt; function) for performing a particular action (adding two numbers). This masking of the implementation of the addition functionality (unwanted information) is referred to as &lt;strong&gt;Abstraction&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here is a table to represent the differences
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fcdn.differencebetween.net%2Fwp-content%2Fuploads%2F2017%2F12%2FDifference-between-Abstraction-and-Encapsulation.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fcdn.differencebetween.net%2Fwp-content%2Fuploads%2F2017%2F12%2FDifference-between-Abstraction-and-Encapsulation.jpg" alt="Abstraction vs Encapsulation"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;source of the table : &lt;a href="http://www.differencebetween.net/technology/difference-between-abstraction-and-encapsulation/" rel="noopener noreferrer"&gt;differencebetween.net&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;If you found this article useful, please leave your suggestions here❤.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>oop</category>
      <category>cpp</category>
    </item>
    <item>
      <title>SEO Tags | Meta tags that you need for previews on social networks.</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Thu, 14 Jan 2021 20:18:58 +0000</pubDate>
      <link>https://dev.to/veerreshr/seo-tags-meta-tags-that-you-need-for-previews-on-social-networks-343n</link>
      <guid>https://dev.to/veerreshr/seo-tags-meta-tags-that-you-need-for-previews-on-social-networks-343n</guid>
      <description>&lt;blockquote&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;To begin with, what are meta tags?&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Meta tags provide information about the web page in the HTML of the document. This information is called "metadata" and while it is not displayed on the page itself, it can be read by search engines and web bots&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I will now show you how you might give an overview of your application when you share it on social media. That is, adding a preview for your app.&lt;br&gt;
Something like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh5i4difh03jj2v0ahpxr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh5i4difh03jj2v0ahpxr.jpg" alt="Google, Whatsapp Previews"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqa54w37ccvlv61es8oi7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqa54w37ccvlv61es8oi7.jpg" alt="Facebook, Instagram, LinkedIn,Twitter Previews"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a web bot to understand your application, this is the basic code you are supposed to add.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;title&amp;gt;Your Page Title&amp;lt;/title&amp;gt;
&amp;lt;meta name="title" content="Your Page Title"&amp;gt;
&amp;lt;meta name="description" content="Your Page Description"&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;But wait, it's not enough for every app to be able to read your web page and so it can give an appropriate preview of your app.&lt;/p&gt;

&lt;p&gt;In order to get a proper preview from Facebook, Instagram, WhatsApp, LinkedIn like apps, you are supposed to add specific meta tags which are required by these crawlers. These tags are called Open Graph tags by Facebook, By which facebook related apps keep control of your app data.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;!-- Open Graph  --&amp;gt;
&amp;lt;meta property="og:type" content="website"&amp;gt;
&amp;lt;meta property="og:url" content="https://yourpage.com/"&amp;gt;
&amp;lt;meta property="og:title" content="Your Page Title"&amp;gt;
&amp;lt;meta property="og:description" content="Your Page Description"&amp;gt;
&amp;lt;meta property="og:image" itemprop="image" content="https://yourimagepath.jpg"&amp;gt;


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;! important&lt;/strong&gt;&lt;br&gt;
You need to add itemprop="image" attribute to og:image tag&lt;br&gt;
In order to display the image in the preview of Whatsapp. Also, be sure to keep your preview image below 300 KB.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you would like to use &lt;a href="https://www.facebook.com/ads/audience-insights" rel="noopener noreferrer"&gt;Facebook Insights&lt;/a&gt;, you need to add the app ID to your page. Insights gives you the ability to view traffic statistics on your site from Facebook. You can do so by adding the tag below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;!-- Replace 123456789123456 with your app id --!&amp;gt;
&amp;lt;meta property=fb:app_id content=123456789123456&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;You are needed to create Facebook developer account in order to get app id. Then, You are supposed to create an app and link your webpage there. Refer this link in order to get your app id : &lt;a href="https://developers.facebook.com/apps" rel="noopener noreferrer"&gt;app id&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now coming to Twitter, below are the tags you need to add in order for Twitter to show a preview of your app when shared.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;meta property="twitter:card" content="summary_large_image"&amp;gt;
&amp;lt;meta property="twitter:url" content="https://yourpage.com/"&amp;gt;
&amp;lt;meta property="twitter:title" content="Your Page Title"&amp;gt;
&amp;lt;meta property="twitter:description" content="Your Page Description"&amp;gt;
&amp;lt;meta property="twitter:image" content="https://yourimagepath.jpg"&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;Similar to Facebook insights, Twitter has its own &lt;a href="https://analytics.twitter.com/about" rel="noopener noreferrer"&gt;Twitter Analytics&lt;/a&gt; which requires the below tag, where you are supposed to enter your Twitter username&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;meta name="twitter:site" content="@twitter-username"&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;After all these changes you may find that you are not able to see your changes&lt;/strong&gt;, That's because your cache is not cleared from your social media pages i.e., your webpages are not yet crawled by bots after your changes. In order to make them crawl use these :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In order to reflect the changes to Facebook, Instagram, WhatsApp, just go to this &lt;a href="https://developers.facebook.com/tools/debug/" rel="noopener noreferrer"&gt;link&lt;/a&gt; and enter your website URL and scrape it again. This site also lets you check which meta tags you can add in order to enhance.&lt;/li&gt;
&lt;li&gt;For twitter just go to &lt;a href="https://cards-dev.twitter.com/validator" rel="noopener noreferrer"&gt;Twitter Validator&lt;/a&gt; and enter your URL and click on preview card. Now twitter fetches new changes and updates its caches.&lt;/li&gt;
&lt;li&gt;LinkedIn provides Post Inspector that deletes the preview cache. Simply debug the cached URL &lt;a href="https://www.linkedin.com/post-inspector/inspect/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Complete code
&lt;/h1&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;!-- Primary Meta Tags --&amp;gt;
&amp;lt;title&amp;gt;Your Page Title&amp;lt;/title&amp;gt;
&amp;lt;meta name="title" content="Your Page Title"&amp;gt;
&amp;lt;meta name="description" content="Your Page Description"&amp;gt;

&amp;lt;!-- Open Graph --&amp;gt;
&amp;lt;meta property="og:type" content="website"&amp;gt;
&amp;lt;meta property="og:url" content="https://yourpage.com/"&amp;gt;
&amp;lt;meta property="og:title" content="Your Page Title"&amp;gt;
&amp;lt;meta property="og:description" content="Your Page Description"&amp;gt;
&amp;lt;meta property="og:image" itemprop="image" content="https://yourimagepath.jpg"&amp;gt;

&amp;lt;!-- Twitter --&amp;gt;
&amp;lt;meta property="twitter:card" content="summary_large_image"&amp;gt;
&amp;lt;meta property="twitter:url" content="https://yourpage.com/"&amp;gt;
&amp;lt;meta property="twitter:title" content="Your Page Title"&amp;gt;
&amp;lt;meta property="twitter:description" content="Your Page Description"&amp;gt;
&amp;lt;meta property="twitter:image" content="https://yourimagepath.jpg"&amp;gt;

&amp;lt;!-- For Facebook Insights --!&amp;gt;
&amp;lt;meta property=fb:app_id content=123456789123456&amp;gt;

&amp;lt;!-- For Twitter Analytics --!&amp;gt;
&amp;lt;meta name="twitter:site" content="@twitter-username"&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;Thanks for making it this far 🙏. If this helped you in any way, please drop a like.&lt;/p&gt;

</description>
      <category>seo</category>
      <category>html</category>
    </item>
    <item>
      <title>Qute Bot GitHub Action</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Tue, 15 Sep 2020 19:03:30 +0000</pubDate>
      <link>https://dev.to/veerreshr/qute-bot-183e</link>
      <guid>https://dev.to/veerreshr/qute-bot-183e</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Its a Telegram bot action which sends inspiring quotes daily morning&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  My Workflow : &lt;a href="https://github.com/veerreshr/quteBot/actions?query=workflow%3A%22Qute+Bot%22"&gt;Qute Bot&lt;/a&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Submission Category: Wacky Wildcards
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Yaml File or Link to Code
&lt;/h3&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/veerreshr"&gt;
        veerreshr
      &lt;/a&gt; / &lt;a href="https://github.com/veerreshr/quteBot"&gt;
        quteBot
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Github Action which fires a Inspirational quote in telegram every day at 8:00 AM IST
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/veerreshr/quteBotlogo.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uc0BXlbu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/veerreshr/quteBotlogo.png" alt="Logo"&gt;&lt;/a&gt; QuteBot&lt;/h1&gt;
&lt;h2&gt;
Telegram bot which messages inspiring quotes at 8am in Indian time, works based on github action&lt;/h2&gt;
&lt;h2&gt;
View :&lt;/h2&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/veerreshr/quteBot20-10-05-08-26-05.GIF"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PLv1pp8m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/veerreshr/quteBot20-10-05-08-26-05.GIF" alt="Demo"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/veerreshr/quteBot"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>actionshackathon</category>
      <category>showdev</category>
      <category>github</category>
    </item>
    <item>
      <title>Deploy react app to GitHub pages with and without a custom domain</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Sun, 16 Aug 2020 10:26:09 +0000</pubDate>
      <link>https://dev.to/veerreshr/deploy-react-app-to-github-pages-with-and-without-custom-domain-1h8d</link>
      <guid>https://dev.to/veerreshr/deploy-react-app-to-github-pages-with-and-without-custom-domain-1h8d</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Want to deploy your react app for free?&lt;br&gt;
If yes, then gh-pages from Github is your free tool for deployment&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let's get started!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l0IyjiXOXTX6Yemsg/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l0IyjiXOXTX6Yemsg/giphy.gif" alt="lets get started"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Here are simple steps we will be going through&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Install gh-pages as a dev dependency&lt;/li&gt;
&lt;li&gt;few changes to package.json in your code&lt;/li&gt;
&lt;li&gt;deployment&lt;/li&gt;
&lt;li&gt;Adding a custom domain&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;STEP 1&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install gh-pages --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will save gh-pages dependency as a dev dependency&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;STEP 2&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"homepage" : "http://{github-user-name}.github.io/{github-repository-name}"
"scripts": {
//...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}

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

&lt;/div&gt;



&lt;p&gt;Paste the above code inside of your package.json.Remember to paste script predeploy and deploy as extra scripts to existing scripts and don't override your previous scripts&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;STEP 3&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the above command in terminal. Now your app is live on GitHub pages. It's available at homepage URL you specified above(http://{github-user-name}.github.io/{github-repository-name})&lt;br&gt;
&lt;a href="https://i.giphy.com/media/3oz8xAFtqoOUUrsh7W/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3oz8xAFtqoOUUrsh7W/giphy.gif" alt="you did it "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Yes, it's live now. But sometimes you won't be able to see your output (maybe due to some GitHub glitches), All you need to do is go to your GitHub repo settings and search for Github pages in it&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--310-gYyq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/14ocn3vpnf5tqbbdrglu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--310-gYyq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/14ocn3vpnf5tqbbdrglu.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Then click on choose a theme and select a random theme from themes page&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j_j8XZjN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n8t7lo5hk3edq6uuqm17.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j_j8XZjN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n8t7lo5hk3edq6uuqm17.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Now your site will be live, I don't know why it's working but it worked 😂&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;STEP 4 :&lt;/strong&gt; &lt;em&gt;Adding custom domain&lt;/em&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Search for GitHub pages in repo settings and enter your domain name inside of custom domain input field(format must be www .domain.com or domain.com only)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--axriZr6c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ruon6l972dfir4bmea5f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--axriZr6c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ruon6l972dfir4bmea5f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
This will create a CNAME file in the root of your project publishing source. This file contains the domain name you entered&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure DNS Records, You just need to set A and CNAME records in your domain name registrar(like GoDaddy, Namecheap etc).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Setting up A record&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A record&lt;/strong&gt; stands for an address record, it connects your domain name to the actual IP addresses where your site resides on a server&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now set the following IP's for A records as value and host(or name) as @ symbol&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;185.199.108.153
185.199.109.153
185.199.110.153 
185.199.111.153
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;setting up CNAME Record
what is CNAME record? &lt;a href="https://support.dnsimple.com/articles/cname-record/"&gt;click here&lt;/a&gt;
Add cname record with name www, type cname,ttl hour or less, data field with URL of your GitHub deployed page domain &lt;strong&gt;ending with dot&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;{username}.github.io/{repo-name}. &lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;h4&gt;
  
  
  &lt;strong&gt;That's it, it will be live on your custom domain may be within 24hrs&lt;/strong&gt;
&lt;/h4&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;yay! now you know how to deploy your react app to GitHub with and without custom domain&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/54YeJKsHggPxoQWXKL/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/54YeJKsHggPxoQWXKL/giphy.gif" alt="yay"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;&lt;center&gt;---Thank You---&lt;center&gt;&lt;/center&gt;
&lt;/center&gt;&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/cL5HSQ3L3bi3DX67nP/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/cL5HSQ3L3bi3DX67nP/giphy.gif" alt="alt"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>react</category>
    </item>
    <item>
      <title>Flash Sale magic</title>
      <dc:creator>Veeresh</dc:creator>
      <pubDate>Thu, 16 Jul 2020 02:54:06 +0000</pubDate>
      <link>https://dev.to/veerreshr/flash-sale-magic-4l4o</link>
      <guid>https://dev.to/veerreshr/flash-sale-magic-4l4o</guid>
      <description>&lt;p&gt;&lt;em&gt;Its a python script that automates to buy the product from amazon(can be anything with little changes).&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;This bot is created to explore selenium in python&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;what is a flash sale? Its a kind of sale where stocks will be limited and get cleared in minutes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;All I wanted to buy a product from amazon which was in flash sales. So thought of creating a python script for automating.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/4QFcVnf41d2Lb5I0MK/giphy-downsized.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/4QFcVnf41d2Lb5I0MK/giphy-downsized.gif" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Idea:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.selenium.dev/"&gt;Selenium&lt;/a&gt; is my go-to tool for automating with python, with the help of selenium we first open the amazon login link. Once after logging in, we will be redirected to the home page of Amazon, then we will be opening our product page. If in case the items are out of stock or not available you will not be getting buy now option, this is where we will taking advantage. We will search for buy now element on the page, we keep refreshing until we find buy now. Once on clicking buy now it will direct you to address, mode of payment, review order page. These steps will be automated with selenium. At last, u are needed to enter your one-time password and confirm to order(in case of cash on delivery it's not needed)&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Let's get into code:&lt;/strong&gt;
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Prerequisite:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Firstly you are required to install selenium and respective web drivers(i will be using chrome web drivers). Don’t know how to install it? here you go- &lt;a href="https://selenium-python.readthedocs.io/installation.html"&gt;installation documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Get your product link&lt;/li&gt;
&lt;li&gt;add address and payment mode in prior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you are ready to get into the code!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Complete code is given at the end of a blog&lt;br&gt;
Lets Import a few packages and will explain those while going through code&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;let us choose page load strategy to eager(which loads page before some images get loaded), which benefits in navigating quicker with pages and its data. Let us also create login_url variable which opens amazon sign-in page&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;options = Options()
options.page_load_strategy = 'eager'
login_url = 'https://amzn.to/38X1LHr'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now let us create a function that takes your amazon account credentials and your products page link(or product share link).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ABEPVqwr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ucu7154n50qnb280jtti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ABEPVqwr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ucu7154n50qnb280jtti.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
XPath elements in the above code are used to identify input elements uniquely from the web page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What is XPath?&lt;br&gt;
XPath is a major element in the XSLT standard.&lt;br&gt;
XPath can be used to navigate through elements and attributes in an XML document.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;address_xpath is used to identify which address you want to deliver from your multiple pre-saved addresses in amazon. Chrome driver is used and set to eager loading mode so that the page doesn't wait for all images to be loaded&lt;/p&gt;

&lt;p&gt;first, we open the login URL of amazon and log in using credentials provided from function parameters, all the browser actions are done with the help of the driver instance we created. once the page gets loaded, we redirect to another page with the help of driver.get(item_url) .till we find the item available we keep refreshing the page with the while provided. Presence of buy button is identified by driver.find_element_by_xpath(XPath-of-buy-button). once we find that element, we click using elements.click() method. All the remaining code is to navigate through remaining pages and explained in the code with comments&lt;/p&gt;

&lt;p&gt;Now let's call the function with username, password,item_url, CVV of our card in amazon&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;purchase("test@test.com", "test", "itemurl.com", "123")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;By running the above code you will be able to automate the bot for purchasing products during a flash sale&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;BONUS:&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;In order to purchase a product from two different accounts at the same time, I used multiprocessing in python. For that, we need to import process from multiprocessing&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from multiprocessing import Process
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now create 2 processes and run at the same time using the below code, you can even more than 2 processes to buy from multiple accounts&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if __name__ == '__main__':
    p1 = Process(target=purchase, args=["test1@test.com", "test_password", "product_link", "cvv"])
    p1.start()
    p2 = Process(target=purchase, args=["test2@test.com", "test_password", "product_link", "cvv"])
    p2.start()
    p1.join()
    p2.join()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Woohoo it's over&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/efHpdducCDKUMMyzte/giphy-downsized.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/efHpdducCDKUMMyzte/giphy-downsized.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Complete code :&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;First code is for a single person to purchase and the second code is for 2 persons(and can be modifiable for more people)to be purchased at the same time&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/hFXwY4lER3oBO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/hFXwY4lER3oBO/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>automation</category>
      <category>bot</category>
      <category>amazon</category>
    </item>
  </channel>
</rss>
