<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adnaan Azam on Medium]]></title>
        <description><![CDATA[Stories by Adnaan Azam on Medium]]></description>
        <link>https://medium.com/@adnaan28.azam?source=rss-a69d3da6bf4d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-fiHcXiOzvhNHSElyTS9Qw@2x.jpeg</url>
            <title>Stories by Adnaan Azam on Medium</title>
            <link>https://medium.com/@adnaan28.azam?source=rss-a69d3da6bf4d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:26:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adnaan28.azam/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Custom getElementsByTagName]]></title>
            <link>https://medium.com/@adnaan28.azam/custom-getelementsbytagname-843a8bc51f98?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/843a8bc51f98</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Tue, 19 May 2026 16:56:21 GMT</pubDate>
            <atom:updated>2026-05-19T17:02:16.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oB936dt1IMPtp46cwthRsA.png" /></figure><p>First lets understand what is DOMParser() and what it do ?</p><p>In JS we have something known as <strong><em>new DOMParser()</em></strong> what it does it takes an string and convert this string into a DOM tree</p><p>Signature</p><pre>const doc = new DOMParser().parseFromString(<br>  `&lt;div id=&quot;foo&quot;&gt;<br>    &lt;span&gt;Span&lt;/span&gt;<br>    &lt;p&gt;Paragraph&lt;/p&gt;<br>    &lt;div id=&quot;bar&quot;&gt;Div&lt;/div&gt;<br>  &lt;/div&gt;`,<br>  &#39;text/html&#39;,<br>);</pre><p>If we try to console.log(doc) then it will be like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDeJKhVUrvT_Cahlud5TAg.png" /></figure><p>If we try to access body we can do like doc.body</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2_h8kuNwReT3R6FSJ5fdQ.png" /></figure><p>similar like we have document and document.body</p><h3>What is getElementsByTagName and does it do ?</h3><p>getElementsByTagName is an inbuilt JavaScript function used to retrieve a collection of HTML elements based on their tag name</p><p>eg. If we have this DOM tree</p><pre>&lt;div id=&quot;foo&quot;&gt;<br>  &lt;span&gt;Span&lt;/span&gt;<br>  &lt;p&gt;Paragraph&lt;/p&gt;<br>  &lt;div id=&quot;bar&quot;&gt;Div&lt;/div&gt;<br>&lt;/div&gt;</pre><p>and if we do document.getElementsByTagName(“div”) then it will grab all div inside the DOM tree</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GoHqPuUvBCN1pAmvv4mmwQ.png" /></figure><h3>So, now we have DOM created using DOMParser() but how do we need to iterate inside it?</h3><h4>Approach 1</h4><p>Using querySelectorAll(“*”) it will select every element inside the body</p><pre>const allElements = document.body.querySelectorAll(&#39;*&#39;);<br><br>allElements.forEach(element =&gt; {<br>  console.log(element);<br>});</pre><p>therefore we can do something like this</p><pre>export default function getElementsByTagName(el, tagName) {<br>  <br>  // select all element inside body<br>  const allElements = el.querySelectorAll(&quot;*&quot;);<br><br>  tagName = tagName.toLowerCase()<br><br>  const arr = [] // output array that we need to return<br><br>  allElements.forEach((element) =&gt; {<br>    // element.tagName always be like in Uppercase eg. DIV<br><br>    if(tagName === element.tagName.toLowerCase()) { <br>      arr.push(element)<br>    }<br>  });<br><br>  return arr // return the array<br>}<br><br><br><br>const doc = new DOMParser().parseFromString(<br>  `&lt;div id=&quot;foo&quot;&gt;<br>    &lt;span&gt;Span&lt;/span&gt;<br>    &lt;p&gt;Paragraph&lt;/p&gt;<br>    &lt;div id=&quot;bar&quot;&gt;Div&lt;/div&gt;<br>  &lt;/div&gt;`,<br>  &#39;text/html&#39;,<br>);<br><br>getElementsByTagName(doc.body, &#39;div&#39;); // [div#foo, div#bar]</pre><h4>Approach 2</h4><p>Using recursion we can iterate with the help of .children it will give list of all childrens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gLf0PaYqk5KiBvPsRyrq1w.png" /></figure><pre>export default function getElementsByTagName(el, tagName) {<br>  tagName = tagName.toLowerCase()<br>  const arr = []<br><br>  function helper(child) {<br>    if(child == null) {<br>      return<br>    }<br>    if(child.tagName.toLowerCase() === tagName) {<br>      arr.push(child)<br>    }<br>    for(const child of child.children) {<br>      helper(child)<br>    }<br>  }<br>  for(const child of el.children) {<br>    helper(child)<br>  }<br>  return arr<br>}</pre><p>Thank you for reading till here have an amazing day ahead :)</p><p>Follow me on <br>Linkedin: <a href="https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/">https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=843a8bc51f98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event bubbling]]></title>
            <link>https://medium.com/@adnaan28.azam/event-bubbling-fae880fe9d91?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fae880fe9d91</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Mon, 18 May 2026 17:28:42 GMT</pubDate>
            <atom:updated>2026-05-18T17:49:32.845Z</atom:updated>
            <content:encoded><![CDATA[<p>Event bubbling is a propagation mechanism in the DOM (Document Object Model). When an event, such as a click or keyboard event, is triggered on a target element, it then propagates upward through the DOM tree to the root of the document.</p><p>Don’t worry, I’ll explain everything step by step, including what the DOM tree is and how it gets generated.</p><p>So what happens? The server sends HTML in the form of packets, and once it reaches your browser, the browser progressively creates a DOM tree. The DOM tree, shown on the right, is a tree representation of HTML elements for the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ixwI23rqkwdhhQ450NBovA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LW3i5IfT2OT1sRCmgcoQUA.png" /></figure><p>Let’s get back to event bubbling. During the bubbling phase, the event starts at the target element and bubbles up through its ancestors in the DOM tree. This means event listeners attached to ancestor elements can also receive that event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CCRsLrKsuhFnvYsXs7jubA.png" /></figure><pre>// HTML:<br>// &lt;section id=&quot;wrapper&quot;&gt;<br>//   &lt;button id=&quot;actionBtn&quot;&gt;Press Here&lt;/button&gt;<br>// &lt;/section&gt;<br><br>const wrapperSection = document.createElement(&#39;section&#39;);<br>wrapperSection.id = &#39;wrapper&#39;;<br><br>const actionBtn = document.createElement(&#39;button&#39;);<br>actionBtn.id = &#39;actionBtn&#39;;<br>actionBtn.textContent = &#39;Press Here&#39;;<br><br>wrapperSection.appendChild(actionBtn);<br>document.body.appendChild(wrapperSection);<br><br>const wrapper = document.getElementById(&#39;wrapper&#39;);<br>const triggerButton = document.getElementById(&#39;actionBtn&#39;);<br><br>wrapper.addEventListener(&#39;click&#39;, () =&gt; {<br>  console.log(&#39;Wrapper section was clicked&#39;);<br>});<br><br>triggerButton.addEventListener(&#39;click&#39;, () =&gt; {<br>  console.log(&#39;Button was clicked&#39;);<br>});<br><br>// Trigger button click programmatically<br>triggerButton.click();<br><br><br><br>Console<br>Button was clicked<br>Wrapper section was clicked</pre><p>Wait! What if I want to stop event bubbling? For that, we can use stopPropagation. It stops the event from bubbling, so the event does not propagate to its ancestor elements.</p><pre>// HTML:<br>// &lt;section id=&quot;wrapper&quot;&gt;<br>//   &lt;button id=&quot;actionBtn&quot;&gt;Press Here&lt;/button&gt;<br>// &lt;/section&gt;<br><br>const wrapperSection = document.createElement(&#39;section&#39;);<br>wrapperSection.id = &#39;wrapper&#39;;<br><br>const actionBtn = document.createElement(&#39;button&#39;);<br>actionBtn.id = &#39;actionBtn&#39;;<br>actionBtn.textContent = &#39;Press Here&#39;;<br><br>wrapperSection.appendChild(actionBtn);<br>document.body.appendChild(wrapperSection);<br><br>const wrapper = document.getElementById(&#39;wrapper&#39;);<br>const triggerButton = document.getElementById(&#39;actionBtn&#39;);<br><br>wrapper.addEventListener(&#39;click&#39;, () =&gt; {<br>  console.log(&#39;Wrapper section was clicked&#39;);<br>});<br><br>triggerButton.addEventListener(&#39;click&#39;, (e) =&gt; {<br>  console.log(&#39;Button was clicked&#39;);<br>  e.stopPropagation()<br>});<br><br>// Trigger button click programmatically<br>triggerButton.click();<br><br><br><br>Console<br>Button was clicked</pre><p>There is one more concept that is based on event bubbling: event delegation.</p><p>In event delegation, we attach a single event listener to a common ancestor of multiple elements to handle events for those elements efficiently.</p><p>Example</p><p>Below, you can see that we need to attach an event listener to each element.</p><pre>// &lt;ul id=&quot;products&quot;&gt;<br>//   &lt;li&gt;&lt;button id=&quot;item1&quot;&gt;Button 1&lt;/button&gt;&lt;/li&gt;<br>//   &lt;li&gt;&lt;button id=&quot;item2&quot;&gt;Button 2&lt;/button&gt;&lt;/li&gt;<br>// &lt;/ul&gt;<br><br>const item1BuyButton = document.getElementById(&quot;item1&quot;)<br>const item2BuyButton = document.getElementById(&quot;item2&quot;)<br><br>item1BuyButton.addEventListener(&quot;click&quot;, handleClick)<br>item2BuyButton.addEventListener(&quot;click&quot;, handleClick)<br><br>function handleClick(event) {<br>  console.log(&quot;Button clicked for&quot;, event.target.id)<br>}</pre><p>But with event delegation, we can add a single event listener to the parent.</p><pre>// &lt;ul id=&quot;products&quot;&gt;<br>//   &lt;li&gt;&lt;button id=&quot;item1&quot;&gt;Button 1&lt;/button&gt;&lt;/li&gt;<br>//   &lt;li&gt;&lt;button id=&quot;item2&quot;&gt;Button 2&lt;/button&gt;&lt;/li&gt;<br>// &lt;/ul&gt;<br><br>const parent = document.getElementById(&quot;products&quot;)<br><br>parent.addEventListener(&quot;click&quot;, handleClick)<br><br>function handleClick(event) {<br>  if(event.target.tagName.toLowerCase() === &quot;button&quot;) {<br>    console.log(&quot;Buy button clicked for&quot;, event.target.id) // item2 if we<br>    // click on button2<br>  }<br>}<br></pre><p>Thank you for reading<br>Follow me on X <a href="https://x.com/adnaanazam">https://x.com/adnaanazam</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fae880fe9d91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Client Server Architecture]]></title>
            <link>https://blog.stackademic.com/client-server-architecture-ad37df68aac1?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad37df68aac1</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Tue, 21 Oct 2025 18:11:42 GMT</pubDate>
            <atom:updated>2025-10-30T01:56:09.701Z</atom:updated>
            <content:encoded><![CDATA[<p>It is important to understand client server architecture for any IT role.</p><p>Every major applications like amazon, facebook, instagram etc all functions based on client server architecture.</p><figure><img alt="client server" src="https://cdn-images-1.medium.com/max/1024/1*LwIHMHwnws4lq6dMVBBlfg.png" /></figure><p>So what happens is client send data to server to process or request data from server and server return data to client.</p><p>In real life when you type amazon.com in your <strong>browser (client) </strong>and we have amazon <strong>(server)</strong> it will request some information from server and after getting response from server it will do necessary things</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*saDaM4IPcs4z_h1LRrrbWg.png" /></figure><h3>How browser get IP address of amazon server ?</h3><p>So when we write any domain in our browser then behind the scene it make a DNS query to get IP address of amazon.com server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PiLdXRenxJ4IHhrgJze4mg.png" /></figure><h4>IP address</h4><p>Is is nothing but a unique identifier of machine eg. Just like our house has an address to identify its location, a machine on a <strong><em>network</em></strong> has an IP address that uniquely identifies it</p><p>All the machines which are connected to internet can discover these <strong><em>public ip addresses</em></strong> and with the help of these we can send data packets in terms of bytes to these IP addresses</p><p>These IP address generally allocated by our cloud service provider eg. <strong><em>AWS or GCP</em></strong> to our machine</p><p>To check the public IP address of any domain we can just write in terminal <strong><em>nslookup google.com</em></strong> this will return you public IP address of that <strong><em>server</em></strong><br>eg. google public IP is <strong><em>172.217.174.238</em></strong> hit this will your browser this will open google.com</p><h3>How data is being transferred from client to server</h3><p>Client sent an HTTP request to the server (which means our browser will sent bytes of characters in form of packets) packet has two parts <strong><em>Header</em></strong> and <strong><em>Payload</em></strong> in payload we have our data in form of bytes and in header we have IP address of <strong><em>source</em></strong> and <strong><em>destination</em></strong>, destination IP address is required because server will need to know which IP address it should sent response to</p><p>Let’s say if we want to send character “A” over the network then first we need to convert into bytes below is the python code to convert character into bytes</p><pre>char = &quot;A&quot;<br>byte_char = char.encode(&quot;utf-8&quot;)<br>print(byte_data) # b&#39;A&#39;</pre><p>The process of converting our data into bytes is know as <strong><em>encoding, s</em></strong>o our packet will look like this</p><pre>[Header: src=192.168.1.2, dst=142.250.183.206, port=443]<br>[Payload: b&#39;A&#39;]</pre><h3>Ports</h3><p>The server listens for client requests on specific ports. Each port is represented using 2 bytes, so the total number of possible ports is 65,535</p><p>So when you want to communicate with server you need to specify the port number, if client uses HTTP protocol to communicate with server then default port will be 80 and 8443 for HTTPS</p><p>I would like to thank Himalay Majumdar, founder of <a href="https://academy.bytemonk.io/">ByteMonk</a>, for creating an exceptional system design course . The code examples and images used in this demonstration are inspired by concepts from his course.</p><p>Thank you</p><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad37df68aac1" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/client-server-architecture-ad37df68aac1">Client Server Architecture</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Simple CSS-in-JS Library: A Practical Approach]]></title>
            <link>https://blog.stackademic.com/building-a-simple-css-in-js-library-a-practical-approach-e86589a3cf5b?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e86589a3cf5b</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Sun, 25 May 2025 13:49:44 GMT</pubDate>
            <atom:updated>2025-05-27T10:23:26.124Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I want to share a small but powerful CSS-in-JS utility I built that makes DOM manipulation more intuitive. If you’ve worked with jQuery, you’ll find this approach familiar, but with a modern twist.</p><p>Here’s the core functionality:</p><pre>// Select an element and change its color<br>$(&#39;#myElement&#39;).css(&#39;color&#39;, &#39;blue&#39;);<br>// Chain multiple style changes<br>$(&#39;#myElement&#39;)<br> .css(&#39;color&#39;, &#39;blue&#39;)<br> .css(&#39;fontSize&#39;, &#39;20px&#39;)<br> .css(&#39;backgroundColor&#39;, &#39;black&#39;);<br>// Get the current style value<br>const color = $(&#39;#myElement&#39;).css(&#39;color&#39;);</pre><p>The implementation is surprisingly compact:</p><pre>export default function $(selector) {<br>  const element = document.querySelector(selector);<br><br>  function helper(key, value) {<br>    // if value is not there that means we need to fetch the style[key] where key can be dynamic<br>    if (!value) {<br>      // check if the selector is there or not + if style is applied or not if no style is applied then this will return undefined<br>      if (element &amp;&amp; element.style) {<br>        // style = { color: &quot;red&quot; } but if we try to access fontSize then this will return &quot;&quot;<br>        return element.style[key] || undefined;<br>      } else {<br>        return undefined;<br>      }<br>    }<br><br>    // just random selector if it is not there in DOM therefor we can also apply the styling<br>    if (!element) {<br>      return { css: helper };<br>    }<br><br>    element.style[key] = value;<br><br>    return {<br>      css: helper,<br>    };<br>  }<br><br>  return {<br>    css: helper,<br>  };<br>}</pre><p>What I like about this approach:<br>- It’s clean and intuitive<br>- Method chaining makes multiple style changes concise<br>- It handles both getting and setting styles<br>- Gracefully handles non-existent elements</p><p>This utility is ideal for small projects that require DOM manipulation without the overhead of larger libraries. It’s also a great learning exercise for understanding closures and method chaining in JavaScript.</p><p>What do you think? Have you built similar utilities for your projects?</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e86589a3cf5b" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/building-a-simple-css-in-js-library-a-practical-approach-e86589a3cf5b">Building a Simple CSS-in-JS Library: A Practical Approach</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Storybook into React Native]]></title>
            <link>https://blog.stackademic.com/react-native-storybook-9e44969b9ee1?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e44969b9ee1</guid>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Tue, 21 Nov 2023 10:34:43 GMT</pubDate>
            <atom:updated>2023-11-23T00:50:26.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FNubArsyUb7vT-Rnku6iRw.png" /></figure><p>Storybook is an exceptional tool that empowers us to visualize and manage components with remarkable ease in this article we’ll discuss how can we integrate Storybook into our React Native project.</p><p>Let’s create a new React Native project with the name <strong>rntemplate </strong>by using this command</p><pre>npx react-native@latest init rntemplate</pre><p>Also, let’s run the project on the iOs simulator, I&#39;ve cleaned up the App.tsx code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peZPEeyMH9LUD10pnrHTZw.png" /></figure><p>Let’s install the packages required for the storybook using this command</p><pre>npm i -D @storybook/react-native @storybook/core-common@6.5.16 @react-native-async-storage/async-storage react-native-safe-area-context react-dom</pre><pre>npm i -D @storybook/addon-ondevice-controls @storybook/addon-ondevice-actions</pre><p>after this install the pods for iOs, by running the following command</p><pre>cd ios; pod install; cd ..</pre><p><strong>Storybook configuration</strong></p><p>We need to create certain files/folders for the storybook let’s create using the below command</p><pre>mkdir .storybook &amp;&amp; cd .storybook &amp;&amp; touch main.js preview.js Storybook.tsx</pre><p>It will create a <strong>.storybook </strong>folder like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ld-mEnVeT0hKPjIVjJlXyw.png" /></figure><p>Paste the below code in</p><p><strong>.storybook/main.js</strong></p><pre>module.exports = {<br>  stories: [<br>    &#39;../src/Components/**/*.stories.?(ts|tsx|js|jsx)&#39;<br>  ],<br>  addons: [&#39;@storybook/addon-ondevice-controls&#39;, &#39;@storybook/addon-ondevice-actions&#39;],<br>};</pre><p><strong>.storybook/preview.js</strong></p><pre>export const decorators = [];<br>export const parameters = {};</pre><p><strong>.storybook/Storybook.tsx</strong></p><pre>import { getStorybookUI } from &#39;@storybook/react-native&#39;;<br><br>import &#39;./storybook.requires&#39;;<br><br>const StorybookUIRoot = getStorybookUI({});<br><br>export default StorybookUIRoot;</pre><p><strong>metro.config.js</strong></p><pre>const {getDefaultConfig, mergeConfig} = require(&#39;@react-native/metro-config&#39;);<br><br>/**<br> * Metro configuration<br> * https://facebook.github.io/metro/docs/configuration<br> *<br> * @type {import(&#39;metro-config&#39;).MetroConfig}<br> */<br>const config = {<br>  resolver: {<br>    resolverMainFields: [&#39;sbmodern&#39;, &#39;react-native&#39;, &#39;browser&#39;, &#39;main&#39;],<br>  },<br>};<br><br>module.exports = mergeConfig(getDefaultConfig(__dirname), config);</pre><p>Also, we need to update our <strong>package.json</strong> file and add the following scripts</p><pre>&quot;prestart&quot;: &quot;sb-rn-get-stories&quot;,<br>&quot;storybook-watcher&quot;: &quot;sb-rn-watcher&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*54f0B6jwEBII8OEoFp4cOQ.png" /></figure><p>Let’s create an src(root) folder in our directory and move the <strong>App.tsx </strong>file inside it <strong>don’t forget to update the path of App.tsx inside the index.js file otherwise it will throw an error.</strong></p><p>Also, let’s create a Components folder inside src and under the Components folder Let’s create a folder named Button which will contain three files</p><pre>Button.stories.tsx<br>Button.styles.ts<br>Button.tsx<br>index.ts</pre><p>Let’s discuss each file and write the code inside it</p><p><strong>Button.tsx</strong></p><p>This file contains our two variants of Button, Primary Button, and Outline Button</p><pre>import React from &#39;react&#39;;<br>import {Button, Pressable, Text} from &#39;react-native&#39;;<br>import {styles} from &#39;./Button.styles&#39;;<br><br>export const PrimaryButton = (props: {title: string}) =&gt; {<br>  const {title} = props;<br>  return &lt;Button title={title} /&gt;;<br>};<br><br>export const OutlineButton = (props: {title: string}) =&gt; {<br>  const {title} = props;<br><br>  return (<br>    &lt;Pressable style={styles.Oultline}&gt;<br>      &lt;Text style={styles.Outline__Text}&gt;{title}&lt;/Text&gt;<br>    &lt;/Pressable&gt;<br>  );<br>};</pre><p><strong>Button.stories.tsx</strong></p><p>Over here we write our stories of buttons as in this code we have two buttons <br>1. Primary Button<br>2. Outline Button</p><p>and grabbing from the <strong>./Button</strong> file and we are exporting each button with const exports with a title <strong>Primary button / Outline button props</strong></p><pre>import React from &#39;react&#39;;<br>import {PrimaryButton as PB, OutlineButton as OB} from &#39;./Button&#39;;<br><br>export default {<br>  title: &#39;components/Button&#39;,<br>};<br><br>export const PrimaryButton = (args: {title: string}) =&gt; &lt;PB {...args} /&gt;;<br><br>PrimaryButton.args = {<br>  title: &#39;Primary button&#39;,<br>};<br><br>export const OutlineButton = (args: {title: string}) =&gt; &lt;OB {...args} /&gt;;<br><br>OutlineButton.args = {<br>  title: &#39;Outline button&#39;,<br>};</pre><p><strong>Button.styles.ts</strong></p><p>This file contains all the styling of buttons.</p><pre>import {StyleSheet} from &#39;react-native&#39;;<br><br>export const styles = StyleSheet.create({<br>  Oultline: {<br>    borderWidth: 1,<br>    borderBlockColor: &#39;#d3d3d3&#39;,<br>    borderRadius: 4,<br>    paddingVertical: 10,<br>    justifyContent: &#39;center&#39;,<br>    alignItems: &#39;center&#39;,<br>  },<br>  Outline__Text: {<br>    color: &#39;#000&#39;,<br>  },<br>});</pre><p><strong>index.ts</strong></p><p>This file will just export all the buttons that we’ve declared in the <strong>Button.tsx</strong> file</p><pre>export * from &#39;./Button&#39;;</pre><p>We’ve completed our button stories and the final step is to update the App.tsx file like this.</p><pre>// import React from &#39;react&#39;;<br>// import {View, Text, StyleSheet} from &#39;react-native&#39;;<br><br>// export default App = () =&gt; {<br>//   return (<br>//     &lt;View style={styles.container}&gt;<br>//       &lt;Text&gt;Visit finoyou at wwww.finoyou.in&lt;/Text&gt;<br>//     &lt;/View&gt;<br>//   );<br>// };<br><br>// const styles = StyleSheet.create({<br>//   container: {<br>//     flex: 1,<br>//     justifyContent: &#39;center&#39;,<br>//     alignItems: &#39;center&#39;,<br>//   },<br>// });<br><br>export {default} from &#39;../.storybook/Storybook&#39;;</pre><p>We need to comment out our App code to run the storybook, therefore I&#39;ve added this line which is at the <strong>bottom of the above code.</strong></p><p>Let’s generate our stories by running the script that we’ve added inside the package.json file</p><pre>npm run prestart</pre><p>Let’s <strong>re-build</strong> our project and run, you will see our storybook will be running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvmNo1VMCCSMWGLJx9NVlA.png" /></figure><p>Yeah, we’ve successfully integrated the storybook into our React Native project.</p><p>All code will be accessible from <a href="https://github.com/mohdadnaanazam/rn-template">here</a></p><p>Follow me on</p><p>LinkedIn: <a href="https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/">https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/</a><br>Twitter: <a href="https://twitter.com/adnaanazam">https://twitter.com/adnaanazam</a></p><p>If you guys having difficulty in managing your finances I&#39;ve made Finoyou a finance management app using React Native give it a try</p><p>Website: <a href="https://www.finoyou.in/">https://www.finoyou.in</a><br>App: <a href="https://play.google.com/store/apps/details?id=com.finoyou">https://play.google.com/store/apps/details?id=com.finoyou</a></p><p>Thanks :)</p><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e44969b9ee1" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/react-native-storybook-9e44969b9ee1">Integrate Storybook into React Native</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Deep Dive into Memoization of JS Functions]]></title>
            <link>https://medium.com/@adnaan28.azam/a-deep-dive-into-memoization-for-functions-js-a12c395424ff?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a12c395424ff</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Sat, 18 Nov 2023 09:47:12 GMT</pubDate>
            <atom:updated>2023-11-20T07:19:32.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAuQvHKdkQDhNKyluc8deA.png" /></figure><p>First of all, let’s understand what is memoization<br>Memoization is a technique used to optimize functions by caching their results based on the input parameters.</p><p>As you can see in the below example <strong>square function expression </strong>is invoked two times because in the log it will print two times <strong>calculating the square</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bUp-inGzzD_CGPyfVzg5zg.png" /></figure><p>We need to memorize this function so that it won’t execute another time if it was called once with the <strong>same argument, </strong>to do this let’s create a memo function and pass the <strong>anonymous function as an argument </strong>like this</p><pre><br>const memo = (cb) =&gt; {<br>  return function (x) {<br>    console.log(x) // 2<br>  }<br>}<br><br>const square = memo(function(x) {<br>  console.log(&#39;Calculating square&#39;)<br>  return x * x<br>})<br><br>square(2) </pre><p>This will log 2 in the console as a memo function return this anonymous function and store it in the square function and we pass 2 in the square function as an argument</p><pre>function (x) {<br>  console.log(x) // 2<br>}</pre><p>Let’s create a cache object inside the memo function and in the if condition we are checking that <strong>if x is present inside the cache object</strong></p><p>If yes, then return the cache value using cache[x] given this will not invoke the <strong>cb [ callback function ]</strong> it just returns the value from the cache object</p><p>If no, then execute the <strong>cb(x) </strong>which will return the square value of x i.e x *x, store it inside the cache, and then return it</p><pre>const memo = (cb) =&gt; {<br>  const cache = {}<br>  <br>  return function (x) {<br>    if(x in cache) {<br>      return cache[x]<br>    } else {<br>      cache[x] = cb(x)<br>      <br>      return cache[x]<br>    }<br>    console.log(x)<br>  }<br>}</pre><p>So the final code will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5GQ9qqH5mOAJ6lhmoT4aQ.png" /></figure><p>If we run this code then we can see the calculating square will log only one time</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZJw7papETFExAZjOFPxQA.png" /></figure><p>Follow me on<br>LinkedIn: <a href="https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/">https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/</a></p><p>Download Finoyou a finance management app</p><p>Website: <a href="https://www.finoyou.in/">https://www.finoyou.in</a><br>App: <a href="https://play.google.com/store/apps/details?id=com.finoyou">https://play.google.com/store/apps/details?id=com.finoyou</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a12c395424ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform basics]]></title>
            <link>https://awstip.com/terraform-basics-484011525258?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/484011525258</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 08:19:26 GMT</pubDate>
            <atom:updated>2023-11-17T14:15:20.405Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUUpdmR-xGyJVIBCUu57Fg.png" /></figure><p>In earlier days everything we were doing manually like if we needed <strong>2 EC2</strong> <strong>instances</strong>, <strong>1RDS</strong>, and <strong>3 S3</strong> buckets we created those manually and this is called <strong>infrastructure provisioning.</strong></p><p><strong>Drawbacks<br></strong>1.<strong> </strong>The<strong> </strong>main issue in this is that if we need to update EC2 instances then we need to do SSH on each instance and run update, so it’s not possible to do so if we have many instances.</p><p>2. If we need the same configuration for another project then every time we need to go to the AWS panel and create those EC2, RDS, S3 etc again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z_BCyr6rs49Aj8N7EMchDg.png" /></figure><p>Earlier we were not able to maintain the state of our infrastructure like if we needed 2EC2, 1RDS, and 3 S3 and also we are not able to remember the configuration of these, so <strong>Terraform</strong> helps us to do these things.</p><p>Let’s understand what is <strong>IaC (Infrastructure as a code)</strong></p><p>IaC are of two types</p><ol><li><strong>Infrastructure provisioning</strong></li></ol><p>We use Terraform to create our infrastructure via Code and we use a tool called <strong>Terraform or Cloud Formation</strong></p><p>2. <strong>Configuration Management</strong></p><p>If we created our EC2 instance, S3, etc then how we are going to update those for this we use one of the famous tools known as <strong>Ansible</strong></p><p>Let’s understand what is <strong>Hardening the infrastructure</strong></p><p>1.<strong> </strong>If we need 2 EC2 instances, 3 S3, etc then we’ll write these in code, and tomorrow it won’t get changed it will be as it is also because there is no chance that we can create more/ less.</p><p>2. If in the future configuration changes then we can easily change in our code.</p><p>Let’s recap</p><p>Earlier we created our infrastructure manually now we will create those via automation through Terraform and Terraform will maintain the state of the same which means if in the future we need to update the configuration of our infrastructure then we have the current state of the same eg. We have 5 EC2 instances, and 4 S3 buckets and what is the configuration? We’ve 5 EC2 of t2.micro and 2GB of RAM and in which AZ’s the EC2 is in.</p><p>Let’s install Terraform locally, you can refer to the download installation instructions <a href="https://developer.hashicorp.com/terraform/install?product_intent=terraform">here</a>, after you install Terraform successfully then in local run the below command it will show the Terraform version installed locally.</p><pre>terraform -v</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsB_flYi3O5uPJOPeE1WKg.png" /></figure><p><strong>Let’s start writing our terraform code</strong></p><p>Let’s create a folder named as Terraform and inside the same let’s have 01 folder and create a main.tf file</p><h4>Terraform &gt; 01 &gt; main.tf</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*23zsA2Myg3zajkrOknlUOw.png" /></figure><p>In Terraform we write code something like this</p><pre>&lt;block&gt; &lt;argument&gt; {<br><br>}</pre><p>The possible values of blocks are</p><ol><li>variable</li><li>output</li><li>resource</li><li>provider</li><li>backend</li><li>module</li></ol><p>Let’s say we need to integrate AWS / AZURE as a provider then we’ll write code something like this.</p><pre>provider aws {<br>  ... // aws configuration<br>}</pre><pre>provider azure {<br>  ... // azure configuration<br>}</pre><p>where the provider is our <strong>provider</strong> <strong>block, </strong>AZURE / AWS <strong>provider</strong></p><p><strong>Let’s create a .txt file via Terraform</strong></p><p>We’ll write the below code in <strong>main.tf</strong></p><pre>resource &quot;local_file&quot; &quot;hello_world&quot; {<br>    content = &quot;Hello, World!&quot;<br>    filename = &quot;hello-world.txt&quot;<br>}</pre><p>Explanation</p><ol><li><strong>resource</strong>: this is a <strong>resource block </strong>that is used to define and provision infrastructure objects.</li><li><strong>local_file</strong>: is a built-in Terraform <strong>provider</strong> that allows you to create a local file.</li><li><strong>hello_world</strong>: is a name given to this specific instance of the local_file resource.</li><li><strong>content</strong>: this attribute specifies the content of the file.</li><li><strong>filename</strong>: this attribute specifies the name of the file that will be created.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAWYC1qFb1iPeu03pjx6ig.png" /></figure><p>Step 1.<br>Run the below command, this will create the terraform lock file</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-jZvYpPuaKgntl59HYKQg.png" /></figure><p>2. Step 2<br>Run the below command, and when it asks to Enter a value then provide <strong>yes</strong>, this will create the file with the name<strong> hello-world.txt </strong>which we mentioned inside the main.tf file</p><pre>terraform apply</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Fojcq8vYiK_vUEHwDFC_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-wapnU17pEnL_jh5BDSBw.png" /></figure><p>As you can see a file with the name <strong>hello-world.txt </strong>is created with the content <strong>Hello, world!</strong> inside it.</p><p>In the next article, we’ll learn about how to provision AWS EC2 instances, S3, etc, I&#39;ll add the article link here.</p><p>Follow me on<br><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/">https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=484011525258" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/terraform-basics-484011525258">Terraform basics</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Docker Container on AWS ECS (Elastic Container Service)]]></title>
            <link>https://awstip.com/deploy-docker-container-on-aws-ecs-elastic-container-service-8bf3740b8c1e?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bf3740b8c1e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-architect]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Mon, 13 Nov 2023 13:46:58 GMT</pubDate>
            <atom:updated>2024-11-09T12:37:11.527Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StI1WkIaK4sitt20KVbMtQ.png" /></figure><p>The prerequisite for deploying the docker container on AWS ECS is that</p><ol><li>You need an AWS account, if you don’t have you create an AWS account for free from <a href="https://portal.aws.amazon.com/billing/signup?type=enterprise#/start/email">here</a></li><li>Basic understanding of Docker i.e how to create an image, use the image to create a container</li></ol><p>Let’s clone the basic node js from <a href="https://github.com/mohdadnaanazam/docker-finoyou-ecs.git">here</a>, which has two routes <strong>/</strong> and <strong>/healthy </strong>we’ll discuss about healthy route later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k7pgukYhdnwlAh-aAiqWSg.png" /></figure><p>To run the project follow the following commands</p><ol><li>npm i or npm install, to install all the dependencies required to run the project</li><li>npm run build, as we are using TS(Typescript) in this project our TS code will be converted into JS and be available inside <strong>out</strong> folder</li><li>npm start, to finally run the project</li></ol><p>After following the steps you will have this in your terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hOaTuA47xZ6E7A4VzgrJzQ.png" /></figure><p>To verify that everything is working fine we need to hit route <a href="http://localhost:3000/">http://localhost:3000</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*doWyy3_3GjKZYUr-ds-0IA.png" /></figure><p>Let’s run the project using Docker, we need to install Docker on our machine you can follow the installation according to your OS from <a href="https://docs.docker.com/get-docker/">here</a></p><p>In the same project, we have this code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JgsudpE0dpwPCg8SRYRTFw.png" /></figure><p>This is just a simple docker file where we are</p><ol><li><strong>FROM node:18</strong> fetching the node 18 image</li><li><strong>WORKDIR app </strong>Using this command we are making a working directory inside the container</li><li><strong>COPY . . </strong>This command helps us to copy all the files/folders inside the container <strong>/app</strong> folder</li><li><strong>RUN npm install </strong>to<strong> </strong>install the dependencies</li><li><strong>EXPOSE 3000 </strong>exposing the port on which the app runs</li><li><strong>CMD [“npm”, “start”] </strong>command to run the application</li></ol><p>To run the project using docker let’s first create a docker image using</p><pre>docker build . -t finoyou-nodejs</pre><p>This will create a docker <strong>image</strong> to create a <strong>container</strong> using this image let’s run</p><pre>docker run -dp 3000:3000 finoyou-nodejs</pre><p>Yeah our container is running let’s hit <a href="http://localhost:3000/"><em>http://localhost:3000</em></a><em> </em>to verify</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxp9A29UixYIWBWWiCIypw.png" /></figure><p>Let’s create an <strong>ECR (Amazon Elastic Container Registry) </strong>on AWS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JV1NWr6oRKBZDZf7OSpmfw.png" /><figcaption>It is a private registry where you can store, manage, and deploy Docker container images.</figcaption></figure><p>Let’s create a repository by clicking the <strong>Create Repository </strong>button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g66_PIWxK4m5Rpb7guKeVA.png" /></figure><p>I named my repository <strong>finoyou-server</strong> you can write whatever you want and hit the <strong>Create repository</strong> button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9imvaOXOw4rINePO8yypkg.png" /></figure><p>Then select the repository you just created click on the <strong>View push commands </strong>and follow the instructions, which will push the docker image into this repository, this will take a little bit of time approximately 2~3 minutes depending upon internet speed.</p><p>After your image is successfully pushed you can see your image inside the repository</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnMq9KWSx0qEEnX1B0u4JQ.png" /></figure><p>Let’s now create an ECS (Elastic Container Service) Cluster</p><p>Before creating a Cluster let’s understand what is <strong>Cluster</strong></p><p>In a cluster, we have different types of services running like authentication, streaming, and socket, in our case, we are creating a service called <strong>API</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ddWWviNemteETkDrdfmnw.png" /></figure><p>Cluster creation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iS1Qy0n5WnmD2KMUGJqS-Q.png" /></figure><p>Enter your cluster name as you can see I wrote <strong>dev-finoyou-cluster </strong>as my cluster name and hit create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iWncO8XcFrRKUcxUOWS5Aw.png" /></figure><p>When your cluster is created successfully it will appear here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McV8oL5govPjlhypeuXhZA.png" /></figure><p>After that, let’s create a task, you will find it inside the sidebar named <strong>Task Definitions, </strong>I&#39;ll explain later why we are creating a task</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BxMZIcc-gisyoVPcHAplA.png" /></figure><p>Let’s create our first task</p><ol><li>Write a task definition family, and Choose infrastructure requirements according to your needs</li></ol><p><strong>NOTE: Choose Linux/arm64 in Operating system/Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6VjoE6psUnPp8yKgTzFHyA.png" /></figure><p>2. Adding container image URI</p><p>Copy the URI for Amazon ECR</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eu30Mt0vHuiUveJmHrdAXQ.png" /></figure><p>Paste this URL into Amazon ECS, under container 1.</p><p>Note: I used container port <strong>3000 </strong>because I wanted to expose the 3000 port of the container</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ttt45H1ecbNDHZ_PnVTnSA.png" /></figure><p>3. Configuring Health Check</p><p>I used this command</p><pre>CMD-SHELL, curl -f http://localhost:3000/healthy || exit 1</pre><p>This will continuously hit the route (http://localhost:3000/healthy) at an interval of 30 seconds and check whether our container is working fine or not.<br>If something goes wrong then execute <strong>exit 1 </strong>this will kill the task</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNoKQYnELEqe0qdpem5J6w.png" /></figure><p>Hit the create button and this will create our first task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NslbEcDLCOxCrRvi48yFEA.png" /></figure><p>Let’s create our <strong>Service</strong> inside the <strong>Cluster</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjsX6MZgCUjqq3-bB1U5wg.png" /></figure><p>After you press the <strong>Create</strong> button then navigate inside the service then there is a section known as <strong>Deployment Configuration, </strong>and choose your previously created task from the dropdown, also in the desired task let’s increase the task to 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ENVFMfakqfJVS1gh8HCDg.png" /></figure><p>Configure ALB which is known as the <strong>Application Load Balancer, and </strong>write your <strong>Load balancer name</strong> and <strong>Target group name</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NPBqAM-OnHLLy0cVN81-6A.png" /></figure><p>At last, let’s configure <strong>Service auto-scaling, </strong>in a minimum number of the task I&#39;ve put 2 this means that it will run a minimum of 2 tasks and a maximum of 10 tasks, and below this, we wrote our policy named <strong>finoyou-dev-scaling </strong>which will continuously monitor our CPU utilization if CPU utilization is more than 80% then it will make a new task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbMBotg1VS06nUHdp_08oQ.png" /></figure><p>After that let’s create our first service, this will be visible inside our cluster like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_GX0QujaCHN4Yl7w_q86VQ.png" /></figure><p>Let’s open <strong>finoyou-dev-service </strong>where we’ll see our 2 task are runing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1I6sxCtHfp9dJ20HVU9sw.png" /></figure><p>Let’s summarise what we have done so far</p><ol><li>We created a service inside a cluster which is our <strong>api service</strong> and connected this service to our task which will run this task inside this cluster.</li><li>This service is also responsibe to do scale up and scale down and if something bad happens then it will restart our task.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MuHSvyEjfdh_AE_Z7iBKvw.png" /></figure><p>To verify our api is running or not let’s open a load balancer then navigate Details tab and copy the DNS record and open in the tab</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOqCQLgMkR1kdLCLRHT1Dg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAWek7PnL-I6XRqjodbpXA.png" /></figure><p>Yeah, we’ve successfully deployed our docker container inside ECS.</p><p>Follow me on <br><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/">https://www.linkedin.com/in/mohd-adnaan-azam-b38151174/</a></p><p>Download finoyou a finance management application <br><strong>Playstore</strong>: <a href="https://play.google.com/store/apps/details?id=com.finoyou">https://play.google.com/store/apps/details?id=com.finoyou</a><br><strong>Website</strong>: <a href="https://www.finoyou.in/">https://www.finoyou.in</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bf3740b8c1e" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/deploy-docker-container-on-aws-ecs-elastic-container-service-8bf3740b8c1e">Deploy Docker Container on AWS ECS (Elastic Container Service)</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless]]></title>
            <link>https://awstip.com/serverless-76106803580b?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/76106803580b</guid>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Sat, 11 Nov 2023 09:24:31 GMT</pubDate>
            <atom:updated>2023-11-17T14:15:08.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0YusZ7hsYY_ld2Zv3qbogg.png" /></figure><p>First, we need to understand what is serverless and non-serveless which we also call monolith.</p><p>Let’s understand <strong>Monolith</strong> first then we’ll deep dive into Serverless.</p><p>In a monolith, we create a virtual machine on AWS, Azure, or GCP where we buy a machine on rent in AWS we call it an EC2 instance and we have a variety of options to choose machines depending upon our needs, as you can see in below picture we have the option to choose machine depending upon our needs and we AWS will charge on an hourly basis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4DtwoRtarnpM7O_J3GuMlg.png" /></figure><p>Let’s say we choose t2.micro after choosing the machine we need to install node js and all the dependencies which is required to run our code then we will run our code on the same machine and this machine is up 24 * 7, if we calculate that how much this t2.micro will cost, we can easily calculate as it’s hourly charge is 0.0116$, so per month cost will be 24 * 30 * 0.0116 = 8.35$ which is equal to 690 INR.</p><p>Drawbacks of using monolith.</p><ol><li>Our machine will be continuously running 24 * 7 whether there is any user using our website or not.</li><li>We need to manage the configuration of EC2, also an OS installation.</li><li>We need to also do the code deployment.</li><li>We need to also worry about the dependencies that are required to run our code, like node js.</li><li>Let’s say 10000 users suddenly come to our website then we need to also worry about scaling up and when there are fewer users then we need to scale down also, in AWS we use ASG(Auto Scaling Group) and definitely ASG also costs some money.</li></ol><p>Let’s see how serverless works</p><p>In serverless we need to only worry about the code and we don’t have to worry about the underlying architecture that is called serverless</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nAnrKnGrgR2Ajmy-_Iu2g.png" /></figure><p>In terms of AWS, there is something which is called <strong>AWS lambda, </strong>we just need to give our code to AWS and it’s AWS&#39;s responsibility to allocate OS(Operating System), RAM, and Storage, handle deployment, upscale, or downscale.</p><p>This is called serverless we don’t have a server we have only code.</p><p>Benefits</p><ol><li>AWS lambda is charged on a per invocation basis as of now it charges 0.001$/ invocation not an hourly basis as in the case of EC2 we have been charged on an hourly basis regardless of whether there is any user on our website or not.</li><li>We don’t have to worry about scaling it will be handled automatically by our cloud provider.</li></ol><p>How Serverless work</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nsy8vPxUKN9930gTnbAHww.png" /></figure><p>We have a code deployed on serverless and as of now, it’s in a <strong>Sleep </strong>state when the user visits <a href="https://finoyou.in/">https://www.finoyou.in</a> our code will change to<strong> a Start </strong>state then our code run line by line and return the response to our user, and then it will switch to <strong>Sleep</strong> state.</p><p>Let’s say at some time 10k users visit our website then serverless will replicate our code, and when there are fewer users it will scale down accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YyYAJ7mDUMKBTWvvqy7adg.png" /></figure><p>Let’s create our first lambda in AWS</p><ol><li>Open AWS and serach for lambda and then hit <strong>Create Function</strong> button</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSKrrxGcUOq_4sOTCjwo3Q.png" /></figure><p>2. Let’s configure our lambda function</p><ul><li>Write our function name</li><li>Choose runtime in this case we choose Node js 18 version.</li><li>Hit <strong>Create Function</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HL4QzFmItb8tKwwodQQRPA.png" /></figure><p>3. When our lambda function is created it will navigate to this page where we can see some of the code written.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VH5-kXTaYjQZ_Wqc8yEXGQ.png" /></figure><p>4. We need to add a trigger so that we can access this code for that we need to add a trigger, click on <strong>Add Trigger</strong> which is on the left-hand side it will navigate to this page, and choose <strong>API Gateway and Rest API </strong>under API type and hit <strong>Add</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9OYrdM6jJqSAfQ725fv3IQ.png" /></figure><p>Yeah we successfully created our first lambda, as you can see at the bottom of the page we got an <strong>API endpoint = </strong><a href="https://gybu7kpo5g.execute-api.ap-south-1.amazonaws.com/default/mediumFunc"><strong>https://gybu7kpo5g.execute-api.ap-south-1.amazonaws.com/default/mediumFunc</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ke6azdRP48-C7NrimzXEWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cclwzhwdtqb7BXLU0CxnEQ.png" /></figure><p>Hope you guys like this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76106803580b" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/serverless-76106803580b">Serverless</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Search]]></title>
            <link>https://medium.com/@adnaan28.azam/binary-search-dd1f39031d68?source=rss-a69d3da6bf4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd1f39031d68</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[binary-search]]></category>
            <dc:creator><![CDATA[Adnaan Azam]]></dc:creator>
            <pubDate>Sun, 03 Jul 2022 08:31:49 GMT</pubDate>
            <atom:updated>2023-11-13T16:23:55.240Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qSfFPNHJO-E5oLbGmzFUaA.png" /></figure><p>Binary search is used to find the element in an array.</p><p>Let’s assume we have an array of 5 element</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9qRiaH3wnZVqGglLTWoQbg.png" /></figure><p>We will follow the following 3 steps to find out whether the element (X) which is present in the above array or not.</p><ol><li>Sort the array if it is not sorted then sort it.</li><li>Place three-pointers on an array of Low ( L ), High ( H ), Mid ( M )</li></ol><p>For calculating Mid(M) we can use this formula M= (low+high)/2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmLdl3F5W75iO8iCdgDr1A.png" /></figure><p>3. Let’s compare the element X with mid (M) value, so there will be three possible scenario</p><p>3.1. Array[Mid (M)] = X<br> 3.2. Array[Mid (M)] &gt; X<br> 3.3. Array[Mid (M)] &lt; X</p><p>3.1 Explanation<br>If Array[Mid (M)] === X , we have find the value what we want.</p><p>3.2 Explanation<br>If Array[Mid(M)] &gt; X then we can say that our target element (X) is present in between M(Mid) and High(H)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GnFAekCD_s7F3Mu8FCDvqA.png" /></figure><p>3.3 Explanation<br>If X &lt; Array[Mid(X)] we can say that our target element is present between Low(L) and Mid(M)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JkqVOtqdapSY-cOAkF6uHw.png" /></figure><p>3.4 Last corner case<br> High(H) is always greater than Low(L), if Low (L) &gt; High(H) then we can say target (X) is not present in array and we’ll print NO MATCH or we can return -1</p><p>We’ll keep iterating the process until and unless we find the target element (X)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*NOZwqviCQEHhPKevZuEdww.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd1f39031d68" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>