<?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: Mohd Ahshan Danish</title>
    <description>The latest articles on DEV Community by Mohd Ahshan Danish (@mailtodanish).</description>
    <link>https://dev.to/mailtodanish</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%2F941984%2F0d08803a-b328-4cdb-8c5f-328cdee0ae8a.png</url>
      <title>DEV Community: Mohd Ahshan Danish</title>
      <link>https://dev.to/mailtodanish</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mailtodanish"/>
    <language>en</language>
    <item>
      <title>Backup, Empty and Restore CRONTAB</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Fri, 23 Feb 2024 05:38:26 +0000</pubDate>
      <link>https://dev.to/mailtodanish/backup-empty-and-restore-crontab-2kb8</link>
      <guid>https://dev.to/mailtodanish/backup-empty-and-restore-crontab-2kb8</guid>
      <description>&lt;p&gt;It is always very challenging to stop and restart crontab. Below are the commands to backup and restore crontab 😀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvufnjys97ds99t4hfpu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvufnjys97ds99t4hfpu.png" alt="Image description" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>flatMap vs map in Array</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Sun, 21 Jan 2024 13:51:56 +0000</pubDate>
      <link>https://dev.to/mailtodanish/flatmap-vs-map-in-array-4jhp</link>
      <guid>https://dev.to/mailtodanish/flatmap-vs-map-in-array-4jhp</guid>
      <description>&lt;p&gt;&lt;strong&gt;flatMap&lt;/strong&gt;: It is identical to a map() followed by a flat() of depth 1 (arr.map(...args).flat()), but slightly more efficient than calling those two methods separately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let LIST = [1,2,3];
let processedLst = LIST.flatMap((route) =&amp;gt; {
    return [route, route];
  }).filter(Boolean);
console.log(processedLst)
// [ 1, 1, 2, 2, 3, 3 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;map:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let LIST = [1,2,3];
let processedLst = LIST.map((route) =&amp;gt; {
    return [route, route];
  }).filter(Boolean);
console.log(processedLst)
//[ [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;flat()&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;processedLst.flat()
//[ 1, 1, 2, 2, 3, 3 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;br&gt;
&lt;strong&gt;So follow me on&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/mohdahshandanish/"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Default CSS for Img</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Sat, 23 Dec 2023 17:16:04 +0000</pubDate>
      <link>https://dev.to/mailtodanish/default-css-for-img-26em</link>
      <guid>https://dev.to/mailtodanish/default-css-for-img-26em</guid>
      <description>&lt;p&gt;Default css for rendering image properly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;max-width:100%&lt;/strong&gt;&lt;br&gt;
(container size is smaller then image)&lt;br&gt;
&lt;strong&gt;hight:auto&lt;/strong&gt;&lt;br&gt;
(maintain aspect ration)&lt;br&gt;
&lt;strong&gt;vertical-align:middle&lt;/strong&gt;&lt;br&gt;
(image will not have empty space in bottom)&lt;br&gt;
&lt;strong&gt;front-style:italic&lt;/strong&gt;&lt;br&gt;
(alt text)&lt;br&gt;
&lt;strong&gt;background-repeat:no repeat;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;background-size : cover&lt;/strong&gt;&lt;br&gt;
(low quality image)&lt;br&gt;
&lt;strong&gt;shape-margin: 0.5rem&lt;/strong&gt;&lt;br&gt;
(margin)&lt;/p&gt;

</description>
      <category>css</category>
    </item>
    <item>
      <title>Solution for 'await is only valid in async functions'</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Fri, 22 Dec 2023 17:07:40 +0000</pubDate>
      <link>https://dev.to/mailtodanish/solution-for-await-is-only-valid-in-async-functions-1coj</link>
      <guid>https://dev.to/mailtodanish/solution-for-await-is-only-valid-in-async-functions-1coj</guid>
      <description>&lt;p&gt;We can only execute &lt;code&gt;await&lt;/code&gt; inside an async function. If you try to use await without an async function, it will result in an error. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qgC4rN-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xtakzo82gjhrof0x1xj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qgC4rN-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xtakzo82gjhrof0x1xj.png" alt="code" width="800" height="547"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; One good option to address this issue is by using IIFE (Immediately Invoked Function Expression).&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(){
    let a = await testSleep();
    console.log(a);
   let b = await testSleep();
    console.log(b);
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Problem with for in</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Sun, 17 Dec 2023 08:10:44 +0000</pubDate>
      <link>https://dev.to/mailtodanish/problem-with-for-in-cb8</link>
      <guid>https://dev.to/mailtodanish/problem-with-for-in-cb8</guid>
      <description>&lt;p&gt;We have an instance of Obj1. This instance has attributes name and age. When we print obj1, it returns the instance properties of the object, only name and not the age. However, Obj1's prototype also has a property age, and that property is not directly accessible through the instance of obj1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function obj1(){
    this.name= "myName";
}
obj1.prototype.age = 10;
const i = new obj1();
console.error(i);
// obj1 { name: 'myName' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but when we do for in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(let prop in i){
   console.error(prop); 
}
// name and age both property is present
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Problem with for in is that it returns not only instance property of object but also all properties it inherit through prototype.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: we can use hasOwnProperty for instance property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(let prop in i){
    if(i.hasOwnProperty(prop)) console.error(prop); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;br&gt;
So follow me on &lt;a href="https://www.linkedin.com/in/mohdahshandanish/"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>groupBy in JS</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Sun, 17 Dec 2023 04:08:30 +0000</pubDate>
      <link>https://dev.to/mailtodanish/groupby-in-js-40eb</link>
      <guid>https://dev.to/mailtodanish/groupby-in-js-40eb</guid>
      <description>&lt;p&gt;Object.groupBy is a recently released method in JavaScript and it is a useful function for manipulating objects and collections. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sbtmZ7wo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzunsbjtbin76egurc6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sbtmZ7wo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzunsbjtbin76egurc6z.png" alt="code" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pCvBh9_a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6ipkufpjuyu46dnb16p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pCvBh9_a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6ipkufpjuyu46dnb16p.png" alt="output" width="401" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: We can pass a complex function as a parameter to the groupBy method for manipulation.&lt;/p&gt;

&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;br&gt;
So follow me on &lt;a href="https://www.linkedin.com/in/mohdahshandanish/"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>toSorted() vs sort()</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Fri, 15 Dec 2023 01:12:21 +0000</pubDate>
      <link>https://dev.to/mailtodanish/tosorted-vs-sort-898</link>
      <guid>https://dev.to/mailtodanish/tosorted-vs-sort-898</guid>
      <description>&lt;p&gt;toSorted() is a recently released method that creates a copy of the existing array and returns a new array. Unlike the sort() function, toSorted() does not alter the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//  sort
const array1 = [ { name: "k", age: 12 } ,{ name: "a", age: 14 }, { name: "b", age: 14 }, { name: "c", age: 13 }, { name: "d", age: 13 }, { name: "e", age: 13 }, { name: "f", age: 13 }, { name: "g", age: 13 }, { name: "h", age: 13 }, { name: "i", age: 12 }, { name: "j", age: 12 }, ]

array1.**sort**( (a,b) =&amp;gt; a.age - b.age)
console.error(array1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;[&lt;br&gt;
  { name: 'k', age: 12 },&lt;br&gt;
  { name: 'i', age: 12 },&lt;br&gt;
  { name: 'j', age: 12 },&lt;br&gt;
  { name: 'c', age: 13 },&lt;br&gt;
  { name: 'd', age: 13 },&lt;br&gt;
  { name: 'e', age: 13 },&lt;br&gt;
  { name: 'f', age: 13 },&lt;br&gt;
  { name: 'g', age: 13 },&lt;br&gt;
  { name: 'h', age: 13 },&lt;br&gt;
  { name: 'a', age: 14 },&lt;br&gt;
  { name: 'b', age: 14 }&lt;br&gt;
]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;toSorted:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mXo7wCJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iztssawmx7vfdx7i0qee.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mXo7wCJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iztssawmx7vfdx7i0qee.png" alt="toSorted" width="800" height="285"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BOuEh3b9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9d7d96hkqdsupirejp4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BOuEh3b9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9d7d96hkqdsupirejp4a.png" alt="outpur" width="482" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see the original array has not been modified.&lt;/p&gt;

&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;br&gt;
&lt;strong&gt;So follow me on&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/mohdahshandanish/"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>null !== undefined</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Wed, 13 Dec 2023 00:49:30 +0000</pubDate>
      <link>https://dev.to/mailtodanish/null-undefined-196l</link>
      <guid>https://dev.to/mailtodanish/null-undefined-196l</guid>
      <description>&lt;p&gt;I have noticed that many developers struggle with the  appropriate use of "null" and "undefined" in JavaScript.&lt;/p&gt;

&lt;p&gt;"Null" refers to the absence of any object value. It is primarily used when an object is not present.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.log(typeof null) // 'object'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;"Undefined" is used when something is not defined. If any attribute in an API is missing, it will be considered as "undefined".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let i;
console.error(typeof i) // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is important to always compare attribute values with "undefined" when processing API responses.  &lt;/p&gt;

&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;/p&gt;

&lt;p&gt;So follow me on &lt;a href="https://www.linkedin.com/mynetwork/discovery-see-all/?usecase=PEOPLE_FOLLOWS&amp;amp;followMember=mohdahshandanish"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Function Scope in JS</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Tue, 12 Dec 2023 02:05:01 +0000</pubDate>
      <link>https://dev.to/mailtodanish/function-scope-in-js-34c5</link>
      <guid>https://dev.to/mailtodanish/function-scope-in-js-34c5</guid>
      <description>&lt;p&gt;Functions in Javascript run in the scope they are defined, not in the scope they are executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var baz;
(function() {
  baz = function() {
    return foo * bar;
  };
  var foo = 20;
  var bar = 2;
})();

console.error(baz());

//output: 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;/p&gt;

&lt;p&gt;So follow me on &lt;a href="https://www.linkedin.com/mynetwork/discovery-see-all/?usecase=PEOPLE_FOLLOWS&amp;amp;followMember=mohdahshandanish"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>SFTP vs FTPS</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Tue, 12 Dec 2023 01:14:46 +0000</pubDate>
      <link>https://dev.to/mailtodanish/sftp-vs-ftps-2hi5</link>
      <guid>https://dev.to/mailtodanish/sftp-vs-ftps-2hi5</guid>
      <description>&lt;p&gt;Recently, I have finished working on an SFTP file transfer implementation. While learning and exploring both SFTP and FTPS protocols,I discovered that we often get confused between SFTP and FTPS.&lt;/p&gt;

&lt;p&gt;FTP and SFTP enable secure file access, but they differ in certain ways. &lt;/p&gt;

&lt;p&gt;SFTP is secure, fully encrypted, and securely integrated with firewalls.&lt;/p&gt;

&lt;p&gt;FTPS, on the other hand, add a layer of encryption using SSL or TLS. It offers faster file transfer compared to SFTP.&lt;/p&gt;

&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;/p&gt;

&lt;p&gt;So follow me on &lt;a href="https://www.linkedin.com/mynetwork/discovery-see-all/?usecase=PEOPLE_FOLLOWS&amp;amp;followMember=mohdahshandanish"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Indent the output of 𝐉𝐒𝐎𝐍.𝐬𝐭𝐫𝐢𝐧𝐠𝐢𝐟𝐲</title>
      <dc:creator>Mohd Ahshan Danish</dc:creator>
      <pubDate>Tue, 12 Dec 2023 00:36:01 +0000</pubDate>
      <link>https://dev.to/mailtodanish/indent-the-output-of--3364</link>
      <guid>https://dev.to/mailtodanish/indent-the-output-of--3364</guid>
      <description>&lt;p&gt;While working with the Oracle Field Service plugin in Javascript, I have observed that many developers use 𝐜𝐨𝐧𝐬𝐨𝐥𝐞.𝐥𝐨𝐠(𝐉𝐒𝐎𝐍.𝐬𝐭𝐫𝐢𝐧𝐠𝐢𝐟𝐲()) and struggle with the structure of objects on the console. The 𝐉𝐒𝐎𝐍.𝐬𝐭𝐫𝐢𝐧𝐠𝐢𝐟𝐲() method provides an option to properly indent the output on the console for debugging, which can be very helpful for understanding the structure of the objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// JSON.stringify 
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
console.log(JSON.stringify(person));
/*
output
  {"firstName":"John","lastName":"Doe","age":50,"eyeColor":"blue"}
*/

// Indent the output with one space
console.log(JSON.stringify(person,null,"\t"));
/*
output
  {
    "firstName": "John",
    "lastName": "Doe",
    "age": 50,
    "eyeColor": "blue"
}
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will be posting tricks I have been using in my journey.&lt;/p&gt;

&lt;p&gt;So follow me on &lt;a href="https://www.linkedin.com/mynetwork/discovery-see-all/?usecase=PEOPLE_FOLLOWS&amp;amp;followMember=mohdahshandanish"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
