<?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>Forem: Keramot UL Islam</title>
    <description>The latest articles on Forem by Keramot UL Islam (@abmsourav).</description>
    <link>https://forem.com/abmsourav</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%2F285347%2F172b72b5-b6e6-4dc6-9a66-308c160d300c.jpg</url>
      <title>Forem: Keramot UL Islam</title>
      <link>https://forem.com/abmsourav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abmsourav"/>
    <language>en</language>
    <item>
      <title>Career Growth tracker</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Tue, 17 Oct 2023 07:38:33 +0000</pubDate>
      <link>https://forem.com/abmsourav/career-growth-tracker-14ef</link>
      <guid>https://forem.com/abmsourav/career-growth-tracker-14ef</guid>
      <description>&lt;p&gt;CV or Resume is not just some words on a paper. But it's a journey that has been written.&lt;/p&gt;

&lt;p&gt;So don't write your CV/Resume just before you apply somewhere.&lt;br&gt;
You should start writing your CV after finishing school, and continuously update it. Update it for the rest of your life.&lt;/p&gt;

&lt;p&gt;Yes, you should update it for the rest of your life, because it's not only for applying for a job. But it will continuously visualize your growth to yourself.&lt;/p&gt;

&lt;p&gt;That's all it takes... &lt;br&gt;
When you are writing the truth about yourself, and visualizing it to yourself, then you can see that you don't have many things to write and so you feel helpless...&lt;/p&gt;

&lt;p&gt;Those feelings will continuously kick on your back and you will start running, and you will become hungry to achieve the next thing, then the next, next thing.&lt;/p&gt;

</description>
      <category>career</category>
      <category>resume</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My learning from creating tools for developers</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Fri, 08 Oct 2021 10:55:00 +0000</pubDate>
      <link>https://forem.com/abmsourav/my-learning-from-creating-tools-for-developers-1m6p</link>
      <guid>https://forem.com/abmsourav/my-learning-from-creating-tools-for-developers-1m6p</guid>
      <description>&lt;p&gt;Once you cross the beginner's level as a developer, some questions should start arising in your head... &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How does a developer think?&lt;/li&gt;
&lt;li&gt;Why does he need that xyz tool?&lt;/li&gt;
&lt;li&gt;How does a tool solve a problem?&lt;/li&gt;
&lt;li&gt;What's happening behind the scenes in that xyz tool?&lt;/li&gt;
&lt;li&gt;How to think in a generic/global way from a problem-solving perspective?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Wait, don't Google these questions, because these are kinda questions where you need to realize the answer, you need to feel the answer.&lt;/p&gt;

&lt;p&gt;So, what's the process, how will we know the answers? &lt;br&gt;
For me the answer is "creating open-source developers tools". I mean, creating open-source tools that will be used by other developers. When you start creating developer tools, your brain starts adopting millions of developers' thought processes. It's a journey where you'll learn the answers to those questions. But if you want to know more than those answers then you need to create multiple personalities in you.&lt;br&gt;
Which are:&lt;br&gt;
=&amp;gt; A problem solver,&lt;br&gt;
=&amp;gt; An observer,&lt;br&gt;
=&amp;gt; A person who has Childish perspective. &lt;/p&gt;

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

&lt;h4&gt;
  
  
  Dev Tools developed by me
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://bdapis.herokuapp.com/"&gt;BD API&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/@abmsourav/localdb"&gt;LocalDB&lt;/a&gt;&lt;br&gt;
These projects are managed by my GitHub organization. Feel free to contribute on these open-source projects on &lt;a href="https://github.com/CodesVault"&gt;CodesVault&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Feeling positive energy, huh?&lt;br&gt;
Now here's a trap. When you want to create a dev tool, lots of ideas will come to your brain. You will peck the most complex one and then after doing some google search, you will know that those types of tools already exist in many ways.&lt;br&gt;
Then after repeating this process for multiple times you'll lose that positive energy :( &lt;/p&gt;

&lt;p&gt;So, the hack is don't find unique, complex ideas. Find the idea that sounds extremely easy to you, and in your thought process you already know the implementation.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>opensource</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Depth First Traverse</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Thu, 01 Jul 2021 09:04:44 +0000</pubDate>
      <link>https://forem.com/abmsourav/depth-first-traverse-3hb7</link>
      <guid>https://forem.com/abmsourav/depth-first-traverse-3hb7</guid>
      <description>&lt;p&gt;Depth First is an algorithm that traverses data structures focusing on the depth of nodes. It is useful for searching data in a DS or adding or updating data in the nth place of a DS.&lt;/p&gt;

&lt;p&gt;There are Three types of DFT [Depth First Traverse]&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pre Order&lt;/li&gt;
&lt;li&gt;In Order&lt;/li&gt;
&lt;li&gt;Post Order&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let’s see a code example of DFT algorithm on a Binary tree.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dft_preOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;dftRecursion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;

        &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// pre order&lt;/span&gt;
        &lt;span class="nx"&gt;dftRecursion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nx"&gt;dftRecursion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;dftRecursion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dft_preOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;binaryTree&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// result: [ 1, 2, 4, 5, 3, 4, 6 ]&lt;/span&gt;

&lt;span class="c1"&gt;// put a binary tree as the root parameter. &lt;/span&gt;
&lt;span class="c1"&gt;// It looks like this:&lt;/span&gt;
&lt;span class="c1"&gt;//            1&lt;/span&gt;
&lt;span class="c1"&gt;//          /   \&lt;/span&gt;
&lt;span class="c1"&gt;//         2      3&lt;/span&gt;
&lt;span class="c1"&gt;//        / \    / \&lt;/span&gt;
&lt;span class="c1"&gt;//       4   5  4   6   &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;
So, What’s happening here:
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access the root node, put it in the stack, then pop from the stack&lt;/li&gt;
&lt;li&gt;Printed its data.&lt;/li&gt;
&lt;li&gt;Then “if next nodes are not null” then, put its next right and left nodes in the stack. But “if null” then bring the last item from the stack.&lt;/li&gt;
&lt;li&gt;Bring the last item from the stack, which is the left node.&lt;/li&gt;
&lt;li&gt;Then printed its data.&lt;/li&gt;
&lt;li&gt;Keep doing the above, till the stack is not empty.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Read the full article to know more about all types of Depth First Traverse using animations on my blog. &lt;a href="https://blog.abmsourav.com/depth-first-traverse/"&gt;Click Here&lt;/a&gt;
&lt;/h4&gt;

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

</description>
      <category>algorithms</category>
      <category>programming</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Web Components with JavaScript</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Wed, 17 Feb 2021 16:36:13 +0000</pubDate>
      <link>https://forem.com/abmsourav/web-components-with-javascript-8c6</link>
      <guid>https://forem.com/abmsourav/web-components-with-javascript-8c6</guid>
      <description>&lt;p&gt;Web components are a way to create custom, reusable HTML elements. Using web components you can create custom HTML elements with JavaScript. Framework/Libraries like ReactJS, VueJS also offer reusable, custom components. But with vanilla JavaScript, we also can create custom components. We also can make our custom elements isolated from other DOM elements. &lt;/p&gt;

&lt;p&gt;Three things need to understand to learn Web Components:&lt;br&gt;
&lt;strong&gt;Custom Elements:&lt;/strong&gt; You can create a custom DOM element/tag with a JavaScript APIs. By convention use hyphen to declare a custom elements, for example: &lt;code&gt;&amp;lt;my-element&amp;gt;&amp;lt;/my-element&amp;gt;&lt;/code&gt; . We use hyphen so that it doesn’t mess with other native elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shadow DOM:&lt;/strong&gt; When you need to create a private, isolated custom element, then we use a set of JavaScript API called Shadow DOM. It also renders separately from the main Document DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML Templates:&lt;/strong&gt; We have a couple of HTML elements that don’t display on the main rendered page. We can render those element contents when we actually need to render those and we also can reuse those contents. Those elements are: &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;slot&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Custom Elements
&lt;/h4&gt;

&lt;p&gt;Now let’s see how we can create a custom element. For creating a custom element let’s call &lt;code&gt;define&lt;/code&gt; method of &lt;code&gt;customElements&lt;/code&gt; API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CustomComponent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s extends CustomComponent class from HTMLElement to create a custom element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CustomComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;p&amp;gt;Hello Universe&amp;lt;/p&amp;gt;`&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="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CustomComponent&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;HTMLElement&lt;/code&gt; has four lifecycle hooks. &lt;code&gt;connectedCallback&lt;/code&gt; is one of them. It executes every time the element is inserted into the DOM. We can put out markups in it, get dependency data from other components, etc.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Shadow DOM
&lt;/h4&gt;

&lt;p&gt;We also can create isolated components. Isolated components don’t mess with the main DOM. It renders in lite wait DOM called Shadow DOM. In main DOM everything is in a global scope. So conflicts and security issues can happen easily. Shadow DOM is a wrapper of the custom component, it makes the component isolated from other main DOM elements/components. You can attach Shadow DOM in any main DOM elements or custom elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CustomComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nx"&gt;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;p&amp;gt;Hello Universe&amp;lt;/p&amp;gt;`&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="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CustomComponent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  HTML Templates
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tag contents don’t render in the page. So you can write your contents in it and then clone those nodes with JavaScript in the custom components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;TestComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;templateNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-template&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;templateContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;templateNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;templateContent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cloneNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&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="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-template&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TestComponent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;a href="https://i.giphy.com/media/PmpojRrxEPLQt4YYar/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/PmpojRrxEPLQt4YYar/giphy.gif" alt="Cheers" width="220" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>webcomponents</category>
    </item>
    <item>
      <title>Headless WordPress Dynamic pages with GatsbyJS</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Sat, 24 Oct 2020 09:02:59 +0000</pubDate>
      <link>https://forem.com/abmsourav/headless-wordpress-dynamic-pages-with-gatsbyjs-1641</link>
      <guid>https://forem.com/abmsourav/headless-wordpress-dynamic-pages-with-gatsbyjs-1641</guid>
      <description>&lt;p&gt;In this article, I will show ‘how to create dynamic pages/routes with GatsbyJS’. I will fetch all post data from the WordPress website and create dynamic routes for each post.&lt;/p&gt;

&lt;p&gt;At first, we need to create &lt;code&gt;gatsby-node.js&lt;/code&gt; file in the root of our &lt;code&gt;wp-gatsby&lt;/code&gt; project directory. Gatsby handles all dynamic routes from this file. Then add this asynchronous function in the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createPages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;graphql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createPage&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wpData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;graphql&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
        {
            allWordpressPost {
                nodes {
                    wordpress_id
                    slug
                    title
                    content
                    author {
                        name
                    }
                }
            }
        }
  `&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wpData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wpData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;allWordpressPost&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wpData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;
    &lt;span class="nx"&gt;allWordpressPost&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;createPage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`./src/templates/post.js`&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;post&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I wrote a Graphql query to fetch post data from the WordPress website than on line 26 creating dynamic routes.&lt;/p&gt;

&lt;p&gt;Behind the screen, Gatsby will create routes &lt;code&gt;root-url/post-slug&lt;/code&gt; for each post, expect output from &lt;code&gt;./src/templates/post.js&lt;/code&gt; this file and Gatsby will also send each post data to this file.&lt;/p&gt;

&lt;p&gt;So now let’s go ahead and create &lt;code&gt;post.js&lt;/code&gt; file on the following path and add these pieces of code to the file…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the original full article on my &lt;a href="https://blog.abmsourav.com/headless-wordpress-dynamic-pages-with-gatsbyjs/"&gt;blog&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article is a part of my  &lt;a href="https://blog.abmsourav.com/category/headless-wp/"&gt;Headless WP&lt;/a&gt; series&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>wordpress</category>
      <category>javascript</category>
      <category>graphql</category>
    </item>
    <item>
      <title>Headless WordPress with GatsbyJS 101</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Mon, 24 Aug 2020 06:36:17 +0000</pubDate>
      <link>https://forem.com/abmsourav/headless-wordpress-with-gatsbyjs-101-5a79</link>
      <guid>https://forem.com/abmsourav/headless-wordpress-with-gatsbyjs-101-5a79</guid>
      <description>&lt;p&gt;WordPress has built-in support for Rest API. So Making WordPress headless is possible with many tools. In this article, I will show “how you can fetch data from WordPress site with GatsbyJS”.&lt;/p&gt;

&lt;p&gt;Why GatsbyJS?&lt;br&gt;
Making dynamic routes are easy and also customizable. Gatsby has some plugins that work out of the box to make WordPress headless easily and their documentation is also amazing. Gatsby also has default support for Graphql.&lt;/p&gt;

&lt;p&gt;What do you need to know before you start following this article?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WordPress, WordPress plugin installation&lt;/li&gt;
&lt;li&gt;Better knowledge of JavaScript&lt;/li&gt;
&lt;li&gt;Familiar with ReactJS, GatsbyJS, Graphql&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/85Q7aV4R5bxDO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/85Q7aV4R5bxDO/giphy.gif" alt="captain" width="500" height="200"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
At first install WordPress on a local environment or on a live server, then install these two plugins: &lt;a href="https://github.com/wp-graphql/wp-graphql"&gt;WP Graphql&lt;/a&gt;, &lt;a href="https://github.com/wp-graphql/wp-graphiql"&gt;WP Graphiql&lt;/a&gt;&lt;br&gt;
WP Graphql will create graphql API for WordPress and WP Graphiql will create a user interface for that. Give some time and get familiar with the interface.&lt;/p&gt;

&lt;p&gt;Now install Gatsby CLI globally: &lt;code&gt;npm install -g gatsby-cli&lt;/code&gt;&lt;br&gt;
Then install a Gatsby starter: &lt;br&gt;
&lt;code&gt;gatsby new wp-gatsby https://github.com/gatsbyjs/gatsby-starter-hello-world&lt;/code&gt;&lt;br&gt;
It will install a Gatsby starter project in &lt;code&gt;wp-gatsby&lt;/code&gt; directory. Now &lt;code&gt;cd&lt;/code&gt; into that folder and run: &lt;code&gt;gatsby develop&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you can see your new Gatsby site running on: &lt;code&gt;http://localhost:8000/&lt;/code&gt;&lt;br&gt;
Install “Gatsby Source WordPress” plugin: &lt;code&gt;npm install gatsby-source-wordpress&lt;/code&gt;. And change &lt;code&gt;gatsby-config.js&lt;/code&gt; file like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;plugins&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="na"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`gatsby-source-wordpress`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`siteUrl`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// site url without http/https&lt;/span&gt;
            &lt;span class="na"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`http`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;hostingWPCOM&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;useACF&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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="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;This Gatsby plugin will help to fetch data from your WordPress site with Graphql. Now again run &lt;code&gt;gatsby develop&lt;/code&gt;, and go to: &lt;code&gt;http://localhost:8000/___graphql&lt;/code&gt;. Here you will see almost the same Graphql IDE which you have seen earlier in your WordPress site... ..&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the original full article on my &lt;a href="https://blog.abmsourav.com/headless-wordpress-with-gatsbyjs-101/"&gt;blog&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>wordpress</category>
      <category>gatsby</category>
      <category>graphql</category>
    </item>
    <item>
      <title>Two Sum Solution in JavaScript</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Mon, 20 Jul 2020 19:38:22 +0000</pubDate>
      <link>https://forem.com/abmsourav/two-sum-solution-in-javascript-3m3f</link>
      <guid>https://forem.com/abmsourav/two-sum-solution-in-javascript-3m3f</guid>
      <description>&lt;p&gt;So what the hell is Two Sum? Well, it's a very popular Problem set in the world of Programming.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Given an array of integers, return indices of the two numbers such that they add up to a specific target.&lt;br&gt;
You may assume that each input would have exactly one solution, and you may not use the same element twice.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Basically what it saying is, you have an array and an integer. For example: &lt;code&gt;[3, 2, 4] 6&lt;/code&gt;. Now add two items of the array and the result must be 6, &lt;code&gt;2 + 4 = 6&lt;/code&gt;. And don't forget that you can not add the same array item &lt;code&gt;3 + 3 = 6&lt;/code&gt;, you can't do this here :P.&lt;br&gt;
When you get the result of the sum which is equal to the integer then return the index of those two array items as an array. So the index of 2 is 1, and the index of 4 is 2, and the result is &lt;code&gt;[1, 2]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In JavaScript there are lot's of ways you can solve this, I will describe you two of them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;twoSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;twoSum&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// [0, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are finding which two array items create a sum that is equal to &lt;em&gt;target&lt;/em&gt; integer, then store the index of those two items in an array and return that array.&lt;br&gt;&lt;br&gt;
Everything works fine here but what about &lt;strong&gt;Time Complexity&lt;/strong&gt;. We are looping through the array twice, which means the &lt;em&gt;Time Complexity&lt;/em&gt; is &lt;code&gt;O(n^2)&lt;/code&gt;. It's quite expensive, isn't it?&lt;/p&gt;

&lt;p&gt;Okay, now let's see a better approach...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;twoSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;secondItemIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// (secondItemIndex &amp;gt; -1) if array item is grater than target, then ignore that item&lt;/span&gt;
        &lt;span class="c1"&gt;// (secondItemIndex !== i) if same index, then ignore that item&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;secondItemIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;secondItemIndex&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;secondItemIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;twoSum&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this function mainly two thinks are happing, at first we are finding the difference between array item and target, &lt;code&gt;2 - 8 = 6&lt;/code&gt;. Then finding the index of that number in the array, &lt;code&gt;nums.indexOf(diff)&lt;/code&gt;.&lt;br&gt;
The most important thing is in this scenario the &lt;strong&gt;Time Complexity&lt;/strong&gt; is &lt;code&gt;O(n)&lt;/code&gt;, which is almost half of the previous one.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>My crappy Thoughts about Programming</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Tue, 16 Jun 2020 15:37:11 +0000</pubDate>
      <link>https://forem.com/abmsourav/my-crappy-thoughts-about-programming-4n57</link>
      <guid>https://forem.com/abmsourav/my-crappy-thoughts-about-programming-4n57</guid>
      <description>&lt;p&gt;All programming ideas or implementations came from real-life solutions or problems. And that makes programming more than just coding.&lt;br&gt;
It takes detailed observation of everything. Because understanding and realizing existing solutions or problems are the most important part of programming.&lt;/p&gt;

&lt;p&gt;For Example:&lt;br&gt;
We know about JWT(JSON Web Token) right?&lt;br&gt;
Did we have seen this idea and the implementation before somewhere else? Yes, we all know this. In fact, we all have gone through this several times. &lt;br&gt;
&lt;strong&gt;=&amp;gt;&lt;/strong&gt; When we go to a service center, at first they give us a ticket/token. Then we go to the service provider and give our ticket/token, if the ticket is not fake then they provide expected services. &lt;br&gt;
Another example is Design Patterns. All design Patterns are also inspired by real-life solutions. &lt;/p&gt;

&lt;p&gt;The idea of implementation has to come from real life. That's why observing life, understanding existing solutions and problems are the most important part of programming.&lt;/p&gt;

&lt;p&gt;The funny thing is - we all know these things. But very few among us truly realize these things and also have the ability of execution. &lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>MongoDB database driver for Deno</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Fri, 22 May 2020 20:04:24 +0000</pubDate>
      <link>https://forem.com/abmsourav/mongodb-database-driver-for-deno-4jb2</link>
      <guid>https://forem.com/abmsourav/mongodb-database-driver-for-deno-4jb2</guid>
      <description>&lt;p&gt;As you already know that Deno is a new run time of JavaScript and TypeScript. Recently it has published first stable release.&lt;/p&gt;

&lt;p&gt;MongoDB is the most popular NoSQL database. Deno also has a third-party module &lt;a href="https://deno.land/x/mongo"&gt;deno_mongo&lt;/a&gt; to handle MongoDB queries.&lt;/p&gt;

&lt;p&gt;deno_mongo is a MongoDB database driver for Deno, based on rust's official MongoDB library package. Right now it's on &lt;code&gt;--unstable&lt;/code&gt; flug. &lt;/p&gt;

&lt;p&gt;I'm assuming that you have installed MongoDB and Deno on your machine. So, let's see how it works...&lt;br&gt;
Necessary permissions to run this module: &lt;code&gt;--allow-net --allow-write --allow-read --allow-plugin --unstable&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MongoClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://deno.land/x/mongo/mod.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;MongoClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;connectWithUri&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mongodb://localhost:27017&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;denoDB&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greetings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greetings&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;on &lt;code&gt;client.connectWithUri&lt;/code&gt; you will put your own URL. In my case, I have a database called &lt;em&gt;denoDB&lt;/em&gt; and a collection called &lt;em&gt;greetings&lt;/em&gt; in that database.&lt;/p&gt;

&lt;p&gt;Now let's insert some data in there:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;greetings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;insertOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you check on the terminal &lt;code&gt;db.greetings.find()&lt;/code&gt; then you'll get that data back, or you can find the data using &lt;em&gt;deno_mongo&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;find&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;greetings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;&lt;br&gt;
Update and Delete: &lt;br&gt;
updateOne returns &lt;code&gt;{ matchedCount, modifiedCount, upsertedId }&lt;/code&gt; these three informations.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// update&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;matchedCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modifiedCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;upsertedId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;greetings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;updateOne&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$ne&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&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="na"&gt;$set&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello Universe...&lt;/span&gt;&lt;span class="dl"&gt;"&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="c1"&gt;// delete&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;greetings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;deleteOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="ltag__link"&gt;
  &lt;a href="/abmsourav" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zZvIjqHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--9MhqgRN_--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/285347/172b72b5-b6e6-4dc6-9a66-308c160d300c.jpg" alt="abmsourav"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/abmsourav/deno-installation-and-vscode-setup-la4" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Deno installation and VScode setup&lt;/h2&gt;
      &lt;h3&gt;Keramot UL Islam ・ May 16 '20 ・ 1 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#deno&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>deno</category>
      <category>mongodb</category>
      <category>javascript</category>
      <category>database</category>
    </item>
    <item>
      <title>Deno installation and VScode setup</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Sat, 16 May 2020 05:01:05 +0000</pubDate>
      <link>https://forem.com/abmsourav/deno-installation-and-vscode-setup-la4</link>
      <guid>https://forem.com/abmsourav/deno-installation-and-vscode-setup-la4</guid>
      <description>&lt;p&gt;Deno is a run time of JavaScript and TypeScript. It's created by the same person who created NodeJS -- Ryan Dahl.&lt;br&gt;
Recently They have published the stable version of Deno 1.0.0&lt;/p&gt;

&lt;p&gt;We also created a Facebook group for Developers:&lt;br&gt;
&lt;a href="//facebook.com/groups/deno.devs.bd"&gt;Deno Developers Bangladesh&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deno Installation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;macOS and Linux:&lt;/strong&gt; &lt;br&gt;
&lt;code&gt;curl -fsSL https://deno.land/x/install/install.sh | sh&lt;/code&gt;&lt;br&gt;
Using Homebrew: &lt;code&gt;brew install deno&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;iwr https://deno.land/x/install/install.ps1 -useb | iex&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now Try to run &lt;code&gt;deno --version&lt;/code&gt; in your terminal, if don't works then you might need to add the path on your OS.&lt;br&gt;
For More Installation options &lt;a href="https://deno.land/manual/getting_started/installation"&gt;Click Here&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual Studio Code Setup
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a project directory, Let's say &lt;code&gt;hello-deno&lt;/code&gt; is the name of the directory/folder.&lt;/li&gt;
&lt;li&gt;Now create a &lt;code&gt;index.ts&lt;/code&gt; file and &lt;code&gt;.vscode&lt;/code&gt; directory, in the root directory.&lt;/li&gt;
&lt;li&gt;Install the &lt;em&gt;Deno&lt;/em&gt; extension for vscode. Which is created by &lt;em&gt;axetroy&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;settings.json&lt;/code&gt; in &lt;code&gt;.vscode&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;add &lt;code&gt;{ "deno.enable": true, }&lt;/code&gt; in &lt;code&gt;settings.json&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;console.log("Hello Universe...")&lt;/code&gt; in the &lt;code&gt;index.ts&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;On your terminal go to the project directory and run &lt;code&gt;deno run index.ts&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: Deno can compile both JavaScript and TypeScript. So, your file extension also can be &lt;code&gt;.js&lt;/code&gt;&lt;/p&gt;

</description>
      <category>deno</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Create Facebook Feed in WordPress with Facebook API</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Thu, 02 Apr 2020 06:26:10 +0000</pubDate>
      <link>https://forem.com/abmsourav/create-facebook-feed-in-wordpress-7j7</link>
      <guid>https://forem.com/abmsourav/create-facebook-feed-in-wordpress-7j7</guid>
      <description>&lt;p&gt;With the help of Facebook rest API, we can create a Facebook feed on our website. Nowadays every business has a Facebook page. A Facebook feed on the website may help to boost business.&lt;br&gt;
In this article, I’ll show how to get data from a Facebook page.&lt;/p&gt;

&lt;p&gt;For fetching data from Facebook you need two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Page ID&lt;/li&gt;
&lt;li&gt;Access Token&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Get these data from &lt;a href="https://developers.facebook.com/docs/pages/"&gt;Here&lt;/a&gt;.&lt;br&gt;
Facebook provides some endpoints to access data. But for authentication, you need those two pieces of information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$page_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'your facebook page id'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'your access token'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://graph.facebook.com/v4.0/'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$page_id&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/posts?'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;amp;access_token='&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$token&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$fb_posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_remote_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_remote_retrieve_body&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$fb_posts&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;print_r&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;json_decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now You are getting data but only basic data. For making a feed you need more depth information right?&lt;br&gt;
You can also add a query in the endpoint.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$url_queries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'fields=status_type,created_time,from,message,story,full_picture,permalink_url,attachments.limit(1){type,media_type,title,description,unshimmed_url},comments.summary(total_count),reactions.summary(total_count)'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$page_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'your facebook page id'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'your access token'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://graph.facebook.com/v4.0/'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$page_id&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/posts?'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$url_queries&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;amp;access_token='&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$token&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$fb_posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_remote_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_remote_retrieve_body&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$fb_posts&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;print_r&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;json_decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now with some HTML and CSS, you can make a pretty visualization of the feed.&lt;/p&gt;

&lt;p&gt;Congratulations, you have created the feed. But if you think deeply, you will find that it’s not good for performance. Because at every page refresh it’ll fetch data from the Facebook database, which is time-consuming.&lt;/p&gt;

&lt;p&gt;So, you need to cash your data for better performance. WordPress has a mechanism called &lt;code&gt;transient&lt;/code&gt;. It is used to cash data for a certain period of time...&lt;br&gt;
&lt;strong&gt;&lt;a href="https://blog.abmsourav.com/facebook-feed-in-wordpress/"&gt;Read More from my original article&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;________________________&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Related Post:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/abmsourav" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zZvIjqHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--9MhqgRN_--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/285347/172b72b5-b6e6-4dc6-9a66-308c160d300c.jpg" alt="abmsourav"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/abmsourav/twitter-feed-on-wordpress-503j" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Twitter Feed on WordPress&lt;/h2&gt;
      &lt;h3&gt;Keramot UL Islam ・ Dec 26 '19 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#wordpress&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#php&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#rest&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#api&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>wordpress</category>
      <category>facebook</category>
      <category>restapi</category>
      <category>webdev</category>
    </item>
    <item>
      <title>WordPress Post Metadata in RestAPI</title>
      <dc:creator>Keramot UL Islam</dc:creator>
      <pubDate>Tue, 03 Mar 2020 10:21:02 +0000</pubDate>
      <link>https://forem.com/abmsourav/wordpress-post-metadata-in-restapi-3he6</link>
      <guid>https://forem.com/abmsourav/wordpress-post-metadata-in-restapi-3he6</guid>
      <description>&lt;p&gt;WordPress has Rest API support since 2016. It’s designed to reach other paradigms. Unfortunately, WordPress doesn’t provide Rest API support for metadata by default. But we can add metadata in Rest API. There are 3 different ways to add metadata in Rest API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Add Rest API support while Registering metadata:&lt;/strong&gt; The simplest way of adding metadata in Rest API is to add support while you’re registering metadata. You can do it by adding &lt;code&gt;show_in_rest&lt;/code&gt; as true in the arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$meta_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; 
    &lt;span class="s1"&gt;'type'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'single'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'show_in_rest'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;register_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'my_meta_keys'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$meta_args&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;2. Add metadata in Rest API response object:&lt;/strong&gt; Most of the time you are going to use this way.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// callback function&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;my_get_post_meta&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// get_post_meta( post_id, meta_key[optional], single[optional] )&lt;/span&gt;
    &lt;span class="nv"&gt;$post_meta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_post_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$meta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$post_meta&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$meta_key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$meta_value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$meta&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$meta_key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$meta_value&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="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$meta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;meta_rest_api&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;register_rest_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'my_meta'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'get_callback'&lt;/span&gt;      &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'my_get_post_meta'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// 'update_callback'=&amp;gt; null,&lt;/span&gt;
        &lt;span class="c1"&gt;// 'schema'         =&amp;gt; null&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'rest_api_init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'meta_rest_api'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, what’s happing here? Well, in the callback function I’m getting all metadata from a post and adding them in an array as key-value pair. Then &lt;code&gt;register_rest_field&lt;/code&gt; is doing the magic. WordPress provides this function to add data in the Rest API response object. It also knows in which route to put data. You also can provide &lt;code&gt;update_callback&lt;/code&gt; and &lt;code&gt;schema&lt;/code&gt; if necessary.&lt;br&gt;
Now you will find all those metadata in &lt;code&gt;https://domain/wp-json/wp/v2/posts/15&lt;/code&gt; under &lt;code&gt;my_meta&lt;/code&gt; property. &lt;br&gt;
Please note that I have provided the post id &lt;code&gt;15&lt;/code&gt;, in your case the post id will be different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Add metadata in a custom route:&lt;/strong&gt; Sometimes you need to add post metadata in a custom route. Sometimes it's may necessary for big projects.&lt;br&gt;
&lt;strong&gt;&lt;a href="https://blog.abmsourav.com/wordpress-meta-in-rest-api/"&gt;Click Here&lt;/a&gt;&lt;/strong&gt; to read the full article.&lt;/p&gt;

&lt;p&gt;Similar Post:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/abmsourav" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zZvIjqHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--9MhqgRN_--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/285347/172b72b5-b6e6-4dc6-9a66-308c160d300c.jpg" alt="abmsourav"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/abmsourav/twitter-feed-on-wordpress-503j" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Twitter Feed on WordPress&lt;/h2&gt;
      &lt;h3&gt;Keramot UL Islam ・ Dec 26 '19 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#wordpress&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#php&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#rest&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#api&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>wordpress</category>
      <category>restapi</category>
      <category>php</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
