<?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: Jorge Colon</title>
    <description>The latest articles on DEV Community by Jorge Colon (@2upmedia).</description>
    <link>https://dev.to/2upmedia</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%2F155114%2F313274c5-1afe-4da0-bfe2-492b0d777859.jpg</url>
      <title>DEV Community: Jorge Colon</title>
      <link>https://dev.to/2upmedia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/2upmedia"/>
    <language>en</language>
    <item>
      <title>What should I name my states for my XState state machine?</title>
      <dc:creator>Jorge Colon</dc:creator>
      <pubDate>Sun, 23 Feb 2020 20:23:19 +0000</pubDate>
      <link>https://dev.to/2upmedia/what-should-i-name-my-states-for-my-xstate-state-machine-80m</link>
      <guid>https://dev.to/2upmedia/what-should-i-name-my-states-for-my-xstate-state-machine-80m</guid>
      <description>&lt;p&gt;I recently implemented &lt;a href="https://xstate.js.org/docs/about/concepts.html"&gt;XState&lt;/a&gt; for a project that went to production. Thinking in terms of state machines was completely different from my usual way of writing programs.&lt;/p&gt;

&lt;p&gt;Here are the lessons that I learned figuring out what states to choose and what to name them.&lt;/p&gt;

&lt;p&gt;In general you should think of your application as what different states it's in &lt;strong&gt;over time&lt;/strong&gt;. So lets look at the dictionary definition for the word state.&lt;/p&gt;

&lt;p&gt;"the particular condition that someone or something is in at a specific time" - Oxford American Dictionary&lt;/p&gt;

&lt;p&gt;So what are the different conditions that your application could be at a &lt;em&gt;specific time&lt;/em&gt;? Look for both states that show &lt;em&gt;what's happening&lt;/em&gt; at the moment and &lt;em&gt;what happened&lt;/em&gt; in the past.&lt;/p&gt;

&lt;p&gt;What you want to focus on, are the states that &lt;em&gt;change&lt;/em&gt; the behavior of your application. If that state doesn't the behavior of your application then you probably don't need to add it to your state machine.&lt;/p&gt;

&lt;p&gt;Some examples of states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;idle&lt;/li&gt;
&lt;li&gt;loading&lt;/li&gt;
&lt;li&gt;loaded&lt;/li&gt;
&lt;li&gt;inProgress&lt;/li&gt;
&lt;li&gt;selecting&lt;/li&gt;
&lt;li&gt;selected&lt;/li&gt;
&lt;li&gt;errored&lt;/li&gt;
&lt;li&gt;rejected&lt;/li&gt;
&lt;li&gt;draft&lt;/li&gt;
&lt;li&gt;published&lt;/li&gt;
&lt;li&gt;unpublished&lt;/li&gt;
&lt;li&gt;publishing&lt;/li&gt;
&lt;li&gt;loggingIn&lt;/li&gt;
&lt;li&gt;loggedIn&lt;/li&gt;
&lt;li&gt;loggingOut&lt;/li&gt;
&lt;li&gt;loggedOut&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once again, think about what condition your application is in over time. Put names to those.&lt;/p&gt;

&lt;p&gt;Thinking about your application in this way, what states would you have? Comment below.&lt;/p&gt;

</description>
      <category>xstate</category>
      <category>statemachines</category>
      <category>fsm</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Solving problems with virtualenvwrapper using mismatched python versions</title>
      <dc:creator>Jorge Colon</dc:creator>
      <pubDate>Mon, 06 May 2019 04:23:22 +0000</pubDate>
      <link>https://dev.to/2upmedia/solving-problems-with-virtualenvwrapper-mismatched-python-versions-57el</link>
      <guid>https://dev.to/2upmedia/solving-problems-with-virtualenvwrapper-mismatched-python-versions-57el</guid>
      <description>&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;understand the precedence of PATH&lt;/li&gt;
&lt;li&gt;understand where PATH is usually set&lt;/li&gt;
&lt;li&gt;make sure your python version is using the corresponding pip shell command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although this is geared specifically towards virtualenvwrapper this could help you to figure out why a shell command you’ve installed isn’t working for some reason.&lt;/p&gt;

&lt;p&gt;If you’ve ever used virtualenvwrapper you know how useful it is to mix and match python versions and have separate dependency silos for each project so that you don’t use the same pip for each project. On some rare occasions virtualenvwrapper might give you problems if you have multiple versions of python installed.&lt;/p&gt;

&lt;p&gt;In my case, mkvirtualenv would fail when specifying a different python interpreter than what was default. I wanted to use python 3.7 and it was picking pip packages from python 2.7. The command that I was using was something like &lt;code&gt;mkvirtualenv -p python3 my-env&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After analyzing my setup there was a couple of problems. I had several versions of python from different sources, some from macports, some from homebrew, and the built-in python that came pre-installed with Mac OS.&lt;/p&gt;

&lt;p&gt;In order to solve what was going on I had to understand the problem. The ultimate problem was that python 3.7 was trying to use pip for python 2.7. This was apparent from the python exceptions where it was obvious that the interpreter being used was python 3.7, but the stack trace was showing paths referencing python 2.7.&lt;/p&gt;

&lt;p&gt;What I had to was to make sure that the correct pip was installed for python 3.7. Homebrew, at least on my machine, took the last entry the macports bin path was taking precedence (showed up first in the PATH) over the homebrew bin path. That is important to understand because the way PATH works is very simple. Whatever path is defined first will be used first to find the shell command you want to run. So if you run &lt;code&gt;$ python&lt;/code&gt; and &lt;code&gt;/opt/local/bin&lt;/code&gt; is defined first in PATH, then it will resolve to &lt;code&gt;/opt/local/bin/python&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I thought that I could remove the macports python out of the picture to see if it was the one causing problems. To do that I used &lt;code&gt;port select python none&lt;/code&gt;. As far as I can tell, what that did was remove the symlink from the macports bin path. For some reason, that didn’t do anything which was strange. So I needed to investigate more.&lt;/p&gt;

&lt;p&gt;I remembered to keep an eye on what in PATH as that basically controls what shell command gets picked up first. When I did &lt;code&gt;echo $PATH&lt;/code&gt; I noticed there was still a reference to macports python. That definitely shouldn’t have happened. I had already ran &lt;code&gt;port select python none&lt;/code&gt;. The $PATH environment gets set in multiple places. In general here’s a couple of places to look with the highest precedence being listed first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/etc/profile&lt;/li&gt;
&lt;li&gt;/etc/bashrc&lt;/li&gt;
&lt;li&gt;~/.bash_profile&lt;/li&gt;
&lt;li&gt;~/.profile&lt;/li&gt;
&lt;li&gt;~/.bashrc&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The culprit was in ~/.profile. There was an entry that prepended $PATH with macports python version &lt;code&gt;export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH&lt;/code&gt;. After I commented that out my shell ended up picking up the homebrew version as I intended to. I validated this by running &lt;code&gt;which python&lt;/code&gt; and seeing that it was picking up from the homebrew bin path &lt;code&gt;/usr/local/bin&lt;/code&gt; and not from macports bin path &lt;code&gt;/opt/local/bin&lt;/code&gt;. There was a problem though, the homebrew python command was actually python 2.7 and not the 3.7 I wanted to use. &lt;/p&gt;

&lt;p&gt;I found out that homebrew installs python 3.7 as python3. I could have just made a symbolic link from python3 python, but then I would need to keep tabs that I actually did that. Macports has a &lt;code&gt;port select&lt;/code&gt; command where I could swap out different versions of the same program, but homebrew doesn’t have that. The closest thing is brew link and unlink, but it doesn’t work the same way as in macports. All it does it remove the program from the homebrew bin path. So that didn’t really help me.&lt;/p&gt;

&lt;p&gt;When I backtracked I remembered that for some reason python 3.7 was trying to use pip installed for python 2.7. When I ran &lt;code&gt;brew link -vd&lt;/code&gt; to show me verbose output there weren't any references to pip which I found very suspicious. After some Google searching, I found that someone recommended doing brew reinstall python. That ended up being the crucial command that installed pip for python 3.7. It ended up using installing pip, but brew names the binary pip3 instead of pip. In homebrew, pip is for python 2.7.&lt;/p&gt;

&lt;p&gt;The next part is very important, because it’s not just as straightforward as specifying the python interpreter version you’d like to use in &lt;code&gt;mkvirtualenv -p python3&lt;/code&gt;. Seems like virtualenvwrapper by default uses the python version and pip version of whatever’s currently installed. As I’ve mentioned before it’s python 2.7 from homebrew that’s installed. So to get around that virtualenvwrapper has an environment variable that you could set to the python interpreter that you’d like to use for virtualenvwrapper itself. It’s called VIRTUALENVWRAPPER_PYTHON. You set it to the absolute path of the python interpreter you’d like to use. In my case I did &lt;br&gt;
&lt;code&gt;export VIRTUALENVWRAPPER_PYTHON=`which python3`&lt;/code&gt;. Now when I run &lt;code&gt;mkvirtualenv -p python3&lt;/code&gt;, it doesn’t throw any python exceptions trying to use pip for python 2.7.&lt;/p&gt;

</description>
      <category>python</category>
      <category>virtualenv</category>
      <category>virtualenvwrapper</category>
      <category>path</category>
    </item>
  </channel>
</rss>
