<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mogwai</title>
    <description>The latest articles on DEV Community by mogwai (@vunderkind).</description>
    <link>https://dev.to/vunderkind</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%2F244908%2F5f13a80e-b3ba-440c-b4fa-6f0024384530.jpeg</url>
      <title>DEV Community: mogwai</title>
      <link>https://dev.to/vunderkind</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vunderkind"/>
    <language>en</language>
    <item>
      <title>What do JavaScript devs need to know about Fintech development?</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Thu, 24 Jun 2021 02:39:17 +0000</pubDate>
      <link>https://dev.to/vunderkind/what-do-javascript-devs-need-to-know-about-fintech-development-5gah</link>
      <guid>https://dev.to/vunderkind/what-do-javascript-devs-need-to-know-about-fintech-development-5gah</guid>
      <description>&lt;p&gt;A brief introduction:&lt;/p&gt;

&lt;p&gt;I work in the European fintech space, on a platform that's an API of APIs that helps fintech businesses get off the ground quickly. &lt;/p&gt;

&lt;p&gt;Even though my coding skills are pretty decent, I find that my real challenge starting out were mostly connected to my limited understanding of the financial industry as a whole. I've been bridging that gap by taking courses on financial markets, business models and technologies but I'd like to know from more experienced developers in the fintech space.&lt;/p&gt;

&lt;p&gt;How did you get knowledgeable, and what would you say was the most important route to gaining this competence?&lt;/p&gt;

</description>
      <category>fintech</category>
      <category>javascript</category>
      <category>crypto</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Understanding Math.random() in JavaScript!</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Sat, 01 Aug 2020 07:10:36 +0000</pubDate>
      <link>https://dev.to/vunderkind/understanding-math-random-in-javascript-3f4</link>
      <guid>https://dev.to/vunderkind/understanding-math-random-in-javascript-3f4</guid>
      <description>&lt;p&gt;It’s incredible the number of times you’ll have to use Math.random() (out of all the Math methods that ship out-of-the-box with JavaScript).&lt;/p&gt;

&lt;p&gt;If you’re a creative coder, you’ll need it to make generative art (even though many of the tools of creative coding ship their own flavor of the trusty Math.random()). As a result, it’s probably a great idea to reason about how Math.random() works.&lt;/p&gt;

&lt;p&gt;At its very base, Math.random() is designed to do only one thing: generate a number between 0 and 1. I like to think of it as a white noise machine, generating white and black pixels to fill a whole screen. That analogy is powerful when you consider that white noise machines go into the creation of mosaics and even procedurally generated clouds, among other things.&lt;/p&gt;

&lt;p&gt;In other words, Math.random() is deceptively simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0≤ n &amp;lt;1
//What Math.random generates
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Math.random() generates a number between zero and one, but never (or rarely ever) generates one itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extending Math.random()
&lt;/h2&gt;

&lt;p&gt;If we think of &lt;code&gt;0≤n&amp;lt;1&lt;/code&gt; as an algorithm for the procedural generation of random floating digits, we can then generate numbers not limited to 0 and one. We only need to reduce the skeleton of our desired range to the base format.&lt;/p&gt;

&lt;p&gt;Say you want to generate a number between 5 and 15. This is the mental sequence you’ll follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I need a number between 5 and 15.&lt;/li&gt;
&lt;li&gt;This can be represented mathematically as 5≤n&amp;lt;16 (can you guess why we write 16 and not 15?)&lt;/li&gt;
&lt;li&gt;But Math.random() can only think in 1s and 0s. So how to get things in agreement?&lt;/li&gt;
&lt;li&gt;First subtract five from every part of that mathematical model of computation.&lt;/li&gt;
&lt;li&gt;That gives us &lt;code&gt;5–5≤n-5&amp;lt;16–5&lt;/code&gt;…&lt;/li&gt;
&lt;li&gt;…which is &lt;code&gt;0≤n-5&amp;lt;11&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Okay. So we have a zero on one end. But we need a 1, not an 11, on the other end!&lt;/li&gt;
&lt;li&gt;Oh, I know! Let’s divide everything by 11!&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0/11≤(n-5)/11&amp;lt;11/11&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;That’s &lt;code&gt;0≤(n-5)/11&amp;lt;1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Yay!&lt;/li&gt;
&lt;li&gt;But we aren’t done :(&lt;/li&gt;
&lt;li&gt;You see, &lt;code&gt;(n-5)/11&lt;/code&gt; is r. That is, the random number &lt;code&gt;Math.random()&lt;/code&gt; will generate. What we want to get it the factor we’ll multiply r by to get numbers within the range we want (in this case, 5–15). To do this, we have to find &lt;code&gt;n&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;r = (n-5)/11&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Multiply both sides by 11&lt;/li&gt;
&lt;li&gt;&lt;code&gt;n-5 = r*11&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Add five to both sides&lt;/li&gt;
&lt;li&gt;n = (r*11) + 5
Let’s take this for a spin, shall we? Let’s write a function called &lt;code&gt;fiveToFifteen&lt;/code&gt;.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h1oYR1Ed--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AxJMGFTmZH1fgVzMY4RhSeQ.png" alt="Carbon"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And it works!&lt;/p&gt;

&lt;p&gt;But what if you wanted to change the number from five and fifteen to, say 8 and 19? Will you have to do that 18-step reasoning we did earlier?&lt;/p&gt;

&lt;p&gt;Mercifully not. Instead of thinking in pure numbers (5 and 15), we can think in terms of &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 is min, 1 is max.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So we can start with this basic idea instead:&lt;br&gt;
&lt;code&gt;min ≤n&amp;lt;max&lt;/code&gt;&lt;br&gt;
If we go through the 18 steps again, we have something like this at step 9:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;min-min≤n-min&amp;lt;max-min&lt;/code&gt;, which gives us &lt;code&gt;0≤n-min&amp;lt;max-min&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Divide through by (max-min), and we get:&lt;/li&gt;
&lt;li&gt;0/(max-min)≤n-min/(max-min)&amp;lt;(max-min)/(max-min)&lt;/li&gt;
&lt;li&gt;0≤n-min/(max-min)&amp;lt;1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aha.&lt;/p&gt;

&lt;p&gt;We can then run &lt;code&gt;r = (n-min)/max-min&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiply both sides by &lt;code&gt;(max-min)&lt;/code&gt;, and we get
&lt;code&gt;r * (max-min) = n-min&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add min
r * (max-min) + min = n&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can then rewrite our function to adapt to any random number generation need like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;anyRandomNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="o"&gt;*=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;anyRandomNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;69&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;87&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thanks to Scrimba’s math for frontend developers for helping me understand this, and I hope it is a useful mental model for you as well!&lt;br&gt;
This was originally published &lt;a href="https://thevunderkind.com/understanding-math-random-c34febf92d31"&gt;on my blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>5 Non-Programming Books That Inspire Me to Become a Better Programmer</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Wed, 08 Jul 2020 00:57:31 +0000</pubDate>
      <link>https://dev.to/vunderkind/5-non-programming-books-that-run-the-risk-of-making-you-a-better-programmer-2eo0</link>
      <guid>https://dev.to/vunderkind/5-non-programming-books-that-run-the-risk-of-making-you-a-better-programmer-2eo0</guid>
      <description>&lt;h2&gt;
  
  
  Who's this for?
&lt;/h2&gt;

&lt;p&gt;For the individual who loves to color outside the lines sometimes; the sort of person who thinks of programming as yet another professional attribute that can benefit from a broader approach to understanding life. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we read?
&lt;/h2&gt;

&lt;p&gt;Since the beginning of July, I've decided to inject a bit of consistency in the way I read. Like everyone else, I read &lt;em&gt;something&lt;/em&gt; every day - a blog post, a news article, or something that ranks high on &lt;a href="https://readup.com/vunderkind"&gt;Readup&lt;/a&gt;, one of my favorite places to discover high-quality reading material. &lt;/p&gt;

&lt;p&gt;As a programmer, however, whenever I find myself reading anything, I also find myself wondering if I wouldn't benefit more from reading Mozilla's (MDN) JavaScript documentation for some obscure JS use case, or completing Wiley's Poignant Guide to Ruby, or Eloquent JavaScript, or 'Think Like a Computer Scientist'...you get the idea. &lt;/p&gt;

&lt;p&gt;So in July, I decided to return to reading about things that would enrich my reading experience overall, biasing in favor of things that will make me a better programmer. Here's a list of some books I have read in the past, and books that are on my in-progress tab which I think help me appreciate programming more instead of distracting me from the noble goal of becoming a 10X developer. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Drunkard's Walk, by Leonard Mlodinow
&lt;/h2&gt;

&lt;p&gt;This is probably my favorite book this year. I consider it a love letter to randomness, and the school of thought that formed around it: probability theory, statistics, even quantum theory. &lt;/p&gt;

&lt;p&gt;It's perfect for people who enjoy prose, or cleverly-written essays. It is written from the perspective of an exploration into the history of the mathematics around randomness, and you'll discover that a lot of what we know about randomness was inspired by gambling, gaming, and the worship of gods! No wonder Einstein said God does not play with dice. &lt;/p&gt;

&lt;p&gt;I started reading this book because I wanted to understand randomness more. It started one night when I was writing several functions to help with creating &lt;a href="https://threejs-inky.now.sh/webgl.html"&gt;generative art&lt;/a&gt;. I was using a library that piggybacked off of the default &lt;code&gt;Math.random()&lt;/code&gt; method to create 'noise' that ensured every generative art piece was different from the last. It piqued my curiosity about randomness and led me to this golden book!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/Drunkards-Walk-Randomness-Rules-Lives/dp/0307275175"&gt;Check out the book on Amazon&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cryptonomicon, by Neal Stephenson
&lt;/h2&gt;

&lt;p&gt;This one is based on history - so probably accurate to call it historical fiction. Neal Stephenson is a masterful storyteller, and I can already see that (disclaimer: I'm about 20% into the book, which is about 1,539 pages on my Apple Books). &lt;/p&gt;

&lt;p&gt;For anyone who's looked up Alan Turing (or watched The Imitation Game), you'd remember that in the Second World War, the Allies decrypted the Enigma Code, then spent a considerable amount of time throwing the Nazis off that scent. In Cryptonomicon, the story goes between two timelines (&lt;a href="https://www.nealstephenson.com/cryptonomicon.html"&gt;one set in the 1940s and 'present-day'&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;A fictional version of Dr. Alan Turing (among other notable scientists of history) is in this book as well, and they work with the protagonists to decode Axis communications, use it to thwart their enemies while simultaneously hiding the fact that they've compromised Axis communication codes. &lt;/p&gt;

&lt;p&gt;In the present-day timeline, the grand-children of the World War II codebreakers continue the tradition, finally confronted with an unbreakable code that throws weirdness in the mix. &lt;/p&gt;

&lt;p&gt;I started reading this based on a Twitter recommendation for some of the best speculative fiction (it started with someone complaining about SF being watered down nowadays), and I found this 'chunky' enough to take a stab at. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/s?k=Cryptonomicon&amp;amp;i=stripbooks&amp;amp;adid=082VK13VJJCZTQYGWWCZ&amp;amp;campaign=211041&amp;amp;creative=374001&amp;amp;tag=x_gr_w_bb_sin-20&amp;amp;ref=x_gr_w_bb_sin"&gt;Get Cryptonomicon on Amazon&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pure Mathematics For Beginners, by Dr Steve Warner
&lt;/h2&gt;

&lt;p&gt;I know, I know. Screw Mathematics. All my friends hate Mathematics. But, you gotta admit - math doth rule everything about us. &lt;/p&gt;

&lt;p&gt;I was never one for Math, and I blame the way it was taught to me as a kid - it was just one more class to pass, with no immediately-apparent connection to my real world. Who cared if a plane traveled 30 degrees west, huh? &lt;/p&gt;

&lt;p&gt;As soon as I entered the fantastic world of algorithms, it became apparent to me how much simpler my life would be if I returned to some math concepts. Here's my unpopular opinion: many tutorials and courses will tell you you don't need to know math to be a good programmer. That's probably true, but knowing math definitely makes you a great problem-solver!&lt;/p&gt;

&lt;p&gt;This book starts with logic, which adds the spice to your &lt;code&gt;||&lt;/code&gt; pipes (or logical ORs) and logical ANDS (&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;), explains Set Theory, the principles of vectors, number bases, linear algebra among other things. &lt;/p&gt;

&lt;p&gt;You don't need to read this deeply. Even a casual read of this will make you a better human being by far, I guarantee it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/Pure-Mathematics-Beginners-Rigorous-Introduction/dp/0999811754/ref=sr_1_2?crid=38TJO1IV9PSO5&amp;amp;dchild=1&amp;amp;keywords=pure+mathematics+for+beginners&amp;amp;qid=1594168959&amp;amp;s=books&amp;amp;sprefix=pure+mahematics+for+beginne%2Cstripbooks%2C500&amp;amp;sr=1-2"&gt;Get Pure Mathematics for Beginners on Amazon&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Final Invention, by James Barrat
&lt;/h2&gt;

&lt;p&gt;I began reading this after getting high on &lt;a href="http://nautil.us/issue/53/monsters/the-last-invention-of-man"&gt;The Last Invention of Man&lt;/a&gt; from Issue 43 of Nautilus. &lt;/p&gt;

&lt;p&gt;If you've been infected by Elon Musk's paranoia about AI, then you should read this. Haha. &lt;/p&gt;

&lt;p&gt;Musing on these topics reminds me of Rita King, who said: "Being human is a fleeting moment between stardust and robots."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/Our-Final-Invention-Artificial-Intelligence/dp/1250058783/ref=sr_1_2?dchild=1&amp;amp;keywords=our+final+invention&amp;amp;qid=1594169260&amp;amp;s=books&amp;amp;sr=1-2"&gt;Our Final Invention&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Tyrannosaurus Prescriptions, by Isaac Asimov
&lt;/h2&gt;

&lt;p&gt;I love Isaac Asimov, and you do too - you just don't know it yet. This book is a collection of essays his sponsors asked him to write about the future, sociopolitical events, and anthropological observations in general. &lt;/p&gt;

&lt;p&gt;Published in 1977, Asimov made attempts to guess the future of humanity. He was uncannily accurate in some regard and hilariously off-course in others, but the main reason I'm recommending this is that it gives you a precious insight into how people &lt;em&gt;think&lt;/em&gt; about life in the meta, or the macro if you will. &lt;/p&gt;

&lt;p&gt;In reading the Tyrannosaurus Prescriptions, I found myself yearning for an opportunity to think about the broader implications of things (Moore's versus Eroom's law, for example). and that is a rewarding exercise in itself. It can help shake the tedium from programming (let's face it: programming does get tedious sometimes!) and offer you a new perspective about your role in the universe. &lt;/p&gt;

&lt;p&gt;I recommend for thinkers and dreamers alike!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/Tyrannosaurus-Prescription-Isaac-Asimov/dp/0879755407/ref=sr_1_1?dchild=1&amp;amp;keywords=the+tyrannosaurus+prescription&amp;amp;qid=1594169633&amp;amp;s=books&amp;amp;sr=1-1"&gt;Take a peek into The Tyrannosaurus Prescriptions here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Final notes
&lt;/h3&gt;

&lt;p&gt;I am not affiliated with any of the links I shared, so this article is not a sinister plot to earn money off affiliate marketing. I just rather love recommending books!&lt;/p&gt;

&lt;p&gt;Also, if you have interesting books I should check out, reply to this!&lt;/p&gt;

&lt;p&gt;Have a great day, DEV sloths!&lt;/p&gt;

</description>
      <category>books</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A Spotify Playlist Based on your Horoscope!</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Thu, 02 Jul 2020 00:28:47 +0000</pubDate>
      <link>https://dev.to/vunderkind/a-spotify-playlist-based-on-your-horoscope-2322</link>
      <guid>https://dev.to/vunderkind/a-spotify-playlist-based-on-your-horoscope-2322</guid>
      <description>&lt;p&gt;Last month, I collaborated with another web developer/designer to create &lt;a href="https://astrofy.live"&gt;Astrofy&lt;/a&gt;, a simple app that creates a playlist based on your Horoscope. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dty8Y44I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gjcqlxf93xpcnottmqor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dty8Y44I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gjcqlxf93xpcnottmqor.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://astrofy.live"&gt;Check it out!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tech
&lt;/h2&gt;

&lt;p&gt;We used the Spotify API for this, and the backend code was written in Node (via Expressjs). &lt;/p&gt;

&lt;p&gt;Some modules that made this possible were aztro.js and horoscope.js. I should mention that we used the &lt;code&gt;web-spotify-api&lt;/code&gt; npm module, which made it significantly easier to use the Spotify API in the backend. &lt;/p&gt;

&lt;p&gt;In the frontend, I used React, with a few basic hooks, namely: &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Help me revamp my web dev portfolio!</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Mon, 29 Jun 2020 02:59:16 +0000</pubDate>
      <link>https://dev.to/vunderkind/help-me-revamp-my-web-dev-portfolio-1fi3</link>
      <guid>https://dev.to/vunderkind/help-me-revamp-my-web-dev-portfolio-1fi3</guid>
      <description>&lt;p&gt;I'm currently getting ready to revamp my portfolio page (I tend to use it as a way to update myself on design + dev knowledge - so my portfolio 'levels up' as my experience does.)&lt;/p&gt;

&lt;p&gt;I've been writing code for ~10 months now, and I wrote this in the 8th month. Overdue for a makeover, eh?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://justinirabor.com"&gt;View here&lt;/a&gt;&lt;br&gt;
&lt;a href="https://justinirabor.com/projects"&gt;See my projects&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would appreciate actionable feedback/resources/considerations for making the new version great.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>What's the quickest, most rigorous path to becoming a game developer?</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Mon, 15 Jun 2020 23:27:36 +0000</pubDate>
      <link>https://dev.to/vunderkind/what-s-the-quickest-most-rigorous-path-to-becoming-a-game-developer-101j</link>
      <guid>https://dev.to/vunderkind/what-s-the-quickest-most-rigorous-path-to-becoming-a-game-developer-101j</guid>
      <description>&lt;p&gt;For context, I'm a JavaScript software developer and I've written my fair share of &lt;a href="https://justin.irabor/projects"&gt;MUD (multi-user dungeon) games and canvas-based games&lt;/a&gt;, but lately I've been trying to kick it up a notch and create more robust, visually appealing games (ideally) for the web. &lt;/p&gt;

&lt;p&gt;(Aside: I've been learning three.js, creative coding and AR.js. I'm neither here nor there with those either)&lt;/p&gt;

&lt;p&gt;I hear that I need to learn Unity and C++, but I'm not particularly sure the best way to dive into this, and the more I think about it, the more I overthink it - the more I find myself procrastinating. &lt;/p&gt;

&lt;p&gt;In a nutshell, I need help: if you're a game developer, what things do I need to know? I could really use a syllabus-styled list. &lt;/p&gt;

&lt;p&gt;I'll appreciate all the help I can get! &lt;/p&gt;

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

</description>
      <category>unity3d</category>
      <category>game</category>
      <category>c</category>
    </item>
    <item>
      <title>Your Heroku App Keeps Crashing After Deploy? Tell Me About It</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Sat, 06 Jun 2020 04:42:21 +0000</pubDate>
      <link>https://dev.to/vunderkind/your-heroku-app-keeps-crashing-after-deploy-tell-me-about-it-1a71</link>
      <guid>https://dev.to/vunderkind/your-heroku-app-keeps-crashing-after-deploy-tell-me-about-it-1a71</guid>
      <description>&lt;p&gt;Heroku is easy to use, until it isn't. The first day we - a bunch of full stack developers-in-training - were introduced to Heroku in class, we were blown away. &lt;/p&gt;

&lt;p&gt;'That's it?' we asked, bewildered.&lt;br&gt;
'That's it!' laughed our instructor. It was the simplest class ever. Click here, tap here, grant permission there and you have a continuously deployed server. Whew. We took the day off and had fun for the first time in a long time. &lt;/p&gt;

&lt;p&gt;Those beautiful days are long gone now, and in the real world, you'll discover that when Heroku fails, it does so in passively tyrannical ways. It is terser than your room mate. Today, I'm going to run through a list of Heroku errors I've encountered so far and how I solved them. Hopefully this article will save you a trek through several Stack Overflow pages. &lt;/p&gt;

&lt;h2&gt;
  
  
  First, let's keep the main thing the main thing
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Don't forget to process.env.PORT all the things
&lt;/h3&gt;

&lt;p&gt;As you probably know, your local environment uses a hard-coded port number to run your local servers. Things like 'localhost:5000' for example are great on your local machine, but if you leave that hard-coded port in your server, it will become a code H10 HEROKU problem.&lt;/p&gt;

&lt;p&gt;As a rule, if you must use port 5000 locally, always use a logical OR to add the heroku environment. &lt;/p&gt;

&lt;p&gt;`const PORT = process.env.PORT || 5000;&lt;/p&gt;

&lt;p&gt;That should do it. &lt;/p&gt;

&lt;p&gt;Why is this necessary? Heroku sets its own port at production time, and if you override it with your local configurations, it will throw up it hands in annoyance and quit on you. &lt;/p&gt;

&lt;h2&gt;
  
  
  The notorious Heroku logs
&lt;/h2&gt;

&lt;p&gt;Sometimes you'll encounter a problem where you'll get a code H10 error that says 'MODULE_NOT_FOUND' without seeing what the module is. I'm not sure why, but it often feels like the heroku logs are incomplete. &lt;/p&gt;

&lt;p&gt;This can be a pain in the ass to debug. What module is not found? Where?! These are the questions!&lt;/p&gt;

&lt;p&gt;To fix this one, a great thing to do is to open the heroku cli on your favorite terminal. &lt;/p&gt;

&lt;p&gt;Type in &lt;code&gt;heroku run bash&lt;/code&gt; then &lt;code&gt;npm start&lt;/code&gt; (if you're using Node js - basically start your server). It will throw the same error as before, but this time more explicitly. Note the errors, exit bash by typing &lt;code&gt;exit&lt;/code&gt;, implement your fixes, do a &lt;code&gt;git push heroku master&lt;/code&gt; and do a &lt;code&gt;heroku restart&lt;/code&gt; and &lt;code&gt;heroku open&lt;/code&gt; and things should be much better. &lt;/p&gt;

&lt;h2&gt;
  
  
  Procfile
&lt;/h2&gt;

&lt;p&gt;You typically don't need to manually add a Procfile, since Heroku can read your package.json file to tell where the server file is located. However, sometimes the odds aren't in your favor (usually your fault), and now you explicitly need to tell Heroku where to look for your server.js or index.js or app.js file. &lt;/p&gt;

&lt;p&gt;Whatever the case, this is where you create a Procfile (no extensions - it's like gitignore like that). &lt;/p&gt;

&lt;p&gt;In the Procfile, you'll tell heroku how to find your file, eg:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;web: src/index.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;HINT: You need a Procfile if Heroku says something like 'cannot find /path/to/file.js' &lt;/p&gt;

&lt;p&gt;That's all for now. I hope this helps at least one person!&lt;/p&gt;

</description>
      <category>heroku</category>
      <category>servers</category>
      <category>api</category>
      <category>node</category>
    </item>
    <item>
      <title>Quick Introduction to React Custom Hooks With Dropdown Selection</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Sun, 16 Feb 2020 14:19:02 +0000</pubDate>
      <link>https://dev.to/vunderkind/quick-introduction-to-react-custom-hooks-with-dropdown-selection-edh</link>
      <guid>https://dev.to/vunderkind/quick-introduction-to-react-custom-hooks-with-dropdown-selection-edh</guid>
      <description>&lt;h2&gt;
  
  
  Who’s this article for?
&lt;/h2&gt;

&lt;p&gt;For people new to React, and for people who have some experience with React who - like me - become confused when they have to build their own (or read others’) custom hooks. I’ll explain this as simply as I wish it was explained to me. &lt;/p&gt;

&lt;h2&gt;
  
  
  Skip this if you already understand the basic philosophy of React Hooks. Everyone else, start here:
&lt;/h2&gt;

&lt;p&gt;As if oft drummed into our heads, React is an unopinionated Library that we use to choreograph the front-end. A very important rookie question you have to ask early enough is "why do I need this complicated thing called React when I can just build my front-end using HTML and CSS?” &lt;/p&gt;

&lt;p&gt;I think this question is important to ask because it allows you understand the value of React, which lies in something called &lt;code&gt;state&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The simplest definition of state is that it represents the ‘status’ of data passing through a component. React updates the DOM when state changes, and this is something HTML and CSS alone are not equipped for. &lt;/p&gt;

&lt;p&gt;Imagine you had a chat app, and you wanted to indicate, with a small ‘status’ icon (usually a tiny cicle) when they are online (green!) or offline (gray!). How would you do that? &lt;/p&gt;

&lt;p&gt;In React, you can do this using something called Hooks. Hooks use ‘events’ to update state. If you spoke to the React hook known as useState, this is how the conversation would go: &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useState: 'Hello, I'm a React Hook called useState! My job is to keep track of state changes in your React app and update everything according to your programming!"

You: "Oh, hey, useState! So I built a component that keeps track of a user's online activity and changes the color of this tiny circle."

useState: "I see. First, you have to set a default state. This is the state I'll display the circle as when nothing's happening."

You: "How about gray? For offline?"

useState: "Excellent. Works for me! Now you have to set a state setter!"

You: "state setter? What?"

useState: "Oh, it's how you teach me what to look out for to change the default state."

You: "Ah, so I tell the state-setter to watch for the user's 'last seen' status, and when it changes to 'last seen: now', to change the circle to green?"

useState: "Now you're getting it!"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That’s a crash course into hooks. &lt;/p&gt;

&lt;h1&gt;
  
  
  And now: Custom Hooks
&lt;/h1&gt;

&lt;p&gt;The true beauty of a custom hook is that you can use it to create components that follow state-setting rules all across your application, which makes it easy to make app-wide updates without breaking anything. &lt;/p&gt;

&lt;p&gt;Note: The following is adapted from a Frontend Masters class I took.&lt;/p&gt;

&lt;p&gt;Imagine we wanted to create a custom hook that gives you a dropdown everytime you invoke it. Why would this be beneficial? &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It means that with one custom hook, you can create all kinds of dropdowns. &lt;/li&gt;
&lt;li&gt;You can have dropdowns with state tracking baked into them.&lt;/li&gt;
&lt;li&gt;You can reuse your dropdowns all over your application. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In code terms, instead of writing this every time you want to make a dropdown, &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';

const dropdownlist = ["item1", "item2", "item3"]

const FirstDropDown = () =&amp;gt; {
  const [firstdropdown, setFirstdropdown] = useState("I am the first!");
return(
  &amp;lt;label htmlFor="First Dropdown"&amp;gt;
    First Dropdown
      &amp;lt;select
        id="first"
        value={firstdropdown}
        onChange={e=&amp;gt; setFirstdropdown(e.target.value)}
        onBlur={e=&amp;gt; setFirstdropdown(e.target.value)}
        disabled={!dropdownlist.length}&amp;gt;
          &amp;lt;option&amp;gt;All&amp;lt;/option&amp;gt;
          {list.map=&amp;gt;(item=&amp;gt; &amp;lt;option key={item} value={item}&amp;gt;
          {item}
          &amp;lt;/item&amp;gt;)}
      &amp;lt;/select&amp;gt;
  &amp;lt;/label&amp;gt;
);
};

export default FirstDropDown
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;you write a hook that allows you to create a state-managed custom component instead: &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Dropdownlist = () =&amp;gt; {
  return (
  &amp;lt;label&amp;gt;
  &amp;lt;FirstDropdown /&amp;gt;
  &amp;lt;SecondDropdown /&amp;gt;
  &amp;lt;ThirdDropdown /&amp;gt;
&amp;lt;/label&amp;gt;
)
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Let’s begin! &lt;/p&gt;

&lt;h1&gt;
  
  
  Constructing the Hook
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First, create a new jsx document for the custom hook. Keep it in the &lt;code&gt;src&lt;/code&gt;  folder (if you’re following the conventional setup for React projects):&lt;br&gt;
&lt;code&gt;file &amp;gt; new &amp;gt; useDropdown.jsx&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Inside your new file, import React and useState:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import React, { useState } from 'react';&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: something that used to trip me up about React hooks is that you can only use hooks inside a function. I imagine this is because it keeps the hook in local scope and prevents unwanted side effects in global.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create the dropdown component  that you’re going to manage with hooks:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const DropDown = (label, defaultstate, options) =&amp;gt; {&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The three arguments above do specific things within the dropdown component, and I’ll mention them now, but they‘ll make sense as we provide.&lt;/p&gt;

&lt;p&gt;“Label”: Think of this as the name of the Dropdown itself. So a “Shoes” Dropdown shows a list of shoes to select, and "Shoes” is the label. In HTML, it would be represented like this: &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;label htmlFor="Shoes"&amp;gt;
    Shoes
&amp;lt;/label&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;“defaultState” represents, well, the default state of the hook. &lt;br&gt;
“Options” in the case of a dropdown is usually an iterable (ideally, a list) that is used to build the options the user can select from. &lt;/p&gt;

&lt;p&gt;Makes sense? Let’s move on!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Define the useState hook (the state setter!)&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const DropDown = (label, defaultstate, options) =&amp;gt; {
const [state, setState) = useState(defaultState);
}
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, we create the Dropdown component itself&lt;br&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const useDropdown = (label, defaultstate, options) =&amp;gt; {
    const [state, setState) = useState(defaultState);
    const Dropdownmaker = () =&amp;gt; (
      &amp;lt;label htmlFor={label}&amp;gt;
        {label}
          &amp;lt;select&amp;gt;
            &amp;lt;option&amp;gt;All&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;
    &amp;lt;/label&amp;gt;
    )
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Basically like you would a regular component. &lt;/p&gt;

&lt;p&gt;Now it’s time to plug our state tracker. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Plug the state tracker to auto-populate the Dropdownmaker:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const useDropdown = (label, defaultstate, options) =&amp;gt; {
    const [state, setState) = useState(defaultState);
    const Dropdownmaker = () =&amp;gt; (
      &amp;lt;label htmlFor={label}&amp;gt;
        {label}
          &amp;lt;select
          id={label}
          value={state}
          onChange={e=&amp;gt;setState(e.target.value)}
          onBlur={e=&amp;gt;setState(e.target.value)}
          disabled={!options.length}
            &amp;gt;
            &amp;lt;option&amp;gt;All&amp;lt;/option&amp;gt;
            {options.map(item=&amp;gt;
            &amp;lt;option key={item} value={item}&amp;gt;{item}&amp;lt;/option&amp;gt;)}
          &amp;lt;/select&amp;gt;
    &amp;lt;/label&amp;gt;
    )
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we return the necessary values for making the custom hook reusable as an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const useDropdown = (label, defaultstate, options) =&amp;gt; {
    const [state, setState) = useState(defaultState);
    const Dropdownmaker = () =&amp;gt; (
      &amp;lt;label htmlFor={label}&amp;gt;
        {label}
          &amp;lt;select
          id={label}
          value={state}
          onChange={e=&amp;gt;setState(e.target.value)}
          onBlur={e=&amp;gt;setState(e.target.value)}
          disabled={!options.length}
            &amp;gt;
            &amp;lt;option&amp;gt;All&amp;lt;/option&amp;gt;
            {options.map(item=&amp;gt;
            &amp;lt;option key={item} value={item}&amp;gt;{item}&amp;lt;/option&amp;gt;)}
          &amp;lt;/select&amp;gt;
    &amp;lt;/label&amp;gt;
    );
    return [state, Dropdownmaker, setState]
    }

    export default useDropdown
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With that, we can now import the custom hook into components that need it!&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import useDropdown from './useDropdown.jsx';

const shoe_list = ["Prada", "Jimmy Choos", "Nike", "Adidas"]
const Component = () =&amp;gt; {
  const [shoe, ShoeDropdown ] = useDropdown("Shoes", "", shoe_list);

  return (
    &amp;lt;ShoeDropdown /&amp;gt;    
)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Explanation&lt;br&gt;
This custom hook gives you a shoe with a label of “shoes”, a default state of empty array, and an options list of “shoe_list” (which I made into an array above - although ideally you’ll be pulling from an API). &lt;/p&gt;

&lt;p&gt;The ShoeDropdown gives you a dropdown list as we designed before, and allows you set the state, which changes the default state based on selection. &lt;/p&gt;

&lt;p&gt;And that’s it! A quick introduction to Custom Hooks using Dropdown Selections! &lt;/p&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>javascript</category>
    </item>
    <item>
      <title>The Dining Philosophers Problem (Or Your Introduction to Thinking in Computer Science)</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Wed, 12 Feb 2020 18:23:52 +0000</pubDate>
      <link>https://dev.to/vunderkind/the-dining-philosophers-problem-or-your-introduction-to-thinking-in-computer-science-8ii</link>
      <guid>https://dev.to/vunderkind/the-dining-philosophers-problem-or-your-introduction-to-thinking-in-computer-science-8ii</guid>
      <description>&lt;h3&gt;
  
  
  Who's this article recommended for
&lt;/h3&gt;

&lt;p&gt;Absolute rookies wondering what to expect from a study in computer science and how it can help elevate their general approach to coding. &lt;/p&gt;

&lt;h2&gt;
  
  
  Five Philosophers, Sitting in a Circle
&lt;/h2&gt;

&lt;p&gt;Imagine that you're in charge of the eating arrangements of five sober philosophers sitting in a circle. On each side of them is a chopstick, which adds up to five chopsticks in total. &lt;/p&gt;

&lt;p&gt;The philosophers, naturally, love to think. But they're also there to eat. The only way that they can eat is if they have two chopsticks. &lt;/p&gt;

&lt;p&gt;How do you design a system (or algorithm, if you will) that ensures the philosophers can eat and think and eat and think and eat and think? &lt;/p&gt;

&lt;h3&gt;
  
  
  System constraints
&lt;/h3&gt;

&lt;p&gt;There are three constraints to take into consideration here:&lt;br&gt;
a. Food is infinite, ie a philosopher can eat for as long as they want, and&lt;br&gt;
b. A philosopher can think for as long as they want.&lt;br&gt;
c. A philosopher can only eat when they have two chopsticks&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%2Fres.cloudinary.com%2Fstudio-mogwai%2Fimage%2Fupload%2Fv1581865192%2FUntitled_Artwork_5.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%2Fres.cloudinary.com%2Fstudio-mogwai%2Fimage%2Fupload%2Fv1581865192%2FUntitled_Artwork_5.png" alt="Dining philosophers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Thinking about the problem
&lt;/h3&gt;

&lt;p&gt;A very useful framework for solving programming challenges like this one is Lambda School's acronym-based formula, called the UPER framework. It's straightforward and intuitive. It reads as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;U for Understand&lt;/li&gt;
&lt;li&gt;P for Plan&lt;/li&gt;
&lt;li&gt;E for Execute&lt;/li&gt;
&lt;li&gt;R for Reflect
(Loop!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Understand
&lt;/h3&gt;

&lt;p&gt;In trying to understand the problem, I made a drawing of the five philosophers and placed the chopsticks on each side of them, until I had the chopsticks distributed among them. &lt;/p&gt;

&lt;p&gt;As soon as this was done, I spent some time thinking about the problem, which led me to realize that the chopsticks lend themselves to a concept known in computer science as semaphores. I'll supply a simple definition: &lt;/p&gt;

&lt;p&gt;A semaphore is something used to keep track of a resource upon which a process (or series of processes) is dependent. In the case of the Dining Philosophers problem, we can think of the resource (chopsticks) in terms of a counting semaphore. A counting semaphore simply counts up (or down) on the availability of the resource (the chopstick). &lt;/p&gt;

&lt;p&gt;Explained in a different way, if you wanted to use a bathroom in a building with only three bathrooms, you could meet the building manager who keeps an updated semaphore of how many bathrooms are occupied and how many are free. Armed with the semaphore, the building manager can then decide (using different techniques) who gets to use the rooms when they're free. After allocating a room, the building manager deducts one resource from the semaphore, and if a room becomes available again, he adds one more resource to the semaphore. &lt;/p&gt;

&lt;p&gt;Long talk, but understanding the Dining Philosophers problem suggests that this is a resource allocation problem, so we need a counting semaphore to keep track of the chopsticks. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;semaphore = 5&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Plan
&lt;/h3&gt;

&lt;p&gt;Now, we need to plan the best way to allocate the chopsticks so that each philosopher can eat and think without obstructing the activities of another one. &lt;/p&gt;

&lt;p&gt;First, we can see that the philosophers have two states: eating and thinking.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;philosopher.state[0] = {eating:true, thinking:false}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These states are mutually exclusive (a thinking philosopher is not eating, and an eating philosopher is not thinking). &lt;/p&gt;

&lt;p&gt;We can go further in our assumptions that when one philosopher picks up a chopstick, it means they're ready to eat, and are simply waiting for the philosopher on either side of them to drop the chopstick they're holding. &lt;/p&gt;

&lt;p&gt;In other words, there's a mid-state we have to account for. Let's call it &lt;code&gt;ready_to_eat&lt;/code&gt; which we can observe by seeing a philosopher pick up one chopstick. &lt;/p&gt;

&lt;p&gt;If we've planned properly, we should have a system that works like this: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;philosopher[i] has 0 chopsticks&lt;/code&gt;&lt;br&gt;
&lt;code&gt;philosopher[i] is in thinking state&lt;/code&gt;&lt;br&gt;
semaphores = 5&lt;code&gt;&lt;br&gt;
&lt;/code&gt;philosopher[i] picks up 1 chopstick&lt;code&gt;&lt;br&gt;
&lt;/code&gt;ready_to_eat = true&lt;code&gt;&lt;br&gt;
&lt;/code&gt;semaphores=4&lt;code&gt;&lt;br&gt;
&lt;/code&gt;philosopher[i] picks up second chopstick&lt;code&gt;&lt;br&gt;
&lt;/code&gt;semaphores=3&lt;code&gt;&lt;br&gt;
&lt;/code&gt;philosopher[i] is in eating state&lt;code&gt;&lt;br&gt;
&lt;/code&gt;philosopher[i] puts down chopsticks&lt;code&gt;&lt;br&gt;
&lt;/code&gt;semaphores=5&lt;code&gt;&lt;br&gt;
&lt;/code&gt;philosopher[i] is in thinking state`&lt;/p&gt;

&lt;p&gt;We can then loop indefinitely with these states and conditions accounted for. &lt;/p&gt;

&lt;h3&gt;
  
  
  Execute
&lt;/h3&gt;

&lt;p&gt;This is the bit where we then create the program and run it with five processes (philosophers) in place. This program is nearly perfect, but as soon as we execute, we'll experience something called a deadlock (when processes are jammed and unable to terminate/complete execution because resources are locked in place). &lt;/p&gt;

&lt;p&gt;In other words, the semaphores go down to &lt;code&gt;zero&lt;/code&gt;, but all philosophers are locked in a &lt;code&gt;ready_to_eat&lt;/code&gt; limbo state forever. &lt;/p&gt;

&lt;p&gt;What happened? All philosophers picked a chopstick each! They're not thinking or eating - but they're ready to eat but have no spare chopsticks! &lt;/p&gt;

&lt;h3&gt;
  
  
  Reflect
&lt;/h3&gt;

&lt;p&gt;In the reflection phase, we sit in the dark and ponder on our code and figure out ways to fix execution problems. In this case, we're going to reflect on fixing the deadlock problem before returning to execution. &lt;/p&gt;

&lt;p&gt;Here are a few ways to resolve the deadlock problem:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Have four, not five philosophers: If we have one chopstick more than philosophers at the table, it becomes possible for a philosopher to be eating while other philosophers are in a &lt;code&gt;ready_to_eat&lt;/code&gt; state without a deadlock happening. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can also artificially constrain the system using a FIFO system + a skip: we start philosopher 1 at at &lt;code&gt;eating&lt;/code&gt; state, which also puts philosopher 3 at an &lt;code&gt;eating&lt;/code&gt; state. This means only philosopher 4 can be in a &lt;code&gt;ready_to_eat&lt;/code&gt; state. If philosopher 4 is truly ready to eat, they’ll pick the chopsticks after 3 is ready and done, otherwise the chopsticks will be free for use by 5 when 1 is done. Whenever the counting semaphore defaults to zero, restart the FIFO (First in, First Out) system + a skip. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make it so a philosopher can only pick up a chopstick when both right and left chopsticks are free.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Closing notes
&lt;/h4&gt;

&lt;p&gt;Can you think of additional ways to fix the deadlock of the philosophers? Share!&lt;/p&gt;

</description>
      <category>python</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>What was the thing that made you finally 'get' JavaScript?</title>
      <dc:creator>mogwai</dc:creator>
      <pubDate>Tue, 08 Oct 2019 00:35:09 +0000</pubDate>
      <link>https://dev.to/vunderkind/what-was-the-thing-that-made-you-finally-get-javascript-427j</link>
      <guid>https://dev.to/vunderkind/what-was-the-thing-that-made-you-finally-get-javascript-427j</guid>
      <description>&lt;p&gt;Over the course of my learnings in different other disciplines, I've found (after the fact) that understanding one fundamental thing is what it took for everything else in the entire discipline to start making sense to me. &lt;/p&gt;

&lt;p&gt;As an example: I struggled with transitioning from CorelDraw to Photoshop for a long time because I didn't intuitively get the 'layer' system of Photoshop (CorelDraw, at the time - dunno if that's still the case - just gave you one workspace and you moved things about relative to each other using 'Align' settings. &lt;/p&gt;

&lt;p&gt;I struggled with CSS until I understood the Box Model (margin vs padding vs border), and now I can theoretically understand the other things and where they fit. &lt;/p&gt;

&lt;p&gt;With JavaScript, I'm wondering what that 'smallest unit of understanding is'? It feels like it should be functions, but despite understanding functions, it took me a while to understand callbacks, and after understanding callbacks, it took me a while to understand eventHandlers, and so on. &lt;/p&gt;

&lt;p&gt;Curious about the experiences of more advanced JavaScript users: what was that crucial turning point for you?&lt;/p&gt;

&lt;p&gt;All responses welcome!&lt;/p&gt;

</description>
      <category>help</category>
    </item>
  </channel>
</rss>
