<?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>Forem: Luca</title>
    <description>The latest articles on Forem by Luca (@the_previ).</description>
    <link>https://forem.com/the_previ</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%2F706091%2Fdf3e9d0c-c00f-4061-9d51-29a1af457f4e.jpg</url>
      <title>Forem: Luca</title>
      <link>https://forem.com/the_previ</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/the_previ"/>
    <language>en</language>
    <item>
      <title>A practical introduction to Git Flow</title>
      <dc:creator>Luca</dc:creator>
      <pubDate>Fri, 25 Feb 2022 13:56:50 +0000</pubDate>
      <link>https://forem.com/the_previ/a-practical-introduction-to-git-flow-5420</link>
      <guid>https://forem.com/the_previ/a-practical-introduction-to-git-flow-5420</guid>
      <description>&lt;p&gt;Most part of the devs out there use Git everyday but for who is not familiar with it, &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git&lt;/a&gt; is the most popular version system control.&lt;/p&gt;

&lt;p&gt;Git basically works by tracking the changes made to the files providing a record of what has been done and allowing to revert to a specific version any time you want.&lt;br&gt;
Git also makes collaboration easier. It enables all changes to be merged into one single source.&lt;br&gt;
These possibilities combined with its ease of use have made it a needful tool to handle the life cycle of the development of a project.&lt;/p&gt;

&lt;p&gt;There are &lt;a href="https://css-tricks.com/branching-strategies-in-git/#aa-two-popular-branching-strategies" rel="noopener noreferrer"&gt;various strategies&lt;/a&gt; for working with Git and and you can choose among them depending on your own context and needs.&lt;br&gt;
Personally, I have used many times the &lt;strong&gt;Git Flow branching model&lt;/strong&gt; which is described in &lt;a href="https://nvie.com/posts/a-successful-git-branching-model/" rel="noopener noreferrer"&gt;this great article&lt;/a&gt; by Vincent Driessen.&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%2F6wly41awljt5kqqww3zq.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%2F6wly41awljt5kqqww3zq.png" alt="Git Flow"&gt;&lt;/a&gt;&lt;br&gt;
The image above, taken from the article by Driessen, shows an example of the flow of this branching model.&lt;/p&gt;

&lt;p&gt;This strategy implies the use of the following types of branches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;master&lt;/code&gt;: it is the branch that reflects the production state. Starting from 2020 it is often named &lt;code&gt;main&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;develop&lt;/code&gt;: is the principal branch where the state of  code represents the latest delivered development changes for the next release.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;feature/&amp;lt;feature-name&amp;gt;&lt;/code&gt;: these branches are completely dedicated to the development of new functionalities. Feature branches come from the develop branch and must be merged back to the develop branch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;release/&amp;lt;release-name&amp;gt;&lt;/code&gt;: the release branches are used to prepare  the release of a new version. These branches start from the develop branch and must be merged in both develop and master branches.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hotfix/&amp;lt;hotfix-name&amp;gt;&lt;/code&gt;: the hotfix branches are used to make urgent corrections to the project. These branches come from the master branch and must be merged back in the master and the develop branches.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;git-flow&lt;/strong&gt; is a set of Git shortcuts to easily apply this branching model, you don’t have to use it necessarily but it is very convenient.&lt;/p&gt;

&lt;p&gt;For information about the installation refer to &lt;a href="https://github.com/nvie/gitflow/wiki/Installation" rel="noopener noreferrer"&gt;the official repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To work with git-flow you need first to initialize it in the project by using&lt;/p&gt;

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

git flow init


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

&lt;/div&gt;

&lt;p&gt;Now let's see how to do the most common activities&lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add a new feature&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to create a new feature branch from the develop branch and switch to it. You can achieve this with&lt;/p&gt;

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

git flow feature start &amp;lt;feature-name&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;After you have done all the needed changes to the feature, you can close it by typing&lt;/p&gt;

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

git flow feature finish &amp;lt;feature-name&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;The feature branch will be merged in the develop branch and then be deleted.&lt;br&gt;
The pointer will be changed to the develop branch.&lt;/p&gt;

&lt;p&gt;Since these actions are performed in your local repository, always remember to push the changes when you finish your features to update the remote develop branch.&lt;br&gt;
Alternatively to push you can use&lt;/p&gt;

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

git flow feature publish &amp;lt;feature-name&amp;gt;


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

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Make a new release&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First you need to start a new release with the command&lt;/p&gt;

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

git flow release start &amp;lt;release-name&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;that creates a new release branch from the develop branch and switches to it.&lt;/p&gt;

&lt;p&gt;Once you have done all the changes needed you can close the release with&lt;/p&gt;

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

git flow release finish &amp;lt;release-name&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;the release will be merged in the master branch and a version tag will be created using the name of the release branch.&lt;br&gt;
Merges the release in develop and delete the release branch.&lt;/p&gt;

&lt;p&gt;Here, too, remember to push the branches and the new tag to update the remote branches. More simply, you can also use&lt;/p&gt;

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

git flow release publish &amp;lt;release-name&amp;gt;


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

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Apply a hotfix&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Like in the other examples we need first to create a new hotfix branch from master branch and then switch to it with the command&lt;/p&gt;

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

git flow hotfix start &amp;lt;hotfix-name&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;When the hotfix is ready to be closed we can use&lt;/p&gt;

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

git flow hotfix finish [&amp;lt;tag version-name&amp;gt;]


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

&lt;/div&gt;

&lt;p&gt;Under the hood this command will merge the hotfix into the master and develop branches, delete the hotfix branch and create a new tag.&lt;/p&gt;

&lt;p&gt;Here, too, it is important to update the remote branches.&lt;/p&gt;

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

(master) $ git push
(master) $ git push --tags
(master) $ git checkout develop
(develop) $ git push
$ git push {github_username} :hotfix/1.3.4


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

&lt;/div&gt;

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

&lt;p&gt;If you are looking for a brief summary of git-flow commands check &lt;a href="http://danielkummer.github.io/git-flow-cheatsheet/" rel="noopener noreferrer"&gt;this cheatsheet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👋 See you in the next article!&lt;/p&gt;

&lt;h4&gt;
  
  
  Learn more
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/fernando_ayon/git-flow-an-introduction-430m"&gt;Introduction to Git-Flow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow#:~:text=Gitflow%20is%20really%20just%20an,that%20has%20an%20installation%20process." rel="noopener noreferrer"&gt;Gitflow Workflow by Atlassian&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to detect file type in JavaScript without checking its file object type?</title>
      <dc:creator>Luca</dc:creator>
      <pubDate>Thu, 16 Sep 2021 14:46:42 +0000</pubDate>
      <link>https://forem.com/the_previ/how-to-detect-file-type-in-javascript-without-checking-its-file-object-type-2lck</link>
      <guid>https://forem.com/the_previ/how-to-detect-file-type-in-javascript-without-checking-its-file-object-type-2lck</guid>
      <description>&lt;p&gt;Usually when we want to check the type for a file that we have to upload we look for its MIME type in the file object.&lt;/p&gt;

&lt;p&gt;MIME type is a standard that indicates the nature and format of a file, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types"&gt;here&lt;/a&gt; you can get a list of the most common, there are really &lt;a href="https://www.iana.org/assignments/media-types/media-types.xhtml"&gt;many&lt;/a&gt; of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  But.. What if the file for some reasons doesn't has an extension or have a wrong extension assigned? 🤔
&lt;/h3&gt;

&lt;p&gt;Luckily the magic numbers come to our aid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Magic numbers&lt;/strong&gt; are a byte pattern inside a file that is used to determine which is the type of the file.&lt;/p&gt;

&lt;p&gt;Or, more properly, from &lt;em&gt;Wikipedia&lt;/em&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Magic numbers implement strongly typed data and are a form of in-band signaling to the controlling program that reads the data type(s) at program run-time. Many files have such constants that identify the contained data&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For have an example of how to implement magic numbers "by hand" with the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader"&gt;FileReader API&lt;/a&gt; I strongly recommend reading &lt;a href="https://medium.com/the-everyday-developer/detect-file-mime-type-using-magic-numbers-and-javascript-16bc513d4e1e"&gt;this article&lt;/a&gt; by Andreas Kihlberg.&lt;/p&gt;

&lt;p&gt;I want instead focus on the &lt;a href="https://github.com/sindresorhus/file-type"&gt;file-type library&lt;/a&gt;. This library applies the magic numbers approach to the ArrayBuffer of the file for detecting its type. It works with a &lt;a href="https://github.com/sindresorhus/file-type#supported-file-types"&gt;large amount&lt;/a&gt; of different file types.&lt;/p&gt;

&lt;p&gt;Unfortunately some file types, especially plain-text files, are harder to spot by this method and if you want to check the type you have to use a parser for every kind of file you have to consider.&lt;br&gt;
For example if you want to spot SVG you can use &lt;a href="https://github.com/sindresorhus/is-svg"&gt;is-svg&lt;/a&gt; library from NPM.&lt;/p&gt;

&lt;p&gt;I've created a Sandbox using React that show how the file-type library works.&lt;br&gt;
C'mon, try it! 👇&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/m7hom"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;👋 See you in the next article!&lt;/p&gt;

&lt;h4&gt;
  
  
  Learn more
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Magic_number_(programming)"&gt;Wikipedia - Magic numbers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"&gt;ArrayBuffer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/File_format"&gt;Wikipedia - File format&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
