<?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: Deepak JOSHI</title>
    <description>The latest articles on DEV Community by Deepak JOSHI (@deepakpro).</description>
    <link>https://dev.to/deepakpro</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%2F314327%2F58871f16-1536-4796-9598-76ef52e23fd3.jpg</url>
      <title>DEV Community: Deepak JOSHI</title>
      <link>https://dev.to/deepakpro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deepakpro"/>
    <language>en</language>
    <item>
      <title>Recreating Whatsapp UI with SwiftUI [Settings Tab]</title>
      <dc:creator>Deepak JOSHI</dc:creator>
      <pubDate>Tue, 29 Sep 2020 03:30:00 +0000</pubDate>
      <link>https://dev.to/deepakpro/recreating-whatsapp-ui-with-swiftui-settings-tab-2hj</link>
      <guid>https://dev.to/deepakpro/recreating-whatsapp-ui-with-swiftui-settings-tab-2hj</guid>
      <description>&lt;p&gt;TL;DR: Source code is available on GitHub. &lt;a href="https://github.com/deepak-pro/whatsappSimple-SwiftUI" rel="noopener noreferrer"&gt;https://github.com/deepak-pro/whatsappSimple-SwiftUI&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Learning a new framework is always exiting but following a proper tutorial path over a month is pretty boring and to learn something quick the best approach is to create a project. In the case of SwiftUI, I can guarantee the excitement is on another level. The simplicity of SwiftUI allows us to develop the user interface quickly without even thinking about layout and constraints.&lt;/p&gt;

&lt;p&gt;So let’s create a project.&lt;/p&gt;

&lt;p&gt;I want to keep this blog simple and quick just like SwiftUI, so we will not waste our time revising how to click on File &amp;gt; New &amp;gt; Project .. Blah… Blah… Blah… But wait remember to select SwiftUI as Interface.&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%2Fi%2Fhs5g9vkj9aca83k1k7dq.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%2Fi%2Fhs5g9vkj9aca83k1k7dq.png" alt="1_HgS7rdj9OyP2qOu39hexLw"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To develop UI of the settings tab of Whatsapp. We need to learn about some Views of SwiftUI:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;TabView: For creating Tab Bar&lt;/li&gt;
&lt;li&gt;NaviationView: For creating a Navigation bar with title 1. and bar button items.&lt;/li&gt;
&lt;li&gt;Form: To create different sections.&lt;/li&gt;
&lt;li&gt;HStack: To group views horizontally.&lt;/li&gt;
&lt;li&gt;VStack: To group views vertically.&lt;/li&gt;
&lt;li&gt;Image: To display an image.&lt;/li&gt;
&lt;li&gt;Text: To display text.&lt;/li&gt;
&lt;li&gt;Button: To create a button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Enough explanation, Now let’s jump right into coding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Tab Bar
&lt;/h3&gt;

&lt;p&gt;TabView is used to create a tab bar. Here we are only creating one tab.&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%2Fi%2Fd77u2ow8n9ehk7b915gw.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%2Fi%2Fd77u2ow8n9ehk7b915gw.png" alt="1_YhDdZ93R63r7nluEjQ2eWg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To keep things organized, we will create a new SwiftUI View for settings. (As we are using TabView and there can be many views). Name it as SettingsView.swift. Also replace the Text(“Hello, world!”) with SettingsView().&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating NavigationView
&lt;/h3&gt;

&lt;p&gt;Now we will create NavigationView with modifiers to set navigation title and a button for QR code in navigation bar items.&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%2Fi%2Fnkgqwz49n0avnxrjtudh.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%2Fi%2Fnkgqwz49n0avnxrjtudh.png" alt="1_6M8RaTzO7o1W_UghJFXXkg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the preview of ContentView.swift&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%2Fi%2Fe3n3idp32s5zpovmfz17.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%2Fi%2Fe3n3idp32s5zpovmfz17.png" alt="1_m8yYmaqh5RIXcIhquY5RGw"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Form
&lt;/h3&gt;

&lt;p&gt;Form in SwiftUI helps up to group views systematically. First Section to group profile picture name and about. I have imported an image named profile in Assets.xcassets.&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%2Fi%2Fx6jjmm0y3yajslo1lkmx.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%2Fi%2Fx6jjmm0y3yajslo1lkmx.png" alt="1_SBsgJmVs3qS3z06zPsI3TA"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the preview.&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%2Fi%2F04wdj5nndezxfwe2yieh.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%2Fi%2F04wdj5nndezxfwe2yieh.png" alt="1_LQLM5w06cGMheqSJCtngFg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you may have noticed, We have used VStack to group the name and about text view vertically and profile picture view and Vstack horizontally with HStack. Similarly, we will create more sections for different settings options using HStack to group image and text.&lt;/p&gt;

&lt;p&gt;Apple has provided us free symbols (SF symbols) so that without importing any other assets we can use them as icons in our app. These symbols have a unique name called systemName.   &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%2Fi%2Ffadpfg2i4w39tt771pvk.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%2Fi%2Ffadpfg2i4w39tt771pvk.png" alt="1_upTPbI-kdpPcJR5820N-tw"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the preview.&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%2Fi%2F2gbh83diwnw8r1pvg31g.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%2Fi%2F2gbh83diwnw8r1pvg31g.png" alt="1_k9SXHyEQfjZT1tGKtnx7lg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly, we will add more sections the same as of Whatsapp app.&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%2Fi%2F0zkk8kaoknbpjv0fdfjc.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%2Fi%2F0zkk8kaoknbpjv0fdfjc.png" alt="1_rIFhK3VN1w55DG-_r7q1WA"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the final Preview in Light Mode and Dark Mode&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%2Fi%2Fuox8j6zizgmaytou7l6b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuox8j6zizgmaytou7l6b.jpg" alt="1_xs2CuaPOtdYMj1ccr1YbYw"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best thing about SwiftUI is that we only need to tell what to put where and in which order on the screen. SwiftUI takes care of all the constraints and layout.&lt;/p&gt;

&lt;p&gt;Thanks for reading.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/deepakjoshipro/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/deepak-pro" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/0xjoshi" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
    <item>
      <title>How I created a tool to efficiently sort a folder</title>
      <dc:creator>Deepak JOSHI</dc:creator>
      <pubDate>Thu, 18 Jun 2020 04:51:17 +0000</pubDate>
      <link>https://dev.to/deepakpro/how-i-created-a-tool-to-efficiently-sort-a-folder-1959</link>
      <guid>https://dev.to/deepakpro/how-i-created-a-tool-to-efficiently-sort-a-folder-1959</guid>
      <description>&lt;p&gt;It is a lockdown period and we all have a lot of spare time. My Downloads folder is messed up with a huge number of files of different types. Every time I decide to clean that folder I go one by one and delete unwanted files. That is not a big task when the numbers are low. But this time there are 2000 files.&lt;/p&gt;

&lt;p&gt;So one thing was clear in my mind, We need automation.&lt;/p&gt;

&lt;p&gt;I am a fan of shell commands and always fascinated by how big tasks can be done with a few lines. Now speaking to the point we need to create a shell script that will sort the files in the order in which it will be easy for us to keep what is important and delete what is not. I was analyzing a few files noted their types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Files that are very important
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Receipts of online transactions -&amp;gt; PDF&lt;/li&gt;
&lt;li&gt;Media from the phone -&amp;gt; JPEG and MOV&lt;/li&gt;
&lt;li&gt;Documents -&amp;gt; DOCX, DOC, PPT etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Files that are not important and can be downloaded later
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Movies -&amp;gt; MKV, MP4, VOB, AVI&lt;/li&gt;
&lt;li&gt;Torrents -&amp;gt;TORRENT&lt;/li&gt;
&lt;li&gt;Songs -&amp;gt; MP3&lt;/li&gt;
&lt;li&gt;Installer or executables -&amp;gt; DMG&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Files that can be important
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Txt files&lt;/li&gt;
&lt;li&gt;Zip files&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So we will now sort files with their types.&lt;br&gt;
The first thing is to get all the types of files that exist in the current directory. A simple ls command in Linux can do the job. but it will list directories too.&lt;br&gt;
Note: We are not sorting the directory in a recursive manner, only considering files that are present in the current directory.&lt;/p&gt;

&lt;p&gt;Having a look at the man page of ls solves our problem. -p option can be used to put a ‘/’ after each filename if that file is a directory. Yes you heard it right “Everything in a Linux system is a file, even directories”.&lt;br&gt;
Now the code is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -p
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To filter only files we will pipe the output into grep with -v option to ignore the result containing “/”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -p | grep -v /
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we have a list of all the files, from now we only need extensions. Generally, we have the file name as “name.extension”, so we will use “.” as the separator and will get the second column. So the code will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -p | grep -v / | cut -d “.” f2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But I see a problem here,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4T5eMxxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/500/1%2A1LxujIt2yKXGXfySiwbKtg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4T5eMxxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/500/1%2A1LxujIt2yKXGXfySiwbKtg.gif" alt="Problem"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if there are files that contain “.”(dot) in the filename for example- “some.thing.extenion”. The above code will take “thing” as an extension. We have a solution for this. Try &lt;br&gt;
understanding the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -p | grep -v / | rev | cut -d “.” f1 | rev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Reversing the string and using cut with “.” as the delimiter to get the first column will give us the last column in the reversed string, again reversing will give the actual extension.&lt;/p&gt;

&lt;p&gt;This will give us all the extension in a list (duplicates for multiple files with the same types).&lt;br&gt;
We will store this in a file. To make a temporary file we can use mktemp. By the below code we will get a list of &lt;br&gt;
extensions in a temp file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ temp = `mktemp`
$ ls -p | grep -v / |  rev | cut -d "." -f1 | rev &amp;gt; $temp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Sure we will remove duplicates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ utemp = `mktemp`
$ sort $temp | uniq &amp;gt; $utemp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We have $utemp file that has a list of all unique extensions.&lt;br&gt;
Now only thing left is to pick a line from the $utemp file and create a directory with that name and copy all files with that extension.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while read ext;
do
   mkdir $ext
   mv *.$ext $ext/
done &amp;lt; $utemp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That’s it we are now done sorting. Remove the temp files now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm $temp
rm $utemp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So, bringing all these commands together in a file and giving permission to execute&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x filter.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can place this script in the Downloads directory and run it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q9v0rfzr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/700/1%2A1QYndAEhkAo9hOfaGbZnIA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q9v0rfzr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/700/1%2A1QYndAEhkAo9hOfaGbZnIA.gif" alt="Github"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have added a few echo commands to know the progress.&lt;br&gt;
Taking about the results we get, After running this script I simply moved the important files in a backup drive. Quickly deleted folders of files that were not important, looked for other file types and kept what was important. These other files were small in number, so the overall process took only a few minutes.&lt;/p&gt;

&lt;p&gt;You can see this project on GitHub &lt;a href="https://github.com/deepak-pro/filterx"&gt;here&lt;/a&gt;.&lt;br&gt;
This is my first article, hope you like it.&lt;/p&gt;

&lt;p&gt;Twitter - &lt;a href="https://twitter.com/0xjoshi/"&gt;0xjoshi&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
