<?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: Adérito Xavier</title>
    <description>The latest articles on DEV Community by Adérito Xavier (@pars3c).</description>
    <link>https://dev.to/pars3c</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%2F405997%2F0ed2c0fa-982a-485e-9e0d-7b246300c58c.jpeg</url>
      <title>DEV Community: Adérito Xavier</title>
      <link>https://dev.to/pars3c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pars3c"/>
    <language>en</language>
    <item>
      <title>Elementary Guide to Hashicorp’s Nomad with Linux.</title>
      <dc:creator>Adérito Xavier</dc:creator>
      <pubDate>Sat, 13 Jun 2020 10:16:23 +0000</pubDate>
      <link>https://dev.to/pars3c/elementary-guide-to-hashicorp-s-nomad-with-linux-2nk8</link>
      <guid>https://dev.to/pars3c/elementary-guide-to-hashicorp-s-nomad-with-linux-2nk8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this hands-on guide, I will show you how ridiculously easy it can be to set up a react front-end container and an express back-end container in &lt;strong&gt;Nomad&lt;/strong&gt; and get them to speak with each other as two microservices.&lt;/p&gt;

&lt;p&gt;Our orchestration will be composed of 1 group where the 2 containers (front-end and back-end microservices) will live. For simplicity, we will run a single Nomad agent in development mode (development mode is explained below do not panic!!!) and statically map all required ports.&lt;/p&gt;

&lt;h2&gt;
  
  
  DO NOT DESPAIR
&lt;/h2&gt;

&lt;p&gt;A second guide will be coming soon where I go more in-depth and explain how you can scale your application and let Nomad take care of the port forwarding by itself. Right now I just want you to get an easy grip on &lt;strong&gt;Nomad&lt;/strong&gt; and discover by yourself that it is not as complicated as you think.&lt;/p&gt;

&lt;h2&gt;
  
  
  The WHY
&lt;/h2&gt;

&lt;p&gt;we went through some changes in how we orchestrate and schedule workloads. Previously, we were using Jenkins and the team was unhappy with its high maintenance, flaky plugins, and inefficient machine usage. So… One day we had a meeting where new technologies are discussed like Docker Swarm and Kubernetes that was when our Senior Tech Lead dropped a bomb on me and brought this idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Guys, why not Nomad? It takes the Unix approach of doing one thing and doing it really well, and won’t force a huge change on our infrastructure like Kubernetes would. It’s also made by HashiCorp (who we love).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I was completely terrified when I heard this I said to myself:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;WTF is Nomad?! If I stay quiet they will not notice that I have absolutely no idea of what they are talking about.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That same afternoon I googled for &lt;strong&gt;Nomad&lt;/strong&gt; documentation and I got even more terrified. They do have a lot of documentation but very few examples, as a very visual guy I struggled in those cases.&lt;/p&gt;

&lt;p&gt;So… I started to break it up into small pieces by finishing Hashicorp’s &lt;strong&gt;Nomad&lt;/strong&gt; &lt;a href="https://learn.hashicorp.com/nomad"&gt;tutorial&lt;/a&gt; amongst other videos which I will share at the end of this guide. While trying to implement basic orchestrations by myself I slowly started to progress and become confident enough to try more and more ambitious orchestrations, until I got where I am now.&lt;/p&gt;

&lt;p&gt;So I decided to help all of you guys who are struggling like I did and give you actual visual examples with multiple basic microservices talking to each other. I hope you enjoy 😃. If I can help one of you it will already be worth it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Any Linux distro (Ubuntu is preferable) as your OS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NodeJS and npm installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GIT installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Docker installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NodeJS, Docker, GIT basic knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kP1mUBXR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7852/0%2A5BH1Rr2Om6Cl-sKG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kP1mUBXR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7852/0%2A5BH1Rr2Om6Cl-sKG" alt="Photo by [Boba Jaglicic](https://unsplash.com/@bobajaglicic?utm_source=medium&amp;amp;utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What the hell is Nomad anyway?
&lt;/h2&gt;

&lt;p&gt;According to its &lt;a href="https://nomadproject.io/"&gt;website&lt;/a&gt; &lt;strong&gt;Nomad&lt;/strong&gt; is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A simple and flexible workload orchestrator to deploy and manage containers and non-containerized applications across on-prem and clouds at scale.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nomad is a scheduler similar to something like ECS, Kubernetes, Swarm, etc. Your scheduler is going to take information like “I want N copies of image X running” and take care of running and maintaining the availability of these containers on a cluster of different hosts.&lt;/p&gt;

&lt;p&gt;If a container crashes, Nomad will detect this and reschedule it. Or say one of your Azure instances crashes and it had 3 different microservices instances running on it. Nomad will reschedule these 3 microservice instances on different machines in your cluster (if capacity is available).&lt;/p&gt;

&lt;p&gt;Say you have version A of your app running and you want to deploy version B. If you want to maintain up time you will need either some form of Blue/Green or rolling deployment. Your scheduler defines and executes these types of tasks.&lt;/p&gt;

&lt;p&gt;Think of it as a lightweight version of Kubernetes and also much easier to learn.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nomad architecture
&lt;/h2&gt;

&lt;p&gt;I will try to simplify as much as I can but I strongly advise you to still read this nonetheless &lt;a href="https://nomadproject.io/docs/internals/architecture/"&gt;https://nomadproject.io/docs/internals/architecture/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Nomad is composed of two agents: &lt;strong&gt;Server&lt;/strong&gt; and &lt;strong&gt;Client.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Server&lt;/strong&gt; — A Server manages all jobs and clients, runs evaluations and creates task allocations. There is a cluster of servers per region and they manage all jobs and clients, run evaluations, and create task allocations. The servers replicate data between each other and perform leader election to ensure high availability. Servers federate across regions to make Nomad globally aware.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client&lt;/strong&gt; — A Client of Nomad is a machine that tasks can be run on. All clients run the Nomad agent. The agent is responsible for registering with the servers, watching for any work to be assigned and executing tasks. The Nomad agent is a long-lived process which interfaces with the servers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;IMPORTANT NOTE&lt;/strong&gt;: We will be running Nomad in development mode as you will see below, this means that our agent will run as both server and client, data will not be persisted which implicates that every time you close Nomad all the data will be gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single Region Architecture:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Df7w65i---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2AmuwgfRjcuDnix2QE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Df7w65i---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2AmuwgfRjcuDnix2QE.png" alt="Nomad single region"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within each region, we have both clients and servers. Servers are responsible for accepting jobs from users, managing clients, and &lt;a href="https://nomadproject.io/docs/internals/scheduling/scheduling"&gt;computing task placements&lt;/a&gt;. Each region may have clients from multiple datacenters, allowing a small number of servers to handle very large clusters.&lt;/p&gt;

&lt;p&gt;In some cases, for either availability or scalability, you may need to run multiple regions. Nomad supports federating multiple regions together into a single cluster. At a high level, this setup looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qbQgG8gz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AkoN8pBJWncaZU-RX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qbQgG8gz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AkoN8pBJWncaZU-RX.png" alt="Hashicorp’s Nomad Multiple Region Server Setup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Nomad installation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to this &lt;a href="https://www.nomadproject.io/downloads.html"&gt;page&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check which version of Nomad is suitable for your machine CPU and hit download.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open your terminal inside the same directory where Nomad was downloaded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Proceed to unzip the file with the unzip command.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;unzip &amp;lt;file&amp;gt;  
# Example: unzip nomad_0.10.2_linux_amd64.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now we just have to move the binary file to our bin.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv nomad /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check if Nomad is installed by opening another terminal tab or window and running.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;which nomad
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Should return something like this:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rihnB-nl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2ADNiB5kDkC1vBqM12" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rihnB-nl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2ADNiB5kDkC1vBqM12" alt=""&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  👏Congratulations you’ve just installed Nomad!
&lt;/h2&gt;

&lt;p&gt;Now we will containerize our front-end and back-end.&lt;/p&gt;

&lt;p&gt;For the sake of simplicity, I chose to fork a super simple project made by &lt;a href="https://medium.com/@jrshenrique"&gt;João Henrique&lt;/a&gt;. To check the forked version click &lt;a href="https://github.com/pars3c/nomad_guide"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is also documented, if you have time please check out the article he made explaining the project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/create-a-react-frontend-a-node-express-backend-and-connect-them-together-c5798926047c/"&gt;&lt;strong&gt;How to create a React frontend and a Node/Express backend and connect them&lt;/strong&gt;&lt;br&gt;
*by João Henrique How to create a React frontend and a Node/Express backend and connect them “two square blue LED…*www.freecodecamp.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The repository contains:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A front-end built with ReactJS that runs on &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A back-end build with ExpressJS that run on &lt;a href="http://localhost:9000/testAPI"&gt;http://localhost:9000/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every time the front-end DOM loads it is going to send a GET request to &lt;a href="http://localhost:9000/testAPI"&gt;http://localhost:9000/testAPI&lt;/a&gt; (our back-end), that GET request will send us a string back with the sentence ‘API is working properly’, which will be displayed on our front-end as well.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JJBXi8lF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/1%2APZPdbxaTJat7vIGlAoqyoA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JJBXi8lF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/1%2APZPdbxaTJat7vIGlAoqyoA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created two docker images to run each of the microservices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Front-end image &lt;a href="https://hub.docker.com/r/aderito/react-app"&gt;link&lt;/a&gt;, the Dockerfile for this image is composed of:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:10

# Create app directory

WORKDIR /usr/src/app

# Install app dependencies

# A wildcard is used to ensure both package.json AND package-lock.json are copied

# where available (npm@5+)

COPY package*.json ./

RUN npm install

# Bundle app source

COPY . .

EXPOSE 3000

CMD [ "npm", "start" ]
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Back-end image &lt;a href="https://hub.docker.com/r/aderito/express-app"&gt;link&lt;/a&gt;, the Dockerfile for this image is (it is a very similar configuration, only the port &lt;strong&gt;EXPOSE&lt;/strong&gt; was changed to &lt;strong&gt;9000&lt;/strong&gt;)composed of:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:10

# Create app directory

WORKDIR /usr/src/app

# Install app dependencies

# A wildcard is used to ensure both package.json AND package-lock.json are copied

# where available (npm@5+)

COPY package*.json ./

RUN npm install

# Bundle app source

COPY . .

EXPOSE 9000

CMD [ "npm", "start" ]
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more info on how to run a node application in Docker check this &lt;a href="https://nodejs.org/de/docs/guides/nodejs-docker-webapp/"&gt;guide&lt;/a&gt;, it helped me a lot.&lt;/p&gt;

&lt;h3&gt;
  
  
  SETUP TIME. YAY!!
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Open your terminal and type:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nomad agent -dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are going to run in development mode as I warned you before.&lt;/p&gt;

&lt;p&gt;You should see something like this in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wF-RWmTl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3812/1%2AJr3KoMrjsMymlUcQMHtmXQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wF-RWmTl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3812/1%2AJr3KoMrjsMymlUcQMHtmXQ.png" alt="Nomad Dev Agent being Spawned"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a browser and use the following address &lt;a href="http://127.0.0.1:4646/"&gt;http://127.0.0.1:4646/&lt;/a&gt; which will give you a full-on UI where you can see your &lt;strong&gt;Jobs.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zqpa58wD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3830/1%2A_9YNdQ8_-dSjs5qzExiuCg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zqpa58wD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3830/1%2A_9YNdQ8_-dSjs5qzExiuCg.png" alt="Nomad Orchestrator/Scheduler UI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As obvious as it is in the image above, we added no Jobs yet. To add a Job press on Run Job .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_bQXbb6m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3830/1%2AmPAsXEc9PwQk6lEzgKJihw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_bQXbb6m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3830/1%2AmPAsXEc9PwQk6lEzgKJihw.png" alt="Nomad’s Job Specifications text area"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Job Definition text area is where we will set all our Job Specifications.&lt;/p&gt;

&lt;p&gt;Keep in mind that Job Specifications can also be added through the terminal, but as I iterated before, we are &lt;strong&gt;&lt;em&gt;keeping it simple, stupid.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Job Specifications follow the HCL (HashiCorp Configuration Language) format, it is a configuration language built by HashiCorp. Think of it as a JSON format with a few added abstractions.&lt;/p&gt;

&lt;h3&gt;
  
  
  OUR JOB SPECIFICATIONS FILE
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; # Name of your job
job "my_job" {
    # Which region are you running your job
    datacenters = ["dc1"]

    /*
    Job type can be "service", "batch" or "system".
    A "service" job is made for long lived services that should never go down,
    Service jobs are made to run until explicitly stopped by the operator.
    A "batch" job is made for short lived operations which can last
    from a couple of minutes to a few days.
    Batch schedulers are very similar to Service schedulers but with a few optimizations,
    for the batch workload.
    Batch jobs are intended to run until the job is successful, if the Batch task
    exits with an error it will be handled according to the job's restart 
    and reschedule stanzas.
    A "system" job is made for registering jobs that should be run on every client,
    that has job's constraints.
    The system job is also used when clients join the cluster or transition into the,
    ready state.

    */

    type = "service"
    # Group represents the same of what a pod is in k8s
    group "web" {
        count = 1
        task "frontend" {
            # The driver used to manage the containers
            driver = "docker"
            config {
                # Image we want to pull
                image = "aderito/react-app" 
                # Define the mapped port
                port_map = {
                  frontendPort = 3000
                }
            }
            # Set the computing resources for this task
            resources {
                cpu = 500 # MHz
                memory = 128 # MB
                network {
                    mbits = 10
                    port "frontendPort" {
                        # Set the port that will bridge our orchestration with the container port
                        static = "3000"
                    }
                }
            }

        }
        task "backend" {
            # The driver used to manage the containers
            driver = "docker"

            config {
                # Image we want to pull
                image = "aderito/express-app"
                # Define the mapped port
                port_map = {
                  backendPort = 9000
                }
            }
            # Set the computing resources for this task
            resources {
                cpu = 500 # MHz
                memory = 128 # MB
                network {
                    mbits = 10
                    port "backendPort" {
                      # Set the port that will bridge our orchestration with the container port
                      static = "9000"
                    }
                }
            }

        }

    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Link for the gist &lt;a href="https://gist.github.com/pars3c/f8dd266ca5b57aee2ef8abf9237869c6"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let us go through each field:
&lt;/h3&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;job "my_job" { 
...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Job&lt;/strong&gt; — It will define the name of your job and inside of it, you will set all the configurations necessary to accomplish your job to run.&lt;/p&gt;

&lt;p&gt;datacenters = ["dc1"]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Datacenters&lt;/strong&gt; — Nomad models infrastructure as regions and datacenters. Regions may contain multiple datacenters. Servers are assigned to a specific region, managing state and making scheduling decisions within that region. In our case, we do not have a real region so we just set it as dc1.&lt;/p&gt;

&lt;p&gt;type = "service"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type&lt;/strong&gt; — Is the scheduler type that can be used in our job, there are 3 types: service, batch and system.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;service job is made for long-lived services that should never go down, Service jobs are made to run until explicitly stopped by the operator. Example: Running a website.&lt;/p&gt;

&lt;p&gt;batchjob is made for short-lived operations which can last from a couple of minutes to a few days. Batch schedulers are very similar to Service schedulers but with a few optimizations, for the batch workload. Batch jobs are intended to run until the job is successful, if the Batch task exits with an error it will be handled according to the job’s restart and reschedule stanzas. Example: A web crawler (you probably just want it to run until you got the data you wanted).&lt;/p&gt;

&lt;p&gt;system job is made for registering jobs that should be run on every client, that has job constraints. The system job is also used when clients join the cluster or transition into the ready state.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;group "web" {
...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Group&lt;/strong&gt; — Defines a series of tasks that should be co-located on the same Nomad Client. Any &lt;a href="https://nomadproject.io/docs/job-specification/task"&gt;task&lt;/a&gt; within a group will be placed on the same client.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you worked with &lt;strong&gt;Kubernetes&lt;/strong&gt; before, you can think of a &lt;strong&gt;Group&lt;/strong&gt; the same way as you do with &lt;strong&gt;Pod.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Count&lt;/strong&gt; — Specifies the number of task groups that should be running under this group. This value must be non-negative. In a nutshell, if you were to add count = 2 it would spawn two times each task, so 2 frontend tasks and 2 backend tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Warning&lt;/strong&gt;: Do not try to amplify the count in this project for more than 1, because the ports are statically set(as told in the &lt;strong&gt;Introduction&lt;/strong&gt;), which will create an overlap and trigger an error for port already in use.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;task "frontend" {
...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Task&lt;/strong&gt; — Creates an individual unit of work, such as a Docker container, web application, or batch processing.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver = "docker"
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Driver&lt;/strong&gt; — Defines the driver used to manage the containers.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config {
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Config&lt;/strong&gt; — Specifies the driver configuration, which is passed directly to the driver to start the task.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image = "aderito/react-app"
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Image&lt;/strong&gt; — Image used for our container.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;port_map {
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Mapped Ports&lt;/strong&gt; — Some drivers (such as &lt;a href="https://nomadproject.io/docs/drivers/docker"&gt;Docker&lt;/a&gt; and &lt;a href="https://nomadproject.io/docs/drivers/qemu"&gt;QEMU&lt;/a&gt;) allow you to map ports. A mapped port means that your application can listen on a fixed port (it does not need to read the environment variable) and the dynamic port will be mapped to the port in your container or virtual machine.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;frontendPort = 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;frontendPort&lt;/strong&gt; — Is the label we are using to map our container port with our orchestration port.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources {
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt; — Describes the requirements an task needs to execute. Resource requirements include memory, network, CPU, and more.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cpu = 500
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CPU&lt;/strong&gt; — Defines the processor required specifications in MHz to run this task.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;memory = 128
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Memory&lt;/strong&gt; — Defines the amount of cache memory required in MBs to run this task.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;network {
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Network&lt;/strong&gt; — Specifies the networking requirements for the task, including the minimum bandwidth and port allocations. When scheduling jobs in Nomad they are provisioned across your fleet of machines along with other jobs and services. Because you don’t know in advance what host your job will be provisioned on, Nomad will provide your tasks with network configuration when they startup.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mbits = 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Mbits&lt;/strong&gt; — Defines the task’s bandwidth for 10mb/s.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;port "frontendPort" {
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Port&lt;/strong&gt; “frontendPort” — Specifies which port to map according to the label.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static = "3000"
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static&lt;/strong&gt; — Describes the port in our orchestration that will speak with the frontend container which is also 3000.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  WARNING: I am not going to specify the task for our backend given the outstanding similarities with our frontend task.
&lt;/h3&gt;

&lt;h2&gt;
  
  
  MAGIC TIME!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Copy what is inside the gist.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste it inside the &lt;a href="http://127.0.0.1:4646/ui/jobs/run"&gt;http://127.0.0.1:4646/ui/jobs/run&lt;/a&gt; text area.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should see a screen like this:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EjEJXmUM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3832/1%2ASMy8I-AAPMrbGTT_BxA3kQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EjEJXmUM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3832/1%2ASMy8I-AAPMrbGTT_BxA3kQ.png" alt="Hashicorp’s Nomad Job start"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Press &lt;strong&gt;Run.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait a couple of minutes until the images are completely pulled and the containers are running.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="http://127.0.0.1:3000/"&gt;http://127.0.0.1:3000/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Voila!!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LTH-gfyY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3836/1%2A8ZGEkiZUcTiRZT15oIna9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LTH-gfyY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3836/1%2A8ZGEkiZUcTiRZT15oIna9g.png" alt="ReactJS API working"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will not go much further, for now, I want you to explore Nomad’s UI and get acquainted with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources that helped me in my struggle:
&lt;/h2&gt;

&lt;p&gt;Introduction to HashiCorp Nomad &lt;a href="https://www.youtube.com/watch?v=s_Fm9UtL4YU"&gt;https://www.youtube.com/watch?v=s_Fm9UtL4YU&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From Zero to WOW! with Nomad &lt;a href="https://www.youtube.com/watch?v=xl58mjMJjrg"&gt;https://www.youtube.com/watch?v=xl58mjMJjrg&lt;/a&gt; — This one helped me the most&lt;/p&gt;

&lt;p&gt;Easy and Flexible Application Deployment with HashiCorp Nomad &lt;a href="https://www.youtube.com/watch?v=A6CuZUoINX0"&gt;https://www.youtube.com/watch?v=A6CuZUoINX0&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>hashicorp</category>
      <category>nomad</category>
      <category>docker</category>
    </item>
    <item>
      <title>Mathematical Notation for Python Developers | Propositional Logic</title>
      <dc:creator>Adérito Xavier</dc:creator>
      <pubDate>Thu, 11 Jun 2020 12:10:48 +0000</pubDate>
      <link>https://dev.to/pars3c/mathematical-notation-for-python-developers-propositional-logic-2dkn</link>
      <guid>https://dev.to/pars3c/mathematical-notation-for-python-developers-propositional-logic-2dkn</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As developers, we require to be always up to date with the new tech stack however we tend to forget the importance of the underlying structure in which new tech stacks are built-in.&lt;/p&gt;

&lt;p&gt;I am not saying we are required to be ninjas at assembly or binary but a good understanding of how they work is necessary in order to progress as a developer.&lt;/p&gt;

&lt;p&gt;Learning &lt;em&gt;Propositional Logic&lt;/em&gt; can help you understand how circuits work programming conditions, writing your code with mathematical notation amongst other things.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Who Is This Article For
&lt;/h2&gt;

&lt;p&gt;By now, you might be wondering: “Do I need to know Python or Binary to understand this article?”. You do not!&lt;/p&gt;

&lt;p&gt;I made this article for anyone who is interested in learning mathematical notation.&lt;/p&gt;

&lt;h2&gt;
  
  
  AND | Conjunction
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;AND&lt;/em&gt; expressions are denoted with the symbol &lt;code&gt;∧&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;a ∧ b = a and b&lt;/p&gt;

&lt;p&gt;Both a and b must be true in order for an &lt;em&gt;AND&lt;/em&gt; statement to be true or else it will always be false.&lt;/p&gt;

&lt;p&gt;|1 ∧ 0 = 0|0 ∧ 1 = 0|1 ∧ 1 = 1 |0 ∧ 0 = 0|&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
x = (1 and 0)
print(x)
# &amp;gt;&amp;gt; 0
x = (1 and 1)
print(x)
# &amp;gt;&amp;gt; 1
x = (False and True)
print(x)
# &amp;gt;&amp;gt; False
x = (True and True)
print(x)
# &amp;gt;&amp;gt; True

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



&lt;h2&gt;
  
  
  OR | Disjunction
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;OR&lt;/em&gt; expressions are denoted with the symbol &lt;code&gt;∨&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;a ∨ b = a or b&lt;/p&gt;

&lt;p&gt;Either a or b must be true in order for an &lt;em&gt;OR&lt;/em&gt; statement to be true.&lt;/p&gt;

&lt;p&gt;|1 ∨ 0 = 1|0 ∨ 1 = 1|1 ∨ 1 = 1|0 ∨ 0 = 0|&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
x = (0 or 0)
print(x)
# &amp;gt;&amp;gt; 0
x = (1 or 0)
print(x)
# &amp;gt;&amp;gt; 1
x = (1 or 1)
print(x)
# &amp;gt;&amp;gt; 1
x = (False or False)
print(x)
# &amp;gt;&amp;gt; False
x = (False or True)
print(x)
# &amp;gt;&amp;gt; True
x = (True or True)
print(x)
# &amp;gt;&amp;gt; True

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



&lt;h2&gt;
  
  
  NOT | Negation
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;NOT&lt;/em&gt; expressions are denoted with the symbols &lt;code&gt;¬&lt;/code&gt; or &lt;code&gt;~&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If a = 1 then ~a = 0 or vice versa&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
x = (not False)
print(x)
# &amp;gt;&amp;gt; True
x = (not True)
print(x)
# &amp;gt;&amp;gt; False

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



&lt;h2&gt;
  
  
  Exclusive OR | Exclusive Disjunction | XOR
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Exclusive OR expressions&lt;/em&gt; are denoted with the symbols &lt;code&gt;⊕&lt;/code&gt; or &lt;code&gt;⊻&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The or exclusivity refers to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a or b but not a and b . They can never be both true at the same time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;|1 ⊻ 0 = 1| 0 ⊻ 1= 1|1 ⊻ 1= 0| 0 ⊻ 0 = 0|&lt;/p&gt;

&lt;p&gt;If this leaves you a bit confused try this XOR sandbox &lt;a href="http://xor.pw/"&gt;http://xor.pw/&lt;/a&gt; you will understand it in no time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# To define XOR declarions in Python you can simply use the symbol ^
x = (0 ^ 0)
print(x)
# &amp;gt;&amp;gt; 0
x = (1 ^ 1)
print(x)
# &amp;gt;&amp;gt; 0
x = (1 ^ 0)
print(x)
# &amp;gt;&amp;gt; 1

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



&lt;h2&gt;
  
  
  NAND
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;NAND&lt;/em&gt; is a contraction of not and , meaning its result will always be the opposite of its &lt;em&gt;AND&lt;/em&gt; expression. &lt;em&gt;NAND&lt;/em&gt; is defined with the symbol &lt;code&gt;↑&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;a ↑ b = ~(a ∧ b)&lt;/p&gt;

&lt;p&gt;|1 ↑ 0 = 1| 0 ↑ 1= 1|1 ↑ 1= 0| 0 ↑ 0= 1|&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
x = not(1 and 0)
print(x)
# &amp;gt;&amp;gt; True
x = not(1 and 1)
print(x)
# &amp;gt;&amp;gt; False
x = not(False and True)
print(x)
# &amp;gt;&amp;gt; True
x = not(True and True)
print(x)
# &amp;gt;&amp;gt; False

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



&lt;h2&gt;
  
  
  Implies | Conditional
&lt;/h2&gt;

&lt;p&gt;As the name indicates there is a condition involved. Meaning if “If A then B” or “A implies B”. Implies are denoted with the symbol &lt;code&gt;→&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;|0 → 0 = 1| 0 → 1 = 1|1 → 1 = 1|1 → 0 = 0|&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def conditional(x, z):
  if x == True:
    return z
  return True

x = True
z = False

print(conditional(x, z))

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



&lt;h2&gt;
  
  
  If and Only If | Biconditional
&lt;/h2&gt;

&lt;p&gt;A &lt;em&gt;biconditional&lt;/em&gt; is a connective that represents the condition “if and only if”, by checking is both propositions have the same value. &lt;em&gt;Biconditionals&lt;/em&gt; are denoted with the symbol &lt;code&gt;↔&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A ↔ B = (A → B) ∧ (B → A)&lt;/p&gt;

&lt;p&gt;|0 ↔ 0 = 1| 0 ↔ 1 = 0|1 ↔ 1 = 1|1 ↔ 0 = 0|&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def main(a, b):

  def conditional(a, b):
    if a == True:
      return b
    return True

  A = conditional(a, b)
  B = conditional(b, a)
  if A == B:
    return True
  else:
    return False

a, b = True, False
print(main(a, b))

a, b = True, True
print(main(a, b))

a, b = False, True
print(main(a, b))

a, b = False, False
print(main(a, b))

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



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Mathematical notation does not have to be complicated as you have seen. Now I leave it up to you as a challenge to try and create your own expressions and test them.&lt;/p&gt;

&lt;p&gt;In case you are a Python developer try and create small algorithms using Propositional Logic Notation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bibliography
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://brilliant.org/wiki/propositional-logic/"&gt;Propositional Logic | Brilliant Math &amp;amp; Science Wiki&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Propositional_calculus"&gt;Propositional calculus&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Links on mathematical notation with Python
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://aderito-xavier.com/posts/mathematical-notation-for-python-developers-part-1"&gt;Mathematical Notation for Python Developers (Part 1)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aderito-xavier.com/posts/mathematical-notation-for-python-developers-part-2"&gt;Mathematical Notation for Python Developers (Part 2) | Sets continuation&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mathematical Notation for Python Developers (Part 2) | Set Notation</title>
      <dc:creator>Adérito Xavier</dc:creator>
      <pubDate>Thu, 11 Jun 2020 11:46:36 +0000</pubDate>
      <link>https://dev.to/pars3c/mathematical-notation-for-python-developers-part-2-set-notation-18e</link>
      <guid>https://dev.to/pars3c/mathematical-notation-for-python-developers-part-2-set-notation-18e</guid>
      <description>&lt;p&gt;In the previous article, we went through a basic understanding of what sets are and how their memberships work through simple Python 3 snippets.&lt;/p&gt;

&lt;p&gt;In this part 2 we will keep on understanding more about set relationships using our friend Python 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Union
&lt;/h2&gt;

&lt;p&gt;As the name denotes, it is a union of 2 or more sets. Unions are denoted with the symbol ∪.&lt;/p&gt;

&lt;p&gt;If A and B are sets and A = {1, 2, 3}, B={3, 4, 5} then A ∪ B = {1, 2, 3, 4, 5}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# For more info https://www.w3schools.com/python/ref_set_union.asp

a = {1, 2, 3}
b = {3, 4, 5}

c = a.union(b)
print(c)
# &amp;gt;&amp;gt; {1, 2, 3, 4, 5}

"""
If you do not want to use any in-build functionalities you can simply use the | operator to unite sets.
For more info https://www.programiz.com/python-programming/methods/set/union
"""

c = a | b

print(c)
# &amp;gt;&amp;gt; {1, 2, 3, 4, 5}

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



&lt;h2&gt;
  
  
  Intersection
&lt;/h2&gt;

&lt;p&gt;Intersections are used when you want to obtain the elements that exist in both sets, intersections are denoted with the symbol ∩.&lt;/p&gt;

&lt;p&gt;If A and B are sets and A = {1, 2, 3}, B={3, 4, 5} then A ∩ B = {3}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# For more info check
# https://www.w3schools.com/python/ref_set_intersection.asp

a = {1, 2, 3}
b = {3, 4, 5}

c = a.intersection(b)
print(c)
# &amp;gt;&amp;gt; {3}

"""
If you do not want to use any in-build functionalities you can simply use the &amp;amp; operator to get the set intersection.
For more info https://www.programiz.com/python-programming/methods/set/intersection
"""

c = a &amp;amp; b

print(c)
# &amp;gt;&amp;gt; {3}

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



&lt;h2&gt;
  
  
  Difference
&lt;/h2&gt;

&lt;p&gt;The difference is the set of all elements of A that are not elements of B. Difference is denoted with the symbol -.&lt;/p&gt;

&lt;p&gt;If A and B are &lt;em&gt;sets&lt;/em&gt; and A = {1, 2, 3}, B={3, 4, 5} then A - B = {1, 2}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# For more info check:
# https://www.w3schools.com/python/ref_set_difference.asp

a = {1, 2, 3}
b = {3, 4, 5}

c = a.difference(b)
print(c)
# &amp;gt;&amp;gt;  {1, 2}

"""
If you do not want to use any in-build functionalities you can simply use the - operator to get the difference.
For more info https://www.programiz.com/python-programming/methods/set/difference
"""

c = a - b

print(c)
# &amp;gt;&amp;gt;  {1, 2}

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



&lt;h2&gt;
  
  
  Complement
&lt;/h2&gt;

&lt;p&gt;If A is a set and A = {1, 2, 3} then, the complement of A will refer to the elements, not in A. Complement can be denoted in different ways like A’ or Aᶜ or:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---S-xLynr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2Ahs8HRz743ErovreT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---S-xLynr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2Ahs8HRz743ErovreT.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE&lt;/em&gt;: In case you are wondering why the last complement notation is in image format, that is because medium does not render some latex configurations correctly.&lt;/p&gt;

&lt;p&gt;Let’s assume that set X contains all the possible numbers in the universe and set X= {1 ,2, 3, 4, 5, 6, 7} and we have another set denoted as set A, A = {1, 2, 3} then Aᶜ = {4, 5, 6, 7}.&lt;/p&gt;

&lt;p&gt;I am not gonna represent this notation in Python 3 since it is similar to what the &lt;em&gt;difference notation represents&lt;/em&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  ALWAYS BE VERY CAREFUL USING THE COMPLEMENT NOTATION AND TRY TO ADD CONTEXT INTO IT OR ELSE YOU MIGHT END UP WITH AN INFINITE SET.
&lt;/h4&gt;

&lt;h2&gt;
  
  
  Symmetric Difference
&lt;/h2&gt;

&lt;p&gt;Symmetric Difference is the set that contains elements that exist in A and B but not both. Symmetric Difference is denoted by the symbol ∆.&lt;/p&gt;

&lt;p&gt;If A and B are sets and A = {1, 2, 3}, B={3, 4, 5} then A — B = {1, 2, 4, 5}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# For more info check:
# https://www.w3schools.com/python/ref_set_symmetric_difference.asp

a = {1, 2, 3}
b = {3, 4, 5}

c = a.difference(b)
print(c)
# &amp;gt;&amp;gt; {1, 2, 4, 5}

"""
If you do not want to use any in-build functionalities you can simply use the ^ operator to get the difference.
For more info https://www.programiz.com/python-programming/methods/set/symmetric_difference
"""

c = a ^ b

print(c)
# &amp;gt;&amp;gt; {1, 2, 4, 5}

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



&lt;h2&gt;
  
  
  Cartesian Product
&lt;/h2&gt;

&lt;p&gt;Cartesian Product is the multiplication of two sets to form the set of all ordered pairs. Cartesian product is denoted by the multiplication symbol ×.&lt;/p&gt;

&lt;p&gt;If A and B are &lt;em&gt;sets&lt;/em&gt; and A = {1, 2, 3}, B={4,5,6}&lt;/p&gt;

&lt;p&gt;A × B = {(a,b): a ∈ A and b ∈ B}&lt;/p&gt;

&lt;p&gt;then A × B = {(2, 4), (3, 4), (1, 5), (1, 4), (2, 6), (3, 6), (1, 6), (2, 5), (3, 5)}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
a = {1,2,3}
b = {4,5,6}
v = {(x, y) for x in a for y in b}

print(v)
# &amp;gt;&amp;gt; {(2, 4), (3, 4), (1, 5), (1, 4), (2, 6), (3, 6), (1, 6), (2,5), # (3, 5)}

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



&lt;h2&gt;
  
  
  Power set
&lt;/h2&gt;

&lt;p&gt;If A is a set, then the power set of A is the set of all subsets of A, this includes the empty set and A itself. Power set of A is denoted by P(A).&lt;/p&gt;

&lt;p&gt;A = {1, 2, 3} then &lt;code&gt;P(A) = {{},{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}}&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  NOTE:
&lt;/h4&gt;

&lt;p&gt;In the Python snippet below you will notice that we are not using sets within sets. This happens because every object you add inside of a set must be immutable. So you will see the parent set and instead of child sets you will see itertools objects with the powerset iterations.&lt;/p&gt;

&lt;h4&gt;
  
  
  WELL, WHY IN THE HELL DO THEY TO BE IMMUTABLE YOU MIGHT ASK?
&lt;/h4&gt;

&lt;p&gt;Because every object you add inside of a set is gonna be hashed, that is the way sets in Python to figure out the unique values and index them, meaning you cannot add sets, lists, dictionaries or any other mutable object within a set.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hashable:&lt;br&gt;
An object is hashable if it has a hash value which never changes during its lifetime (it needs a hash() method), and can be compared to other objects (it needs an eq() or cmp() method). &lt;br&gt;
Hashable objects which compare equal must have the same hash value. Hashability makes an object usable as a dictionary key and a set member, because these data structures use the hash value internally. &lt;br&gt;
All of Python’s immutable built-in objects are hashable, while no mutable containers (such as lists or dictionaries) are. Objects which are instances of user-defined classes are hashable by default; they all compare unequal, and their hash value is their id().&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
from itertools import combinations, chain

# Defines the parent set and adds an empty tuple inside (this is our # equivalent to an empty set)
empty_set = {(), }

def powerset(someset):

  try:

    # Check if someset is a set

    someset.isdisjoint

  except AttributeError:

    raise TypeError(

      f"{powerset.__name__} accepts only a set-like object as       parameter"

    ) from None

  # Get the length/cardinality of the set. 

  size = len(someset) # Check below for more information on length.

  combs =  set()

  for k in range(1, size+1):
    """

    Combinations are emitted in lexicographic sorted order. So,if the input iterable is sorted, the combination tuples will be produced in sorted order.

    For more info check:  https://docs.python.org/3/library/itertools.html#itertools.combinations

    """

    subset = combinations(someset, k)

    combs.add(subset)

  """

  Make an iterator that returns elements from the first iterable  until it is exhausted, then proceeds to the next iterable, until all of the iterables are exhausted. Used for treating consecutive sequences as a single sequence.

  For more info check: https://docs.python.org/3/library/itertools.html#itertools.chain

  """

  return set(chain(empty_set, *combs))

print(powerset({1, 2, 3}))
# &amp;gt;&amp;gt; {(1, 3), (2,), (1, 2), (1, 2, 3), (2, 3), (1,), (), (3,)}

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



&lt;h2&gt;
  
  
  Cardinality
&lt;/h2&gt;

&lt;p&gt;Cardinality represents the number of elements within a set also known as set length. If A is a set then the cardinality of A is denoted by |A|.&lt;/p&gt;

&lt;p&gt;If A is a set and A = {1, 2, 3} then |A| = 3&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
a = {1, 2, 3}
cardinality = len(a)
print(cardinality)
# &amp;gt;&amp;gt; 3

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



&lt;h3&gt;
  
  
  Helpful Links:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.rapidtables.com/math/symbols/BasicMathSymbols.html"&gt;https://www.rapidtables.com/math/symbols/BasicMathSymbols.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Mathematical Notation for Python Developers (Part 1)</title>
      <dc:creator>Adérito Xavier</dc:creator>
      <pubDate>Wed, 10 Jun 2020 11:58:58 +0000</pubDate>
      <link>https://dev.to/pars3c/mathematical-notation-for-python-developers-part-1-lab</link>
      <guid>https://dev.to/pars3c/mathematical-notation-for-python-developers-part-1-lab</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As a self-taught developer, I struggled most of the time reading whitepapers, or going through data science courses that contain incredible amounts of mathematical jargon (mostly weird and magic symbols).&lt;/p&gt;

&lt;p&gt;This tutorial is going to be focused on translating mathematical notation to Python.&lt;/p&gt;

&lt;p&gt;NOTE: Python 3.6 is what I will be using throughout this tutorial series.&lt;/p&gt;

&lt;p&gt;FYI: I will avoid using any libraries whenever I can so that anyone can easily understand what is going on underneath the notation.&lt;/p&gt;

&lt;p&gt;My thanks to &lt;strong&gt;Edward R. Scheinerman&lt;/strong&gt; for the book &lt;em&gt;Mathematical Notation: A Guide for Engineers and Scientists&lt;/em&gt; which was my biggest help at the start.&lt;/p&gt;

&lt;p&gt;If you are struggling as I did I strongly advice you to buy it, here is a link if you feel inclined to &lt;a href="https://www.amazon.co.uk/Mathematical-Notation-Engineers-Scientists-Scheinerman/dp/B00E321MU8" rel="noopener noreferrer"&gt;https://www.amazon.co.uk/Mathematical-Notation-Engineers-Scientists-Scheinerman/dp/B00E321MU8&lt;/a&gt;.&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A_rJI9gv6gpkw7LmO" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A_rJI9gv6gpkw7LmO" alt="Mathematical Notation: A Guide for Engineers and Scientists"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  SO… LET’S GET STARTED SHALL WE?
&lt;/h2&gt;

&lt;h2&gt;
  
  
  SETS
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;set&lt;/strong&gt; is a collection of items where repetition is forbidden.&lt;/p&gt;

&lt;p&gt;Example: {1, 2, 3, 4}&lt;/p&gt;

&lt;p&gt;Reinforced note: A set with repetition like {1,2,3,4,4} will be equal to {1,2,3,4} again, because repetition is non-existent within a set.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set declaration in Python:
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Declare the set
my_set = {1, 2, 3, 4, 4}
# Will output {1, 2, 3, 4}

# FUN NOTE: Strings can also be added to sets in Python like        
# {"Banana", "Apple"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Set and element membership
&lt;/h2&gt;

&lt;p&gt;Memberships between Sets and elements are defined with the following symbols:&lt;/p&gt;

&lt;p&gt;For easy readability, I will add the symbol followed by it’s meaning.&lt;/p&gt;

&lt;p&gt;∈ (element exists in), 1 ∈ {1, 2, 3}&lt;/p&gt;

&lt;p&gt;∋ (set contains element), {1, 2, 3} ∋ 1&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Declare the set
my_set = {1, 2, 3}

print(1 in my_set) # Equivalent to 1 ∈ {1, 2, 3} or {1, 2, 3} ∋ 1
&amp;gt;&amp;gt; True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;∉ (element does not exist in), 1 ∉ {2, 5, 6}&lt;/p&gt;

&lt;p&gt;∌ (set does not contain element), {2, 5, 6} ∌ 1&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Declare the set
my_set = {1, 2, 3}

(1 not in my_set) # Equivalent to 1 ∉ {2, 5, 6} or {2, 5, 6} ∌ 1
&amp;gt;&amp;gt; True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Dealing with large Sets
&lt;/h3&gt;

&lt;p&gt;Let’s say you want to create a set that goes from 1 to 100, you do not want to write everything on paper, instead, you can show some of the elements that convey the pattern and fills the rest with ellipses (…).&lt;/p&gt;

&lt;p&gt;Example: {1, 2, 3, 4, 5, …, 100}&lt;/p&gt;

&lt;p&gt;You can also take the following approach:&lt;/p&gt;

&lt;p&gt;{x ∈ ℤ: 1 ≤ x ≤ 100}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTES&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ℤ = {-∞, …, -2,-1,0,1,2….∞} = the set of all integers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;x represents a dummy variable used for each iteration.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;x ∈ ℤ = x iteration is part of the ℤ set, in other words, x is gonna be an integer in each iteration.&lt;/p&gt;

&lt;p&gt;1 ≤ x ≤ 100 = Each x iteration is going to be (greater or equal to 1) and (less or equal to 100).&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# In case you are wondering about why the range goes to 101, that is 
# because, the last argument is where it stops, meaning it will only 
# reach the previous iteration (100).
# For more information check:   
# https://www.geeksforgeeks.org/python-range-function/

our_set = {x for x in range(1, 101)}
print(our_set)
&amp;gt;&amp;gt; {1, 2, 3, 4,..., 100}

# or the easiest approach for newcomers.

our_set = set()
for x in range(1, 101):    
    our_set.add(x)
print(our_set)
&amp;gt;&amp;gt; {1, 2, 3, 4,..., 100}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Set to Set Membership
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Set Equality
&lt;/h3&gt;

&lt;p&gt;A = {1, 2, 3, 4, 5} and B = {1, 2, 3, 4, 5} then we can say that **A = B **because the elements found in both variables are the same.&lt;/p&gt;
&lt;h3&gt;
  
  
  Subsets
&lt;/h3&gt;

&lt;p&gt;A = {1, 2, 3} and B = {1, 2, 3, 4, 5}&lt;/p&gt;

&lt;p&gt;We can see that every element in A can be found in B as well, meaning A is a subset of B or A ⊆ B = {1, 2, 3} ⊆ {1, 2, 3, 4, 5}&lt;/p&gt;

&lt;p&gt;⊆ equivalent to“subset of”.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# For more info check:
# https://www.programiz.com/python-programming/methods/set/issubset
A = {1, 2, 3}
B = {1, 2, 3, 4, 5}
C = {1, 2, 4, 5}

# Returns True
print(A.issubset(B))

# Returns False
# B is not subset of A
print(B.issubset(A))

# Returns False
print(A.issubset(C))

# Returns True
print(C.issubset(B))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Supersets
&lt;/h3&gt;

&lt;p&gt;A superset is taken by the opposite order of a subset, since here we are defining that set A has *&lt;em&gt;all *the elements of | is a superset of **B in which we could also say that B is a subset of A.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A ⊇ B = B ⊆ A&lt;/p&gt;

&lt;p&gt;A = {1, 2, 3, 4, 5} and B = {1, 2, 3}&lt;/p&gt;

&lt;p&gt;A ⊇ B = {1, 2, 3, 4, 5} ⊆ {1, 2, 3}&lt;/p&gt;

&lt;p&gt;⊇ equivalent to “superset of”.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""
For more information check:
https://www.programiz.com/python-programming/methods/set/issuperset
"""

A = {1, 2, 3, 4, 5}
B = {1, 2, 3}
C = {1, 2, 3}

# Returns True
print(A.issuperset(B))

# Returns False
print(B.issuperset(A))

# Returns True
print(C.issuperset(B))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>mathematics</category>
      <category>science</category>
    </item>
  </channel>
</rss>
