<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Eric Karugu</title>
    <description>The latest articles on Forem by Eric Karugu (@erickarugu).</description>
    <link>https://forem.com/erickarugu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F239130%2F45e0a100-355c-4016-91b9-19b9a77b96c3.jpg</url>
      <title>Forem: Eric Karugu</title>
      <link>https://forem.com/erickarugu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/erickarugu"/>
    <language>en</language>
    <item>
      <title>What are you currently working on? Which technologies/tools are you using? Why?</title>
      <dc:creator>Eric Karugu</dc:creator>
      <pubDate>Sat, 14 Aug 2021 13:38:36 +0000</pubDate>
      <link>https://forem.com/erickarugu/what-are-you-currently-working-on-which-technologies-tools-are-you-using-why-1mk3</link>
      <guid>https://forem.com/erickarugu/what-are-you-currently-working-on-which-technologies-tools-are-you-using-why-1mk3</guid>
      <description></description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tooling</category>
    </item>
    <item>
      <title>What is your favorite VS Code theme extension and why?</title>
      <dc:creator>Eric Karugu</dc:creator>
      <pubDate>Sat, 27 Mar 2021 16:22:51 +0000</pubDate>
      <link>https://forem.com/erickarugu/what-is-your-favorite-vs-code-theme-extension-and-why-32lm</link>
      <guid>https://forem.com/erickarugu/what-is-your-favorite-vs-code-theme-extension-and-why-32lm</guid>
      <description></description>
      <category>vscode</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to Implement the Stack Data Structure in Javascript</title>
      <dc:creator>Eric Karugu</dc:creator>
      <pubDate>Tue, 28 Jul 2020 14:06:23 +0000</pubDate>
      <link>https://forem.com/erickarugu/implementing-the-stack-data-structure-in-javascript-59n5</link>
      <guid>https://forem.com/erickarugu/implementing-the-stack-data-structure-in-javascript-59n5</guid>
      <description>&lt;p&gt;In Data Structures, a &lt;strong&gt;Stack&lt;/strong&gt; is an abstract data type that serves as a collection of items. A stack has two core operational principles: pop and push. The data type got its name from its behavior where similar to a real-world stack, a stack ADT only allow operations from one end.&lt;/p&gt;

&lt;h3&gt;
  
  
  The LIFO Principle
&lt;/h3&gt;

&lt;p&gt;Due to its behavior, the stack is called a LIFO data structure. LIFO stands for Last In First Out, where the last element put in the storage is the first one to be popped out.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq5a0ym6de9ckp9buhkob.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq5a0ym6de9ckp9buhkob.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;Enough with the texts, let us see the code in action.&lt;br&gt;
We will cover the following JavaScript topics in this challenge:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;Array's pop and push functions&lt;/li&gt;
&lt;li&gt;The "&lt;strong&gt;new&lt;/strong&gt;" keyword&lt;/li&gt;
&lt;li&gt;Constructor&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Class Definition
&lt;/h4&gt;

&lt;p&gt;First, we define our class using the "class" keyword and declare a constructor function to create an empty array when the class is first initialized.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Stack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Typically, the class name begins with a capital letter. However, this is just a widely adopted naming convention and not a syntax requirement. Note, the constructor function does not require the "function" keyword. This is true for all functions declared inside the class. Another point worth noting is that functions declared inside a class are referred to as &lt;strong&gt;methods&lt;/strong&gt; and are accessible from outside of the class by default.&lt;/p&gt;

&lt;h3&gt;
  
  
  Methods inside the class
&lt;/h3&gt;

&lt;p&gt;Next, we add methods to perform the different operations on the stack.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Stack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;  
    &lt;span class="c1"&gt;// Push&lt;/span&gt;
    &lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; 
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="c1"&gt;// pop() &lt;/span&gt;
    &lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt; 
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="c1"&gt;// peek() &lt;/span&gt;
    &lt;span class="nf"&gt;peek&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt; 
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="c1"&gt;// isEmpty() &lt;/span&gt;
    &lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt; 
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;push&lt;/strong&gt; method is used to add an element on top of the stack and does not return anything.&lt;br&gt;
The &lt;strong&gt;pop&lt;/strong&gt; method, on the other hand, removes the topmost element from the stack and returns it. Inside this method, we first confirm that the stack is not empty and only proceed to "pop" the element on top of the stack if it is not empty.&lt;br&gt;
The &lt;strong&gt;peek&lt;/strong&gt; method, just like the method name suggests, returns the element on top of the stack without affecting the stack.&lt;br&gt;
The &lt;strong&gt;isEmpty&lt;/strong&gt; method is used to check whether the stack is empty and return true or false.&lt;/p&gt;
&lt;h3&gt;
  
  
  Working with the Stack
&lt;/h3&gt;

&lt;p&gt;First, we initialize a new instance of the stack by using the "&lt;strong&gt;new&lt;/strong&gt;" keyword and assign that to a variable. This creates an empty stack as the constructor inside the class is called immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, we can use the various methods in our class instance to perform the various operations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;   &lt;span class="c1"&gt;//returns true&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;//does not return anything&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;peek&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;      &lt;span class="c1"&gt;// returns 1&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;peek&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;      &lt;span class="c1"&gt;// returns the string "Hello"&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;       &lt;span class="c1"&gt;// returns "Hello"&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;peek&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;      &lt;span class="c1"&gt;// returns 1&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;       &lt;span class="c1"&gt;//returns 1&lt;/span&gt;
&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;peek&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;      &lt;span class="c1"&gt;//returns -1(indicates the stack is empty)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note, you can work with more than one stack by creating new instances of the "&lt;strong&gt;&lt;strong&gt;Stack&lt;/strong&gt;&lt;/strong&gt;" class using the "&lt;strong&gt;&lt;strong&gt;new&lt;/strong&gt;&lt;/strong&gt;" keyword and assigning that to different variables.&lt;/p&gt;

&lt;p&gt;That is all we need to create a functional Stack in Javascript!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>computerscience</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>My #100DaysOfCode experience during the pandemic</title>
      <dc:creator>Eric Karugu</dc:creator>
      <pubDate>Sun, 26 Jul 2020 08:32:04 +0000</pubDate>
      <link>https://forem.com/erickarugu/my-100daysofcode-experience-during-the-pandemic-372o</link>
      <guid>https://forem.com/erickarugu/my-100daysofcode-experience-during-the-pandemic-372o</guid>
      <description>&lt;p&gt;I committed and completed the 100DaysofCode challenge by taking advantage of the COVID-19 pandemic. Here I share what I learned and think about this challenge.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learning how to code
&lt;/h3&gt;

&lt;p&gt;To give a little bit of my coding life context, I first stumbled into programming back in 2017 after joining college. Before then, I had not interacted with a computer leave alone working with one. Instantly, I was amused to learn how computer programs, websites, and software come to life. I fell in love with Web Development in particular and would always squeeze a few minutes in my schedule to write some HTML and CSS whenever I could. However, there was a problem. I was not consistent! You see, programming is not the type of skill to sharpen over the weekend. It requires consistency. That is, setting aside some few minutes every day to practice: the main emphasis being, every single day. Also, one has to commit, be patient, and persistent to succeed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Committing to the challenge - Having a solid plan
&lt;/h3&gt;

&lt;p&gt;Before trying again and finally succeeding this year, I had dared to commit to the challenge before, but I failed terribly. I only managed to go for two weeks. Back then, I had a million excuses. I had no plan, no self-drive, and ultimately no energy. Finally, after the COVID-19 pandemic hit, I decided to take advantage and commit, this time, with a solid plan and schedule. I noted down my overall goals, including the specific areas where I wanted to improve and curated a list of projects I wanted to complete.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/document/d/1K7xI2CavJRLRp2QJrxyOQs1x8NriCCYcxA71x0BSQGg/edit?usp=sharing"&gt;My Overall Plan&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For anyone thinking about daring to try this challenge, this should be your first task. Have a solid plan. Having a daily schedule will help program your mind to always be ready for coding practice at a specific time of the day, every day!&lt;/p&gt;

&lt;h3&gt;
  
  
  Documenting Progress
&lt;/h3&gt;

&lt;p&gt;Every day, I logged my progress in a GitHub repo and shared it on Twitter. Well, technically, not every single day. I took a few breaks in between, but I made sure they are essential. In general, I believe that it is okay to relax and take a break, provided you have set your mind straight.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://twitter.com/karugu_eric/status/1241388821473828865"&gt;Twitter thread&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/erickarugu32/100-days-of-code/blob/master/log.md"&gt;GitHub Log&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Time Management
&lt;/h3&gt;

&lt;p&gt;I used a popular time management technique: the promodoro. The method involves breaking down your tasks into intervals with short and long breaks in between. Traditionally the "intervals" are 25 minutes long. The technique helps you focus during the set "intervals" and then allow your mind to internalize what you have learned or worked on over the break. It is a proven technique, and I would recommend it to everyone. Check out &lt;a href="https://tomato-timer.com/"&gt;this simple online promodoro tool&lt;/a&gt; or &lt;a href="https://pomofocus.io/"&gt;this one with some great additional features&lt;/a&gt; to help you stay focused and be productive.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finding Motivation
&lt;/h3&gt;

&lt;p&gt;When it comes to motivation, it can be arduous to remain excited about learning. Learning becomes interesting if you are interested. I managed to beat around this impediment by working on small projects. While working on the small projects, I was always excited about adding a feature or improving on the overall look. I found myself learning a lot in this process without exerting too much pressure on myself in the long run. Overall, I always find this method more helpful rather than following tutorials or coding lessons. &lt;/p&gt;

&lt;h3&gt;
  
  
  Learning how to learn
&lt;/h3&gt;

&lt;p&gt;In the programming world, scenarios are forever different, and learning how to learn fast and implement is an essential skill. Unfortunately, watching tutors code applications on youtube one after another will not help you as much. Speaking from personal experience, I think such tutorials are great being a supplement in your learning journey.&lt;/p&gt;

&lt;h3&gt;
  
  
  Interacting with others
&lt;/h3&gt;

&lt;p&gt;In the course of the coding challenge, I interacted with other developers who were attempting the coding challenge as well. I found this to be helpful in terms of inspiration and support. I met so many people on Twitter, Slack channels, discord channels, and LinkedIn, who were ready to help and collaborate along the journey.&lt;/p&gt;

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

&lt;p&gt;I believe the #100DaysOfCode challenge is exceptional for developers in all levels to learn and level-up their skills. In my case, I saw my software development skills improve. Consequently, I have developed other daily routines with ease in areas that I wish to improve myself. I would recommend checking out the following channels for anyone who wants to try the challenge but do not know how to start.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://www.100daysofcode.com"&gt;#100DaysOfCode Official Website&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;The #100DaysOfCode hashtag on Twitter&lt;/li&gt;
&lt;li&gt;The #100DaysOfCode Slack channels&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is my first article, comments are very much welcome.&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
