<?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: Danyson</title>
    <description>The latest articles on DEV Community by Danyson (@danyson).</description>
    <link>https://dev.to/danyson</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%2F586356%2Fd0be1dee-26d1-4820-b5ea-640164d8d84d.png</url>
      <title>DEV Community: Danyson</title>
      <link>https://dev.to/danyson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danyson"/>
    <language>en</language>
    <item>
      <title>Reactive Programming with RxJS</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Tue, 26 Dec 2023 11:56:48 +0000</pubDate>
      <link>https://dev.to/danyson/reactive-programming-with-rxjs-4ok7</link>
      <guid>https://dev.to/danyson/reactive-programming-with-rxjs-4ok7</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Reactive programming&lt;/u&gt;&lt;/strong&gt; is a paradigm that deals with asynchronous data flows, where the data is transformed and manipulated by applying various operators. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;RxJS is a library that implements reactive programming in JavaScript, providing a rich set of operators and utilities to work with observables, which are streams of data that can be subscribed to and reacted to.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the main benefits of reactive programming is that it allows us to write cleaner, more maintainable, and robust code, especially when dealing with complex logic, concurrency, and error handling. Reactive programming also enables us to create declarative UIs that react to changes in data and user interactions.&lt;/p&gt;

&lt;p&gt;To illustrate reactive programming with examples from RxJS, let's look at some common scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fetching data from an API&lt;/strong&gt;: Suppose we want to fetch some data from an API endpoint using RxJS. We can use the &lt;code&gt;from&lt;/code&gt; operator to create an observable from a function that returns a promise. The promise will resolve with the data when it is available. Then we can use the &lt;code&gt;map&lt;/code&gt; operator to transform the data into a desired format. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs/operators&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a function that returns a promise&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Create an observable from the function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchDataObservable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Map the data into an array of objects&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fetchDataObservable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Do some transformation here&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Subscribe to the observable and log the array&lt;/span&gt;
&lt;span class="nx"&gt;dataArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Filtering and sorting data&lt;/strong&gt;: Suppose we want to filter and sort some data based on some criteria using RxJS. We can use the &lt;code&gt;filter&lt;/code&gt; operator to apply a predicate function that returns true or false for each element in the stream. The predicate will determine which elements are emitted by the stream. Then we can use the &lt;code&gt;sorted&lt;/code&gt; operator to sort the elements based on one or more keys. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sorted&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs/operators&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define some sample data&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sampleData&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="na"&gt;id&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Charlie&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Filter out elements with price less than or equal to 15&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filteredData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sampleData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Sort elements by name in ascending order&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortedData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;filteredData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Subscribe to the observable and log the arrays&lt;/span&gt;
&lt;span class="nx"&gt;sortedData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Combining multiple streams&lt;/strong&gt;: Suppose we want to combine multiple streams of data into one stream using RxJS. We can use various operators such as &lt;code&gt;merge&lt;/code&gt;, &lt;code&gt;concat&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt;, or &lt;code&gt;combineLatest&lt;/code&gt; depending on our needs. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define two sample streams of numbers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stream1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&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="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stream2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Merge both streams into one stream&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mergedStream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stream1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stream2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Subscribe to the observable and log each number emitted by both streams&lt;/span&gt;
&lt;span class="nx"&gt;mergedStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are just some examples of how reactive programming with RxJS can help us write better code for various scenarios. If you want to learn more about reactive programming with RxJS, you can check out the official documentation =&amp;gt; &lt;a href="https://rxjs.dev/"&gt;RxJs&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Explore more about me here:- &lt;a href="https://danyson.netlify.app"&gt;danyson.netlify.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LinkedIn : &lt;a href="https://www.linkedin.com/in/danyson"&gt;LinkedIn/danyson&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>Reactive Programming with RxJS</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Tue, 26 Dec 2023 11:56:48 +0000</pubDate>
      <link>https://dev.to/danyson/reactive-programming-with-rxjs-3fp9</link>
      <guid>https://dev.to/danyson/reactive-programming-with-rxjs-3fp9</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Reactive programming&lt;/u&gt;&lt;/strong&gt; is a paradigm that deals with asynchronous data flows, where the data is transformed and manipulated by applying various operators. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;RxJS is a library that implements reactive programming in JavaScript, providing a rich set of operators and utilities to work with observables, which are streams of data that can be subscribed to and reacted to.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the main benefits of reactive programming is that it allows us to write cleaner, more maintainable, and robust code, especially when dealing with complex logic, concurrency, and error handling. Reactive programming also enables us to create declarative UIs that react to changes in data and user interactions.&lt;/p&gt;

&lt;p&gt;To illustrate reactive programming with examples from RxJS, let's look at some common scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fetching data from an API&lt;/strong&gt;: Suppose we want to fetch some data from an API endpoint using RxJS. We can use the &lt;code&gt;from&lt;/code&gt; operator to create an observable from a function that returns a promise. The promise will resolve with the data when it is available. Then we can use the &lt;code&gt;map&lt;/code&gt; operator to transform the data into a desired format. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs/operators&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a function that returns a promise&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Create an observable from the function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchDataObservable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Map the data into an array of objects&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fetchDataObservable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Do some transformation here&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Subscribe to the observable and log the array&lt;/span&gt;
&lt;span class="nx"&gt;dataArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Filtering and sorting data&lt;/strong&gt;: Suppose we want to filter and sort some data based on some criteria using RxJS. We can use the &lt;code&gt;filter&lt;/code&gt; operator to apply a predicate function that returns true or false for each element in the stream. The predicate will determine which elements are emitted by the stream. Then we can use the &lt;code&gt;sorted&lt;/code&gt; operator to sort the elements based on one or more keys. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sorted&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs/operators&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define some sample data&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sampleData&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="na"&gt;id&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Charlie&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Filter out elements with price less than or equal to 15&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filteredData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sampleData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Sort elements by name in ascending order&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortedData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;filteredData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Subscribe to the observable and log the arrays&lt;/span&gt;
&lt;span class="nx"&gt;sortedData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Combining multiple streams&lt;/strong&gt;: Suppose we want to combine multiple streams of data into one stream using RxJS. We can use various operators such as &lt;code&gt;merge&lt;/code&gt;, &lt;code&gt;concat&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt;, or &lt;code&gt;combineLatest&lt;/code&gt; depending on our needs. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define two sample streams of numbers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stream1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&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="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stream2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Merge both streams into one stream&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mergedStream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stream1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stream2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Subscribe to the observable and log each number emitted by both streams&lt;/span&gt;
&lt;span class="nx"&gt;mergedStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are just some examples of how reactive programming with RxJS can help us write better code for various scenarios. If you want to learn more about reactive programming with RxJS, you can check out the official documentation =&amp;gt; &lt;a href="https://rxjs.dev/"&gt;RxJs&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>What does the "yield" keyword do in Python and Javascript?</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Tue, 12 Dec 2023 20:27:35 +0000</pubDate>
      <link>https://dev.to/danyson/what-does-the-yield-keyword-do-in-python-and-javascript-p7f</link>
      <guid>https://dev.to/danyson/what-does-the-yield-keyword-do-in-python-and-javascript-p7f</guid>
      <description>&lt;p&gt;The "yield" keyword in both Python and Javascript plays a key role in working with generators, but with some subtle differences:&lt;/p&gt;

&lt;h2&gt;
  
  
  Python:
&lt;/h2&gt;

&lt;p&gt;Function creation: yield is used to create generator functions, which are functions that can pause and resume their execution multiple times, yielding values each time they resume. This allows for memory-efficient iteration over large datasets or lazy evaluation of expressions.&lt;br&gt;
Pausing and resuming: Within a generator function, yield pauses execution and returns a value to the caller. The function can then resume execution when the caller requests the next value using an iterator interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def fibonacci(n):
  a, b = 0, 1
  for _ in range(n):
    yield a
    a, b = b, a + b

# Use the generator with a for loop
for num in fibonacci(10):
  print(num)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code generates the first 10 Fibonacci numbers without storing them all in memory at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Javascript:
&lt;/h2&gt;

&lt;p&gt;Async iteration: yield is used with the async and await keywords to pause and resume execution in asynchronous code. It allows for iterating over asynchronous operations one by one, similar to a regular loop.&lt;br&gt;
Returning values: Similar to Python, yield within an async generator function returns a value to the caller. However, it doesn't pause execution; instead, it signals that the next value is ready when the caller resumes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchUserRepos(username) {
  const response = await fetch(`https://api.github.com/users/${username}/repos`);
  const repos = await response.json();

  for (const repo of repos) {
    yield repo.name;
  }
}

(async () =&amp;gt; {
  const repoNames = [];
  for await (const name of fetchUserRepos('&amp;lt;insert_userName_here&amp;gt;')) {
    repoNames.push(name);
  }
  console.log(repoNames); // Prints all repository names
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code fetches a user's repositories from Github and iterates over them one by one, waiting for each repository to be fetched before proceeding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key differences:
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Feature&lt;/th&gt;
      &lt;th&gt;Python&lt;/th&gt;
      &lt;th&gt;Javascript&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Execution&lt;/td&gt;
      &lt;td&gt;Synchronous&lt;/td&gt;
      &lt;td&gt;Asynchronous&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Value consumption&lt;/td&gt;
      &lt;td&gt;
&lt;code&gt;for&lt;/code&gt; loop or iterators&lt;/td&gt;
      &lt;td&gt;
&lt;code&gt;next()&lt;/code&gt; method&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Generator completion&lt;/td&gt;
      &lt;td&gt;
&lt;code&gt;return&lt;/code&gt; statement or end of function&lt;/td&gt;
      &lt;td&gt;
&lt;code&gt;return&lt;/code&gt; statement or end of function&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Purpose:
&lt;/h2&gt;

&lt;p&gt;In Python, yield is primarily used for memory-efficient iteration and lazy evaluation. In Javascript, it's used for asynchronous iteration and managing control flow in async functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution:
&lt;/h2&gt;

&lt;p&gt;Python's yield pauses execution completely, while Javascript's yield only signals that a value is ready for the caller.&lt;/p&gt;

&lt;p&gt;I hope this clarifies the role of yield in both Python and Javascript. Feel free to ask if you have further questions!&lt;/p&gt;

&lt;p&gt;Website: &lt;a href="https://danyson.netlify.app/"&gt;https://danyson.netlify.app/&lt;/a&gt;&lt;br&gt;
LinkedIn: &lt;a href="https://www.linkedin.com/in/danyson/"&gt;https://www.linkedin.com/in/danyson/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Clean Code Principles - Vadivelu Version 1</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Tue, 05 Dec 2023 21:26:05 +0000</pubDate>
      <link>https://dev.to/danyson/clean-code-principles-vadivelu-version-1-4cb7</link>
      <guid>https://dev.to/danyson/clean-code-principles-vadivelu-version-1-4cb7</guid>
      <description>&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://www.linkedin.com/embed/feed/update/urn:li:ugcPost:7130550886413570048" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--JPv3GsrI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://static.licdn.com/aero-v1/sc/h/c45fy346jw096z9pbphyyhdz7" height="457" class="m-0" width="800"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://www.linkedin.com/embed/feed/update/urn:li:ugcPost:7130550886413570048" rel="noopener noreferrer" class="c-link"&gt;
          Keep it simple Stupid (KISS). Avoid unnecessary complexity in your code. | Danyson Jose posted on the topic | LinkedIn
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          1. Keep it simple Stupid (KISS). Avoid unnecessary complexity in your code. If you can find a simpler way to write something, do it.

2. Single Responsibility…
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--aGQ1YUtN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://static.licdn.com/aero-v1/sc/h/al2o9zrvru7aqj8e1x2rzsrca" width="64" height="64"&gt;
        linkedin.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>programming</category>
      <category>cleancode</category>
      <category>cloudcomputing</category>
      <category>software</category>
    </item>
    <item>
      <title>How to temporarily save your uncommitted changes using Git Stash?</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Tue, 05 Dec 2023 21:08:23 +0000</pubDate>
      <link>https://dev.to/danyson/how-to-temporarily-save-your-uncommitted-changes-using-git-stash-2fho</link>
      <guid>https://dev.to/danyson/how-to-temporarily-save-your-uncommitted-changes-using-git-stash-2fho</guid>
      <description>&lt;p&gt;Use &lt;code&gt;git stash&lt;/code&gt; to temporarily save your uncommitted changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make some changes to your files.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git status&lt;/code&gt; to see that you have uncommitted changes.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git stash&lt;/code&gt; to save your uncommitted changes.&lt;/li&gt;
&lt;li&gt;Make some more changes to your files.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git status&lt;/code&gt; to see that you have uncommitted changes again.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git stash list&lt;/code&gt; to see your stashed changes.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git stash apply&lt;/code&gt; to apply your first stashed changes and restore your working directory to the state it was in before you ran &lt;code&gt;git stash&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git stash pop&lt;/code&gt; to apply your first stashed changes and delete them from the stash.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This trick can be useful if you need to temporarily switch to a different branch or work on another task without losing your uncommitted changes.&lt;/p&gt;

&lt;p&gt;My Website: &lt;a href="https://danyson.netlify.app/"&gt;danyson.netlify.app&lt;/a&gt;&lt;br&gt;
My LinkedIn: &lt;a href="https://www.linkedin.com/in/danyson/"&gt;linkedin/danyson&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Last Write Wins - A Conflict resolution strategy</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Sun, 24 Apr 2022 17:16:59 +0000</pubDate>
      <link>https://dev.to/danyson/last-write-wins-a-conflict-resolution-strategy-2al6</link>
      <guid>https://dev.to/danyson/last-write-wins-a-conflict-resolution-strategy-2al6</guid>
      <description>&lt;p&gt;Imagine, a file or database is written concurrently by 3 processes.&lt;/p&gt;

&lt;p&gt;Eventhough from the user point of view where all the file write processeses happen at the same time, but that doesn't mean all three can co exist in the same file or database field right?&lt;/p&gt;

&lt;p&gt;It will break consistency.&lt;/p&gt;

&lt;p&gt;So, we need to make sure only the last written data as the final data for the file, in a given time.&lt;/p&gt;

&lt;p&gt;How do we consider which data is the last data?&lt;/p&gt;

&lt;p&gt;Timestamp of course!&lt;/p&gt;

&lt;p&gt;Timestamp is used for each write operation to identify which write is the final write.&lt;/p&gt;

&lt;p&gt;MongoDB and Cassandra are examples of having Last Write Wins Strategy.&lt;/p&gt;

&lt;p&gt;More importantly in Cassandra if we are quering an update, each column has its own timestamp value.&lt;/p&gt;

&lt;p&gt;Hope you guys find usefull&lt;/p&gt;

&lt;h1&gt;
  
  
  Support us by &lt;a href="https://www.buymeacoffee.com/dogealgo"&gt;Buying us some Cookies&lt;/a&gt;
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Visit our site &lt;a href="//dogealgo.netlify.app"&gt;Doge Algo&lt;/a&gt;
&lt;/h1&gt;

</description>
      <category>database</category>
      <category>computerscience</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Staged Event Driven Architecture for highly concurrent systems</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Sat, 09 Apr 2022 14:42:13 +0000</pubDate>
      <link>https://dev.to/danyson/staged-event-driven-architecture-for-highly-concurrent-systems-3b99</link>
      <guid>https://dev.to/danyson/staged-event-driven-architecture-for-highly-concurrent-systems-3b99</guid>
      <description>&lt;h3&gt;
  
  
  Brief:
&lt;/h3&gt;

&lt;p&gt;Anything connected to internet has the probability of accessing its resources from anywhere at any given time from any number of users.&lt;/p&gt;

&lt;p&gt;As the "any number of users" translates to the number of users can be from 1 to billion at any given time.&lt;/p&gt;

&lt;p&gt;Arises the question of, how we are going to allocate resources accessible by the users of any number?&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets break things up,
&lt;/h3&gt;

&lt;p&gt;So any number of user can be accessing resources at any time, says clearly the need arises dynamically.&lt;/p&gt;

&lt;p&gt;So lets say we can dynamically increase our resources at any time.&lt;/p&gt;

&lt;p&gt;A fictious controller that is responsible for increasing the resource pool as per the load.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Staged Event driven system:
&lt;/h2&gt;

&lt;p&gt;Consider every call towards the system as Event.&lt;/p&gt;

&lt;p&gt;Each Event can be processed by Network of Stages.&lt;/p&gt;

&lt;p&gt;Why Events should be processed by "Network of Stages"?&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets take HTTP request as an example,
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;A Socket connection Event is established with the server and request is read from Socket&lt;/li&gt;
&lt;li&gt;The HTTP request packet is parsed in HTTP parser &lt;/li&gt;
&lt;li&gt;If the requested data by the HTTP request Event is available in Cache, then Cache hit and proceeds to send response by writing the data to the Socket &lt;/li&gt;
&lt;li&gt;If the requested data by the HTTP request is not available in Cache, then Cache miss, now handle Cache miss by doing an I/O Event to the Database to fetch the Cache missed Data back to system, now system sends data by writing the data to the Socket&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The above 4 steps are general, which is why Events are processed in stages.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Staged event driven HTTP server will look as follows
&lt;/h3&gt;

&lt;p&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%2Fuploads%2Farticles%2F6xjtid3t3jchzje79ibv.png" 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%2Fuploads%2Farticles%2F6xjtid3t3jchzje79ibv.png" alt="Staged event driven HTTP server"&gt;&lt;/a&gt;&lt;br&gt;
                           Figure 1: Staged event driven HTTP server[1]&lt;/p&gt;

&lt;h3&gt;
  
  
  Each stage from above example
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Socket IN&lt;/li&gt;
&lt;li&gt;Data Parser &lt;/li&gt;
&lt;li&gt;Cache &lt;/li&gt;
&lt;li&gt;Database (File I/O)&lt;/li&gt;
&lt;li&gt;Socket OUT&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;as each stage handles their very own Events, each stages will have a Event Queue, Event Handler and Resource Pool Controller&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Event Queue holds events&lt;/li&gt;
&lt;li&gt;Event Handler manages the events by doing enqueue and dequeue operations on the Event Queue&lt;/li&gt;
&lt;li&gt;Resource Pool Controller will allocate the resources like CPU, Network I/O, Memory required by Each Stage 
&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%2Fuploads%2Farticles%2Fe9qeacz6yawv2zzryska.png" alt="SEDA Stage"&gt;
                          Figure 2: SEDA Stage[1]&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Resource Pool Controller can be classified in to two types
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Thread pool controller&lt;/li&gt;
&lt;li&gt;Batching controller&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As the name suggest the Thread pool controller controls the amount of threads running in the pool.&lt;/p&gt;

&lt;p&gt;While the Batch controller controls the number of events processed by Event handlers on their each iterations&lt;/p&gt;

&lt;p&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%2Fuploads%2Farticles%2F4j1y466dvdx1kjgwateb.png" 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%2Fuploads%2Farticles%2F4j1y466dvdx1kjgwateb.png" alt="Thread pool controller &amp;amp; Batching controller"&gt;&lt;/a&gt;&lt;br&gt;
Figure 3:  Thread pool controller[1] and Batching controller[1]&lt;/p&gt;

&lt;p&gt;Reference:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="http://www.sosp.org/2001/papers/welsh.pdf" rel="noopener noreferrer"&gt;http://www.sosp.org/2001/papers/welsh.pdf&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope you guys find usefull&lt;/p&gt;

&lt;h1&gt;
  
  
  Support us by &lt;a href="https://www.buymeacoffee.com/dogealgo" rel="noopener noreferrer"&gt;Buying us some Cookies&lt;/a&gt;
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Visit our site &lt;a href="//dogealgo.netlify.app"&gt;Doge Algo&lt;/a&gt;
&lt;/h1&gt;

</description>
      <category>devops</category>
      <category>database</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Firewall: Egress Filtering with ufw</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Sat, 12 Feb 2022 08:45:15 +0000</pubDate>
      <link>https://dev.to/danyson/firewall-egress-filtering-with-ufw-2038</link>
      <guid>https://dev.to/danyson/firewall-egress-filtering-with-ufw-2038</guid>
      <description>&lt;h3&gt;
  
  
  What is about Firewalls with Egress filtering?
&lt;/h3&gt;

&lt;p&gt;Egress filtering is when we control the traffic leaving our network. Egress filtering limits our outbound traffic flow to a reduced subset by introducing Firewall rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  Which tool we are going to use for implementing Egress Filtering?
&lt;/h3&gt;

&lt;p&gt;We are going to use the &lt;code&gt;ufw&lt;/code&gt; tool which defaults in Ubuntu distros. You can also install &lt;code&gt;ufw&lt;/code&gt; for other Linux distros.&lt;/p&gt;

&lt;p&gt;Lets go root first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo su
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are assuming here that we have a system with Ubuntu,&lt;br&gt;
lets start by enabling &lt;code&gt;ufw&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw enable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why is there a need for Egress Filtering?
&lt;/h3&gt;

&lt;p&gt;Egress filtering restricts the information that you don't want to leak into internet. Whether an internal system is compromised and it shares information to some remote hosts that can we avoided, an information leak may happen due to misconfigurations or network mapping attempts and that can also we avoided.&lt;/p&gt;

&lt;p&gt;Now we are going to block some TCP/UDP ports and IP from establishing outbound connections&lt;/p&gt;

&lt;h3&gt;
  
  
  Trivial File Transfer Protocol - TFTP - UDP - 69
&lt;/h3&gt;

&lt;p&gt;TFTP helps to move files between remote hosts, thus it will be a doorway for the attacker to move their payloads to the compromised system, an unsual connection between your system and a remote host through tftp is an indication of a compromised system&lt;/p&gt;

&lt;p&gt;You can find if any connection established through this port by using the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netstat -anu | grep ":69" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;its better to block its port so that it wont do any outbound communications.&lt;/p&gt;

&lt;p&gt;for that try the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw deny out 69/udp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your firewall is updated with blocking the TFTP on UDP at port 69&lt;/p&gt;

&lt;h3&gt;
  
  
  Syslog - UDP - 514
&lt;/h3&gt;

&lt;p&gt;Syslog operating on UDP at port 514 helps to send logs to a server. Log files may contain sensitive or private information, anytime if you are not sure of any system, you can block syslog from making any oubound connection.&lt;/p&gt;

&lt;p&gt;Try,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw deny out 514/udp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Simple Network Management Protocol – SNMP - UDP - 161-162
&lt;/h3&gt;

&lt;p&gt;SNMP on UDP at port range 161 to 162 is capable of collecting,organizing informations, monitor the network, detect network faults, and sometimes even used to configure remote devices.&lt;/p&gt;

&lt;p&gt;To block SNMP, Try&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw deny out 161:162/udp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  SMTP mail server TCP - 25
&lt;/h3&gt;

&lt;p&gt;Many systems are compromised for to be used as SPAM relays for sending emails. To avoid this we can block all the IPs from accessing TCP port 25 execpt our mail server ip&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw allow from &amp;lt;our-mail-server-ip&amp;gt; to any proto tcp port 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw deny from any to any proto tcp port 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Internet Relay Chat – IRC - TCP 6660-6669
&lt;/h3&gt;

&lt;p&gt;IRC is a network for text-based messaging. An attacker can communicate with the compromised system throuh IRC, eventhough IRC can connect with any port, the most common port ranges are 6660 to 6669.&lt;/p&gt;

&lt;p&gt;Try,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw deny out 6660:6669/tcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Internet Control Message Protocol - ICMP
&lt;/h3&gt;

&lt;p&gt;ICMP is a network layer protocol used by network devices to diagnose network communication issues. ICMP is mainly used to determine whether or not data is reaching its intended destination in a timely manner.&lt;/p&gt;

&lt;p&gt;Using ICMP can lead to three differnt scenarios of vulnerablity&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Echo reply packets (type 0 code 0) are returned by a system in response to receiving Echo Request packets. This is when someone pings our system replies back. An attacker can use this for secret communication channel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An attacker can ping a network with its connected hosts and look for host unreachable (type 3 code 1) reply from the network to identify which hosts are offline and which are online which in turn becomes a network mapping tool for the attacker.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Time Exceeded in Transit (type 11 code 0) Network mapping tools like traceroute, tracert, Firewalk and tcptraceroute map all of the routers between a source and a target host by creating modified packets with having abnormal low Time To Live (TTL). So the routing devices in its path return ICMP time exceeded.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As usual got root with,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo su
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets take a back up of our firewall rules&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp /etc/ufw/before.rules /etc/ufw/before.rules_backup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vi /etc/ufw/before.rules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which will output as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ok icmp codes for INPUT
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT
-A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT
-A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT
-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT
-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;try changing like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ok icmp codes for INPUT
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j DROP
-A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT
-A ufw-before-input -p icmp --icmp-type time-exceeded -j DROP
-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT
-A ufw-before-input -p icmp --icmp-type echo-request -j DROP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then reload the firewall&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope you guys find usefull&lt;/p&gt;

&lt;h1&gt;
  
  
  Support us by &lt;a href="https://www.buymeacoffee.com/dogealgo"&gt;Buying us some Cookies&lt;/a&gt;
&lt;/h1&gt;

</description>
      <category>ubuntu</category>
      <category>beginners</category>
      <category>linux</category>
      <category>security</category>
    </item>
    <item>
      <title>How do I undo 'git add'?</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Sat, 29 Jan 2022 14:14:43 +0000</pubDate>
      <link>https://dev.to/danyson/how-do-i-undo-git-add-5c6e</link>
      <guid>https://dev.to/danyson/how-do-i-undo-git-add-5c6e</guid>
      <description>&lt;p&gt;Lets say we either did a &lt;code&gt;git add &amp;lt;file-name&amp;gt;&lt;/code&gt; to stage a specific modified file or &lt;code&gt;git add .&lt;/code&gt; to stage all the modified files.&lt;/p&gt;

&lt;p&gt;We may consider &lt;code&gt;git reset&lt;/code&gt; but we must do git reset only if we are trying to unstage "a change" in the file.&lt;/p&gt;

&lt;p&gt;When we need to just unstage the file. &lt;/p&gt;

&lt;p&gt;Good practice is, &lt;/p&gt;

&lt;p&gt;if we done a &lt;code&gt;git add &amp;lt;file-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then the solution is &lt;code&gt;git rm --cached&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;if we done a &lt;code&gt;git add .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then the solution is &lt;code&gt;git rm -r --cached&lt;/code&gt;, as the &lt;code&gt;git add .&lt;/code&gt; is recursive, we need to bring in the flag &lt;code&gt;-r&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Support Us: &lt;a href="https://www.buymeacoffee.com/dogealgo"&gt;Buy Me a Cookie 🍪&lt;/a&gt;
&lt;/h1&gt;

</description>
      <category>beginners</category>
      <category>git</category>
      <category>codenewbie</category>
      <category>devops</category>
    </item>
    <item>
      <title>What is the difference between 'git pull' and 'git fetch'?</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Sat, 29 Jan 2022 13:58:11 +0000</pubDate>
      <link>https://dev.to/danyson/what-is-the-difference-between-git-pull-and-git-fetch-548e</link>
      <guid>https://dev.to/danyson/what-is-the-difference-between-git-pull-and-git-fetch-548e</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git fetch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;code&gt;git fetch&lt;/code&gt; fetches commits from the target branch that is not in our current local branch and stores them in our local repository. &lt;/p&gt;

&lt;p&gt;It does not merge. Which means we have the changes from target branch but not yet merged to our local branch.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;code&gt;git pull&lt;/code&gt; does both &lt;code&gt;git fetch&lt;/code&gt; and &lt;code&gt;git merge&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Which means changes from target branch will be fetched and merged to our local branch.&lt;/p&gt;

&lt;h1&gt;
  
  
  Support Us: &lt;a href="https://www.buymeacoffee.com/dogealgo"&gt;Buy Me a Cookie 🍪&lt;/a&gt;
&lt;/h1&gt;

</description>
      <category>git</category>
      <category>devops</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Micro Frontends</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Sun, 09 Jan 2022 19:14:45 +0000</pubDate>
      <link>https://dev.to/danyson/micro-front-ends-2f41</link>
      <guid>https://dev.to/danyson/micro-front-ends-2f41</guid>
      <description>&lt;p&gt;&lt;strong&gt;We all familiar with the term Micro Services&lt;/strong&gt;, lot of organizations adapted this pattern to decompose their monolith back-end applications in to seperate entities based on their functions, that can be coveniently developed, tested and deployed with lot of other services.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;While the Front-end mostly kept Monolith.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Now what if we apply this pattern of decomposing a monolith Front-end application to many pieces of Front-end applications?&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let's discuss few scenarios:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A company with lot of experience on CRM applications developed with an very old legacy Native HTML, CSS and JS wants to taste the Latest Angular or React&lt;/li&gt;
&lt;li&gt;A complex food ordering and delivery company with a Front-end that handles ordering, delivery and listing restaurants with their foods needs to manage the code base complex free among various teams working on the same monolith Front-end&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;There can be a solution as mentioned by the below image from Thoughtworks latest article on Micro Front-ends&lt;/em&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0DjMWlOh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxbrsxo86e2rce2ceeyp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0DjMWlOh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxbrsxo86e2rce2ceeyp.png" alt="Micro Front-ends Block Diagram" width="724" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now the question arises, how these different blocks of front end applications route among themselves?&lt;br&gt;
There is one such example as the Thoughtworks article discusses with the term as follows&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Cross Application Routing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f3nLWK1v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/puro59aehg2uzld8f3zq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f3nLWK1v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/puro59aehg2uzld8f3zq.png" alt="Cross Application Routing" width="622" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Benifits:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Adopting this pattern can lead to much smaller source code of each individual micro frontend  than that of source code of a single monolithic frontend. &lt;/li&gt;
&lt;li&gt;These smaller codebases can be  simple and easy to develop for developers. &lt;/li&gt;
&lt;li&gt;We can avoid the complexity due to unwanted coupling between components that needs to be hidden.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Possible Downsides:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Increased Payload size due to different JS bundles.
&lt;strong&gt;Solution:&lt;/strong&gt; &lt;em&gt;The integration team should know about the possible bottlenecks&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The situation where multiple teams working on differnt components face a co-ordination crisis&lt;br&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; &lt;em&gt;An intense Test driven Production like deployment cycle must be followed before the actual production deployment&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Final thing is to consider is how we are going to manage when the Micro Frontend components gets increased in numbers?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Support Us: &lt;a href="https://www.buymeacoffee.com/dogealgo"&gt;Buy Me a Book&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Explore more on&lt;/strong&gt;&lt;/em&gt; &lt;a href="https://dogealgo.netlify.app/"&gt;dogealgo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://martinfowler.com/articles/micro-frontends.html"&gt;https://martinfowler.com/articles/micro-frontends.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>docker</category>
    </item>
    <item>
      <title>How to delete remote commits in git?</title>
      <dc:creator>Danyson</dc:creator>
      <pubDate>Thu, 06 Jan 2022 18:00:54 +0000</pubDate>
      <link>https://dev.to/danyson/how-to-delete-remote-commits-in-git-11h0</link>
      <guid>https://dev.to/danyson/how-to-delete-remote-commits-in-git-11h0</guid>
      <description>&lt;p&gt;Assume you have pushed commits in order A1 =&amp;gt; B2 =&amp;gt; C3 in remote repository.&lt;/p&gt;

&lt;p&gt;Now you want to delete commits C3 and B2.&lt;/p&gt;

&lt;p&gt;The simple solution is as follows using  &lt;code&gt;git reset&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; git reset --hard &amp;lt;A1-commit-id&amp;gt;
 git push -f origin &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, you should avoid doing this if anyone else is working with your remote repository and has pulled your changes C3 and B2.&lt;/p&gt;

&lt;p&gt;That's where &lt;code&gt;git revert&lt;/code&gt; comes in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git revert --no-commit C3
git revert --no-commit B2
git commit -m "commit message for your reverts"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Avail My IT Services on&lt;/strong&gt; &lt;a href="https://danyson.netlify.app/"&gt;https://danyson.netlify.app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
