<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by JordanisNotACoder on Medium]]></title>
        <description><![CDATA[Stories by JordanisNotACoder on Medium]]></description>
        <link>https://medium.com/@jordanIrabor?source=rss-3190c898b40f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*IgC8Pr8FSc5GEB8DzXadgA.jpeg</url>
            <title>Stories by JordanisNotACoder on Medium</title>
            <link>https://medium.com/@jordanIrabor?source=rss-3190c898b40f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:25:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jordanIrabor/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Music — free method of self-refuel.]]></title>
            <link>https://medium.com/@jordanIrabor/music-free-method-of-self-refuel-f8a6bc16fb04?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8a6bc16fb04</guid>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[poem]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[músic]]></category>
            <category><![CDATA[deep]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Sun, 05 May 2019 17:06:17 GMT</pubDate>
            <atom:updated>2019-05-05T19:39:26.162Z</atom:updated>
            <content:encoded><![CDATA[<h3>Music — free method of self-refuel.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*raY3leU6foOsW76dzkGROA.jpeg" /></figure><p>Music is food for the soul,</p><p>Truly hungry souls may eat a lot.</p><p>Food can only be digested while the heart beats,</p><p>Be sure to try out a variety of meals (genres),</p><p>Expand your appetite then devour as you please.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8a6bc16fb04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A torch, a cardigan and an empty bucket of life.]]></title>
            <link>https://medium.com/@jordanIrabor/a-torch-a-cardigan-and-an-empty-bucket-of-life-ffae5e1b5668?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffae5e1b5668</guid>
            <category><![CDATA[life]]></category>
            <category><![CDATA[darkness]]></category>
            <category><![CDATA[poem]]></category>
            <category><![CDATA[melancholy]]></category>
            <category><![CDATA[poetry]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Thu, 02 May 2019 08:35:45 GMT</pubDate>
            <atom:updated>2019-05-02T11:47:29.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/849/0*5fZIs9WedHGJBEDR.jpg" /></figure><h3>A torch, a cardigan and a depleting bucket of life.</h3><p><em>Be wise, let this torch be your companion in the darkness of tonight,</em></p><p><em>The waters of time will remain still without a paddle to sway.</em></p><p><em>Crawl on your knees if the passage reeks with stagnation and fright,</em></p><p><em>The night arrives hastily and promises a world that is grey.</em></p><p><em>There is unforeseen darkness that absorbs our sight,</em></p><p><em>It feeds on our fear and leaves a hideous crease.</em></p><p><em>Darkness has smitten his enemies with the assistance of daylight,</em></p><p><em>He rules over the deceased and spreads a threatening disease.</em></p><p><em>Hope is a particle of light in the wreckage of uncertainty,</em></p><p><em>An optimistic dance of faith in the absence of redemption.</em></p><p><em>We exchange bits of life for a solution to this catastrophe,</em></p><p><em>We are our own medicines in an experiment of eternal damnation.</em></p><p><em>Even when our homes are shaped like a one-sided tunnel,</em></p><p><em>We must sneak love in and nurture it until it blossoms.</em></p><p><em>Your thoughts of a better life have birthed a rebel,</em></p><p><em>The pureness of our love will define the basis for all fathoms.</em></p><p><em>Soft hair that tickles at the gentleness of daylight,</em></p><p><em>You are the unexplored body of water I hope to be bathed in.</em></p><p><em>As a young phoenix is excited for the joys of death and flight,</em></p><p><em>I want to be lost in your pure and undiluted beauty.</em></p><p><em>Take this torch and let it be your guide on this dim journey.</em></p><p><em>A cardigan will protect you from the snatching arms of the frost,</em></p><p><em>The farther you travel, the louder the drums of melancholy,</em></p><p><em>What was once a bucket of optimism is fading into a worthless bag of dust.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffae5e1b5668" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-Time Smart Facebook Messenger Bot With No Code.]]></title>
            <link>https://medium.com/@jordanIrabor/real-time-smart-facebook-messenger-bot-with-no-code-31d289bff011?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/31d289bff011</guid>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[messenger]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Sun, 17 Jun 2018 23:22:23 GMT</pubDate>
            <atom:updated>2018-06-17T23:22:23.556Z</atom:updated>
            <content:encoded><![CDATA[<p>In the past, building a regular bot would require large blocks of code and careful structuring of the logic that would drive the entire process. Today, developing simple and fairly complex bots can be achieved pretty easily, even without writing a single line of code; thanks to the technology that is available to us.</p><p>By the end of this article, we would have built a smart Facebook Messanger bot that is able to process messages sent to a Facebook page and respond appropriately in real time. We will not write a single line of code ( though we should if we intend to build a more complex bot ) for this implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*JMXt_OIW_FLe78J5.gif" /></figure><blockquote><em>While this article promises that zero code is required to follow along, the article also assumes very basic knowledge working with the Facebook developer platform and DialogFlow ( formerly Api.ai ).</em></blockquote><p>Let’s create our own Facebook bot in just four steps:</p><ol><li>Create An Agent</li><li>Integrating Facebook Messenger</li><li>Configuring Facebook Messenger</li><li>Testing the Facebook Messenger Bot</li></ol><h3>Create An Agent:</h3><p>First, let’s visit DialogFlow ( formerly Api.ai ) and sign in with a Google account. Immediately after that, we will be redirected to the ‘Get Started’ Page with an option to create a new agent. Click on the ‘Create Agent’ option to the left of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*p8I79C71E8J6V5oW.png" /></figure><p>Next, let’s fill out the form that is presented to us. For the sake of this article, we will call the agent smallTalkBot ( Well, why not? ). After the necessary fields are filled, click on the &#39;Save&#39; button.</p><blockquote><em>There really is no need to specify the </em><em>ADD SAMPLE DATA field as we intend to create an empty agent.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*XyF6psyfC_6lOgB7.png" /></figure><p>On the new page, there will be a scrollable section to the left, we’ll scroll down a bit so we can find the option that says ‘Small Talk’, click on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*qKJZE6Lh1fq6Kt3E.png" /></figure><p>Great, now we are on the Small Talk dashboard and this is where most of the logic will be done so let&#39;s begin by enabling the Small Talk feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*qGenc6V5IguV9ZAe.png" /></figure><p>On the Small Talk dashboard, we can train our agent on how to engage in small conversations and respond adequately depending on the messages it receives. Let&#39;s begin by teaching the agent how to respond to questions under the About Agent category.</p><blockquote>Protip:<em> A great way to make the agent ( bot ) seem smarter is by entering several answer variants, it will help the agent respond differently to similar questions.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*oJXSRm2-__S1YHj7.png" /></figure><p>Though you don’t have to fill in everything, for the sake of this article we will provide answers to all the suggested questions in the small talk dashboard. Click on the Save option when you are done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*xjTAvZVmNsMsVSLA.png" /></figure><p>Awesome stuff! We have completed the first step.</p><h3>Integrating Facebook Messenger</h3><p>On the left section of the agent’s dashboard, there is an option that says Integrations, click on it. Great, now we have a page body that says One-click integrations.The page also has lots of integration options, let&#39;s modify the settings for the &#39;Facebook Messenger&#39; integration by clicking on the &#39;SETTINGS&#39; just below the icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*LNMBydL_sAD98uyk.png" /></figure><p>We get a pop up with three fields, we need to enable the Facebook Messenger integration before we can start filling in the fields, so let’s do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*rtYWJUFRUJ3Okme4.png" /></figure><p>The three fields are:</p><blockquote><em>Callback URL - This is the URL facebook will be sending data to whenever our page gets a message.</em></blockquote><blockquote><em>Verify Token - We need to specify a custom token here ( we&#39;ll specify the same token on Facebook when we create our app, so write a token you can remember ).</em></blockquote><blockquote><em>Page Access Token- This token will be given to us by Facebook after we create an app.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*oU7tcGwqbpNMfjlb.png" /></figure><p>At this point, we cannot continue setting up the integration until we create the Facebook app that will be linked to the smallTalkBot. The reason is that we need the Page Access Token to proceed. Let&#39;s head over to the <a href="https://developers.facebook.com/">Facebook for developers platform</a> ( in a new tab ) and create an app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*__4A6UgsMyRoJCCs.png" /></figure><p>Now that we are here, let’s fill in the details for a new Facebook app. Immediately that is done, we’ll automatically be redirected to the app’s dashboard. The screen also says Select A Product so let&#39;s select the messenger option and click on Set up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*8VDNb-MdSXWh1_0g.png" /></figure><p>Now, we scroll down a bit till we get to the Token Generation section. We need to select a page for our app and generate a token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*xrKp_n2o2Xlm1ZNI.png" /></figure><p>The generated token is the reason we came here, let’s briefly go back to DialogFlow (in the other tab) and do three simple things:</p><ol><li>Paste the token from Facebook in the Page Access Token field.</li><li>Copy the Callback URL ( Facebook needs this URL so it knows where to send data to )</li><li>Click on the Start Option to run our bot!</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*mKBlVRXfYWKaBaut.png" /></figure><p>Hooray! Our bot is running now but let’s not rejoice just yet, we need to do a bit more before we can start exchanging crazy texts with our creation over Facebook.</p><h3>Configuring Facebook Messenger</h3><p>Now, back on the Facebook Messenger Platform, just below where we generated the token for DialogFlow, there is a section that says Webhooks. Click on the Setup Webhooks Option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*JY2QeoyZHpnE-5G_.png" /></figure><p>Great work! Now there is a pop up with two fields and several checkboxes in our face, let’s fill in the fields with the right data:</p><ol><li>Callback URL - This is quite obvious, remember the Callback URL we copied from DialogFlow? Paste it in here.</li><li>Verify Token - Here, let&#39;s enter the same custom Verify Token we entered for DialogFlow. In my case, it&#39;s VERIFY_ME_HERE.</li><li>The checkboxes — We can ignore most of the checkboxes, we only need to subscribe to two events so let’s check messages &amp; messaging_postbacks.</li></ol><p>Great! Now click on Verify and Save and we are good to go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*U-013WhxzBVBtQ5s.png" /></figure><p>Congratulations, we have set the bot up successfully.</p><h3>Testing the Facebook Messenger Bot</h3><p>To test the bot, simply message the linked Facebook page and wait for the lightning response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*FbY7tM6KVcbHAuBU.gif" /></figure><h3>Conclusion</h3><p>As promised in the beginning of this article, we have successfully built a ( seemingly smart and sarcastic ) bot that is able to respond to messages sent to a Facebook page based on the intent ( This is mostly NLP technology ) of the text it receives. As you test your bot out, you will realise that it isn’t as smart as it appears and the reason is; it only responds to messages using the predefined texts we supplied when we created smallTalkBot.</p><p>Working with the Small Talk feature DialogFlow provides is just an atom of the awesome things that can be done with DialogFlow, for instance, you can train your bot to respond more accurately to the messages it receives!</p><p>While we haven’t fully explored the complexity of DialogFlow, you can read the docs <a href="https://dialogflow.com/docs/getting-started/basics">here</a> if you wish to build an awesome bot that doesn&#39;t give the same responses all the time.</p><p><em>Originally published at </em><a href="https://dev.to/jordanirabor/building-a-real-time-smart-facebook-messenger-bot-with-no-code-832"><em>dev.to</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31d289bff011" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a scientific calculator using Vuejs]]></title>
            <link>https://medium.com/@jordanIrabor/build-a-scientific-calculator-using-vuejs-87f770a3a2f1?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/87f770a3a2f1</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[calculator]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Fri, 25 May 2018 17:04:26 GMT</pubDate>
            <atom:updated>2018-05-25T17:04:26.218Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>This article teaches how to build a scientific calculator using VueJS.</p><p>Here’s a visual display of end result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/0*DMn5DcPn3dqoCP0V.gif" /></figure><p>The source code for this article is available here on <a href="https://github.com/Jordanirabor/Scientific-Calculator-With-VueJS">Github</a></p><p>Let’s get started.</p><h3>Setup VueJS</h3><p>For the sake of this tutorial, we will be using the Vue CLI for installation and setup, an alternative would be to reference Vue from a CDN</p><pre>https://unpkg.com/vue</pre><p>We can install the Vue CLI with this command:</p><pre>$ npm install --global vue-cli</pre><p>Next, let’s create a new project:</p><pre>$ vue init webpack-simple vueCalulator</pre><p>After responding to a few terminal prompts, we would have set everything up.</p><p>Let’s navigate into the working directory, install dependencies and start our application:</p><pre>$ cd vueCalulator <br>$ npm install <br>$ npm run dev</pre><h3>Defining The Vue Components</h3><p>Since we are building a calculator with two modes [ Basic and Advanced ], let’s define two components to represent each one.</p><p>First, let’s create a components folder in the src directory [ it&#39;s not necessary to do this but I like keeping a clean working directory ].</p><p>Next, we create two new Vue files in the components directory. We will call these files:</p><p>The logic behind the different modes of this calculator is:</p><blockquote><em>The root component [ App.vue ] will hold the input field while the </em><em>Basic and </em><em>Advanced components will be toggled within the space beneath the input field.</em></blockquote><p>Now let’s get down to business!</p><h3>Build the Basic component</h3><p>Let’s write the template, data, and methods that will reside within the Basic component.</p><p>The Basic template will hold calculator buttons that listen for click events on any of the buttons</p><pre>&lt;template&gt;</pre><pre>&lt;div @<em>click</em>=&quot;buttonClick&quot;&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;7&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;8&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;9&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;/&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;&amp;larr;&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;C&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;4&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;5&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;6&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;*&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt; ( &lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt; ) &lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;1&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;2&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;3&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;-&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;x²&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;±&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;0&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;.&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;%&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;+&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>equals btn btn-primary</em>&quot;&gt;=&lt;/button&gt;</pre><pre>&lt;/div&gt;<br></pre><pre>&lt;/template&gt;</pre><p>We can see that the buttons are wrapped within a root div tag that calls a buttonClick method whenever a button is click.</p><p>Next, let’s export and define the methods within our Basic component, we simply do this by writing a script tag:</p><pre>&lt;script&gt;</pre><pre><em>export</em> <em>default</em> {</pre><pre>data () {</pre><pre><em>return</em> {}</pre><pre>},</pre><pre><em>methods</em>: {</pre><pre><em>buttonClick</em>: <em>function</em>(<em>e</em>){</pre><pre><em>let</em> value = e.target.innerText;</pre><pre><em>this</em>.$emit(&#39;<em>addNumber</em>&#39;, value)</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>&lt;/script&gt;</pre><p>In this script tag, we have not defined any data [ we don’t need any on this component ], we have defined a single buttonClick method that catches click events, gets the innerText value and emits an event to the root component.</p><p>We need this method so that the root component can act on the buttons that are clicked when the calculator is in Basic mode.</p><h3>Build the Advanced component</h3><p>The Advanced component is very much like the Basic component in structure and logic.</p><p>First, let’s write the template that will hold Advanced calculator buttons and listen for click events on any of the buttons.</p><pre>&lt;template&gt;</pre><pre>&lt;div @<em>click</em>=&quot;buttonClick&quot;&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;sin&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;cos&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;tan&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;x^&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;&amp;larr;&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;C&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;log&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;ln&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;e&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;∘&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;rad&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;√&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;7&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;8&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;9&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;/&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;x²&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;x!&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;4&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;5&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;6&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;*&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;(&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;)&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;1&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;2&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;3&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;-&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;%&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;+&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;±&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;0&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;.&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;&amp;#x003C0;&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary</em>&quot;&gt;+&lt;/button&gt;</pre><pre>&lt;button <em>class</em>=&quot;<em>btn btn-primary equals</em>&quot;&gt;=&lt;/button&gt;</pre><pre>&lt;/div&gt;<br></pre><pre>&lt;/template&gt;</pre><p>Similar to the Basic component, we will not be defining any data within the data object, we will also emit an event to the root component whenever a button is clicked.</p><pre>&lt;script&gt;</pre><pre><em>export</em> <em>default</em> {</pre><pre><em>name</em>: &#39;<em>Advanced</em>&#39;,</pre><pre>data () {</pre><pre><em>return</em> {}</pre><pre>},</pre><pre><em>methods</em>: {</pre><pre><em>buttonClick</em>: <em>function</em>(<em>e</em>){</pre><pre><em>let</em> value = e.target.innerHTML;</pre><pre><em>this</em>.$emit(&#39;<em>addNumber</em>&#39;, value)</pre><pre>}</pre><pre>}</pre><pre>}<br></pre><pre>&lt;/script&gt;</pre><p>We can see that the buttonClickmethod in the Advanced component is exactly like the one in the Basic component.</p><h3>Let’s dig into the root component!</h3><p>Lastly, let’s connect the entire application together via the root component [ App.vue ].</p><p>The code structure for the root component is pretty straightforward.</p><p>Just as we did with the two children components, we need to define the template that will hold the input field and house the toggling of the other two components [ the children components mostly contain buttons for the calculator ].</p><p>The root template will have:</p><ol><li>A mechanism to toggle between advanced and basic modes [using v-show]</li></ol><p>2. An input field to display the punched digits</p><p>3. A housing tag for the children components [in this case, it is a div tag with a class called buttons’]</p><p>Here’s a visual display of the template code:</p><pre>&lt;template&gt;</pre><pre>&lt;div <em>id</em>=&quot;<em>this</em>&quot;&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>container box</em>&quot;&gt;</pre><pre>&lt;p&gt; {{ mode }} &lt;/p&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>row input-data</em>&quot;&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>col-lg-12</em>&quot;&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>input-group</em>&quot;&gt;</pre><pre>&lt;span <em>class</em>=&quot;<em>input-group-addon</em>&quot;&gt; &lt;input <em>class</em>=&quot;<em>input-data</em>&quot; @<em>click</em>=&quot;changeToggle&quot; <em>type</em>=&quot;<em>checkbox</em>&quot; <em>aria-label</em>=&quot;<em>Checkbox for following text input</em>&quot;&gt; &lt;/span&gt;</pre><pre>&lt;input <em>type</em>=&quot;<em>text</em>&quot; <em>class</em>=&quot;<em>form-control text-right</em>&quot; <em>v-model</em>=&quot;current&quot; <em>aria-label</em>=&quot;<em>Text input with checkbox</em>&quot; <em>disabled</em>&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;hr&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>buttons</em>&quot;&gt;</pre><pre>&lt;Basic <em>v-show</em>=&quot;!toggle&quot; <em>v-bind</em>:<em>current</em>=&quot;current&quot; @<em>addNumber</em>=&quot;doStuff($event)&quot;&gt;&lt;/Basic&gt;</pre><pre>&lt;Advanced <em>v-show</em>=&quot;toggle&quot;  <em>v-bind</em>:<em>current</em>=&quot;current&quot; @<em>addNumber</em>=&quot;doStuff($event)&quot;&gt;&lt;/Advanced&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;<br></pre><pre>&lt;/template&gt;</pre><p>From this code, we can see that the Basic and Advanced components are nested within a div tag [with the class ‘buttons’].</p><p>The root component registers an event listener to capture and act upon the emitted events by the children components.</p><p>Let’s see how things are handled within the script section in the root component[:</p><pre>&lt;template&gt;</pre><pre>&lt;div <em>id</em>=&quot;<em>this</em>&quot;&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>container box</em>&quot;&gt;</pre><pre>&lt;p&gt; {{ mode }} &lt;/p&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>row input-data</em>&quot;&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>col-lg-12</em>&quot;&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>input-group</em>&quot;&gt;</pre><pre>&lt;span <em>class</em>=&quot;<em>input-group-addon</em>&quot;&gt; &lt;input <em>class</em>=&quot;<em>input-data</em>&quot; @<em>click</em>=&quot;changeToggle&quot; <em>type</em>=&quot;<em>checkbox</em>&quot; <em>aria-label</em>=&quot;<em>Checkbox for following text input</em>&quot;&gt; &lt;/span&gt;</pre><pre>&lt;input <em>type</em>=&quot;<em>text</em>&quot; <em>class</em>=&quot;<em>form-control text-right</em>&quot; <em>v-model</em>=&quot;current&quot; <em>aria-label</em>=&quot;<em>Text input with checkbox</em>&quot; <em>disabled</em>&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;hr&gt;</pre><pre>&lt;div <em>class</em>=&quot;<em>buttons</em>&quot;&gt;</pre><pre>&lt;Basic <em>v-show</em>=&quot;!toggle&quot; <em>v-bind</em>:<em>current</em>=&quot;current&quot; @<em>addNumber</em>=&quot;doStuff($event)&quot;&gt;&lt;/Basic&gt;</pre><pre>&lt;Advanced <em>v-show</em>=&quot;toggle&quot;  <em>v-bind</em>:<em>current</em>=&quot;current&quot; @<em>addNumber</em>=&quot;doStuff($event)&quot;&gt;&lt;/Advanced&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;script&gt;</pre><pre><em>import</em> <em>Basic</em> <em>from</em> &#39;<em>./components/Basic</em>&#39;;</pre><pre><em>import</em> <em>Advanced</em> <em>from</em> &#39;<em>./components/Advanced</em>&#39;;</pre><pre><em>export</em> <em>default</em> {</pre><pre><em>name</em>: &#39;<em>Calculator</em>&#39;,</pre><pre><em>components</em>: {</pre><pre>&#39;<em>Basic</em>&#39;<em> </em>: Basic,</pre><pre>&#39;<em>Advanced</em>&#39;<em> </em>: Advanced</pre><pre>},</pre><pre>data () {</pre><pre><em>return</em> {</pre><pre><em>current</em>: 0,</pre><pre><em>toggle</em>: <em>false</em>,</pre><pre><em>mode</em>: &#39;<em>Basic</em>&#39;</pre><pre>}</pre><pre>},</pre><pre><em>methods</em>: {</pre><pre><em>changeToggle</em>: <em>function</em>(){</pre><pre><em>this</em>.toggle = !<em>this</em>.toggle;</pre><pre><em>if</em> (<em>this</em>.mode == &#39;<em>Basic</em>&#39;){</pre><pre><em>this</em>.mode = &#39;<em>Advanced</em>&#39;</pre><pre>} <em>else</em> {</pre><pre><em>this</em>.mode = &#39;<em>Basic</em>&#39;</pre><pre>}</pre><pre>},</pre><pre><em>doStuff</em>: <em>function</em>(<em>data</em>){</pre><pre><em>let</em> temp;</pre><pre><em>if</em>(Number(data) || data == 0){</pre><pre>temp =  data</pre><pre><em>if</em>( <em>this</em>.current === 0 ) <em>this</em>.current = &quot;&quot;;</pre><pre><em>this</em>.current += &quot;&quot; + temp;</pre><pre>}</pre><pre><em>if</em>( !Number(data) ) {</pre><pre><em>switch</em> ( data ) {</pre><pre><em>case</em> &quot;<em>/</em>&quot; : {</pre><pre><em>this</em>.divide();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>←</em>&quot; : {</pre><pre><em>this</em>.backspace();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>C</em>&quot; : {</pre><pre><em>this</em>.clear();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>*</em>&quot; : {</pre><pre><em>this</em>.multiply();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>-</em>&quot; : {</pre><pre><em>this</em>.minus();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>+</em>&quot; : {</pre><pre><em>this</em>.plus();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>x²</em>&quot; : {</pre><pre><em>this</em>.square();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>(</em>&quot; : {</pre><pre><em>this</em>.openbracket();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>)</em>&quot; : {</pre><pre><em>this</em>.closebracket();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>=</em>&quot; : {</pre><pre><em>this</em>.equals();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>±</em>&quot; : {</pre><pre><em>this</em>.plusMinus();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>%</em>&quot; : {</pre><pre><em>this</em>.percent();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>.</em>&quot; : {</pre><pre><em>this</em>.decimal();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>sin</em>&quot; : {</pre><pre><em>this</em>.sin();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>cos</em>&quot; : {</pre><pre><em>this</em>.cos();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>tan</em>&quot; : {</pre><pre><em>this</em>.tan();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>ln</em>&quot; : {</pre><pre><em>this</em>.ln();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>e</em>&quot; : {</pre><pre><em>this</em>.exp();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>∘</em>&quot; : {</pre><pre><em>this</em>.degrees();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>x!</em>&quot; : {</pre><pre><em>this</em>.factorial();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>rad</em>&quot; : {</pre><pre><em>this</em>.radians();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>√</em>&quot; : {</pre><pre><em>this</em>.squareRoot();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>x^</em>&quot; : {</pre><pre><em>this</em>.exponent();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>π</em>&quot; : {</pre><pre><em>this</em>.pi();</pre><pre><em>break</em>;</pre><pre>}</pre><pre><em>case</em> &quot;<em>log</em>&quot; : {</pre><pre><em>this</em>.log();</pre><pre><em>break</em>;</pre><pre>}<br></pre><pre>}</pre><pre>}</pre><pre>},<br></pre><pre><em>clear</em>: <em>function</em>() {</pre><pre><em>this</em>.current = 0;</pre><pre>},</pre><pre><em>backspace</em>: <em>function</em>() {</pre><pre><em>this</em>.current = <em>this</em>.current.substring(0, <em>this</em>.current.length - 1);</pre><pre>},</pre><pre><em>multiply</em>: <em>function</em>() {</pre><pre><em>this</em>.current += &quot;<em>*</em>&quot;;</pre><pre>},</pre><pre><em>divide</em>: <em>function</em>() {</pre><pre><em>this</em>.current +=  &quot;<em>/</em>&quot;;</pre><pre>},</pre><pre><em>openbracket</em>: <em>function</em>() {</pre><pre><em>this</em>.current +=  &quot;<em>(</em>&quot;;</pre><pre>},</pre><pre><em>closebracket</em>: <em>function</em>() {</pre><pre><em>this</em>.current +=  &quot;<em>)</em>&quot;;</pre><pre>},</pre><pre><em>plus</em>: <em>function</em>() {</pre><pre><em>this</em>.current +=  &quot;<em>+</em>&quot;;</pre><pre>},<br></pre><pre><em>minus</em>: <em>function</em>() {</pre><pre><em>this</em>.current +=  &quot;<em>-</em>&quot;;</pre><pre>},<br></pre><pre><em>decimal</em>: <em>function</em>() {</pre><pre><em>this</em>.current +=  &quot;<em>.</em>&quot;;</pre><pre>},<br></pre><pre><em>plusMinus</em>: <em>function</em>() {</pre><pre><em>if</em> ( (<em>this</em>.current !== 0) &amp;&amp; <em>this</em>.current.charAt(0) === &quot;<em>-</em>&quot; )  {</pre><pre><em>this</em>.current = <em>this</em>.current.slice(1);</pre><pre>} <em>else</em> {</pre><pre><em>this</em>.current = &quot;<em>-</em>&quot; + <em>this</em>.current;</pre><pre>}</pre><pre>},</pre><pre><em>equals</em>: <em>function</em>() {</pre><pre><em>if</em> ((<em>this</em>.current).indexOf(&quot;<em>^</em>&quot;) <em>&gt;</em> -1) {</pre><pre><em>var</em> base = (<em>this</em>.current).slice(0, (<em>this</em>.current).indexOf(&quot;<em>^</em>&quot;));</pre><pre><em>var</em> exponent = (<em>this</em>.current).slice((<em>this</em>.current).indexOf(&quot;<em>^</em>&quot;) + 1);</pre><pre><em>this</em>.current = eval(&quot;<em>Math.pow(</em>&quot; + base + &quot;<em>,</em>&quot; + exponent + &quot;<em>)</em>&quot;);</pre><pre>} <em>else</em> {</pre><pre><em>this</em>.current = eval(<em>this</em>.current);</pre><pre>}</pre><pre>},</pre><pre><em>factorial</em>: <em>function</em> () {</pre><pre><em>var</em> number = 1;</pre><pre><em>if</em> (<em>this</em>.current === 0) {</pre><pre><em>this</em>.current = &quot;<em>1</em>&quot;;</pre><pre>} <em>else</em> <em>if</em> (<em>this</em>.current <em>&lt;</em> 0) {</pre><pre><em>this</em>.current = <em>NaN</em>;</pre><pre>} <em>else</em> {</pre><pre><em>var</em> number = 1;</pre><pre><em>for</em> (<em>var</em> i = <em>this</em>.current; i <em>&gt;</em> 0; i<em>--</em>) {</pre><pre>number *=  i;</pre><pre>}</pre><pre><em>this</em>.current = number;</pre><pre>}</pre><pre>},</pre><pre><em>pi</em>: <em>function</em>() {</pre><pre><em>this</em>.current = (<em>this</em>.current * <em>Math</em>.PI);</pre><pre>},</pre><pre><em>square</em>: <em>function</em>() {</pre><pre><em>this</em>.current = (<em>this</em>.current * <em>this</em>.current);</pre><pre>},</pre><pre><em>squareRoot</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>Math</em>.sqrt(<em>this</em>.current);</pre><pre>},</pre><pre><em>percent</em>: <em>function</em>() {</pre><pre><em>this</em>.current = <em>this</em>.current / 100;</pre><pre>},</pre><pre><em>sin</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>Math</em>.sin(<em>this</em>.current);</pre><pre>},</pre><pre><em>cos</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>Math</em>.cos(<em>this</em>.current);</pre><pre>},</pre><pre><em>tan</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>Math</em>.tan(<em>this</em>.current);</pre><pre>},</pre><pre><em>log</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>Math</em>.log10(<em>this</em>.current);</pre><pre>},</pre><pre><em>ln</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>Math</em>.log(<em>this</em>.current);</pre><pre>},</pre><pre><em>exponent</em>: <em>function</em> () {</pre><pre><em>this</em>.current += &quot;<em>^</em>&quot;;</pre><pre>},</pre><pre><em>exp</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>Math</em>.exp(<em>this</em>.current);</pre><pre>},</pre><pre><em>radians</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>this</em>.current * (<em>Math</em>.PI / 180);</pre><pre>},<br></pre><pre><em>degrees</em>: <em>function</em> () {</pre><pre><em>this</em>.current = <em>this</em>.current * (180 / <em>Math</em>.PI);</pre><pre>}</pre><pre>}</pre><pre>}<br></pre><pre>&lt;/script&gt;</pre><p>First, we import the basic and advanced components into the root component because we need to reference them.</p><p>Next, we declare the name of the application and create a components object (this is where we register the components).</p><p>In the data section, we register three key/value pair:</p><ol><li>current — This keeps track of the current input value</li><li>toggle — This stores the current toggle value</li><li>mode — This stores the current mode</li></ol><p>Next, we register a few methods :</p><p>The changeToggle is responsible for toggling between the Basic and Advanced mode and also updating the value of mode.</p><p>The doStuff method handles the events that are emitted by the children components. It receives a data parameter and pipes it through several cases. When a case is matched, it calls the right function to handle the mathematical calculations.</p><p>For this application to run correctly, there are a lot more mathematical functions defined, though they are not included in the snapshot.</p><h3>Conclusion</h3><p>Awesome! 🔥 That is all it takes to build a scientific calculator with VueJS.</p><p>To run this project locally, type in the following commands in a terminal.</p><pre>-- clone the repository<br>git clone https://github.com/Jordanirabor/Scientific-Calculator-With-VueJS<br><br>-- navigate into the directory --<br>cd Scientific-Calculator-With-VueJS<br><br>-- install dependencies --<br>npm install<br><br>-- serve with hot reload at localhost:8080 --<br>npm run dev<br><br>-- build for production with minification --<br>npm run build</pre><p>The end!</p><p><em>Originally published at </em><a href="https://dev.to/jordanirabor/scientific-calculator-with-vuejs--day-1--30-days-of-code--c3j"><em>dev.to</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87f770a3a2f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Dynamic Breadcrumbs In Laravel]]></title>
            <link>https://medium.com/@jordanIrabor/building-dynamic-breadcrumbs-in-laravel-f6bf1eb23a7d?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6bf1eb23a7d</guid>
            <category><![CDATA[breadcrumbs]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Sat, 19 May 2018 20:23:53 GMT</pubDate>
            <atom:updated>2019-02-10T15:40:15.100Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*yRB3dLkPf_tQfkNp.jpg" /></figure><h3>The Importance of Breadcrumbs</h3><p>In the past, web developers were more concerned with the functions (back-end) and information web applications could deliver and didn’t pay as much attention to the visual appearance (front-end) of web pages. This wasn’t entirely their fault, there weren’t fitting technology to develop complex web page designs at that time. The few ones that could do a bit of magic were a hassle to use.</p><p>Today, it’s a whole different story; the UI/UX design stage in web development is just as important as the pre-planning of the backend logic that keeps everything running. There lie a wide spectrum of acceptable design practices that can help a web application earn the “user-friendly” tag, but there are even more design flaws that everyone should watch out for.</p><p>People hate getting unsolicited pop-up boxes in their faces; I do too, but pop-ups aren’t the only things that can grind the user’s gears. The inability to locate one’s self and navigate easily on a website is as bad as getting lost in a big mall; the same feeling of overwhelmingness.</p><p>While that could be a serious problem, it doesn’t have to be! Breadcrumbs can be the easiest solution to giving users the smooth web navigation experience they deserve.</p><blockquote><em>Breadcrumbs provide a navigation system to help users know their current location in relation to other web pages on a website. The name breadcrumbs is derived from the well-known fairy tale </em><a href="https://en.wikipedia.org/wiki/Hansel_and_Gretel"><em>Hansel and Grettel</em></a><em> because it does pretty much the same thing; leaves a trail behind to prevent users from getting lost hence promoting user experience. Breadcrumbs on a website will also reduce the number of actions a user has to trigger to reach a page of choice.</em></blockquote><p>Setting up breadcrumbs in Laravel is quite simple. There is a package that takes care of most of the logic, and we will be looking at how to use this package and get the best features out of it.</p><p>The source code for this tutorial is available <a href="https://github.com/Jordanirabor/Laravel-Breadcrumbs">here</a> on GitHub.</p><h3>Setting up the Laravel application</h3><p>This entire tutorial is targeted at Laravel developers.</p><p>We will be pulling in the <a href="https://github.com/davejamesmiller/laravel-breadcrumbs">Laravel Breadcrumbs</a> package via Composer and writing code to render breadcrumb navigation services dynamically, depending on what page the user is viewing.</p><p>The resulting code for this article is available <a href="https://github.com/Jordanirabor/Laravel-Breadcrumbs">here</a> on GitHub.</p><p>For the sake of this article, we will be installing a fresh instance of a Laravel application.</p><pre>laravel new breadcrumbs</pre><p>OR</p><pre>composer create-project --prefer-dist laravel/laravel breadcrumbs</pre><p>Next, we pull in the <a href="https://github.com/davejamesmiller/laravel-breadcrumbs">Laravel Breadcrumbs</a> package by typing the command below in the terminal.</p><pre>composer require davejamesmiller/laravel-breadcrumbs</pre><h3>Creating the HTTP routing</h3><p>Let’s create some HTTP routes ( and name them as well ) in theroutes/web.php file — we will be referring to these routes by name in later parts of this article.</p><p>These are the routes needed for this example:</p><p><em>routes/web.php</em></p><pre>Route::get(&#39;/&#39;,  [&#39;as&#39; =&gt; &#39;home&#39;, &#39;uses&#39; =&gt; &#39;MainController@home&#39;]);<br><br>Route::get(&#39;/continent/{name}&#39;,  [&#39;as&#39; =&gt; &#39;continent&#39;, &#39;uses&#39; =&gt; &#39;MainController@continent&#39;]);<br><br>Route::get(&#39;/country/{name}&#39;,  [&#39;as&#39; =&gt; &#39;country&#39;, &#39;uses&#39; =&gt; &#39;MainController@country&#39;]);<br><br>Route::get(&#39;/city/{name}&#39;,  [&#39;as&#39; =&gt; &#39;city&#39;, &#39;uses&#39; =&gt; &#39;MainController@city&#39;]);</pre><p>To demonstate the power of Laravel Breadcrumbs, we will build a small application where we register continent, country and citiy models. We will also say that a continent hasMany countries and a country hasMany cities.</p><p>To create these models, we write these commands to the terminal:</p><pre>php artisan make:model Continent<br>php artisan make:model Country<br>php artisan make:model City</pre><p>Let’s also create the migration files for each of these models:</p><pre>php artisan make:migration continents<br>php artisan make:migration countries<br>php artisan make:migration cities</pre><p>Next, let’s define the relationship methods in each one of the model classes:</p><p><em>app/Continent.php</em></p><pre>namespace App;<br>use App\Country;<br><br>use Illuminate\Database\Eloquent\Model;<br><br>class Continent extends Model<br>{<br>    public function country(){<br>        return $this-&gt;hasMany(Country::class);<br>    }<br>}</pre><p><em>app/Country.php</em></p><pre>namespace App;<br><br>use App\City;<br>use App\Continent;<br><br>use Illuminate\Database\Eloquent\Model;<br><br>class Country extends Model<br>{<br><br>    protected $guarded = [];<br>    public function city(){<br>        return $this-&gt;hasMany(City::class);<br>    }<br><br>    public function continent(){<br>        return $this-&gt;belongsTo(Continent::class);<br>    }<br>}</pre><p><em>app/City.php</em></p><pre>namespace App;<br><br><br>use App\Country;<br><br>use Illuminate\Database\Eloquent\Model;<br><br>class City extends Model<br>{<br><br>    protected $guarded = [];<br>    public function country(){<br>        return $this-&gt;belongsTo(Country::class);<br>    }<br>}</pre><blockquote><em>Notice that </em><em>guarded is set to an empty array, this is because we intend to do some form of mass assignment when seeding the database. Whenever you make a change like this to a model file, always remember to revert the change before the application gets to production stage.</em></blockquote><p>Now let’s create a controller that will handle all the HTTP requests the application receives. We will call the controller MainController and will declare different actions (methods) to compact instances of models with the returning view, each view will display its own breadcrumb(s).</p><p>To create this controller, we write this command to the terminal:</p><pre>php artisan make:controller MainController</pre><p>Now let’s write the actions (methods) that will return views after handling the HTTP requests.</p><p><em>app/Http/Controllers/MainControllers.php</em></p><pre>namespace App\Http\Controllers;<br>use App\Continent;<br>use App\Country;<br>use App\City;<br>use Illuminate\Http\Request;<br><br>class MainController extends Controller<br>{<br>    public function home(){<br>        return view(&#39;home&#39;);<br>    }<br><br>     public function continent($name){<br>           $continent = Continent::where(&#39;name&#39;, $name)-&gt;first();<br>        return view(&#39;continent&#39;, compact(&#39;continent&#39;));<br>    }<br><br>     public function country($name){<br>           $country = Country::where(&#39;name&#39;, $name)-&gt;first();<br>        return view(&#39;country&#39;, compact(&#39;country&#39;));<br>    }<br><br>     public function city($name){<br>           $city = City::where(&#39;name&#39;, $name)-&gt;first();<br>        return view(&#39;city&#39;, compact(&#39;city&#39;));<br>    }<br>}</pre><p>We have included the relationships between models so we can explore the capabilities of the <a href="https://github.com/davejamesmiller/laravel-breadcrumbs">Laravel Breadcrumbs</a> package when it comes to dynamic linking and relational properties.</p><p>Now let’s create some views to match the models we just created. In the resources/views directory, we&#39;ll add four new files, we&#39;ll name them:</p><pre>home.blade.php<br>continent.blade.php<br>country.blade.php<br>city.blade.php</pre><p>Their names are quite intuitive; the first will hold the frontend code for the homepage, the second will hold the frontend code for the continent page, the third will hold the frontend code for the country page and the last will hold the frontend code for the city page.</p><p>Great, now let’s put some code in these new views:</p><p><em>resources/views/home.blade.php</em></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br><br>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css&quot; integrity=&quot;sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ&quot; crossorigin=&quot;anonymous&quot;&gt;<br><br> &lt;/head&gt;<br> &lt;body&gt;<br><br>{{ Breadcrumbs::render(&#39;home&#39;) }}<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><em>resources/views/continent.blade.php</em></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br><br>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css&quot; integrity=&quot;sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ&quot; crossorigin=&quot;anonymous&quot;&gt;<br><br> &lt;/head&gt;<br> &lt;body&gt;<br><br>{{ Breadcrumbs::render(&#39;continent&#39;, $continent) }}<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><em>resources/views/country.blade.php</em></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br><br>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css&quot; integrity=&quot;sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ&quot; crossorigin=&quot;anonymous&quot;&gt;<br><br> &lt;/head&gt;<br> &lt;body&gt;<br><br>{{ Breadcrumbs::render(&#39;country&#39;, $country-&gt;continent, $country) }}<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><em>resources/views/city.blade.php</em></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br><br>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css&quot; integrity=&quot;sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ&quot; crossorigin=&quot;anonymous&quot;&gt;<br><br> &lt;/head&gt;<br> &lt;body&gt;<br><br>{{ Breadcrumbs::render(&#39;city&#39;, $city-&gt;country-&gt;continent, $city-&gt;country, $city) }}<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>The Continent and Country models exhibit a One To Many relationship. Many cities belong to one country and many countries belong to one continent. A continent is the grandparent of a city while a country is the parent of a city. We won&#39;t be diving into the logic that binds Laravel relationships in this article but if you wish to learn about it, you can find good knowledge <a href="https://scotch.io/courses/laravel-eloquent-relationships/getting-started">here</a>.</p><p>Lastly, Let’s modify the migration files a bit so they define the proper structure for the tables in the database.</p><p><em>database/migrations/2017_11_02_092826_continents.php</em></p><pre>use Illuminate\Support\Facades\Schema;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Database\Migrations\Migration;<br><br>class Continents extends Migration<br>{<br>    /**<br>     * Run the migrations.<br>     *<br>     * @return void<br>     */<br>    public function up()<br>    {<br>        Schema::create(&#39;continents&#39;, function (Blueprint $table) {<br>            $table-&gt;increments(&#39;id&#39;);<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;timestamps();<br>        });<br>    }<br><br>    /**<br>     * Reverse the migrations.<br>     *<br>     * @return void<br>     */<br>    public function down()<br>    {<br>        //<br>    }<br>}</pre><p><em>database/migrations/2017_11_02_092835_countries.php</em></p><pre>use Illuminate\Support\Facades\Schema;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Database\Migrations\Migration;<br><br>class Countries extends Migration<br>{<br>    /**<br>     * Run the migrations.<br>     *<br>     * @return void<br>     */<br>    public function up()<br>    {<br>        Schema::create(&#39;countries&#39;, function (Blueprint $table) {<br>            $table-&gt;increments(&#39;id&#39;);<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;string(&#39;continent_id&#39;);<br>            $table-&gt;timestamps();<br>        });<br>    }<br><br>    /**<br>     * Reverse the migrations.<br>     *<br>     * @return void<br>     */<br>    public function down()<br>    {<br>        //<br>    }<br>}</pre><p><em>database/migrations/2017_11_02_092845_cities.php</em></p><pre>use Illuminate\Support\Facades\Schema;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Database\Migrations\Migration;<br><br>class Cities extends Migration<br>{<br>    /**<br>     * Run the migrations.<br>     *<br>     * @return void<br>     */<br>    public function up()<br>    {<br>        Schema::create(&#39;cities&#39;, function (Blueprint $table) {<br>            $table-&gt;increments(&#39;id&#39;);<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;string(&#39;country_id&#39;);<br>            $table-&gt;timestamps();<br>        });<br>    }<br><br>    /**<br>     * Reverse the migrations.<br>     *<br>     * @return void<br>     */<br>    public function down()<br>    {<br>        //<br>    }<br>}</pre><p>We can run the migrations with this command on the terminal:</p><pre>php artisan migrate</pre><p>Let’s insert some data into the database so we can test this application. To do this, we’d create three factory files [ one for each model ] and update the run method of the [ already existing ] DatabaseSeeder.php file in the database/seeds directory.</p><p>To create the factory files, we’d write these commands to the terminal:</p><pre>php artisan make:factory ContinentFactory --model=Continent<br>php artisan make:factory CountryFactory --model=Country<br>php artisan make:factory CityFactory --model=City</pre><p>The commands above will create these files respectively:</p><p><em>database/factories/ContinentFactory.php</em></p><pre>use Faker\Generator as Faker;<br><br>$factory-&gt;define(App\Continent::class, function (Faker $faker) {<br>    return [<br>        //<br>    ];<br>});</pre><p><em>database/factories/CountryFactory.php</em></p><pre>use Faker\Generator as Faker;<br><br>$factory-&gt;define(App\Country::class, function (Faker $faker) {<br>    return [<br>        //<br>    ];<br>});</pre><p><em>database/factories/CityFactory.php</em></p><pre>use Faker\Generator as Faker;<br><br>$factory-&gt;define(App\City::class, function (Faker $faker) {<br>    return [<br>        //<br>    ];<br>});</pre><p>Lastly, let’s update the DatabaseSeeder.php file that ships with every fresh instance of a Laravel application. We&#39;ll use this file to insert three rows into the database, we&#39;ll insert Africa [ of the continent model], South Africa [ of the country model ] and Johannesburg[ of the city model ], we&#39;ll also specify their relationships :</p><pre>use Illuminate\Database\Seeder;<br><br>class DatabaseSeeder extends Seeder<br>{<br>    /**<br>     * Run the database seeds.<br>     *<br>     * @return void<br>     */<br>    public function run()<br>    {<br><br>      factory(App\City::class)-&gt;create([<br>        &#39;name&#39; =&gt; &#39;Johannesburg&#39;,<br>        &#39;country_id&#39; =&gt; function(){<br><br>            return factory(App\Country::class)-&gt;create([<br>                &#39;name&#39; =&gt; &#39;South Africa&#39;,<br>                &#39;continent_id&#39; =&gt; function(){<br><br>                    return factory(App\Continent::class)-&gt;create([<br>                        &#39;name&#39; =&gt; &#39;Africa&#39; ])-&gt;id;<br>                }<br>                ])-&gt;id;<br>        }<br>        ]);<br>    }<br>}</pre><p>We can seed the database with this command to the terminal:</p><pre>php artisan db:seed --class=DatabaseSeeder</pre><h3>Setting up the breadcrumbs file</h3><p>We need to create a breadcrumbs.php file in the routes directory. This file will be referenced whenever a breadcrumb is rendered because it instructs Laravel on how to process the breadcrumb information. Without this file, Laravel will squawk an error in our faces whenever it encounters a call to a breadcrumb function in the views.</p><p>The first breadcrumb function we will be defining in our newly created breadcrumbs.php file is the one for our homepage. The &#39;home&#39; breadcrumb will be loaded whenever the route named &#39;home&#39; is visited.</p><p><em>routes/breadcrumbs.php</em></p><pre>Breadcrumbs::register(&#39;home&#39;, function ($breadcrumbs) {<br>     $breadcrumbs-&gt;push(&#39;Home&#39;, route(&#39;home&#39;));<br>});</pre><h3>Rendering a static breadcrumb</h3><p>In the above code, we see that the Breadcrumbs class is used to call a static method. The register method registers a new breadcrumb with the name home and calls a closure. Then the closure takes a $breadcrumbs parameter and pushes a new breadcrumb instance alongside its URL.</p><pre>$breadcrumbs-&gt;push(&#39;Home&#39;, route(&#39;home&#39;));</pre><p>The ‘Home’ in the push method is hard-coded and what will appear when the breadcrumb is rendered on the home view or any other view that requires the Home breadcrumb to display a complete navigation chain.</p><p>The route(&#39;home&#39;) returns the URL of &#39;home&#39; and will be the link Home leads to when it is rendered on any view.</p><p>Finally, in the home view code, this is how we render the breadcrumb.</p><p><em>resources/views/home.blade.php</em></p><pre>{{ Breadcrumbs::render(&#39;home&#39;) }}</pre><p>The render method receives the name of the breadcrumb to display on the home view. In more complex navigation chains that include some form of database relationship, the render function will accept as many instances of Models as arguments, as are required to render the complete breadcrumb navigation chain.</p><p>We will talk more about this next.</p><h3>Rendering a dynamic breadcrumb</h3><p>What happens when we have a web application where we do not know the exact attributes of the pages users will be visiting? For example, we have a website that displays information about continents, countries, and cities. We can’t always hard-code the name of any continent, country or city to the routes/breadcrumbs.php file because we never know which one a user will be viewing.</p><p>To make it possible for dynamic breadcrumb rendering in real time, we can write the routes/breadcrumbs.php file to efficiently work with the dynamic Models in our application and create the breadcrumb navigation chain as users explore deeper layers in our web application.</p><p>As we said before, the continent Model hasMany countries and the country Model hasMany cities. Knowing this, we should be able to get a breadcrumb display that looks like this if we visit Johannesburg of South Africa where South Africa belongs to Africa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*qog35Ig3Syw7720Z.png" /></figure><p>To generate the chain of breadcrumb navigation using Model relationships as we see above, we start by writing the code for registering the continent breadcrumb:</p><p><em>routes/breadcrumbs.php</em></p><pre>Breadcrumbs::register(&#39;continent&#39;, function ($breadcrumbs, $continent) {<br>    $breadcrumbs-&gt;parent(&#39;home&#39;);<br>    $breadcrumbs-&gt;push($continent-&gt;name, route(&#39;continent&#39;, [&#39;name&#39; =&gt; $continent-&gt;name]));<br>});</pre><p>We register a continent breadcrumb and pass a closure. The closure accepts a new parameter, the $continent (which will be supplied by the calling view in real time). Next, the home breadcrumb is assigned as the parent and lastly, the name and URL of the $continent breadcrumb is pushed.</p><p>To render the breadcrumb in the continent view code, we write this snippet:</p><p><em>resources/views/continent.blade.php</em></p><pre>{{ Breadcrumbs::render(&#39;continent&#39;, $continent) }}</pre><p>The render method receives the name of the breadcrumb as the first argument. It also receives a $continent argument that will help in resolving the instance of the continent Model to its basic properties such as name and URL.</p><p>On my local machine, visiting http://127.0.0.1:8000/continent/africa will result in the Africa continent page with this breadcrumb display.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*QuxgfSf3GGixoshq.png" /></figure><h3>Rendering a complete navigation chain</h3><p>We have looked at the code to render individual breadcrumbs, now let’s look at the code and logic to render a complete breadcrumb chain. For the sake of this article, we will be rendering a city page that is related to a country page, then a continent page and lastly, a home page.</p><p>This is the final code [for this article, it can get way bigger depending of what you aim to achieve ] for the routes/breadcrumbs.php file:</p><p><em>routes/breadcrumbs.php</em></p><pre>Breadcrumbs::register(&#39;home&#39;, function ($breadcrumbs) {<br>     $breadcrumbs-&gt;push(&#39;Home&#39;, route(&#39;home&#39;));<br>});<br><br>Breadcrumbs::register(&#39;continent&#39;, function ($breadcrumbs, $continent) {<br>    $breadcrumbs-&gt;parent(&#39;home&#39;);<br>    $breadcrumbs-&gt;push($continent-&gt;name, route(&#39;continent&#39;, [&#39;name&#39; =&gt; $continent-&gt;name]));<br>});<br><br>Breadcrumbs::register(&#39;country&#39;, function ($breadcrumbs, $continent, $country) {<br>    $breadcrumbs-&gt;parent(&#39;continent&#39;, $continent);<br>    $breadcrumbs-&gt;push($country-&gt;name, route(&#39;country&#39;, [&#39;name&#39; =&gt; $country-&gt;name]));<br>});<br><br>Breadcrumbs::register(&#39;city&#39;, function ($breadcrumbs, $continent, $country, $city) {<br>    $breadcrumbs-&gt;parent(&#39;country&#39;, $continent, $country);<br>    $breadcrumbs-&gt;push($city-&gt;name, route(&#39;city&#39;, [&#39;name&#39; =&gt; $city-&gt;name]));<br>});</pre><p>We have added two more breadcrumbs — country and city — We need these additional breadcrumbs so that all the breadcrumbs can effectively communicate with one another when a view calls for a navigation chain that involves more than one breadcrumb.</p><p>The methods for registering and pushing the country and city breadcrumbs are the same as the ones for the continent breadcrumb so we will not be looking at it in detail.</p><p>To render the breadcrumb in the view code for the city page, we simply insert this snippet of code in the desired location:</p><p><em>resources/views/city.blade.php</em></p><pre>{{ Breadcrumbs::render(&#39;city&#39;, $city-&gt;country-&gt;continent, $city-&gt;country, $city) }}</pre><p>The render method here receives the name of the breadcrumb as the first argument. Next, it receives a $city-&gt;country-&gt;continent argument which will evaluate to an instance of a continent Model, also it receives a $city-&gt;country argument which is the country the city belongsTo and lastly a $city instance.</p><p>That is it. We have completely generated our fully functional and dynamic breadcrumb navigation in only a few lines of code.</p><h3>Conclusion</h3><p>In a world where the ‘users’ of internet services seek for the easiest to use products, it is only right for developers to add breadcrumbs to websites. This article has taught that, with just a few lines of code, we can create a fully functional navigation service. There are lots more that can be done with the <a href="https://github.com/davejamesmiller/laravel-breadcrumbs">Laravel Breadcrumb</a> package [ for example, we can affect the style and layout to our taste ], feel free to explore it to its fullest power.</p><p>The source code for this tutorial is available <a href="https://github.com/Jordanirabor/Laravel-Breadcrumbs">here</a> on GitHub.</p><p><em>Originally published at </em><a href="https://dev.to/jordanirabor/building-dynamic-breadcrumbs-in-laravel-926"><em>dev.to</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6bf1eb23a7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Super-Simple Guide To Bitcoin And The Blockchain]]></title>
            <link>https://medium.com/@jordanIrabor/a-super-simple-guide-to-bitcoin-and-the-blockchain-f36c2680a1d7?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f36c2680a1d7</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[mining]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Sat, 19 May 2018 20:04:54 GMT</pubDate>
            <atom:updated>2018-05-19T20:29:27.662Z</atom:updated>
            <content:encoded><![CDATA[<p>If children were asked to invent money for themselves, how would they do it?</p><p>Imagine that you’re back in kindergarten and this is the situation; each child may own one or more crayons, or own none at all. The kids with crayons can give them out in exchange for other items of equivalent value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*VJhH5ARHbuaBUN5H.jpg" /></figure><p>In the playground, some kids exchange their crayon for a pen, others do for a ruler or an eraser. More often, kids exchange crayons for money. It really depends on what is agreed upon at the time of the transaction. One thing remains constant though; a piece of crayon is an asset.</p><p>For a transaction to occur (“for example, let’s say Johnny wants to give Peter three crayons”), Johnny and Peter will go together to the teacher and inform her so she has it documented in the central register. Miss Juliet ( the teacher ) documents all transactions to prevent future troubles among the pupils.</p><p>During the transaction between Johnny and Peter, Miss Juliet ensured that Johnny actually has three crayons to give to Peter. Immediately she verified this, she updated the central register to say that Johnny has three fewer crayons and Peter owns three more.</p><p>Although Miss Juliet does a good job, she isn’t always accurate; sometimes it is difficult for her to focus because she is always busy processing school work. Occasionally, she doesn’t write the proper number of crayons traded.</p><p>One day, after teaching hours, a group of fifteen smart kids who frowned upon Miss Juliet’s documenting process (due to obvious flaws and lack of speed), decided to make their own crayon transaction system ( yes, because crayon is very important ).</p><p>These pupils (including Johnny and Peter) came up with a method to trade crayons among one another and have no intermediary ( Miss Juliet ) whatsoever controlling the transaction flow.</p><p>Here’s their idea:</p><blockquote><em>Whenever two children want to transact crayons, they will have to inform everyone in the group (simply screaming for attention does the trick). The other kids in the group will quickly verify that pupil A has enough crayons to give pupil B.</em></blockquote><blockquote><em>Immediately this verification is done, every kid will take note of it by recording it in </em><em>his/her own ledger (there will be no central ledger but each kid will have a separate ledger) and the transfer will be approved. This way, transactions will always be secure and accurate.</em></blockquote><blockquote><em>Lastly, for the pupils who do the work of verifying that a crayon transaction is valid; the parents (obviously the parents are the ones who buy the kids crayons in the first place) of the entire group will jointly issue a number of crayons to them as a reward for their efforts.</em></blockquote><p>This is actually a good idea, think about it. The structure of this newly contrived system annihilates the need for an intermediary. Transactions will be very secure since each kid has his own ledger and updates it whenever a new transaction occurs. The best part is, the kids who tirelessly verify and seal transactions in their ledgers will be rewarded with more crayons!</p><p>If only such a system existed in real life but for transacting actual currency, right? Well, guess what? It already exists and it is called the blockchain technology.</p><p>The kindergarten story we started off with is merely an analogy to help us understand bitcoin and the blockchain without delving into technical details, let’s break it down one by one:</p><p>The crayons are what bitcoins are to the blockchain — a bitcoin is a unit of digital currency ( there are several other digital currencies ).</p><p>The intermediary (Miss Juliet) represents bodies like banks, the government, and accountants. In actual life, we have trusted these third parties for many years to coordinate transactions for us but they are obviously flawed and not very secure (if someone is able to hack into a bank’s central system, files could be corrupted).</p><p>The kids who verify transactions between two members of the group are analogous to miners in the blockchain; they are of high importance to the system.</p><p>Miners are the reason bitcoins are very secure. They are constantly using their computers to do thousands (or millions or less, it depends) of complex mathematics each second to ensure that the ledger is always correct. This way, it is impossible for a single miner or a group of miners to cheat the system in their favour; the entire thing wouldn’t add up!</p><p>For a transaction to be approved, all the ledgers within the system must tally and the miners must agree upon the mathematical result.</p><p>We already saw that to reward the efforts of the kids who verify transactions, they are given new crayons. Something similar happens in the blockchain; whenever a miner is able to solve the mathematics ( using a computer) and verify a transaction, the other miners confirm that his work is correct before they all document it into their ledgers. He/she is then rewarded with an amount of bitcoins.</p><p>When a miner receives bitcoins as a reward for hard work, new bitcoins are introduced into the blockchain.</p><p>The cryptocurrency paradigm presents humanity with endless possibilities, only the future will tell what we make out of it.</p><p>By the day, more people are finding the concept of bitcoins interesting, here are a few reasons:</p><blockquote><em>Bitcoins are scarce.</em></blockquote><blockquote><em>Bitcoins are divisible.</em></blockquote><blockquote><em>Bitcoins are durable.</em></blockquote><blockquote><em>Bitcoins can be stored.</em></blockquote><blockquote><em>Bitcoins are portable.</em></blockquote><blockquote><em>Bitcoins are transferable.</em></blockquote><blockquote><em>Bitcoins are difficult to counterfeit.</em></blockquote><p><em>Originally published at </em><a href="https://dev.to/jordanirabor/a-super-simple-way-to-understand-bitcoin-and-the-blockchain-cg6"><em>dev.to.</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f36c2680a1d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build An Audio Translator With Vue.js, Yandex Translate API and Responsive Voice]]></title>
            <link>https://medium.com/@jordanIrabor/build-an-audio-translator-with-vue-js-yandex-translate-api-and-responsive-voice-6a34607bf83a?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a34607bf83a</guid>
            <category><![CDATA[yandex]]></category>
            <category><![CDATA[responsivevoice]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Tue, 15 May 2018 01:11:08 GMT</pubDate>
            <atom:updated>2018-05-19T20:32:01.921Z</atom:updated>
            <content:encoded><![CDATA[<p>A few weeks ago, I decided to put together a list of cool projects to do in Vue.js and for this reason, I started digging around the internet in search of valuable resources. At the end of the day, I had gathered significant chunks of knowledge on some useful APIs. Among the others, I found the <a href="https://translate.yandex.com/developers">Yandex Translate API</a> really fascinating; it’s able to take almost any text and return its equivalent in over 90 languages.</p><p>After playing around with the API ( using <a href="https://www.getpostman.com/">Postman</a> ) for a bit, I decided to take my Vue.js knowledge and wrap it within the awesomeness of this API. The result? I hacked together a Vue.js translator web application.</p><p>During the project, I integrated audio functionally by referencing the <a href="https://responsivevoice.org/">ResponsiveVoiceJS</a> <a href="https://code.responsivevoice.org/responsivevoice.js">CDN</a> and firing a simple function.</p><p>Here’s a visual display of the completed project :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*7sdavLRnGYNYQegw.gif" /></figure><p>Let’s see how I built it.</p><h3>Requirements</h3><p>Since we are going to be building this application with the Progressive Javascript Framework <a href="https://vuejs.org/">Vue.js</a>, we need to be sure to have a few things installed before proceeding:</p><p>We also need:</p><ul><li>An API key to use the <a href="https://translate.yandex.com/developers/keys">Yandex Translate API</a></li></ul><p>To create an account with Yandex, go <a href="https://passport.yandex.com/registration?origin=translate&amp;retpath=https%3A%2F%2Ftranslate.yandex.com%2Fdevelopers">here</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*Art4vzi8aS_rKO_P.png" /></figure><p>To create a free API key, go <a href="https://translate.yandex.com/developers/keys">here</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*sCPwvESVZs9SwK2a.png" /></figure><p>Once the dependencies are installed and you have a key, we are set to begin!</p><h3>Creating The Project</h3><p>We’ll be creating this project with the Vue-CLI tool, an alternative would be to reference Vue.js from a <a href="https://unpkg.com/vue@2.5.13/dist/vue.js">CDN</a> and you can do that if you choose to.</p><p>We’ll be using the webpack-simple template since this will not be overly complex to develop.</p><blockquote><em>You might need to change the ownership for the project directory and run some of these commands as root ( using </em><em>sudo )</em></blockquote><pre>vue init webpack-simple translator</pre><p>With this command, you’ll need to respond to a few lines of command prompt query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*cq32EP1ZQCh60UFu.png" /></figure><p>Let’s navigate to the project directory and install dependencies :</p><pre>cd translator <br>npm install</pre><h3>Creating The Translate Component</h3><p>We will create exactly one component for this project since we don’t want to clutter up the development environment with unnecessary components. This component will contain two textareas positioned side by side; one would hold the text to be translated while the other displays the translated text, both sides will also have an audio functionality.</p><p>Let’s create a components directory and a translate file in the src directory of our freshly installed project.</p><pre>mkdir -p src/components<br>cd src/components<br>touch translate.vue</pre><p>This file will contain all the code for the translate component.</p><h3>Writing The Code For The Translate Component</h3><p>Before we write any code at all, let’s think of the relationship between the root component ( App.vue ) and the child component ( translate.vue ). Let’s assume that the heavy lifting would be done by the root component, so the child component would receive props, register a few variables and emit events up to the root component on user interaction.</p><p>Now that we understand how this is going to work, let’s write some code in the script tag to receive props and initialize variables.</p><pre>export default {<br><br>  name: &#39;translate&#39;,<br><br>  props: {<br><br>   AvailableLanguages : {<br>     type : Object<br>   },<br><br>   ResponseText : {<br>     type : String<br>   },<br><br>   CurrentLanguage : {<br>     type : String<br>   },<br><br>   TranslateLanguage : {<br>     type : String<br>   }<br> },<br><br>  data () {<br>    return {<br>      Text: &#39;&#39;,<br>      FromLanguage : &quot;English&quot;,<br>      ToLanguage : &quot;French&quot;<br>    }<br>  }<br>}</pre><p>Let’s analyze the above code from top to bottom so we understand what is going on:</p><ol><li>First, we are exporting default, which is what would allow us to import this component into the root component.</li><li>We initialize the name variable then receive and validate some props, apparently, these props would be coming from the root component. Here&#39;s what they are and what they do:</li></ol><ul><li>AvailableLanguages would hold an object of the available languages for translation returned by the Yandex API.</li><li>ResponseText would hold the translated text for a specified language returned by the Yandex API.</li><li>CurrentLanguage would be the code for the current language we are typing in.</li><li>TranslateLanguage would be the code for the language that the translation would come in.</li></ul><ol><li>Lastly, we initialize a Text ( this is for the text being typed ) variable to an empty string. We then initialize two other variables, FromLanguage and ToLanguage, to &quot;English&quot; and &quot;French&quot; respectively. These are the variables that would hold the full name ( not code ) of the selected language.</li></ol><p>Awesome.</p><h3>Writing The MarkUp</h3><p>Having received the props and initialized some variables in the code above, we should write the HTML now. We will mostly be binding the textareas to their matching data variables and triggering events upon user interaction. The HTML will be written within the template tags so that Vue.js knows that this is MarkUp and renders it at runtime.</p><pre>&lt;div id=&quot;parent_translate&quot;&gt;<br><br>&lt;div id=&quot;input&quot;&gt;<br><br>&lt;div id=&quot;imageholder&quot;&gt;<br><br>&lt;select v-model=&quot;FromLanguage&quot; @change=&quot;changeFromLanguage&quot;&gt;<br><br>&lt;option v-for=&quot;(lang, code) in AvailableLanguages&quot; :value=&quot;code&quot;&gt; {{ lang }} &lt;/option&gt;<br><br>&lt;/select&gt;<br><br>&lt;img @click=&quot;translateSpeak&quot; src=&quot;../assets/speaker.png&quot;&gt;<br><br>&lt;/div&gt;<br><br>&lt;textarea placeholder=&quot;Type in something here&quot; v-model=&quot;Text&quot;&gt;&lt;/textarea&gt;<br><br>&lt;button @click=&quot;submit&quot; id=&quot;submit&quot;&gt;SUBMIT&lt;/button&gt;<br>&lt;/div&gt;<br><br>&lt;div id=&quot;output&quot;&gt;<br><br><br>&lt;div id=&quot;imageholder&quot;&gt;<br><br>&lt;select v-model=&quot;ToLanguage&quot; @change=&quot;changeToLanguage&quot;&gt;<br><br>  &lt;option v-for=&quot;(lang, code) in AvailableLanguages&quot; :value=&quot;code&quot;&gt; {{ lang }} &lt;/option&gt;<br><br>&lt;/select&gt;<br><br>&lt;img @click=&quot;responseSpeak&quot; src=&quot;../assets/speaker.png&quot;&gt;<br><br>&lt;/div&gt;<br><br>&lt;textarea placeholder=&quot;Your output goes here&quot; disabled v-model=&quot;ResponseText&quot;&gt; &lt;/textarea&gt;<br><br>&lt;/div&gt;<br><br>&lt;/div&gt;</pre><p>Let’s take a close look at the functionality bound to this MarkUp:</p><p>The first select tag is bound to the FromLanguage data variable using the v-model directive and it triggers an event handler &quot;changeFromLanguage&quot;, whenever its value is changed.</p><p>The option tag nested within the first select tag accepts the object of available languages ( which will come as a property from the root component ) and loops through it using the v-for directive. It&#39;s :value directive is bound to the code variable so that each option tag created during the loop has it&#39;s own unique code.</p><p>Let’s see some more of the MarkUp :</p><pre>&lt;select v-model=&quot;FromLanguage&quot; @change=&quot;changeFromLanguage&quot;&gt;<br><br>&lt;option v-for=&quot;(lang, code) in AvailableLanguages&quot; :value=&quot;code&quot;&gt; {{ lang }} &lt;/option&gt;<br><br>&lt;/select&gt;</pre><p>The img tag just below the previously discussed select tag holds an image representation for audio functionality and directs click events to a &quot;translateSpeak&quot; event handler.</p><pre>&lt;img @click=&quot;translateSpeak&quot; src=&quot;../assets/speaker.png&quot;&gt;</pre><p>The first textarea is quite straightforward with what it does, it binds the Text variable with itself so that it displays a placeholder only when there is no text written in it.</p><pre>&lt;textarea placeholder=&quot;Type in something here&quot; v-model=&quot;Text&quot;&gt;&lt;/textarea&gt;<br><br>&lt;button @click=&quot;submit&quot; id=&quot;submit&quot;&gt;SUBMIT&lt;/button&gt;</pre><p>The button tag performs a single function; it triggers a submit method whenever it is clicked.</p><p>After this point in the MarkUp, the remaining code is just a repetition of what has already been displayed, no new logic or functionality.</p><p>Let’s write the event handlers within the methods object.</p><h3>Writing The Event Handlers</h3><p>Let’s begin this section by writing the handlers for the select boxes, they are triggered whenever the selected option is changed.</p><pre>changeFromLanguage:function( ev ) {<br>    let LanguageCode = ev.target.value;<br>    this.$emit(&#39;updateFromLanguage&#39;, LanguageCode)<br>  },<br><br>  changeToLanguage:function( ev ) {<br>    let LanguageCode = ev.target.value;<br>    this.$emit(&#39;updateToLanguage&#39;, LanguageCode)<br>  }</pre><p>The function of these two handlers is quite obvious. First, a new variable holds the language code for the selected option and then this update is emitted to the root component. The handlers on the root component to handle these emitted events are also specified.</p><pre>submit:function( ev ){<br>    let Word = this.Text<br>    if ( Word ) {<br>    this.$emit(&#39;translate&#39;, Word)<br>    }<br>  }</pre><p>The submit method above is called whenever the Submit button is clicked and its simple job is to emit an event while passing the typed text to the parent component.</p><p>Before we look into the event handlers for the audio functions, we have to pull in the ResponsiveVoiceJS library because we depend on it for the audio functions, we can do this by plugging in a script tag just before the closing &lt;/body&gt; tag of the index.html file.</p><pre>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;utf-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;link href=&quot;https://fonts.googleapis.com/css?family=Indie+Flower&quot; rel=&quot;stylesheet&quot;&gt;<br>    &lt;title&gt;A simple translator application using the Yandex API&lt;/title&gt;<br>    &lt;style&gt;<br><br>    body{<br>      overflow-x: hidden;<br>      overflow-y: hidden; <br>      background: linear-gradient( to right, DodgerBlue, lightblue);<br>    }<br><br>    &lt;/style&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;div id=&quot;app&quot;&gt;&lt;/div&gt;<br>    &lt;script src=&quot;/dist/build.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&#39;https://code.responsivevoice.org/responsivevoice.js&#39;&gt;&lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>To make the application speak, we require a single function from the ResponsiveVoiceJS library:</p><pre>responsiveVoice.speak()</pre><p>We can embed this function within our audio handlers and have something like this:</p><pre>translateSpeak:function(){<br>    responsiveVoice.speak(this.Text);<br>  },<br><br>  responseSpeak:function(){<br>    responsiveVoice.speak(this.ResponseText);<br>  }</pre><p>The speak() function takes in the text in either one of the two data variables and plays it.</p><h3>Inlcuding Styles</h3><p>Lastly, let’s include some scoped Styles to help things stay pretty:</p><pre>&lt;style scoped&gt;<br>#parent_translate {<br>  width: 100%;<br>  height: 100%;<br>  display: flex;<br>  flex-wrap: nowrap;<br>  flex-direction: row;<br>}<br>select {<br>  padding: 0.2em 0em;<br>  margin: 0;<br>  font-family: &#39;Indie Flower&#39;, cursive;<br>}<br>#submit {<br>background: #4ed34c;<br>padding: 0.7em;<br>border: none;<br>border-radius: 1px;<br>cursor: pointer;<br>color: black;<br>}<br>#input, #output {<br>  background-color: #f1f1f1;<br>  width: inherit;<br>  height: inherit;<br>  text-align: center;<br>  font-size: 30px;<br>  border-radius: 60px;<br>}<br>#input {<br>  margin: 0px 2px 0px 0px;<br>}<br>#output {<br>    margin: 0px 0px 0px 2px;  <br>}<br>textarea {<br>  width: inherit;<br>  height: 60%;<br>  margin: 0px;<br>  padding: 45px 20px;<br>  box-sizing: border-box;<br>  outline: none;<br>  border: none;<br>  text-align: center;<br>  font-size: 25px;<br>  font-family: &#39;Indie Flower&#39;, cursive;<br>  font-weight: bold;<br>}<br>#input &gt; div, #output &gt; div {<br>  width: inherit;<br>  height: 20%;<br>  margin: 0px;<br>  padding: 0px;<br>}<br>#input &gt; div &gt; img, #output &gt; div &gt; img {<br> padding: 10px 0px 0px 0px;<br> width: 12%;<br> height: 60%;<br> cursor: pointer;<br>}<br>&lt;/style&gt;</pre><p>That’s really everything for the translate component, things are about to get functional and way more interesting.</p><h3>Building The Root Component</h3><p>Before we start writing code for this component, I want us to quickly explore the <a href="https://translate.yandex.com/developers">Yandex Translate API</a> and retrieve a <a href="https://translate.yandex.com/developers/keys">free key</a> if you haven’t already done that because it’s essential to the further parts of this project.</p><p>After <a href="https://passport.yandex.com/registration?origin=translate&amp;retpath=https%3A%2F%2Ftranslate.yandex.com%2Fdevelopers">creating an account</a> with Yandex :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*w18z_FmYdJoZ47tV.png" /></figure><p>You will be able to create a <a href="https://translate.yandex.com/developers/keys">free key</a> :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*o15JLzs4bJ5q2m8N.png" /></figure><h3>Writing The MarkUp</h3><p>The root component doesn’t need so much MarkUp so we will only write a few lines in which we would plug in the translate component as a custom tag :</p><pre>&lt;div id=&quot;app&quot;&gt;<br><br>&lt;h2&gt;VUE AUDIO TRANSLATOR &lt;/h2&gt;<br><br>&lt;div id=&quot;translate&quot;&gt;<br><br>&lt;translate v-bind:AvailableLanguages=&quot;AvailableLanguages&quot; v-bind:TranslateText=&quot;TranslateText&quot; v-bind:ResponseText=&quot;ResponseText&quot;  @updateFromLanguage=&quot;updateFromLanguage($event)&quot; @updateToLanguage=&quot;updateToLanguage($event)&quot; @translate=&quot;handleTranslation($event)&quot;&gt;<br>&lt;/translate&gt;<br><br>&lt;/div&gt;<br><br>&lt;/div&gt;</pre><p>There are quite two noteworthy activities going on on the &lt;translate&gt; custom tag, let&#39;s look at them:</p><ol><li>AvailableLanguages, TranslateText and ResponseText are passed down as props.</li><li>@updateFromLanguage, @updateToLanguage and @translate are received as emitted events by the root component from the translate component.</li></ol><h3>Including Styles</h3><p>Let’s include some styles to help the UI look good:</p><pre>&lt;style scoped&gt;<br>#translate {<br>  height: 45vh;<br>  max-width: 90%;<br>  margin: 2.5vh auto;<br>}<br>h2 {<br>  text-align: center;<br>  font-size: 1.6rem;<br>  color: black;<br>  font-weight: bold;<br>  font-family: &#39;Indie Flower&#39;, cursive;<br>}<br>&lt;/style&gt;</pre><p>At this point, we can run the application with this command:</p><pre>npm run dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*UWgonmP33REaKPdd.gif" /></figure><p>The output shows that the UI of both components have been done but when the dropdown is clicked, it is not populated with languages. This is because we have not written the scripts to drive this functionality.</p><p>Let’s do that now.</p><h3>Writing The Javascript</h3><p>Let’s do three things in this component:</p><ol><li>Import the translate component.</li><li>Register the component</li><li>Initialize variables</li></ol><pre>import translate from &#39;./components/translate.vue&#39;<br><br>export default {<br>  name: &#39;app&#39;,<br><br>  components: {<br>    translate : translate<br>  },<br><br>  data () {<br>    return {<br>      TranslateText : &#39;&#39;,<br>      ResponseText : &#39;&#39;,<br>      CurrentLanguage : &#39;en&#39;,<br>      TranslateLanguage : &#39;fr&#39;,<br>      AvailableLanguages : {}<br>    }<br>  }<br><br>  }</pre><h3>Hooking Into The Created() Lifecycle Method</h3><p>Vue.js allows us to hook into different <a href="https://vuejs.org/v2/guide/instance.html#Instance-Lifecycle-Hooks">component lifecycle methods</a> and do different things to enhance the flexibility of the application. For this application, we want to send a GET request to the Yandex Translate API when the application is created. Since Yandex Translate API allows us to make an HTTP request for a JSON payload of the supported languages alongside their codes, we will send a request whenever the application is created.</p><p>We need an HTTP client to send this request so let&#39;s get one, while there are a number of competent alternatives ( vue-resource, Fetch API etc ), we’ll be using the Promise based HTTP client <a href="https://www.npmjs.com/package/axios">axios</a>.</p><p>Let’s pull in axios and a small wrapper for integrating axios to Vue.js :</p><pre>npm install --save axios vue-axios</pre><p>To actually use axios and vue-axios, we need to import and use them into the src/main.js file :</p><pre>import Vue from &#39;vue&#39;<br>import App from &#39;./App.vue&#39;<br><br>import axios from &#39;axios&#39;<br>import VueAxios from &#39;vue-axios&#39;<br><br>Vue.use(VueAxios, axios)<br><br>new Vue({<br>  el: &#39;#app&#39;,<br>  render: h =&gt; h(App)<br>})</pre><p>Now that we have set up axios, we can request for the object of supported languages and their codes on every creation of the application:</p><pre>created(){<br><br>  var self = this;<br><br> this.axios.get(&#39;https://translate.yandex.net/api/v1.5/tr.json/getLangs?ui=en&amp;key=YOUR_KEY_GOES_HERE&#39;)<br>  .then(function (response) {<br>    self.AvailableLanguages = response.data.langs;<br>  })<br>  .catch(function (error) {<br>    console.log(error);<br>  })<br><br>  }</pre><p>After querying the Yandex Translate API, the response is asynchronously passed back as a Promise, we dig a bit into the response and update the value of the AvailableLanguages object.</p><h3>Writing The Translate And ValidateResponse Methods</h3><p>This is the central theme of this entire article because this is where the actual translation of texts and validation of requests happen. We would be doing three simple things here:</p><ol><li>Making a request to the Yandex Translate API with our unique key and the text to be translated.</li><li>Checking the response to confirm whether the text was translated properly or if an error was returned.</li><li>Updating the value of the ResponseText data variable if the response code is 200 or logging an error string to the console when it&#39;s not.</li></ol><pre>translate:function(){<br><br>  var self = this;<br><br> this.axios.get(&#39;https://translate.yandex.net/api/v1.5/tr.json/translate?key=YOUR_KEY_GOES_HERE&amp;text=&#39;+self.TranslateText+&#39;&amp;lang=&#39;+self.CurrentLanguage+&#39;-&#39;+self.TranslateLanguage+&#39;&amp;format=plain&#39;)<br>  .then(function (response) {<br><br>  self.validateResponse(response);<br>  })<br>  .catch(function (error) {<br>    console.log(error);<br>  })<br><br>  },<br><br>  validateResponse:function(response){<br><br>        if (response.status === 422) {<br><br>            console.log(&#39;Could Not Translate Text Please Try Again Later&#39;);<br><br>        } else if (response.status === 413) {<br><br>            console.log(&#39;Please Enter A Shorter Text to translate&#39;);<br><br>        } else if (response.status === 200) { <br><br>           this.ResponseText = response.data.text[0]<br><br>        } else {<br><br>          console.log(&#39;Cannot translate at this moment please try again later&#39;);<br>        }<br>    }</pre><p>That is pretty much the entire function of these methods, let’s see how the root component handles the emitted events from the translate component.</p><h3>Writing The Event Handlers</h3><p>From the earlier section above, we know that the root component has to handle three events emitted by the translate component:</p><ul><li>@updateFromLanguage, @updateToLanguage and @translate</li></ul><p>Let’s write the methods to handle these respectively:</p><pre>updateFromLanguage:function( value ){<br>    this.CurrentLanguage = value;<br>    this.translate();</pre><p>This handler receives a value from the translate component and updates the value of the CurrentLanguage variable with it. It then calls the translate() method to complete its job.</p><p>This is the method that is triggered on the root component whenever a new language ( the language to be translated from ) is selected.</p><p>The reason it calls on the translate method is so that a user can get instant updates on translations as they toggle between languages, without having to hit the submit button every time.</p><pre>updateToLanguage:function( value ){<br>    this.TranslateLanguage = value;<br>    this.translate();<br>  }</pre><p>This method does nearly the same thing as the one above, the only difference is that it works on the selection of the language being translated to, rather than the language being translated from.</p><p>Lastly, behold the method for handling click events to the submit button of the translate component:</p><pre>handleTranslation:function( value ){<br>    this.TranslateText = value;<br>    this.translate();<br>  }</pre><p>This handler simply updates the TranslateText variable with the value of the parameter received from the translate component, then it translates the text by calling the translate() method.</p><h3>Running The Application</h3><p>We can run the application with this command :</p><pre>npm run dev</pre><p>This should open a new window in the browser at the development address localhost:8080 :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*-FZCOVpigcdT9W39.gif" /></figure><p>That is all! We have just built a functional audio translator application and it’s ready for testing.</p><h3>Build The Application</h3><p>We can optionally build for production with this command:</p><pre>npm run build</pre><h3>Conclusion</h3><p>In this tutorial, we have seen how to build a simple audio translation application in Vue.js. We also used a powerful HTTP client, axios to query the Yandex Translate API for data.</p><p>We can conclude that Vue.js is a very exciting Progressive Framework to build lots of awesome projects.</p><p>The code for this project is available on <a href="https://github.com/Jordanirabor/Audio-Translator">Github</a>.</p><p><em>Originally published at </em><a href="https://dev.to/jordanirabor/build-an-audio-translator-with-vuejs-yandex-translate-api-and-responsive-voice--5b52"><em>dev.to.</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a34607bf83a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OOPS! Here comes the OOP.]]></title>
            <link>https://medium.com/@jordanIrabor/oops-here-comes-the-oop-26b103be2d83?source=rss-3190c898b40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/26b103be2d83</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[JordanisNotACoder]]></dc:creator>
            <pubDate>Mon, 07 Aug 2017 00:56:31 GMT</pubDate>
            <atom:updated>2018-05-15T01:33:58.293Z</atom:updated>
            <content:encoded><![CDATA[<p>I started writing computer programs solely for pleasure.</p><p>Initially, I wanted to play little tricks on my friends and do other pranks, it occurred to me a little late that i was going to take computer programming seriously in the immediate future.</p><p>Sometime this year, someone offered me a one time job, my first web development job actually — — he asked me to build a basic website and I thought it would be a great time to put everything I had learnt to exercise.</p><p>It took me roughly two weeks to complete the project. In the end, I had produced something good enough to be used and had also boastfully defied all the rules governing OOP and programming in general. Well, I guess I can’t be entirely blamed, 95 percent of the code was comprised of random stackoverflow answers.</p><p>My belief at that time was: if it looks like it works then it probably does.</p><p>Much later, I had the opportunity to work with an actual software driven company and it was then it dawned on me that doing things the right way mattered in computer programming; nobody wants to get involved with spaghetti code.</p><p>Realizing this, I began working intentionally to make my code more readable, adopted the habit of indenting and also made sure to comment every vague block of code in my programs but still, my efforts weren’t enough.</p><p>Some days, I looked at the code of the better developers around me and was met by some keywords I had used too often but never really knew what they meant. I wasn’t really familiar with the OOP fundamentals either and that was the most disturbing of my problems. I tried studying and understanding OOP at that time and it proved difficult like every other thing.</p><p>This article will introduce you to the basic concepts of OOP with examples but in a way I would have liked to read it when I was having OOP struggles.</p><p>Let’s begin by understanding what object oriented programming is about.</p><p>Object oriented programming is a programming style that supports the concept of defining all the properties and functions of an object within a class, this ensures that code is reusable and is a far more efficient approach to programming than previous paradigms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Vqdv2XFX93k9P3tYIZ57fg.gif" /></figure><p>Now this leads to the question, what is a class and what should a class contain? How do we know we have enough properties and functions to be grouped together as a class?</p><p>To answer these questions, let’s think this way; a class can contain all the code that deals with a certain element of a program. An example to explain this would be: Assume we have a general program that does lots of things but we have a smaller part of that program that defines a ‘user’ element, we can group all our code relating to the user properties and user functions within a single class and this would be beneficial to our program as a whole in lots of ways.</p><p>Code examples are written in PHP and kept short.</p><p>We should name a class according to what it is, for readability purposes and also, it is customary to begin the class name with a capital letter, if a class name contains two words or more then it should be written in upper camel case.</p><pre>class User {<br>// The code<br>}</pre><p>A class can have properties; properties are variables within a class, these variables may be initialized to contain values or may be left uninitialized (In some programming languages, they have to be initialized before the source code can compile.)</p><p>We can also specify how accessible these properties are by using access modifier keywords.</p><pre>class User {<br>protected $age;<br>public $name;<br>public $clothed = true;<br>}</pre><p>Now here’s the fun part, we can go ahead to create objects of the same class and each object would have its own set of properties unique to just that object.</p><pre>$firstUser = new User ();<br>$secondUser = new User ();<br>$thirdUser = new User ();</pre><p>Now you may be wondering, what good are classes and why do we need to create instances (objects) of classes anyway? Think about it this way; In the past, the procedural approach to programming allowed all variables and functions to live together on the global scope of the entire program, that is, they all lived on one surface and could possibly interact with one another just by calling their names and such.</p><p>With classes, this isn’t so; a class defines a scope outside the reach of the global scope, every operation carried out within the class scope is completely hidden from the global scope. The code nested within the class scope is encapsulated by the class and unavailable for use to the global scope, in order for the code within the class to be accessed and used, a class instance must be created. This class instance is called an object.</p><p>We may create as many objects of a class as we wish and each object differs from the other. On creation or instantiation of an object, the object inherits all properties from its class and can receive unique values for its own properties.</p><p>It is worth remembering that a class defines the structure and behavior of the objects that would be created from it.</p><p>Getting the value within an object’s property is easy. In PHP it can be accomplished by referencing the object’s name, attaching a dash greater than sign(-&gt;), then the property name.</p><pre>echo $firstUser-&gt;age;<br>echo $secondUSer-&gt;name;<br>echo $thirdUser-&gt;clothed;</pre><p>Result:</p><p>12<br>Jordan<br>false</p><p>It is also worth remembering that the $ sign is only attached to the object’s name but not the name of the property.</p><p>Setting a new value to an object’s property isn’t entirely different, we just attach the assignment operator to the right and the value gets assigned to the object’s property.</p><pre>$firstUser-&gt;age = 20;<br>$secondUSer-&gt;name = “Castiel”;<br>$thirdUser-&gt;clothed = true;</pre><p>Now printing the property of these objects would produce:</p><p>20<br>Castiel<br>true</p><p>That was fun to do!</p><p>Classes are wonderful to use, the idea behind properties is also scintillating but think about this. Imagine a class that defines users, this class says that all users must have a name and an age property, that’s great but this class doesn’t define the functionalities associated with a user object, objects are most likely to carry out operations using functions and these functions are called methods, the class should define methods for its objects.</p><p>Examples of functions for the user class performed by methods would be ‘create a post’, ‘make a comment’ and other similar ones.</p><pre>class User{<br>protected $age; <br>public $name; <br>public $clothed = true; <br>public function makePost() { <br>// code for making a post go here;<br>}</pre><p>We just included a simple makePost() method to our user class, notice that we prefix the method with the public access modifier to indicate that this method can be called from the global scope by a concrete instance of a class.</p><p>It is customary to name a method in lower camel case. Methods should be named according to the functions they perform and kept brief.</p><p>We call methods in a similar way as we refer to object properties; the object’s name, dash greater than sign(-&gt;) and the method’s name.</p><pre>$firstUser = new User();<br>$firstUser-&gt;makePost();</pre><p>The first line of code above created an object of the user class, while the other line invoked the makePost() method. In actual programming, the makepost() method will better have a parameter to receive the text made by a user and maybe save it to a database but these are just examples and everything is kept very simple since this is just an introduction to the basics of OOP.</p><p>Now let’s look at how much we have done, we have learnt about the basic idea of OOP and now know what OOP means in clearer terms, we have also seen why classes and objects are great for modern programming. Well-done, we’ve done so much! This should help lay the foundation if you wish to know more about OOP.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26b103be2d83" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>