<?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 Amos Machora on Medium]]></title>
        <description><![CDATA[Stories by Amos Machora on Medium]]></description>
        <link>https://medium.com/@amosmachora?source=rss-8f4b825473a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*imOfoDNuN3OkC2UBNexW5w.jpeg</url>
            <title>Stories by Amos Machora on Medium</title>
            <link>https://medium.com/@amosmachora?source=rss-8f4b825473a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 16:29:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amosmachora/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[YouTube thumbnails suck. I built a solution.]]></title>
            <link>https://medium.com/@amosmachora/youtube-thumbnails-suck-i-built-a-solution-66f10b229cbb?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/66f10b229cbb</guid>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[merita]]></category>
            <category><![CDATA[television]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Mon, 25 Aug 2025 13:20:25 GMT</pubDate>
            <atom:updated>2025-08-26T16:44:16.807Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A screenshot of the calendar page on Merita.tv" src="https://cdn-images-1.medium.com/max/1024/1*h4MQaB3furWeAbsobFYq2A.png" /><figcaption>A screenshot of the scheduling experience on merita.tv</figcaption></figure><ol><li><em>Food that looks good but tastes otherwise or is plain unhealthy.</em></li><li><em>That type of LinkedIn post that makes you want to jump off the nearest balcony.</em></li><li><em>Ladies with so much makeup they look easy to draw.</em></li><li><em>Focusing on recording moments instead of living them.</em></li><li><em>YouTube thumbnails.</em></li></ol><p>What do all the above scenarios have in common? The tendency in our modern world to prefer being fake over being real, preferring the image of something over its substance. I know this might look like an extrapolation, and maybe it is, but the core message is true: we have this proclivity to undervalue what is real for its representation, it is subtle, appears in many forms, only to those with the eye to see it.</p><p>Reading YouTube CEO Neal Mohan’s blog on <a href="https://blog.youtube/inside-youtube/our-big-bets-for-2025/">YouTube’s big bets for 2025</a>, and the continuos growth of the internet that does not show any sign of stopping it is becoming more and more obvious that Youtube will remain core to our lives and the “epicenter of culture” in Neal’s words for the foreseeable future, no longer just a place for people to post cute cat videos but a culture shaping tool, at the heart of media itself, for more and more people all over the world, that being said Youtube’s core design has nudged us in a direction that could need just a bit of retooling, just a bit of redirection, and that is what we are here for today.</p><p><em>Disclaimer</em></p><p><em>The thoughts below are my own personal thoughts on how YouTube could be most useful for me. I have nothing against YouTube, nor does this blog’s aim to “throw shade” or manufacture negativity on YouTube’s side. I absolutely love YouTube; in fact, I do not think I would even be writing this if it were not for the incredible work that super-talented people have put into creating a free platform to which so much is owed, technologically, economically, and socially. This blog is not an attempt to denigrate YouTube but rather to promote a product I have created and found very useful called </em><a href="https://www.merita.tv/"><em>Merita.tv</em></a>,<em> a product that I built because YouTube thumbnails really, really annoyed me. Please keep that in mind.</em></p><h4>Tell us about YouTube thumbnails, man.</h4><p>Every day as I visit YouTube.com, something inside me dies. I don’t know what, but there is a sense of the fakeness I was talking about earlier, from YouTubers with “that face” thumbnail to plain clickbait, competing for clicks has made YouTube an awesome place, only beyond that first click on a video. <a href="https://www.youtube.com/@veritasium">Veritasium</a>, one of my favorite creators, has an <a href="https://www.youtube.com/watch?v=S2xHZPH5Sng">excellent video</a> on this topic, and the TL;DR is THEY WORK. Aggregious YouTube thumbnails just work. They DO get the clicks, not entirely sure why, but in my estimation, YouTubers have learnt to optimize for the innate nature of human beings, the tendency for homo sapiens to avoid danger, or our intense drive to be curious.</p><p>The argument seems to be “the end justifies the means,” and fair enough, maybe it does, but still, I couldn&#39;t ignore the sinking feeling, for some reason that may not be as well represented in words, I couldn’t rest, hence Merita.tv. While some of thumbnails are “harmless” some cross the line in my estimation, an example is one from one of my favorite podcasters Jordan B Peterson on his clips channel, for context he and his guest <a href="https://youtu.be/FjKKKeZwCns?si=JfGlnFDgfO55Gdek">are talking about the Atacama Mummy</a>, an event that is used as proof of the presence of UFOs, in this podcast episode his guest tells him that the Atacama mummy atleast in his estimation <a href="https://youtu.be/FjKKKeZwCns?t=103">is a human baby</a>, but look at this thumbnail..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LM4XiiGkTglhmJjCORr_Bg.png" /></figure><p>If you focus on the text “IT’S NOT FAKE?” it does look like it is just to prompt inquiry, but for a very long time, for some reason, I have always read this text as “ITS NOT FAKE!”, I infact just noticed the question mark as I was taking the screenshot for this blog, perhaps that is my fault, could it be that I as a user i’m seeing a thousand of this a day? maybe.</p><p>While the 96K who watched that video will get to understand, for the few to whom that video just flashed and disappeared in their YouTube recommendations, or read it as I did, it has served as a source of panic, worry, and maybe even unintentional misinformation. This is nothing against the creator, I love Dr. Jordan, I have watched almost 90 percent of his videos, I owe almost everything I know and how I think to him, I just believe that media shouldn&#39;t be a “business”, knowledge is not something “optimizable”. Most likely he himself actually had no hand in this thumbnail, most of big channels have a big team as highlighted in the 2nd point of the Youtube blog, “#2: YouTubers are becoming the startups of Hollywood.” People with time on their hands to cook up views do this kind of thing all the time, it should be stopped.</p><p><em>What if we could get the incentives right?</em></p><p>What if, instead of encouraging content creators to optimize for clicks, they would otherwise be encouraged to optimize for genuine engagement? genuine knowledge propagation? Wouldn&#39;t that be nice? How could that even be done? I know there are already metrics of that sort on YouTube, but I feel the thumbnail presence accounts for a certain contradiction in terms here.</p><h4>Perception &amp; Reality.</h4><blockquote>The eye is the lamp of the body, so if your eye is clear, your whole body will be full of light</blockquote><blockquote>Mathew 6:22</blockquote><p>Apologies for making this a theological blog to those who aren’t inclined that way, but the core concept highlighted in that biblical verse is right; it is a description of how reality works, what we see defines who we are and who we become. Companies know this, from the absolutely devastating attempts at psychological engineering that have and still are carried out by some people on dark corners of the internet, it is obvious that perception is not a cold, rational faculty; it is a living creature that gets shaped by repetition, emotion, and attention in ChatGPT’s words.</p><p>The malleability of our human brains is a fact that has been unjustly taken advantage of by people for profit or other dark motivations, but we are built this way for a reason, imagine if we came out of our mother’s womb armed with immovable perceptions and opinions about everything, that wouldn’t be right, perhaps then this ability we have could actually be used for good then. If people are using it to infect others’ brains with content that is not useful or is addictive and dangerous, then some of us can be intentional in defining what we see for ourselves and for our loved ones. To “manufacture” a culture we want to live in, not wait for it to happen by accident.</p><h4>We lost community; maybe we should bring that back.</h4><p>Despite the numerous online “communities,” it is obvious that what humans consider true communal activity is long gone, in varying degrees, in different parts of the world. I am not saying that this is a problem solveable by technology. A few weeks ago, I was listening to Alejandro Fernández’s <a href="https://www.youtube.com/watch?v=jCYQJKbpr7I&amp;list=RDjCYQJKbpr7I&amp;start_radio=1">No Se Me Hace Fácil</a> when I ran into the below comment.</p><blockquote>You should just know that your song ruled KENYA 🇰🇪 as the theme song for the soap opera STORM OVER PARADISE..TORMENTA EN EL PARAISO . We ran from wherever we were when we heard the first note of this song. My mother used to leave the food burning on the stove just for us to sing this song as the opening theme damn . This is still a masterpiece. Love from Kenya 🇰🇪</blockquote><blockquote>Vanidia — Youtube Commenter and Storm over paradise enjoyer.</blockquote><p>The writer of the comment describes my childhood, that song wasnt just music it was community experience, i remember running through corridors and hearing the neighbours watch exactly what we were watching in our house and talk about it the next day with my friends at school, it was awesome, unfortunately Youtube doesn’t have that or atleast not the way it was back then, yeah sure you can watch the same youtube video but the chances of that are lower and the chances of watching it at the same physical time even lower, there is gold in that, watching the same thing at the same time creates a different kind of connection, it is even hard to put into words, but it is there.</p><p>Viewing experiences should unite, and now more than ever, we have an opportunity to delocalize that effect from our local country to the whole world! The potential is immense. It is obvious that there is a proclivity for things to unite, for things to come together to one, and as YouTube becomes television now, there is an opportunity to harmonize our viewing experience, for the better.</p><h4>Illusion of choice and Information overload.</h4><p>Unfortunately, watching YouTube every day feels like decisions, and these decisions cost brain headspace that I would rather use doing something else. I can never relax watching YouTube, unless it is a super long video that will make me forget that other options exist. Traditional TV had one underrated strength: <strong>you didn’t have to choose</strong>. Psychologists call this the <strong>Paradox of Choice</strong> (Barry Schwartz): more options make people <em>less satisfied</em> with whatever they pick, because they worry about the “better” option they didn’t choose.</p><p>Wouldn’t it be easier if what you want to see or what we would all want to see could already be chosen for us? We could outsource that choice to someone else, all whilst trusting they choose what&#39;s best for us, and yes, generally outsourcing our brain power does not always work out as well in application as it is in theory. That concept has definitely been used for evil across a lot of applications and contexts, That being said, it is better to clean up the dust from those shoes (somehow, I really need ideas) than wear those shoes on opposite feet. There is definitely benefit in not having to think about every single detail in your life; endless choice keeps your head constantly evaluating, deciding, optimizing, there is freedom in not having to choose; maybe that is what people call peace.</p><h4><strong>Introducing Merita.tv</strong></h4><p>Real people have always had a better understanding of each other&#39;s needs; sometimes this ability can be used to manipulate and take advantage of, but regardless, they still have it. Algorithms are so good but also so bad. Algorithms are predictive in nature; they predict so well and sometimes almost too well. Merita.tv is an attempt to put you, as a viewer in the driving seat of your viewing experience.</p><p>Merita.tv is a “reskin” of YouTube. It takes advantage of YouTube&#39;s I<a href="https://developers.google.com/youtube/iframe_api_reference">frame API</a> to build an in my opinion better experience of YouTube. It is not a whole new product from the ground up, but rather a redressing of YouTube’s viewing experience. All your favorite YouTube content creators are on Merita.tv by default. All the things you see on a daily basis are on Merita.tv, but the experience is custom, for you, for everyone.</p><p>The idea is you create your own screens, define slots within the day in which you will see certain types of content and or channels. Suppose you have your own Sports channel inside which you watch the Premier League and Man United, Man City at night at 8, etc. Or even better, if you do not want the hassle of defining your own screens, you can join <a href="https://community.merita.tv/">community screens</a>, like <a href="https://www.merita.tv/the-sports-channel">The Sports Channel </a>or <a href="https://www.merita.tv/programming">Programming</a>, which I personally created and manage for my viewers.</p><p>You can use Artificial Intelligence to classify the type of content per playtime slot. A good example is <em>The Wan Show</em> by <a href="https://www.youtube.com/@LinusTechTips">LTT</a> that runs every Sunday from 10 AM to 13 PM on <a href="https://community.merita.tv/technology">the technology channel</a>, or <em>The standup</em> by <a href="https://www.youtube.com/@ThePrimeTimeagen">The Primeagen</a> every Wednesday at 8 PM to 9 PM.</p><p>You can mix and match to find a balance that truly fits your needs; that is the power of Merita.tv. There are more features like syncing your screens with your Google Calendar for that extra bit of organization, and so much more. I highly encourage you to visit <a href="https://about.merita.tv/">about.merita.tv</a> to find more detailed information on the application.</p><h4>There are definitely downsides though..</h4><p>So what problems does Merita.tv create as it attempts to solve others?</p><ol><li>Creators might not be the happiest. On Merita.tv, there is no like and subscribe button, there are no comments either nor even a description section. This will most likely not sit well with content creators, an idea I am currently playing with is a light mobile application that allows you to interact with the non-playable content of a video, as well as acting as a remote “remote” for your TV. Also right now the app is “open”, it is for people to watch as they wish youtube channel videos or combinations of them, this might put a bad taste in creator’s mouths, a potential solution here is a sort of licensing system, this will open up another revenue stream for creators, its an idea in its infancy though and I have no bloody clue how it will work out.</li><li>There is definitely some magic lost, algorithms are good at showing us what we might be interested in, and at times that is a very good thing, it is often that I log on to YouTube.com and actually find a video I genuinely want to see that I would have missed otherwise.</li><li>Merita.tv is definitely not for everything; it works best for episodic content or episodic-like YouTube videos. This is awesome, though, because the definition of what episodic content is falls entirely on the user (or community screen owner). In the future, we might add features to allow users to more easily define episodes across videos and channels.</li></ol><h4>Conclusion</h4><p>It is time we were intentional with what we see; there is real gold in that. In a world with so much content, restriction now paradoxically holds all the benefits, whether it is too much choice, perception protection, or my personal favorite, a burning dislike of YouTube thumbnails, Merita.tv offers a lot of benefit and even more in the future as I learn, iterate and build what I hope is the next generation of television. Join me today, create a free account at <a href="https://www.merita.tv/">Merita.tv</a>, and if you are inclined to support or find the premium features useful, use the code <strong>FROMTHEBLOG </strong>for 50% off your first month’s premium subscription (first 100 subscribers).</p><p>Finally, THERE WILL BE BUGS. I work on this alone, and there is A LOT. Please bear with me. Also, I know this goes without saying, but do not create content or screens aimed at conflict or creating unnecessary drama, while I figure out ways to automate the prevention of this, I am relying on you to be responsible and wise with the content you create on Merita.tv, especially community screens.</p><p>Shout out to <a href="https://www.youtube.com/@t3dotgg">Theo</a>, <a href="https://www.youtube.com/@webdevcody">Web Dev Cody</a> &amp; <a href="https://www.youtube.com/@ThePrimeTimeagen/featured">Prime</a>, their content has been incredibly useful in many ways, and it is accurate to say that this product could not be here if it weren&#39;t for them.</p><p><em>With grace to the internet from,</em></p><p><em>Amos Machora,</em></p><p><em>CEO? Maybe CEO, Merita.tv.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66f10b229cbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate Mpesa Payment QRCode in NextJS 14: A 5-Minute Guide]]></title>
            <link>https://medium.com/@amosmachora/generate-mpesa-payment-qrcode-in-nextjs-14-a-5-minute-guide-ae6136076bb0?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae6136076bb0</guid>
            <category><![CDATA[daraja]]></category>
            <category><![CDATA[nextjs14]]></category>
            <category><![CDATA[react-daraja]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Sun, 07 Jan 2024 15:20:50 GMT</pubDate>
            <atom:updated>2024-01-07T15:20:50.647Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dp1pMbwo_4gM6zp8MEZMdw.jpeg" /></figure><p>In less than 5 mins we will generate a QR Code that people will scan to pay to your till or pay bill number. You will be surprised how easy it is.</p><h4>Install the react-daraja library</h4><p><a href="https://www.npmjs.com/package/react-daraja">React daraja</a> is a library I built to simplify interactions with the Safaricom daraja API. It is a bunch of utility functions and typescript types to help developers work with that monstrosity of documentation.</p><p>So install that</p><pre>npm install react-daraja</pre><h4>Create the environment variables</h4><p>Just copy and paste the below code to your .env file.</p><pre>ENVIRONMENT=&#39;development&#39; # Set the environment to either &quot;production&quot; or &quot;development.&quot;<br>MPESA_CONSUMER_KEY=&#39;&#39; # Consumer Key obtained from Safaricom Daraja.<br>MPESA_CONSUMER_SECRET=&#39;&#39; # Consumer Secret obtained from Safaricom Daraja<br>MPESA_BUSINESS_SHORT_CODE=&#39;174379&#39; # Your M-Pesa business short code. For Sandbox use the code 174379<br>MPESA_TRANSACTION_TYPE=&#39;CustomerPayBillOnline&#39; # Set the transaction type, either &quot;CustomerPayBillOnline&quot; or &quot;CustomerBuyGoodsOnline.&quot;<br>MPESA_API_PASS_KEY=&#39;bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919&#39; # Your M-Pesa API pass key. For sandbox use bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919</pre><p>The consumer key and secret can be obtained by creating an app in the <a href="https://developer.safaricom.co.ke/">Safaricom </a>developer portal.</p><h4>Import and use the QR code react server component</h4><pre>import React from &quot;react&quot;;<br>import {<br>  BUSINESS_SHORT_CODE,<br>  QRCodeDisplay,<br>  ScannableQrParams,<br>} from &quot;react-daraja&quot;;<br><br>export const QrCode = () =&gt; {<br>  const qrCodeParams: ScannableQrParams = {<br>    Amount: 100,<br>    CPI: BUSINESS_SHORT_CODE,<br>    MerchantName: &quot;React daraja docs&quot;,<br>    RefNo: &quot;REF100&quot;,<br>    Size: &quot;100&quot;,<br>    TrxCode: &quot;PB&quot;,<br>  };<br><br>  return (<br>    &lt;div className=&quot;w-[100px] aspect-square mt-5 mx-auto&quot;&gt;<br>      &lt;QRCodeDisplay scannableQRParams={qrCodeParams} /&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><h4>Be careful though</h4><p>The component is a react server component so don&#39;t call it inside a client component.</p><p>Boom you are done. If you want any explanation of the fields in that qrCodeParams object hover over the field you will find an accurate description.</p><p>Thanks for reading through. Leave the library a star <a href="https://github.com/amosmachora/react-daraja">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae6136076bb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero #64.Transpilers]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-64-transpilers-f4792dee201d?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4792dee201d</guid>
            <category><![CDATA[bundler]]></category>
            <category><![CDATA[transpilers]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Fri, 09 Jun 2023 12:50:42 GMT</pubDate>
            <atom:updated>2023-06-09T12:50:42.281Z</atom:updated>
            <content:encoded><![CDATA[<h3>Javascript zero to hero #64.Transpilers and bundlers. Streamlining development and optimizing performance. An overview 💭</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ3AOsfosigzVqjEB4PJeg.jpeg" /></figure><h3>Introduction</h3><p>Transpilers and bundlers are essential components of any development process. They are essential for ensuring compatibility across different environments. Today we demystify transpilers and bundlers. Lets go 🚀</p><h3>Transpilers</h3><p>Bridging the Gap in Compatibility</p><p>Transpiling, or source-to-source compilation, is the process of converting code written in one version of JavaScript into an equivalent version that can run on older or different environments. The primary reason for transpiling is to overcome compatibility issues between different JavaScript versions and browsers.</p><h4>1.1 Necessity of Transpiling:</h4><p>Programming languages evolve and javascript is no different. New features are introduced and transpilers help to ensure that your code runs on all browsers and environments.</p><h4>1.2 When to Use Transpilers</h4><p>Developers use transpilers to take advantage of the most recent JavaScript features without sacrificing compatibility. Transpilers are essential for bridging the gap between the most recent language version and the one that is supported by the target platform when targeting particular platforms or environments.</p><h4>1.3 How to Use Transpilers</h4><p>Well-known transpilers like Babel have made the transpiling of code simple. Using presets and plugins, developers can tailor the translation process to suit their unique requirements. When given modern JavaScript code, the transpiler converts it into code that can run in target environments while also being backward-compatible.</p><h3>Bundlers</h3><p>Bundling is the process of combining multiple JavaScript files and their dependencies into a single, optimized file. This process is called optimizing code delivery. Bundlers improve performance by minimizing file sizes and network requests, which shortens the time it takes for applications to load.</p><h4>2.1 Importance of Bundling:</h4><p>When a web application grows, it often requires numerous JavaScript files to manage different functionalities. Loading multiple files individually can lead to slower page rendering and increased latency. Bundling solves this problem by creating a single file that contains all the necessary code, reducing the number of requests and enhancing overall performance.</p><h4>2.2 Popular Bundlers</h4><p>Two popular bundlers in the JavaScript ecosystem are Webpack and Rollup. Numerous customization options are available with Webpack, including support for CSS, images, and other formats. In contrast, Rollup concentrates on creating smaller, more optimized bundles, which makes it perfect for libraries and smaller applications.</p><h4>2.3 How to Use a Bundler</h4><p>Developers must configure a bundler to meet the needs of their project before using it. This entails defining the output paths, setting the entry point, configuring transformations and optimizations, and managing dependencies. A single optimized bundle file that is prepared for deployment is produced by running the bundler.</p><h3>Conclusion</h3><p>Tools like bundlers and transpilers are crucial in contemporary JavaScript development. Developers can write code that takes advantage of the newest language features while still maintaining platform compatibility thanks to transpilers. Bundlers improve performance and reduce network requests to optimize code delivery. The process of transpiling and bundling is made simpler by tools like Babel, Webpack, and Rollup, which makes it simpler for programmers to create effective and universally compatible JavaScript applications. Developers can maintain their leadership in JavaScript innovation while ensuring optimal performance and user experience by utilizing these technologies.</p><p>And that&#39;s it for transpilers and bundlers, an light beginners guide to show you what exactly they are. Thanks for trading.</p><p><em>I am running out of topics to write about . Any suggestions would be greatly appreciated 😄</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4792dee201d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero #63 Polyfill]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-63-polyfill-ea6b3521865?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea6b3521865</guid>
            <category><![CDATA[polyfill-in-javascript]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 13:30:29 GMT</pubDate>
            <atom:updated>2023-06-07T13:30:29.169Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ3AOsfosigzVqjEB4PJeg.jpeg" /></figure><p>Polyfills in javascript are code snippets or libraries that are used to emulate the functionality of newer js features to older browsers that do not support certain features or APIs. They typically have some sort of conditional logic that ascertains if a feature exists in a browser and provides an alternative implementation if it is not.</p><h4>Why do we need polyfills?</h4><p>The main purpose of polyfills is to ensure cross-browser compatibility. As web technologies advance, new features and APIs are introduced to JavaScript. However, older browsers may not support these features, causing compatibility issues. By using polyfills, developers can make their code work consistently across different browsers, including older versions.</p><h4>Examples of polyfills</h4><ol><li>Promises polyfill =&gt; Promises are a javascript feature in modern js for handling asynchronous operations. However older browser may lack the implementation. A polyfill like “es6-promise” can be used to enable promise functionality in older browsers.</li><li>Fetch polyfill =&gt; The Fetch API provides an easier and more powerful way to make HTTP requests. Older browsers, especially Internet Explorer, do not support the Fetch API natively. Polyfills like whatwg-fetch allow developers to use the Fetch API in older browsers.</li><li>Object.assign polyfill =&gt; Object.assign is a method that merges the properties of multiple objects into a target object. Some older browsers like internet explorer dont support the method and that is an example of the relevance of polyfills.</li></ol><h4>Advantages of polyfills</h4><p>The most obvious one is cross-browser compatibility. Polyfills enable developers to write modern JavaScript code while ensuring compatibility with older browsers, reducing the need for browser-specific workarounds.</p><p>Future-proofing code: By using polyfills, developers can take advantage of new features and APIs without worrying about whether they are supported in all browsers.</p><h4>Disadvantages of Polyfills:</h4><p>Increased bundle size =&gt; Including polyfills in your code adds additional JavaScript code, which can increase the file size. This may impact page load times, especially on slower networks.</p><p>Performance considerations=&gt; Polyfills are essentially workarounds, and their implementations may not be as optimized as native browser support. Some polyfills can have performance overhead, affecting the overall performance of your application.</p><h4>How to use Polyfills:</h4><p>To use polyfills include the javascript bundle of the polyfill in your script tags.The polyfill will then detect if a certain feature is missing in the browser and add the necessary functionality if required.</p><p>Example</p><pre>&lt;script src=&quot;promise-polyfill.js&quot;&gt;&lt;/script&gt;</pre><h4>When to use polyfills</h4><p>Before deciding on whether or not you need a polyfill it is essential to assess your target audience and determine whether you should include a polyfill. f you have a significant user base on older browsers, using polyfills can be a pragmatic approach to ensure your application functions properly for all users.</p><p>However if you are developing modern apps it might not only be unnecessary but its need might be significantly minimal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea6b3521865" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero #63 ES updates. Rollout, Availability and Adoption.]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-63-es-updates-rollout-availability-and-adoption-ded450bf4266?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ded450bf4266</guid>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[updates]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Wed, 31 May 2023 13:42:18 GMT</pubDate>
            <atom:updated>2023-05-31T13:42:18.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ3AOsfosigzVqjEB4PJeg.jpeg" /></figure><p>If you are a follower of my articles i reference EcmaScript(ES) a lot. Today we are going to understand what exactly ES is and how it influences the JS eco system.In this article, we’ll examine how ECMAScript updates are released, how they can be used by developers, how they’re adopted, and when new features will be added to browsers.</p><p>The standardized scripting language specification used by JavaScript is called ECMAScript (ES). It acts as the building block for web development, allowing programmers to build dynamic, interactive websites. Regular updates to ECMAScript are made to address language flaws, add new features, and improve performance as the web develops.</p><h3>Rollout of ECMAScript Updates</h3><p>The Ecma International standards body, which also controls the standardization of other technologies like JavaScript, is in charge of managing ECMAScript updates. There are several steps involved in updating ECMAScript:</p><ol><li>Developers, industry professionals, and browser manufacturers make suggestions for new features. These ideas are circulated within the ECMAScript committee, where they are carefully discussed and assessed.</li><li>Stages: There are four stages of maturity for proposals: finished (stage four), proposal (stage one), draft (stage two), and candidate (stage three). Each stage denotes a greater degree of agreement and readiness for implementation.</li><li>Specification: A proposal is deemed complete and added to the ECMAScript specification once it has reached Stage 4. Each new feature’s syntax, behavior, and application are described in the specification.</li></ol><h3>Availability for usage</h3><p>Developers can use an ECMAScript update in their code once it is included in the specification. However, a number of factors determine whether new features are accessible to developers:</p><ul><li>Browser Implementation: The new ECMAScript features must be added to JavaScript engines in web browsers like Chrome, Firefox, Safari, and Edge. Each vendor of browsers has a different implementation schedule and set of priorities.</li><li>Polyfills and transpilers: While they wait for browser support, developers can use transpilers like Babel, which transform current ECMAScript syntax into more established, earlier versions. Additionally, polyfills are pieces of JavaScript code that enable the use of fresh features in more mature browsers.</li></ul><h3>How do we adopt to new features?</h3><p>Developers must update their code to take advantage of the newest language improvements when implementing new ECMAScript features. The steps in the procedure typically include:</p><ol><li>Knowledge: The most recent ECMAScript update added new features that developers need to be aware of. To stay current, they can subscribe to official documentation, online sources, and developer communities.</li><li>Browser Support: To confirm that the targeted features are broadly supported across their desired browser versions, developers should check the browser compatibility tables. Using this information, it is possible to decide whether transpilers or polyfills are required.</li><li>Refactoring of the code is required once a developer decides to use a new feature in order to incorporate the revised syntax and functionality. This might entail writing new code or using programs like ESLint to automate the process.</li></ol><h3>Browser support</h3><p>Timeline for Browser Support: Depending on the browser vendor and the importance of the update, different browsers will take different amounts of time to support new ECMAScript features. In general, browser developers work to quickly implement widely used features. This is how the procedure can be summed up:</p><ol><li>Early Implementations: Before they complete Stage 4, some browser vendors may offer early versions of experimental versions of proposed features. These early versions enable experimentation and feedback from developers.</li><li>Preview Releases: To showcase upcoming features and gather more feedback from developers and the general public, browser vendors frequently release preview versions or beta builds.</li><li>Stable Releases: Once the new ECMAScript features are stable, they are included in the next stable release of the browser. The release cycles vary, but major browsers typically release new versions every few months.</li></ol><p>And that`s it for ES updates. Stay online and watch on social media as new features are announced. Remember to update your codebase to leverage the use of the features provided to us by the Ecma International standards body!</p><p>👋 remember to follow me for free daily articles 🤭</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ded450bf4266" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero # 62 Call and Bind.]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-62-call-and-bind-9e80d274b843?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e80d274b843</guid>
            <category><![CDATA[call-and-bind]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Tue, 30 May 2023 11:57:39 GMT</pubDate>
            <atom:updated>2023-05-30T11:57:39.749Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ3AOsfosigzVqjEB4PJeg.jpeg" /></figure><h3>Call</h3><p>Normally when you call a JS function, the “this” keyword in the function refers to the object that called the function. However sometimes this is not necessary or might be actually problematic. With the call method you can explicitly set the value of this to a specific object even if that object did not call the function.</p><p>Here is the syntax.</p><pre>function myFunction(arg1, arg2) {<br>  // Function code here<br>}<br><br>myFunction.call(thisValue, arg1, arg2);</pre><p>any other arguements can also be passed alongside the this object.</p><p>By using the “call” method, you can control the context in which a function is executed and access properties and methods of a specific object as if they were part of the function itself. This can be useful in situations where you want to reuse a function but with different objects as the context.</p><h3>Bind</h3><p>The bind method is kind of different though. It is used to create a new function that has a specific value for its this arguement. Allows you to permanently glue together a function and the object on which its executed hence bind .The “bind” method allows you to permanently bind a function to a specific object as its context, regardless of how the function is later invoked.</p><p>Here is the syntax.</p><pre>function myFunction(arg1, arg2) {<br>  // Function code here<br>}<br><br>var boundFunction = myFunction.bind(thisValue, arg1, arg2);</pre><p>The result of a bind call is a bound function whose this and arguments are tightly coupled with the function.</p><p>The “bind” method is often used when you want to create a new function that can be passed around or stored as a reference, but with a fixed context. It allows you to define the execution context and set initial arguments for the function, ensuring consistent behavior regardless of how or where the function is later called.</p><p>Here is a jogger. Can you override the arguments passed by the <em>bind function</em>?</p><p>Adios. 🙋‍♂️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e80d274b843" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero #61 Bind (Syntax and Example for beginner]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-61-bind-syntax-and-example-for-beginner-85c37b15f69a?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/85c37b15f69a</guid>
            <category><![CDATA[bind]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Fri, 26 May 2023 18:00:32 GMT</pubDate>
            <atom:updated>2023-05-26T18:00:32.805Z</atom:updated>
            <content:encoded><![CDATA[<h3>Javascript zero to hero #61 Bind (Syntax and Example for beginners) 👭</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ3AOsfosigzVqjEB4PJeg.jpeg" /></figure><p>The bind() method is a fundamental feature of JavaScript functions, providing a powerful way to control the execution context of a function. It creates a new function with the same body as the original function, but with a permanently bound this value and optionally, pre-specified arguments. The bound function can be called later with a different this value, and the original function&#39;s behavior remains unchanged.</p><h4>Syntax:</h4><p>The bind() method follows the syntax: function.bind(thisArg[, arg1[, arg2[, ...]]]).If that looked too much to you don&#39;t worry about it. Here, thisArg is the value that will be bound to this when the bound function is invoked. The subsequent optional arguments, arg1, arg2, etc., represent the arguments to be pre-specified when invoking the bound function.</p><h4>Creating a Bound Function</h4><p>Let’s take a closer look at how to create a bound function using the bind() method:</p><pre>const originalFunction = function(arg1, arg2) {<br>  console.log(this.name, arg1, arg2);<br>};<br><br>const boundFunction = originalFunction.bind({ name: &#39;Bound&#39; }, &#39;Argument1&#39;);<br><br>boundFunction(&#39;Argument2&#39;);<br>// Output: Bound Argument1 Argument2</pre><p>In the example above, we create a bound function boundFunction by invoking bind() on the originalFunction. We pass { name: &#39;Bound&#39; } as the thisArg parameter, which sets the this value inside originalFunction to the provided object. Additionally, we pre-specify the argument &#39;Argument1&#39; for the bound function. When we call boundFunction(&#39;Argument2&#39;), it prints the expected output by combining the bound this value and the provided arguments.</p><p>Other interesting function methods like call and apply will be discussed in subsequent blog articles. Have a nice day 🌼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85c37b15f69a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero #60 Object getters and setters]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-60-object-getters-and-setters-2b9b4f2a6bf4?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b9b4f2a6bf4</guid>
            <category><![CDATA[getters-and-setters]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Wed, 24 May 2023 11:33:29 GMT</pubDate>
            <atom:updated>2023-05-24T11:33:29.818Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="An image of Marcus Aurelius holding flowers" src="https://cdn-images-1.medium.com/max/1024/1*6S9fkSRwLWXurPJ5kFyUog.png" /></figure><p>In Javascript , objects are the most common data structure. Working with their properties might seem like a straight forward approach but the traditional method lacks the flexibility and control of getters and setters. In this article we are going to learn about getters and setters in depth.</p><h4>Disadvantages of direct property manipulation.</h4><p>Lets take an example.</p><pre>const person = {<br>  firstName: &quot;John&quot;,<br>  lastName: &quot;Doe&quot;<br>};<br><br>person.firstName = &quot;Jane&quot;; // Directly set the firstName property<br><br>console.log(person.firstName); // Output: Jane</pre><p>In this case anyone can directly change the firstName of this user but here is the problem. How about if we want to ensure that the first name always starts with capital letters?</p><h4>The power of getters and setters</h4><p>Getters and setters allow us to define custom behavior when accessing or modifying object properties. By leveraging these features, we gain fine-grained control over property manipulation. Let’s see how to create and use getters and setters:</p><pre>const person = {<br>  _firstName: &quot;John&quot;, // underscore prefix to indicate private property<br><br>  get firstName() {<br>    return this._firstName;<br>  },<br><br>  set firstName(newFirstName) {<br>    if (typeof newFirstName === &quot;string&quot; &amp;&amp; newFirstName.length &gt; 0) {<br>      this._firstName = newFirstName.charAt(0).toUpperCase() + newFirstName.slice(1);<br>    } else {<br>      throw new Error(&quot;Invalid first name.&quot;);<br>    }<br>  }<br>};<br><br>person.firstName = &quot;jane&quot;; // Using the setter to assign a new value<br><br>console.log(person.firstName); // Output: Jane</pre><p>In this approach we created a private property _firstNameand created getters and setters for it. The getter allows us to retrieve the value of _firstName, while the setter performs validations and manipulations before assigning a new value.</p><p>Now that we have the setter we can do everything we want with it. By implementing the setter, we enforce the rule that the firstName must always start with an uppercase letter. If an invalid value is provided, an error is thrown, ensuring data integrity and preventing unexpected behavior.</p><h4>Why bother with getters and setters?</h4><p>Benefits and Applications: Using getters and setters brings numerous advantages to our JavaScript code:</p><ol><li>Encapsulation: Getters and setters allow us to encapsulate the internal state of an object, providing a controlled interface for accessing and modifying properties.</li><li>Validation and Error Handling: We can perform validations and implement error handling logic within setters to ensure data consistency and prevent incorrect values from being assigned.</li><li>Computed Properties: Getters can dynamically compute and return values based on other properties, enabling us to derive complex data on the fly.</li><li>Side Effects and Actions: Setters can trigger additional actions or updates when properties are modified, allowing us to maintain consistency across related data or perform necessary calculations.</li></ol><p>Well this is not a concept to go all day for. Getters and setters provide a certain power that you can only realize if you understand how direct manipulation can trip you up. Consider leveraging the power of getters and setters next time in your JS projects 🔥</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b9b4f2a6bf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero #59 Iterators and Iterables.]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-59-iterators-and-iterables-35d9596c5053?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/35d9596c5053</guid>
            <category><![CDATA[iterables]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[iterators]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Mon, 22 May 2023 17:31:12 GMT</pubDate>
            <atom:updated>2023-05-22T17:31:12.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ3AOsfosigzVqjEB4PJeg.jpeg" /></figure><p>An iterator is an object that provides a way to access elements sequentially from a collection such as an array or a string (or any other iterable object).It defines a standard interface that allows you to traverse the elements of a collection one at a time, without needing to know the internal details of the collection.</p><p>Before we dive deeper into iterators its best we learn about iterables first.</p><p>In JavaScript, an iterable is an object that defines an iterator, allowing it to be iterated over using the for...of loop, the spread operator (...), and other built-in mechanisms that expect iterables. An iterable object must implement the Symbol.iterator method, which returns an iterator object.</p><p>The Symbol.iterator method is a well-known symbol in JavaScript that represents the iterator for an object. When called, it should return an iterator object that conforms to the iterator protocol. The iterator protocol requires the iterator object to have a next() method that returns an object with two properties: value, which represents the next value in the iteration, and done, which indicates whether the iteration is complete.</p><p>Here’s an example of an iterable object:</p><pre>const iterable = {<br>  [Symbol.iterator]() {<br>    let count = 1;<br>    return {<br>      next() {<br>        if (count &lt;= 5) {<br>          return { value: count++, done: false };<br>        }<br>        return { value: undefined, done: true };<br>      }<br>    };<br>  }<br>};<br><br>for (const value of iterable) {<br>  console.log(value);<br>}</pre><p>In this example, iterable is an object with a Symbol.iterator method. The method returns an iterator object that counts from 1 to 5. The for...of loop iterates over the iterable object, printing the values 1 to 5.</p><p>Not all objects are iterables by default. Objects like numbers, booleans, and null are not iterable. However, many built-in JavaScript data structures are iterable, such as arrays, strings, maps, sets, and generators. Additionally, you can make custom objects iterable by implementing the Symbol.iterator method.</p><h4>iterators continuation….</h4><p>To work with iterators, JavaScript provides the concept of an iterable object. An iterable object is an object that implements the Symbol.iterator method, which returns an iterator object. The iterator object, in turn, provides a next() method that returns the next element in the collection along with a done property to indicate whether the iteration is complete.</p><p>Here’s an example that demonstrates the usage of iterators in JavaScript:</p><pre>const iterable = [1, 2, 3, 4, 5];<br>const iterator = iterable[Symbol.iterator]();<br><br>console.log(iterator.next()); // { value: 1, done: false }<br>console.log(iterator.next()); // { value: 2, done: false }<br>console.log(iterator.next()); // { value: 3, done: false }<br>console.log(iterator.next()); // { value: 4, done: false }<br>console.log(iterator.next()); // { value: 5, done: false }<br>console.log(iterator.next()); // { value: undefined, done: true }</pre><p>In this example, the array iterable is an iterable object. We obtain an iterator by calling iterable[Symbol.iterator](), and then we can use the iterator&#39;s next() method to iterate over the elements of the array. Each call to next() returns an object with a value property representing the current element and a done property indicating whether the iteration is complete.</p><p>Quick description of iterators. Hope you loved learning about the concept. 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35d9596c5053" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript zero to hero #58 Generators⚙]]></title>
            <link>https://medium.com/@amosmachora/javascript-zero-to-hero-58-generators-e4c12c954cef?source=rss-8f4b825473a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4c12c954cef</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[generator]]></category>
            <dc:creator><![CDATA[Amos Machora]]></dc:creator>
            <pubDate>Sat, 20 May 2023 07:20:21 GMT</pubDate>
            <atom:updated>2023-05-20T07:20:21.040Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJ3AOsfosigzVqjEB4PJeg.jpeg" /></figure><h3>Generators</h3><p>What do you think about when you hear the word generator? An Electric <strong>generator</strong>, a device that converts mechanical energy to electrical energy. So what is it then in Javascript?</p><p>Traditionally when you create a Javascript function and call it it executes and returns a value. The execution of the function is not up to the programmer during runtime. Its like you make a baby and let it run whether or not it will fall over its not up to you because well you had the chance to code it right and you did or didn&#39;t.</p><p>Generators are function that can be paused and asked to resume execution at a later time. It allows you to control the execution flow and generate a sequence of values over time, instead of computing them all at once.</p><p>So how do we create them?</p><pre>function* numberGenerator() {<br>  let num = 1;<br>  while (true) {<br>    yield num;<br>    num++;<br>  }<br>}</pre><p>In the example above, the numberGenerator function is a generator that yields an incremented number each time next() is called. The generator can be used to generate numbers indefinitely. Each call to generator.next() returns an object with a value property representing the yielded value.</p><p>When a generator encounters a yield statement it pauses execution and returns the yielded value. The execution can later be resumed by calling the next method on the generator object.</p><p>You can actually pass arguments to generator functions by passing values to the next method of thee generator. For example suppose we want to create a function that we call to greet a user with different userNames, how would we do that?</p><pre>function* greetGenerator() {<br>  const name = yield &quot;What is your name?&quot;;<br>  yield `Hello, ${name}!`;<br>}</pre><p>The first time we call next().value what do you think will be returned? How about the second?</p><pre>const generator = greetGenerator();<br>console.log(generator.next().value); // Output: &quot;What is your name?&quot;<br>console.log(generator.next(&quot;John&quot;).value); // Output: &quot;Hello, John!&quot;</pre><p>to stop the execution of generator functions we call the return method of the generator object.</p><pre>function* infiniteGenerator() {<br>  let num = 1;<br>  while (true) {<br>    yield num;<br>    num++;<br>  }<br>}<br><br>const generator = infiniteGenerator();<br>console.log(generator.next().value); // Output: 1<br>console.log(generator.next().value); // Output: 2<br><br>generator.return(); // Terminate the generator<br><br>console.log(generator.next().value); // Output: undefined</pre><p>There are a lot of generator use cases for example</p><ul><li>Custom control flow</li><li>infinite sequences and stream processing</li><li>asynchronous programming</li></ul><p>But we are not going to delve into that because those are advanced topics and this series was made for beginners but if you wish to learn about them I would be happy to follow up this article with another one.</p><p>Adios friends 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4c12c954cef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>