<?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"><channel><title><![CDATA[Prashant's Blogs]]></title><description><![CDATA[Prashant's Blogs]]></description><link>https://blogs.bigomega.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 12:10:03 GMT</lastBuildDate><atom:link href="https://blogs.bigomega.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[We are repeating the same mistakes]]></title><description><![CDATA[For the last 2 years, I have been working with Dr. James Walden at Miami University on research that focuses on Large Language Models, Cybersecurity, and their implications for software engineering. T]]></description><link>https://blogs.bigomega.dev/we-are-repeating-the-same-mistakes</link><guid isPermaLink="true">https://blogs.bigomega.dev/we-are-repeating-the-same-mistakes</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Mon, 25 May 2026 14:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/628dd2ab99d0b58aec5ada0d/38fb1ba9-8b65-4a94-9c1c-57a1fc61ebe3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For the last 2 years, I have been working with Dr. James Walden at Miami University on research that focuses on Large Language Models, Cybersecurity, and their implications for software engineering. The research we are working on uses different datasets covering the most frequent vulnerabilities that arise in software engineering. I became curious and decided to see how many of these vulnerabilities repeat every single year. A simple data analysis on the Top 25 CWEs for the last 5 years made me realize that we are not learning from our mistakes.</p>
<h3>Common Weakness Enumeration (CWEs)</h3>
<p>Common Weakness Enumeration (CWEs) is a community-developed classification system that lists common weaknesses and vulnerabilities found in software and hardware systems. It is maintained by MITRE, and it provides standard identifiers called CWE IDs so developers, security researchers, and organizations can talk about security issues in a consistent way.</p>
<p>Each CWE entry describes a specific type of weakness, like SQL Injection (CWE-89) or Cross-Site Scripting (CWE-79). It also includes information about how the weakness occurs, its potential impact, and how it can be detected or fixed. New CWE IDs are added when cybersecurity researchers, industry experts, government agencies, or the wider security community identify recurring patterns in real-world systems.</p>
<p>Every year, MITRE publishes the “Top 25 Most Dangerous Software Weaknesses” by analyzing thousands of publicly disclosed CVEs (Common Vulnerabilities and Exposures). These rankings are based on how often a weakness appears and how severe its impact is. The goal is to highlight the most common and persistent security problems that continue to affect modern software systems.</p>
<h3>CWEs focused on the web</h3>
<p>I am most familiar with web development and have around 5 years of experience working in it. Because of that, I want to write a series of blogs focused on common vulnerabilities in web applications and share practical ideas on how to mitigate them while writing code.</p>
<ul>
<li><p>CWE-79 — Cross-Site Scripting (XSS)</p>
</li>
<li><p>CWE-89 — SQL Injection</p>
</li>
<li><p>CWE-352 — Cross-Site Request Forgery (CSRF)</p>
</li>
<li><p>CWE-862 — Missing Authorization</p>
</li>
<li><p>CWE-434 — Unrestricted File Upload</p>
</li>
<li><p>CWE-20 — Improper Input Validation</p>
</li>
<li><p>CWE-502 — Deserialization of Untrusted Data</p>
</li>
<li><p>CWE-287 — Improper Authentication</p>
</li>
<li><p>CWE-306 — Missing Authentication for Critical Function</p>
</li>
<li><p>CWE-918 — Server-Side Request Forgery (SSRF)</p>
</li>
<li><p>CWE-77 — Command Injection</p>
</li>
</ul>
<h3>The repeating pattern</h3>
<p>I created a chart showing how often each vulnerability appears across the last five years. What stood out is that 8 of these CWEs (focused on web) show up every single year, and 2 more appear in 4 out of the 5 years. It’s a pretty clear signal that these aren’t one-off issues; they keep coming back in practice, year after year.</p>
<img src="https://cdn.hashnode.com/uploads/covers/628dd2ab99d0b58aec5ada0d/254549ff-a43a-4bb0-b6e1-60a433139877.png" alt="" style="display:block;margin:0 auto" />

<h3>AI is not saving us</h3>
<p>You probably knew this already, but AI is not saving us. Many current code-generation models are trained on large amounts of existing code, and a significant portion of that code already contains security vulnerabilities. As a result, the same insecure patterns tend to repeat in the output as well.</p>
<p>To mitigate this, developers using these tools need to be familiar with these common vulnerabilities. Instead of blindly relying on generated code, prompts should be more security-aware, and the output should always be carefully reviewed before use in production. These tools can help speed things up, but they don’t replace an understanding of secure coding practices.</p>
<p>This is also reflected in benchmark results like <a href="https://baxbench.com/?utm_source=chatgpt.com">BaxBench</a>, which evaluates how well models generate code for full backend systems that is both functionally correct and secure. Even the best-performing models in their evaluation only produce secure and correct code about 56% of the time. That’s barely better than a coin toss, which shows how fragile “out-of-the-box” code generation still is when it comes to security.</p>
<h3>The next steps (for me)</h3>
<p>Going forward, I want to write blogs in the next few days that focus on how to mitigate these vulnerabilities while actually writing code. I’ll mainly use languages like JavaScript/TypeScript, Go, and Python since these are the ones I have the most experience with. The goal is to connect these common CWEs to practical coding patterns, so it’s easier to avoid them in day-to-day development instead of just understanding them in theory.</p>
]]></content:encoded></item><item><title><![CDATA[A Bash Script With Node.JS]]></title><description><![CDATA[JavaScript is a scripting language, therefore you can write scripts to automate your workflow with JavaScript.
The background of the snippet
I created a node script recently to automate one workflow that I do repeatedly. Every time I create a new Jav...]]></description><link>https://blogs.bigomega.dev/bash-script-node</link><guid isPermaLink="true">https://blogs.bigomega.dev/bash-script-node</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Tue, 01 Dec 2020 17:45:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234431628/hYXcRT3PP.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>JavaScript is a scripting language, therefore you can write scripts to automate your workflow with JavaScript.</p>
<h3 id="heading-the-background-of-the-snippet">The background of the snippet</h3>
<p>I created a node script recently to automate one workflow that I do repeatedly. Every time I create a new JavaScript project, I’d create a <code>.prettierrc</code> file and add 4 configurations.</p>
<p>The file looks something like this,</p>
<pre><code class="lang-plaintext">{  
    "semi": true,  
    "singleQuote": true,  
    "tabWidth": 2,  
    "useTabs": false,  
}
</code></pre>
<p>For those who don’t know what this is, it is a configuration file for prettier. You can install it in your code editor to format your source code in a certain way.</p>
<p>The configuration I created above will make sure that my JS source code will have a semicolon at the end, it will use a single quote on strings, it will use 2 spaces for indentation and instead of using tabs, the editor will use space for formatting indentations.</p>
<p>This process is extremely repetitive. I would do this twice or thrice somedays when I am testing some simple snippets. I care about consistent formatting even in simple snippets that I create to test code (maybe because I have OCD).</p>
<p>This is why I decided to create this script to save me from this trouble and it was a great learning experience. In my opinion, it will open opportunities for me to do so much with this knowledge.</p>
<h3 id="heading-the-major-pieces">The major pieces</h3>
<p>Let’s first understand the pieces that create this script and fit it all in together.</p>
<h3 id="heading-the-interpreter">The interpreter</h3>
<p>On the top of your scripts, we have to specify the path to the interpreter we plan to use. In our case, it is node. To do so, we have to use <a target="_blank" href="https://en.wikipedia.org/wiki/Shebang_%28Unix%29">a shebang line</a>.</p>
<p>For node</p>
<pre><code class="lang-plaintext">#!/usr/bin/env node
</code></pre>
<p>Some other examples</p>
<pre><code class="lang-plaintext">- for python   
#!/usr/bin/env python3   
- for bash  
#!/bin/bash
</code></pre>
<h3 id="heading-the-working-directory">The working directory</h3>
<p>For this script to work, it has to know where it is being run at. For example, if I run this script on Projects directory on my home directory (in Linux), it should be able to identify that and create a <code>.prettierrc</code> file inside <code>~/Projects</code>.</p>
<p>For that, we can extract the current working directory from the node’s global process object.</p>
<pre><code class="lang-plaintext">process.cwd()
</code></pre>
<p>This gives us the path to the current working directory.</p>
<h3 id="heading-the-file-system-module">The file system module</h3>
<p>Node ships a file system module by default. We need to grab the writeFile function from the <code>fs</code> module and write our <code>.prettierrc</code> file to our file system.</p>
<p>Read the <a target="_blank" href="https://nodejs.org/dist/latest-v14.x/docs/api/fs.html#fs_fs_writefile_file_data_options_callback">official docs</a>.</p>
<p><strong>Example</strong></p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%2891%2C107%2C109%2C1%29&amp;t=one-dark&amp;wt=boxy&amp;l=auto&amp;ds=true&amp;dsyoff=30px&amp;dsblur=68px&amp;wc=false&amp;wa=false&amp;pv=0px&amp;ph=0px&amp;ln=false&amp;fl=1&amp;fm=dm&amp;fs=18px&amp;lh=143%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=%2520%2520const%2520fs%2520%253D%2520require%28%27fs%27%29%253B%250A%250A%2520%2520%252F%2A%2A%250A%2520%2520%2520%2520%2A%2520writeFile%28filename%252C%2520content%252C%2520callback%29%253B%250A%2520%2520%2520%2520%2A%252F%250A%250A%2520%2520fs.writeFile%28%250A%2520%2520%2520%2520%27test.txt%27%252C%2520%250A%2520%2520%2520%2520%27This%2520is%2520the%2520content%2520for%2520the%2520file%27%252C%2520%250A%2520%2520%2520%2520%28error%252C%2520data%29%2520%253D%253E%2520%257B%250A%2520%2520%2520%2520%2520%2520if%2520%28error%29%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520console.log%28error%29%253B%250A%2520%2520%2520%2520%2520%2520%257D%250A%250A%2520%2520%2520%2520%2520%2520console.log%28%27File%2520written%2520successfully%27%29%253B%250A%2520%2520%2520%2520%257D%250A%2520%2520%29%253B" width="700" height="328"></iframe>

<h3 id="heading-fitting-it-all-together">Fitting it all together</h3>
<p>Now as we have all the background information, we can create the script.</p>
<p>First, create a file called <code>prettier-config</code> or <code>prettier-config.js</code> and paste the following content.</p>
<p><strong>Note:</strong> the extension is not mandatory but remember what you name it because we have to access it later.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%2891%2C107%2C109%2C1%29&amp;t=one-dark&amp;wt=boxy&amp;l=javascript&amp;ds=true&amp;dsyoff=30px&amp;dsblur=68px&amp;wc=false&amp;wa=false&amp;pv=0px&amp;ph=0px&amp;ln=false&amp;fl=1&amp;fm=dm&amp;fs=18px&amp;lh=143%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=%2520%2520%2523%21%252Fusr%252Fbin%252Fenv%2520node%250A%250A%2520%2520const%2520fs%2520%253D%2520require%28%27fs%27%29%253B%250A%250A%2520%2520const%2520configs%2520%253D%2520%257B%250A%2520%2520%2520%2520semi%253A%2520true%252C%250A%2520%2520%2520%2520tabWidth%253A%25202%252C%250A%2520%2520%2520%2520useTabs%253A%2520false%252C%250A%2520%2520%2520%2520singleQuote%253A%2520true%252C%250A%2520%2520%257D%253B%250A%250A%2520%2520fs.writeFile%28%250A%2520%2520%2520%2520%2560%2524%257Bprocess.cwd%28%29%257D%252F.prettierrc%2560%252C%250A%2520%2520%2520%2520JSON.stringify%28configs%29%252C%250A%2520%2520%2520%2520%28error%252C%2520data%29%2520%253D%253E%2520%257B%250A%2520%2520%2520%2520%2520%2520if%2520%28error%29%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520console.error%28%27Error%2520creating%2520the%2520configuration%2520file.%27%252C%2520error%29%253B%250A%2520%2520%2520%2520%2520%2520%257D%250A%2520%2520%2520%2520%2520%2520console.log%28%27Configuration%2520created%27%29%253B%250A%2520%2520%2520%2520%257D%250A%2520%2520%29%253B" width="700" height="328"></iframe>

<p>Here, I am just fitting together the information provided above and mixing it to create the .prettierrc file.</p>
<p>The script stores the configuration file in an object called <code>configs</code>. You can add as more configs as you like in this file.</p>
<p>JSON and JS objects might seem similar but they have some minor differences. For example, the keys in a JSON have to be wrapped inside double-quotes. That is the reason why I have used <code>JSON.stringify(configs)</code> to convert the JS object into a JSON string while writing to the file.</p>
<h3 id="heading-executable-permission-and-global-access">Executable permission and global access</h3>
<p>We generally want our scripts to be available everywhere in our system. Also, we have to give executable permission to our scripts.</p>
<p>Moving our script to <code>/usr/local/bin</code> on our file system will allow us to use the script anywhere on our system. To do so, move the script file,</p>
<pre><code class="lang-plaintext">mv prettier-config /usr/local/bin/prettier-config   
sudo mv prettier-config /usr/local/bin/prettier-config
</code></pre>
<p>We want our scripts to have executable (x) permission and we want it to provide this permission to the owner/user, group and others (a).</p>
<pre><code class="lang-plaintext">sudo chmod a+x /usr/local/bin/prettier-config
</code></pre>
<p>Now if you try to run <code>prettier-config</code> command anywhere on your file system, you will get a .prettierrc file with necessary configuration created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234429699/QxK1TTQ4p.png" alt /></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>If you like my content and want to have a chat then please hit me up on <a target="_blank" href="https://twitter.com/dev_prashaant">Twitter</a>.</p>
<p><em>Originally published at</em> <a target="_blank" href="https://www.bigomega.dev/bash-script-node"><em>https://www.bigomega.dev</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[Simple Markdown Parser with JavaScript and Regular Expressions]]></title><description><![CDATA[In this article, you will learn to build a Markdown parser which compiles into HTML with JavaScript and Regular Expression
Markdown is a markup language like HTML. It is quite popular among developers to write blogs, readme files, and documentation. ...]]></description><link>https://blogs.bigomega.dev/markdown-parser</link><guid isPermaLink="true">https://blogs.bigomega.dev/markdown-parser</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Fri, 21 Aug 2020 17:54:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234578431/8uKea52PI.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-in-this-article-you-will-learn-to-build-a-markdown-parser-which-compiles-into-html-with-javascript-and-regular-expression">In this article, you will learn to build a Markdown parser which compiles into HTML with JavaScript and Regular Expression</h4>
<p>Markdown is a markup language like HTML. It is quite popular among developers to write blogs, readme files, and documentation. Some of the popular websites that support rich text like Reddit, GitHub, Notion etc allow you to write Markdown. I use Markdown to convert my blog from a Markdown file to HTML web pages. Markdown is simple yet very powerful. In this blog, I will be writing about how to build a simple Markdown parser to convert Markdown to HTML with JavaScript using Regular Expressions.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234578431/8uKea52PI.png" alt /></p>
<p>Markdown Parser</p>
<h3 id="heading-how-does-markdown-text-look-like">How does Markdown text look like</h3>
<p>If you open a markdown file, you’ll see the following syntax.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=markdown&amp;ds=true&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=56px&amp;ph=56px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=14px&amp;lh=133%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=%2523%2520The%2520text%2520after%2520hash%2520is%2520converted%2520to%2520an%2520h1%2520in%2520HTML%250A%250A%2523%2523%2520Get%27s%2520converted%2520to%2520h2%250A%250A%2A%2AThis%2520is%2520a%2520bold%2520text%2A%2A%2520_italics_%250A%255BLink%2520Text%255D%28url%29" width="700" height="328"></iframe>

<p>Markdown text example</p>
<p>Learn more from this <a target="_blank" href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet">Markdown cheatsheet</a>.</p>
<h3 id="heading-regular-expressions">Regular Expressions</h3>
<p>A regular expression is a character sequence that helps us to capture patterns in a text. We can use it to validate user input, find and replace texts and yup, you guessed it, build our Markdown parser. 😉</p>
<p>Different languages have different ways to represent RegEx. Here is how it is done in JavaScript.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=false&amp;pv=56px&amp;ph=56px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=%252F%252F%2520Validates%2520all%2520the%2520text%2520that%2520includes%2520the%2520text%2520Hello%2520%28case%2520sensitive%29%250Aconst%2520pattern%2520%253D%2520%252FHello%252F%250Aconst%2520text%2520%253D%2520%27Hello%252C%2520beautiful%2520people%27%250Apattern.test%28text%29%2520%252F%252F%2520Returns%2520true" width="700" height="328"></iframe>

<p>Markdown example in JavaScript</p>
<p>I will explain the patterns we use in our parser as we reach that section. However, if you want to read more about regular expressions, visit <a target="_blank" href="https://javascript.info/regular-expressions">https://javascript.info</a>.</p>
<h3 id="heading-markdown-parser">Markdown parser</h3>
<p>The Markdown parser I intend to build is a function that takes Markdown text as input and returns HTML.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=19px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=function%2520parseMarkdown%28markdownText%29%2520%257B%250A%2509const%2520htmlText%2520%253D%2520markdownText%2520%250A%2520%2520%2520%2520%252F%252F%2520do%2520something%2520to%2520this%2520markdown%2520text%250A%250A%2509return%2520htmlText%250A%257D" width="700" height="328"></iframe>

<p>Markdown parser function</p>
<p>Here, we want to find a certain pattern in <code>markdownText</code> and perform replace operations.</p>
<h3 id="heading-string-replace-function">String replace function</h3>
<p>Our Markdown parser is simple. It captures a pattern from Markdown string passed to the function as <code>markdownText</code> argument and replaces it with certain HTML pattern.</p>
<p>Here is how the string replace function works.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=text%2520%253D%2520%27hello%2520world%2520and%2520hello%2520everyone%27%250AregEx%2520%253D%2520%252FHello%252Fgi%250Aconsole.log%28text.replace%28regEx%252C%2520%27hi%27%29%29%250A%252F%252F%2520prints%253A%2520%27hi%2520world%2520and%2520hi%2520everyone%27" width="700" height="328"></iframe>

<p>Working of replace function</p>
<p><em>Note: Here the</em> <strong><em>i flag represents case insensitive</em></strong> <em>and</em> <strong><em>g flag represents global*</em></strong>, which means it matches patterns everywhere on the string, not just the first match.*</p>
<h3 id="heading-capturing-groups-in-regular-expression">Capturing groups in Regular Expression</h3>
<p>Regular Expressions allows us to capture patterns of text and reference them with something like an index. We can use the index in the replace operation. To represent a group, we can simply wrap it in a parenthesis <code>()</code>.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=text%2520%253D%2520%27hello%2520world%2520and%2520hello%2520everyone%27%250A%252F%252F%2520RegEx%2520to%2520match%2520a%2520string%2520starting%2520with%2520hello%2520followed%2520by%2520anything%250AregEx%2520%253D%2520%252F%28Hello%29.%2A%252Fi%250Aconsole.log%28text.replace%28regEx%252C%2520%27Matched%2520Group%253A%2520%25241%27%29%29%250A%252F%252F%2520prints%253A%2520%27Matched%2520Group%253A%2520hello%27" width="700" height="328"></iframe>

<p>Capturing groups in Regular Expression</p>
<p>Here, we have stored the starting hello in a group. The group can then be referenced with <strong>$1</strong> on our replace operation.</p>
<h3 id="heading-back-to-the-parser">Back to the parser</h3>
<p>Now, we want to parse the Markdown text and replace it with HTML.</p>
<p>Here are the RegExes we will use in our parser and their explanation.</p>
<p><strong>Heading</strong><br />For heading, we want a string that starts with a hash(es) and captures everything after those characters.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=const%2520h3%2520%253D%2520%252F%255E%2523%2523%2523%2520%28.%2A%2524%29%252Fgim" width="700" height="328"></iframe>

<p>RegEx for h3</p>
<p>Here the first carat <code>^</code> represents line starting with and m flag represents multiple lines and by doing .* we are capturing everything (letters, numbers, special characters) that exists there.</p>
<p><strong>Blockquote</strong><br />For blockquote, we want a line that starts with<code>&gt;</code> and captures everything after that character.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=const%2520bq%2520%253D%2520%252F%255E%255C%253E%2520%28.%2A%2524%29%252Fgim" width="700" height="328"></iframe>

<p>Blockquote RegEx</p>
<p>Note: \&gt; represents escaping &gt; character. That means, don’t treat &gt; as a part of special regEx character but as a part of that text itself.</p>
<p><strong>Bold Text</strong><br />For bold text, we want to capture a text between 2 asterisks.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=const%2520bold%2520%253D%2520%252F%255C%2A%255C%2A%28.%2A%29%255C%2A%255C%2A%252Fgim" width="700" height="328"></iframe>

<p>RegEx for Bold text</p>
<p><strong>Italics Text</strong><br />For italic text, we want to capture a text between one asterisk.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=const%2520italics%2520%253D%2520%252F%255C%2A%28.%2A%29%255C%2A%252Fgim" width="700" height="328"></iframe>

<p>RegEx for Italics</p>
<p><strong>Image, links and line break</strong></p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=%252F%252F%2520!%255BAlt%2520text%255D%28url%29%250Aconst%2520image%2520%253D%2520%252F!%255C%255B%28.%2A%253F%29%255C%255D%255C%28%28.%2A%253F%29%255C%29%252Fgim%250A%252F%252F%2520%255Btext%255D%28url%29%250Aconst%2520link%2520%253D%2520%252F%255C%255B%28.%2A%253F%29%255C%255D%255C%28%28.%2A%253F%29%255C%29%252Fgim%250Aconst%2520lineBreak%2520%253D%2520%252F%255Cn%2524%252Fgim" width="700" height="328"></iframe>

<p>RegEx for Image, Link and Line break</p>
<h3 id="heading-fitting-it-all-together">Fitting it all together</h3>
<p>By this point, you probably have all the background necessary to understand the concepts. Let’s fit all the things that we have learnt up to now and build the parser.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=function%2520parseMarkdown%28markdownText%29%2520%257B%250A%2509const%2520htmlText%2520%253D%2520markdownText%250A%2509%2509.replace%28%252F%255E%2523%2523%2523%2520%28.%2A%2524%29%252Fgim%252C%2520%27%253Ch3%253E%25241%253C%252Fh3%253E%27%29%250A%2509%2509.replace%28%252F%255E%2523%2523%2520%28.%2A%2524%29%252Fgim%252C%2520%27%253Ch2%253E%25241%253C%252Fh2%253E%27%29%250A%2509%2509.replace%28%252F%255E%2523%2520%28.%2A%2524%29%252Fgim%252C%2520%27%253Ch1%253E%25241%253C%252Fh1%253E%27%29%250A%2509%2509.replace%28%252F%255E%255C%253E%2520%28.%2A%2524%29%252Fgim%252C%2520%27%253Cblockquote%253E%25241%253C%252Fblockquote%253E%27%29%250A%2509%2509.replace%28%252F%255C%2A%255C%2A%28.%2A%29%255C%2A%255C%2A%252Fgim%252C%2520%27%253Cb%253E%25241%253C%252Fb%253E%27%29%250A%2509%2509.replace%28%252F%255C%2A%28.%2A%29%255C%2A%252Fgim%252C%2520%27%253Ci%253E%25241%253C%252Fi%253E%27%29%250A%2509%2509.replace%28%252F!%255C%255B%28.%2A%253F%29%255C%255D%255C%28%28.%2A%253F%29%255C%29%252Fgim%252C%2520%2522%253Cimg%2520alt%253D%27%25241%27%2520src%253D%27%25242%27%2520%252F%253E%2522%29%250A%2509%2509.replace%28%252F%255C%255B%28.%2A%253F%29%255C%255D%255C%28%28.%2A%253F%29%255C%29%252Fgim%252C%2520%2522%253Ca%2520href%253D%27%25242%27%253E%25241%253C%252Fa%253E%2522%29%250A%2509%2509.replace%28%252F%255Cn%2524%252Fgim%252C%2520%27%253Cbr%2520%252F%253E%27%29%250A%250A%2509return%2520htmlText.trim%28%29%250A%257D" width="700" height="328"></iframe>

<p>Time to test the parser.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=const%2520text%2520%253D%2520%2560%250A%2523%2520Hello%2520World%250A%2A%2AThis%2520is%2520a%2520bold%2520text%2A%2A%250A%2560%250A%250Aconsole.log%28parseMarkdown%28text%29%29" width="700" height="328"></iframe>

<p>Testing the parser</p>
<p>Should print:</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=material&amp;wt=none&amp;l=htmlmixed&amp;ds=true&amp;dsyoff=15px&amp;dsblur=24px&amp;wc=true&amp;wa=false&amp;pv=20px&amp;ph=23px&amp;ln=false&amp;fl=1&amp;fm=Fira%20Code&amp;fs=16px&amp;lh=150%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=%253Ch1%253EHello%2520World%253C%252Fh1%253E%250A%253Cb%253EThis%2520is%2520a%2520bold%2520text%253C%252Fb%253E%253Cbr%2520%252F%253E" width="700" height="328"></iframe>

<p>Output</p>
<p>Our Markdown parser is now completed. It doesn’t cover everything that Markdown supports. Try implementing them and share the solution with me via twitter.</p>
<p><em>Originally published at</em> <a target="_blank" href="https://www.bigomega.dev/markdown-parser"><em>https://www.bigomega.dev</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[Error handling for express.js applications]]></title><description><![CDATA[Handling error in express applications can be more challenging than building web applications and APIs
Building web applications or APIs with express.js is not difficult in my opinion. I think it is more difficult to handle errors, error status codes...]]></description><link>https://blogs.bigomega.dev/error-handling-for-express-js-applications-a26a3002ef82</link><guid isPermaLink="true">https://blogs.bigomega.dev/error-handling-for-express-js-applications-a26a3002ef82</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Tue, 05 May 2020 17:13:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234440257/70-iC4dqF.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-handling-error-in-express-applications-can-be-more-challenging-than-building-web-applications-and-apis">Handling error in express applications can be more challenging than building web applications and APIs</h4>
<p>Building web applications or APIs with express.js is not difficult in my opinion. I think it is more difficult to handle errors, error status codes and error messages properly. Below, I’m going to list out a few techniques by which I handle errors in my express.js applications.</p>
<p>We need to understand <strong>middleware</strong> to handle errors if you want to apply the technique I am going to suggest. Simply, a middleware in express is a function that has access both the request and the response objects for a particular route. Additionally, they take in an argument <strong>next</strong> which is a function that gets called after the middleware function is executed.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=one-dark&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=14px&amp;ph=13px&amp;ln=false&amp;fl=1&amp;fm=Anonymous%20Pro&amp;fs=18px&amp;lh=133%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=const%2520express%2520%253D%2520require%28%27express%27%29%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%250Aconst%2520app%2520%253D%2520express%28%29%250A%250Afunction%2520someMiddleware%28req%252C%2520res%252C%2520next%29%257B%250A%2509console.log%28%27Request%2520made%27%29%250A%2520%2520%2509%252F%252F%2520after%2520the%2520task%2520of%2520middleware%2520is%2520complete%250A%2520%2520%2509%252F%252F%2520we%2520call%2520the%2520next%2520function%250A%2520%2520%2509next%28%29%250A%257D%250A%250A%252F%252F%2520this%2520middleware%2520get%27s%2520called%2520before%2520%2520the%2520%252Fsomeroute%2520get%27s%2520hit%250A%252F%252F%2520some%250Aapp.use%28someMiddleware%29%250Aapp.get%28%27%252Fsomeroute%27%252C%2520controller%29" width="700" height="328"></iframe>

<p>Middleware example</p>
<p>In the above example, if you send a get request to <em>/someroute</em> route ‘Request made’ will be logged on the console.</p>
<h4 id="heading-controllers-and-middlewares">Controllers and Middlewares</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234438847/TmwzFC2OY.png" alt /></p>
<p>Controllers and Middlewares</p>
<p>The above image explains what is a controller and what is middleware. When a request is received on a particular route, middleware-1,2 and 3 gets called before the controller for that route is called. The controller can then send a response. However, the middleware function also has access to the response object, middleware can also send a response and close the request. So, you can assume that any middleware is a controller and any controller is a middleware.</p>
<p>For example, a middleware function to verify JWTs can be created. The middleware will verify if the token is valid. If it is invalid, the middleware will send an error response back to the client and close the request. The middlewares/controller after that JWT verification middleware will not be called in that case.</p>
<h4 id="heading-project-structure">Project Structure</h4>
<p>Express is an unopinionated web framework for building web applications using Node.JS. Since, it is an unopinionated web framework, the directory structure for organizing project is not strictly recommended by the framework creators. Below, I am going to show you the screenshot of my project structure which you can follow to organize your projects, however, you can follow your own structure if that feels right.</p>
<p>Project Structure</p>
<h4 id="heading-function-to-create-error-objects">Function to create error objects</h4>
<p>Inside <em>utils/createError.js</em> file, I have a function that takes in two things: a status code and an error message and returns an error object.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=one-dark&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=14px&amp;ph=13px&amp;ln=false&amp;fl=1&amp;fm=Anonymous%20Pro&amp;fs=18px&amp;lh=133%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=module.exports%2520%253D%2520%28status%252C%2520message%29%2520%253D%253E%2520%257B%2509%2509%2509%2509%2509%250A%2509const%2520error%2520%253D%2520new%2520Error%28message%29%250A%2520%2520%2520%2520error.status%2520%253D%2520status%250A%2520%2520%2509return%2520error%250A%257D" width="700" height="328"></iframe>

<p><strong>utils/createError.js</strong></p>
<h3 id="heading-centralized-error-handler-in-appjs">Centralized Error Handler in app.js</h3>
<p>This is the main part of this story. We are going to make a middleware function that can accept error objects and if an error is received, it can send an error response to the client making the request. To do so, we are going to create 2 middleware functions. One of the middleware will get triggered if none of the routes above gets called and another will get triggered if any middleware/controller throws an error.</p>
<p>The structure of our app.js will look something like the following.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=one-dark&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=14px&amp;ph=13px&amp;ln=false&amp;fl=1&amp;fm=Anonymous%20Pro&amp;fs=18px&amp;lh=133%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=const%2520express%2520%253D%2520require%28%27express%27%29%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%250Aconst%2520app%2520%253D%2520express%28%29%250A%250A......%2520Othe%2520code%2520.....%250A%250Aapp.use%28someMiddleware%29%250Aapp.get%28%27%252Fsomeroute%27%252C%2520controller%29%250Aapp.use%28%27%252Fauth%27%252C%2520authRouter%29%250Aapp.use%28%27%252Fpost%27%252C%2520postRouter%29%250A............%250A%250A%252F%252F%2520the%25202%2520middlewares%2520I%2520mentioned%250A%252F%252F%2520if%2520none%2520of%2520the%2520routes%2520above%2520gets%2520hit%250Aapp.use%28%28req%252C%2520res%252C%2520next%29%2520%253D%253E%2520%257B%250A%2509next%28createError%28404%252C%2520%27Page%2520not%2520found%27%29%29%250A%257D%29%250A%250A%252F%252F%2520middleware%2520that%2520can%2520accept%2520errors%250A%252F%252F%2520the%2520first%2520argument%2520has%2520error%250Aapp.use%28%28error%252C%2520req%252C%2520res%252C%2520next%29%2520%253D%253E%2520%257B%250A%2520%2520%2509res%250A%2520%2520%2520%2520%2509.status%28error.status%2520%257C%257C%2520500%29%250A%2520%2520%2520%2520%2509.send%28%257B%2520status%253A%2520%27Error%27%252C%2520message%253A%2520error.message%2520%257D%29%253B%250A%257D%29" width="700" height="328"></iframe>

<p>Middleware functions</p>
<p>Generally, all errors have a message property so, you can trust that there will be a message with error object in our error handling middleware. If in case there’s not one then, by default ‘Internal server error will be sent.’</p>
<h4 id="heading-how-to-trigger-an-error-to-utilize-our-centralized-error-handler">How to trigger an error to utilize our centralized error handler?</h4>
<p>Imagine that you have a controller that logs in users to the application. A high-level implementation example will be shown in the example here. On the bottom of this story, I will add a GitHub repository of an express application which will include all these applied on a real project.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=one-dark&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=14px&amp;ph=13px&amp;ln=false&amp;fl=1&amp;fm=Anonymous%20Pro&amp;fs=18px&amp;lh=133%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=app.post%28%27%252Fauth%252Flogin%27%252C%2520async%2520%28req%252C%2520res%252C%2520next%29%2520%253D%253E%2520%257B%2509%2509%2509%250A%2509try%2520%257B%250A%2520%2520%2520%2520%2520%2520%2509%252F%252F%2520find%2520a%2520user%2520matchign%2520username%2520from%2520the%2520DB%250A%2520%2520%2520%2520%2509const%2520user%2520%253D%2520await%2520User.find%28req.body.username%29%250A%2520%2520%2520%2520%2520%2520%2520%2520%250A%2520%2520%2520%2520%2520%2520%2520%2520%252F%252F%2520if%2520there%27s%2520no%2520user%250A%2520%2520%2520%2520%2520%2520%2520%2520if%28!user%29%2520throw%2520createError%28403%252C%2520%27Username%2520or%2520password%2520do%2520not%2520match%27%29%2509%2509%2509%2509%250A%2520%2520%2520%2520%2520%2520%2509%252F%252F%2520if%2520password%2520does%2520not%2520equal%2520hashed%2520password%250A%2520%2520%2520%2520%2520%2520%2509%252F%252F%2520throw%2520error%250A%2520%2520%2520%2520%2520%2520%2509if%28user.password%2520%253D%253D%2520hashed%28req.body.password%29%29%2509%2509%2509%2509%2509%2509%2509%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2509res.send%28%27Logged%2520in%27%29%250A%2520%2520%2520%2520%2520%2520%2509else%2520throw%2520createError%28403%252C%2520%27Username%2520or%2520password%2520do%2520not%2520match%27%29%250A%2520%2520%2520%2520%257D%2520catch%2520%28error%29%2520%257B%250A%2520%2520%2520%2520%2520%2520%2509%252F%252F%2520this%2520will%2520be%2520handled%2520by%2520our%2520error%2520handler%250A%2520%2520%2520%2520%2509next%28error%29%250A%2520%2520%2520%2520%257D%250A%257D%29" width="700" height="328"></iframe>

<p>Login and error handling example</p>
<p>This is how you can apply error handling practices in your express.js applications.</p>
<p>If you want to see a project with all these applied, go to this <a target="_blank" href="https://github.com/prashantacharya/idea-submission">GitHub Repository</a> and see the code in action.</p>
<p>Thank you for reading. I also write contents for my own website <a target="_blank" href="https://bigomega.dev.">https://bigomega.dev.</a> You can sign up for my newsletter.</p>
<h3 id="heading-a-note-in-plain-english"><strong>A note In Plain English</strong></h3>
<p>Did you know that we have four publications and a YouTube channel? You can find all of this from our homepage at <a target="_blank" href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> — show some love by giving our publications a follow and <a target="_blank" href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>subscribing to our YouTube channel</strong></a><strong>!</strong></p>
]]></content:encoded></item><item><title><![CDATA[Async Await in JavaScript]]></title><description><![CDATA[This blog is a follow-up to my last blog in which I talked about promises. If you are unfamiliar with promises in JavaScript, please read that article before reading this one. Also, some familiarity with exception handling would be useful.
Async Awai...]]></description><link>https://blogs.bigomega.dev/async-await</link><guid isPermaLink="true">https://blogs.bigomega.dev/async-await</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Sat, 15 Feb 2020 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>This blog is a follow-up to my last blog in which I talked about promises. If you are unfamiliar with promises in JavaScript, please read <a target="_blank" href="https://bigomega.dev/promises">that article</a> before reading this one. Also, some familiarity with exception handling would be useful.</p>
<p>Async Await is a syntactic sugar added to ECMAScript 2017 standard that helps us work with promises easier. As I mentioned in the last blog, promises were introduced to work with asynchronous code and avoid callback hell. Though promises aimed to do so, the code still looks kind of callbacky. Async and await help us to write asynchronous code but it looks like synchronous code.</p>
<p>On the last blog, we created an imitation of the fetch API. It was a function that returned a promise. It looked like this</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetch</span>(<span class="hljs-params">requestPassed = true</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (requestPassed) {
            resolve(<span class="hljs-string">'{"success": true,
            "data": {"movies": ["batman", "iron man"]}}'</span>)
        } <span class="hljs-keyword">else</span> {
            reject(<span class="hljs-string">'{"success": false,
            "message": "Database connection failed"}'</span>)
        }
    })
}
</code></pre>
<p>To consume the promise, we did the following</p>
<pre><code class="lang-js">fetch()
    .then(<span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> <span class="hljs-built_in">JSON</span>.parse(data))
    .then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(res))
    .catch(<span class="hljs-function"><span class="hljs-params">err</span> =&gt;</span> <span class="hljs-built_in">JSON</span>.parse(err))
    .then(<span class="hljs-function"><span class="hljs-params">errorMsg</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(errorMsg))
</code></pre>
<p>This is the part where we can use async-await to make our code look better. To consume the promise, we have to use an async function which we can describe as follows:</p>
<pre><code class="lang-js"><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetchData</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p>Inside an <code>async</code> function, we can use the <code>await</code> keyword to wait for the promise to resolve.</p>
<pre><code class="lang-js"><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetchData</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">/*
     * here the fetch function returns a promise
     * we have to await the promise to get resolved here
     */</span>
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> fetch()
    <span class="hljs-comment">// once the data is fetched, we can do anything we want</span>
    <span class="hljs-comment">// lets parse the JSON string to a JS object and</span>
    <span class="hljs-comment">// log it onto the console</span>
    <span class="hljs-keyword">const</span> res = <span class="hljs-built_in">JSON</span>.parse(data)
    <span class="hljs-built_in">console</span>.log(res)
}

fetchData()
</code></pre>
<p>The above code will print the following onto the console</p>
<pre><code class="lang-js">{ <span class="hljs-attr">success</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">data</span>: { <span class="hljs-attr">movies</span>: [ <span class="hljs-string">'batman'</span>, <span class="hljs-string">'iron man'</span> ] } }
</code></pre>
<p>If we revisit the promise, we know that the promise might get resolved or might get rejected. Rejection of a promise might be because of some error (it all depends on the use case too but that's the only thing I can think of right now). Hence, the use of <strong>exception handling</strong> with <strong>try-catch</strong> can be really handy while using <code>async-await</code>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetchData</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> fetch(<span class="hljs-literal">false</span>)
        <span class="hljs-keyword">const</span> res = <span class="hljs-built_in">JSON</span>.parse(data)
        <span class="hljs-built_in">console</span>.log(res)
    } <span class="hljs-keyword">catch</span> (error) {
        <span class="hljs-keyword">const</span> errorObject = <span class="hljs-built_in">JSON</span>.parse(error)
        <span class="hljs-built_in">console</span>.log(errorObject)
    }
}

fetchData()
</code></pre>
<p>I have intentionally passed false value as an argument to the fetch function to make the promise reject. Anything passed to the reject function will be received by the catch block as an exception. We can reference the rejected error on the <code>error</code> argument we have passed to the catch block. The above code logs the following onto the console.</p>
<pre><code class="lang-js">{ <span class="hljs-attr">success</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">message</span>: <span class="hljs-string">'Database connection failed'</span> }
</code></pre>
<p>This is how async and await can be used with promises to make our code more readable. If you revisit and make a comparison with the code we wrote earlier, you'll find a vast difference. Async-await is one of my favourite features on JavaScript and I use it all the time. It has made my life as a JavaScript developer easier.</p>
<p>Thanks for reading. If you like my content, consider subscribing.</p>
]]></content:encoded></item><item><title><![CDATA[Promises in JavaScript]]></title><description><![CDATA[Promises in JavaScript behave similarly to promises we make normally to people. It's something like you'll get great score if submit your assignments on time. In this example, if the student submits his assignments on time, the promise made to him ge...]]></description><link>https://blogs.bigomega.dev/promises-in-javascript</link><guid isPermaLink="true">https://blogs.bigomega.dev/promises-in-javascript</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Tue, 11 Feb 2020 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>Promises in JavaScript behave similarly to promises we make normally to people. It's something like <strong>you'll get great score if submit your assignments on time.</strong> In this example, if the student submits his assignments on time, the promise made to him gets fulfilled else, it will not. In JavaScript, promises let us handle tasks that might happen in the future. This concept is really important while doing tasks like making <strong>network requests</strong>, as we're not certain if the request gets resolved or not.</p>
<p>Promises were released in ES2015 to minimize the callbacky code we used to write.</p>
<h2 id="heading-the-syntax">The Syntax</h2>
<p>To use a promise, we have to create a promise object that takes in a callback function with 2 arguments: <strong>resolve</strong> and <strong>reject</strong>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> myPromise = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {})
</code></pre>
<h3 id="heading-resolve">Resolve</h3>
<p>If the <strong>promise is fulfilled</strong>, <strong>resolve gets called</strong>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> myPromise = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> condition = <span class="hljs-literal">true</span>

    <span class="hljs-keyword">if</span> (condition) resolve(<span class="hljs-string">'Promise is resolved.'</span>)
})
</code></pre>
<p>Here, if the value of the condition is true, we resolve the promise. The promise returns the thing inside the resolve function if it gets resolved.</p>
<h3 id="heading-reject">Reject</h3>
<p>If the <strong>promise is not fulfilled</strong>, <strong>reject gets called</strong>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> myPromise = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> condition = <span class="hljs-literal">true</span>

    <span class="hljs-keyword">if</span> (condition) resolve(<span class="hljs-string">'Promise is resolved.'</span>)
    <span class="hljs-keyword">else</span> reject(<span class="hljs-string">'Promise is rejected.'</span>)
})
</code></pre>
<p>We have successfully created a promise object that resolves if the condition is true and rejects if the condition is false. You can modify the use case as you want but this is the basic concept with which you can create promises.</p>
<p>The next step is to use the promise.</p>
<h2 id="heading-using-the-promise-object">Using the promise object</h2>
<p>Before promises, we had a concept of callbacks. With callbacks, we'd create a function to do something and after the function completes its execution, we'd call a function that does something to complement the task done by the first function. This step would be repeated again and again until we reach a callback hell. Promises solve this problem.</p>
<p>We can use a series of <code>.then</code>s to use a promise, <strong>if it's resolved</strong>.</p>
<p>Let's see how we'd use the <code>myPromise</code> promise object we defined above.</p>
<pre><code class="lang-js">myPromise.then(<span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(data))
</code></pre>
<p>This would output the following on the console</p>
<pre><code class="lang-shell">Promise is resolved.
</code></pre>
<p>If the promise is rejected, we have to use a catch to handle promise. To make the promise reject, we can change the value of the condition variable to equal <code>false</code>. In such a case, our promise gets rejected.</p>
<pre><code class="lang-js">myPromise
    .then(<span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> {
        <span class="hljs-comment">// This function only gets called if</span>
        <span class="hljs-comment">// the promise is resolved</span>
        <span class="hljs-built_in">console</span>.log(data)
    })
    .catch(<span class="hljs-function"><span class="hljs-params">err</span> =&gt;</span> {
        <span class="hljs-comment">// This function gets called if</span>
        <span class="hljs-comment">// the promise is rejected</span>
        <span class="hljs-built_in">console</span>.log(err)
    })
</code></pre>
<p>After running the following program, we'll get the following output on the shell.</p>
<pre><code class="lang-shell">Promise is rejected.
</code></pre>
<p>If you've noticed, the <code>data</code> and <code>err</code> we've passed on then and catch equals to the data we've passed to the <code>resolve</code> and <code>reject</code> functions in the promise object we created above.</p>
<h2 id="heading-implementation-of-existing-fetch-api-on-our-own">Implementation of existing fetch API on our own</h2>
<p>The fetch API in JavaScript is a recent addition to JavaScript that allows us to make AJAX requests. Here's how it looks on code</p>
<pre><code class="lang-js">fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/todos/1'</span>)
    .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
    .then(<span class="hljs-function"><span class="hljs-params">json</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(json))
</code></pre>
<p>Here, the <code>fetch</code> requests for data on the URL. The data we receive might not be in a JSON format, therefore we change it to be a JSON on the first <em>then</em> call. The JSON response after we convert the string is passed as <code>json</code> variable on the second <em>then</em>, which is printed on the console after that.</p>
<p>If we run the code above, we get the following output on the console.</p>
<pre><code class="lang-js">{
  <span class="hljs-attr">completed</span>: <span class="hljs-literal">false</span>,
  <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>,
  <span class="hljs-attr">title</span>: <span class="hljs-string">"delectus aut autem"</span>,
  <span class="hljs-attr">userId</span>: <span class="hljs-number">1</span>
}
</code></pre>
<p>Let's try to create a simulation of the fetch API. For simplicity, we'll not handle the network request part. We will just see how the promise is used in the fetch API.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetch</span>(<span class="hljs-params">requestPassed = true</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (requestPassed) {
            resolve(<span class="hljs-string">'{"success": true,
            "data": {"movies": ["batman", "iron man"]}}'</span>)
        } <span class="hljs-keyword">else</span> {
            reject(<span class="hljs-string">'{"success": false,
            "message": "Database connection failed"}'</span>)
        }
    })
}
</code></pre>
<p>To use this function that returns a promise, we can do the following</p>
<pre><code class="lang-js">fetch()
    .then(<span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> <span class="hljs-built_in">JSON</span>.parse(data))
    .then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(res))
    .catch(<span class="hljs-function"><span class="hljs-params">err</span> =&gt;</span> <span class="hljs-built_in">JSON</span>.parse(err))
    .then(<span class="hljs-function"><span class="hljs-params">errorMsg</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(errorMsg))
</code></pre>
<p>Here, we have a default argument <code>requestPassed</code> which is a boolean. If it is set to <code>true</code> or even <code>false</code>, we return a JSON string. We have to parse the string to JavaScript objects so that we can use that properly on our application. Therefore, on the first <code>.then</code> call, we parse the string to represent it in an object format.</p>
<p>Thank you for reading. The next blog will be about <code>async-await</code> which makes using promises even more fun.</p>
]]></content:encoded></item><item><title><![CDATA[Storing passwords the right way on a database with an example on Node.JS backend]]></title><description><![CDATA[Storing a password is a challenge while designing applications. We have to do it well if we don't want to compromise the security of our applications and users. I would like to briefly explain the approaches we might consider while designing an authe...]]></description><link>https://blogs.bigomega.dev/passwords-in-node</link><guid isPermaLink="true">https://blogs.bigomega.dev/passwords-in-node</guid><category><![CDATA[Bcrypt ]]></category><category><![CDATA[passwords]]></category><category><![CDATA[Node.js]]></category><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Wed, 29 Jan 2020 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>Storing a password is a challenge while designing applications. We have to do it well if we don't want to compromise the security of our applications and users. I would like to briefly explain the approaches we might consider while designing an authentication system that stores users' passwords but first, it's also essential to talk about the approaches we should never take.</p>
<p>This blog is inspired by <a href="https://www.youtube.com/watch?v=8ZtInClXe1Q" target="_blank">Tom Scott's video about storing passwords on Computerphile channel on YouTube</a> and also my knowledge of Cryptography.</p>
<h2 id="heading-how-not-to-store-passwords-on-a-database">How not to store passwords on a database?</h2>
<h3 id="heading-plain-text">Plain Text</h3>
<p>I don't think I have to mention this but <strong>plain text</strong> is a format we should never consider while storing passwords. The plain text is the password the user entered while signing up for the service.</p>
<p>For Example: If a user enters <code>123456</code> as a password, we simply store <code>123456</code> in the database.</p>
<p>So simply if the system gets compromised/hacked, we'll be showing the actual password of the user to the hacker. The main problem with this is, most people use the same email and password combination while signing up for multiple services. So the breacher can have access to all the services.</p>
<h3 id="heading-encryption">Encryption</h3>
<p>Encryption means converting plain text (normal text) into cypher text (encrypted text) with the help of some key.</p>
<p>For Example, We might have an algorithm that maps letters of the alphabet with the letters that are shifted to 3 positions. So, if plain text is <strong>abc</strong> then the cypher text would be <strong>def</strong>.</p>
<p>Technically, we're adding a layer of security by simply not exposing the password but there's a problem with this approach. If the breacher gets the key then he can decrypt (obtain the original message) from the encrypted password easily. It's easy to do so because the encryption algorithm is known to us and the only thing we don't know is the key. So hypothetically, if the hacker has acquired the key then all the encrypted passwords in the database get compromised.</p>
<h3 id="heading-cryptographic-hash-function">Cryptographic Hash Function</h3>
<p>A cryptographic hash function is similar to an encryption algorithm. The only difference is, if the message is processed with the cryptographic hash function then it is irreversible (i.e. we'll not get back the original password/message from the hash). A cryptographic hash function always generates an output of fixed length and even a slight variation of plain text will result in a totally different hash.</p>
<p>This is slightly an improvisation over encryption but still, it possesses threats. The main problem with this approach is, two passwords get converted to the same hash.</p>
<p>Simply, the breacher might perform a brute-force attack or a dictionary attack on the system to guess the password. He might take the list of guessed passwords, hash it with the hash function and if any of the hash matches the hash on the database then he has successfully decrypted the password from the hash.</p>
<h2 id="heading-how-to-do-it-right">How to do it right?</h2>
<p>As we have discarded the possibilities of how not to store passwords on the database, let's talk about how we could store passwords well.</p>
<p>The approach that we have to take while doing so is <strong>hashing and salting</strong>. In this mechanism, salt is simply a string of random characters that get added to the password every time we store a new one on the database. If we do this, two different users with the same password will have a different hash.</p>
<p>The salt is <strong>generated randomly</strong> every time a new password is stored on the database. The salt is a long and random string which increases the cost of doing a brute-force attack.</p>
<p><strong>Hashing Only</strong></p>
<pre><code>hash(password)
</code></pre><p><strong>Hashing and Salting</strong></p>
<pre><code>hash(salt + password)
</code></pre><p>The salt is included in the password, therefore we don't have to separately store the salt.</p>
<h2 id="heading-example-of-using-salting-and-hashing-on-nodejs">Example of using salting and hashing on Node.JS</h2>
<p>To do this, we need a package called <code>bcrypt</code> which we can download from the NPM registry.</p>
<pre><code class="lang-shell">npm i bcrypt
</code></pre>
<p>To hash the password, we need to generate a salt. After the generation of salt, we hash the password along with the randomly generated salt. All this is handled by the bcrypt package so we don't have to think much about it.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> hashPasswordAsync = <span class="hljs-keyword">async</span> password =&gt; {
    <span class="hljs-keyword">const</span> salt = <span class="hljs-keyword">await</span> bcrypt.genSalt()
    <span class="hljs-keyword">const</span> hash = <span class="hljs-keyword">await</span> bcrypt.hash(password, salt)
    <span class="hljs-comment">/*
     * Instead of logging on the console
     * you can store the password on the DB
     */</span>
    <span class="hljs-built_in">console</span>.log(hash)
}

hashPasswordAsync(<span class="hljs-string">'123456'</span>)
</code></pre>
<p>I ran the application multiple times and every single time, I was able to get a different hash for the same password <code>123456</code>.</p>
<p>Here are some of the outcomes.</p>
<pre><code class="lang-shell">$2b$10$ZSiqlDuvOrjg8AII94LsROYH.rq.sD0dHaI1P/WxdJkMo7d3Q1FbS
$2b$10$YQYR5GjknzFv0majqhjuQ.e6/P4esEZUmEWBR3P8HwD/AHyNp7Q5y
$2b$10$f9AjCHiiGkgamZ81Tzgu6OZcq6h2sNwTrGZW2DrgpO//BvDBvgMn.
</code></pre>
<h2 id="heading-some-tips-on-creating-passwords-for-normal-user">Some tips on creating passwords for normal user</h2>
<p>As a user, your instinct will be to store a password that is common for every platform because you're likely to forget your password if you use a different password for every different platform. This is not what you should be doing and I highly recommend using a password manager in this case.</p>
<p>Also, do not create a password yourself. Let the password manager generate a random password and store it for you. If you do so, you only have to remember a strong master password that unlocks the password manager which in return gives you access to every password you have stored on the password manager.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Thank you for reading the blog. If you liked it, please subscribe to my newsletter to not miss my uploads.</p>
]]></content:encoded></item><item><title><![CDATA[A beginners guide to Git and Github]]></title><description><![CDATA[Git and GitHub are important for software engineers/developers. To understand Git and GitHub, we have to understand version control first.
Version Control simply means how we can switch between the versions of code. With version control, we can break...]]></description><link>https://blogs.bigomega.dev/a-beginners-guide-to-git-and-github</link><guid isPermaLink="true">https://blogs.bigomega.dev/a-beginners-guide-to-git-and-github</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Sat, 25 Jan 2020 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>Git and GitHub are important for software engineers/developers. To understand Git and GitHub, we have to understand version control first.</p>
<p><strong>Version Control</strong> simply means how we can switch between the versions of code. With version control, we can break the code at some instance and if necessary switch back to the instance when the code was running fine. This can also be useful if you have a client who complains a lot and asks you to make a lot of changes all the time.</p>
<h3 id="heading-what-is-git">What is Git?</h3>
<p><strong>Git</strong> is a distributed version control system created by <strong>Linus Torvalds</strong>. With the help of git, we can control the version of the code. It is the most popular version control tool that exists. <a href="https://git-scm.com/" target="_blank">Read more</a> about git on the official website.</p>
<h3 id="heading-what-is-github">What is GitHub?</h3>
<p><strong>GitHub</strong> is a tool that works well with git. With GitHub, we can collaborate in teams in a project. Simply, GitHub is a website or a cloud platform that helps us to host Git repositories.</p>
<hr />
<h2 id="heading-some-common-git-terminologies">Some common Git Terminologies</h2>
<p><strong>Repository</strong> is the most commonly referred term in Git. It simply means a project directory.</p>
<p><strong>Commit</strong> is another term that is used while using Git. When we hit <code>ctrl + s</code> or <code>cmd + s</code>(on Mac), the file gets saved to the file system. But if we commit the code, it gets saved to the git history.</p>
<p><strong>Push</strong> simply refers to uploading the current local changes to the server (i.e. GitHub in our case).</p>
<p><strong>Pull</strong> refers to downloading the changes that exist, from the cloud to our local machine.</p>
<p><strong>Clone</strong> means duplicating a repository that exists on the server to our local machine.</p>
<hr />
<h2 id="heading-some-git-commands">Some git commands</h2>
<h3 id="heading-initialize-an-empty-git-repository">Initialize an empty git repository</h3>
<p>To initliaze a git repository, navigate to your project directory and run the following command on your terminal or shell.</p>
<pre><code class="lang-shell">git init
</code></pre>
<h3 id="heading-stage-files-to-commit">Stage files to commit</h3>
<p>After making a change to project files, if we wish to commit the changes, we have to move the unstaged/untracked files to the staging area. To do so, we add the necessary files to commit.</p>
<pre><code class="lang-shell">git add &lt;filename&gt;
# OR to add all files at once
git add .
</code></pre>
<h3 id="heading-commit-the-changes">Commit the changes</h3>
<p>Commit allows us to register the changes into git history.</p>
<pre><code class="lang-shell">git commit -m 'commit message'
</code></pre>
<h3 id="heading-connecting-to-a-repository-that-exists-on-the-cloud">Connecting to a repository that exists on the cloud</h3>
<p>To connect our local repository with the repository that exists on the cloud, we have to use the following command.</p>
<pre><code class="lang-shell">git remote add origin &lt;link to the repository&gt;
</code></pre>
<h3 id="heading-pushing-changes-to-the-github-repository">Pushing changes to the GitHub repository</h3>
<p>If we want to push/upload the local changes into the cloud, we have to use the following command.</p>
<pre><code class="lang-shell">git push origin &lt;branch name&gt;
</code></pre>
<h3 id="heading-pulling-the-latest-changes-that-exist-on-the-cloud-to-a-local-machine">Pulling the latest changes that exist on the cloud to a local machine</h3>
<p>If we want to pull or download the changes that exist on the cloud, we have to pull it into our local machine.</p>
<pre><code class="lang-shell">git pull origin &lt;branch name&gt;
</code></pre>
<hr />
<h2 id="heading-branching">Branching</h2>
<p>Branching is one of the most important concepts in git. We generally create branches to isolate a feature from the rest of the code. For example, we might have a code running fine on a production environment. We might want to add a new feature. In this case, we cannot risk the code running in the production environment to stop working. This is when we create branches. We can then work on a new feature, complete the feature, test it and then merge with the code in production.</p>
<p>To switch branch that already exists in the repository,</p>
<pre><code class="lang-shell">git checkout &lt;branch name&gt;
</code></pre>
<p>If the branch doesn't exist yet,</p>
<pre><code class="lang-shell">git checkout -b &lt;branch name&gt;
</code></pre>
<h3 id="heading-view-the-list-of-the-branches">view the list of the branches</h3>
<pre><code class="lang-shell">git branch -a
</code></pre>
<h3 id="heading-merge-some-branch-with-the-current-branch">merge some branch with the current branch</h3>
<pre><code class="lang-shell">git merge &lt;branch name&gt;
</code></pre>
<p>for example, you're on master branch, you want to merge it with a branch called dev, you'd navigate to master branch and then do the following,</p>
<pre><code class="lang-shell">git merge dev
</code></pre>
<h3 id="heading-view-the-commits-history">view the commits history</h3>
<p>To see the commit history, use the following command</p>
<pre><code class="lang-shell">git log
</code></pre>
<p>To exit the log, press Q.</p>
<h3 id="heading-navigating-to-a-specific-commit">Navigating to a specific commit</h3>
<p>Sometimes we might have to refer to a commit if things break. To do so, we need a commit identifier. When we do <code>git log</code>, we get to see all the commits that we've made including an id like <code>e2123ndsadsadzoqm23</code>. To switch into a specific commit, we simply use the following command</p>
<pre><code class="lang-shell">git checkout &lt;commit id&gt;

# example
git checkout e2123ndsadsadzoqm23
</code></pre>
<h3 id="heading-reverting-changes-to-a-specific-commit">Reverting changes to a specific commit</h3>
<p>Sometimes we might have to revert our changes to a specific commit. To do so, we need a commit ID (explained above). To revert to specific commit, use the following command</p>
<pre><code class="lang-shell">git reset --hard &lt;commit id&gt;

# example
git reset --hard e2123ndsadsadzoqm23
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Thanks for reading this guide. I want to make it a series and in the next one, I'll be talking about collaboration with GitHub among teams. I additionally will also be covering about deploying our static websites using GitHub and netlify. If you don't want to miss those contents, subscribe to my newsletter by entering your email below.</p>
]]></content:encoded></item><item><title><![CDATA[Error handling while making AJAX requests in JavaScript]]></title><description><![CDATA[Error handling is vital while making AJAX requests in any tool. The solution I propose can be applicable for all kinds of frameworks or libraries. I am used to working with React.JS and in this blog, I talk about the approach I use handling errors th...]]></description><link>https://blogs.bigomega.dev/error-handling-while-making-ajax-requests-in-javascript</link><guid isPermaLink="true">https://blogs.bigomega.dev/error-handling-while-making-ajax-requests-in-javascript</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Tue, 21 Jan 2020 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>Error handling is vital while making AJAX requests in any tool. The solution I propose can be applicable for all kinds of frameworks or libraries. I am used to working with React.JS and in this blog, I talk about the approach I use handling errors that occur during AJAX requests.</p>
<p>There can be 3 kinds of situation where we might receive errors.</p>
<h3 id="heading-request-could-not-be-sent">Request could not be sent</h3>
<p>This kind of error might occur if there's no internet connection or the server is not running.</p>
<h3 id="heading-response-is-recieved-that-has-error-message-on-it">Response is recieved that has error message on it</h3>
<p>This kind of error might occur in the following scenarios.</p>
<p>We have a server that authenticates the users. We send username and password to the server and the password is incorrect. In this case, we have sent the data, the server has recieved the data but the information we're sending with the request is invalid.</p>
<p>This is the easiest way to handle error because we on the front end (or the side to send request), don't have to think what might have gone wrong. If the API is built considering the errors, it will respond with proper error message.</p>
<p>Axios automatically throws errors that lie out of the range <em>2xx</em> and the kinds of error I have mentioned above returns a status code that falls out this range.</p>
<h3 id="heading-some-other-internal-error-has-occured">Some other internal error has occured</h3>
<p>I have never faced error of this kind while building application but there might be something that might go wrong. We don't know what it is but there might be something. In this case, we could consider handling these kinds of errors.</p>
<p>Below, I define a function that makes an AJAX request to a dummy API and handle the errors I've mentioned above.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> makeRequest = <span class="hljs-keyword">async</span> () =&gt; {
    <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> axios.get(<span class="hljs-string">"https://somedummyapi.com"</span>)
        <span class="hljs-keyword">return</span> response
    } <span class="hljs-keyword">catch</span> (error) {
        <span class="hljs-keyword">if</span> (error.request) {
            <span class="hljs-comment">// Maybe we don't have internet connection</span>
            <span class="hljs-comment">// or our server has stopped</span>
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Could not connect to the server"</span>)
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (error.response) {
            <span class="hljs-comment">// Server received a request</span>
            <span class="hljs-comment">// and responded with a status code</span>
            <span class="hljs-comment">// that falls out of the range 2xx.</span>
            <span class="hljs-built_in">console</span>.log(error.response.data)
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">// something happened while making the request</span>
            <span class="hljs-comment">// that we're not really aware of</span>
            <span class="hljs-built_in">console</span>.log(error)
        }
    }
}
</code></pre>
<p>These are the most common types of error I try to handle while building JavaScript Apps with React and I think you should too. 😄</p>
]]></content:encoded></item><item><title><![CDATA[A minor error we make while creating a React's state]]></title><description><![CDATA[A state in react doesn't have a type. A counter can hold a value of a number at an instance and it can be changed into something else like a string in another instance. Doing this causes no errors and there isn't one either.
Though this doesn't raise...]]></description><link>https://blogs.bigomega.dev/a-minor-error-we-make-while-creating-a-reacts-state</link><guid isPermaLink="true">https://blogs.bigomega.dev/a-minor-error-we-make-while-creating-a-reacts-state</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Sat, 28 Dec 2019 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>A state in react doesn't have a type. A counter can hold a value of a number at an instance and it can be changed into something else like a string in another instance. Doing this causes no errors and there isn't one either.</p>
<p>Though this doesn't raise an error, an error might arise later unintentionally. Once I was building an app that made an API request to a server and the API returned an array of items. I looped over the array of objects using the map method that exists in the Array prototype. I had initially assigned the state for items object to be a string.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [items, setItem] = useState(<span class="hljs-string">""</span>)

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-comment">/*
     * Make an API call
     * Set the new state to be the response from API call
     */</span>
  }, [])

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        {items.map(item =&gt; (
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>{item.name}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        ))}
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}
</code></pre>
<p>For simplicity, I have created a dummy data that I might get as a response from an API. In order to simulate the feel of a real API responding to an AJAX request, I have created a setTimeout that resolves after 3 seconds.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">const</span> dummyData = [
  {
    <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>,
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Smith"</span>,
  },
  {
    <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>,
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Dan"</span>,
  },
  {
    <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>,
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Prashant"</span>,
  },
]

useEffect(<span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> setItems(dummyData), <span class="hljs-number">3000</span>)
}, [])
</code></pre>
<p>On the surface, this code looks normal but it's not. The problem lies here</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> [items, setItem] = useState(<span class="hljs-string">""</span>)
</code></pre>
<p>I have initially assigned items to be an empty string. Now if we see the return statement, I have mapped over items (which I expect to be an array). The value of items is an array only after the network request is resolved and the items is set to the new value we get from the API.</p>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> (
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      {items.map(item =&gt; (
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>{item.name}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      ))}
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
)
</code></pre>
<p>Initially when <code>items = ''</code>, <code>items.map</code> fails to execute because map method doesn't exist on a string.</p>
<blockquote>
<p>You should always declare/initialize your state carefully. If you know the response you're going to get from an API request then assign it to be the type you're going to get.</p>
</blockquote>
<p>So you could do something like this</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> [items, setItem] = useState([])
</code></pre>
<p>Just a minor change from <code>''</code> to <code>[]</code> would save me hours of random google searches and scratching my head.</p>
<p>I hope you like the blog. If it was worth your time then please consider subscribing to not miss future updates.</p>
]]></content:encoded></item><item><title><![CDATA[Organizing and Speaking at a tech conference]]></title><description><![CDATA[On October 19th 2019, I was supposed to give a talk on Building and Deploying Node.JS apps with Azure. Unfortunately, things took a turn and I had to slightly modify the scope of my session and diverge a little from the originally planned content. Th...]]></description><link>https://blogs.bigomega.dev/organizing-and-speaking-at-a-tech-conference</link><guid isPermaLink="true">https://blogs.bigomega.dev/organizing-and-speaking-at-a-tech-conference</guid><category><![CDATA[events]]></category><category><![CDATA[tech communities]]></category><category><![CDATA[community]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Wed, 23 Oct 2019 00:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1704818918967/f47d4e8e-e1df-4061-b190-7c124ad82dad.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>On October 19th 2019, I was supposed to give a talk on <strong>Building and Deploying Node.JS apps with Azure</strong>. Unfortunately, things took a turn and I had to slightly modify the scope of my session and diverge a little from the originally planned content. This was due to the lack of internet connectivity, the time frame of the session and whether the participants would grasp all the information we provided.</p>
<p><img src="https://github.com/prashantacharya/bigomega/blob/master/contents/tech-conference/images/presentation.JPG?raw=true" alt="presentation.JPG" /></p>
<h2 id="heading-about-the-conference">About the Conference</h2>
<p>The event we organized was <strong>STUDENT DEVELOPER DAY</strong> and 4 of us were organizers. <a target="_blank" href="https://twitter.com/diwastha">Diwash Shrestha</a>, <a target="_blank" href="https://twitter.com/bjungbogati">Binod Jung Bogati</a> and <a target="_blank" href="https://twitter.com/Ddr_Shrez">Yunip Shrestha</a> were the other 3 members of the organizing team. The content for the event was provided by Major League Hacking.</p>
<h2 id="heading-what-does-it-feel-like-to-organize-and-speak-at-a-conference">What does it feel like to organize and speak at a conference?</h2>
<p>As an organizer, I mainly took on the responsibility of designing the banners and social media posts. Additionally, due to my network, I was able to negotiate and find a sponsor for the event.</p>
<p>Whenever I try to do something, I always think about the impact it might have. In terms of impact, this event was a huge success because I was able to teach what I know to about 30-40 people. Also, due to the feedback I got on the days that followed the event, I am overwhelmed by the appreciation of the people.</p>
<p>We were able to give something to the tech community of Nepal from the session and we aim to organize more events in the future.</p>
<p><img src="https://github.com/prashantacharya/bigomega/blob/master/contents/tech-conference/images/teaching.JPG?raw=true" alt="teaching.JPG" /></p>
<h2 id="heading-the-networking-part">The Networking Part</h2>
<p>Whenever you organize or attend events, you're likely to meet new people. This event was not an exception. I got to meet with someone who has been programming since 1983, which was long before I was even born. Events also let you market yourself and your skills in the community. I believe it will also get me some more reach in the blogs I write. 🤞🏻</p>
<p><img src="https://github.com/prashantacharya/bigomega/blob/master/contents/tech-conference/images/award.JPG?raw=true" alt="award.JPG" /></p>
<h2 id="heading-learning-from-the-failures">Learning from the failures</h2>
<p>Whenever you organize events, you want it to go smoothly and be right in all aspects but the possibility of the event going right as expected is thin. You might ask why. Here are the reasons why.</p>
<ul>
<li><p><strong>Nepali Time</strong> is the synonym for <strong>unpunctuality</strong> in Nepal.</p>
</li>
<li><p>People might not care about events. I invited more than 15 people I know in the events but only 3 of them were present.</p>
</li>
<li><p>Getting the target audience is also tough most of the time because the content might be too basic for one group of audiences and too tough for the other.</p>
</li>
<li><p>The internet in Nepali colleges is so bad. I don't understand the purpose of internet service in colleges because it's so difficult to get connectivity.</p>
</li>
</ul>
<p>You have to be prepared to tackle these things during events. You can solve some of them.</p>
<p>To solve the unpunctuality problem, you can host an event at 11 AM and tell students that the event is going to start at 9. This might solve the issue. 😉</p>
<p>Don't expect your friends to attend the events because they will not. The people close to you will have the least amount of appreciation for things that you're trying to do.</p>
<p>To solve the issue with the target audience, try to be in the middle ground. Also, you can study the target audience before the event and deliver content accordingly.</p>
<h2 id="heading-next-events">Next events</h2>
<p>Sometime during November, the team that organized Student Developer Day is planning to do another event. Stay tuned to this blog and my social media to get notified of the announcement.</p>
]]></content:encoded></item><item><title><![CDATA[How to use .env in a React app using Create React App?]]></title><description><![CDATA[When you have a project that uses API keys or any other private keys, and want to push it on GitHub, you might probably want to hide those details from any other people who see the code. That's when you have store the API key as environment variable ...]]></description><link>https://blogs.bigomega.dev/cra-env</link><guid isPermaLink="true">https://blogs.bigomega.dev/cra-env</guid><category><![CDATA[React]]></category><category><![CDATA[create-react-app]]></category><category><![CDATA[Environment variables]]></category><category><![CDATA[secretmanager]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Sun, 20 Oct 2019 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>When you have a project that uses API keys or any other private keys, and want to push it on GitHub, you might probably want to hide those details from any other people who see the code. That's when you have store the API key as environment variable on a <code>.env</code> file and add it on a <code>.gitignore</code> file on the root of the project. Lucky for you all, <code>create-react-app</code> is already configured with git and adds all the list of files and folders that should not be pushed onto GitHub or anything similar like gitlab or bitbucket.</p>
<h2 id="heading-what-is-create-react-app">What is create-react-app?</h2>
<p><code>create-react-app</code> is a tool created by facebook to create applications with <strong>React.JS</strong>. It creates all the necessary build setup with no manual configuration required. To initialize a react app using <code>create-react-app</code> go to your terminal and type the following:</p>
<pre><code class="lang-shell">$ npx create-react-app hiding-env
</code></pre>
<p>This gives you the bare minimum setup required to start building React applications.</p>
<p>If you want to learn about environment variables then check out <a href="https://www.youtube.com/watch?v=ADh_OFBfdEE" target="_blank">this</a> video by Jacob Sorber who is a computer scientist and a professor.</p>
<p>Coming back to our react app, the folder structure now must look like this</p>
<pre><code><span class="hljs-operator">-</span> hiding<span class="hljs-operator">-</span>env
    <span class="hljs-operator">-</span> .git
    <span class="hljs-operator">-</span> node_modules
    <span class="hljs-operator">-</span> <span class="hljs-keyword">public</span>
    <span class="hljs-operator">-</span> src
    package.json
    .gitignore
</code></pre><p>So now, create an <code>.env</code> file on the root of your project.
<code>create-react-app</code> comes with all the necessary configurations to use environment variables in our applications so there's no setup required.</p>
<p>Open the <code>.env</code> file and create an environment variable. The environment variable must be prefixed with <code>REACT_APP</code> so any variable you name must be like <code>REACT_APP_MY_KEY</code>. It is something enforced by create-react-app. You can read the docs <a href="https://create-react-app.dev/docs/adding-custom-environment-variables/" target="blank"> here</a>.</p>
<p>Open <code>.env</code> variable and add the following key. It means nothing and just for the test purpose.</p>
<pre><code class="lang-bash">REACT_APP_API_KEY=123jkawqo-123@3
</code></pre>
<p>Go to the <code>app.js</code> file inside <code>src</code> and add the following code inside the <strong>App component</strong>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> key = process.env.REACT_APP_API_KEY
<span class="hljs-built_in">console</span>.log(key)
</code></pre>
<p>If you run the development server for the app and check the console you will then see the key being printed on the console of your browser.</p>
<h3 id="heading-changing-the-variable-depending-on-environment">Changing the variable depending on environment</h3>
<p>There might be a case when you have to hit to a particular endpoint while you are in a development environment and a different endpoint while you are in a production environment. <code>process.env.NODE_ENV</code> gives us the information about the environment the app is currently running on. So in order to do that we can do something like the following.</p>
<p>First add the URL to the development and production server in env file</p>
<pre><code class="lang-bash">REACT_APP_DEV_SERVER=localhost:3000/api/some_api
REACT_APP_PROD_SERVER=https://bigomega.dev/api/some_api
</code></pre>
<p>Then, check the environment you're on with the following code.</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span>(process.env.NODE_ENV == <span class="hljs-string">'development'</span>) {
    <span class="hljs-comment">// do something</span>
} <span class="hljs-keyword">else</span> {
    <span class="hljs-comment">// do some other things</span>
}
</code></pre>
<p>What we want to do is create a url variable that points to either development server or the production server so for that, we can do</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span>(process.env.NODE_ENV == <span class="hljs-string">'development'</span>) {
    <span class="hljs-keyword">const</span> url = process.env.REACT_APP_DEV_SERVER
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">const</span> url = process.env.REACT_APP_PROD_SERVER
}
</code></pre>
<p>You can refactor the code inside the App component or any other component as follows:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> { NODE_ENV, 
             REACT_APP_DEV_SERVER, 
             REACT_APP_PROD_SERVER, 
             REACT_APP_API_KEY } = process.env

    <span class="hljs-keyword">const</span> url = 
          NODE_ENV == <span class="hljs-string">"development"</span> ? REACT_APP_DEV_SERVER : REACT_APP_PROD_SERVER

      <span class="hljs-keyword">const</span> key = REACT_APP_API_KEY
      <span class="hljs-built_in">console</span>.log(key, url);

      <span class="hljs-built_in">console</span>.log(process.env.NODE_ENV)

      <span class="hljs-keyword">return</span>(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>Hi<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>)
}
</code></pre>
<p>Check the above example and explore the code yourself at <a href="https://codesandbox.io/s/hiding-env-g8r44" target="blank">this link</a>.</p>
<p>You can optionally create a context or use redux to store these keys on a global state so that you do not have to check for environment and set URL on every file you encounter.</p>
<p>Thanks for reading.</p>
]]></content:encoded></item><item><title><![CDATA[Minor Updates: Data Structures Tutorial Series & Email Subscription]]></title><description><![CDATA[If you see the history of this blog then you can see I have been totally inconsistent about the contents I share on the website. Therefore I am not sure about how to make new promises or commitments about the contents I plan to share ahead. I would s...]]></description><link>https://blogs.bigomega.dev/minor-updates-data-structures-tutorial-series-and-email-subscription</link><guid isPermaLink="true">https://blogs.bigomega.dev/minor-updates-data-structures-tutorial-series-and-email-subscription</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Wed, 16 Oct 2019 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>If you see the history of this blog then you can see I have been totally inconsistent about the contents I share on the website. Therefore I am not sure about how to make new promises or commitments about the contents I plan to share ahead. I would still try to make a promise one more time. 😉 Also, I would like to give minor updates on what's happening in my life, the contents of the blog and the contents I am preparing for the future. Let's start with the obvious one first.</p>
<h3 id="heading-subscription-feature">Subscription feature 📧</h3>
<p>If you like my content then you have the option to subscribe to my newsletter by scrolling down to the bottom of the page and entering your email. You'll have to check your email and confirm subscription. After that, whenever I add new content, I will notify you through email. That way you'll never have to miss on the contents I share on the website.</p>
<h3 id="heading-data-structures-repository">Data Structures Repository</h3>
<p>With my friend and a colleague who is an android developer, I have started a repository to upload programs of various data structures. To upload the content I would be referring to various online resources. I have also got a book named Data Structures using C and C++ from my college library by the authors Yedidyah Langsam, Moshe J. Augenstein, Aaron M. Tenenbaum. So I will also refer to the book a lot for the explanation of the contents.</p>
<p> Though the book is in C and C++, I will be writing the codes in JavaScript and Python and my friend will be writing the codes in Kotlin. I have other works too so I am not sure how frequently I will be contributing to the repository but I will try my best to write proper documentation and proper codes every weekend and update the repository.</p>
<p><a href="https://github.com/Prashant-Acharya/Data-Structures-and-Algorithm" target="blank">Link to the repository</a>. Go ahead, check the repository, show some love. Star the repo, fork the repo and please contribute on this open source project. 😉</p>
<p><img src="images/repo.png" alt="Data Structure and Algorithm Repo" /></p>
<h3 id="heading-data-structures-course">Data Structures Course 📚</h3>
<p>Warning! No promises. I am thinking about making videos on youtube and other social media platforms for BigOmega.  I want to create a video series on Data Structures.</p>
<p>Now this is a promise, even if I don't do the videos, I will definitely write about Data Structures on the blog. If you don't wanna miss out, go ahead and subscribe. </p>
<h2 id="heading-some-personal-stuffs">Some personal stuffs 👦</h2>
<p>In a personal blog, I guess I am allowed to talk about or share about myself. 😁</p>
<h3 id="heading-internship">Internship ⚛</h3>
<p>I have been doing internship for a few months now and I am working on the front end of a project. I am working with React and exploring a lot more about the react ecosystem so maybe in the future, a lot of content on react will be uploaded on the blog. </p>
<h3 id="heading-expanding-bigomega">Expanding BigOmega</h3>
<p>My intention has always been expanding BigOmega to not just a blog and to much more. I want to upload pictures and videos on the pages/accounts on various social media that I want to create for BigOmega. I will create accounts on Instagram and YouTube. I have already created a facebook page and a twitter account. I will share the twitter handle and other plans later because there's nothing really for you guys to follow me there because there are no contents.</p>
<h3 id="heading-hosting-a-mlh-workshop-on-student-developer-day">Hosting a MLH workshop on Student Developer Day</h3>
<p>On October 19th, I will be hosting a workshop on <strong>Building and Deploying Node JS apps with Microsoft Azure</strong>. Interested people can come to Asian College Of Higher Studies at 9:00 AM in the morning to attend the session. There will be 3 other awesome instructors teaching other stuffs. You can attend all 4 workshops if you want to and guess what? The event is totally free and we're also going to provide you a great lunch. 😉</p>
<p><img src="image/../images/Prashant Acharya.jpg" alt="Student Developer Day" /></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>So that is all for this blog. If you want to stay tuned for the contents that I plan to share in the future as mentioned above then please subscribe to the newsletter by dropping your email below. I am super excited for what's coming next.</p>
]]></content:encoded></item><item><title><![CDATA[How much JavaScript is necessary to learn React?]]></title><description><![CDATA[A framework or library is just a set of tools that are created to solve a recurring problem more efficiently. Hence, there’s nothing that vanilla JS can’t solve which can be solved by using a framework like React, Angular or Vue. Most of the people j...]]></description><link>https://blogs.bigomega.dev/how-much-javascript-is-necessary-to-learn-react-88d4e9d278ba</link><guid isPermaLink="true">https://blogs.bigomega.dev/how-much-javascript-is-necessary-to-learn-react-88d4e9d278ba</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Wed, 02 Oct 2019 11:30:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234447604/I3CYoxdKy.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A framework or library is just a set of tools that are created to solve a recurring problem more efficiently. Hence, there’s nothing that vanilla JS can’t solve which can be solved by using a framework like React, Angular or Vue. Most of the people jump into learning frameworks before learning enough JavaScript. It is not totally wrong but there’s just one problem. If one doesn’t have enough experience learning core JavaScript, he doesn’t know the benefits the particular framework/library provides nor the problem it tries to solve. So developers/programmers need to have a clear idea about what the framework is trying to provide and what is available in the language itself. Also, it is always a good thing to know what problems might have arisen if we had tried to solve the same problem with the basic language itself.</p>
<p>React JS</p>
<p>In this article, I will try to list out some of the core concepts that are necessary for learning a JavaScript library such as React.</p>
<h4 id="heading-object-oriented-programming-and-es6-class-keyword">Object-oriented programming and ES6 class keyword</h4>
<p>Object-oriented programming principles play a vital role in react. Prior to React 16.08, all stateful components in React were created using class-based components and functional components were called stateless functional components. The newer addition of hooks allows us to create a state on functional components, but as it is a new feature added in the library, it might take time for adoption of this feature. Therefore it is important for the learners to learn about Object-oriented programming and the class keyword added in 2015 in the language. It is also necessary for people to know about prototypal inheritance, constructor functions and many more concepts such as inheritance and composition.</p>
<p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes">Read the docs here</a></p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%28171%2C%20184%2C%20195%2C%201%29&amp;t=one-dark&amp;wt=none&amp;l=javascript&amp;ds=true&amp;dsyoff=27px&amp;dsblur=27px&amp;wc=true&amp;wa=true&amp;pv=90px&amp;ph=56px&amp;ln=false&amp;fl=1&amp;fm=dm&amp;fs=14.5px&amp;lh=116%25&amp;si=false&amp;es=1x&amp;wm=false&amp;code=class%2520Person%2520%257B%250A%2509constructor%28name%252C%2520age%29%257B%250A%2509%2509this.name%2520%253D%2520name%250A%2509%2509this.age%2520%253D%2520age%250A%2509%257D%250A%257D%250A%250Aclass%2520Student%2520extends%2520Person%2520%257B%250A%2509constructor%28name%252C%2520age%252C%2520major%29%257B%250A%2509%2509super%28name%252C%2520age%29%250A%2509%2509this.major%2520%253D%2520major%250A%2509%257D%250A%250A%2509showInfo%28%29%257B%250A%2509%2509console.log%28%2560%2524%257Bthis.name%257D%2520is%2520%2524%257Bthis.age%257D%2520and%2520studies%2520%2524%257Bthis.major%257D.%2560%29%250A%2509%257D%250A%257D%250A%250Alet%2520s1%2520%253D%2520new%2520Student%28%27Prashant%27%252C%252021%252C%2520%27Computer%2520Science%27%29%250As1.showInfo%28%29" width="700" height="328"></iframe>

<p>Code like this shouldn’t get you banging head trying to understand what each line means</p>
<h4 id="heading-all-sorts-of-different-methods-available">All sorts of different methods available</h4>
<p>You should also be able to use different kinds of default methods available for data types like strings and arrays. You’ll have to sort, filter, map through a list of items more often than you imagine while building these kinds of applications. Therefore I recommend you learning at least some of the methods available on JavaScript.</p>
<p>The ones that I recommend are map, filter, reduce, sort, include etc for arrays, split, join, reverse etc for strings. You’ll explore more as you learn more stuff in react.</p>
<p><a target="_blank" href="https://javascript.info/array-methods">Read the docs here</a></p>
<h4 id="heading-promises-callbacks-and-asynchronous-javascript">Promises, callbacks and asynchronous JavaScript</h4>
<p>Asynchronous JavaScript is super important in Single Page Applications. You have to make network calls asynchronously and for that, the knowledge of asynchronous JS and the ways to handle AJAX requests becomes a necessity.</p>
<p>Promises provide a way to handle asynchronous code. Callbacks can do that too but Promises make the code a lot cleaner.</p>
<p><a target="_blank" href="https://javascript.info/async">Read the docs here</a></p>
<h4 id="heading-async-await">Async Await</h4>
<p>Async-await provides a simpler way to interact with promises. They make asynchronous code look synchronous and yet, the working is still asynchronous.</p>
<p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">Read the docs here</a></p>
<h4 id="heading-modules-import-export-babel">Modules, import, export, babel</h4>
<p>When working with React, you isolate your components on separate files. You export some component from a file and import in the another.</p>
<p>Facebook provides a tool called <code>create-react-app</code> that helps users to initialize a react project in a convenient fashion.</p>
<p><code>create-react-app</code> comes with all these settings and configurations pre-built so you don’t have to do these manually but it is super important for you to understand how these things are happening behind the scenes.</p>
<p><strong>Babel</strong> is a tool that compiles modern JavaScript to JavaScript version supported by all popular browsers. You can also explore how those work and try experimenting what the code you’re used to writing compiles to in the older versions.</p>
<p><a target="_blank" href="https://javascript.info/modules">Read the docs here</a></p>
<p>The above list explained the concepts that you must be familiar before jumping to react. There’s one other thing that I would like to recommend and it is to build projects using Vanilla JS. To appreciate the full beauty of React or other frameworks, you should try building a project without using a framework or a library. That will help you to know and understand the complexity without the existence of that particular library.</p>
<p>A “to-do list” is kind of a standard and in my opinion, it is the project you should do too. A “to-do list” application should contain a form to add to-dos. There should also exist a button to delete the particular to-do and also mark them if they are completed or not.</p>
<p>Implementation of to-do with these features would be enough for you to understand how react works and the important concepts such as states, components, lifecycle, state change etc.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Thank you for reading the article. If you like it and want to read more of my blogs you can check my website <a target="_blank" href="https://bigomega.dev">https://bigomega.dev</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Recursion]]></title><description><![CDATA[Most of the people find recursion difficult but it's not. Students find difficulty in learning it because of the examples that teachers and online tutorials aim to provide. So in this blog, we are going to talk about recursion with a very basic examp...]]></description><link>https://blogs.bigomega.dev/recursion</link><guid isPermaLink="true">https://blogs.bigomega.dev/recursion</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Wed, 04 Sep 2019 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>Most of the people find recursion difficult but it's not. Students find difficulty in learning it because of the examples that teachers and online tutorials aim to provide. So in this blog, we are going to talk about recursion with a very basic example of recursion using JavaScript. Recursion is a concept so it is language independent. If you know how to define and call a function in a language that you are using then you can pretty much go along and understand everything that I want to cover in the blog.</p>
<blockquote>
<p>Simply, recursion is a concept in which a function calls itself again and again until some condition is met. A function that uses this practice and calls itself is called a recursive function. In recursion, the function calls itself with the smaller instance of itself.</p>
</blockquote>
<p>We are going to create a function that takes in a number as an argument and makes a count down from it. For example: <strong>countDownFrom(3) will print 3 2 1 on the screen.</strong></p>
<p>Open your web developer console on your browser by opening a browser and pressing <code>ctrl + shift + j</code> and write a bare minimum function to get started with.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">countDownFrom</span>(<span class="hljs-params">n</span>) </span>{}
</code></pre>
<p>The first thing that we want to do when the function start executing is to print whatever there is in n. In code, that would look something like this</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">countDownFrom</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-built_in">console</span>.log(n) <span class="hljs-comment">// highlight-line</span>
}
</code></pre>
<h2 id="heading-the-two-cases-in-a-recursive-function">The two cases in a recursive function</h2>
<p>So as I said, recursive function calls itself until some condition is met. They are <strong>base case</strong> and <strong>recursive case</strong>.</p>
<h3 id="heading-base-case">Base Case</h3>
<p>The base case is the case when the function stops calling itself and returns some value which stops its recurring operation. For example, in the case of a countdown, when the value of the counter is set to 1, it must exit the function. To do that we can simply return without returning anything i.e. null/undefined.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">countDownFrom</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-built_in">console</span>.log(n)

  <span class="hljs-comment">// highlight-start</span>
  <span class="hljs-keyword">if</span> (n == <span class="hljs-number">1</span>) <span class="hljs-keyword">return</span>
  <span class="hljs-comment">// highlight-end</span>
}
</code></pre>
<h3 id="heading-recursive-case">Recursive case</h3>
<p>The recursive case is the case in which the function keeps calling itself until the base case is arrived. So in the case of a countdown, if the countdown starts from 5, the function calls itself when the value of counter variable(denoted by n in our case) is 5, 4, 3 and 2 but as soon as the value is 1, it returns. Easy? Let's write that in code.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">countDownFrom</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-built_in">console</span>.log(n)

  <span class="hljs-keyword">if</span> (n == <span class="hljs-number">1</span>) <span class="hljs-keyword">return</span>
  <span class="hljs-comment">// highlight-start</span>
  <span class="hljs-comment">// reduce the value of n by 1</span>
  <span class="hljs-comment">// and call the function again</span>
  <span class="hljs-comment">// with the new value of n</span>
  <span class="hljs-keyword">else</span> countDownFrom(--n)
  <span class="hljs-comment">// highlight-end</span>
}

<span class="hljs-comment">// calling the function here.</span>
countDownFrom(<span class="hljs-number">3</span>)
</code></pre>
<p>The function call at the else statement simply decreases the value of n and calls the function itself as explained in the comments in the code block.</p>
<p>The image below explains what's going on.</p>
<p><img src="images/Recursion.png" alt="Recursion" /></p>
<h2 id="heading-refactoring">Refactoring</h2>
<p>If you look at the code the else statement is absolutely unnecessary because if the value of n is 1 it returns and if it's not the code below executes. So, if it's not one it will execute the codes below. So, we can refactor it as</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">countDownFrom</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-built_in">console</span>.log(n)

  <span class="hljs-keyword">if</span> (n == <span class="hljs-number">1</span>) <span class="hljs-keyword">return</span>

  countDownFrom(--n)
}

countDownFrom(<span class="hljs-number">5</span>)
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Thank you for reading the blog. Feature to subscribe on the mailing list will be coming soon so till then you can follow me on social media to get updates on the new blogs.</p>
]]></content:encoded></item><item><title><![CDATA[Techniques For Learning a New Technology Or a New Tool]]></title><description><![CDATA[In the field of technology, there is always so much to learn and explore. Most of us get overwhelmed by the number of technologies that we want to or need to learn. We all have been in a situation where we have learnt a technology or a tool but only ...]]></description><link>https://blogs.bigomega.dev/techniques-for-learning-a-new-technology-or-a-new-tool</link><guid isPermaLink="true">https://blogs.bigomega.dev/techniques-for-learning-a-new-technology-or-a-new-tool</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Tue, 27 Aug 2019 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>In the field of technology, there is always so much to learn and explore. Most of us get overwhelmed by the number of technologies that we want to or need to learn. We all have been in a situation where we have learnt a technology or a tool but only that tool might not be enough to create a project that we want to complete. There might not be the necessity to learn but still, we push ourselves to learn new technology or more technologies that we have not used before due to the fear that something else might be the next big thing and you might have to switch in a rush. We also learn new technology or tool to become problem solvers, not just a trained professional who specializes in using a particular tool. So, what approach to take while learning a new tool or technology? I am going to say a few techniques that I have tried. I am also going to say if it is appropriate or not. I hope it helps you.</p>
<p><img src="images/js-technologies.jpeg" alt="Technologies" /></p>
<blockquote>
<p>Note: Tools and technologies in this blog refer to languages, libraries or frameworks in this blog.</p>
</blockquote>
<h2 id="heading-watching-tutorials">Watching tutorials</h2>
<p>If you have been in a situation where you watch a tutorial then the next and then the next till you realize that you have reached tutorial hell then raise your hands. This is the problem with watching tutorial videos. You get addicted to them and when you have to try something on your own, you don't be able to because you're not trained to that mindset. I have been in similar situations and I know how frustrating that gets overtime. Nowadays, I am trying to move away from the tutorials and I don't mean I avoid them completely. I take a slightly different approach than what I have done up to the moment. So the way I make use of tutorials is to watch crash courses on youtube and jumping on a personal pet project instead of a full 20+ hours of project-based tutorial learning. I also watch videos on advanced topics on some tool. I like videos from the youtube channel named <a href="https://www.youtube.com/channel/UCO1cgjhGzsSYb1rsB4bFe4Q" target="_blank">funfunfunction</a>. He doesn't create a tutorial but talks about concepts on JS mostly. </p>
<h2 id="heading-official-documentation">Official Documentation</h2>
<p>People and organization that create a tool want more people to use that tool. In order to do that, they have to create great documentation which everyone can understand so that more people try to adopt the technology. I want to admit it shamelessly that this approach has mostly failed me. 
However, there is a slightly different approach that has worked quite well. In almost every documentation, there is a section with tutorials that walks you through all the necessary concepts of that technology. This approach is quite nice as you will have a project to build along with learning that particular technology.</p>
<p>![ReactJS](images/react-js.png 'React JS')</p>
<h2 id="heading-interactive-tutorialsresources">Interactive Tutorials/Resources</h2>
<p>This includes site like <a href="https://freecodecamp.org" target="_blank">FreeCodeCamp</a> or <a href="https://www.codecademy.com/" target="_blank">Codecademy</a> etc. These sites give you resources to read on the side of the screen followed by a challenge to solve as you go through the resources to learn the technology. This is quite an awesome way to learn and in fact, I seriously started learning programming with JavaScript through FreeCodeCamp. This approach not just gives you the content but a challenge to solve as soon as you complete the content to study. This improves you to think differently and your mindset will not be fixed to tutorials only. A lot of times I have seen people who go through the tutorial and complete it but when asked to solve a problem out of the tutorial, they struggle. So it is really important to not just follow the tutorial but also to develop a problem-solving mindset and I think Interactive tutorials do just that.</p>
<p>![FreeCodeCamp](images/freecodecamp.png 'FreeCodeCamp')</p>
<h2 id="heading-building-projects">Building Projects</h2>
<p>I have enrolled in an internship and there I was able to learn quite a lot with this approach to learn new technology. So this approach starts with a project in mind. You think of a project or a problem and then understand the application's requirement then you approach the application, feature by feature. You learn a lot with this approach but I would not really recommend it to you unless you have a mentor who could help you while you do so.</p>
<p>If you learn with this approach then you'll learn what feature of a language/library/framework you must specialize on. You will have a project to complete and show it to people. It also helps you build your portfolio. So, if you have a mentor, this is the best approach one can take to learn new technology.</p>
<p>I will cover more on this topic on my next blog. It will be dedicated blog for this approach.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In a world where everything is changing and new things coming every single time, it is really difficult to keep up with our knowledge and expertise. We must adapt to be familiar with new technologies all the time. There is no other way around it so we must get used to doing this all the time. It is also important to figure out what technique of learning helps you the best so that when the time comes, you can easily make the switch. In this blog, I tried to mention a few that have helped me to learn new technologies. I hope it helps you too. </p>
<p>Glad you stuck around for this long and I am really sorry for not being able to upload contents on this blog regularly. I am planning something with the site and some other things too and I hope to be more regular with the content I post on this blog.</p>
]]></content:encoded></item><item><title><![CDATA[The State Of Computer Science In Nepal]]></title><description><![CDATA[Computer Science is one of the most popular career path for students in this generation. Factors like the scope of it and the pay rate in the field excites many. The case is not different in Nepal and this has few problems. In this blog, I will try t...]]></description><link>https://blogs.bigomega.dev/the-state-of-computer-science-in-nepal</link><guid isPermaLink="true">https://blogs.bigomega.dev/the-state-of-computer-science-in-nepal</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Wed, 03 Jul 2019 00:00:00 GMT</pubDate><content:encoded><![CDATA[<p>Computer Science is one of the most popular career path for students in this generation. Factors like the scope of it and the pay rate in the field excites many. The case is not different in Nepal and this has few problems. In this blog, I will try to provide my opinion, the problems and not the statistics about Computer Science in the context of Nepal.</p>
<p>I study Computer Science and Information Technology at Sagarmatha College of Science and Technology which is affiliated to Tribhuvan University. At the time of writing, I am in the 4th semester. </p>
<h2 id="heading-computer-science">Computer Science</h2>
<p>According to Wikipedia, Computer Science is the study of processes that interact with data and that can be represented as data in the form of programs. It enables the use of algorithms to manipulate, store, and communicate digital information.</p>
<p>Now as we have at least known what Computer Science is, it's really important to solve the misconception about what Computer Science is not. I found a great article by the Boston Univeristy which talks about what is computer science what is it not and many more. You can read the article <a href="https://www.cs.bu.edu/AboutCS/WhatIsCS.pdf" target="_blank">here</a>. I am going to briefly write it here instead of copying everything. </p>
<blockquote>
<p>So according to the Boston University, Computer Science is not just about building computers or writing computer programs like astronomy about building telescopes, biology about building microscopes or music about building musical instruments. Computer Science is not about the tools we use to solve a Computer Science problem. It is about when to use the tool to solve a particular problem. Computer Science problems don't even require Computers considering the fact that these problems were solved even before computers were built. So, Computer Science is about building computers, writing computer programs and <em>so much more</em>....</p>
</blockquote>
<p><img src="./images/cs.png" alt="Computer Science" /></p>
<h2 id="heading-computer-science-in-nepal">Computer Science in Nepal</h2>
<p>Nepal is a small country with 10 Universities in the entire country which I didn't even knew before the time of writing. I knew 4 of them and they are Tribhuvan University, Kathmandu University, Pokhara University and Purwanchal University. My unawareness might be because of the quality of them and could also mean that I am not interested in the course they provide like Nepal Sanskrit University which probably teaches the sanskrit language which I am not sure of and it's not the concern right now. Let's move on to discuss about the most popular computer science course in Nepal. I am covering it specifically because this is the course that has the potential to fulfill the demand of IT in the context of Nepal.</p>
<p><strong>Tribhuvan University</strong> is the largest university of Nepal. It has affiliated colleges all over the country and hence the number of students enrolled in the univeristy is massive. In terms of no of student enrollment, TU is regarded as one of the top univerisities. I am aware of 4 courses TU provides in the field related to computers. They are Bachelor's of Science in Computer Science and Information Technology (B.Sc CSIT), Bachelor of Engineering in Computer (B.E. Computer), Bachelor of Arts in Computer Application (BCA), and Bachelor in Information Management (BIM). All these subjects deal with similar core subjects related to computers and differ in the additionals they provide like BIM, which deals with Computer and also the use of it in business. The focus of my blog would be about CSIT as it is their core Computer Science subject.</p>
<p><strong>B.Sc CSIT</strong> is a 4 year (8 Semester) course. There are more than 50 colleges affiliated to the Tribhuvan university that teaches CSIT in Nepal. <strong>CSIT is a research oriented course that focuses more on thoretical computations, design and analysis of algorithms, the internal workings of a computer etc and it keeps development/engineering of softwares and hardwares secondary.</strong> The subjects covered in this course are the Fundamentals of Computer Programming with C, Object Oriented Programming with C++, Physics, Calculus, Linear algebra, Statistics, Discrete Mathematics, Data Structures and Algorithms, Design and Analysis of Algorithms, Theory of Computations, Compilers, Operating Systems, Databases, Artificial Intelligence, Computer Networking and more. There are a lot of prospects and challenges in this particular course. The syllabus of the course is really good and upto the international standards but there are negative factors that outweighs the benifits.</p>
<h2 id="heading-the-problems-with-computer-science-in-nepal">The problems with Computer Science in Nepal</h2>
<p>The benefits of Computer Science in Nepal is not the same as it is in other countries. No one is sane here. Students, teachers, university, college and companies contribute in this equally and that frustrates me which can actually be considered as the point of this article to be honest.</p>
<h3 id="heading-csit-a-safe-landing">CSIT, A Safe Landing</h3>
<p>Go ahead and try to make an estimation about how many students who enroll in CSIT have enrolled in CSIT because they are really passionate about Computers and the Science revolves around it. Do the numbers frighten you? It does to me. Let me explain with context and the result.</p>
<p>Currently, there's a large population of students who choose to study CSIT if they don't get enough scores to qualify for the scolarship in MBBS, Nursing (and similar faculties) or Engineering entrance. I don't want to blame those students because the faculties like MBBS, Agriculture, Nursing etc have unaffordable fee strcuture for a middle class family from Nepal to even think it as a possibility. CSIT has been a place for the safest landing for this group of people because of job security and pay rate. I think Computer Science will never be a great field in Nepal until people stop treating it as a faculty to join when there's no other option left. However, I have also heard stories from people who had never even seen a computer but join computer science for their undergraduate degree and have reached in a successful position. Those people, in their position are not in that situation because of their past. There was a factor that determined their success and it is passion. They were able to bridge the void that existed between the knowledge they had and the knowledge they wanted to acquire. There is a possibility to have a fruitful career in Computer Science even as an alternative if you make it your passion after you join it.</p>
<blockquote>
<p>Like Computers, Success in computer science is determined by a binary and some exceptions. You're either passionate about it or you're not and the exception is you might simply get lucky and not everyone is lucky.</p>
</blockquote>
<p>Due to this reason, CSIT has been filled with students who are not passionate. How can someone excel in a field in which he doesn't feel passionate about?</p>
<h3 id="heading-colleges">Colleges</h3>
<p>The other problem CSIT faces is the colleges that teach CSIT teach you the syllabus not the essense of the course. Not all but most of the teachers are too lazy to even get them updated with latest available technologies. Don't you believe me? Ask your C++ teacher the current stable version of C++. You'll get the answer. 😉</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674233579249/kfZwfdLm2.gif" alt="No Idea" /></p>
<p>I don't mean to disrespect any teachers. I am trying to express the reality. I would also like to thank those teachers who are working really hard to teach computer science as more than syllabus and there are a lot of them too.</p>
<h3 id="heading-university-and-the-entire-country">University and the entire Country</h3>
<p>There is simply not enough resource available for computer science in Nepal. Suppose there's a student who wants to do research in the field of IoT in Nepal. Where does he get the support from and is there even a lab where he can continue his work?</p>
<p>This is too much to expect from the university. There is too much carelessness going on in the case of exams. Sometimes the question are out of syllabus. The checking of exam papers is so poor. There has been a case in which someone I know has got more scores than he attempted.</p>
<h3 id="heading-the-companies">The Companies</h3>
<p>The number of companies in Nepal who are willing to take a batch of interns and be willing to provide them industry level skills can be counted in fingers. There are companies in Nepal who make interns do client projects with no assistance and pay nothing when they are making money out of it. To be able to fit in this kind of market the only thing a student can try to do is teach himself the required skills to fit in the market.</p>
<h3 id="heading-situation-outside-the-kathmandu-valley">Situation outside the Kathmandu Valley</h3>
<p>In Nepal, everything is centralized inside the Kathmandu valley. The students outside of Kathmandu don't even have proper internet connection and enough lab facilites to complete their experiments specified in the syllabus. </p>
<p>I interacted with a teacher of mine who worked as the coordinator of a CSIT college outside of the Kathmandu valley and he says the students have to limit themselves with a lot of knowledge and exposure outside the valley. They don't even have teachers in the region to teach them skills outside of the syllabus so for internship they have to come to the capital for <strong>training, not internship</strong> in their final semester.</p>
<p>Students inside Kathmandu valley get to attend a lot of free workshops and technical seminars or meetups which is not possible outside the valley. Exposure in the community is really necessary in the case of the tech industry. In the regions outside the valley, students just have one option. It is to limit themselves to the course content which is not enough. </p>
<h2 id="heading-the-positives-about-cs-in-nepal">The Positives About CS in Nepal</h2>
<p>I don't want to discourage anyone by saying all the negatives about the course. There are positive aspects too. I would like to talk about them briefly because there are just few aspects I see as the possibilities. There are still great companies, colleges that teach students with the contents outside of the syllabus but the number of them are few and in the case of college, expensive too.</p>
<h3 id="heading-positives-in-csit">Positives in CSIT</h3>
<p>CSIT course is an affordable course with a lot of prospects. In the past, CSIT was really unmanaged but now it has better management. The course now has been updated to meet the world demands.</p>
<h3 id="heading-digital-revolution">Digital Revolution</h3>
<p>Nepal is going through a digital revolution. In the near future, there are going to be a lot of governmental and private jobs in the field of Computer Science in Nepal. There are a lot of possibilites and it's going to grow in the future.</p>
<h3 id="heading-unlimited-scope-outside-the-country">Unlimited scope outside the country</h3>
<p>The best thing about computer science is it is not centralized so you can really fit in anywhere in the world if you have skills. Programming language is same everywhere, data structures are not going to change &amp; the algorithms too.</p>
<h2 id="heading-my-suggestion">My Suggestion</h2>
<p>I might have said a lot of cons about the situation of CS in Nepal but there are things that I would like to suggest which would eventually help you in your career.</p>
<h3 id="heading-try-to-get-outside-of-the-syllabus">Try to get outside of the syllabus</h3>
<p>Tech industry is always changing and you need to update yourself with the latest and greatest available technology. It is mandatory which is why from your earlier semesters, you need to learn about latest and greatest available technology as you will be working on them later.</p>
<h3 id="heading-understand-the-value-of-a-particular-subject-and-how-things-work-internally">Understand the value of a particular subject and how things work internally</h3>
<p>Almost every student studying CS curses the course by arguing about the existance of some subject with no use in real life. This is where people are wrong. Every subject has some application which we are too lazy to search for. You need to know the unobvious application of something. Knowing the internal working of technologies will help you figure out your interest on a particular subject.</p>
<h3 id="heading-attend-events-and-try-to-organize-some">Attend events and try to organize some</h3>
<p>You will get to learn a lot from events and people you meet in the events. It will increase your exposure in the industry and will help you later in your career. Organizing events will teach you management skills which will make your profile stronger.</p>
<h3 id="heading-respect-teachers-andamp-try-to-interact-with-them">Respect teachers &amp; try to interact with them</h3>
<p>Sometimes, teachers have more to offer than what they seem in reality. So it's really important to raise questions to them and interact with them to get your confusion cleared.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>A lot of what I said above might be discouraging to people but that is how the reality looks like. I cannot avoid it even if I try to because the nation is moving towards a digital revolution and there is a huge requirement of qualified manpower in the nation and also outside of the nation. Financial stability is a must so choosing computer science for it is not wrong as well. But your passion determines success. Financial security is highly dependent on your willingness to take risk to dedicate time to learn and flourish your skills.</p>
]]></content:encoded></item><item><title><![CDATA[Using the useState hook]]></title><description><![CDATA[This article was originally published in https://bigomega.dev.
I tried react hooks and it's pretty awesome. With hooks, you can create functional components that can store state. It would not have been possible earlier. Hooks are a newer addition to ...]]></description><link>https://blogs.bigomega.dev/usestate</link><guid isPermaLink="true">https://blogs.bigomega.dev/usestate</guid><category><![CDATA[React]]></category><category><![CDATA[state]]></category><category><![CDATA[hooks]]></category><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Sat, 25 May 2019 12:58:19 GMT</pubDate><content:encoded><![CDATA[<p>This article was originally published in https://bigomega.dev.</p>
<p>I tried react hooks and it's pretty awesome. With hooks, you can create functional components that can <strong>store state</strong>. It would not have been possible earlier. Hooks are a newer addition to the react library. They are included in the react 16.8 stable release.</p>
<p>In this blog, we will explore hooks briefly by creating a simple counter app. To get started open your terminal and type the following commands &amp; open the project in the code editor of your choice.</p>
<pre><code class="lang-bash">$ npx create-react-app hooks-counter
$ <span class="hljs-built_in">cd</span> hooks-counter
$ npm start
</code></pre>
<p>Open <code>app.js</code> in the <code>/src</code> folder, delete everything inside the <code>&lt;div className='App'&gt;&lt;/div&gt;</code> &amp; the logo import.</p>
<p>The code should look like this at this point:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App
</code></pre>
<p>Let's also add bootstrap so that we don't have to bother about styling. Go to <code>public/index.html</code> and add the following link at the end of the head tag.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"</span>&gt;</span>
</code></pre>
<p>Now let's create a <strong>Counter</strong> component. Inside the <code>src</code> directory, create a file named <code>Counter.js</code> and copy the following code inside it.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">const</span> Counter = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> count = <span class="hljs-number">0</span>
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>A simple counter application using Hooks.<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn-group'</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>-<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>{count}<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>+ <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Counter
</code></pre>
<p>We are setting the count as 0 by hard coding the value. Now we will explore how to make it a state and act according.</p>
<p>Now let's import the <code>Counter</code> component in the <code>app.js</code> file and use it in the app component.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>
<span class="hljs-keyword">import</span> Counter <span class="hljs-keyword">from</span> <span class="hljs-string">'./Counter'</span> <span class="hljs-comment">// highlight-line</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
     // highlight-next-line
      <span class="hljs-tag">&lt;<span class="hljs-name">Counter</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App
</code></pre>
<p>In order to use the <code>useState</code> hook, we have to import it from react. To do that we can simply add the import in the first line of the <code>Counter.js</code> file.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span> <span class="hljs-comment">// highlight-line</span>

<span class="hljs-keyword">const</span> Counter = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> count = <span class="hljs-number">0</span>
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>A simple counter application using Hooks.<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn-group'</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>-<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>{count}<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>+ <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Counter
</code></pre>
<p>Now, let's use the <code>useState</code> to set the count value to 0.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">const</span> Counter = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-comment">// highlight-next-line</span>
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>)
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>A simple counter application using Hooks.<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn-group'</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>-<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>{count}<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>+ <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Counter
</code></pre>
<h3 id="heading-lets-observe-whats-happening">Let's observe what's happening</h3>
<p>Have a look at the following line.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>)
</code></pre>
<p>This is where we are using the first hook, useState. In the code, the <strong>count</strong> is the application state and you can think of the <strong>setCount</strong> as a function that can change the count state, just like <code>this.setState()</code> could change the values of the state object. The argument to <code>useState()</code> <strong>initializes the count with whatever it is passed with</strong>. In this case, it's 0.</p>
<h3 id="heading-adding-the-event-handlers">Adding the event handlers</h3>
<p>In order to change the value of the count object, we now have to add event handlers to the + and - buttons. Let's attach increment and decrement functions to with the ability to change the count object.</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">const</span> Counter = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>)

  <span class="hljs-comment">// highlight-start</span>
  <span class="hljs-keyword">const</span> increment = <span class="hljs-function">() =&gt;</span> {
    setCount(count + <span class="hljs-number">1</span>)
  }

  <span class="hljs-keyword">const</span> decrement = <span class="hljs-function">() =&gt;</span> {
    setCount(count - <span class="hljs-number">1</span>)
  }
  <span class="hljs-comment">// highlight-end</span>

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>A simple counter application using Hooks.<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn-group'</span>&gt;</span>
        // highlight-next-line
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{decrement}</span>&gt;</span>-<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span>&gt;</span>{count}<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        // highlight-next-line
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'btn btn-lg btn-outline-danger'</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{increment}</span>&gt;</span>+<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Counter
</code></pre>
<p>And with that, our counter application is completed. Your output should look like this now</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1663419437998/jK-IjDI0O.png" alt="image.png" /></p>
<p><br /></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Thank you for reading the blog. The source code for the example can be found at this <a target="_blank" href="https://github.com/Prashant-Acharya/hooks-counter">link</a> and if you want to learn more about react hooks, you could try exploring the official documentation <a target="_blank" href="https://reactjs.org/docs/hooks-intro.html">here</a>. <a target="_blank" href="Link">Text</a></p>
]]></content:encoded></item><item><title><![CDATA[Making AJAX requests to an API in React JS]]></title><description><![CDATA[This blog is targetted to beginners who are learning React JS. It is going to be a short blog in which I will talk about making an API request in React JS. I will link the core concepts required to make API calls to the official documentation of reac...]]></description><link>https://blogs.bigomega.dev/making-ajax-requests-to-an-api-in-react-js-d280d41a45f0</link><guid isPermaLink="true">https://blogs.bigomega.dev/making-ajax-requests-to-an-api-in-react-js-d280d41a45f0</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Thu, 18 Apr 2019 20:17:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234456071/39qlhXrkw.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This blog is targetted to beginners who are learning React JS. It is going to be a short blog in which I will talk about making an API request in React JS. I will link the core concepts required to make API calls to the official documentation of react as we encounter them in the story.</p>
<p>First of all, <strong>create a react project</strong>. To do so, you can use the <strong>create-react-app</strong> package provided by Facebook. I am assuming that you know how to do so. If you don’t, use the following steps to do so. Open the terminal and type the following commands (not the ones on BLOCK letters).</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%2846%2C76%2C98%2C1%29&amp;t=material&amp;wt=none&amp;l=application%2Fx-sh&amp;ds=false&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=88px&amp;ph=100px&amp;ln=false&amp;fm=Fira%20Code&amp;fs=18px&amp;lh=131%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=INSTALL%2520create-react-app%2520GLOBALLY%2520ON%2520YOUR%2520MACHINE%250Anpm%2520install%2520-g%2520create-react-app%250A%250ASTART%2520A%2520NEW%2520PROJECT%250Acreate-react-app%2520ajax-req%250A%250ANAVIGATE%2520TO%2520THE%2520PROJECT%2520FOLDER%250Acd%2520ajax-req%250A%250ASTART%2520THE%2520DEVELOPMENT%2520SERVER%250Anpm%2520start" width="700" height="323"></iframe>

<p>Creating a new react app</p>
<p><strong>Project Structure  
</strong>The create-react-app creates all the necessary boilerplate code for us. Open the project in your favourite text editor. Mine happens to be Visual Studio Code. The project structure will look like this</p>
<p>You can get rid of most of the files here but I am not going to talk about it. Now we are going to talk about the actual thing we’re planning to do.</p>
<h4 id="heading-lets-code">Let’s Code</h4>
<p>Open <strong>App.js</strong> and <em>remove the unnecessary code (you can copy the codes below)</em>. The code should look like this:</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%2883%2C94%2C110%2C1%29&amp;t=material&amp;wt=none&amp;l=auto&amp;ds=false&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=52px&amp;ph=100px&amp;ln=false&amp;fm=Fira%20Code&amp;fs=15px&amp;lh=152%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=import%2520React%252C%2520%257B%2520Component%2520%257D%2520from%2520%27react%27%253B%2509%2509%2509%2509%250A%250Aclass%2520App%2520extends%2520Component%2520%257B%250A%2509render%28%29%2520%257B%250A%2509%2509return%2520%28%250A%2509%2509%2509%253Cdiv%2520className%253D%2522App%2522%253E%250A%2509%2509%2509%250A%2509%2509%2509%253C%252Fdiv%253E%250A%2509%2509%29%253B%250A%2509%257D%250A%257D%250A%250Aexport%2520default%2520App%253B%250A" width="700" height="323"></iframe>

<p>App.js file till this point</p>
<p>Now, we want to <strong>initialize the application state</strong> inside the App component. To do so, we can simply <strong>initialize state as an empty object</strong>. The code must look like the following:</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%2883%2C94%2C110%2C1%29&amp;t=material&amp;wt=none&amp;l=auto&amp;ds=false&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=true&amp;pv=52px&amp;ph=100px&amp;ln=false&amp;fm=Fira%20Code&amp;fs=15px&amp;lh=152%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=%250Aclass%2520App%2520extends%2520Component%2520%257B%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%250A%2509state%2520%253D%2520%257B%257D%250A%250A%2509render%28%29%2520%257B%250A%2509%2509console.log%28this.state%29%250A%2509%2509return%2520%28%250A%2509%2509%2509%253Cdiv%2520className%253D%2522App%2522%253E%250A%250A%2509%2509%2509%253C%252Fdiv%253E%250A%2509%2509%29%253B%250A%2509%257D%250A%257D" width="700" height="323"></iframe>

<p><strong>WHAT EXACTLY IS A STATE?</strong></p>
<blockquote>
<p>A state is a property of React Components with the help of which we can make them interactive, dynamic. We can assign different behavior according to the available application state.<br /><strong>For example:  
</strong>In many applications such as an online store, you can enter the product name as a search query. Until the data is loaded, we can see some pre loading animations. As soon as the data is available the preloader disappears and we can see our result. This can be achieved with the help of state change.</p>
<p><strong>Read more about states on the</strong> <a target="_blank" href="https://reactjs.org/docs/state-and-lifecycle.html"><strong>official documentation</strong></a>.</p>
</blockquote>
<p>Inside the render method, I have <strong>logged the application state</strong> to the console <em>(first line on the render method)</em>. If you go to <a target="_blank" href="http://localhost:3000/">http://localhost:3000</a> on your browser and see the console, you’ll find <strong>an empty object {}</strong>.</p>
<h4 id="heading-lifecycle-methods">Lifecycle Methods</h4>
<blockquote>
<p>A react component goes through mounting, updating and unmounting phases. To deal with these, we have these methods called lifecycle methods which act handy to do something if something happens to the component like mounting, unmounting, change of state, receiving props etc.</p>
<p><strong>Read more about Lifecycle Methods on the</strong> <a target="_blank" href="https://reactjs.org/docs/state-and-lifecycle.html"><strong>official documentation</strong></a><strong>.</strong></p>
</blockquote>
<p><strong>Mounting  
</strong>Mounting of react components simply means rendering the component in the page. We have <em>componentDidMount(),</em> that gets called as soon as the component gets mounted in the view.<br /><strong>Mounting and unmounting process of a react component:<br />*</strong>1. Render the content returned by the render() method.<br />2. Check componentDidMount() method to see anything that happens after mounting action occurs.<br />3. Update the component if the application state changes. (re-rendering)<br />4. Unmount*</p>
<p>So we use componentDidMount lifecycle method to make AJAX request to <a target="_blank" href="https://jsonplaceholder.typicode.com/users">this URL</a> and change the application state.</p>
<iframe src="https://carbon.now.sh/embed?bg=rgba%2883%2C94%2C110%2C1%29&amp;t=material&amp;wt=none&amp;l=javascript&amp;ds=false&amp;dsyoff=20px&amp;dsblur=68px&amp;wc=true&amp;wa=false&amp;pv=0px&amp;ph=0px&amp;ln=false&amp;fm=Fira%20Code&amp;fs=15px&amp;lh=152%25&amp;si=false&amp;es=2x&amp;wm=false&amp;code=class%2520App%2520extends%2520Component%2520%257B%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%2509%250A%2509state%2520%253D%2520%257B%257D%2509%250A%250A%2509componentDidMount%28%29%2520%257B%250A%2509%2509fetch%28%27https%253A%252F%252Fjsonplaceholder.typicode.com%252Fusers%27%29%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2509.then%28response%2520%253D%253E%2520response.json%28%29%29%250A%2509%2509%2509.then%28users%2520%253D%253E%2520this.setState%28%257Busers%257D%29%29%250A%2509%257D%250A%250A%2509render%28%29%2520%257B%250A%2509%2509console.log%28this.state%29%250A%2509%2509return%2520%28%250A%2509%2509%2509%253Cdiv%2520className%253D%2522App%2522%253E%250A%2509%2509%2509%253C%252Fdiv%253E%250A%2509%2509%29%250A%2509%257D%250A%257D" width="700" height="323"></iframe>

<p>The code above makes an API request to the given URL, then it parses the response as json then we pass the data to <em>this.setState()</em> which sets the state of the application with the data we get from the request. If you check the console now, in few seconds you will see objects with data of 10 users logged on the console.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234454537/GUF-mdxrP.png" alt /></p>
<p>Now you can do anything you want with the data. Try to do something with it. You can find the source code on my GitHub. <a target="_blank" href="https://github.com/Prashant-Acharya/making-ajax-request">Here’s the link</a>.</p>
<p>Thank you for reading.</p>
]]></content:encoded></item><item><title><![CDATA[Boosting workflow and Customization]]></title><description><![CDATA[To write this blog I asked people of a techy facebook group a few questions. I just wanted to know if people customize their system or not and why do they do so? In this blog, I want to talk about the answers I got, my opinion on customization and ho...]]></description><link>https://blogs.bigomega.dev/boosting-workflow-and-customization-4a8f845dc298</link><guid isPermaLink="true">https://blogs.bigomega.dev/boosting-workflow-and-customization-4a8f845dc298</guid><dc:creator><![CDATA[Prashant Acharya]]></dc:creator><pubDate>Thu, 18 Apr 2019 07:25:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234600953/6Tb0ygVFF.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To write this blog I asked people of a techy facebook group a few questions. I just wanted to know <strong>if people customize their system</strong> or not and <strong>why do they do so</strong>? In this blog, I want to talk about the <strong>answers I got</strong>, <strong>my opinion on customization</strong> and how can you <strong>customize your computer for better workflow</strong>. I would like to mention that it is an opinionated blog so your preferences might be different.</p>
<h4 id="heading-answers-review-and-my-opinion">Answers review and my opinion</h4>
<p>According to the answers I got in the post, most people responded that they go with a fairly minimal level of customization. They are pretty much satisfied with what they get out of the box and add little tweaks. It is a <em>personal preference</em> and <em>there’s no right or wrong</em> when it comes to how you make your computer look like. I love to customize and I think people should customize their computers for the following reasons.</p>
<ol>
<li><strong>Customization makes you more connected to your machine and fall in love with it.</strong> Do you ever feel bored with how your computer looks or works like? Try to customize the looks and feel, the <strong>experience</strong> you might find might be completely different. Customization also makes your system <strong>feel more personal</strong> and that is why customization is also called <strong>personalization</strong>. I personally love to work on my machine after making tweaks because they seem so beautiful to work with.</li>
<li><strong>Customization can help your computer work for you.  
</strong>When you customize your computer, you <strong>tweak the functionality</strong> according to <strong>your preferences</strong> and that is probably making your computer work according to you because it is your preference ultimately. Your computer is your machine and use the power of customization to make it work for you.</li>
<li><strong>Customization helps you to boost your workflow.  
</strong>Customizing your computer helps you to boost your workflow because you can get more room to work, access things you access frequently faster and so on.</li>
</ol>
<h4 id="heading-customization-options-on-a-windows-machine">CUSTOMIZATION OPTIONS ON A WINDOWS MACHINE</h4>
<p>First I would like to talk about windows operating system. I personally don’t have any experience using an Apple computer so I would not be talking about it. Windows operating system looks <strong>very polished</strong> and recent versions are <strong>absolutely beautiful.</strong> The <strong>customization options you get is fairly low</strong> in comparison to a Linux Operating System. Even though it is low, you can definitely make proper use of customization options it provides. You can change wallpapers, choose between a dark and a light theme, change the size of icons, zoom level and so much more. I would like to share how I have customized my laptop.</p>
<p><strong>Desktop  
</strong>I like to have <strong>a clean desktop</strong>. So the only thing that I have is a recycle bin and also I keep a copy of the folder of a project that I am working on. It could be the photos or videos that I am editing, documents that I am planning to print or upload somewhere.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234587311/Ehgn5AHsZ.png" alt /></p>
<p>My desktop</p>
<p><strong>Keep things small</strong> The other thing that I like to do is keep things really small so that I <strong>get more room to work</strong>. I use small icons so that the taskbar doesn’t take much space of my working window. You might say I could autohide the taskbar but that feature as I had tried earlier works like shit so I don’t use it. I have also changed the <strong>default zoom level to 100% which by default is 125%</strong> in my <em>1920x1080</em> display. That makes things smaller giving me more room to work. I prefer to <strong>change the default zoom level inside the apps</strong> that need to be zoomed (like text editors).</p>
<p><strong>More on taskbars  
</strong>The difference in the size of icons by just a few millimetres makes no difference in precision. So the size, in that case, doesn’t make a difference to me in a negative way. By default, Cortana also has a huge search bar. I change it to just display icon only that gives me more room for the tasks that get stacked in the taskbar. It also gives me <strong>a clean look and feel</strong>. I also try <strong>not to pin unnecessary taskbar icons</strong>. On the right side, I keep notification icons of really necessary stuff like time, battery, WiFi and volume.</p>
<p><strong>Start Menu  
</strong>Customization option on the start menu in windows 10 is massive. You have a proper place to pin apps, group them, change the size of tiles, increase the size of the start menu and so on.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234589121/eoaZ7Jie4.png" alt /></p>
<p>Start Menu Windows 10</p>
<p>As you can see I have <strong>pinned important apps</strong> I use on my start menu. There are unnecessary apps like camera, video player and so on but mostly there are apps that I use on a frequent basis. I have also tried to <strong>group them properly</strong>. On the left-hand side, I <strong>haven’t pinned</strong> μtorrent, photoshop and adobe premier because they will always be on the top so I don’t feel the necessity to do so. This customization helps me to access these apps I use frequently.</p>
<h4 id="heading-customization-option-on-a-linux-operating-system"><strong>CUSTOMIZATION OPTION ON A LINUX OPERATING SYSTEM</strong></h4>
<p>I am using <strong>Manjaro Linux</strong> with <strong>KDE desktop environment</strong> and it is beautiful. Customization options on Linux are more than on the Windows operating system. I have probably customized everything on my Linux OS. I would like to list out a few customization options that you can try or I have already made in order to make your computer look better. First I would like to start with an operating system independent option that I use everywhere.</p>
<p><strong>Make Everything Dark ✔️  
</strong>The only thing that my heart and apps on my computer look similar is the colour/theme 🖤. I try to set every app to have <strong>a dark theme</strong>. This doesn’t probably boost the workflow but it is <strong>pleasing for your eyes</strong> and it also looks really cool.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234590885/1_eNoOeXN.png" alt /></p>
<p>Dark File Explorer 😍</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234592543/pd-pOF7AJ.png" alt /></p>
<p>VS Code with Min Dark theme</p>
<p><strong>Desktop 💻  
</strong>I take <strong>keeping things small to another level</strong> in Manjaro. Take a look at my desktop.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234594288/Q-X5s-yiD.png" alt /></p>
<p>Linux desktop</p>
<p>As you can see I don’t have a traditional taskbar. I removed the space completely and shrunk it down to just fit the notification menu on the top right corner. I have <strong>a dock which acts as a taskbar</strong> where I also pin apps I use on a frequent basis. The advantage I get is it auto hides and shows more smoothly than taskbar on Windows operating system.</p>
<p><strong>Terminal  
</strong>I use two terminals. One is a drop-down terminal and the other is a normal terminal. I use the drop-down terminal for running a development server and the other terminal for installing packages for the project. That is just one of the many used cases. You can do a lot with it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234596115/kraK1_CP2.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234597837/5vXpPuo4o.png" alt /></p>
<p>Normal terminal (Left) Drop-down terminal (Right)</p>
<p><strong>ZSH &amp; Oh my ZSH</strong> I use the z shell or zsh as my default terminal. According to the <a target="_blank" href="http://www.zsh.org/">official website</a>:</p>
<blockquote>
<p>Zsh is a shell designed for interactive use, although it is also a powerful scripting language. More information can be found on the “Zsh Web Pages” sites.</p>
</blockquote>
<p>Oh my ZSH is <strong>a framework</strong> for the z shell. It gives various features such as <em>syntax highlighting, command predictions, autocomplete, themes and many more</em>. To install it on your system, read the <a target="_blank" href="https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH">official guide</a> on GitHub 📓.</p>
<p><strong>Project Directory 📁  
</strong>In Linux, unlike windows in which I keep my current project in desktop, I have a dedicated folder in my home directory named projects where I keep all my programming projects. That way it is easier for me to navigate to that project directory from my terminal window.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674234599195/fCov18toQ.png" alt /></p>
<p>Project directory</p>
<p><strong>Hot Keys and Shortcuts</strong> ⌨In any operating system or simply a tool, knowledge of shortcut keys and hotkeys are mandatory to boost workflow. Personally, I am very efficient in using my computer when I am not touching the trackpad or a mouse. In KDE, you get an option called screen edge. It helps you to map any app when you hover your mouse to that edge.</p>
<h4 id="heading-conclusion">Conclusion</h4>
<p>Customization is freedom. You don’t have to follow what I do. You can do whatever you want with your system. Give it a shot and compare it with your workflow.<br />Thank you for reading the blog. If you like, please give this story a clap and share it with your friends and as always, feedbacks are appreciated. ❤️️</p>
]]></content:encoded></item></channel></rss>