<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cole Gawin on Medium]]></title>
        <description><![CDATA[Stories by Cole Gawin on Medium]]></description>
        <link>https://medium.com/@colegawin?source=rss-cc4c226671db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YmVWHaZU5HDvFjuiLo4Vaw.jpeg</url>
            <title>Stories by Cole Gawin on Medium</title>
            <link>https://medium.com/@colegawin?source=rss-cc4c226671db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:54:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@colegawin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Leveraging Vector Embeddings and Similarity Search to Supplement ChatGPT’s Training Data]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://pub.aimind.so/leveraging-vector-embeddings-and-similarity-search-to-supplement-chatgpts-training-data-f6585914bf3b?source=rss-cc4c226671db------2"><img src="https://cdn-images-1.medium.com/max/2600/1*EF4mMdp3s18S5aJla582Zw.png" width="3840"></a></p><p class="medium-feed-snippet">Unlocking the Power of Sentence Transformers and FAISS for NLP</p><p class="medium-feed-link"><a href="https://pub.aimind.so/leveraging-vector-embeddings-and-similarity-search-to-supplement-chatgpts-training-data-f6585914bf3b?source=rss-cc4c226671db------2">Continue reading on AI Mind »</a></p></div>]]></description>
            <link>https://pub.aimind.so/leveraging-vector-embeddings-and-similarity-search-to-supplement-chatgpts-training-data-f6585914bf3b?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6585914bf3b</guid>
            <category><![CDATA[semantic-search]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Tue, 04 Jul 2023 23:40:59 GMT</pubDate>
            <atom:updated>2023-07-05T17:41:54.230Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Web Scraping Techniques to Source Reliable Information for ChatGPT]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@colegawin/web-scraping-techniques-to-source-reliable-information-for-chatgpt-1c5f58d72ef5?source=rss-cc4c226671db------2"><img src="https://cdn-images-1.medium.com/max/1920/1*VuxAAobguKql6r2fN_JPYA.png" width="1920"></a></p><p class="medium-feed-snippet">Quickly and efficiently extract useful data from the web to augment the capabilities of LLMs</p><p class="medium-feed-link"><a href="https://medium.com/@colegawin/web-scraping-techniques-to-source-reliable-information-for-chatgpt-1c5f58d72ef5?source=rss-cc4c226671db------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@colegawin/web-scraping-techniques-to-source-reliable-information-for-chatgpt-1c5f58d72ef5?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c5f58d72ef5</guid>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Wed, 21 Jun 2023 13:35:08 GMT</pubDate>
            <atom:updated>2023-06-24T00:15:26.167Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The art of “brand-gineering”]]></title>
            <link>https://medium.com/design-bootcamp/the-art-of-brand-gineering-253e4d4d3333?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/253e4d4d3333</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[brand-gineering]]></category>
            <category><![CDATA[branding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Wed, 22 Dec 2021 04:36:51 GMT</pubDate>
            <atom:updated>2023-06-09T04:03:10.845Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PpfS19rEOvvz0PEKlbzCYw.png" /></figure><h4>More than an engineer — more than a designer.</h4><h4>I always go above and beyond in my work. Here’s what that entails — and why it is so rewarding.</h4><p>Being a full-time student, I dedicate the majority of my day to learning more about how the cogs of the world turn. Certainly, you have heard from a multitude of students how monotonous, but important nonetheless, general education is to the average student. My respect goes out to those of us who find a source of enjoyment in this process, but alas, that is not me.</p><p>I find enjoyment in being able to forge my own path — in thinking outside of the box — and I’ve found this to be true in nearly everything I do. When I play soccer, I love the thrill of formulating dynamic plays on the fly; when I cook and prepare a meal (or a midnight snack), I put a dash of my own imagination into the dish; and even when I complete schoolwork, I always find a way to make learning more interesting and less tedious of a task.</p><p>This holds true in my career and my work, as well. As a software engineer, my task is always to find a new or better way to do something. <em>In other words</em>, my job is to</p><blockquote>“<em>think different”</em>.</blockquote><p>I love that quote because it resonates to my soul and speaks to who I am as an individual. I live for the challenge of having to do something my own way, to “think different,” as it allows me to pour a sense of myself into whatever I am doing.</p><p>With this in mind, I can begin my discussion on what it means to be a “brand-gineer,” and how it leads me to always strive to go above and beyond in my work.</p><h3>meaningful.</h3><p>For a project to be worth my time, it has to be <em>meaningful</em> to me in some way. What makes a project <em>meaningful</em>? That’s certainly a loaded question, but to answer it in the most simple terms, I believe a meaningful project is one that has the ability to make a notable impact on society.</p><p>I believe that this is well reflected in <a href="https://projects.colegaw.in/">my portfolio</a>. I demonstrate the projects of which I am most fond, which oftentimes is because of the real-world impact they have the potential to make. For example, “<a href="https://www.notion.so/Well-Reboot-Your-Mindset-ad1070400b0940578d4c5ae3423d64e5"><strong>Well: Reboot Your Mindset</strong></a>” is a mental health-focused app designed to improve its users mindset and boost their happiness and positivity; this app addresses the ever-relevant issue of mental health, and is based on research in the field of positive psychology. I am so proud of that app because not only am I incredibly pleased with the resulting product, but also because I know the beneficial impact it can make on people’s lives.</p><p>It’s these sorts of meaningful projects that give me the most fulfillment in my work. Creating projects that can make an impact drives me to create again and again.</p><h3>passionate.</h3><p><strong><em>Passion</em>.</strong> What is <em>passion</em>? Sports teams will consider it a “core value.” Scientists will consider it a “driving force.” Artists will consider it “a motivator.” To me, passion is all of these things and more. Passion truly is what keeps me afloat.</p><blockquote>Passion is what keeps me going, even when I am at my lowest points.</blockquote><p>When it comes to my work, <em>passionate</em> is such an apt description because that’s exactly what it is. Everything that I work on, I dedicate so much passion into because I am doing something that I love to do — thinking different.</p><p>This works hand-in-hand with the quality of being “meaningful”. I don’t just complete simple projects that will look good in a showcase portfolio; the projects that I work on are meaningful and have the potential to make positive impacts on the world. These are the projects that I enjoy working on because I am <em>passionate</em> about them.</p><h3>all-encompassing.</h3><p><em>A job half done is as good as none.</em> I think that’s true for all things in life, especially when it comes to the projects I choose to work on. When I take on a project, I look at it as something I can mold into whatever I think would work best; to do so, I come prepared and ready with a full suite of skills at my disposal. I am experienced in both design and development, which enables me to be a true <em>full-stack engineer</em>.</p><p>To me, the design and ideation process shouldn’t be separated from the actual development of a product. These processes should be seamless and integrated at their cores. If a product is made by two completely separated teams, the product will appear just as disjointed and incompatible to the end user.</p><p>For these reasons, my work is <em>all-encompassing</em>. I bring to the table skills that will not only help bring ideas to fruition, but to help develop and design those ideas to begin with.</p><h3>“brand-gineering”</h3><p>To conclude this (perhaps needlessly) long soliloquy, I’ll move onto the term “brand-gineering” itself.</p><p>In my humble opinion, my work doesn’t fit into the categories of “engineering” or “design” — it’s more than that. “Brand-gineering” involves working on a project or with a product or brand and taking a hands-on approach to its goals and objectives. The work I do as a “brand-gineer” is <em>meaningful</em>, <em>passionate</em>, and <em>all-encompassing</em>.</p><p>In other words, my work allows me to <em>think different</em>.</p><p>I look forward to working on projects and with teams where I can take a leadership role, and where I know my opinion will be valued and appreciated. I am always looking for new opportunities to grow and gain more experience as a “brand-gineer” because I value the work I do, and I hope others do too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=253e4d4d3333" width="1" height="1" alt=""><hr><p><a href="https://medium.com/design-bootcamp/the-art-of-brand-gineering-253e4d4d3333">The art of “brand-gineering”</a> was originally published in <a href="https://medium.com/design-bootcamp">Bootcamp</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why the New Firebase Web v9 Modular SDK is a Game-Changer]]></title>
            <link>https://medium.com/better-programming/working-with-the-new-firebase-web-v9-modular-sdk-aad1c641640e?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/aad1c641640e</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Fri, 06 Aug 2021 21:54:48 GMT</pubDate>
            <atom:updated>2021-08-12T00:16:53.229Z</atom:updated>
            <content:encoded><![CDATA[<h4>The future of Firebase is here</h4><h4>Reduce unnecessary bloat from Firebase-powered web apps</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lS_m1cH7m5r2ufOvY2FZA.png" /><figcaption>Image design by author; Firebase Logo used in accordance with<a href="https://firebase.google.com/brand-guidelines"> Firebase Brand Guidelines</a></figcaption></figure><p>Firebase is one of the most popular Backend-as-a-Service options for a modern tech stack. In addition to offering a NoSQL database solution called Firestore, the Firebase platform provides solutions for authentication, file storage, hosting, and analytics. The Firebase SDK is available for many platforms, including mobile, Unity, Java, C++, and the web.</p><p>One of the major shortcomings of Firebase on the web, however, was its sheer size.</p><p>According to <a href="https://bundlephobia.com/">BundlePhobia</a>, a tool used to determine the size of NPM packages, the firebase Web Javascript package <a href="https://bundlephobia.com/package/firebase@8.9.0">weighs in at 235.5kB when minified &amp; g-zipped</a>.</p><p>This can result in an additional 0.59s of loading time for some users with slower network connections. For comparison, lodashis another notoriously heavy NPM package yet it only <a href="https://bundlephobia.com/package/lodash@4.17.21">weighs 24.5kB when minified &amp; g-zipped</a>: a 10th of the size of Firebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8pEl4vbdjzQgbjZfAt50Og.png" /><figcaption>Screengrab by author</figcaption></figure><p>This is a known issue with the Firebase Web Javascript SDK and has turned many developers away from the product. Especially for developers building products for end-users who may not have access to a fast internet connection, loading a package as large as Firebase was simply not an option for them.</p><p>Thankfully, the Firebase team has been hard at work recreating the Firebase Web SDK from the group up. On July 27th, 2021, the official Firebase Blog account <a href="https://firebase.googleblog.com/2021/07/introducing-the-new-firebase-js-sdk.html">announced the pre-release of a new, modular Javascript SDK</a> that can be “up to 80% smaller!”</p><h3>Firebase on Twitter: &quot;🥁🥁 Introducing our new JavaScript library! Did we mention that it&#39;s up to 80% smaller in size? Oh yeah. It&#39;s a big deal.Check out the blog to learn more → https://t.co/XcE2T5v0im pic.twitter.com/uK9v0qe8G1 / Twitter&quot;</h3><p>🥁🥁 Introducing our new JavaScript library! Did we mention that it&#39;s up to 80% smaller in size? Oh yeah. It&#39;s a big deal.Check out the blog to learn more → https://t.co/XcE2T5v0im pic.twitter.com/uK9v0qe8G1</p><p>Firebase Web v9 will completely change how web developers use Firebase. With the introduction of a fully overhauled, modular, functional programming style and the inclusion of a Firestore “lite” library, web apps powered by Firebase Web v9 will run faster, loader quicker, and dramatically enhance both the user and developer experience.</p><p>With all that said, let’s take a look at some of the radical changes introduced in this new modular Firebase Web SDK.</p><h3><strong>Side-effect-free Imports</strong></h3><p>Previously, the Firebase Javascript SDK incorporated what is known as <em>side-effect imports</em>. In simplest terms, a side-effect occurs when a function modifies state outside of its provided scope.</p><p>For example, if function a were to modify a global variable x, then function a would produce a side-effect.</p><p>Side-effect <em>imports</em> effect the state, logic, or functionality of your program without calling any methods or referencing any variables that are exported from the package. The mere presence of the package in your program (via an import statement or require call) can affect the functionality of your program.</p><p>The old Firebase Web SDK heavily relied on side-effect imports. For each additional Firebase functionality you wanted to include in your app (authentication, Firestore, cloud storage, analytics, etc.), you had to import an additional package like so:</p><pre>// main firebase app import<br>import app from &quot;firebase/app&quot;;</pre><pre>// SIDE EFFECT PACKAGES<br>import &quot;firebase/auth&quot;;<br>import &quot;firebase/firestore&quot;;<br>import &quot;firebase/storage&quot;;</pre><p>If you have experience with working with the old Firebase Web SDK, you might have incorporated lazy-loading for importing the Firebase packages.</p><p>This solution would decrease the initial load size and time of your web app, but users would still be forced to wait for all of these packages to load before the app became fully functional.</p><p>Firebase Web v9 changes all of this. The concept of side-effect packages is non-existent in the new Firebase Web SDK, and all of the packages are completely tree-shakable.</p><p>That means that only the parts of Firebase that are needed by your app will be imported on the client. This drastically reduces the final bundle size of your app and will lead to much faster loading times.</p><h3><strong>Native Javascript ES Modules</strong></h3><p>In the new Firebase Web SDK, each individual functionality of Firebase that your app requires is imported separately thanks to the introduction of modular packages.</p><p>Because the new SDK is built into native Javascript ES modules, you can directly import only the features that your program needs: nothing more, nothing less. For example, let’s say you want to initialize your Firebase app and then watch for auth changes:</p><pre>// imports with ES modules<br>import { initializeApp } from “firebase/app”;<br>import { getAuth, onAuthStateChanged } from “firebase/auth”;</pre><pre>// initialize firebase app<br>initializeApp(firebaseConfig);</pre><pre>// watch for auth changes<br>const auth = getAuth();<br>onAuthStateChanged(auth, (user) =&gt; {<br>  // deal with authentication changes<br>});</pre><p>The introduction of modular packages in turn results in the introduction of a more functional programming style when working with the Firebase Web SDK.</p><h3><strong>Functional Programming Style</strong></h3><p>If you have ever worked with functional programming languages or libraries, you will be familiar with the advantages that functional programming grants you as a developer.</p><p>Programs that adhere to the functional programming style often have the advantages of being very intuitive and incredibly test-friendly. Although the old Firebase Web SDK was hardly difficult to comprehend, the new Firebase Web SDK is no less intuitive or beginner-friendly.</p><p>To demonstrate the functional programming style introduced by the new modular Firebase packages, let’s look at an example of updating a document in Firestore:</p><pre>import { getStorage, ref, uploadBytes } from “firebase/storage”;</pre><pre>// first, get a reference to the storage bucket for our app<br>const storage = getStorage();</pre><pre>// then, make a reference to the file<br>const usersCollection = ref(storage, “files/example.png”);</pre><pre>// finally, upload the file to the reference<br>uploadBytes(usersCollection, file);</pre><p>As you can see, there is a lot of function nesting present in this code example — the result of one function is passed as the argument to <em>another</em> function, whose result is passed to the argument of <em>another</em> function, and so on. This is in stark contrast to the method chaining approach used by the old Firebase Web SDK.</p><p>To summarize, the code used with the new Firebase SDK functional languages like F# or Scala (or functional libraries like Ramda and RxJS), whereas the code used with the old Firebase Web SDK resembles that of Java or C++.</p><h3><strong>Firestore Lite</strong></h3><p>Firestore is an incredibly powerful and useful database service. It provides a lot of features, many of which aren’t actually utilized in all web apps that use Firestore.</p><p>Many developers simply use Firestore as an easy-to-implement NoSQL database that handles many of the complexities of operating a database on both the client- and server-side.</p><p>To that extent, a lot of web apps don’t need the real-time updates capability of Firestore — they just need access to one-time document and collection queries.</p><p>The Firebase team recognizes this valid use case and has addressed it with the introduction of a new library: Firestore Lite.</p><p>The Firestore Lite library is up to 80% lighter than the old Firestore v8 library. All of the features of Firestore that you have grown to love and take full advantage of, minus real-time updates, are available in the Firestore Lite library.</p><p>This is a big win for the Firebase Web community because your apps can now be more performant and less bloated with unused code!</p><h3><strong>Compatibility</strong></h3><p>The new Firebase Web v9 SDK makes it easy to progressively upgrade from the v8 SDK. The firebase package provides a compat library to make migrating from v8 to v9 easy and incremental. For all of the places in your codebase where you aren’t ready to make the full switch to Firebase Web v9, you can take advantage of the compat library and incrementally upgrade parts of your codebase until you no longer need to use the compat library functionality.</p><p>The main drawback for this is that you won’t experience all of the bloat and load time reducing features of the new v9 SDK when using the compat library. The compat library still relies on side-effect imports, so you will have to deal with those like you would with the Firebase Web v8 SDK.</p><h3><strong>Conclusion</strong></h3><p>If you have ever worked with Firebase on the web before, the future of Firebase should really excite you.</p><p>The introduction of this new modular Firebase Web v9 SDK changes everything in terms of developing with Firebase on the web.</p><p>From making your apps less bloated to improving the experiences of both the developer and the end-user, the new Firebase Web v9 modular SDK removes one of the biggest downsides to using Firebase and will revolutionize the future of Firebase-powered web apps.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aad1c641640e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/working-with-the-new-firebase-web-v9-modular-sdk-aad1c641640e">Why the New Firebase Web v9 Modular SDK is a Game-Changer</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[9 Experience-Enhancing Technologies To Check Out For Your Next.js And React Project]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/9-experience-enhancing-technologies-to-check-out-for-your-next-js-and-react-project-68bb56741f37?source=rss-cc4c226671db------2"><img src="https://cdn-images-1.medium.com/max/2400/1*t8pXypUgpzFFSJLu42GC8Q.jpeg" width="2400"></a></p><p class="medium-feed-snippet">Libraries, frameworks, and services that will take your project to the next level.</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/9-experience-enhancing-technologies-to-check-out-for-your-next-js-and-react-project-68bb56741f37?source=rss-cc4c226671db------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/9-experience-enhancing-technologies-to-check-out-for-your-next-js-and-react-project-68bb56741f37?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/68bb56741f37</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 08:46:18 GMT</pubDate>
            <atom:updated>2021-06-29T08:46:18.140Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[3 Algorithm Runtimes Visualized With Python]]></title>
            <link>https://medium.com/better-programming/3-algorithm-runtimes-visualized-with-python-e51441827917?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/e51441827917</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Wed, 02 Jun 2021 15:35:19 GMT</pubDate>
            <atom:updated>2021-06-03T18:13:25.737Z</atom:updated>
            <content:encoded><![CDATA[<h4>Use code to visualize and determine runtime complexities for different algorithms. Featuring Matplotlib and NumPy</h4><figure><img alt="glowing colored cubes stacked on top of each other" src="https://cdn-images-1.medium.com/max/1024/0*5BXb9jSrtQHUDZzk" /><figcaption>Photo by <a href="https://unsplash.com/@joshstyle?utm_source=medium&amp;utm_medium=referral">JOSHUA COLEMAN</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>By using visualization libraries and software in Python, we are able to determine runtime complexities for different algorithms. We will first go over the basics of runtime complexity and runtime complexity analysis. Then we will cover the basic usage of <a href="https://matplotlib.org/">Matplotlib</a> for visualization of 2D plots and <a href="https://numpy.org/">NumPy</a> for calculating lines of best fit, and find out how these libraries can be used to determine their runtime complexity by comparing the plots of their runtimes to that of known functions (e.g., y = n^2, y = 2^n).</p><p>If you are interested in downloading the code featured in this article, please visit <a href="https://github.com/chroline/visualizingRuntimes">this repository on my GitHub (chroline/visualizingRuntimes)</a>.</p><h3>What is Runtime Complexity?</h3><p><em>Runtime complexity</em>, more specifically <em>runtime complexity analysis</em>, is a measurement of how “fast” an algorithm can run as the amount of operations it requires increases. Before we dive into visualizing the runtimes of different algorithms, let’s look at a couple of basic examples to explain the concept.</p><p>Consider the following add function. It accepts two parameters, a and b, and performs addition on a and b.</p><pre>def add(a, b):<br>    return a + b</pre><p>When given any two parameters (1 and 2, 2 and 3, 29347 and 93648), the amount of operations does not change. Therefore we say the algorithm runs in constant, or O(1) , time.</p><p>However, now consider the following permutations function. It accepts one main parameter, string, and prints all of the permutations of that string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/337ccb1068953208dccf794114999e75/href">https://medium.com/media/337ccb1068953208dccf794114999e75/href</a></iframe><p>As you could imagine, this function would take much longer than the previous add function; in fact, this function would run in what is called <em>factorial</em> time, represented as O(n!). That is because as the number of characters in string increases, the number of operations required to find all the permutations increases factorially.</p><p>When comparing the runtimes of two functions visually, you would notice a stark contrast in the graphs they produce. For the add function, you would observe a flat line, as the input of the function does not affect the number of operations required by the function. However, for the permutations function, you would observe a line that drastically spikes upwards (the slope of the line would approach infinity) because the number of operations increases factorially as the size of the input increases.</p><p>Now that we have covered the basics of runtime complexity analysis, we can begin the process of writing code to visualize the runtimes of different algorithms.</p><h3>Initialization</h3><p>Before running any visualizations, we must first import the necessary libraries and initialize them.</p><ul><li>Matplotlib is a library that will create and display the graphs.</li><li>NumPy is a library that consists of numerous mathematical utility functions.</li><li><a href="https://docs.python.org/3/library/timeit.html">timeit</a> is a library that we will use to time how long each call to the algorithm takes.</li><li><a href="https://docs.python.org/3/library/math.html?highlight=math#module-math">math</a> is the basic Python math library.</li><li><a href="https://docs.python.org/3/library/random.html">random</a> is the basic Python randomization library.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3650d1d0829a001825b5bb63603e1cde/href">https://medium.com/media/3650d1d0829a001825b5bb63603e1cde/href</a></iframe><h3>Demonstrations</h3><p>Below are some code segments that demonstrate how to use Matplotlib and NumPy.</p><h4>sum function</h4><p>The built-in Python sum function calculates the sum of all elements of a provided Iterable. This function implements an algorithm with a O(n) runtime complexity.</p><p>To test this, we will use the linspace method from the NumPy library to generate an iterable with 50 evenly spaced values ranging from 10 to 10,000. The graph, although not a perfectly straight plot, illustrates this.</p><pre>ns = np.linspace(10, 10_000, 50, dtype=int)<br>ts = [timeit.timeit(&#39;sum(range({}))&#39;.format(n), number=100)<br>      for n in ns]</pre><pre>plt.plot(ns, ts, &#39;or&#39;)</pre><figure><img alt="plot for sum function" src="https://cdn-images-1.medium.com/max/601/1*B_XSe_AD0g6AMTz4QivpBw.png" /><figcaption>Source: Author</figcaption></figure><p>We can add a line of best fit (using a fourth-degree function) to further exemplify this. The graph will never be a perfectly straight line, but it should come close.</p><pre>degree = 4<br>coeffs = np.polyfit(ns, ts, degree)<br>p = np.poly1d(coeffs)<br>plt.plot(ns, ts,&#39;or&#39;)<br>plt.plot(ns, [p(n)for nin ns],&#39;-b&#39;)</pre><figure><img alt="plot for sum function with line of best fit" src="https://cdn-images-1.medium.com/max/601/1*r5oVQnR26G7rfv5vruYfTQ.png" /><figcaption>Source: Author</figcaption></figure><h4>List indexing</h4><p>Retrieving an item from a list (list indexing) runs with O(1) runtime complexity, which means that the number of items in the list does not affect how long the algorithm takes to run. How is this represented in a graph?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88f601739de3d30032f8a1e9217626bf/href">https://medium.com/media/88f601739de3d30032f8a1e9217626bf/href</a></iframe><figure><img alt="graph for list indexing" src="https://cdn-images-1.medium.com/max/614/1*6ccezgQ9vX_6OvHuulIthQ.png" /><figcaption>Source: Author</figcaption></figure><h3>Algorithms</h3><p>Now we will look at the graphs produced by the following algorithms:</p><ul><li>linear search</li><li>binary search</li><li>insertion sort</li></ul><h4>Linear search</h4><p>Linear search has a runtime complexity of O(n), which will be represented by an approximately straight line.</p><p><strong>Red plots</strong> demonstrate searching for an element in a shuffled list, <strong>blue plots</strong> demonstrate searching for an element that is not present in the list.</p><p>The line of best fit for the red plots will generally be lesser than that of the blue plots because searching for an element that is not present in the list requires iterating through the entire list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2814da3907239738ef8af18c738afcb/href">https://medium.com/media/d2814da3907239738ef8af18c738afcb/href</a></iframe><figure><img alt="graph for linear search" src="https://cdn-images-1.medium.com/max/607/1*q9U9PkX2e1ig4EU3RTIOog.png" /><figcaption>Source: Author</figcaption></figure><h4>Binary search</h4><p>Binary search runs with O(log n) runtime complexity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96366e4e70a3c4d0ec22762c60d16d89/href">https://medium.com/media/96366e4e70a3c4d0ec22762c60d16d89/href</a></iframe><figure><img alt="graph for binary search" src="https://cdn-images-1.medium.com/max/391/1*KBkX7O6JA6VLl8WaOFUR2w.png" /><figcaption>Source: Author</figcaption></figure><p>After multiple runs, above is what the graph could look like in a near-perfect simulation. As you can see, there are some outliers, and in a perfect simulation, the line of best fit would be identical to a logarithmic function.</p><h3>Insertion Sort</h3><p>What runtime complexity does insertion sort have? We can use the plots of its runtime and compare those plots against the graphs of known runtimes to determine which is the closest match.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ba90fc862991ebc49eb8c99fef3b684/href">https://medium.com/media/1ba90fc862991ebc49eb8c99fef3b684/href</a></iframe><figure><img alt="graph for insertion sort" src="https://cdn-images-1.medium.com/max/595/1*uPX_TvXHHhYCIbSKYufRBQ.png" /><figcaption>Source: Author</figcaption></figure><p>We can compare that graph with graphs of different runtimes to ultimately determine which is most similar and which runtime complexity insertion sort has.</p><p><strong>Red plots</strong> represent O(log n), <strong>blue plots</strong> represent O(n^2), and <strong>green plots</strong> represent O(2^n).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9717428a28d87a500bcdc00f10ce1224/href">https://medium.com/media/9717428a28d87a500bcdc00f10ce1224/href</a></iframe><figure><img alt="graph for insertion sort with three different runtimes" src="https://cdn-images-1.medium.com/max/610/1*AIlZd2VriUIfA2vP3N1XOg.png" /><figcaption>Source: Author</figcaption></figure><p>Based on these graphs, it is safe to assume that insertion sort runs in O(n^2) time.</p><h3>Mystery Function Runtime Analysis</h3><p>Can we use visualization of the runtimes of mystery functions to determine their runtime complexities?</p><h4>Mystery function #1</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a955918baaa8778807539fbc876f38be/href">https://medium.com/media/a955918baaa8778807539fbc876f38be/href</a></iframe><figure><img alt="graph for mystery function #1" src="https://cdn-images-1.medium.com/max/614/1*4IFDDOqbYMBHK38w6QmriA.png" /><figcaption>Source: Author</figcaption></figure><p>Without even comparing this graph to the graphs of the possible runtimes, we can already safely assume that this function operates in O(n) runtime.</p><h4>Mystery function #2</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1f0866407f8b45d4c8818b14d7f7dc8/href">https://medium.com/media/a1f0866407f8b45d4c8818b14d7f7dc8/href</a></iframe><figure><img alt="graph for mystery function #2" src="https://cdn-images-1.medium.com/max/607/1*EYaSOB9QGKMNEtv30r3F5g.png" /><figcaption>Source: Author</figcaption></figure><p>This graph looks very similar to the one for insertion sort, so we can determine that this function has a runtime complexity of O(n^2).</p><h4>Mystery function #3</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1773693fd59e6c391a68476c8456cd99/href">https://medium.com/media/1773693fd59e6c391a68476c8456cd99/href</a></iframe><figure><img alt="graph for mystery function #3" src="https://cdn-images-1.medium.com/max/603/1*vdKvkHW6e4W-bC7zmio8Gw.png" /><figcaption>Source: Author</figcaption></figure><p>This function is more ambiguous than the previous two. It is evident that its runtime must be greater than O(n), as the slope increases as n increases. Let’s consider the graphs of runtimes O(n^2) in <strong>red</strong> and O(2^n) in <strong>blue</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd3c0abdd8c718f5c71ee4757778c1fa/href">https://medium.com/media/cd3c0abdd8c718f5c71ee4757778c1fa/href</a></iframe><figure><img alt="graph for mystery function #3 with two different runtimes" src="https://cdn-images-1.medium.com/max/603/1*f6jAJDByskEx39F_86l3Og.png" /><figcaption>Source: Author</figcaption></figure><p>The graph of the runtime of mystery function #3 more closely resembles the blue plots, so therefore the runtime complexity of mystery function #3 is O(2^n).</p><h3>Conclusion</h3><p>Using these visualization libraries, we are able to determine the runtime complexities of functions and algorithms by comparing them to plots/graphs of known runtimes (e.g., comparing plots of insertion sort runtime against y=n^2). In addition to determining runtime complexities, this methodology can be used to compare the speeds of different algorithms against each other. With only a few lines of code, you can quickly see the speed at which your chosen algorithms will run with large sets of data!</p><h3>Resources</h3><ul><li><a href="https://matplotlib.org/stable/tutorials/introductory/pyplot.html">Pyplot tutorial — Matplotlib 3.4.2 documentation</a></li><li><a href="https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html">numpy.polyfit — NumPy v1.20 Manual</a></li><li><a href="https://www.programiz.com/python-programming/examples/fibonacci-recursion">Python Program to Display Fibonacci Sequence Using Recursion (programiz.com)</a></li><li><a href="https://www.tutorialspoint.com/How-to-find-all-possible-permutations-of-a-given-string-in-Python#:~:text=To%20find%20all%20possible%20permutations%20of%20a%20given%20string%2C%20you,in%20the%20iterable%20as%20tuples.">How to find all possible permutations of a given string in Python? (tutorialspoint.com)</a></li><li><a href="https://adrianmejia.com/most-popular-algorithms-time-complexity-every-programmer-should-know-free-online-tutorial-course/">8 time complexities that every programmer should know | Adrian Mejia Blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e51441827917" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/3-algorithm-runtimes-visualized-with-python-e51441827917">3 Algorithm Runtimes Visualized With Python</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn How To Build APIs With Next.js]]></title>
            <link>https://medium.com/better-programming/learn-how-to-build-apis-with-next-js-109d381f8b30?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/109d381f8b30</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Mon, 08 Mar 2021 17:15:13 GMT</pubDate>
            <atom:updated>2021-03-08T17:15:13.444Z</atom:updated>
            <content:encoded><![CDATA[<h4>Use the API routes feature in Next.js to build extensible serverless lambda functions</h4><figure><img alt="screenshot" src="https://cdn-images-1.medium.com/max/1024/1*9TsvMzies8CnR77qhK287w.png" /><figcaption>Image by author</figcaption></figure><p><a href="https://nextjs.org/">Next.js</a> is a framework for React that makes developing SEO-friendly sites easy and effective for developers. Because it is loaded with great features and has <a href="https://nextjs.org/docs/getting-started">amazing documentation</a> (along with an <a href="https://nextjs.org/learn">introductory course</a>), Next.js is a great choice for developers of any experience level.</p><p>To most developers who have heard of Next.js, what comes to mind when it is mentioned is “frontend web development.” However, many may not be aware of its API routes feature, which enables you to write your frontend and<em> </em>backend code within the same code base. When combined with a serverless platform like Vercel (which was developed specifically for Next.js) or Netlify, the API routes feature of Next.js gives developers the power to easily write lambda functions for their project’s API.</p><p>In this tutorial, we will make use of this innovative feature to create a basic example of a real-world API. We will walk through the basic steps of productive API design and development, including topics such as <a href="https://en.wikipedia.org/wiki/Abstraction_(computer_science)">logic abstraction</a>, <a href="https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design">top-down design</a>, and <a href="https://en.wikipedia.org/wiki/Skeleton_(computer_programming)">skeleton code</a>. Once we have completed the API and if you are interested in going above and beyond, read the bonus “Integration Testing” section and/or optional “Create a Landing Page” and “Deploy to Vercel” sections.</p><h3>Finished Code</h3><p>As always, the code for this project is available on GitHub: <a href="https://github.com/chroline/words-aas">https://github.com/chroline/words-aas</a>. If you are interested in seeing the final product, visit <a href="https://words-aas.vercel.app/">https://words-aas.vercel.app/</a>. You can test the API routes on this URL.</p><h3>The Objective</h3><p>For this project, we will create a basic API that lets its end users randomly generate phrases based on a given query; think of it as a computer filling in the blanks for a MadLibs game. Let’s look at some examples of queries and possible responses:</p><ul><li>the $animal jumped over the $noun might respond with the cow jumped over the moon or the cat jumped over the river.</li><li>I like $gerund $pluralNoun might respond with I like dancing cars or I like bubbling buildings.</li><li>my $bodyPart is $adjective might respond with my tonsil is arrogant or my forearm is dumb.</li></ul><p>As you can see from these examples, the word type preceded by the $ character informs the API to replace it with a word. The word that it will replace it with is randomly generated from a list of words that the API will access.</p><h3>API Design</h3><p>Before we get started coding the project, let’s plan how the API will work, and then how we plan on organizing our code.</p><h4>Routes</h4><p>Next.js API routes adhere to the REST (representational state transfer) protocol, a standardized protocol used by the majority of internet APIs. As such, we have a great amount of flexibility for designing the routes of the API.</p><p>This API will accept two routes: One route will accept a slug, whereas another route will accept a JSON object with a query property.</p><ul><li><strong>Slug route:</strong> In web development, a <em>slug</em> is the unique identifier of a URL, typically at the end of the URL. For example, in the URL https://example.com/blog/this-is-the-post, the slug would be this-is-the-post. For this API, the URL will look something like this: http://localhost:3000/api/[slug], where [slug] is replaced with the desired query. Because the URL of this route will change depending on the request, it is called a <em>dynamic route</em>. This API route will be performed by sending a GET request to the server with the desired query URL.</li><li><strong>Request Body API route:</strong> This API route will accept a JSON object with the following format: { &quot;query&quot;: QUERY }, where QUERY is the desired format. This API route will not be performed simply by changing the URL; it must be performed through a POST request to the server, with the body of the request being the object with the described format.</li></ul><p>All of these routes will be written as lambda functions, with the functions accepting a req request parameter (for interacting with the user&#39;s request) and a res response parameter (for interacting with the response data to send back to the user).</p><h4>What is a lambda function?</h4><p>In computer science theory terms, a <em>lambda function</em> is any function that is not bound to an identifier, also known as being <em>anonymous</em>. The theory behind lambda functions comes from the field of lambda calculus. In essence, they allow functions to be passed as parameters to other functions.</p><p>In terms of serverless computing, the phrase <em>lambda function</em> was popularized by the AWS Lambda service which allows you to write functions that act as API endpoints (similar to what we will be doing with Next.js API routes). Like the definition in terms of computer science theory, these serverless lambda functions are not bound to any server and are given to the serverless service to call when that API endpoint is reached (hence matching the functions-passed-as-parameters quality of computer science theory lambda functions).</p><h4>Code base structure</h4><p>The most basic structure of a Next.js project is as follows:</p><pre>- pages<br>  - index.js<br>- package.json</pre><p>The pages/index.js file represents the index location of your website&#39;s router. If you had a /about page, this would correspond to the pages/about.js file, etc.</p><p>For this project, we will be using <a href="https://www.typescriptlang.org/docs/">TypeScript</a>, so instead of .js, we will use .tsx. Additionally, because we are writing API routes, they must be located in the pages/api directory.</p><pre>- pages<br>  - api<br>    - index.tsx<br>    - [slug].tsx<br>- package.json</pre><p>The two files in the api directory will be the two API routes that were previously described: index.tsx will be used for the request body route, and [slug].tsx will be used for the slug route. [slug].tsx must be wrapped in brackets [] to tell Next.js that this is a dynamic route.</p><h3>Set Up the Code Base</h3><h4>Bootstrap a Next.js project</h4><p>To start, we can create a basic Next.js project. To do so, run:</p><pre>npx create-next-app<br># or<br>yarn create next-app</pre><p>This will run the create-next-app CLI and will prompt you for your project name. I will call it words-aas for the sake of this tutorial.</p><h4>Install dependencies</h4><p>Because this project will be using TypeScript, we will need to install the typescript dependency, along with the typings dependencies for react, react-dom, and node. These dependencies are only used for development, so we will add them to devDependencies with the -D flag.</p><pre>yarn add -D typescript @types/react @types/react-dom @types/node</pre><h4>Create the util/api.ts file</h4><p>This file will contain all the logic for the API. Since we will have multiple API routes that share the same logic, it makes sense for us to adhere to the DRY (do not repeat yourself) principle and to abstract the logic into a single file that can be imported later on. That way, we can put all the complexities of the API logic away from the actual API routes, which will make development much more efficient.</p><p>Depending on the structure of your project, you can create/use a lib directory as opposed to a util directory.</p><h3>Create Skeleton API Routes</h3><p>Before we write the API logic, we can create the two skeleton API routes. Next.js houses API routes in the pages/api folder, so we will create the following two files:</p><ul><li>pages/api/[slug].ts — the slug API route. Wrapping slug in brackets will tell Next.js that this is a dynamic route, and the slug will be passed to the lambda function.</li><li>pages/api/index.ts — the request body API route. This route accepts a JSON object, so there is no need to make it a dynamic route.</li></ul><p>Inside both of these files, we will create a basic API route:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff5609987726446d8317f5598371b31a/href">https://medium.com/media/ff5609987726446d8317f5598371b31a/href</a></iframe><p>To test these API routes, run yarn dev or simply next in your project. Then, visit http://localhost:3000/api in the browser and/or http://localhost:3000/api/[slug] ([slug] can be any string). You should be greeted with Hello, world! as a response.</p><h4>Slug API route</h4><p>The slug API route will take a slug string and transform it into a phrase. As previously mentioned, the slug will consist of a list of word types joined by a comma ,.</p><p>Because the slug API route is a dynamic route, the slug will be passed to us in the req.query object. We will need to explicitly tell TypeScript that the req.query object contains a slug property, so we can use a type annotation (as { slug: string }) to fix this issue.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f1b4671aecd067f282e99a3af8dc96b/href">https://medium.com/media/1f1b4671aecd067f282e99a3af8dc96b/href</a></iframe><p>To test this route, visit http://localhost:3000/api/the $pluralNoun is $gerund in the browser, and the slug you entered should be the response you are given.</p><h4>Request body API route</h4><p>The request body API route provides a lot more customizability to the desired phrase than the slug API route. As such, we will need to manipulate the provided query string to transform it into an array of word types, as we did for the slug API route.</p><p>Because this API route accepts a JSON object, we will use the req.body object as opposed to the req.query object. We will also explicitly tell TypeScript that the req.body object contains a query property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/464516457b04e9b9b1a055b726d4c0f0/href">https://medium.com/media/464516457b04e9b9b1a055b726d4c0f0/href</a></iframe><p>To test this route, you can open a REST Client like Insomnia or Postman and test sending a JSON object with the query property to http://localhost:3000/api.</p><p>To learn more about testing these routes, scroll down to the bonus Integration Testing section.</p><h3>Write API Logic</h3><p>Here comes the fun part! Now that we have phrases split up into individual words/word types within the skeleton API routes, we can open the util/api.ts file to code the API logic.</p><p>To create the API logic, we will follow the <em>top-down design</em> practice, in which we break down the total API logic (the system) into individual functions (called subsystems). Using this practice, we can put all the individual subsystems together as we complete the system, which allows us to be much more efficient than starting from the bottom up.</p><p>The following functions will live in the util/api.ts file.</p><h4>getWordFile</h4><p>The getWordFile function accepts a wordType: string parameter and returns a list of words that match the given word type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55d18d6012a0503c1ab83d87b98ccf00/href">https://medium.com/media/55d18d6012a0503c1ab83d87b98ccf00/href</a></iframe><p>This function fetches the file for the given word type. If you are a savvy full-stack developer, you may notice that we are actually using fetch on the server side, and you may wonder, “isn&#39;t fetch only supported on the browser side?<em>”</em> Yes, the fetch API is only natively supported in browsers, but Next.js provides a polyfill for the fetch API so we can use it on the backend!</p><p>The word files will be located in the public/db folder. To download them to use in your own project, you can <a href="https://github.com/chroline/words-aas/releases/tag/word-files">download the word files folder</a>.</p><h4>getRandomWord</h4><p>The getRandomWord function accepts a contents: string parameter and returns a random word from the given contents.</p><p>The contents string is the return value from the getWordFile function and is the contents of a word file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b77ccd4ab322b7ab9ae8f5f1c5d5abc0/href">https://medium.com/media/b77ccd4ab322b7ab9ae8f5f1c5d5abc0/href</a></iframe><p>This function replaces all carriage returns with a blank string. Then, we can split the contents string into a list of words. From that list of words, we can find a random element and return it.</p><h4>phraseGenerator</h4><p>The phraseGenerator function accepts a words: string[] parameter, and returns the transformed phrase from the given words.</p><p>The words parameter is the list of word types that we obtained previously in the slug and request body routes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4d3dc19535d2a0ebdba9a2d690fb1c7/href">https://medium.com/media/f4d3dc19535d2a0ebdba9a2d690fb1c7/href</a></iframe><p>This function runs through all of the word types in the words parameter and builds the phrase based on the following conditions:</p><ul><li>If the word is empty, OR the first word is <em>a</em> (remember, a phrase that starts with <em>a</em> is an edge case that we will deal with later), we will ignore it and continue.</li><li>If the word begins with the $ character, then it is a word type that we need to handle: If the word type is not included in the database, throw an error. Else, get a random word of that word type and add it to the phrase.</li><li>Else, simply add the word to the phrase.</li></ul><p>Now we have an (almost) fully generated phrase! Because there will be an extra space at the end, we can slice it off.</p><h4>vowelTester</h4><p>The vowelTester function accepts a phrase: string argument and returns a boolean.</p><p>This function is used to determine if the first letter in the provided phrase is a vowel, which will then be used to determine if the first word <em>a</em> should be transformed into <em>an</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/882d8057946b3a127a1e2adc11dfbcb2/href">https://medium.com/media/882d8057946b3a127a1e2adc11dfbcb2/href</a></iframe><p>This function uses a RegExp expression that tests globally (g) for vowels ([aeiou]) that are lowercase or uppercase (i).</p><h4>phraseResolver</h4><p>The phraseResolver function accepts a query: string argument and returns a phrase string.</p><p>This function brings all of the previous subsystems together.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7524767d1d8b7108a92f5e33d5b4fd7a/href">https://medium.com/media/7524767d1d8b7108a92f5e33d5b4fd7a/href</a></iframe><p>The query is split up by each occurrence of a space character. A phrase is generated from those words. If the first word is <em>a</em>, the function tests for vowels to determine if the word should be kept as <em>a</em> or <em>an</em>. Finally, the phrase is returned.</p><p>Phew, that was a lot of coding and a lot of (hopefully) straightforward logic. You can view the <a href="https://github.com/chroline/words-aas/blob/main/util/api.ts">complete file on GitHub</a> to review.</p><h3>Put It All Together</h3><p>Now that we have written the API logic, we can connect it to the skeleton API routes that we created earlier.</p><h4>Slug API route</h4><p>Here is the final code for the slug API route:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75e64823a9f751e2dd3f1faf1edd241b/href">https://medium.com/media/75e64823a9f751e2dd3f1faf1edd241b/href</a></iframe><p>First, we try to resolve a phrase from the given slug. If this is successful, we send it to the user as a JSON object. However, if it is not successful, we tell the user we ran into an error. This might happen if, for example, the user requests a word type that does not exist in the database.</p><h4>Request body API route</h4><p>The code for the request body API route is almost identical to the slug API route:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cbbf5ea35643561da8be1e74ca8f6e6/href">https://medium.com/media/7cbbf5ea35643561da8be1e74ca8f6e6/href</a></iframe><p>Because we abstracted the API logic, we can simply import the phraseResolver function from the util/api.ts file in the lambda functions for both API routes.</p><p>You might notice that the logic within both lambda functions is almost nearly identical, too. Could we abstract that logic out as well so as to completely adhere to the DRY principle? Yes, we could, but it is typically considered best practice to encapsulate the req and res objects within the lambda function itself. This makes the lambda functions easier to understand because a programmer can immediately see what is being read from the req object and what is being sent back to the end user with the res object.</p><h3>Bonus: Integration Testing</h3><p>In the world of software development, there are two main types of testing your code: unit testing and integration testing.</p><ul><li><strong>Unit testing</strong> involves breaking down your code into the smallest individual units that can be tested. If your code base uses proper top-down design, your code is already broken up into small units of code: Each individual function is a unit that can be tested.</li><li><strong>Integration testing</strong> involves testing the behavior of your project/service as a whole. Whereas unit testing would test every individual subsystem, integration testing would test the entire system itself.</li></ul><p>For this project, integration testing makes more sense since the amount of logic used is minimal. (For bigger projects, consider using a combination of both unit testing and integration testing to get the most thorough results.)</p><p>If you are using a JetBrains IDE like WebStorm or IntelliJ, follow method one. Otherwise, follow method two.</p><h4>Method one: Use JetBrains IDEs</h4><p>JetBrains IDEs that are suited for web development have a built-in way to test RESTful APIs — that is, APIs that adhere to the REST protocol.</p><p>Open your project and create a new HTTP file called test. Then enter the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdd5cdca5f55625e7514b97d5dbc7620/href">https://medium.com/media/fdd5cdca5f55625e7514b97d5dbc7620/href</a></iframe><p>This code runs two requests to the API: The first tests the slug route, and the second tests the request body route.</p><p>Once you have started your development server by running yarn dev or next in your project, click the “Run all requests in file” button and select &quot;Run with no environment.&quot; A new panel should open in the bottom of your window.</p><figure><img alt="new panel" src="https://cdn-images-1.medium.com/max/1024/1*iodtpobcAyr7gaA2aWGatg.png" /></figure><p>If all goes well, you should see a green check next to “All in test,” which means that all of your requests were successfully completed. To verify the results of your requests, you can click on the file name in the output, which will bring up the response text from the server.</p><h4>Method two: Use a REST client</h4><p>There are a lot of great REST clients available to test out your RESTful API. The two most popular are <a href="https://www.postman.com/product/rest-client/">Postman</a> and <a href="https://insomnia.rest/">Insomnia</a>. I will be using Postman, but most of the steps should be similar in Postman or other REST clients.</p><p>First, create a new folder and call it API test.</p><figure><img alt="screen showing creation of new folder" src="https://cdn-images-1.medium.com/max/1024/1*y2kVA4TjiQWhmG6Rk7dMWg.png" /></figure><figure><img alt="screen showing creation of a new request" src="https://cdn-images-1.medium.com/max/1024/1*8U7JqQECICO8vTGT4Nruyw.png" /></figure><p>Then add two requests:</p><ol><li><strong>slug route</strong>: GET &lt;http://localhost:3000/api/[slug]&gt; (replace [slug] with a phrase to test.)</li><li><strong>request body route</strong>: POST &lt;http://localhost:3000/api&gt;. Switch the body type to JSON and enter a demo request object like { &quot;query&quot;: &quot;$gerund $pluralNoun&quot; }</li></ol><figure><img alt="screen showing creation of slug and body route requests" src="https://cdn-images-1.medium.com/max/1024/1*AOKBshlx77gQGKMCPh_Pjg.png" /></figure><p>You can Send both of these requests, and if they succeed you should see the response on the right-hand panel of the window.</p><h3>Wrapping Up</h3><p>Congratulations, we have finished our simple API project using Next.js!</p><p>What we just made is basic, but it hopefully gave you a good overview of what writing lambda functions for API routes in Next.js is like. If you found this tutorial helpful, stay tuned for a tutorial on more advanced practices for writing APIs with Next.js</p><p>If you are interested in going above and beyond with this project, read below for an optional and a bonus section to give your project an extra sense of completion.</p><h3>Optional: Create a Landing Page</h3><p>To attract more users, consider adding an attractive landing page for your service. Not only is Next.js great for creating serverless API routes, it’s also a framework for React. This means that you can create your frontend site and backend logic within the same project.</p><p>The Next.js router corresponds the pathname of the URL to the file of the same name in the pages directory. For example, /about will correspond to the about.tsx or about.js file, and / will correspond to the index.tsx or index.js file. To make a homepage, create an index.tsx file within the pages directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a30cacd89bca496fc2a51f8a4997b2d3/href">https://medium.com/media/a30cacd89bca496fc2a51f8a4997b2d3/href</a></iframe><p>Within each file in the pages directory, there should be a default exported function. This function is what will be rendered when Next.js retrieves your file. Therefore, when your path is /, the JSX in the Home function will be rendered.</p><p>Use your React skills to create a landing page for your Next.js service.</p><h3>Optional: Deploy to Vercel</h3><p><a href="https://vercel.com/">Vercel</a> is a platform that was developed specifically for Next.js that provides first-class support for API routes created with Next.js. Using their CLI, you can easily deploy your Next.js project to Vercel and share it with the world.</p><h4>Download Vercel CLI</h4><p>To download the Vercel CLI, run:</p><pre>yarn global add vercel</pre><p>You may have to run this command in sudo mode (only if absolutely necessary).</p><h4>Log in to Vercel</h4><p>Before you can deploy your project, you must first log in to Vercel. Run:</p><pre>vercel login</pre><p>This will prompt you to log in to Vercel in a browser window.</p><h4>Deploy</h4><p>Once you have logged in to Vercel, you can deploy by simply running:</p><pre>vercel</pre><p>Follow the steps for deploying your project.</p><p>After the deployment has succeeded, it should provide you with a link to your hosted project. Now you can share it with your friends and show them what you’ve made!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=109d381f8b30" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/learn-how-to-build-apis-with-next-js-109d381f8b30">Learn How To Build APIs With Next.js</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Innovating at Home with Emerging Robotics Technologies]]></title>
            <link>https://medium.com/swlh/robotics-technologies-26cbe49cb866?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/26cbe49cb866</guid>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[innovation]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[hardware]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Tue, 11 Aug 2020 15:01:01 GMT</pubDate>
            <atom:updated>2020-08-11T15:01:01.935Z</atom:updated>
            <content:encoded><![CDATA[<h4>New robotics software and hardware that will make you a better engineer.</h4><h4>Become an innovator by experimenting with your own robotics projects.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ifoRPmOcV4BDfUSzwKnZhw.jpeg" /><figcaption>Photo by Jelleke Vanooteghem | <a href="https://unsplash.com/@ilumire">@ilumire on Unsplash</a></figcaption></figure><p>While stuck indoors during these past few months, I have had a lot more time on my hands, something which presumably is very common around the world.</p><p>If you, like me, are experiencing newfound free time, there’s never been a better time to improve your repertoire as a programmer, builder, and innovator by working with new technologies and homemade robotics.</p><blockquote>The best way to gain knowledge is through experience—this is especially true when it comes to programming and building.</blockquote><p>By providing some emerging and innovative concepts in the field of robotics and computing, I hope to offer a way that you can become an innovator with simple homemade robotics projects.</p><p>I’ll also share how I used each of these concepts to create a project of my own that demonstrates the real-world applications of these technologies.</p><h3>First thing: hardware</h3><p>Many developers focus only on honing in on their programming skills, and not the real-world applications of such programming. However, especially in the field of robotics, it is advantageous for developers to have valuable knowledge on the uses of tangible products, and to have experience working with not only software but hardware as well.</p><h4>Using a Raspberry Pi 4 as a server</h4><p>The Raspberry Pi is not a new nor “emerging” technology — the first RPi was released in 2012, and it has established itself as an essential part of many hobby or homemade computer projects.</p><p>Despite this, Raspberry Pis are proving themselves to be very efficient microcomputers, and Raspberry Pi clusters are becoming more and more popular among developers and early-stage startups. Raspberry Pis are no longer just for hobbyists and low-resource projects. The Raspberry Pi 4 was recently released and featured a faster processor, 4k mini-HDMI ports, and USB-C power supply.</p><p>You can treat a Raspberry Pi as your personal in-house server. If you give it power and don’t turn it off, a Raspberry Pi can be a very effective solution for always-on projects. By simply running your server-side application on your Raspberry Pi, you can have a complete backend that runs inside in-house, which can be a very cost-effective solution.</p><h4>Controlling robotics components with an Arduino</h4><p>Like Raspberry Pi, the Arduino has become a necessity in almost all robotics projects. Arduino is a programmable microcomputer that allows its user to control various sensors and moving pieces. Its versatility and user-friendliness make the Arduino one-of-a-kind. Arduinos are used by engineers of all skill levels, from beginners to experienced builders.</p><p>Configuring and programming the Arduino is a great way to gain experience controlling robotics components. You can build anything from small projects to full-scale robots and machines. You can program the Arduino using the Arduino IDE, but the Arduino also <a href="https://www.arduino.cc/en/reference/firmata">supports the Firmata protocol</a>. The Arduino IDE only supports the Arduino programming language, but if you opt-in to using Firmata, you have more languages to choose from, including Javascript.</p><h4>Bluetooth on Arduino with HC-05 module</h4><p>When Bluetooth was introduced to mass markets in the late ’90s and early 2000s, it revolutionized the way people used their devices. With Bluetooth, users are able to wirelessly connect and interact with their devices. This functionality is available on Arduino with the HC-05 module.</p><p>With Bluetooth on Arduino, you can wirelessly control your robot from a controller, a computer, or even a smartphone. This opens up many possibilities for creative projects with Arduino.</p><h3>Next: software</h3><p>Software is often overlooked in robotics. Many teams tend to focus solely on the hardware aspect of the robot all the while treating software with less priority.</p><blockquote>In fact, software should be of utmost priority to engineers, because lackluster programming can lead to a lackluster final result.</blockquote><h4>Program microcomputers in Javascript with Johnny-Five</h4><p>When you think of programming languages for robotics, Javascript probably doesn’t immediately come to mind. Despite being ranked consistently in the top 5 most used programming languages, Javascript isn’t often used to control low-level machines or robotics.</p><p>Johnny-Five is a complete paradigm shift for the world of robotics. It gives developers the ability to program microcomputers like Arduinos in Javascript.</p><blockquote>“Any application that can be written in JavaScript, will eventually be written in JavaScript.”— Jeff Atwood</blockquote><p>You can now program your robotics programs in Javascript, a language many developers are most comfortable with. This means that you are able to use the millions of available Node.js packages inside of your robotics programs, which will hopefully lead to many creative robotics projects that are programmed with Javascript!</p><h4>Kotlin, the language of tomorrow</h4><p>Kotlin is a language based on the JVM that compiles to Java or Javascript (as well as native binaries with Kotlin/Native.) Since the release of v1.0 in 2016, Kotlin has become increasingly popular, with users ranging from single-person development teams to large hundred-person teams. After the introduction of Kotlin on Android, it has been called the <a href="https://dzone.com/articles/why-kotlin-is-the-future-of-android-app-developmen">“future of Android App Development.”</a> However, Kotlin can be used for much more than Android development.</p><p>Ktor is a web framework for Kotlin that is <a href="https://ktor.io/">“easy to use, fun and asynchronous”</a> — from experience I can confirm that is very true. Kotlin has an innovative modern syntax that allows programmers to be more expressive and efficient with their code. Using Ktor, you can write a fully functional backend server in minimal time.</p><p>Kotlin also introduces a concept known as “coroutines” which is a unique, cutting-edge take on asynchronous programming. At a very (very) high level, coroutines allow a program to perform multiple tasks at once, and coroutines give developers a pragmatic way to manage those tasks. With these things in mind, you should consider using Kotlin for your next proof-of-concept and/or server-side application.</p><h3>Putting it all together</h3><h4>Planning and ideation</h4><p>After diving deeper into these exciting technologies in the world of robotics, I challenged myself to create my own unique project. The project I chose was a robot built with an Arduino that would be controlled by my smartphone. I decided that I would set up an application flow that would work as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iZ9SYFUU0VhyLjp8SiP1kw.png" /></figure><p>This was what I determined would be the most effective way of accomplishing the final product I wanted.</p><blockquote>Remember, software should not be a low priority in your project.</blockquote><h4>Robot hardware</h4><p>I built the robot using some spare metal parts, a breadboard, a battery case, the HC-05 module, two motors, and of course an Arduino. I was very pleased with the final result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KInIlJyk9jVHUgacr_xKSA.jpeg" /><figcaption>Featuring a 3d printed mascot.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqSnvEFOa7TqMcmVjF4Gnw.jpeg" /></figure><h4>Front-end app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*cd3hZ1ODKnjUtI_wivvHyA.png" /></figure><p>For the front-end app that would control the robot, I wanted to use the phone’s gyroscope to control the robot. This would mean that when you tilt the phone, the robot would move in that direction. It’s a little gimmicky, but in the end, it was very fun to play around with.</p><p>I chose to write the app in Flutter so that it would work cross-platform.</p><p>The app works by first connecting to the Raspberry Pi server and establishes a connection via WebSockets. Then, it begins to listen to updates from the phone’s gyroscope. Every 250 milliseconds, the app checks for an update, and if it detects one, it will send the updated data back to the RPi server.</p><p>I am working on the ability to program routines for the robot to do. This could be anything from a square, to a couple of spins, to a choreographed dance!</p><h3>Final thoughts</h3><p>To be an innovator is to do something your own way, and to not be afraid to try new things. What better way to become an innovator than by gaining new skills in the field of robotics?</p><p>I hope that by reading about these concepts and technologies for robotics, you are excited to learn more and that you start to build your own projects. The best way to gain knowledge is through experience; this is especially true when it comes to programming and building. These are only a couple of new technologies in the world of programming and robotics. If you are interested in more of these ideas, I implore you to look into the exciting new innovations made in real-world robotics. These new ideas and technologies are going to change our world.</p><blockquote>“If you want something new, you have to stop doing something old.” — Peter F. Drucker</blockquote><p><em>This article was written in collaboration with members of FTC Robotics team #10415. Go Warbots!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26cbe49cb866" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/robotics-technologies-26cbe49cb866">Innovating at Home with Emerging Robotics Technologies</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate TypeScript Development Configuration]]></title>
            <link>https://medium.com/better-programming/ultimate-typescript-development-configuration-4ecf9f22686?source=rss-cc4c226671db------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ecf9f22686</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[eslint]]></category>
            <dc:creator><![CDATA[Cole Gawin]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 02:24:21 GMT</pubDate>
            <atom:updated>2020-03-14T22:54:01.912Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<h4>A good starting point</h4><h4>How I configure for development with ts-node-dev, ESLint with Airbnb style guide, Prettier, and TypeScript</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4oFpzzAu_bvQHAkfiTovbA.png" /></figure><p><a href="https://www.typescriptlang.org/">TypeScript</a> is quickly becoming one of the most-used, most-loved, and <a href="https://redmonk.com/sogrady/2019/07/18/language-rankings-6-19/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=language-rankings-6-19">most-popular</a> languages.</p><p>However, setting up a productive workspace for TS development can be a hassle. This guide demystifies the one of the most frustrating yet most essential parts of modern programming with TypeScript.</p><p>All code used in this guide is available on <a href="https://gitlab.com/colegawin/ts-ultimate">GitLab</a>.</p><p>In this guide, I’ll be using <a href="https://yarnpkg.com/">Yarn</a>. It’s my package manager of choice due to its versatility, speed, and performance compared to <a href="https://www.npmjs.com/">npm</a>.</p><p>I use <a href="https://code.visualstudio.com/">Visual Studio Code</a> as my IDE, so I will first set up VS Code for TypeScript development. Feel free to skip this section and continue with part 2.</p><h3>Part 1: VS Code Setup</h3><p>The are the extensions I use for TypeScript development in VS Code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/095c0348ea361acac7c28a2c64c9a973/href">https://medium.com/media/095c0348ea361acac7c28a2c64c9a973/href</a></iframe><p>Some personal choices that I use in VS Code:</p><ul><li><a href="https://marketplace.visualstudio.com/items?itemName=monokai.theme-monokai-pro-vscode">Monokai Pro</a>: “Professional theme and matching icons, from the author of the original Monokai color scheme.” (The best color theme imo.)</li><li><a href="https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons">vscode-icons</a>: Icons for Visual Studio Code. (The best set of icons for VS Code imo.)</li><li><a href="https://marketplace.visualstudio.com/items?itemName=natqe.reload">Reload</a>: Add a reload button to the status bar’s bottom right. (For when VS Code decides it’s time to get funky.)</li></ul><p>Add these lines to your VS Code settings.json:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb2c7a29d6c19294419f9f5f8eb38f29/href">https://medium.com/media/bb2c7a29d6c19294419f9f5f8eb38f29/href</a></iframe><p>This enables <a href="https://eslint.org/">ESLint</a> auto-fixing and <a href="https://prettier.io/">Prettier</a> auto-formatting.</p><h3>Part 2: Project Configuration</h3><p>Let’s first create a directory. For this, we’ll call it ts-ultimate.</p><pre>mkdir ts-ultimate</pre><p>While we’re at it, run npm init.</p><p>Inside that directory, create a src folder. This is where your TS/JS files will go. Create an index.ts file inside as well.</p><h4>Install TypeScript and ts-node-dev</h4><p>Next, we will install TypeScript (of course) and <a href="https://github.com/TypeStrong/ts-node">ts-node</a>.</p><pre>yarn add typescript ts-node-dev —-dev</pre><p>ts-node-dev enables REPL for TypeScript, with auto-restarting, which enables us to see our TypeScript code work in real-time, sans compilation (think <a href="https://www.npmjs.com/package/nodemon">nodemon</a> or <a href="https://www.npmjs.com/package/node-dev">node-dev</a>, but for TypeScript).</p><p>Save these packages to devDependencies as they will only be required for development purposes.</p><h4>ESLint, extensions, and plugins</h4><p>We’ll also need ESLint and a few extensions and plugins</p><pre>yarn add eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-airbnb eslint-config-prettier eslint-plugin-prettier prettier —-dev</pre><p>Add these to a .eslintrc.js file, like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d62f8bb67072845baad81795fbd6812b/href">https://medium.com/media/d62f8bb67072845baad81795fbd6812b/href</a></iframe><h4>Configure Prettier</h4><p>This is how I personally configure Prettier:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2119b2381776da8416a562ba6185469/href">https://medium.com/media/c2119b2381776da8416a562ba6185469/href</a></iframe><p>Now, go ahead and open up your original package.json.</p><p>Add a script called lint. We will use this script to lint our TS/JS files.</p><pre>&quot;lint&quot;: &quot;eslint --fix ./src/*&quot;</pre><p>This tells the ESLint CLI to lint all files located in the src directory and fix any problems it is able to. Note that <em>most</em> problems you will have to fix yourself.</p><p>Run yarn lint in your ts-ultimate directory and no errors should be found!</p><p>However, if you have no files in the src directory, you may get an error that says: “No files matching the pattern”. That is expected behavior, so you can ignore this error.</p><p>If you are using VS Code, this is automatically integrated into the ESLint and Prettier plugins, so most errors will show up in your workspace while editing.</p><h3>Part 3: Live Updates Without Compiling</h3><p>To accomplish this not-so-daunting task, we will use ts-node-dev.</p><p>According to its npm README, ts-node-dev “restarts the target node process when any of the required files change, but shares the TypeScript compilation process between restarts.”</p><p>Basically, this means that we will be able to auto-reload our TypeScript file without waiting for tsc to compile it.</p><p>Let’s create a dev script that uses nodemon:</p><pre>&quot;dev&quot;: &quot;ts-node-dev --respawn --transpileOnly src/index.ts&quot;</pre><p>…and a dev:debug script:</p><pre>&quot;dev:debug&quot;: &quot;ts-node-dev --inspect=4321 --respawn --transpileOnly src/index.ts&quot;</pre><p>The inspect flag informs ts-node-dev to attach a <em>debugger</em> to the process at port 4321 (this number doesn’t matter) to which VS Code will listen.</p><h3>Part 4: Visual Studio Code Debugging</h3><p>Using VS Code, we can add breakpoints to our TypeScript code to inspect and debug our code at these points.</p><p>Go to your ts-ultimate directory and create a file called launch.json inside.</p><pre>mkdir .vscode<br>cd .vscode<br>touch launch.json</pre><p>Paste the following into your launch.json:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75527f2eec631e3a8ca841d6ab76f1c2/href">https://medium.com/media/75527f2eec631e3a8ca841d6ab76f1c2/href</a></iframe><p>This creates a debug config that will attach itself to the dev:debug script when running.</p><p>To do so, first run the dev:debug script.</p><pre>yarn dev:debug</pre><p>Once you have this script running, open the debug tab, and, in the top navbar, click the play button next to <em>Node: Nodemon</em>.</p><p>VS Code should now be able to debug your script when you add breakpoints.</p><h3>Conclusion</h3><p>Congrats on making it this far! You now have a super-powerful TypeScript development environment with ESLint with Airbnb style guide and Prettier integration, live reloading, and on-the-fly VS Code debugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eRSBSnKslszUIwdzOLMQ7Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ecf9f22686" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/ultimate-typescript-development-configuration-4ecf9f22686">The Ultimate TypeScript Development Configuration</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>