<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ಮಿಥುನ್ </title>
    <description>The latest articles on DEV Community by ಮಿಥುನ್  (@mithunkumarc).</description>
    <link>https://dev.to/mithunkumarc</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%2F423529%2Fe1b72f17-2171-4691-876d-1207b6b7607f.jpeg</url>
      <title>DEV Community: ಮಿಥುನ್ </title>
      <link>https://dev.to/mithunkumarc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mithunkumarc"/>
    <language>en</language>
    <item>
      <title>git stash usage for beginners</title>
      <dc:creator>ಮಿಥುನ್ </dc:creator>
      <pubDate>Sat, 25 Feb 2023 04:31:51 +0000</pubDate>
      <link>https://dev.to/mithunkumarc/git-stash-usage-for-beginners-5a00</link>
      <guid>https://dev.to/mithunkumarc/git-stash-usage-for-beginners-5a00</guid>
      <description>&lt;p&gt;In the below branch tree, let's say you are working on Feature-branch-helper. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;master

&lt;ul&gt;
&lt;li&gt;develop

&lt;ul&gt;
&lt;li&gt;Feature-branch

&lt;ul&gt;
&lt;li&gt;Feature-branch-helper&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you completed working on Feature-branch-helper, before you merge with Feature-branch, you would want to take latest from Feature-branch. Without taking latest from Feature-branch you cannot merge. In this case we can use git stash.&lt;/p&gt;

&lt;p&gt;Steps I follow to update current branch. Assuming you are in Feature-branch-helper.&lt;/p&gt;

&lt;p&gt;First take backup of your changes&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Second take latest of Feature-branch&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; git pull origin Feature-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Resume your changes to your branch ,Feature-branch-helper&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Simple Dictionary Program in GO</title>
      <dc:creator>ಮಿಥುನ್ </dc:creator>
      <pubDate>Sun, 20 Mar 2022 07:02:13 +0000</pubDate>
      <link>https://dev.to/mithunkumarc/simple-dictionary-program-in-go-187c</link>
      <guid>https://dev.to/mithunkumarc/simple-dictionary-program-in-go-187c</guid>
      <description>&lt;p&gt;Hello Friends, As a beginner in GO I have written a simple Dictionary program. This program uses Map to store word and meaning. This program also allows user to update, delete, search and list all words. Feel free to comment and let me know how can i improve this program. Thanks.&lt;/p&gt;

&lt;p&gt;Please follow this link to see program.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mithunkumarc/learning-golang/blob/master/examples/dictionary_program.go"&gt;Dictionary Program&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
    </item>
    <item>
      <title>using axios in nodejs</title>
      <dc:creator>ಮಿಥುನ್ </dc:creator>
      <pubDate>Thu, 23 Sep 2021 15:06:59 +0000</pubDate>
      <link>https://dev.to/mithunkumarc/using-axios-in-nodejs-2hmk</link>
      <guid>https://dev.to/mithunkumarc/using-axios-in-nodejs-2hmk</guid>
      <description>&lt;p&gt;axios is Promise based Http Client for the browser and node.js&lt;/p&gt;

&lt;p&gt;install axios into your nodejs project using below command.&lt;/p&gt;



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

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

&lt;/div&gt;



&lt;p&gt;import axios using below statement.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
     const axios = require('axios');

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

&lt;/div&gt;



&lt;p&gt;Below sample code to shows how to use axios. since axios returns promise object handle success and error data with then() and catch() callback functions.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
app.get("/yourapi", function(req, res, next) =&amp;gt; {
    axios.get("https://replace/your/url/here")
    .then(function (response) {
        // handle success
        return res.send(response.data);
    })
    .catch(function (error) {
        // handle error
        console.log(error);
        // return res.send(error["message"]); // send response or 
        next(error); // pass error to global error handler
  })
})

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

&lt;/div&gt;



&lt;p&gt;global error handler example. make sure you use error handler middleware at the end of entry script file(index/server.js file).&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    app.use(function (err, req, res, next) {
      res.status(500).send(err["message");
    })

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

&lt;/div&gt;




&lt;p&gt;&lt;b&gt;References&lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/axios"&gt;axios&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://expressjs.com/en/guide/error-handling.html"&gt;error handler&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>RxJs interval with condition</title>
      <dc:creator>ಮಿಥುನ್ </dc:creator>
      <pubDate>Wed, 06 Jan 2021 14:17:24 +0000</pubDate>
      <link>https://dev.to/mithunkumarc/rxjs-interval-with-condition-bc3</link>
      <guid>https://dev.to/mithunkumarc/rxjs-interval-with-condition-bc3</guid>
      <description>&lt;p&gt;We have used setInterval() to run a task multiple times after every specific interval. We need to clear interval after the task is done. Using RxJs interval function we can simulate setInterval function.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { interval } from "rxjs";

// creating observable
let numbers = interval(1000);

// subscribe function returns reference to observable
let numbesubs = numbers.subscribe(x =&amp;gt; {
  console.log("Next: ", x);
  // clearing interval when x reaches 10 value
  if (x == 10) {
    unSubscribingfunction();
  }
});

function unSubscribingfunction() {
    // clearing interval
    numbesubs.unsubscribe();
}

// Logs:
// Next: 0
// Next: 1
// Next: 2
// ..
// Next: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>why to use sync.WaitGroup in golang?</title>
      <dc:creator>ಮಿಥುನ್ </dc:creator>
      <pubDate>Fri, 14 Aug 2020 15:47:14 +0000</pubDate>
      <link>https://dev.to/mithunkumarc/why-to-use-sync-waitgroup-in-golang-34ph</link>
      <guid>https://dev.to/mithunkumarc/why-to-use-sync-waitgroup-in-golang-34ph</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;WaitGroup instance is available in sync package in golang. WaitGroup is required to force Main GoRoutine to wait all other GoRoutine complete their tasks. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before we see how to use waitgroup lets discuss about Goroutines first.&lt;/p&gt;

&lt;h4&gt;
  
  
  what is Goroutine?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Goroutine is separate path of execution if you familiar with Java, it is same as thread.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By default there is will atleast one Goroutine in golang program, which i call as &lt;strong&gt;Main Goroutine&lt;/strong&gt; as i come from java background. &lt;/p&gt;

&lt;p&gt;On top of that you can create your own Goroutine which can be called as &lt;strong&gt;user defined Goroutines&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to create Goroutine?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;it is simple, just use prefix "go" to your function call.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eg :   go myTask() // creates a Goroutine.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  why we need WaitGroup? lets look at this example
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main
import "fmt"
func task(msg string) {
for i := 0 ; i &amp;lt; 10 ; i++ {
    fmt.Println(msg)
}
}

func main() {
    // we are creating two goroutine
    go task("first")
    go task("second")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;output : program exited&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the above example , we are creating two Goroutine but we are not making Main Goroutine to wait till "first" and "second" Goroutine completes. Now sync.WaitGroup comes into picture.&lt;/p&gt;

&lt;h4&gt;
  
  
  steps to use sync.WaitGroup
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;import "sync" package and declare variable sync.WaitGroup &lt;/li&gt;
&lt;li&gt;increment counter by using function Add(numberOfGroutineAdding)&lt;/li&gt;
&lt;li&gt;use Wait() at the end of program&lt;/li&gt;
&lt;li&gt;use Done() when each Goroutine is completed. It decrements counter by 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Now working example with sync.WaitGroup
&lt;/h4&gt;

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

import (
"fmt"
"sync"
)

func task(msg string, wg *sync.WaitGroup) {
for i := 0 ; i &amp;lt; 10 ; i++ {
    fmt.Println(msg)
}
wg.Done() // decrement counter
}

func main() {
    var wg sync.WaitGroup
    wg.Add(1) // incrment counter for "first"
    go task("first", &amp;amp;wg)
    wg.Add(1) // increment counter for "second"
    go task("second", &amp;amp;wg)
    // Main Goroutine will wait till "first" and "second" completes
    wg.Wait() 

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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;output: ten times "first" and "second" will be printed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the above program , we have added one more parameter sync.WaitGroup to call Done() when each Goroutine is completed.&lt;/p&gt;

</description>
      <category>go</category>
      <category>goroutine</category>
    </item>
    <item>
      <title>Typescript Mixin example</title>
      <dc:creator>ಮಿಥುನ್ </dc:creator>
      <pubDate>Sun, 05 Jul 2020 20:07:23 +0000</pubDate>
      <link>https://dev.to/mithunkumarc/typescript-mixin-example-4jp6</link>
      <guid>https://dev.to/mithunkumarc/typescript-mixin-example-4jp6</guid>
      <description>&lt;p&gt;Typescript doesn't allow multiple inheritance through classes, although an interface extends multiple classes but it doesn't inherit methods implementation, it inherits only method declaration.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class One {
    one() {
    }
}

class Two {
    two() {
    }
}

interface Three extends One, Two {
   // inherits One's, Two's method declarations
   one();
   two();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;There is another way to inherit methods from multiple special class(In typescript mixin used as function) called Mixin. According to Wikipedia, In object-oriented programming languages, a mixin (or mix-in) is a class that contains methods for use by other classes without having to be the parent class of those other classes. How those other classes gain access to the mixin's methods depends on the language.&lt;/p&gt;

&lt;p&gt;Mixins are sometimes described as being "included" rather than "inherited". Basically in typescript Mixin is used to create a class. To this newly created class it adds new property and adds property from existing class.&lt;/p&gt;

&lt;p&gt;it can be said as  &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Base/our class properties -&amp;gt; [ Mixin adds properties] -&amp;gt; NewClass
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and then you can add few more properties&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NewClass  properties -&amp;gt; [ AnotherMixin adds properties] -&amp;gt; AnotherNewClass
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Steps to use Mixin  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create your class with properties, lets say User.&lt;/li&gt;
&lt;li&gt;Create constructor function&lt;/li&gt;
&lt;li&gt;Create Mixin function which return new class with new properties added by mixin and properties from User class.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Implementation  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;let's create a User class with property name&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; class User {
   name: string;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;let's create constructor function, used to create mixin class. refer this link for more details : &lt;a href="https://blog.rsuter.com/how-to-instantiate-a-generic-type-in-typescript/"&gt;instantiating generic type&lt;/a&gt;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // declaring generic type

 type Constructor&amp;lt;T = {}&amp;gt; = new (...args: any[]) =&amp;gt; T;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A mixin function that adds new property and returns new class&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Timestamped&amp;lt;TBase extends Constructor&amp;gt;(Base: TBase) {
  // User is considered as Base and Base is extended by new class
  // return a class, combining "name" and "timestamp"  
  return class extends Base {
    timestamp = Date.now(); // goes inside new class constructor 
  };
} 
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;New class is named as TimestampedUser&lt;br&gt;
it consists of new property timestamp and "name" from User&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const TimestampedUser = Timestamped(User);
  const timestampedUserExample = new TimestampedUser();
  timestampedUserExample.name = "vishruth";
  console.log(timestampedUserExample.name); //"vishruth"
  console.log(timestampedUserExample.timestamp);//1593976747100
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You can create another Mixin and keep add properties to new class TimestampedNewMixinUser. like&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      // define NewMixin function here and call like below    
      const TimestampedNewMixinUser = Timestamped(NewMixin(User));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>typescript</category>
      <category>mixin</category>
      <category>typescriptmixin</category>
      <category>multipleinheritance</category>
    </item>
  </channel>
</rss>
