<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Joshua M Loran</title>
    <description>The latest articles on Forem by Joshua M Loran (@joshualoran).</description>
    <link>https://forem.com/joshualoran</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%2F144875%2F5c673dfb-812c-4adc-ac7d-e4d0a72161d3.jpg</url>
      <title>Forem: Joshua M Loran</title>
      <link>https://forem.com/joshualoran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/joshualoran"/>
    <language>en</language>
    <item>
      <title>What are websockets</title>
      <dc:creator>Joshua M Loran</dc:creator>
      <pubDate>Tue, 14 May 2019 18:50:55 +0000</pubDate>
      <link>https://forem.com/joshualoran/what-are-websockets-14f5</link>
      <guid>https://forem.com/joshualoran/what-are-websockets-14f5</guid>
      <description>&lt;p&gt;A web socket is a computer communications protocol that provides full-duplex communication channels over a single TCP connection. TCP stands for Transmission Control Protocol and is one of the main communication protocols in the &lt;a href="https://en.wikipedia.org/wiki/Internet_protocol_suite" rel="noopener noreferrer"&gt;internet protocol suite&lt;/a&gt;.  Establishing a full-duplex communication is the the power of the web socket.  &lt;/p&gt;

&lt;p&gt;What is Full-duplex communication? Picture a section of road with a post office on either end (A and B) that is 1 lane wide. Cars can go in either direction, BUT can only go when they are told it’s all clear by the other side or they may get in a head on collision (also, if they go even slightly off road they explode into a million shiny pieces).  So, a car leaves A and travels towards B, and B knows not to go until the car from A reaches B and says the road is clear.  Car A may have a request that something be sent back to post office A, and/or it may be communicating some info by dropping off some mail. &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%2Fwww.dangerousroads.org%2Fimages%2Fstories%2F__Roads00000e%2FBigKahekili%2520Highway0.jpg" 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%2Fwww.dangerousroads.org%2Fimages%2Fstories%2F__Roads00000e%2FBigKahekili%2520Highway0.jpg" title="One Lane Road" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This happens a lot with web communication. Client sends a request and/or info, server gets the request/info, processes what to do with it and sends back some info. Turns are taken, my kindergarten teacher, Mrs. Smith, is happy and all is well in the world. But web sockets throw all that polite turn taking out the window.&lt;/p&gt;

&lt;p&gt;We’ve picture a single lane road as standard communication where two entities communicate by taking turns sending requests and information. But, and I know this is crazy, what if there was a TWO lane road. What if there was a world where 2 entities could send information whenever they wanted, AND, could receive information whenever the other felt like sending it.  This bi-directional  road means that each side doesn’t have to send out requests because there is no  need  to control who’s turn it is, an entity simply needs to “subscribe” to the other to accept any information that may come from that direction.&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%2Fi.pinimg.com%2Foriginals%2F39%2F3a%2F81%2F393a813c18c76da08c22efc0c6086413.jpg" 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%2Fi.pinimg.com%2Foriginals%2F39%2F3a%2F81%2F393a813c18c76da08c22efc0c6086413.jpg" title="Two Lane Road" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, another thought experiment. Entity A is a server that performs some function and returns an answer. However, this time there isn’t just  entity B as a client, there are hundreds of clients and they all have this 2 lane road leading to/from the server. The server can now  update all the clients without the need for request/response from each individual client. The server can simply “broadcast” some information to all the clients “subscribed” to that lane (or channel) at the same time and each client can send information to the server for processing.  &lt;/p&gt;

&lt;p&gt;Cool! No more polling or long-polling for a client to try to stay current with the state of the server.  Information is now realtime, being sent by both sides upon processing, and received whenever it comes at them.  We now live in a turn free world where things just do as they please.  Now we can do cool things like make multiplayer realtime games!&lt;/p&gt;

&lt;p&gt;To dip a little into web sockets, I made a 2 player tic-tac-toe game that used them.  Ruby on rails and Action cable provide a pretty straight forward implementation of web sockets for beginners.  Here is a some basic setup to get you started with Ruby and Actioncable with a React frontend to use websockets. &lt;/p&gt;

&lt;p&gt;First generate your React front end by entering the following into your console:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
create-react-app &amp;lt;your-frontend-project-name&amp;gt;&lt;br&gt;
cd &amp;lt;your-frontend-project-name&amp;gt;&lt;br&gt;
yarn add actioncable&lt;br&gt;
yarn start&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
And then get you rails backend wireframe up by entering the following into your console:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
rails new &amp;lt;your-backend-project-name&amp;gt; --api&lt;br&gt;
cd &amp;lt;your-backend-project-name&amp;gt;&lt;br&gt;
rails g scaffold &amp;lt;your-model-name&amp;gt; &amp;lt;your-models-attributes&amp;gt;&lt;br&gt;
rails db:migrate&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The next step is to persist an instance of your model by creating one in the rials console:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
rails c &lt;br&gt;
&amp;lt;your-model&amp;gt;.create!(attributes)&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Be sure to setup cors by uncommenting the 'rack-cors' gem in your gemfile and uncommenting the following in your application.rb. Making sure origins is set to the acceptable url, or in this case I used * to make every url acceptable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert_before&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Rack&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Cors&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
      &lt;span class="n"&gt;allow&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;origins&lt;/span&gt; &lt;span class="s1"&gt;'*'&lt;/span&gt;
        &lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s1"&gt;'*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:headers&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ss"&gt;:any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:methods&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:options&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run Bundle install.&lt;/p&gt;

&lt;p&gt;Now to wire up actioncable. The next few steps are fairly simple. Navigate to your &lt;code&gt;config.routes.rb&lt;/code&gt; and add the following before the last &lt;code&gt;end&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;&lt;br&gt;
mount ActionCable.server =&amp;gt; '/cable'&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Then, go to your console and type in the following:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
rails g channel &amp;lt;your-model-name&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now Actioncable can pickup websockets that are coming into &lt;code&gt;/cable&lt;/code&gt; and your rails backend will have a new file &lt;code&gt;app/channels/&amp;lt;your-model&amp;gt;_channel.rb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open that file up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="no"&gt;Channel&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationCable&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Channel&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;subscribed&lt;/span&gt;
    &lt;span class="c1"&gt;# stream_from "some_channel"&lt;/span&gt;
    &lt;span class="n"&gt;stream_from&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;your-model&amp;gt;'&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;unsubscribed&lt;/span&gt;
    &lt;span class="c1"&gt;# Any cleanup needed when channel is unsubscribed&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;Your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Model&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;attr: &lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"attr"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="no"&gt;ActionCable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;broadcast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;your-model&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we've added &lt;code&gt;stream_from&lt;/code&gt; to the subscribed method and then told rails what to do with received data in the receive method. Our backend is  now setup for streaming!&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%2Fmedia0.giphy.com%2Fmedia%2F2csuIJj6TmuKA%2Fgiphy.webp%3Fcid%3D790b76115cdb073431614a326f5eedb6%26rid%3Dgiphy.webp" 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%2Fmedia0.giphy.com%2Fmedia%2F2csuIJj6TmuKA%2Fgiphy.webp%3Fcid%3D790b76115cdb073431614a326f5eedb6%26rid%3Dgiphy.webp" title="cool stream" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, lets setup our frontend to subscribe and talk to our backend.  We will need to do a few things in order to accomplish this.  First, connect to &lt;code&gt;/cable&lt;/code&gt; that we setup in our backend. Second, subscribe to the our model channel. And last, send any data by the user on the front side.&lt;/p&gt;

&lt;p&gt;To accomplish these 3 things we must first import actioncable by putting &lt;code&gt;import ActionCable from 'actioncable'&lt;/code&gt; at the top of your app.js and creating a consumer inside of your componentDidMount method. We must next setup our subscription and set a callback for when we receive data. The final file might look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ActionCable&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;actioncable&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:3001/&amp;lt;your-model&amp;gt;/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ActionCable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createConsumer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ws://localhost:3001/cable&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscriptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NotesChannel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;received&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleReceiveNewText&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleReceiveNewData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That pretty much the gist of setting up a websocket with rails and react. There is obviously some more things that need to be done like displaying/grabbing information on the screen (controlled inputs are best), data sanitization, authorization, and more. But, this is a super simple setup to get you started. &lt;/p&gt;

</description>
      <category>rails</category>
      <category>actioncable</category>
      <category>react</category>
      <category>websockets</category>
    </item>
    <item>
      <title>From Ruby to Rust</title>
      <dc:creator>Joshua M Loran</dc:creator>
      <pubDate>Wed, 24 Apr 2019 17:21:33 +0000</pubDate>
      <link>https://forem.com/joshualoran/from-ruby-to-rust-1hgn</link>
      <guid>https://forem.com/joshualoran/from-ruby-to-rust-1hgn</guid>
      <description>&lt;p&gt;I’m more than half through a software engineering bootcamp. I can’t believe how much we’ve learned over the last 2 and half months, and how much information I’ve been able to cram in this melon. But, if you’re like me, you’re passionate about software engineering and thinking about what your next step might be in the engineering world. After learning Ruby, Ruby on Rails, Javascript, HTML, and CSS, I’m learning some of the limitations of these languages as well as their strengths. &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%2Fd2v9y0dukr6mq2.cloudfront.net%2Fvideo%2Fthumbnail%2FNGTYhyRhgilq4uu1a%2Fcartoon-animation-design-of-knowledge-creativity-and-intellectual-education-icons-flow-from-a-man-head-brain-with-infographic-text-in-4k-ultra-hd-video_s4urukez__F0014.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%2Fd2v9y0dukr6mq2.cloudfront.net%2Fvideo%2Fthumbnail%2FNGTYhyRhgilq4uu1a%2Fcartoon-animation-design-of-knowledge-creativity-and-intellectual-education-icons-flow-from-a-man-head-brain-with-infographic-text-in-4k-ultra-hd-video_s4urukez__F0014.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ruby is an intuitive, easily readable, and easily setup language. With Ruby on Rails, typing in a generate scaffold command sets up the start of a backend server that might take a day more to type out from scratch, but does in it a few seconds. Ruby has syntactical sugar on top of syntactical sugar to make typing out code pleasurable.  Like wait…I don’t need parenthesis here or typing there, but how does ruby know…magic. Ruby is full of magical behind the scenes workings that just make programming easier and more intuitive than most other languages.  This magic is part of what made Slant.co rank ruby 5th for beginning developers. Why not first? Because the magic of Ruby comes with several drawbacks.&lt;/p&gt;

&lt;p&gt;Developers that start with Ruby, and only know Ruby, may not understand things like pointers, typing, and/or data structures.  Also, since Ruby almost strictly functions as an object oriented language, Ruby only developers may not learn or understand many of the other programming paradigms.  Ruby also has limitations of scale and resource consumption making working with larger projects far less efficient, case in point Twitter &lt;a href="https://blog.twitter.com/engineering/en_us/topics/infrastructure/2017/the-infrastructure-behind-twitter-scale.html" rel="noopener noreferrer"&gt;switching languages&lt;/a&gt;. So...&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%2Fgx0ri2vwi9eyht1e3iyzyc17-wpengine.netdna-ssl.com%2Fwp-content%2Fuploads%2F2018%2F01%2Fnext.jpg" 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%2Fgx0ri2vwi9eyht1e3iyzyc17-wpengine.netdna-ssl.com%2Fwp-content%2Fuploads%2F2018%2F01%2Fnext.jpg" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All this brought me to a question. What would be a good language to learn that would help solidify deeper concepts and make me a more useful and productive developer? I want to write efficient code that uses minimum resources. I want to have the power of C++ without the years long learning curve or the complexity of syntax.  And, I wanted the enjoyability and ease of coding I get with Ruby. I’d heard about Rust from a few more experienced developers that were kind of pointing me towards it after I told them what I was looking for.  &lt;/p&gt;

&lt;p&gt;Rust is closer to C than Ruby. However, It has better memory safety and management.  For example, pointers are not allowed to point to other pointers. On compile, the intermediate pointers are removed from the equation. Types are only mutable or immutable if you explicitly them to be.  There is also no automated garbage collector. Instead, it uses RAII (Resource Acquisition Is Initializtion) which provides deterministic management of resources and at compile, prevents  things like dangling pointers and other forms of undefined behavior.  Also, the syntax and code structure force developers to write optimal code. &lt;/p&gt;

&lt;p&gt;Because of its memory safety and resource efficiency, slant.co has ranked Rust as the #1 language to learn for backend developers, the #2 language for concurrency and meta programming.  Rust also earned #1 as the best all around compiled language, as well as 2017’ and 2018’s most loved programming language on Stack Overflow’s &lt;a href="https://stackoverflow.com/insights/survey/2017#most-loved-dreaded-and-wanted." rel="noopener noreferrer"&gt;developer survey&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Getting started with Rust is fairly easy and straight forward. You can read “&lt;a href="https://doc.rust-lang.org/book/" rel="noopener noreferrer"&gt;The Book&lt;/a&gt;” online.  The book will walk you through all the basics from Hello World, to building a CLI, and even a server setup.  Going from any language, even magical Ruby, to Rust isn’t too difficult since a lot of the concepts are the same.  You just get to learn to how to have more control over how things work.  In ruby, you might make an object that looks something like:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fp1q428svihtmawbjjow5.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fp1q428svihtmawbjjow5.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Rust, the same thing might look something like:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqa8nirw5q70vgx6hxrdf.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqa8nirw5q70vgx6hxrdf.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rust has a large community to learn from and is well documented.  So, as you dive deeper into the language there is ever more information and people to learn from.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Is multi-threading in Ruby a thing?</title>
      <dc:creator>Joshua M Loran</dc:creator>
      <pubDate>Wed, 03 Apr 2019 20:04:08 +0000</pubDate>
      <link>https://forem.com/joshualoran/is-multi-threading-in-ruby-a-thing-2556</link>
      <guid>https://forem.com/joshualoran/is-multi-threading-in-ruby-a-thing-2556</guid>
      <description>&lt;p&gt;All programming languages have their advantages and disadvantages. Ruby’s ease of use and semantic language makes it a great introduction to the world of software engineering.  A topic came up the other day in a discussion about the pluses and minus of Ruby vs some other languages.  Ruby is kind of in this grey area of being neither, and both, a compiled language and an interpreted one.  The code we right is compiled into a lower level language called byte code before that is then interpreted into machine code, and even lower level language native.  Interpreted languages tend to be more portable to other environments while compiled languages give no guarantee they will work on a machine they were not compiled on.  Compiled languages are generally faster and less resource intensive and can be tweaked for optimization down to the machine code level, while interpreted languages cannot.  &lt;/p&gt;

&lt;p&gt;I was told by a fellow colleague that Ruby was slow in comparison due to the fact that multi-threading is not possible with an interpreted language. In fact, ruby does have a few ways to utilize multiple threads.  But, what does that even mean? When people talk about multi-threading, they are saying “a technique by which a single set of code can be used by several processors at different stages of execution.”  To clarify, it is a way to run code in parallel with separate processors.  If a program takes 4 minutes to compute, you may be able to break the work load into to 4 parts and run them in 4 threads for a total process time of 1 minute instead of 4. &lt;/p&gt;

&lt;p&gt;We’ll get back to multi-threading in a moment. There are two things that often get confused, so let’s first talk about concurrency and parallelism.  Parallelism is when two tasks run at the same time. While concurrency is when two tasks can start, run, and complete in overlapping time periods but that doesn’t mean that they are ever running at the same time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqa00z2ly7qyr99wzi7ev.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqa00z2ly7qyr99wzi7ev.jpg" alt="alt text" width="554" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see from the image above, concurrency is cool, but what I really want is parallelism.  In Ruby, it turns out there are a few ways to achieve parallelism. We can use multiple processes or multiple threads, and again, each way has it’s pluses and minuses.  In Ruby, we can use the fork() method to create a “copy” of the process we are calling it on. &lt;/p&gt;

&lt;p&gt;Using fork() is very memory intensive however. This is because resources are allocated for each fork.  So, if you are running a process that takes 10mb to run but are running it 1000 times, it might get done in the timespan of running just a few processes, but  but the memory required would now be 10gb.  Also, if there are nested processes and the parent process dies before the child process, the child may turn into a zombie and you may end up with zombie processes running in the background just eating up resource with no purpose.  Examples for using multiple processes include &lt;a href="https://rubygems.org/gems/unicorn" rel="noopener noreferrer"&gt;Unicorn&lt;/a&gt;, and &lt;a href="https://github.com/resque/resque" rel="noopener noreferrer"&gt;Resque&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Here is an info graphic that explains some of the pluses and minuses to both multi-processing and multi-threading: &lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qvfwyfoqwdoclaks4el.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qvfwyfoqwdoclaks4el.png" alt="alt text" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking at the table above, we can see that the advantages to multi-threading are more numerous than that of using multi-processing.  However, the drawbacks of multi-threading can be more complex to deal with.  With multi-threading, the resource usage is much less because memory allocation only occurs once per defined container/object.  This is great!….But, this can lead to data corruption and unexpected value returns because multiple threads are accessing and/or writing a single memory address.  Ruby has a handy “thread()”  class to assign threads to processes, however controlling and debugging how memory is accessed by multiple accessors can be very complicated.&lt;/p&gt;

&lt;p&gt;Something that safeguards against funky memory access is called the GIL (Global Interpreter Lock) and it is utilized by most Ruby engines. The definition of a GIL is as follows : A mechanism used in computer-language interpreters to synchronize the execution of threads so that only one native thread can execute at a time. An interpreter that uses GIL always allows exactly one thread to execute at a time, even if run on a multi-core processor.  So basically, it won’t allow true multi-threading in order to safeguard against memory access/writing issues.&lt;/p&gt;

&lt;p&gt;So are we just screwed in Ruby? The answer is kind of, but no.  There are implementations of Ruby such as CRuby that have the GIL safe-guard built in.  But, there are also implementations like JRuby and Rubinius that do not include the GIL safeguard.  There are a few frameworks for working with server side multi-threading: &lt;a href="https://github.com/macournoyer/thin/" rel="noopener noreferrer"&gt;Thin&lt;/a&gt;, &lt;a href="https://github.com/mperham/sidekiq/wiki" rel="noopener noreferrer"&gt;Sidekiq&lt;/a&gt;, and &lt;a href="https://github.com/puma/puma" rel="noopener noreferrer"&gt;Puma&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In conclusion, there are a few ways to handle running multiple processes simultaneously and ruby. Multi-processing and multi-threading are both possible.  They each have different pros and cons and usage should be chosen depending on the application. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Bootstrap! A useful tool for beginners front end development</title>
      <dc:creator>Joshua M Loran</dc:creator>
      <pubDate>Mon, 25 Mar 2019 17:28:36 +0000</pubDate>
      <link>https://forem.com/joshualoran/bootstrap-a-useful-tool-for-beginners-front-end-development-3g52</link>
      <guid>https://forem.com/joshualoran/bootstrap-a-useful-tool-for-beginners-front-end-development-3g52</guid>
      <description>&lt;p&gt;So, I’m going to school to learn to be a full stack developer. So far we have learned many useful tools. We’ve learn various methods on how to manipulate datasets.  We’ve learned object oriented programming with ruby and how to build relationships  between the models. We’ve learned SQLite and active record database management.  And, we’ve learned some simple ways users can interact with views (or webpages).  Everything we’ve learned to this point enables us to build a a fairly complex backend for a website, but we have yet to learn about the user experience.&lt;/p&gt;

&lt;p&gt;An aweful experience...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3.amazonaws.com%2Flowres.cartoonstock.com%2Fcomputers-ux-user_experience_design-hci-website-dungeon-llan1943_low.jpg" 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%2Fs3.amazonaws.com%2Flowres.cartoonstock.com%2Fcomputers-ux-user_experience_design-hci-website-dungeon-llan1943_low.jpg" title="Horrible user experience" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is not what we as developers want for our users, and wouldn’t you know it, our next project is to build a fully functional website with a great frontend.  Sure, no problem. But what about the user experience? I’ve never dabbled in html, css, or javascript and while I have full confidence developing the scaffold for a website, I’ve never built a good looking front end. I had a chance to meetup with some of the students in the cohort before mine and their projects look amazing.  They include interactive sliders, buttons, great images and layouts that scale and adapt to to the users device and preferences. I want that same level of polish. I want the user and my site to be:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxv6rpdxips5le36m6zlr.gif" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxv6rpdxips5le36m6zlr.gif" title="Best friends forever" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How could some of these students, that were at the same level as me build such wonderful things.  The answer was, Bootstrap.  I’d never heard of bootstrap and didn’t know what it was, so I’ve spent the last few days researching what it is and how to use it.  I must say, it’s pretty cool stuff.  &lt;/p&gt;

&lt;p&gt;In a basic sense, bootstrap is a framework that can be accessed by front end developers for use in their designs.  It is composed of CSS, JavaScript/jQuery, and glyphicons.  At this point, those are magical things I don’t fully understand. But, the beauty of bootstrap is that I don’t need to have a robust knowledge of these things. It is a framework that lets me play with how a page looks and how a user interacts with it in such an easy way that I can accept it as a tool and move on to more important things.  &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%2Fencrypted-tbn0.gstatic.com%2Fimages%3Fq%3Dtbn%3AANd9GcRn_s0DI2LNNtQhXBzn87t3fO2EfqWxYLLII9rsouRL9lthcgMo" 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%2Fencrypted-tbn0.gstatic.com%2Fimages%3Fq%3Dtbn%3AANd9GcRn_s0DI2LNNtQhXBzn87t3fO2EfqWxYLLII9rsouRL9lthcgMo" title="magical" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The easiest way to get started is to head over to &lt;a href="https://getbootstrap.com/docs/4.3/getting-started/introduction/" rel="noopener noreferrer"&gt;the getting started&lt;/a&gt; page. However, you don't necessarily need to download the files to use it. It can also be used by utilizing a CDN, Content Delivery Network. One advantage of using a CDN is that bootstrap is used by MANY sites and is often in the users cache, which means potential faster load times.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/bootstrap/bootstrap_get_started.asp" rel="noopener noreferrer"&gt;w3schools&lt;/a&gt; has a great resource for playing around with some of the features of bootstrap. There are interactive "try it yourself" sections that let you play with the code before you even use in your project. But, perhaps an even better resource, once your comfortable with how bootstrap works is the &lt;a href="https://hackerthemes.com/bootstrap-cheatsheet/" rel="noopener noreferrer"&gt;bootstrap cheatsheet&lt;/a&gt; which has a very robust set of bootstrap interactions to make the user experience more enjoyable.&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%2Fpublic-media.interaction-design.org%2Fimages%2Fuploads%2F9153fdf2373a09b5a3d95cc4e68a966f.gif" 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%2Fpublic-media.interaction-design.org%2Fimages%2Fuploads%2F9153fdf2373a09b5a3d95cc4e68a966f.gif" title="user experience" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that you've read over and played with bootstrap a little bit and have a long list of usability features, you want to make it look pretty too. Some background imaging and device scaling sure would give the look and feel an upgrade. One of the great things about bootstrap is that it has a large open source community.  So, with sites like &lt;a href="https://startbootstrap.com/themes/" rel="noopener noreferrer"&gt;Start Bootstrap&lt;/a&gt;, &lt;a href="https://themes.getbootstrap.com/" rel="noopener noreferrer"&gt;Get Bootstrap&lt;/a&gt;(some cost money), and &lt;a href="http://wowslider.com/posts/35-top-free-bootstrap-templates-2016-95.html" rel="noopener noreferrer"&gt;Wowslider&lt;/a&gt;, it is easy to find a theme that will work for you. And, you can always tweek a theme to suit your needs.&lt;/p&gt;

&lt;p&gt;Good luck out there friends!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Desk Light Project! First steps into Dev'dom</title>
      <dc:creator>Joshua M Loran</dc:creator>
      <pubDate>Fri, 15 Mar 2019 04:31:38 +0000</pubDate>
      <link>https://forem.com/joshualoran/a-desk-light-project-first-steps-into-devdom-4iig</link>
      <guid>https://forem.com/joshualoran/a-desk-light-project-first-steps-into-devdom-4iig</guid>
      <description>&lt;p&gt;Since this is my first blog post, like…anywhere, I think it’s appropriate to tell you fine people how I started my journey into the dev world.  Micro-controllers!  A while back I happened into an Arduino Uno starter box and quickly tore through all of the starter projects that were explained in the included book.&lt;/p&gt;

&lt;p&gt;Micro controllers are great! Not only do they give us the ability to create something new, but also give us the ability to hack into almost any device that uses electricity as well has many that don’t.&lt;/p&gt;

&lt;p&gt;A micro controller does exactly what the name implies, it controls things, more importantly it controls things in a manner that you decide. There are many controllers on the market these days with Raspberry Pi and Arduino being two of the most commonly known to hobbyists.  A friend of mine had shown me his Raspberry Pi and it seemed like a bit of magic.  I had no programming experience other than an intro to Java course I took one quarter in college. What made the Pi actually work completely escaped me, but I wanted to know how to MAKE the magic. &lt;/p&gt;

&lt;p&gt;I asked my buddy to show me how the Pi knew to do things. He had no idea. He had put a Nintendo emulator a jillion games on there, fabricated a little box and connected it to his TV. COOL!!  He knew how to load software on it and run a program, but had no idea how to write the games or make it turn on a light switch.&lt;/p&gt;

&lt;p&gt;Arduino Uno...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F20190314_194714.jpg%3Fraw%3Dtrue" 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%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F20190314_194714.jpg%3Fraw%3Dtrue" title="Arduino Uno" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m going to talk about and show you one of the first rewarding projects I did using controllers.  &lt;/p&gt;

&lt;p&gt;I put up some shelves up above my wife’s desk so she could have more storage, but in doing so made the desk a bit dimmer on the working area and putting a desk lamp to light it was a bit ridiculous.&lt;/p&gt;

&lt;p&gt;I had an Arduino already so I knew I could probably something neat. I wanted to try to make some lights that one could control from their phone. So, i ordered a jy-mcu bluetooth chip so my arduino uno would be able to talk to another device through bluetooth.  I also ordered 3 meters of neopixel WRGB LED strips for the lighting.&lt;/p&gt;

&lt;p&gt;JY-MCU Bluetooth transmitter...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F5fER7MVjT3yHrvvDimidcQ_thumb_2.jpg%3Fraw%3Dtrue" 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%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F5fER7MVjT3yHrvvDimidcQ_thumb_2.jpg%3Fraw%3Dtrue" title="JY-MCU Bluetooth controller" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After reading the specs for all my components and doing a little online poking around, I wired them together accordingly. It is fairly straight forward wiring, and I learned quite a bit. The neopixel lighting uses only a single data line to control every light with each pixel talking to it's neighbor.  I added a 1000uf capacitor to smooth out any energy spikes in the data line since a dirty power signal could cause dirty data. A 220ohm resistor was also necessary on the data line. It looked like this...&lt;/p&gt;

&lt;p&gt;Inside the Box...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F20190314_064930.jpg%3Fraw%3Dtrue" 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%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F20190314_064930.jpg%3Fraw%3Dtrue" title="inside the box" alt="alt text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;From the outside...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F20190314_064949.jpg%3Fraw%3Dtrue" 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%2Fgithub.com%2FWTFCodingPotato%2FNeoPixelDeskShelves%2Fblob%2Fmaster%2F20190314_064949.jpg%3Fraw%3Dtrue" title="outside the box" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the main resources I used drive the lights was &lt;a href="https://www.Adafruit.com" rel="noopener noreferrer"&gt;Adafruit.com&lt;/a&gt;, which is where I purchased the light strips. They have a neopixel library that always you to choose a pixel and feed it WRGB values.  I asked my wife what kind of colors she wanted and went about finding the correlating wrgb values. Once I understand what was going on I wrote buttons to dim and brighten as well as seperate the 3 tiers so they could be selected individually or grouped. I then added some animations for Hannukah and Christmas. Adafruit also had a rainbow animation that I didn't fully understand, but still used! &lt;/p&gt;

&lt;p&gt;The addition of the tier selection meant that you could have your desk lit by the color of choice, while the accent lighting of the shelves above could be a soft blue or violet, an in your face red or orange, or an cool animated rainbow. &lt;a href="https://github.com/WTFCodingPotato/NeoPixelDeskShelves" rel="noopener noreferrer"&gt;Here&lt;/a&gt; is a link to my github for closer look. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.youtube.com/watch?v=ESvgF8Sfwa0" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fimg.youtube.com%2Fvi%2FESvgF8Sfwa0%2F0.jpg" alt="IMAGE ALT TEXT HERE"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
