<?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 Bryan Fajardo on Medium]]></title>
        <description><![CDATA[Stories by Bryan Fajardo on Medium]]></description>
        <link>https://medium.com/@BryanFajardo?source=rss-4532d3cfd5b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Fp5O5Xk4vSEp9YYa-dqkkQ.jpeg</url>
            <title>Stories by Bryan Fajardo on Medium</title>
            <link>https://medium.com/@BryanFajardo?source=rss-4532d3cfd5b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 09:24:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@BryanFajardo/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[How to Chain Asynchronous Methods in JavaScript]]></title>
            <link>https://medium.com/swlh/how-to-chain-asynchronous-methods-in-javascript-c363c5d18cdc?source=rss-4532d3cfd5b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c363c5d18cdc</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Bryan Fajardo]]></dc:creator>
            <pubDate>Wed, 04 Dec 2019 08:31:01 GMT</pubDate>
            <atom:updated>2019-12-05T04:24:02.043Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z7cHG77xYeUqwMGYYGSGMA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dezjeff?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jeff Frenette</a> on <a href="https://unsplash.com/s/photos/order?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>If you’ve worked with JavaScript you’ve probably done a thing or two with asynchronous operations. This article will show you how to sequence or chain asynchronous operations so the next one begins after the first is completed. We can use an iterator, loops, or promises to do it in a clean way and avoid doing something like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12940246c8b0cc5d130a1758d05f036c/href">https://medium.com/media/12940246c8b0cc5d130a1758d05f036c/href</a></iframe><p>Here’s why the code above can be problematic:</p><ul><li>Poor readability — as it stands you can see that it is already a bit difficult to read and it will only get worse the more asynchronous operations you add to it and the more code you need to write in between the calls.</li><li>More susceptible to bugs — all code is susceptible to bugs. This snippet of code even more so because we are nesting so much of it. This means that we not only have to be extra careful about variable names but also that we are writing inside of the correct code segment. You can see that I named the responses and errors differently to have to account for this.</li><li>Not reusable —sure we might be able to “reuse” this entire snippet, but what if I only want to use 2 methods instead of 3 next time? Then it becomes unusable.</li></ul><p>So how can we improve this? Let’s start by creating our own <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators">JavaScript iterator</a> to do this for us in a class. First, define an array of methods that will be used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0215d84f85b180151849572986609d74/href">https://medium.com/media/0215d84f85b180151849572986609d74/href</a></iframe><p>We have three AJAX methods we want to call in order. ajax1(seconds), ajax2(), and ajax3(). Please note that these do not need to be AJAX methods, it can be any asynchronous method.</p><p>The route test.ajaxCalls calls a simple PHP function that sleeps for a period of time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d69fe8246152b6d570a4e695564f5d1f/href">https://medium.com/media/d69fe8246152b6d570a4e695564f5d1f/href</a></iframe><p>Now let’s define our method iterator class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e52808a3b52b94bbe8836cbbb8c8d0bc/href">https://medium.com/media/e52808a3b52b94bbe8836cbbb8c8d0bc/href</a></iframe><p>We will save the iterator state inside of the this.iterator variable. We will be referencing this iterator every time the next() function is called. When you create the iterator, implement the <em>iterator</em> <em>protocol </em>by returning an object with <strong>value </strong>and <strong>done </strong>properties.</p><p>In our case value is the next function of our methods array. Done is a <em>boolean </em>that becomes true when there are no more items to iterate over.</p><p>Let’s create the methods that will start our iterator and then keep it going.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60e7d7b1552726cd567b20732c669027/href">https://medium.com/media/60e7d7b1552726cd567b20732c669027/href</a></iframe><p>The execute() function gets our iterator started, all we are doing here is calling iterate() with the first iteration as an argument.</p><p>The iterate(iteration) function takes a specific iteration as an argument. If we are not through consuming our iterator we will call the method (represented by res,iteration.value) and then we will call iterate(iteration) again so that we consume our iterator via <strong>recursion</strong>. Additionally, we can execute some generic action here before moving onto the next iteration. Now, to put our class into action we just need a few lines.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b74637348763694150feb2aa14325a3f/href">https://medium.com/media/b74637348763694150feb2aa14325a3f/href</a></iframe><p>Based on this example we can expect to see the following results <strong>in the console</strong>.</p><pre><strong>[5 SECONDS PASS]</strong><br>ajax1Response: {...}<br>iteratorResponse: {...}<br><strong>[2 SECONDS PASS]</strong><br>ajax2Response: {...}<br>iteratorResponse: {...}<br><strong>[3 SECONDS PASS]</strong><br>ajax3Response: {...}<br>iteratorResponse: {...}</pre><h3>Iterating Over Synchronous and Asynchronous Methods</h3><p>What if we want to iterate over async and non-async functions? In this case let’s change our methods array to contain a list of objects which will have <strong>async </strong>and <strong>func</strong> properties. The <strong>async </strong>property will be a <em>boolean </em>that tells us whether the function is asynchronous and the <strong>func </strong>property is the function that we want to execute.</p><p>The new methods array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7294e7a8be2f42b8b2b2f80b62b6c79/href">https://medium.com/media/b7294e7a8be2f42b8b2b2f80b62b6c79/href</a></iframe><p>You will need to update the iterate(iteration) method inside of methodIterator class to account for these changes. Check whether or not the function is asynchronous first, and then call iteration.func() with or without .then() as necessary. Now we can expect the following results <strong>in the console.</strong></p><pre><strong>[5 SECONDS PASS]</strong><br>ajax1Response: {...}<br>iteratorResponse: {...}<br>Not Asynchronous.<br><strong>[2 SECONDS PASS]</strong><br>ajax2Response: {...}<br>iteratorResponse: {...}<br><strong>[3 SECONDS PASS]</strong><br>ajax3Response: {...}<br>iteratorResponse: {...}</pre><p>Notice how not_async was called immediately, and 2 seconds later, ajax2() returned a response.</p><h3>Come on, there has to be an easier way to do this!</h3><p>Here are two other ways to do this without using the <em>iterator protocol. </em>They are not necessarily easier. It also isn’t necessary to create your own class, though it might be a good idea depending on your needs.</p><p>The first is a for loop that uses await.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13d5ecb436d8336d4c8bcfed4d89f350/href">https://medium.com/media/13d5ecb436d8336d4c8bcfed4d89f350/href</a></iframe><p>This will yield the following <strong>in the console.</strong></p><pre><strong>[5 SECONDS PASS]</strong><br>ajax1Response: {...}<br>Not Asynchronous<br><strong>[2 SECONDS PASS]</strong><br>ajax2Response: {...}<br><strong>[3 SECONDS PASS]</strong><br>ajax3Response: {...}</pre><p>We can also use promises and <a href="https://javascript.info/promise-chaining">promise chains</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f494f0367e32d881fe2ac98782f82cda/href">https://medium.com/media/f494f0367e32d881fe2ac98782f82cda/href</a></iframe><p>Which will yield the following <strong>in the console.</strong></p><pre><strong>[5 SECONDS PASS]</strong><br>ajax1Response: {...}<br>Not Asynchronous<br><strong>[2 SECONDS PASS]</strong><br>ajax2Response: {...}<br><strong>[3 SECONDS PASS]</strong><br>ajax3Response: {...}<br>Methods complete.</pre><p>There are many ways to iterate through asynchronous methods and there are also many use cases for it. If you have any questions, want to point something out, or share an alternative — comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c363c5d18cdc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-chain-asynchronous-methods-in-javascript-c363c5d18cdc">How to Chain Asynchronous Methods in JavaScript</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Send Post Requests Between Laravel Controllers]]></title>
            <link>https://medium.com/swlh/how-to-send-post-requests-between-laravel-controllers-6a1e0cb4dc93?source=rss-4532d3cfd5b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a1e0cb4dc93</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Bryan Fajardo]]></dc:creator>
            <pubDate>Mon, 11 Nov 2019 17:01:03 GMT</pubDate>
            <atom:updated>2019-11-11T17:01:03.137Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Call Post Methods from Laravel Controllers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ViK9OhgSd5Es4parmQpoOg.jpeg" /><figcaption>Photo from <a href="http://pixabay.com/">Pixabay</a></figcaption></figure><p>Sometimes you may come across a need to call a post method from another function in Laravel. These methods may or may not be in the same controllers/classes.</p><p>Say you have a very complex method that accepts Illuminate\Http\Request $request as the argument. The method is normally called from a form or AJAX (Asynchronous Javascript and XML) function. So how would you go about calling that method from another method — maybe even in another class?</p><p>Below we have a very complex method we inherited and don’t want to have to rewrite. The other method is where we want to use the complex method’s return.</p><h4>The Very Complex Method</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b712843bcd041b730bbe64115602b1d7/href">https://medium.com/media/b712843bcd041b730bbe64115602b1d7/href</a></iframe><h4>The Other Method</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8781e0b7fb6bf4a2c50de1fc5baf0b50/href">https://medium.com/media/8781e0b7fb6bf4a2c50de1fc5baf0b50/href</a></iframe><p><em>So what can be done?</em></p><h3>A Non-Preferred Solution</h3><p>We can create a “Calling” function. Copy the actionable parts of the method into another function that can be called. In essence, you are creating a function that retrieves the data from the POST request and then calls the actual function that processes the data bypassing the data as a parameter. So now when veryComplexMethod is called, it will extract the data from the request and pass it into veryComplexMethodProcessing which is the real method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4aaf26ee036c07059467829803e9387b/href">https://medium.com/media/4aaf26ee036c07059467829803e9387b/href</a></iframe><h4><strong>Pros</strong></h4><ul><li>Don’t Repeat Yourself — you are adhering to the DRY principle. You don’t have to rewrite any code.</li></ul><h4><strong>Cons</strong></h4><ul><li>Refactoring — You have to move things around and change things.</li><li>Inconsistency — Not all of your methods may need this, so you will end up with some functions using a calling function and some not.</li><li>In the scenario where you are consistent and all your POST methods do have a calling function, you just increased the number of functions you have to deal with. Your best bet would probably be to make a generic calling function.</li></ul><h3>A Preferred Solution</h3><p>Let’s create a class that will create a request, and then execute any method we want while passing that request as an argument. In other words, we will try to mimic what a form or AJAX call would do.</p><p>For the sake of this example we will call the class <strong>POST_Caller</strong>.</p><p>Let’s start by declaring some variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2c1aa6b2399de2dc1b1ff6bb8d7a199/href">https://medium.com/media/e2c1aa6b2399de2dc1b1ff6bb8d7a199/href</a></iframe><p>Now, let’s setup the constructor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36952a305075884bd25a8309cea6c38e/href">https://medium.com/media/36952a305075884bd25a8309cea6c38e/href</a></iframe><p>Finally, let’s create the caller function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e7ab27b55904bb6578e41d72e650d01/href">https://medium.com/media/4e7ab27b55904bb6578e41d72e650d01/href</a></iframe><p>This solution addresses some issues that the previous solution does not. First, it becomes a generic caller function that works for any method that expects a request in any class. Second, it is actually sending a Request as the argument, which <em>may or may not</em> be important to the functionality of the method you are calling. You also don’t have to refactor the method you are trying to call. In the previous solution we had to move the part that extracted the data from the Request to the caller function, and then pass the extracted data to the method that uses that data.</p><p>Let’s dissect the POST_Caller call() method.</p><p><strong>app($this-&gt;class)</strong></p><p>Here you are creating a Laravel service container instance and binding to it the class of your choice. You get some good things by using the service container this way, here are a few of them.</p><ol><li>Don’t need to use the new keyword.</li></ol><p>2. This returns an instance of the class which you can use right away in the same line.</p><p>3. You do not need to import the class namespace into the scope of POST_Caller through the use keyword.</p><p>Plus other potential benefits that come with the <a href="https://laravel.com/docs/6.x/container">service container</a>.</p><p><strong>{$this-&gt;method}()</strong></p><p>Call a specific method inside of the class we passed in. Using the {} syntax we can dynamically call a method. So if my class was TestingClass::class and the method was runTest. This would be the equivalent of app(TestingClass::class)-&gt;{&#39;runTest&#39;}().</p><p><strong>$this-&gt;requestClass::createFromBase($this-&gt;requestSending)</strong></p><p>We create an Illuminate request from a Symfony Instance. We will pass in our requestClass which is most likely to be anIlluminate\Http\Request but can also be a custom <a href="https://laravel.com/docs/6.x/validation#creating-form-requests">FormRequest</a>.</p><p><strong>return $response</strong></p><p>Then we return whatever response that method returned to us. It is up to the method that is using this class to define how to deal with the return data.</p><p>Finally, we want to put this to use. This is our POST_Caller class in action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3552482074f47a1a7bc681c59d5b87b9/href">https://medium.com/media/3552482074f47a1a7bc681c59d5b87b9/href</a></iframe><p>These are just a couple of ways we can call a method that expects a Request from another method in Laravel. There are <em>probably</em> many more ways to do this. If you have any questions, want to point something out, or share an alternative — comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a1e0cb4dc93" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-send-post-requests-between-laravel-controllers-6a1e0cb4dc93">How to Send Post Requests Between Laravel Controllers</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Psychology of APR and APY]]></title>
            <link>https://medium.com/swlh/the-psychology-of-apr-and-apy-395350176080?source=rss-4532d3cfd5b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/395350176080</guid>
            <category><![CDATA[interest-rates]]></category>
            <category><![CDATA[debt]]></category>
            <category><![CDATA[business]]></category>
            <category><![CDATA[psychology]]></category>
            <category><![CDATA[economy]]></category>
            <dc:creator><![CDATA[Bryan Fajardo]]></dc:creator>
            <pubDate>Sun, 03 Nov 2019 02:25:36 GMT</pubDate>
            <atom:updated>2019-11-25T04:23:46.001Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vk3LToZ93asd6_n_GrGZQQ.png" /><figcaption>Image by <a href="https://pixabay.com/users/artsybee-462611/">ArtsyBee </a>from <a href="https://pixabay.com/">Pixabay</a></figcaption></figure><p>Up until a little while ago I was like many people that didn’t know the difference between APY and APR. In fact, I didn’t even know there was a difference. I kind of always assumed it was the same thing, just two different names for it, or even if it was different it simply wouldn’t affect me. I have learned that many times it is the things we know little of that have the greatest impact in our lives. So, I would like to share what I’ve learned regarding APY, APR, and our minds.</p><h4>APR</h4><p>APR stands for <em>annual percentage rate. </em>It is also commonly referred to as <em>interest rate. </em>As the name suggests it is the percent of interest that <strong>you will pay</strong> or <strong>be paid</strong> for a period of time. For example, say you open a credit card that has an APR of 24%.</p><p>Usually credit cards have a monthly periodic rate which means the interest compounds each month. So you will take 24% and divide it by 12 — a year has 12 months — this will give you your <em>monthly </em>interest rate (periodic interest rate) which in this example is 2%.</p><p>Every month your balance will be multiplied by 0.02 (2%) and <em>the product </em>will be added to your balance. The process will rinse and repeat for the remainder of your balance.</p><blockquote>Month 1: <br>Balance — $2,000 <br>$2,000 x 0.02 = $40<br>$2,000 + $40 = $2,040</blockquote><blockquote>Month 2: <br>Balance — $2,040 <br>$2,040 x 0.02 = $40.80 <br>$2,040 + $40.80 = $2,080.80</blockquote><p>Obviously payments would reduce your balance and subsequently reduce your interest payment but you can see how your interest <em>compounds</em> each month and a part of your payment would actually only go towards paying the interest. By the end of the year you would be paying <strong>more than 24% </strong>because interest has been added to whatever you owe.</p><h4>APY</h4><p>APY on the other hand stands for <em>annual percentage yield.</em> This is the actual percent of interest you would pay on a balance if you ignore payments made. A credit card with an interest rate of 24% actually yields almost <strong>27% </strong>to the lender.</p><h3>The Elephant in the Room</h3><p>Would you have gotten this credit card if it said <strong>27% </strong>instead of <strong>24%</strong>? Would the bank have approved you for a $2,000 line of credit if they were getting <strong>24% annual percentage yield?</strong> These are valid questions to ask, and in fact you should be asking them (at least to yourself).</p><p>Training your mind to notice these differences first requires becoming aware that they exist. If you know the difference between APR and APY your brain will assess the <strong>real cost of the loan</strong> or the <strong>real return on your investment </strong>and you can make better informed financial decisions in your home, education, and business.</p><p>If you look around at credit cards, loans, investments, etc. a pattern will emerge. A pattern we are all susceptible to unless we actively search for and do our best to recognize.</p><blockquote>Generally when talking about loans, credit cards, and other debt — banks, private institutions, and lenders will show you the APR. When talking about investments, savings accounts, certificate of deposits, and other investment vehicles — they will show you the APY.</blockquote><p>The reason for this is simple psychology. People want to pay less and earn more. APR appears to be less, and APY appears to be more. This is simple business, wouldn’t you do the same if you are trying to sell something?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7nX1ojD-ZeEJAMfsd8erg.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/stevepb-282134/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1232944">Steve Buissinne</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1232944">Pixabay</a></figcaption></figure><h3>Only $3.99!</h3><p>A similar psychological methodology can be seen somewhere else, at the center point of American culture — the retail and service business. Go to almost any store and you are guaranteed to see a price tag that ends in 99 cents or even dollars in more expensive items.</p><p>This trick is known as “the left digit effect” or “odd-pricing” and it has been around for a while.</p><blockquote>They show that lowering a price by one cent to a 99 ending affects magnitude perceptions when the left digit changes (e.g., $3.00 to $2.99) …These studies, contrary to some of the earlier views (e.g., Gabor 1977; Knauth 1949), provide experimental evidence that nine-ending prices are perceived to be smaller than a price one cent higher. These experimental results also corroborate Stiving and Winer’s (1997) finding, using scanner data, that the left digit exerts a stronger influence than the right digits in price evaluation. (Penny Wise and Pound Foolish: The Left-Digit Effect in Price Cognition; Manoj Thomas, Vicki Morwitz)</blockquote><p>Basically, because we read from left to right, we attribute more importance to the left-most digit. In the case of $3.99, the 3 dollars resonate more with us but the cost is actually 4 dollars.</p><p>This effect is not directly embedded in APR and APY but it shows us how vulnerable our minds can be. The similarity here is the object of manipulation — <strong>our perceptions</strong>. When the price is $3.99 we <em>perceive </em>the cost to be about 3 dollars, when in reality the price is 4 dollars. When we see an APR of 24% we <em>perceive </em>that we are paying 24% interest on our balance, when we are in fact paying closer to 27% interest.</p><p>Likewise, if we open a savings account we may incorrectly believe that we are getting more money than we are. I made that mistake when I first opened an account with SoFi (Social Finance), I was excited that I would be earning 2.25% APY on my money (now it’s about 1.60% APY due to fed cuts) and right away I began calculating something like <em>this</em>:</p><blockquote>0.0225 annual percentage yield as a decimal<br>12 months in a year<br>0.0225 / 12 = .001875 monthly interest rate as a decimal</blockquote><blockquote>Month 1:<br>$1000 x 0.001875 = $1.87<br>$1,000 + $1.87 = $1,001.87</blockquote><blockquote>Month 2: <br>$1,001.87 x 0.001875 = $1.88<br>$1,001.87 + $1.88 = $1,003.75</blockquote><p>I had the incorrect notion that the <strong>annual percentage yield</strong> was an <strong>annual percentage rate. </strong>The calculations had already been done for me. If I put $1,000 in my account, I would have $1,022.50 at the end of the year, that was the <strong>yield</strong> (<em>duh!</em>). The APR was would actually be about 2.23% which means that the above calculations should have been something like this:</p><blockquote>0.0223 annual percentage rate as a decimal<br>12 months in a year<br>0.0223 / 12 = .00185 monthly interest rate as a decimal</blockquote><blockquote>Month 1:<br>$1000 x 0.00185 = $1.85<br>$1,000 + $1.85 = $1,001.85</blockquote><blockquote>Month 2: <br>$1,001.85 x 0.00185 = $1.85<br>$1,001.85+ $1.85 = $1,003.70</blockquote><p>You’ll notice that the actual results can be considered negligible by <em>most</em> standards.</p><blockquote>$1,000 at 2.25% APY: $1,022.50<br>$1,000 at 2.25% APR: $1,022.73</blockquote><blockquote>$10,000 at 2.25% APY: $10,225<br>$10,000 at 2.25% APR: $10,227.33</blockquote><blockquote>$100,000 at 2.25% APY: $102,250<br>$100,000 at 2.25% APR: $102,273.35</blockquote><p>The results become more important the more zeros you add to the end of whatever your investment is. <strong>However,</strong> most of us are not in the position where confusing APY for APR in an investment is a serious problem.</p><p>In reality the reverse of that is most damaging to people, <strong>confusing APR for APY (</strong>not APY for APR as in the previous example<strong>)</strong>, and it is there that these numbers make a bigger and more profound difference in people’s lives over the long term. For example:</p><blockquote>A credit card debt of $2,000</blockquote><blockquote>$2,000 at 24% APR: $2,536<br>$2,000 at 24% APY: $2,480</blockquote><p>In conclusion, the next time you, a friend, or a family member are looking at taking out a loan or opening a line of credit and they flash the APR at you, ask the lender— <em>“so what is the annual percentage yield?” </em>If you don’t want to ask then pull out your phone, crunch some numbers or type <em>“apr to apy calculator”</em> in google, and you will get your answer faster than they can say “your application has been submitted”.</p><ol><li><a href="https://www.investor.gov/additional-resources/free-financial-planning-tools/compound-interest-calculator">Compound interest calculator</a></li><li><a href="https://mindyourdecisions.com/blog/apr-to-apy-converter/">APR to APY calculator</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=395350176080" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/the-psychology-of-apr-and-apy-395350176080">The Psychology of APR and APY</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use Associative Entities in Relational Databases]]></title>
            <link>https://medium.com/@BryanFajardo/how-to-use-associative-entities-in-relational-databases-4456a2c71cda?source=rss-4532d3cfd5b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4456a2c71cda</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Bryan Fajardo]]></dc:creator>
            <pubDate>Fri, 01 Nov 2019 03:05:09 GMT</pubDate>
            <atom:updated>2019-12-13T07:22:17.905Z</atom:updated>
            <content:encoded><![CDATA[<p>When you associate with someone or something you are connected in some way, this concept can be applied to relational databases through the use of associative entities. We will work through an example that shows how associative entities work. Hopefully, that will shed some light on different ways of thinking about associative entities and the many solutions they can provide in a business or in an academic environment.</p><h3>An Example of When to Use Associative Entities</h3><p>Say you own a movie rental service and your business is doing poorly. You want to track inventory using databases because you haven’t been doing this at all. So you create a database and a model where you can keep track of what movies your customers have rented out at any given moment.</p><p>You initially decide to use a <em>one </em>to <em>many</em> relationship (1:M). Where many movies can be attached to a single customer. The tables for that model would look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*GfHsKKBjBCSmeSwT8L6xzw.png" /><figcaption>The customers and movies tables.</figcaption></figure><p>In this model whenever a movie is rented out to a customer, the customer_id column is set to that customer’s primary key. You know a movie is rented when that column is set, and you know a movie is available if that column is null.</p><p>A query to check if <a href="https://en.wikipedia.org/wiki/Fight_Club">Fight Club</a> is available would look like this:</p><pre>select * from movies<br>where customer_id is null and name = &#39;Fight Club&#39;</pre><p><strong>Mr. Bernard </strong>is a regular customer at your store. In fact he is your number 1 customer — literally <strong>his id is 1</strong>. He usually rents about 2 movies a week. If at any given moment you want to know what Bernard is watching you can write the following query.</p><p>select * from movies where customer_id = 1</p><p>Boom, you just got all the movies he has currently rented out.</p><p><strong><em>However</em></strong>, one glaring problem with this model is that if you’re owning a movie store it is very likely that you have multiple copies of a movie. This model would force you to create a record for each movie. So say you have 10 copies of <em>The Matrix</em>, your database would look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*E96UIW_c_X_eGb0kfaKfBQ.png" /><figcaption>Oh look, Bernard is watching The Matrix this week.</figcaption></figure><p>I think you can see why this is a problem. You may have to represent each movie you own with a table record anyways, but the worse part of this model is the amount of repetitive data you are saving to the database every time. Also, you are very likely going to have more than 3 columns with movie data and other meta data. Just as an example there are movie <em>titles, descriptions, versions, dates released, etc. etc. etc. </em>Would you really want to save that for each movie record even if it’s the same? Hopefully the answer is <strong><em>no</em>.</strong></p><p>This is where <strong>associative entities</strong> come in handy.</p><h3>Solution By Association</h3><p>An associative table will allow us to represent each rental as a record. At the same time we can avoid storing repetitive data. As with anything there are pros and cons, but depending on the use case and data involved this is can be a more viable solution.</p><p>So here is what our new model would look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*SkaA8foyiPJSG7A2hdGeGw.png" /><figcaption>The table lk_customer_movies is our <strong>associative entity. </strong>The “lk” part is so that you can quickly recognize that this table is a link table.</figcaption></figure><p>This model is a <em>many </em>to <em>many </em>relationship (M:M) between movies and customers. Whenever a movie is rented out to a customer, a <strong>lk_customer_movies</strong> record will be created. This record can hold additional information relevant to the business such as the date rented, rental length, rental price, etc. Better yet! If you wanted you could add an additional column to <strong>lk_customer_movies </strong>called transaction_id which would be the foreign key to the rental transaction that took place. The transaction_id column could point to a record stored in a table called <em>transactions</em>. Inside of that rental transaction you could store the details relevant to the business transaction that took place. Here is an example of the pliancy of this model to further extend our database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*-h54ZLPXdamjmtqRqk_8PQ.png" /><figcaption>It wouldn’t be difficult to add transactions table into the mix to keep track of customer transactions. Since a customer may rent multiple movies in one transaction, multiple <strong>lk_customer_movies </strong>can share the same transaction_id.</figcaption></figure><p>Here are some pros and cons!</p><h4>Pros</h4><ol><li>less prone to human errors — you can mess things up when entering information that is the same multiple times. What if you mistype ‘Fight Club’ as <strong>‘Fight Cub’</strong>, now you’re looking for a totally different movie about animals.</li><li>more organized — there is a movies table which has data relevant to the movie and there is a link table (associative entity) which connects that movie to other tables. Additionally, the link table can also have its own relevant data like what time was the movie rented? When is it due?</li><li>less likely to quit of extreme boredom — ah yes, you don’t want to make the data entry guy or gal want to quit with your new order of 1000 copies of ‘The Avengers’. (You can also just write some code to do this)</li></ol><h4>Cons</h4><ol><li>More complex queries — your queries will get more complex because you will most likely want to fetch data from various tables.</li><li>More complex data structure — at first you might say WHAT DOES ALL THIS EVEN MEAN when you stare at it.</li></ol><p>Alright, so now let’s say that Bernard rented out two movies this week. <em>The Matrix </em>and <a href="https://en.wikipedia.org/wiki/No_Country_for_Old_Men_(film)"><em>No Country For Old Men</em></a><em> </em>(Bernard has impeccable taste in movies). What would that look like?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LaU_YL3PfQQtn7rUHa5Vaw.png" /></figure><p>With this structure, we only need to set our movie data once in the movies table. Our customers are connected to the movies via our <strong>bridge </strong>or <strong>link</strong> table, the lk_customer_movies table. Whenever we rent out a movie, a lk_customer_movies record is created.</p><p><strong>Note: </strong>Notice how the movies table has a column called quantity. This column is used to indicate total copies of that movie. An alternative method of knowing how many copies you have could be to create a lk_customer_movies record for each movie copy right away.</p><p>So what would some of the queries look like?</p><h4>Query to fetch movies rented by Bernard:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/510ccc209422106537297547da9725d7/href">https://medium.com/media/510ccc209422106537297547da9725d7/href</a></iframe><h4>Query to fetch specific movie rentals and check availability:</h4><p>Since we create a record in <strong>lk_customer_movies</strong> when a movie is rented. For this one we will have to add a new column to <strong>lk_customer_movies</strong>, we can add a returned_at date column to indicate the movie is no longer being rented and has been returned. Furthermore, this allows us to keep a record that the movie was once rented.</p><p>This would tell you how many copies of the movie are rented out and the max copies your store has, so you could compare the number of records returned to max copies and see if you have any left in stock.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7b471fa69ed7f34c651cab8fac5cc49/href">https://medium.com/media/d7b471fa69ed7f34c651cab8fac5cc49/href</a></iframe><p><strong>Query to check how many movies are currently rented out:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa729b98028fd32e079065e02c62fc86/href">https://medium.com/media/aa729b98028fd32e079065e02c62fc86/href</a></iframe><p>Associative entities are not <strong>always</strong> helpful, it is important that you learn to distinguish when it is needed, otherwise you will add unnecessary complexity to your project. Here are a couple of thoughts that indicate an associative entity might help your data structure.</p><ol><li><strong>“I have to insert repetitive data” </strong>— this may be an indication that you need to separate the tables which represent your data. All tables represent <em>data</em><strong>,</strong> but data can represent different things. Some data can represent information (like a movie title) whereas other data can represent something tangible or distinct (in this case a physical movie copy).</li><li><strong>“My relationship needs a relationship” </strong>— This one sounds a little weird but if you find yourself saying this you <em>might</em> need an associative entity in your database.</li></ol><p>There you have it! You should take the time to really understand the needs of your application before developing the architecture. As you ask yourself questions about data requirements you will <em>probably </em>come across a situation where you think “an associative entity is perfect for this”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4456a2c71cda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Vue.js inside of Sweet Alert 2 modals]]></title>
            <link>https://medium.com/@BryanFajardo/how-to-use-vue-js-inside-of-sweet-alert-2-modals-31da49e2e4d8?source=rss-4532d3cfd5b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/31da49e2e4d8</guid>
            <category><![CDATA[sweetalert]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[modal]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Bryan Fajardo]]></dc:creator>
            <pubDate>Sun, 27 Oct 2019 21:31:12 GMT</pubDate>
            <atom:updated>2019-12-13T07:31:52.059Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Use Vue.js Inside of Sweet Alert 2 Modals</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*9TVcoW47QdZcIZ9_gpo7Bw.jpeg" /></figure><p>One of the challenges any developer may encounter when using multiple packages/libraries is how to have them work together. This can be particularly tricky when they aren’t created with each other in mind. This article will show how to use Vue.js components inside of Sweet Alert modals <strong>without</strong> depending on other packages to do it for us.</p><p>I will make the assumption that you have installed Vue.js and Sweet Alert 2 in your project. If not, take a look at some of the links at the end to read the official Vue.js and SweetAlert2 guides. <em>I will not be covering how to install those in this article.</em></p><p><em>Now unto the good stuff!</em></p><h3><strong>Step 1: Create your Vue.js single file component</strong></h3><p>Go to wherever your components are located and add a component you would like to exist inside of the Sweet Alert 2 modal. For this article we will create a very basic notes component where the user can add a note to a list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49f99acc810cd31b46cc2b0ab2962794/href">https://medium.com/media/49f99acc810cd31b46cc2b0ab2962794/href</a></iframe><p>You’ll notice there are two props: title and noteProp. This is to test that our component can receive <em>non-reactive</em> data and use it inside the component from within the Sweet Alert 2 modal.</p><p>Let’s register this component with our application. Depending on how you are running Vue.js, it may also be necessary to register it with the Vue root instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb82f79fc0b559a45c7f56139fd84abe/href">https://medium.com/media/bb82f79fc0b559a45c7f56139fd84abe/href</a></iframe><h3><strong>Step 2: Create a method which will call the Sweet Alert 2 modal with the component you specify.</strong></h3><p>We will be creating a method that mounts our component of choice and then appends that component to our Sweet Alert 2 modal. The first parameter will be the name of the single file component as you registered it with your app in Step 1. The second parameter will be the props data you want to pass into the component.</p><p><strong>Note:</strong><em> This method will need to have access to Vue and Sweet Alert 2.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/573cb9241521d8d0da3d1890b7687bec/href">https://medium.com/media/573cb9241521d8d0da3d1890b7687bec/href</a></iframe><p>You should place this code wherever you feel is appropriate for your use case. Since I am using Laravel I will add it to the head of my master file which is extended across my application. In the master head I will place it in _modals.js file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96e1fc403cc5d6ef7a09acacc2e071a9/href">https://medium.com/media/96e1fc403cc5d6ef7a09acacc2e071a9/href</a></iframe><h3><strong>Step 3: Call the method (yay 😃)!</strong></h3><h4>A few things before you do (aww).</h4><ol><li>You should be able to call this method from inside of script tags, other Vue components or any JavaScript code which has access to the method you created.</li><li>The Vue component instance is destroyed when you close the modal so any data inside that was not saved will be lost. Depending on your use case you may have to think of ways to persist the data inside of the component either by using a package like Vuex, or by making database queries inside of the component, etc.</li><li>A new Vue component instance is mounted every time you call the method.</li><li>Inside of the Vue component you can use the Sweet Alert close() method to close the modal.</li></ol><p>The code below shows an example of calling the method from a basic Javascript script. You can see the second parameter I passed contained an object with the title and noteProp values we discussed earlier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd076fbc31c4918ea7ccb3f32861f5f4/href">https://medium.com/media/bd076fbc31c4918ea7ccb3f32861f5f4/href</a></iframe><p><em>Finally..</em>.</p><figure><img alt="Notes Vue component inside of a Sweet Alert 2 modal" src="https://cdn-images-1.medium.com/max/955/1*UnYRQ9ZAa5RcPSYsbOm_Mw.png" /><figcaption>Our VueSweetAlert2 modal in action!</figcaption></figure><p>Notice how it contains the title and notes we passed in. Additionally, with Vue.js and Sweet Alert 2 you can make this modal fit into any theme or make it look however you want.</p><p>To read more about how you can get started with Vue.js and Sweet Alert check out these links:</p><p>Vue.js: <a href="https://vuejs.org/v2/guide/">https://vuejs.org/v2/guide/</a><br>SweetAlert2: <a href="https://sweetalert2.github.io/">https://sweetalert2.github.io/</a></p><p>If you have any questions or something you want to be clarified please comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31da49e2e4d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>