<?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: Upamanyu Das</title>
    <description>The latest articles on Forem by Upamanyu Das (@tintindas).</description>
    <link>https://forem.com/tintindas</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%2F447846%2F4928c4b0-2ed9-4cf1-9d62-f74217038d77.jpeg</url>
      <title>Forem: Upamanyu Das</title>
      <link>https://forem.com/tintindas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tintindas"/>
    <language>en</language>
    <item>
      <title>LeetCode Daily Problem - 967. Numbers With Same Consecutive Differences</title>
      <dc:creator>Upamanyu Das</dc:creator>
      <pubDate>Sat, 03 Sep 2022 22:05:33 +0000</pubDate>
      <link>https://forem.com/tintindas/leetcode-daily-problem-967-numbers-with-same-consecutive-differences-16eg</link>
      <guid>https://forem.com/tintindas/leetcode-daily-problem-967-numbers-with-same-consecutive-differences-16eg</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Return all non-negative integers of length n such that the absolute difference between every two consecutive digits is k.&lt;/p&gt;

&lt;p&gt;Note that every number in the answer must not have leading zeros. For example, 01 has one leading zero and is invalid.&lt;/p&gt;

&lt;p&gt;You may return the answer in any order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Idea
&lt;/h2&gt;

&lt;p&gt;The way to solve this is to construct the number digit by digit. We can pick any digit &lt;code&gt;x&lt;/code&gt; from 1 through 9 as the first digit. Once we have picked the digit we have at most two valid choices &lt;code&gt;x + k&lt;/code&gt; and &lt;code&gt;x - k&lt;/code&gt; i.e. they both lie in [0, 9]. The problem then reduces to solving a smaller problem with similar structure, i.e. with one less digit at every step. When n digits have been picked we can add the number to our answer array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;dfs&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;NumOfDigits&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;currNum&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NumOfDigits&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;currNum&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;nextDigits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;tailDigit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;currNum&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;nextDigits&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tailDigit&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;nextDigits&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tailDigit&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;nextDigit&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nextDigits&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;nextDigit&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;nextDigit&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;currNum&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;nextDigit&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;dfs&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NumOfDigits&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;numsSameConsecDiff&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LinkedList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;();&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;dfs&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;mapToInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;toArray&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Runtime: 9 ms, faster than 21.14% of Java online submissions for Numbers With Same Consecutive Differences.&lt;/p&gt;

&lt;p&gt;Memory Usage: 44.2 MB, less than 6.62% of Java online submissions for Numbers With Same Consecutive Differences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; - The BFS solution of this problem will be much more memory efficient as the recursion stack will not have to be dealt with.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>medium</category>
      <category>java</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Real World Python 🐍: Environment Setup - pyenv</title>
      <dc:creator>Upamanyu Das</dc:creator>
      <pubDate>Sun, 29 Aug 2021 19:22:26 +0000</pubDate>
      <link>https://forem.com/tintindas/real-world-python-environmet-setup-pyenv-3c0o</link>
      <guid>https://forem.com/tintindas/real-world-python-environmet-setup-pyenv-3c0o</guid>
      <description>&lt;p&gt;You should &lt;strong&gt;never ever&lt;/strong&gt; touch system python.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is system python?
&lt;/h2&gt;

&lt;p&gt;System python is the python that comes installed with your operating system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why shouldn't I touch it?
&lt;/h2&gt;

&lt;p&gt;There are a host of reasons to not use system python.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not the version of python you're looking for. Maybe you want the latest features from python 3.9 but your OS only came with 3.8.&lt;/li&gt;
&lt;li&gt;Globally installing dependencies is never a good idea and problems with multiple versions of a dependency will have you troubleshooting on a Sunday morning.&lt;/li&gt;
&lt;li&gt;Your OS might have a system dependency on python which might make your entire system unusable because you managed to break python.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  pyenv
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Simple Python version management.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This tool lets us install our preferred python version and use that for our projects so that we don't have to touch system python.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/pyenv" rel="noopener noreferrer"&gt;
        pyenv
      &lt;/a&gt; / &lt;a href="https://github.com/pyenv/pyenv" rel="noopener noreferrer"&gt;
        pyenv
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Simple Python version management
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Installing pyenv
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Build dependencies
&lt;/h3&gt;

&lt;p&gt;pyenv builds python from source, so you will need some build dependencies to use pyenv. These dependencies vary by platform.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mac
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;openssl readline sqlite3 xz zlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Assumes you have brew installed on your machine.&lt;/p&gt;

&lt;h4&gt;
  
  
  Debian
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; make build-essential libssl-dev zlib1g-dev &lt;span class="se"&gt;\&lt;/span&gt;
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev &lt;span class="se"&gt;\&lt;/span&gt;
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For other systems please refer to the &lt;a href="https://github.com/pyenv/pyenv#installation" rel="noopener noreferrer"&gt;official installation docs&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  pyenv
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://pyenv.run | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This uses the &lt;a href="https://github.com/pyenv/pyenv-installer" rel="noopener noreferrer"&gt;pyenv-installer&lt;/a&gt; project to install pyenv on your system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing a python version
&lt;/h2&gt;

&lt;p&gt;Check what versions are available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install a python version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; 3.9.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting python version
&lt;/h2&gt;

&lt;p&gt;pyenv lets us set the python version globally, locally in our project and even for a particular shell.&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%2Fyh9l7zbv7t1ngrllapri.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%2Fyh9l7zbv7t1ngrllapri.png" alt="Pyenv pyramid - System python at the bottom, above it global python, above it local python and at the top shell python"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We want to set the python version for our project so we will use &lt;code&gt;local&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We will create our project directory and navigate into it.&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="nb"&gt;mkdir &lt;/span&gt;quotes-scraper &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;quotes-scraper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then set the python version we want to use for our project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;local &lt;/span&gt;3.9.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a &lt;code&gt;.python-version&lt;/code&gt; file in the root directory of the project. If pyenv is active in our environment, this file will automatically activate the specified python version in the project.&lt;/p&gt;




&lt;p&gt;I hope you found this post useful. Please leave any feedback in the comments or DM me &lt;a href="https://twitter.com/tintin_das" rel="noopener noreferrer"&gt;@tintin_das&lt;/a&gt; on Twitter 🐦.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1432055144640704512-158" src="https://platform.twitter.com/embed/Tweet.html?id=1432055144640704512"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1432055144640704512-158');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1432055144640704512&amp;amp;theme=dark"
  }



&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Real World Python 🐍: Introduction</title>
      <dc:creator>Upamanyu Das</dc:creator>
      <pubDate>Sun, 29 Aug 2021 16:28:44 +0000</pubDate>
      <link>https://forem.com/tintindas/real-world-python-introduction-3km4</link>
      <guid>https://forem.com/tintindas/real-world-python-introduction-3km4</guid>
      <description>&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;There is a gap in the python material available online. While a lot of tutorials are available for absolute beginners, there is a distinct lack of content for those who are looking to take the next step.&lt;/p&gt;

&lt;p&gt;Nature abhors a vacuum. So, here I am to fill the void. In this series we will cover all the stuff that goes into making a real world python project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intended Audience
&lt;/h2&gt;

&lt;p&gt;Python beginners who have knowledge of the fundamentals of programming and are looking to start with their first real project. I will assume that the reader already knows topics such as conditional statements, loops, functions etc. My focus will be more on the structure and the "flow" of a project rather than the logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we will build
&lt;/h2&gt;

&lt;p&gt;A web scraper which grabs quotes from &lt;a href="https://www.goodreads.com/quotes/437173-talk-is-cheap-show-me-the-code" rel="noopener noreferrer"&gt;goodreads.com&lt;/a&gt; and stores them locally or to a remote database.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/tintindas" rel="noopener noreferrer"&gt;
        tintindas
      &lt;/a&gt; / &lt;a href="https://github.com/tintindas/quotes-scraper" rel="noopener noreferrer"&gt;
        quotes-scraper
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Scrape quotes based on author (or search term) from Goodreads.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Roadmap
&lt;/h2&gt;

&lt;p&gt;These are the planned topics for the series.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Environment Setup - pyenv&lt;/li&gt;
&lt;li&gt;Project Setup&lt;/li&gt;
&lt;li&gt;Directory Structure&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Some Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This is my way of doing things which is just one way out of many. There are no hard and fast rules. Most of the steps in this series are optional, but highly recommended.&lt;/li&gt;
&lt;li&gt;The series is mostly geared towards Mac/Linux systems. Though it should all work on WSL too.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Uh Oh! I Cloned without Forking!</title>
      <dc:creator>Upamanyu Das</dc:creator>
      <pubDate>Sat, 14 Aug 2021 07:36:57 +0000</pubDate>
      <link>https://forem.com/tintindas/uh-oh-i-cloned-without-forking-2eaj</link>
      <guid>https://forem.com/tintindas/uh-oh-i-cloned-without-forking-2eaj</guid>
      <description>&lt;p&gt;Last week I cloned a repo without forking it first and only realised my mistake after I had already made some commits to my local copy.&lt;/p&gt;

&lt;p&gt;Rookie mistake!  &lt;/p&gt;

&lt;p&gt;But there's an easy fix.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Remove the existing remote from your local repo.
&lt;/h4&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can get a list of configured remotes and their URLs by running:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Fork the project and copy the fork's URL
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UfVEcwve--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/is9brfbn1iuq54lo5rg5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UfVEcwve--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/is9brfbn1iuq54lo5rg5.png" alt="Copy fork's URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Add the URL to your local copy.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin [copied URL]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you're done 😀 ! You can now push your code and it will go to your fork.&lt;/p&gt;

&lt;p&gt;Hope this was helpful!&lt;/p&gt;




&lt;p&gt;Hi, I am Upamanyu! &lt;/p&gt;

&lt;p&gt;If you liked this post maybe you'll like my tweets too. Follow me &lt;a href="https://twitter.com/intent/user?screen_name=tintin_das"&gt;@tintin_das 🐦&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>fork</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Adding Typescript to my existing Node + Express API - Part 2 - Directory Structure </title>
      <dc:creator>Upamanyu Das</dc:creator>
      <pubDate>Tue, 26 Jan 2021 06:30:48 +0000</pubDate>
      <link>https://forem.com/tintindas/adding-typescript-to-my-existing-node-express-api-part-2-directory-structure-376m</link>
      <guid>https://forem.com/tintindas/adding-typescript-to-my-existing-node-express-api-part-2-directory-structure-376m</guid>
      <description>&lt;p&gt;If you're reading this I am assuming you are familiar with the set up steps we took in my &lt;a href="https://dev.to/tintindas/adding-typescript-to-my-existing-node-express-api-part-1-set-up-48io"&gt;earlier post&lt;/a&gt;. &lt;/p&gt;




&lt;p&gt;Before we get VSCode to chill let's make sure our project's directory structure is easily understandable.&lt;/p&gt;

&lt;p&gt;My directory structure used to look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L-5rMV8k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vuq4omxok128tl2p2qhi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L-5rMV8k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vuq4omxok128tl2p2qhi.png" alt="Previous directory structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it looks like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yDU-QUZ1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3t72jgezrs356znsv5ev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yDU-QUZ1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3t72jgezrs356znsv5ev.png" alt="New directory structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The names of the folders are pretty self-explanatory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;config&lt;/strong&gt; exports all our configuration options for mongodb and our server. The most important variables being exported are the username and password with which we access our database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mine looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;dotenv&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;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;dotenv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&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;MONGO_OPTIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;useUnifiedTopology&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;useNewUrlParser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;keepAlive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;poolSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&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;MONGO_USER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_USER&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MONGO_PASS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_PASS&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MONGO_DB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_DB&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MONGO&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MONGO_USER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MONGO_PASS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MONGO_DB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MONGO_OPTIONS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`mongodb+srv://&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;MONGO_USER&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;MONGO_PASS&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;@cluster0-yo7rn.mongodb.net/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;MONGO_DB&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;mongo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MONGO&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;controllers&lt;/strong&gt; is the folder where we write the main control functions for our API, i.e., the main logic. These files will export functions which will be executed when the user goes to one of our API's endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;models&lt;/strong&gt; is where we will create the models which tell our server how to interact with the data in our database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;interfaces&lt;/strong&gt; are to make sure that mongoose's model definitions play nice with typescript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In &lt;strong&gt;routes&lt;/strong&gt; we define routers which will connect the controllers with the routes they are intended for. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In the next part we will download some dependencies and set up some npm scripts that will let us set up our development server.&lt;/p&gt;

&lt;p&gt;If you liked this post consider,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;checking out my projects at &lt;a href="https://github.com/tintindas"&gt;tintindas&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;following me on twitter &lt;a href="https://twitter.com/tintin_das"&gt;@tintin_das&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--UGSLp2Af--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1287980160533147648/RF3bfpZ6_normal.jpg" alt="Upamanyu Das profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Upamanyu Das
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @tintin_das
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir1kO05j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      I'm so Bengali even my zsh shell is fishy themed.&lt;br&gt;&lt;br&gt;&lt;a href="https://twitter.com/hashtag/fishy"&gt;#fishy&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/zsh"&gt;#zsh&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/Ubuntu"&gt;#Ubuntu&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/webdev"&gt;#webdev&lt;/a&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      17:00 PM - 30 Nov 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1333455982739869698" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFnoeFxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-reply-action-238fe0a37991706a6880ed13941c3efd6b371e4aefe288fe8e0db85250708bc4.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1333455982739869698" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6dcrOn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-retweet-action-632c83532a4e7de573c5c08dbb090ee18b348b13e2793175fea914827bc42046.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/like?tweet_id=1333455982739869698" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRQc9lOp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-like-action-1ea89f4b87c7d37465b0eb78d51fcb7fe6c03a089805d7ea014ba71365be5171.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


</description>
      <category>node</category>
      <category>typescript</category>
      <category>mongodb</category>
      <category>api</category>
    </item>
    <item>
      <title>Adding Typescript to my existing Node + Express API - Part 1 - Set up</title>
      <dc:creator>Upamanyu Das</dc:creator>
      <pubDate>Thu, 21 Jan 2021 17:40:39 +0000</pubDate>
      <link>https://forem.com/tintindas/adding-typescript-to-my-existing-node-express-api-part-1-set-up-48io</link>
      <guid>https://forem.com/tintindas/adding-typescript-to-my-existing-node-express-api-part-1-set-up-48io</guid>
      <description>&lt;p&gt;This is some documentation I am writing mostly for myself and   for anyone who might want to add typescript to their own projects.&lt;/p&gt;

&lt;p&gt;The project we are adding typescript to can be found at &lt;a href="https://github.com/tintindas/quotes-api"&gt;https://github.com/tintindas/quotes-api&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Making a new branch
&lt;/h2&gt;

&lt;p&gt;Always make a new branch before screwing around with code that already works. Learnt this the hard way.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git checkout -b add-typescript&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Adding typescript and required types as dev dependencies
&lt;/h2&gt;

&lt;p&gt;The typescript compilers and the types of the libraries used in our project need to be added as developer dependencies so that we have access to all the type definitions we require.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D typescript @types/node @types/express @types/mongoose @types/cors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Make a tsconfig.json file
&lt;/h2&gt;

&lt;p&gt;If you have typescript globally installed run &lt;br&gt;
&lt;code&gt;tsc --init&lt;/code&gt;&lt;br&gt;
else run &lt;br&gt;
&lt;code&gt;npx tsc --init&lt;/code&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  4. Edit tsconfig.json
&lt;/h2&gt;

&lt;p&gt;Edit the outDir and rootDir properties in the tsconfig file. &lt;br&gt;
Set the rootDir to be the directory where all your logic is stored. &lt;br&gt;
The outDir is the destination where the typescript transpiler puts all the files vanilla javascript files produced after transpilation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"outDir": "./dist",                         
"rootDir": "./src",   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I named my input directory &lt;strong&gt;src&lt;/strong&gt; and the target directory &lt;strong&gt;dist&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set the include property to be &lt;strong&gt;src&lt;/strong&gt; or whatever you have named your rootDir if there are typescript files you do not wish to be transpiled outside of the rootDir folder.&lt;/p&gt;

&lt;p&gt;How my tsconfig.json file looks like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "outDir": "./dist",                         
    "rootDir": "./src", 
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Create src directory and move all of your logic into it.
&lt;/h2&gt;

&lt;p&gt;Anything outside of the src folder will not be put into the dist folder which will be our final production code.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Change extension .ts
&lt;/h2&gt;

&lt;p&gt;Change the javascript files into typescript files by changing all the extensions to .ts.&lt;/p&gt;




&lt;p&gt;This was the setup part of the project. VSCode should be screaming at you right now. Don't worry we will fix that in next part.&lt;/p&gt;




&lt;p&gt;If you liked this post consider, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;checking out my projects at &lt;a href="https://github.com/tintindas"&gt;https://github.com/tintindas&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;following me on twitter &lt;a href="https://twitter.com/tintin_das"&gt;@tintin_das&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>typescript</category>
      <category>node</category>
      <category>express</category>
      <category>api</category>
    </item>
  </channel>
</rss>
