<?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 Ajdin Imsirovic on Medium]]></title>
        <description><![CDATA[Stories by Ajdin Imsirovic on Medium]]></description>
        <link>https://medium.com/@ajdin.imsirovic?source=rss-1c991106bfa2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aAzMrcZmyH2a5VpwAeTnBg.jpeg</url>
            <title>Stories by Ajdin Imsirovic on Medium</title>
            <link>https://medium.com/@ajdin.imsirovic?source=rss-1c991106bfa2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 00:31:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ajdin.imsirovic/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[10 Reasons to Write Tutorials as a Web Developer]]></title>
            <link>https://medium.com/@ajdin.imsirovic/10-reasons-to-write-tutorials-as-a-web-developer-c03c88345905?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c03c88345905</guid>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 10:31:48 GMT</pubDate>
            <atom:updated>2021-08-12T02:39:03.982Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many reasons why web developers should write tutorials on web development topics. Or even articles about the industry in general, even if those articles are not directly aimed at teaching others to code.</p><p>However, in this post we’ll focus on the top 10 reasons why web developers can benefit from writing coding tutorials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*b74nCTDja9DiwjCJ.jpg" /></figure><p>Ok, it’s time to list the ten reasons. Number 10 is a real gem — a great lesson I learned from being both a published and a self-published author.</p><h3>1. Tutorial Writing Improves Your Technical Communication Skills</h3><p>Having to think through how to exactly phrase a technical concept that is hard to grasp is a great way to improve your technical communication skills.</p><h3>2. Tutorial Writing Improves Your Coding Skills</h3><p>The following quote has been attributed to Albert Einstein:</p><blockquote><em>If you can’t explain it simply, you don’t understand it well enough.</em></blockquote><p>Thus, having to explain something in an easy-to-understand language, keeping in mind thay your audience is, say, mostly consisting of beginners, will do wonders for your own examination of the topic at hand. How well do you know the subject?</p><p>Tutorial writing will give you great insights towards finding the answer to this question.</p><h3>3. Writing Tutorials on a Strict Schedule Will Surely Build Your Discipline</h3><p>The popular self-help idea of “Miracle Morning” has some truth to it. Surely, we can benefit from getting up earlier than others — or just getting up early to begin with — and going through a pre-defined set of important activities. That way, it could be, say, 8AM, and we’ve already completed several important activities, including:</p><ul><li>exercise</li><li>reading</li><li>prayer/meditation</li><li>tutorial writing (why not?)</li></ul><p>It can be beneficial to our personal and professional well-being to batch together important activities like that. Also, it can obviously improve our discipline, because good habits can often promote and prop up other good habits.</p><p>The takeaway: Try it for a week, and see what happens.</p><h3>4. Writing Tutorials Will Help You Get a Feel for Breaking Down Coding Problems into Simple Steps</h3><p>Like anything else, breaking down big coding problems into smaller pieces is a skill. It can be learned. It can be acquired. And it can be improved. While many coders don’t even think about this, and out of the select few that do think about it, leave it up to chance or experience, you can be in an even more rare group of developers who is <em>consciously pursuing</em> the sharpening of this skill.</p><p>Keeping track of how you write about solving coding problems, while also analyzing other times you did the same thing (other times you wrote coding tutorials), can elevate your skills on breaking down complex problems into smaller, manageable pieces.</p><p>After long enough time passes, you might start getting a gut feeling of the approach to take in tackling all kinds of issues: and that’s a sign of a senior developer.</p><h3>5. Tutorial Writing Helps Organize Your Code-related Thinking</h3><p>This one is sort of a continuation on the previous point. But it’s far from being the same thing — actually it’s not even similar.</p><p>What I mean by “organizing code-related thinking” is: having the ability to understand the <em>gist</em> of the coding problem you’re solving at any given time.</p><p>By writing coding tutorials that focus on solving a specific issue, you’ll begin getting deeper insight into separating the essential and the non essential.</p><p>You’ll begin understanding the relevant and the irrelevant parts of other people’s code.</p><p>An example of this is a simple tutorial on <a href="https://www.codingexercises.com/calculate-fibonacci-sequence-in-js">writing a fibonacci-sequence-generating function in vanilla JavaScript</a>. At its core, it’s a very simple piece of code — but I’ve seen many cases where developers over-complicate such an implementation.</p><p>The point is — writing coding tutorials will give you a chance to get to the very core of a coding solution — to remove all the redundant pieces until all that is left is the essence of a specific solution.</p><h3>6. Tutorial Writing is Great for Networking</h3><p>You could write tutorials for a number of reasons:</p><ul><li>To try another income stream</li><li>To improve your personal website</li><li>To position yourself as an expert in a given tech stack</li></ul><p>Whatever the reason, all of the above activities mean that you interact with people — thus increasing your network of contacts.</p><p>After you’ve developed a professional connection with relevant people in your industry, you could take that to the next level by looking for contributors to your projects, looking for sponsors, looking for new employment opportunities, etc.</p><h3>7. Tutorial Writing is Another Skill in Your Skillset</h3><p>Many developers don’t realize that technical communication abilities are a skill that can be cultivated. In your day to day work, you might be tasked with having to document an API or having to read lots of documentation. Understanding the principles and rules of good technical documentation is another skill that can improve you as that well-rounded, perfect team member.</p><h3>8. Tutorial Writing Forces You to Think Outside of the Box</h3><p>While writing tutorials, you might need to check your articles against plagiarism. I’m using the <a href="https://www.quetext.com/">Quetext plagiarism checker</a>, which I find pretty good for my needs.</p><h3>9. Tutorial Writing will help You Become a Senior Developer</h3><p>What makes a senior developer?</p><p>There are many skills, and of course, experience — but I firmly believe that tutorial writing (or video tutorial production) is an important ingredient.</p><p>Most tutorial writing opens up the author to public scrutiny — especially in our industry which is full of people who pride themselves with being smart and precise — and thus perfect candidates for pinpointing other people’s errors.</p><p>Thus, most developers who do write coding tutorials do their best to make them as good as possible.</p><p>This is a tall order. It is hard. It requires time and effort. It’s a specific skill.</p><h3>10. Tutorial Writing Helps You Stay Ahead in the Industry</h3><p>Speaking about specific skills, I remember a quote from a Liam Neeson movie: “I posses a unique set of skills acquired over a long career.”</p><p>How do you prove it?</p><p>With tutorial writing, you can set yourself aside from the pack.</p><p>It’s a numbers game:</p><ul><li>How many developers write tutorials (a smaller group than all web developers)</li><li>How many developers write tutorials on a regular schedule (an even smaller group)</li><li>How many developers write tutorials on their own blog (yet an even smaller group)</li><li>How many developers have been writing tutorials on their own website for more than 5 or 10 years? (an extremely small number of developers — and this can be a significant advantage)</li></ul><p>In conclusion, over the years, tutorial writing can help you move from a purely coding role to a more of an advisory, consultant, or teaching role.</p><p>There you have it, a bunch of reasons to start writing coding tutorials today.</p><p><em>Originally published at </em><a href="https://www.codingexercises.com/10-reasons-to-write-tutorials-as-a-web-developer"><em>https://www.codingexercises.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c03c88345905" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a blog post image maker app in vanilla JS]]></title>
            <link>https://medium.com/@ajdin.imsirovic/build-a-blog-post-image-maker-app-in-vanilla-js-254e65fa7f6a?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/254e65fa7f6a</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Sat, 24 Jul 2021 12:40:26 GMT</pubDate>
            <atom:updated>2021-07-24T12:40:26.223Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post we’ll code a custom blog post image generator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/0*Y99GjIJ-Shthp_9M.jpg" /></figure><h3>Scratching our own itch</h3><p>In IT, there’s an old concept of “scratching your own itch”. What that means is that you build a project that solves a problem that <em>you</em> are having.</p><p>Thus, this chapter deals with such a scenario. This book’s accompanying website, <a href="https://www.codingexercises.com/">codingexercises.com</a>, currently has a layout which assumes that each blog post has an image associated with it.</p><p>Since this blog also runs on a small budget (basically, whatever I invest in it from my paycheck), it’s not really worth it for me to spend any money on blog post images.</p><p>Unfortunately, free image resources such as unsplash.com or pexels.com offer only a limited amount of JavaScript-related or coding-related photos and illustrations.</p><p>Which means that very often, I’d have to come up with my own graphics. Hence, I came up with the <strong>simple image maker app</strong>.</p><h3>Preview the app live</h3><p>Currently, the app has only the minimal functionalities. But it still works for me.</p><p>To preview the app live, visit <a href="https://www.codingexercises.com/simple-image-maker">codingexercises.com/simple-image-maker</a>.</p><p>Here’s how we’re going to re-built it.</p><h3>Building the app from scratch</h3><p>We’ll again start with a basic HTML page that has bootstrap 4 added to it from a CDN.</p><p>After this basic setup is ready, we’ll turn to the body element; inside of the body element we’ll add the following code:</p><p>Next, we’ll replace the HTML with the following code:</p><p>Additionally, just above the closing &lt;/body&gt; tag, we&#39;ll add the following script element:</p><p>Next, we’ll move the inline styles in the #bg div to a separate style tag in the head of our HTML file. Additionally, we&#39;ll add the dropdown with five possible choices for background colors in our form.</p><h3>Getting the values from the option element using JavaScript</h3><p>Now we’ll need to expand our JavaScript logic so that it takes care of the option the user picks from the color-choosing select element (i.e the dropdown):</p><p>That’s it for our simple image maker.</p><p>It is still a work in progress, as I keep improving the app, I’ll upload it to the live version, at <a href="https://www.codingexercises.com/simple-image-maker">codingexercises.com/simple-image-maker</a>.</p><p>Obviously, I’ll also make updates to this book, so that the current state of the app reflects the code here.</p><p>In the next chapter, we’ll build a simple stopwatch.</p><p>Note: <br> This exercise comes from <a href="https://leanpub.com/a-better-way-to-learn-javascript-building-mini-apps">Book 4</a> of <a href="https://leanpub.com/b/a-better-way-to-learn-javascript-book-series">my book series on JS</a>, available on Leanpub.com.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*g9Vevbhv4mp8UQUm.png" /></figure><p><em>Originally published at </em><a href="https://www.codingexercises.com/build-a-blog-post-image-maker"><em>https://www.codingexercises.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=254e65fa7f6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Simple Movie Reviews Website in Rails 6, part 2]]></title>
            <link>https://medium.com/@ajdin.imsirovic/build-a-simple-movie-reviews-website-in-rails-6-part-2-d2bcd2284a09?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2bcd2284a09</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 15:54:17 GMT</pubDate>
            <atom:updated>2019-12-17T15:54:17.667Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://www.codingexercises.com/projects/build-a-simple-movie-review-website-in-rails-6-part-1">the previous article</a>, we’ve installed all the pre-requisites to start building our site.</p><p>Let’s get right into it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/0*4HSmg8hSb2s6zfjI.png" /></figure><h3>First, let’s commit the new Rails app</h3><p>To commit the newly-made Rails app, let’s run the following commands:</p><pre>git add --all<br>git status<br>git commit -m &quot;Initialize a new Rails project&quot;<br>git log --oneline</pre><p>Now that we are sure that git is tracking our app, we can run our first migration.</p><h3>Running our First Migration</h3><pre>rails db:migrate</pre><p>To run our first migration, let’s open the console and type:</p><p>This will add a new file to our app; the file is called schema.rb, and it’s located in the db folder.</p><p>We can also run the git status command to verify a new file has been added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/0*6ogyJdedy_u81bY3.png" /></figure><p>Now we’ll commit the changes:</p><pre>git add --all<br>git commit -m &quot;Run the first &#39;rails db:migrate&#39; command&quot;</pre><p>Let’s verify that our app still works by visiting http://localhost:3000. Of course, for this to work, the rails s command has to already be running in a console on our machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/0*-TKyIVr1wQhYlao_.png" /></figure><p>Now we can also push the app to remote, i.e to GitHub.</p><h3>Pushing the local app to GitHub</h3><p>Let’s make a new repository in GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/0*BNOmq-hsyeSvYbkN.png" /></figure><p>Now we’ll push the existing local repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/0*zL8mbHzmxFUl5lwE.png" /></figure><p>As the screenshot shows, we’ll run these two commands from the command line:</p><p>Here’s the result of running these two commands in the console:</p><pre>git remote add origin https://github.com/ImsirovicAjdin/movieSiteRails6V2.git<br>git push -u origin master</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rbvemnmckxiFuGMe.png" /></figure><p>Now, back on GitHub, you can click on the repository name to see the commits that have been pushed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cW586ZOeDm8woxaQ.png" /></figure><p>Next we’ll install a front-end framework.</p><p>This time, it’s gonna be Bulma.</p><h3>Install Bulma Framework in Rails 6</h3><p>To do this, we’ll press the keyboard shortcut of <strong>CTRL + p</strong> in VS Code.</p><p>This shortcut will open the file launcher; now we’ll click the name of the file we’re looking for.</p><p>This time, we want to locate the file called Gemfile.</p><p>Once we’ve located and opened the Gemfile, let’s add Bulma gems:</p><pre>gem &#39;bulma-rails&#39;, &#39;~&gt; 0.7.4&#39;<br>gem &#39;bulma-extensions-rails&#39;, &#39;~&gt; 1.0.30&#39;</pre><p>Now that we’ve added the gems, we’ll need to use them in our application.css file, inside the app/assets/stylesheets folder.</p><pre>@import &#39;bulma&#39;;<br>@import &#39;bulma-extensions&#39;;</pre><p>Save all the changes, and inside the console, run:</p><pre>bundle</pre><p>This is the result of running the above command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/0*m0n5MLwbm9SW1QBG.png" /></figure><p>Next, we’ll be adding jQuery.</p><h3>Add jQuery to Rails 6</h3><p>Since we’re using Yarn, adding jQuery is easy:</p><pre>yarn add jquery</pre><p>In the image below, you can see the output of the command:</p><pre>$(&#39;body&#39;).hide();</pre><p>Now we can try running a simple jQuery command inside browser devtools with the localhost:3000 homepage open.</p><p>This <em>will</em> throw an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*inNNMiG0QKU7Iv_O.png" /></figure><p>Alternatively, we can run the git diff command, to see all the changes that have taken place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kiShhNxfoxwnwLqj.png" /></figure><p>Obviously, jQuery should be available in our app.</p><p>If we inspect our app’s Gemfile, we can find the jQuery dependency has been added. We also saw that earlier, yarn add command reported a successful addition of jQuery. So why doesn’t it work?</p><p>The reason is: we need to add it to webpacker, by expanding the environment.js file with additional code.</p><p>We need to locate the file called environment.js, inside the config/webpack folder.</p><p>The quickest way to do this is to run the file launcher in VS Code using the above mentioned keyboard combo of CTRL + p.</p><p>Once we’ve located the file, we need to add:</p><pre>const webpack = require(&#39;webpack&#39;)<br>environment.plugins.append(&#39;Provide&#39;, <br>    new webpack.ProvidePlugin({<br>        $: &#39;jquery/src/jquery&#39;,<br>        jQuery: &#39;jquery/src/jquery&#39;<br>    })<br>)</pre><p>Why did we do this? We added this code <strong>to make jQuery globally available</strong> in our app, in each of its files.</p><p>This is a good time to commit our changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*B1Uc-hzJWDPkoGDR.png" /></figure><p>Next, we’ll add our first static page in Rails.</p><h3>Add a Static Page in Rails 6</h3><p>To add a static page, we’ll run a generate command, in its short version, which is just g.</p><pre>rails g controller Pages home</pre><p>Pages is the controller name, and home is the Pages controller&#39;s action.</p><p>It’s possible you’ll see a “FATAL” error at this point:</p><pre>FATAL: Listen error: unable to monitor directories for changes.<br>Visit https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers for info on how to fix this.</pre><p>The fix is to run this command:</p><pre>echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf &amp;&amp; sudo sysctl -p</pre><p>Now our rails g command should run just fine, and generate the following output in console:</p><pre>create  app/controllers/pages_controller.rb<br>route  get &#39;pages/home&#39;<br>invoke  erb<br>create    app/views/pages<br>create    app/views/pages/home.html.erb<br>invoke  test_unit<br>create    test/controllers/pages_controller_test.rb<br>invoke  helper<br>create    app/helpers/pages_helper.rb<br>invoke    test_unit<br>invoke  assets<br>invoke    scss<br>create      app/assets/stylesheets/pages.scss</pre><p>Let’s also inspect the changes with git, by running git status or git diff --stat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/0*ROOvNGFuMG5izjzC.png" /></figure><p>As shown in the image above, running the git status command shows both the <em>existing, modified files</em>, as well as the <em>newly added</em> files.</p><p>Running git diff --stat just shows one-liners for each modified file that was already tracked by git, but it doesn&#39;t show new files.</p><p>Regardless of how we inspect the changes, here’s the list of files that the rails g command produced:</p><p>We can now look at the contents of the above-referenced app/views/pages/ folder, inside VS Code, by running the file launcher.</p><p>Expectedly, home.html.erb is the only file that gets filtered as we type app/views/pages inside the launcher.</p><p>Let’s inspect it:</p><pre>&lt;h1&gt;Pages#home&lt;/h1&gt;<br>&lt;p&gt;Find me in app/views/pages/home.html.erb&lt;/p&gt;</pre><p>If we navigate to localhost:3000/pages/home, this will be the output of the above code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*9UKwO6kWQ_Vi4upe.png" /></figure><p>Next, let’s update the above page with some Bulma code.</p><p>This code is just to test-drive Bulma. It can be anything really. It’s just some temporary code.</p><p>So let’s copy <a href="https://bulma.io/documentation/components/card/">a Bulma card example</a>.</p><p>Here’s the code:</p><pre>&lt;div class=&quot;card&quot;&gt;<br>  &lt;div class=&quot;card-image&quot;&gt;<br>    &lt;figure class=&quot;image is-4by3&quot;&gt;<br>      &lt;img src=&quot;https://bulma.io/images/placeholders/1280x960.png&quot; alt=&quot;Placeholder image&quot;&gt;<br>    &lt;/figure&gt;<br>  &lt;/div&gt;<br>  &lt;div class=&quot;card-content&quot;&gt;<br>    &lt;div class=&quot;media&quot;&gt;<br>      &lt;div class=&quot;media-left&quot;&gt;<br>        &lt;figure class=&quot;image is-48x48&quot;&gt;<br>          &lt;img src=&quot;https://bulma.io/images/placeholders/96x96.png&quot; alt=&quot;Placeholder image&quot;&gt;<br>        &lt;/figure&gt;<br>      &lt;/div&gt;<br>      &lt;div class=&quot;media-content&quot;&gt;<br>        &lt;p class=&quot;title is-4&quot;&gt;John Smith&lt;/p&gt;<br>        &lt;p class=&quot;subtitle is-6&quot;&gt;@johnsmith&lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br><br>    &lt;div class=&quot;content&quot;&gt;<br>      Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>      Phasellus nec iaculis mauris. &lt;a&gt;@bulmaio&lt;/a&gt;.<br>      &lt;a href=&quot;#&quot;&gt;#css&lt;/a&gt; &lt;a href=&quot;#&quot;&gt;#responsive&lt;/a&gt;<br>      &lt;br&gt;<br>      &lt;time datetime=&quot;2016-1-1&quot;&gt;11:09 PM - 1 Jan 2016&lt;/time&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>And here’s the result of copy-pasting the above code and refreshing localhost:3000/pages/home.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/0*lGLgyuhE481i-UC4.png" /></figure><p>As we can see, our Bulma styles are obviously not loading.</p><p>If we inspect the application.css file in Chrome, we&#39;ll see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/0*mStx0_bxMnTvf7HM.png" /></figure><p>Sidenote: Notice the bunch of additional letters and numbers in the application.css file&#39;s name? These are there for cache-busting.</p><h3>Importing Bulma into application.html.erb</h3><p>Why doesn’t our current import work?</p><p>Because of this error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/0*OwQCRO17tRfMkmVY.png" /></figure><p>This is the first version of this error: The stylesheet was not loaded because its MIME type, “text/sass”, is not “text/css”.</p><p>An alternative version of this error is: “Resource interpreted as Stylesheet but transferred with MIME type text/sass:”.</p><p>So how do we fix this?</p><p>Actually, the fix is very easy. We’ll just rename the application.css file into application.scss file.</p><p>Why does this work?</p><p>The explanation can be found in the beginning lines of the multi-line comment inside the existing application.css file itself:</p><pre>/*<br> * This is a manifest file that&#39;ll be compiled into application.css, which will include all the files<br> * listed below.<br> *<br> * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin&#39;s<br> * vendor/assets/stylesheets directory can be referenced here using a relative path.</pre><p>The heavy lifting is done by <a href="https://www.codingexercises.com/guides/understanding-node-npm-and-javascript-modules#what-is-webpack">webpack</a> in the background.</p><p>This is a good time to save our changes.</p><p>First, let’s make sure we’ve saved all changes in VS Code.</p><p>Next, let’s see our git status. Then we&#39;ll add all our changes and commit them as: &quot;Rename application.css to application.scss and add a card to pages/home&quot;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H4Azsb6krJGtc1t4.png" /></figure><p>Next, we’ll add the navbar to our code.</p><h3>Add Main Nav to our Application</h3><p>The navbar will appear on every page of our application, thus we’ll need to add it as a partial view file, and then we’ll import that partial into application.html.erb file.</p><p>Let’s add a new folder to hold the partial files. In app/views, run:</p><pre>mkdir partials</pre><p>Thus, we have a new folder called app/views/partials.</p><p>Next, let’s add a new partial file. Partial files, by convention, begin with an underscore, so:</p><pre>touch _nav.html.erb</pre><p>Now let’s copy-paste <a href="https://bulma.io/documentation/components/navbar/#basic-navbar">the navbar from Bulma</a>, and remove the redundant code.</p><p>Here’s what we end up with:</p><pre>&lt;nav class=&quot;navbar&quot; role=&quot;navigation&quot; aria-label=&quot;main navigation&quot;&gt;<br>  &lt;div class=&quot;navbar-brand&quot;&gt;<br>    &lt;a class=&quot;navbar-item&quot; href=&quot;https://bulma.io&quot;&gt;<br>      &lt;img src=&quot;https://bulma.io/images/bulma-logo.png&quot; width=&quot;112&quot; height=&quot;28&quot;&gt;<br>    &lt;/a&gt;<br><br>    &lt;a role=&quot;button&quot; class=&quot;navbar-burger burger&quot; aria-label=&quot;menu&quot; aria-expanded=&quot;false&quot; data-target=&quot;navbarBasicExample&quot;&gt;<br>      &lt;span aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;<br>      &lt;span aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;<br>      &lt;span aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;<br>    &lt;/a&gt;<br>  &lt;/div&gt;&lt;!-- /navbar-brand --&gt;<br><br>  &lt;div id=&quot;navbarBasicExample&quot; class=&quot;navbar-menu&quot;&gt;<br><br>    &lt;div class=&quot;navbar-start&quot;&gt;<br><br>      &lt;!-- &lt;a class=&quot;navbar-item&quot;&gt;<br>        Home<br>      &lt;/a&gt; --&gt;<br><br>    &lt;/div&gt;&lt;!-- /navbar-start --&gt;<br><br>    &lt;div class=&quot;navbar-end&quot;&gt;<br>      &lt;div class=&quot;navbar-item&quot;&gt;<br>        &lt;div class=&quot;buttons&quot;&gt;<br>          &lt;a class=&quot;button is-primary&quot;&gt;<br>            &lt;strong&gt;Sign up&lt;/strong&gt;<br>          &lt;/a&gt;<br>          &lt;a class=&quot;button is-light&quot;&gt;<br>            Log in<br>          &lt;/a&gt;<br>        &lt;/div&gt;&lt;!-- /buttons --&gt;<br>      &lt;/div&gt;&lt;!-- /navbar-item --&gt;<br>    &lt;/div&gt;&lt;!-- /navbar-end --&gt;<br><br>  &lt;/div&gt;&lt;!-- /navbar-menu --&gt;<br><br>&lt;/nav&gt;</pre><p>Finally, we’ll need to add call the render function to call the _nav.html.erb file from the partials folder.</p><p>We’ll make this call to render function from inside the application.html.erb file, as follows:</p><pre>&lt;%= render &quot;partials/nav&quot; %&gt;</pre><p>Note: Rails is smart enough to understand what file we’re referring to.</p><p>Now that we’ve added the navbar, on narrow screens, it will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*SSm3IZ11-easON3f.png" /></figure><p>As we can see, on small widths, our navbar’s links are hidden behind a toggleable button (commonly known as the “burger” button).</p><p>However, clicking on the button toggle will not work, because Bulma is a CSS-only framework, and for the toggle to work, we need to add some jQuery.</p><p>Before we do, let’s commit our changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/0*GrQZqUxhXb9hgDRy.png" /></figure><h3>Making the toggle button work</h3><p>To make the toggle button work, navigate to <a href="https://bulma.io/documentation/components/navbar/#navbar-menu">navbar-menu</a> section of the navbar page on Bulma docs.</p><p>At the bottom of the <em>JavaScript toggle</em> card, you’ll find the jQuery code to add:</p><pre>$(document).ready(function() {<br><br>  // Check for click events on the navbar burger icon<br>  $(&quot;.navbar-burger&quot;).click(function() {<br><br>      // Toggle the &quot;is-active&quot; class on both the &quot;navbar-burger&quot; and the &quot;navbar-menu&quot;<br>      $(&quot;.navbar-burger&quot;).toggleClass(&quot;is-active&quot;);<br>      $(&quot;.navbar-menu&quot;).toggleClass(&quot;is-active&quot;);<br><br>  });<br>});</pre><p>Now we’ll add the above code into _nav.html.erb, at the very bottom, inside a pair of opening and closing script tags:</p><pre>&lt;script&gt;<br>$(document).ready(function() {<br><br>  // Check for click events on the navbar burger icon<br>  $(&quot;.navbar-burger&quot;).click(function() {<br><br>      // Toggle the &quot;is-active&quot; class on both the &quot;navbar-burger&quot; and the &quot;navbar-menu&quot;<br>      $(&quot;.navbar-burger&quot;).toggleClass(&quot;is-active&quot;);<br>      $(&quot;.navbar-menu&quot;).toggleClass(&quot;is-active&quot;);<br><br>  });<br>});<br>&lt;/script&gt;</pre><p>If we now click the toggle button, this is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/0*5Bpwtvd91cJImGDX.png" /></figure><p>Let’s commit our changes again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/0*Ivbe_3YlovRJWPep.png" /></figure><p>Next, we’ll add authentication with the devise gem.</p><h3>Adding the Devise Gem</h3><p>To have our users log in and out of our application, we’ll use the devise gem.</p><p>We’ll add it to our app like this:</p><pre>gem install devise</pre><p>Here’s the bash output:</p><pre>Successfully installed devise-4.7.1<br>1 gem installed</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*j0N55qVCfTSI1GE-.png" /></figure><p>Now we’ll add it to our Gemfile, and specify the version:</p><p>Now we’ll install it using <a href="https://bundler.io/">bundler</a>:</p><pre>bundle</pre><p>Next we’ll run rails g devise:install. This will install the devise initializer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/0*QMVarscg6E7644zF.png" /></figure><p>It will also print a lot of instructions to the console, which can be abbreviated to:</p><ol><li>Reminder to define default url options in the environment files</li><li>Reminder to define root_url (which we haven’t yet done)</li><li>Reminder to add flash messages in application.html.erb layout file</li><li>Reminder to copy Devise views so that we can customize them</li></ol><p>To use Devise, we’ll need to have a User, so let’s add a User model.</p><pre>rails g devise User</pre><p>Let’s also run git status to see the changes made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/0*AVtluRYub04YMBdx.png" /></figure><p>Now we’ll migrate the database:</p><pre>rails db:migrate</pre><p>Let’s do git status again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/0*xRuELw3O2Ppuo6c1.png" /></figure><p>If we run git add --all, then git status, we&#39;ll see the list of all the staged files, ready to commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/0*2a39rZ-rtyO4o90L.png" /></figure><p>Now let’s run git commit:</p><pre>git commit -m &quot;Add the devise User model and run rails db:migrate&quot;</pre><p>Next, we can see the last five commits with git log --oneline -5.</p><p>Here’s the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/0*mxiHD3YQOAa6GNcb.png" /></figure><p>Now we can see the commits’ SHA hashes (random letters and numbers before the commit message). These hashes are 40 characters long, but for our convenience, they’re shortened to only 8 characters.</p><p>Thus, to see the changes on files between any commit, we can do, for example, this:</p><pre>git diff &lt;previous-commit&gt; &lt;current-commit&gt; &lt;filename&gt;</pre><p>In practice, we’re interested in db/migrate/20191217144111_devise_create_users.rb, so:</p><pre>git diff e462ad2 9be3ce3 db/migrate/20191217144111_devise_create_users.rb</pre><p>Here’s the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/0*X4sMrErI_-T_pb87.png" /></figure><p>As we can see, the db migration file gets a sort of a timestamp that will identify it inside the db/migrate folder.</p><p>The code in the migration file shows the changes to the database that need to be performed in order to create the User model.</p><p>Thus, database migrations are syncing the changes made to our Rails application’s code.</p><p>Now let’s add the flash messages.</p><h3>Adding the Flash Messages</h3><p>Flash messages are simply notifications in our app.</p><p>We’ll paste them inside application.html.erb so that they show up everywhere.</p><pre>&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;<br>&lt;p class=&quot;alert&quot;&gt;&lt;%= alert %&gt;&lt;/p&gt;</pre><p>Here’s the complete application.html.erb file:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;title&gt;MovieSiteRails6V2&lt;/title&gt;<br>    &lt;%= csrf_meta_tags %&gt;<br>    &lt;%= csp_meta_tag %&gt;<br><br>    &lt;%= stylesheet_link_tag &#39;application&#39;, media: &#39;all&#39;, &#39;data-turbolinks-track&#39;: &#39;reload&#39; %&gt;<br>    &lt;%= javascript_pack_tag &#39;application&#39;, &#39;data-turbolinks-track&#39;: &#39;reload&#39; %&gt;<br>  &lt;/head&gt;<br><br>  &lt;body&gt;<br>    &lt;%= render &quot;partials/nav&quot; %&gt;<br><br>    &lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;<br>    &lt;p class=&quot;alert&quot;&gt;&lt;%= alert %&gt;&lt;/p&gt;<br><br>    &lt;%= yield %&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Next, we’ll commit this update with message: “Add flash messages”.</p><p><a href="https://www.codingexercises/projects/build-a-simple-movie-review-website-in-rails-6-part-2">The article continues here</a>.</p><p><em>Originally published at </em><a href="https://www.codingexercises.com/projects/build-a-simple-movie-review-website-in-rails-6-part-2"><em>https://www.codingexercises.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2bcd2284a09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Rise and Rise of M-Commerce]]></title>
            <link>https://medium.com/@ajdin.imsirovic/the-rise-and-rise-of-m-commerce-420cbe951328?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/420cbe951328</guid>
            <category><![CDATA[shopping]]></category>
            <category><![CDATA[payments]]></category>
            <category><![CDATA[banking]]></category>
            <category><![CDATA[wechat]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Sun, 15 Dec 2019 09:39:18 GMT</pubDate>
            <atom:updated>2019-12-15T09:49:10.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RGQRvTSwjjfN6331" /><figcaption>Photo by <a href="https://unsplash.com/@jonasleupe?utm_source=medium&amp;utm_medium=referral">Jonas Leupe</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>April 21, 2015, was the day of one of many Google search engine algorithm updates. Chuck Price dubbed it <em>Mobilegeddon</em>, in <a href="https://www.searchenginewatch.com/2015/04/21/google-mobilegeddon-has-officially-arrived/">his article</a> published on March 9, 2015. The reason for such an apocalyptic name for a simple search engine update? It symbolized the end of an era where desktop-based browsing was a major way in which most people accessed the internet.</p><p>This Google algorithm update goes hand-in-hand with smartphone adoption and market penetration. According to <a href="https://www.statista.com/statistics/203734/global-smartphone-penetration-per-capita-since-2005/">statista.com</a>, the global smartphone penetration rate has been increasing year over year, from 33.5% in 2016 to the projected 44.9% in 2020. As mobile devices become more popular the world over, an ever-increasing number of people is using them to stay in touch, consume content, and shop online.</p><p>According to <a href="https://www.emarketer.com/articles/topics/retail-ecommerce">emarketer.com</a>, by the end of next year, 54% of all e-commerce sales will be conducted via mobile commerce. This is not surprising. A <a href="https://www.forbes.com/sites/cherylsnappconner/2013/11/12/fifty-essential-mobile-marketing-facts/#300144d27475">study</a> shows that 70% of all searches on mobile devices have an action as a result, inside the first hour from when the search happened.</p><p>As more people are spending an increasing amount of time on their mobile devices, businesses, big and small, are trying to get a piece of the action.</p><p>The battle for our pockets has moved from the wallet to the smartphone.</p><p>There are several market segments where this battle is fought, but three of them stand out:</p><ul><li>Near Field Communication (NFC)</li><li>Messaging Services</li><li>Direct Carrier Billing</li></ul><h3>Near Field Communication and Banking</h3><p>NFC is based on RFID technology (the term is an acronym for Radio Frequency Identification). RFID is a form of wireless data transfer, and it is used for communication using short distance, high-frequency radio waves.</p><p>On each side of an NFC connection, there is an NFC chip, which makes the wireless communication possible. The communication is triggered once the two chips get close to each other.</p><p>NFC is a technology that has already been around for some time; it has been in use for payments via credit cards for almost two decades. The first contactless card using near-field communication was <a href="https://newsroom.mastercard.com/2018/01/17/dispelling-the-myths-the-reality-about-contactless-security-2/">introduced by Mastercard</a> in 2003.</p><p>The worldwide rise of mobile usage has lead to mobile phones as a perfect replacement for contactless cards. Many financial technology news outlets have reported on many strategic alliances between banks and various IT companies. The goal of these alliances is to “rule our pockets” — to be <em>the way</em> we pay. For example, <a href="https://www.fintechfutures.com/2017/11/erste-austria-chooses-gd-mobile-security-for-mobile-payments/">fintechfutures.com</a> reported Erste Austria bank choosing the G+D Mobile Security company to facilitate their NFC mobile payments. The same site reports on many other similar initiatives.</p><h3>WeChat Messenger Payment Platform</h3><p>WeChat is a messaging app owned by Tencent. WeChat is the most popular app in this market niche, with over 1 billion monthly users. Initially, it was used just for messaging, similar to Facebook’s Messenger or Rakuten’s Viber.</p><p>However, WeChat quickly progressed from a mere messaging app to include various other functionalities. Using unique QR codes, users can exchange their contact information. This provides a viable alternative to using phone numbers to add contact information. It is simply more convenient to just scan a new acquaintance’s QR code from WeChat than it is to, say, type in their name and phone number.</p><p>Soon enough, WeChat became a means of payment. With WeChat, it’s possible to pay for any goods or services, big or small. Similar to how users can scan each other’s QR codes, shops and other places of business can charge customers using their WeChat barcode.</p><p>Today, WeChat is a platform that allows other companies to publish their apps inside the WeChat ecosystem, rather than publishing them independent of the WeChat platform. The upside of this approach is the ability to access WeChat’s market of one billion users.</p><p>Similar to WeChat, other big companies in the west are trying to replicate its business model, including Facebook with its Messenger.</p><h3>Direct Carrier Billing</h3><p>DCB is another take on mobile payments. Instead of charging a customer’s bank directly, this payment method charges their mobile phone bill. This method of payment is popular in areas where there is limited access to banks or where parts of the population simply don’t have a bank account. Ovum, an independent consultancy with headquarters in London, UK, <a href="https://ovum.informa.com/resources/product-content/global-carrier-billing-forecast-201823-ces003-000352">reports </a>that the global DCB market has increased from the global worth of $14.5 billion in 2014 to $45.7 billion in 2018. Ovum also projects that in 2023, the market will be $79.5 billion worth globally.</p><h3>Conclusion</h3><p>Banks are quickly turning our mobile phones into our mobile wallets. Messaging apps are allowing us to communicate with each other and with retailers, both online and in-person. Technologies like direct carrier billing make it possible to utilize m-commerce even without a bank account. It is becoming obvious that our mobile phones, with their ever-increasing market penetration and user-base, will be the way to pay, receive shopping-related information, and communicate. Mobile commerce is here to stay.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=420cbe951328" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Doing a demo]]></title>
            <link>https://medium.com/@ajdin.imsirovic/doing-a-demo-7214fc0fb393?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7214fc0fb393</guid>
            <category><![CDATA[checklist]]></category>
            <category><![CDATA[présentation]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[kaizen]]></category>
            <category><![CDATA[atul-gawande]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Sat, 19 Oct 2019 03:57:41 GMT</pubDate>
            <atom:updated>2019-10-19T03:57:41.391Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>The one thing that connects medical doctors, airline pilots, software companies, and Japanese productivity</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CPEJmTAXoZtscCtG" /><figcaption>Photo by <a href="https://unsplash.com/@austindistel?utm_source=medium&amp;utm_medium=referral">Austin Distel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There’s this medical doctor, named Atul Gawande.</p><p>He’s a general surgeon, working at a hospital in Boston.</p><p>He’s also a staff writer for <em>The New Yorker</em>.</p><p>Furthermore, he’s an assistant professor at <em>Harvard Medical School</em>.</p><p>Would you like to sit down with this guy for a coffee? Pick his brain, ask him a few questions that sometimes crossed your mind?</p><p>Me, I’d love to do that, for sure.</p><p>And there’s a pretty easy way for me to do so, any time I feel like it.</p><p>Because this guy wrote a book.</p><p>And not just any book.</p><p>His book is titled <a href="https://www.amazon.com/Checklist-Manifesto-How-Things-Right/dp/0312430000"><em>The Checklist Manifesto: How to Get Things Right</em></a>.</p><p>And this book’s title hits the nail right on the head because it’s very close to what this post is about: <em>Doing a demo</em>.</p><p>The premise of his book starts with a common-sense observation: The world is complex, our collective knowledge is vast, and human beings are prone to errors, both of judgment and memory. That’s why we should be using one powerful and simple tool: <em>the checklist — </em>a lot more often then we do presently.</p><h4>Planes, doctors, and agile software demoing</h4><p>The original place of checklists was the commercial airline industry. Before every flight, a pilot and a co-pilot go through a series of checks, to make sure they deliver to the best of their abilities.</p><p>The initial premise of <em>The Checklist Manifesto</em> is defended by the author throughout the book: we can, and should, apply the checklist tool to any area of human activity where excellent performance is necessary, so that we can consistently, correctly, and safely perform a series of complex tasks.</p><p>Besides the airline industry, another place where this is crucial is the healthcare industry.</p><p>I firmly believe that any person undergoing a complex medical procedure would be happy to know that the medical staff performing the task is going through a series of checks, tested and retested, and improved over the countless past procedures.</p><p>If any patient was to be asked whether they’d like their doctors to perform such a series of checks from a predefined checklist, it seems to me that the only logical answer would be a resounding “yes”.</p><p>I believe that the conclusion here is obvious: We, workers in the software development industry, have a thing or two to learn from the pilots and the doctors.</p><p>When doing a demo for our clients, it would benefit us immensely to utilize a checklist.</p><h3>How in the world do I checklist a demo?</h3><p>In his ultra-short book, <a href="https://www.amazon.com/Just-ing-Demo-Tactics-Leading-ebook/dp/B00NT66SVW"><em>Just F*cking Demo!</em></a>, the book author, Rob Falcone, gives us a treasure trove of practical advice on making our demos instantly better.</p><p>Let’s take the advice from the above-mentioned book and marry it with the <em>checklist-everything</em> approach. We’ve just gotten ourselves an actionable demo checklist!</p><p>Note that this is not a one-time process. It’s not an easy process either. However, there’s another tool that we can put to good use here: the principle of <em>kaizen</em>.</p><h3>Continuous improvement and agile demo checklists</h3><p>Sakichi Toyoda is the founder of Toyota. In the 1950s the Toyota company piloted <em>Kaizen</em>, a system of implementing continuous quality improvements throughout the company, including technology, processes, company culture, productivity, safety, and leadership.</p><p>The philosophy of <em>Kaizen </em>is based on continuous small improvements and continuous efforts at reducing waste.</p><p>The focus on continuous improvement can be seen in another one of Toyota’s inventions: just-in-time manufacturing.</p><p>This is a prime example of a dedication to <em>Kaizen </em>bearing fruits in unexpected ways, spilling over into other areas of a company’s performance, boosting creativity and innovation.</p><p>How could we in the IT sector, see the benefits of the <em>Kaizen </em>approach in general?</p><p>What could we expect from it when applied to software demoing in particular?</p><p>The thing that immediately comes to mind is that once we’ve created all the checklists for our software demoing, we can apply <em>Kaizen </em>to constantly monitor the performance of our software demos, analyze what went wrong and find the ways to both make it better and “reduce the waste” next time around.</p><p>Obviously, this should be a team effort.</p><p>Similar to a pilot and a co-pilot performing checklists pre-flight, preparing and analyzing both a great software demo and a catastrophic one, should involve at least two team members in your organization.</p><p>Where to go from here?</p><p>Just implement <em>Kaizen</em> and carve out your company’s best practices through experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7214fc0fb393" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Anatomy of a JavaScript function, (part 2)]]></title>
            <link>https://medium.com/@ajdin.imsirovic/the-anatomy-of-a-javascript-function-part-2-f25217f6b785?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f25217f6b785</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Fri, 18 Oct 2019 13:31:01 GMT</pubDate>
            <atom:updated>2019-11-22T10:54:41.675Z</atom:updated>
            <content:encoded><![CDATA[<h4>Let’s learn how to generalize functions in JS!</h4><p>This article was originally published on my own website, <a href="https://www.codingexercises.com/">CodingExercises.com</a>.</p><p>If you like white I do, please support the site by <a href="https://www.codingexercises.com/learn-to-code/the-anatomy-of-a-javascript-function-part-2">visiting the original article</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TRNkpUVu-8YBP-I0" /><figcaption>Photo by <a href="https://unsplash.com/@kobbymendez?utm_source=medium&amp;utm_medium=referral">Kobby Mendez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you are brand new to functions in JavaScript, I warmly recommend <a href="https://medium.com/@ajdin.imsirovic/the-anatomy-of-a-javascript-function-part-1-49a71d48dfb1">reading part 1</a> first.</p><p>Let’s quickly revise what we’ve learned:</p><p>Javascript functions are <em>like machines</em>.</p><p>We can <em>define them</em> — i.e “build the machine”.</p><p>We can <em>call them</em> — i.e “run the machine”.</p><p>We can define what inputs (“raw materials”) the machine will take — i.e we specify <em>function parameters</em>.</p><p>We can give the actual inputs to the machine when we run it — i.e we call our function, and we <em>pass in arguments</em> it will use.</p><p>In part 1, we’ve seen an example of a Bottle Capper machine and then we wrote a JavaScript function to imitate that behavior.</p><p>When we built the Bottle capper machine in the form of the bottleCapper function, we gave it two parameters: a bottle and a cap.</p><pre>function bottleCapper(bottle, cap) {<br>  return bottle + cap;<br>}</pre><p>Now we realize that we want to build another machine. This one will staple two pieces of paper together, so we’ll call it paperStapler.</p><pre>function paperStapler(firstPiece, secondPiece) {<br>  return firstPiece + secondPiece<br>}</pre><p>And now we can run it too, just like this:</p><pre>paperStapler(“Page 1”, “Page 2”)</pre><p>Great! We’ve just built and ran our new machine!</p><p>Soon enough, if we keep going like this, we might have a full warehouse of those things!</p><p>We just think of a simple machine, and <em>poof — </em>we build it, just like that.</p><p>Things can’t possibly get better than this, right?</p><p>Or can they?</p><p>Truth is, if we compare our bottleCapper and our paperStapler , we’ll see they’re doing almost the exact same thing.</p><p>Even their structure is almost the same. <strong><em>Generally</em></strong>, we could look at it like this:</p><pre>function machineName(something1, something2) {<br>  return something1 + something2<br>}</pre><p>Taking things even further, let’s change a rather non-descript machineName function name and call it concatenateArgs.</p><p>“Concatenate” is a fancy way of saying “put them together”, and “Args” is just an abbreviation of “Arguments”.</p><p>We can make our function name even shorter, and call it concatArgs.</p><p>Instead of something1 and something2, let’s give it a more generic a and b.</p><p>Now we have our updated function definition:</p><pre>function concatArgs(a, b) {<br>  return a + b<br>}</pre><p>We’ve just built a magical machine! We no longer have to specify if it’s a <em>Bottle capper </em>or a <em>Paper stapler </em>— whatever two things we give it, it will put them together.</p><p>Thus, instead of filling up our warehouse with a bunch of machines that <strong><em>generally</em></strong> do the same thing, we’ve just built a single one that’s gonna do <em>all</em> the work. Pretty cool stuff!</p><h3>Generalizing functions</h3><p>Hopefully you’ve caught me writing the word “generally” in the previous section twice. It was a hint at the formal name for what we did in the previous section: <em>We took the </em><em>bottleCapper and the </em><em>paperStapler functions and we </em><strong>generalized<em> </em></strong><em>them into </em><em>concatArgs.</em></p><p>Generalizing makes our functions applicable to more situations.</p><p>Let’s look at another example to see this in practice.</p><p>Let’s say we want to allow a user to give us a number, and we’ll tell our user if that number is divisible by 2.</p><p>Of course, this is a trivial example, but our focus here is on <em>function generalization</em>; our focus is <em>not </em>on building complex functions.</p><p>We’ll keep things even simpler and use ES5 syntax:</p><pre>var divisibleByTwo = function() {<br>  var num = Number(prompt(&quot;Enter a number&quot;))<br>  var testResult = num % 2;<br>  if (testResult == 0) {<br>    alert (&quot;This number IS divisible by 2&quot;);<br>  } <br>  if (testResult != 0) {<br>    alert (&quot;This number ISN&#39;T divisible by 2&quot;);<br>  }<br>}</pre><p>In the above function, we’re keeping things as simple as possible:</p><ul><li>On line 1, we start to define our function</li><li>On line 2, we <em>prompt</em> the user for an answer. Since that answer is a string, we convert it to a number using the native Number() function</li><li>On line 3, we declare the testResult variable; we also store the result of num % 2 inside of it. The % is the modulus operator, and returns the remainder of division. If our number is divisible by 2, there will be no remainder — i.e the remainder of such division is <strong><em>zero</em></strong>.</li><li>On lines 4, 5, and 6, we test if the value stored in testResult is indeed a zero. If it is, we’ll alert the message: <em>This number IS divisible by 2.</em></li><li>On lines 7, 8, and 9, we test if the value stored in testResult is not a zero. This means that our division has a remainder, such as if we divided 3 with 2, or 5 with 2, or 7 with 2, etc. If this if statement’s condition is satisfied, we’ll alert the message: <em>This number ISN’T divisible by 2.</em></li></ul><p>Let’s now imagine that we need to check if user input is <strong><em>divisible by 3</em></strong>.</p><p>We could write a similar function to the one we just saw:</p><pre>var divisibleByThree = function() {<br>  var num = Number(prompt(&quot;Enter a number&quot;))<br>  var testResult = num % 3;<br>  if (testResult == 0) {<br>    alert (&quot;This number IS divisible by 3&quot;);<br>  } <br>  if (testResult != 0) {<br>    alert (&quot;This number ISN&#39;T divisible by 3&quot;);<br>  }<br>}</pre><p>This function, just like the previous one, works perfectly.</p><p>But how do we make a function that will check if a number is divisible by any other number, without remainder? Do we write an infinite number of functions, for each specific number?</p><p>Of course not. That would be silly.</p><p>Instead, we write a generalized divisibleByX function, like this:</p><pre>var divisibleByX = function() {<br>  var testedNumber = Number(prompt(&quot;Enter the num to be tested&quot;));<br>  var x = Number(prompt(&quot;Enter the num that tests&quot;));<br>  var testResult = testedNumber % x;<br>  if (testResult == 0) {<br>    alert (&quot;This number IS divisible by &quot; + x);<br>  } <br>  if (testResult != 0) {<br>    alert (&quot;This number ISN&#39;T divisible by &quot; + x);<br>  }<br>}</pre><p>Now we can run our function, and we’ll be asked two questions:</p><ol><li><em>Enter the num to be tested </em>— I’ve typed in <strong><em>15</em></strong>.</li><li><em>Enter the num that tests </em>— I’ve typed in <strong><em>5</em></strong>.</li></ol><p>Once we give these two answers, we’ll get back the following message:</p><p><em>This number IS divisible by 5.</em></p><p>If we give a different answer, such as <strong><em>16</em></strong> and <strong><em>5</em></strong>, the message will be:</p><p><em>This number ISN’T divisible by 5.</em></p><p>Great! We’ve just learned how to generalize functions in JavaScript.</p><p>This wraps up part 2 of the Anatomy of a JavaScript function.</p><p>In part 3, we’ll learn about differences between ES5 and ES6 functions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25217f6b785" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using ngx-bootstrap on Stackblitz with Angular 8]]></title>
            <link>https://medium.com/@ajdin.imsirovic/using-ngx-bootstrap-on-stackblitz-with-angular-8-cc3e9fda6e25?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc3e9fda6e25</guid>
            <category><![CDATA[ngx-bootstrap]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[stackblitz]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Mon, 02 Sep 2019 20:26:23 GMT</pubDate>
            <atom:updated>2019-11-22T11:00:07.732Z</atom:updated>
            <content:encoded><![CDATA[<p>I have published a series of 8 articles on using ngx-bootstrap components in Angular 8 on Stackblitz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LCx2iZwO1COYxbbp" /><figcaption>Photo by <a href="https://unsplash.com/@halgatewood?utm_source=medium&amp;utm_medium=referral">Hal Gatewood</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Here I’ll republish the first article in the series.</p><p>We’ll begin by listing all the articles in the article series:</p><ol><li><a href="https://www.codingexercises.com/guides/how-to-prototype-bootstrap-layouts-with-angular-8-part-1">Working with the <strong>accordion </strong>component</a></li><li><a href="https://www.codingexercises.com/guides/how-to-prototype-bootstrap-layouts-with-angular-8-part-2">Building a Bootstrap-styled navbar with the <strong>collapse </strong>component</a></li><li><a href="https://www.codingexercises.com/guides/working-with-ngx-bootstrap-tabs-in-angular-8">Adding <strong>tabs</strong> in ngx-bootstrap and Angular 8</a></li><li><a href="https://www.codingexercises.com/guides/working-with-ngx-bootstrap-alerts-in-angular-8">Working with ngx-bootstrap <strong>alerts</strong> in Angular 8</a></li><li><a href="https://www.codingexercises.com/guides/working-with-ngx-bootstrap-buttons-carousel-datepicker-and-dropdowns-in-angular-8">Using <strong>buttons</strong>, <strong>carousel</strong>, <strong>datepicker</strong>, and <strong>dropdowns</strong></a></li><li><a href="https://www.codingexercises.com/guides/working-with-ngx-bootstrap-modals-pagination-popover-and-progress-bar-in-angular-8">Adding <strong>modals</strong>, <strong>pagination</strong>, <strong>popover</strong>, and <strong>progress bars</strong></a></li><li><a href="https://www.codingexercises.com/guides/working-with-ngx-bootstrap-rating-sortable-timepicker-and-tooltip-in-angular-8">Working with rating, sortable, timepicker, and tooltip components in Angular 8</a></li><li><a href="https://www.codingexercises.com/guides/working-with-ngx-bootstrap-typeahead-in-angular-8">Implementing the <strong>typeahead </strong>component in ngx-bootstrap</a></li></ol><p>Let’s start!</p><h3>From the barebones Stackblitz app to the finished example</h3><h4>Step 1: Add app-routing.module.ts</h4><p>In the src/app/ folder, add a new file, call it app-routing.module.ts, and add the following code to it:</p><h4>Step 2: Import the app-routing.module.ts into the app.module.ts, and use it</h4><p>Back inside app.module.ts, we need to import the newly-added routing module. At the top of the file, at the bottom of the list of imports, add the following line:</p><pre>import { AppRoutingModule } from &#39;./app-routing.module&#39;;</pre><p>Still inside app.module.ts, in order to tell the AppModule class to use the AppRoutingModule, we need to add it to the list of imports:</p><pre>imports:      [ BrowserModule, FormsModule, AppRoutingModule ],</pre><p>Next, we’ll add Bootstrap to our app.</p><h4>Step 3: Add Bootstrap 4 dependency</h4><p>Stackblitz makes it really easy to add a dependency to it. One such dependency is npx-bootstrap, which is simply an Angular-adjusted implementation of Bootstrap.</p><p>Why use ngx-bootstrap instead of regular Bootstrap? The main reason is that Angular doesn’t use jQuery, but rather has it’s own implementation of the JavaScript functionality in Bootstrap. An example of this is the navbar and its toggle button.</p><p>We are not really concerned with this at the moment because our focus is on just adding components rather than building fully functional pages.</p><p>Like we mentioned at the beginning of this section, with Stackblitz, it is really easy to add a dependency to our Angular projects. In a local development environment, we’d need to use NPM to install any additional dependency. On Stackblitz, we just click the “DEPENDENCIES” dropdown, and type the package name, like in the following image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lnbsVjpm8sxpXsaI.PNG" /></figure><p>Now we’ll simply press the ENTER key to have the dependency added. Doing so will make a notification appear at the very top of the app, updating us on the progress of the installation of the new dependency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cSnxxxO2J7ya2--Y.PNG" /></figure><p>Once done, our ngx-bootstrap dependency shows in the list of other dependencies in the dependency dropdown.</p><p>Next, we’ll add our first component.</p><h4>Step 4: Add a Bootstrap component</h4><p>In this step, we’ll add an accordion component.</p><p>The documentation for the ngx-bootstrap accordion component is <a href="https://valor-software.com/ngx-bootstrap/#/accordion"><strong>available here</strong></a>.</p><p>To add this accordion component, we’re going to need at least 2 files: the template file, and the component file. We’ll also group these files into a separate folder.</p><p>Thus, we first need to add a new folder in Stackblitz. To do that, hover over the app folder, and right-click on it. This will make a contextual menu appear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/0*z-RlY5EJ9ITGDp3a.PNG" /></figure><p>Now, simply click on the “New Folder” command, and type the new folder name: accordion.</p><p>To add a new file to our new accordion folder, we hover over the folder, right-click it, and click on the “New File” command, then type the name of our new file. We’ll be adding two files:</p><ul><li>accordion.component.ts</li><li>accordion.component.html</li></ul><p>We’ll be copying the actual code from the official ngx-bootstrap accordion’s documentation page, available here: <a href="https://valor-software.com/ngx-bootstrap/#/accordion#basic-accordion"><strong>https://valor-software.com/ngx-bootstrap/#/accordion#basic-accordion</strong></a>.</p><p>This is the code for the accordion.component.ts file:</p><pre>import { Component } from &#39;@angular/core&#39;;<br> <br>@Component({<br>  selector: &#39;demo-accordion-basic&#39;,<br>  templateUrl: &#39;./accordion.component.html&#39;<br>})<br>export class DemoAccordionBasicComponent {}</pre><p>This is the code for the accordion.component.html file:</p><pre>&lt;accordion&gt;<br>  &lt;accordion-group heading=&quot;Static Header&quot;&gt;<br>    This content is straight in the template.<br>  &lt;/accordion-group&gt;<br>  &lt;accordion-group heading=&quot;Another group&quot;&gt;<br>    &lt;p&gt;Some content&lt;/p&gt;<br>  &lt;/accordion-group&gt;<br>  &lt;accordion-group heading=&quot;Another group&quot;&gt;<br>    &lt;p&gt;Some content&lt;/p&gt;<br>  &lt;/accordion-group&gt;<br>  &lt;accordion-group heading=&quot;Another group&quot;&gt;<br>    &lt;p&gt;Some content&lt;/p&gt;<br>  &lt;/accordion-group&gt;<br>&lt;/accordion&gt;</pre><p>Note that we could have added two additional files to our accordion folder, namely:</p><ul><li>accordion.component.css (an optional component-specific CSS file)</li><li>accordion.component.spec.ts (a unit-testing file)</li></ul><p>Adding these files is optional, and since we’re trying to keep things simple, we’re choosing not to add them.</p><p>Now that we’ve built our accordion file, we need to use it. We’ll do that next.</p><p>To view the code of our app so far, refer to <a href="https://github.com/ImsirovicAjdin/angular-quickly-prototype-bootstrap-4/commit/69ced29657d58b927dab243424e5e03f90bb848f"><strong>this Github commit</strong></a>.</p><h4>Step 5: Display the newly-added Bootstrap component in our AppComponent</h4><p>We’ll add the new DemoAccordionBasicComponent to our AppComponent.</p><p>To do that, we simply need to add a custom html element, whose name corresponds to the value of the selector key inside the @Component decoration in the accordion.component.ts file.</p><p>In other words, we need to add the following line of code to app.component.html:</p><pre>&lt;demo-accordion-basic&gt;&lt;/demo-accordion-basic&gt;</pre><p>After adding the above code to app.component.html and saving it, we’ll see the following error in the web page preview:</p><pre>...<br>Template parse errors:<br>&#39;demo-accordion-basic&#39; is not a known element:<br>1. If &#39;demo-accordion-basic&#39; is an Angular component, then verify that it is part of this module.<br>...</pre><p>We can ignore the rest of the error message, because the solution of our error is right there: we need to add the demo-accordion-basic element to the AppModule, so that the app.component.html template file is aware of it.</p><p>To do that, we’ll go to the app.module.ts file, and add the exported class name to our declarations array inside the @NgModule decorator:</p><pre>declarations: [ AppComponent, HelloComponent, DemoAccordionBasicComponent ],</pre><p>Of course, to have the component available in declarations, we still need to import it inside app.module.ts. At the bottom of the list of imports, add the following line:</p><pre>import { DemoAccordionBasicComponent } from &#39;./accordion/accordion.component&#39;;</pre><p>When we save everything, we’ll get another template parse error. This one reads:</p><pre>Template parse errors:<br>&#39;accordion-group&#39; is not a known element:<br>1. If &#39;accordion-group&#39; is an Angular component, then verify that it is part of this module.</pre><p>Similar to the previous error, we can safely ignore the rest of the error as the solution is obvious. Angular doesn’t recognize the &lt;accordion-group&gt; custom HTML element. To add it, we’ll need to import it into the module, like this:</p><pre>import { AccordionModule } from &#39;ngx-bootstrap/accordion&#39;;</pre><p>Of course, we also need to add it to the imports array:</p><pre>imports:      [ BrowserModule, FormsModule, AppRoutingModule, AccordionModule ],</pre><p>We can see that we’re getting somewhere because our template parse errors are gone and we are greeted with the Can&#39;t find package error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CdyDfbEZ0mlT8RcL.PNG" /></figure><p>This time, our fix is to just click the blue-colored “Install package” button.</p><p>Now our app loads successfully, but the &lt;demo-accordion-basic&gt; custom HTML element is not showing on the page.</p><p>To understand the issue, we can click on the console toggle in the bottom right corner of the browser window. This will make the built-in Stackblitz console visible. We can now see another error:</p><pre>NullInjectorError: No provider for AccordionConfig!</pre><p>Here is the screenshot with our current error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_DIa7H70MUlqxXTV.PNG" /></figure><p>To fix this, we need to add the forRoot() method to our AccordionModule import, like this:</p><pre>imports:      [ BrowserModule, FormsModule, AppRoutingModule, AccordionModule.forRoot() ],</pre><p>This will throw another error: NullInjectorError: No provider for AnimationBuilder!.</p><p>To fix this, we can refer to <a href="https://stackoverflow.com/questions/51530877/nullinjectorerror-no-provider-for-animationbuilder-in-angular-6"><strong>this StackOverflow answer</strong></a>.</p><p>The fix is simple enough: import the BrowserAnimationsModule. First we’ll add it to the imports array:</p><pre>imports:      [ BrowserModule, FormsModule, AppRoutingModule, AccordionModule.forRoot(), BrowserAnimationsModule ],</pre><p>Finally, we’ll import it so that it can be used in the imports array:</p><pre>import { BrowserAnimationsModule } from &#39;@angular/platform-browser/animations&#39;;</pre><p>The code for the app at this stage can be found in <a href="https://github.com/ImsirovicAjdin/angular-quickly-prototype-bootstrap-4/commit/24c1fdec20a05a3f9fae98799aba549f7ae06e6b"><strong>this Github commit</strong></a>.</p><h4>Final Touches</h4><p>To add a smooth animation to the accordion, all it takes now is to add the isAnimatedproperty binding to the &lt;accordion&gt; element in the template, and set it to true, like this:</p><pre>&lt;accordion [isAnimated]=&quot;true&quot;&gt;</pre><p>Also, currently we have the JavaScript behavior inside Angular taken care of. That’s what we’ve been working on all along! But, what about the styles? We have the working accordion, but the styles are not there.</p><p>We need to install another dependency to our Stackblitz app, plain old “bootstrap”. This will add the necessary bootstrap css file.</p><p>This time, we’ll first add a call to the bootstrap.min.css file, inside the non-existent bootstrap folder, inside the node_modules folder.</p><p>We’ll need to open the the angular.json file, and update the “styles” entry, like this:</p><pre>&quot;styles&quot;: [<br>    &quot;../node_modules/bootstrap/dist/css/bootstrap.min.css&quot;,<br>    &quot;src/styles.css&quot;<br>],</pre><p>Once you save the updated angular.json file, you’ll get the following error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ryYDX-C7XQu4NIUs.PNG" /></figure><p>To fix the error, simply click the big blue “Install package” button, and voila: your styles are showing.</p><p>Now we have a working accordion, with all the Bootstrap styling, just like we set out to do at the beginning of this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NYV2YJwBG_tTPKY_.PNG" /></figure><p>The github commit for the app at this stage <a href="https://github.com/ImsirovicAjdin/angular-quickly-prototype-bootstrap-4/commit/b36bf5be4dc844a642acb3f25948e0f364da4e2f"><strong>can be found here</strong></a>.</p><h3>Conclusion and summary</h3><p>We’ve just added a completely functional, standalone accordion component to our Angular app, with the help of ngx-bootstrap.</p><p>To reiterate what we’ve covered in this article, when you’re adding a new component to an existing module in Angular, these are the steps to follow:</p><ol><li>Add Bootstrap 4 dependency (ngx-bootstrap), if not installed already</li><li>Add a new folder for a component we want to use (and add at least the *.component.ts and *.component.html files)</li><li>Display the new component as a custom HTML element (the name of the element is specified in the component class’ selector entry inside the @Component decorator)</li><li>Fix potential template parse errors by following advice in error messages</li><li>Specify Bootstrap styling inside the angular.json file</li></ol><p>In this article, we’ve seen how to add the accordion component. In the next article in this series, we’ll look at how to add some other components to our Bootstrap layout prototypes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc3e9fda6e25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add a custom pipe to Angular 8]]></title>
            <link>https://medium.com/@ajdin.imsirovic/add-a-custom-pipe-to-angular-8-e0124931813d?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0124931813d</guid>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[custom]]></category>
            <category><![CDATA[pipes]]></category>
            <category><![CDATA[angular8]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Fri, 23 Aug 2019 13:54:51 GMT</pubDate>
            <atom:updated>2019-12-12T12:12:01.287Z</atom:updated>
            <content:encoded><![CDATA[<p>In this short article, you’ll see how to add a custom pipe to your Angular app. The purpose of a custom pipe is some custom formatting on your data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M3LVK-2Ks4oulqKk" /><figcaption>Photo by <a href="https://unsplash.com/@samthewam24?utm_source=medium&amp;utm_medium=referral">Samuel Sianipar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>For this simple demonstration, we’ll be using the Stackblitz website, and it’s default Angular barebones app. The only twist here is: Instead of showing “Hello Angular!” on the screen, we’ll show just “Hello A!”.</p><p>Here’s the link:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular-phs1lx%3Fembed%3D1&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular-phs1lx&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/463a73348353c5267ec5a2dabb5d66eb/href">https://medium.com/media/463a73348353c5267ec5a2dabb5d66eb/href</a></iframe><p>There are only a few steps to take when making a custom pipe:</p><h4>The First Step: Add the pipe in a new file.</h4><p>In the root of the Stackblitz default Angular app, let’s add a new file and call it asdfasdf. Then we’ll add the following code:</p><pre>import { Pipe, PipeTransform } from &#39;@angular/core&#39;;</pre><pre>@Pipe({name: &#39;trimStr2&#39;})<br>export class TrimStrTwo implements PipeTransform {<br>  transform(str: string): string {<br>    const takeFirst1 = str.substring(0,1);<br>    return takeFirst1;<br>  }<br>}</pre><h4>The Second Step: Import the pipe into the appropriate module.</h4><p>Since the starter Stackblitz Angular app only has a single module (app.module.ts), that’s where we’ll import the pipe, like this:</p><pre>import { TrimStrTwo } from &#39;./trim-str2.pipe&#39;;</pre><p>Now we just need to add it to the list of declarations:</p><pre>declarations: [ AppComponent, HelloComponent, TrimStrTwo ],</pre><h4>Step 3: Use the pipe as needed</h4><p>Here, we’ll be using it to trim the word “Angular”, so that only the first letter is shown.</p><p>We need to update this line of code in hello.component.ts:</p><pre>template: `&lt;h1&gt;Hello {{name }}!&lt;/h1&gt;`,</pre><p>The update is just a simple addition of our custom pipe:</p><pre>template: `&lt;h1&gt;Hello {{name | trimStr2 }}!&lt;/h1&gt;`,</pre><p>There you have it! It’s all that it takes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0124931813d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding a Vue project via NPM and using webpack with it]]></title>
            <link>https://medium.com/@ajdin.imsirovic/adding-a-vue-project-via-npm-and-using-webpack-with-it-b93c8b15b25f?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b93c8b15b25f</guid>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Fri, 02 Aug 2019 12:45:36 GMT</pubDate>
            <atom:updated>2020-08-08T06:03:14.581Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will clarify what webpack does with Vue files behind the scenes. To accomplish this, we’ll build everything from scratch and add in different moving parts when we need them.</p><p>Please note that Vue CLI does this automatically. This article is showing what is happening behind the scenes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v1Y8XQxRyztsJV0n" /><figcaption>`Photo by <a href="https://unsplash.com/@iurte?utm_source=medium&amp;utm_medium=referral">Iker Urteaga</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Shameless plug: <br>This text comes from my recent book, <a href="https://www.amazon.com/Vue-js-Quick-Start-Guide-applications/dp/1789344107"><strong>Vue CLI 3 Quick Start Guide</strong></a>, published by <a href="https://www.packtpub.com/web-development/vue-cli-3-quick-start-guide">Packt</a>.</p><p>In this section, we’ll build a new project with NPM, then add webpack to it, and finally add a Vue single file component to it.</p><h3><strong>Make a new directory, install Vue and Webpack, and launch VS Code</strong></h3><p>First, let’s make a new directory by taking the following steps. We’ll call our project npm-vue-webpack.</p><p>Open Git Bash and add a new folder as follows:</p><pre>mkdir npm-vue-webpack &amp;&amp; cd $_</pre><p>Initialize npm as follows:</p><pre><strong>npm init -y</strong></pre><p>Next, install Vue and webpack into our new project as follows:</p><pre><strong>npm install vue webpack webpack-cli --save-dev --verbose</strong></pre><p>Once the NPM installation is complete, we can verify the folders and the contents of package.json as we did earlier in the chapter.</p><p>Next, add the source and output folders our project will use as follows:</p><pre>mkdir dist src</pre><p>Open our new project in VS Code as follows:</p><pre>code .</pre><p>Now, we can add two new files right from the VS Code editor. We’ll call the first file source.js, and we&#39;ll call the second file output.js. Make sure you have added and saved these two empty files in your project at this stage: source.js in the src folder, and output.js in the dist folder.</p><h3>Add our Vue component as a JavaScript module</h3><p>Now let’s add our Vue component.</p><p>First, let’s add this code to source.js as follows:</p><pre>import CustomArticle from &#39;./CustomArticle.js&#39;;</pre><pre>new Vue({<br>    el: &#39;#app&#39;,<br>    render: h =&gt; h(CustomArticle),<br>})</pre><p>On the first line, we’re importing a file called CustomArticle.js.<br>Let’s make a new file inside the src folder. We’ll call this file CustomArticle.js.</p><p>Now let’s add the following code to it:</p><pre>let CustomArticle = Vue.component(&#39;custom-article&#39;, {<br>    template: `<br>      &lt;article&gt;<br>        Our own custom article component!<br>      &lt;/article&gt;`<br>  })</pre><pre>export default CustomArticle;</pre><p>As we can see, we’re using the ESM syntax to export and import a JS module.</p><h3>Compiling JavaScript Modules with Webpack</h3><p>We are almost ready now to compile our source.js to output.js with the help of webpack. However, before we do it, we still need to update the scripts section of our package.json as follows:</p><pre>&quot;scripts&quot;: {<br>    &quot;webpack&quot;: &quot;webpack&quot;<br>},</pre><p>Now, we can run the following command inside Git Bash:</p><pre><strong>npm run webpack ./src/source.js ./dist/output.js</strong></pre><p>As expected, we see the output in the console, together with the warning about setting the mode option. We now know what this means, so it’s not important to deal with it at this time.</p><p>If we inspect the contents of output.js, we&#39;ll see that it&#39;s empty, and that, by default, webpack minified and obfuscated our output code to the default main.js file as follows:</p><pre>!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i ...</pre><p>This is all good, but how do we make webpack output to a different file, other than the default main.js? We use the webpack configuration file!</p><h3>Adding Options with the Help of Webpack Configuration File</h3><p>Using the webpack configuration file, we can add various options to the way our apps get bundled with webpack. Here is how:</p><p>We’ll begin by adding a new file to the root of our project. We’ll call this webpack.config.js file. Here is the code:</p><pre>module.exports = {<br>  output: {<br>    filename: &#39;output.js&#39;,<br>  }<br>};</pre><p>Now, run our command again as follows:</p><pre>npm run webpack ./src/source.js ./dist/output.js</pre><p>This time it will output to the correct file.</p><p>Note that just as we can specify the output file, we can also specify the input file as follows:</p><pre>module.exports = {<br> entry: &#39;./src/source.js&#39;,<br> output: {<br> filename: &#39;output.js&#39;,<br> }<br>};</pre><p>We still need to render our Vue component somewhere on the screen. We need an HTML file for that.</p><h3>Adding an HTML file so that we can render our Vue component</h3><p>Let’s add a new HTML file, we’ll call it index.html, to our dist folder as follows:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Compiled HTML file&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div id=&quot;entryPoint&quot;&gt;&lt;/div&gt;</pre><pre>&lt;script src=&quot;<a href="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.min.js">https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.min.js</a>&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;output.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Just as we discussed at the very beginning of this chapter, we are adding scripts directly to our HTML in the old-schoolway, by just stacking script tags at the bottom of our HTML file. The first script tag we&#39;re using is fetching Vue from a CDN, and the second script tag fetches our output.js file from the dist folder.</p><p>If you’re using VS Code, you can now right-click on your new dist/index.html file, and click the <strong>Open in default browser</strong> command.</p><p>You will see the following sentence on the web page that opens:</p><p><strong>Our own custom article component!</strong></p><p>Now, we need to give webpack the ability to output an HTML file. For that, we’ll need to use the html-webpack-plugin.</p><h3>Giving webpack the ability to output an HTML file</h3><p>In this section, we’ll see how to output an HTML file using a webpack plugin by taking the following steps.</p><p>First, we’ll install html-webpack-plugin via NPM as follows:</p><pre>npm install html-webpack-plugin --save-dev --verbose</pre><p>Our devDependencies inside package.json have updated accordingly, as follows:</p><pre>&quot;devDependencies&quot;: {<br>    &quot;html-webpack-plugin&quot;: &quot;^3.2.0&quot;,<br>    &quot;vue&quot;: &quot;^2.6.7&quot;,<br>    &quot;webpack&quot;: &quot;^4.29.5&quot;,<br>    &quot;webpack-cli&quot;: &quot;^3.2.3&quot;<br>}</pre><p>Now we’ll update our webpack.config.js, as follows:</p><pre>let HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);</pre><pre>module.exports = {<br>    entry: &#39;./src/source.js&#39;,<br>    output: {<br>        filename: &#39;output.js&#39;,<br>    },<br>    plugins: [new HtmlWebpackPlugin()]<br>};</pre><p>Before we continue, we must delete the index.html file that we had in our dist folder. Don’t worry about deleting it, though, since webpack will soon recreate it.</p><p>Once we’ve deleted index.html, let’s run the webpack script again as follows:</p><pre>npm run webpack</pre><p>Webpack just created a new index.html file for us! Here’s the contents of the file:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Webpack App&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>  &lt;script type=&quot;text/javascript&quot; src=&quot;output.js&quot;&gt;&lt;/script&gt;&lt;/body&gt;<br>&lt;/html&gt;</pre><p>This is all great, but obviously, our file is not the same. We have lost our entry point for the Vue component we had. Also, we need to update our Vue code so that it works as a single file component.</p><h3>Adding a .vue file as a JavaScript module</h3><p>First, let’s update the source.js file, to the following:</p><pre>import Vue from &#39;vue&#39;;<br>import CustomArticle from &#39;./CustomArticle.vue&#39;;</pre><pre>new Vue({<br>    el: &#39;#entryPoint&#39;,<br>    render: h =&gt; h(CustomArticle),<br>})</pre><p>We can now also rename our CustomArticle.js to CustomArticle.vue, and add the following code to it:</p><pre>&lt;template&gt;<br>  &lt;div id=&quot;entryPoint&quot;&gt;<br>      &lt;article&gt;<br>        Our own custom article component!<br>      &lt;/article&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>Unfortunately, webpack doesn’t work with .vue files out of the box. To fix the issue at hand, we need to use a <strong>webpack loader</strong>. A webpack loader helps webpack understand the files it&#39;s working with. There are many loaders out there, but for now, we need to work with Vue.</p><h3>Adding a webpack loader to work with .vue files</h3><p>To work with .vue files, we need to take the following steps:</p><p>First, we need to install a webpack loader called vue-loader via NPM as follows:</p><pre><strong>npm install vue-loader --save-dev --verbose</strong></pre><p>Now that we’ve saved it, we need to use it, and we’ll do that by updating the webpack configuration as follows:</p><pre>let HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);<br>let VueLoaderPlugin = require(&#39;vue-loader/lib/plugin&#39;);</pre><pre>module.exports = {<br>    entry: &#39;./src/source.js&#39;,<br>    output: {<br>        filename: &#39;output.js&#39;,<br>    },<br>    plugins: [<br>        new HtmlWebpackPlugin(),<br>        new VueLoaderPlugin(), <br>    ]<br>};</pre><p>Try running webpack now as follows (<strong>Spoiler alert</strong>: it will fail):</p><pre>npm run webpack</pre><p>The error message we get reads as follows:</p><pre><strong>Error: [VueLoaderPlugin Error] No matching rule for .vue files found.</strong></pre><p>To fix this error, we need to add a rule for our Vue loader, by updating our webpack.config.js file to the following:</p><pre>let HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);<br>let VueLoaderPlugin = require(&#39;vue-loader/lib/plugin&#39;);</pre><pre>module.exports = {<br>    entry: &#39;./src/source.js&#39;,<br>    output: {<br>        filename: &#39;output.js&#39;,<br>    },<br>    module: {<br>        rules: [<br>            { test: /\.vue$/, use: &#39;vue-loader&#39; }<br>        ]<br>    },<br>    plugins: [<br>        new HtmlWebpackPlugin(),<br>        new VueLoaderPlugin(), <br>    ]<br>};</pre><p>The test key inside the array in the rules option receives a regex as a value. This regex is checking for the presence of a file with a vue file extension. If it matches, that is, if it finds a vue file, it will use the vue-loader module on it.</p><p>Let’s run our webpack script again as follows:</p><pre>npm run webpack</pre><p>Running this command now will throw a number of errors and log them into the console, but our focus at this time should be on this one error:</p><pre>ERROR in ./src/CustomArticle.vue<br>Module Error (from ./node_modules/vue-loader/lib/index.js):<br>[vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options</pre><p>Why should we focus on this particular error? Because this error is the one that we need to fix by adding another NPM package, like this:</p><pre><strong>npm install vue-template-compiler --save-dev --verbose</strong></pre><p>The devDependencies entry inside package.json just received another update, as follows:</p><pre>&quot;devDependencies&quot;: {<br>    &quot;html-webpack-plugin&quot;: &quot;^3.2.0&quot;,<br>    &quot;vue&quot;: &quot;^2.6.7&quot;,<br>    &quot;vue-loader&quot;: &quot;^15.6.4&quot;,<br>    &quot;vue-template-compiler&quot;: &quot;^2.6.7&quot;,<br>    &quot;webpack&quot;: &quot;^4.29.5&quot;,<br>    &quot;webpack-cli&quot;: &quot;^3.2.3&quot;<br>  }</pre><p>So, now we can try running webpack again:</p><pre><strong>npm run webpack</strong></pre><p>After webpack ran, if you opened output.js at this time, you&#39;d see that it has the full Vue library inside of it, along with our CustomArticle at the very end. This all compiled without any errors.</p><h3>Fixing the issue with our index.html file</h3><p>We still have the issue of the index.html file in the dist folder. It&#39;s an easy fix! We&#39;ll just add our own index.html file to the src folder, with the following contents:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Compiled HTML file&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div id=&quot;entryPoint&quot;&gt;&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Note that we have now removed our own script tags, since webpack will be adding them. Also, make sure to delete the index.html file inside the dist folder. Now, run the npm run webpack command again, and you&#39;ll get this output in dist/index.html as follows:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Webpack App&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>  &lt;script type=&quot;text/javascript&quot; src=&quot;output.js&quot;&gt;&lt;/script&gt;&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Why is this not working?</p><p>It is not working because we need to update both the JS files to be output, as well as the HTML files. Currently, we are only updating the JS files, but we still need to do it for our index.html file. Luckily, we already have html-webpack-plugin to help out.</p><h4>Delivering HTML files via webpack with the help of html-webpack-plugin</h4><p>We’ll begin by updating the html-webpack-plugin in the webpack.config.js file as follows:</p><pre>plugins: [<br>    new HtmlWebpackPlugin({<br>        template: &#39;./src/index.html&#39;,<br>    }),<br>    new VueLoaderPlugin(), <br>]</pre><p>What we did in the plugins section was, we passed an options object to our HtmlWebpackPlugin() call. Inside this options object, we specified our template: ./src/index.html.</p><p>Before we run the webpack script again, we need to make sure to add the meta tag with charset set to utf-8. Otherwise, we&#39;ll get an error in our console when we open dist/index.html in the browser.</p><p>Let’s now run npm run webpack again. This time, everything works! We get our humble looking sentence on the screen:</p><p><strong>Our own custom article component!</strong></p><p>Congratulations! Although it is humble looking, you have successfully added a Vue app to an NPM-powered project, running on webpack.</p><p>Why is this important?</p><p>It is important because now that we’ve made Vue and webpack work on our own, without the help of Vue CLI, we can better appreciate all the heavy lifting that the Vue CLI and webpack do for us behind the scenes.</p><p>This has been an excerpt from my recent book, <a href="https://www.amazon.com/Vue-js-Quick-Start-Guide-applications/dp/1789344107"><strong>Vue CLI 3 Quick Start Guide</strong></a>, published by <a href="https://www.packtpub.com/web-development/vue-cli-3-quick-start-guide">Packt</a>. If you’d like to find out more about Vue CLI 3, do check it out!</p><p>By the way, if you liked the article, please add a few claps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Cw6747ybZfNHZyo3S6pcbg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b93c8b15b25f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Problem of Learning: Does the World Really Need Another JavaScript Book?]]></title>
            <link>https://medium.com/@ajdin.imsirovic/the-problem-of-learning-does-the-world-really-need-another-javascript-book-db4227fb19f7?source=rss-1c991106bfa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/db4227fb19f7</guid>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[books]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ajdin Imsirovic]]></dc:creator>
            <pubDate>Wed, 01 May 2019 05:09:32 GMT</pubDate>
            <atom:updated>2019-11-22T11:04:03.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fMvOT-Pol2fJUVnk" /><figcaption>Photo by <a href="https://unsplash.com/@jeremybishop?utm_source=medium&amp;utm_medium=referral">Jeremy Bishop</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article has been published as the introduction to my self-published book, <a href="https://leanpub.com/a-better-way-to-learn-javascript">A better way to learn JavaScript</a>.</p><p>There are so many books on JavaScript out there! Why write another one?</p><p>Well, honestly, I believe that most of these books are lacking because they don’t focus on knowledge transfer.</p><p>Those books aren’t badly written. Then aren’t technically incorrect.</p><p>The problem is the one of <strong><em>focus</em></strong>.</p><p>I strongly believe that the authors of these books don’t put themselves into their reader’s shoes.</p><p>Instead, they focus on things that matter. But they just don’t matter enough.</p><p>Another common issue I see in many books is <strong><em>the case of the missing stairs</em></strong> (the sudden jumps in knowledge level needed to comprehend the material).</p><p>Trying to fix the problem of the <strong><em>missing stairs</em></strong>, you inevitably end up with the problem of <strong><em>endless explanation (infinite regression)</em></strong>.</p><p>Finally, once a learner manages to learn something, there is the issue of <strong><em>effective retension</em></strong>.</p><p>It seems to me that most book authors don’t even recognize that these problems exist!</p><p>Maybe, at best, they do recognize them, but they don’t know how to deal with them.</p><p>So they just ignore them.</p><p>Let’s quickly inspect each of these <strong><em>impediments to learning</em></strong>.</p><h3>Impediment #1: Knowledge transfer</h3><p>Before writing this book, I’ve spent years looking for the best way to transfer knowledge.</p><p>I asked myself these questions:<br>- What is the best way to teach a “difficult” concept?<br>- How does an expert teach a begginer so that they clearly understand what’s being taught?<br>- How does a begginer retain and reproduce that knowledge independently?</p><p>In short, <strong><em>what is the best way to transfer knowledge</em></strong>?</p><p>Unfortunately, most coding books focus on <strong><em>knowledge listing</em></strong> — they try their best to make sure that they list out every single bit of syntax, every design pattern, every possible use case.</p><p>It’s almost as if the authors are trying to convince us <strong><em>that they are competent in the subject matter</em></strong>.</p><p>This is misguided, because most authors don’t understand that they are not only supposed to be competent in the language, but even more importantly, they must be <strong><em>competent in the ability to transfer their knowledge</em></strong>.</p><p>In my opinion, <strong><em>you prove competence by giving people results</em></strong>!</p><p>It is much better to effectively teach people to code, than it is to convince them you’re the expert.</p><p>Another common pitfall of many learning materials in the case of the missing stairs.</p><h3>Impediment #2: The Case of The Missing Stairs</h3><p>Let’s imagine that the expertise in JavaScript is like a skyscraper: you have solid foundations, then you get to level 1, then level 2, and so on. The more you know, the higher level you’re on.</p><p>Well, very often in books and courses, the author <strong><em>starts off on the ground floor, and then jumps</em></strong>!</p><p><strong><em>And just like that, you’re on the fifth floor of knowledge!</em></strong></p><p>Which is great, except <strong><em>I’m no super-hero</em></strong>.</p><p>I can’t just skip floors like that!<strong><em> I need a staircase</em></strong>.</p><p>From a learner’s perspective, a staircase is all the underlying knowledge that the learner needs to have <strong><em>BEFORE </em></strong>they are able to fully comprehend a new idea.</p><p>From a teacher’s perspective, a staircase is the knowledge that the teacher assumes you have when you are presented with new knowledge.</p><p>For example, let’s imagine I show you this piece of code:</p><p>x = x + 1;</p><p>And I say: “<em>I’m incrementing the value of x by 1</em>”.</p><p><strong>What is the assumption I’m making here?</strong></p><p>I’m assuming that:<br>- You know that in JS, <strong><em>the = sign does not mean the same as it does in mathematics</em></strong><br>- You know how <strong><em>the plus operator</em></strong> works (and obviously, you know what operators are, including precedence and associativity)<br>- You know what <strong><em>increment </em></strong>means<br>- You know what will be <strong><em>the result of running this line of code</em></strong></p><p>This brings us to another major obstacle to knowledge transfer: <strong><em>endless explanation</em></strong>.</p><h3>Impediment #3: Endless explanation</h3><p>The problem of <strong><em>endless explanation</em></strong> is subtle, but devastating.</p><p>It appears when an expert is aware of <strong><em>the case of the missing stairs</em></strong>, and they try to solve it.</p><p>So they go into every single detail, before they explain the new concept.</p><p>Why is this so bad?</p><p>Because of software complexity, or should we say, knowledge complexity.</p><p>For every new concept I’m trying to explain, I decide to clarify its underlying concepts as well.</p><p>Unfortunately, these underlying concepts also stand on a few other underlying concepts, so I try to explain those as well. This can go on forever, and it’s what I call the problem of <strong><em>endless explanation</em></strong>. We might also call it <strong><em>infinite regression: a series of never-ending questions and answers</em></strong>.</p><h3>Impediment #4: Effective Retention</h3><p>As a 12-year-old, while I was trying to learn English, I stumbled across a genius approach: I learned from music.</p><p>I would get the lyrics to the song.</p><p>I would get the dictionary and find all the words that I didn’t know.</p><p>I would memorize the words even before listening to music.</p><p>I would play the song over, and over, and over again.</p><p>By age 14, I could think in English. Now I consider myself bilingual, or as close to a native speaker as possible.</p><p>How was I able to be so successful? Because I had a process in place that helped me with effective retention.</p><p>One of the biggest problems in learning to code is: what do you do with the knowledge?</p><p>After all, like they say, If you don’t use it, you lose it.</p><p>In this book, I’ll show you how to effectively solve the problem of retention, along with all the others mentioned before it.</p><p>You will be able to reproduce what you learn here, with ease. You will be able to use your new knowledge daily.</p><p>Alright, so that was an excerpt from the introduction to my first self-published book, titled <a href="https://leanpub.com/a-better-way-to-learn-javascript"><strong><em>A Better Way to Learn JavaScript</em></strong></a>.</p><p>What I love about the process of publishing my book on Leanpub is the fact that I can practice kaizen with it.</p><p>Kaizen is a Japanese word meaning “good change”. It is a philosophy in business and everyday life that has gradual continuous improvement at its core.</p><p>Applied to my book, and the way that I view it, it means that by constantly striving to make it better, ultimately this book will become the best possible book on the subject. Or at least, to stay humble, I could say that this book will become the best possible book <em>that I could write </em>on the subject.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db4227fb19f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>