<?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: Hashir Baig</title>
    <description>The latest articles on DEV Community by Hashir Baig (@imhashir).</description>
    <link>https://dev.to/imhashir</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%2F186782%2F1f70e4eb-d720-47a1-9ae5-59ce1f6be364.png</url>
      <title>DEV Community: Hashir Baig</title>
      <link>https://dev.to/imhashir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imhashir"/>
    <language>en</language>
    <item>
      <title>name2mime - A simple node package to get MIME types of file</title>
      <dc:creator>Hashir Baig</dc:creator>
      <pubDate>Sat, 23 May 2020 20:59:25 +0000</pubDate>
      <link>https://dev.to/imhashir/name2mime-a-simple-node-package-to-get-mime-types-of-file-3b28</link>
      <guid>https://dev.to/imhashir/name2mime-a-simple-node-package-to-get-mime-types-of-file-3b28</guid>
      <description>&lt;h1&gt;
  
  
  Background
&lt;/h1&gt;

&lt;p&gt;So I recently had a client who wanted a &lt;a href="https://aws.amazon.com/lambda/"&gt;Lambda&lt;/a&gt; trigger on his &lt;a href="https://aws.amazon.com/s3"&gt;S3&lt;/a&gt; bucket which writes some files to a directory in his bucket. Everything was going well, except that the content type of all the files was being set to &lt;code&gt;application/octet-stream&lt;/code&gt;. So he wanted me to fix this issue such that when we put the object in the bucket, the ContentType gets set to an appropriate one. I thought it'll hardly take an hour. All I'd have to do is to search for a node package, install it and the issue is solved. But nope. NOPE!&lt;/p&gt;

&lt;h1&gt;
  
  
  Exiting solutions
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://www.npmjs.com/package/mmmagic"&gt;mmmagic&lt;/a&gt;:&lt;br&gt;
It's a great package, uses C-language binding behind the scene, takes file buffer as input, and spits out a lot of metadata about a file. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limitations&lt;/strong&gt;: When passed an SVG/DXF, it categorizes them as text/html. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://www.npmjs.com/package/file-type"&gt;file-type&lt;/a&gt;:&lt;br&gt;
It also takes a file buffer as input and returns MIME type. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limitations&lt;/strong&gt;: When passed an SVG/DXF or some other kind of files, it retuns &lt;code&gt;null/undefined&lt;/code&gt;. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://www.npmjs.com/package/mime-kind"&gt;mime-kind&lt;/a&gt;:&lt;br&gt;
It takes a file buffer and a default value as input and if the file type is not determined, it returns that default value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limitations&lt;/strong&gt;: Same results here, it was assigning that default value for SVF/DXF and some other files.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/fabiospampinato/ext2mime"&gt;ext2mime&lt;/a&gt;:&lt;br&gt;
This one works similar in fashion to the one I created. It takes in files name and spits out its MIME types.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limitations&lt;/strong&gt;: The dataset of extensions was very limited and couldn't recognize all kinds of files.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  600+ extensions supported
&lt;/h1&gt;

&lt;p&gt;No credits to me. Thanks to the good guys at &lt;a href="https://www.freeformatter.com/mime-types-list.html"&gt;FreeFormatter&lt;/a&gt;. I wrote a simple script in the browser console to extract all the extensions from their site.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.write(JSON.stringify(Array.from(document.getElementsByClassName('bordered-table zebra-striped table-sort')[0].children[1].children).reduce((obj, row) =&amp;gt; {
    let objs = {...obj};
    row.children[2].childNodes[0].data.split(', ').map(ext =&amp;gt; objs = objs[ext] ? objs : ({...objs, [ext]: {'type': row.children[1].childNodes[0].data, 'name': row.children[0].childNodes[0].data}}))
    return objs;
}, {})))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2lhc5Sve--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/nvcar34stxwm9dicvm04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2lhc5Sve--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/nvcar34stxwm9dicvm04.png" alt="The Magic Script" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hit ENTER!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X4eUjoX1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/o48nig2hluwg5nt7e0zf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X4eUjoX1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/o48nig2hluwg5nt7e0zf.png" alt="The MAGIC Itself" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Building the idea into an NPM package
&lt;/h1&gt;

&lt;p&gt;I used &lt;a href="https://github.com/flexdinesh/npm-module-boilerplate"&gt;this&lt;/a&gt; amazing boilerplate code to build my NPM package. It already had template for test cases and &lt;a href="https://travis-ci.org/"&gt;Travis-CI&lt;/a&gt;, so whenever I push my code to github, it automatically runs test cases and updates the status on my repo homepage. Amazing isn't it?&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;name2mime &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn add name2mime
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Sample
&lt;/h1&gt;



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

const value = getMime('filename.jpg');

console.log(value);

// { type: 'image/jpeg', name: 'JPEG Image' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  For Maintainers &amp;amp; Contributors
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm run clean&lt;/code&gt; - Remove &lt;code&gt;lib/&lt;/code&gt; directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm test&lt;/code&gt; - Run tests with linting and coverage results.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm test:only&lt;/code&gt; - Run tests without linting or coverage.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm test:watch&lt;/code&gt; - You can even re-run tests on file changes!&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm test:prod&lt;/code&gt; - Run tests with minified code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run test:examples&lt;/code&gt; - Test written examples on pure JS for better understanding module usage.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run lint&lt;/code&gt; - Run ESlint with airbnb-config&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run cover&lt;/code&gt; - Get coverage report for your code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run build&lt;/code&gt; - Babel will transpile ES6 =&amp;gt; ES5 and minify the code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run prepublish&lt;/code&gt; - Hook for npm. Do all the checks before publishing your module.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>mime</category>
      <category>npm</category>
      <category>javascript</category>
    </item>
    <item>
      <title>I took 30 apps in 30 days challenge with flutter, I failed and I don't regret</title>
      <dc:creator>Hashir Baig</dc:creator>
      <pubDate>Tue, 20 Aug 2019 07:19:44 +0000</pubDate>
      <link>https://dev.to/imhashir/i-took-30-apps-in-30-days-challenge-with-flutter-i-failed-and-i-don-t-regret-181o</link>
      <guid>https://dev.to/imhashir/i-took-30-apps-in-30-days-challenge-with-flutter-i-failed-and-i-don-t-regret-181o</guid>
      <description>&lt;h1&gt;
  
  
  My Intro
&lt;/h1&gt;

&lt;p&gt;Just for a brief introduction of mine, I am an Android developer for more than about two years now. I have been developing apps as a hobby and as a freelancer. Natively!!! &lt;/p&gt;

&lt;h3&gt;
  
  
  The battle between Native and cross platform
&lt;/h3&gt;

&lt;p&gt;I have always been a great advocate of Native App development and always considered Cross-platform or hybrid solutions as cheaper solutions resulting in lower quality apps. Not that I never tried developing a cross-platform app. I did. Using React Native. But I was disappointed. I am not questioning the capabilities of React Native. They might be really good. But designing user interface of React Native was a pain for me. Maybe due to my lack of experience in React Native but I just didn't like that experience. So I never worked on React Native again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flutter, the beauty
&lt;/h3&gt;

&lt;p&gt;But here comes flutter. Google was crazily promoting this framework. They have a dedicated youtube channel for flutter where they post podcasts and short tutorials almost daily. Initially, I was like "Why have they introduced a cross-platform solution, they'll kill native development with their bare hands. Urrghhhh!!!!". Yeah 🤐 Sorry for that. This is how crazy I was in favor of Native development. But seeing flutter videos in my recommendation almost on a daily basis urged me to give this framework a try. (Googleee!!! You won. You prediction played very well with my mind)&lt;/p&gt;

&lt;h3&gt;
  
  
  The mission, the failed one
&lt;/h3&gt;

&lt;p&gt;I was kinda free these days. Recently graduated. So I decided to take on a challenge that was previously taken by another guy. This is his &lt;a href="https://medium.com/@gpj/30-apps-in-30-days-6686a570e90"&gt;post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This man did an amazing job and his post really inspired me. So I decided to take on this challenge. I wanted to have some well defined criteria in mind for apps. Because its easy to publish one app per day if I am just publishing plain empty activities.&lt;/p&gt;

&lt;p&gt;So here was my criteria. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The apps will have internet connectivity&lt;/li&gt;
&lt;li&gt;Apps will have user authetication&lt;/li&gt;
&lt;li&gt;Apps must perform some read/write operation on some database (firebase in my case)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The journey began - The First App!
&lt;/h3&gt;

&lt;p&gt;I started working on my first app. Note that this is the first-ever app I am going to develop on Flutter. And my goal is to publish this app in 24 hours. Yes.  So I worked on it. Worked on it. And everything just seemed to work. Layouts, lists, formatting, styling, everything was beautiful. Everything went smoother than expected. And it was so much less code than I was used to writing natively. I knew I am already in love with flutter. But it took me about 30 hours (including other activities like going for food or just some rest) to complete and publish the app. But I did. And here it is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.meethashirb.moment_share"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_IXfh54l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/HqETnzw.png" alt="N|Solid" width="576" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.meethashirb.moment_share"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PjqUfVYR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/q9kkw47.png" alt="N|Solid" width="338" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mission continues - The second App!
&lt;/h3&gt;

&lt;p&gt;Feeling motivated after publishing my first app, I moved on towards my second one. Not denying that I was mentally tired after those hours of extreme coding, but lets continue. This time, I discovered something else in Flutter. The ANIMATIONS!!! This was kind of a no go area for me in my whole two years of Android development. Because the time it requires in building a simple feature in native development is always so much that one can hardly imagine adding even more beauty in terms of animations. But in flutter, I thought why not give it a try. And I did. And I don't regret that decision. It's amazingly beautiful and extremely easy. Flutter renders UI in 60 FPS so the animations are buttery smooth. And here goes my second application. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.meethashirb.feels"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vkqQlslD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/vq1P2UO.png" alt="N|Solid" width="376" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.meethashirb.feels"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PjqUfVYR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/q9kkw47.png" alt="N|Solid" width="338" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Beautiful, isn't it? Trust me. This is the most favorite app of mine. And the idea of it is even more beautiful. I've written a separate article on this app. Being my most favorite app, I worked on it later as well. So the current state of this app on Play Store is a bit more evolved than what I developed that day.&lt;br&gt;
Feel free to read more about this app here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@hashirbaig/how-the-world-feels-today-f342e16982b1"&gt;How the World Feels today!&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Continuing the mission - The third and last one!
&lt;/h3&gt;

&lt;p&gt;At this moment, I was extremely tired. Building that second app made me so tired that I wasn't able even to look at my screen. I was feeling bad at getting tired so early but I somehow started this third app. But this time, my goal wasn't to publish this app in a day. I wanted to publish a good app. I was willing to give it the time it deserves. And it took 3 days. Not saying this was the most complex app. I was just too tired to work with the same speed (And I was going crazy with animation, I wanted to add animation everywhere, like a cook who adds his favorite ingredient in every dish he makes). No doubt I removed a lot of animations along the way because it felt like I was overdoing it. But.... I was enjoying it. So it felt fine. And after three days, this app was published.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.meethashirb.vise"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Bf_pS0e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/tON3dFx.png" alt="N|Solid" width="288" height="479"&gt;&lt;/a&gt; &lt;a href="https://play.google.com/store/apps/details?id=com.meethashirb.vise"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BaAZ3FMA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/kvTfZ7z.png" alt="N|Solid" width="288" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.meethashirb.vise"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PjqUfVYR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/q9kkw47.png" alt="N|Solid" width="338" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The mission ends
&lt;/h2&gt;

&lt;p&gt;At this moment, I knew that I wasn't going to publish 30 apps in 30 days. But I was so happy that I opted flutter for my quest. I don't think if I can ever work natively again. If given choice, I'll choose flutter any day. As of right now, I am so happy for getting my hands dirty with flutter. &lt;/p&gt;

</description>
      <category>android</category>
      <category>flutter</category>
      <category>dart</category>
      <category>flutterio</category>
    </item>
  </channel>
</rss>
