<?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 Jamaicancoder on Medium]]></title>
        <description><![CDATA[Stories by Jamaicancoder on Medium]]></description>
        <link>https://medium.com/@juniormarch48?source=rss-28501ba74031------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qK2yRV_EfFg-uzACovR4Wg.jpeg</url>
            <title>Stories by Jamaicancoder on Medium</title>
            <link>https://medium.com/@juniormarch48?source=rss-28501ba74031------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 23:52:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@juniormarch48/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[The Step-by-Step Guide to Create Your First Product in Shopify]]></title>
            <link>https://medium.com/@juniormarch48/the-step-by-step-guide-to-create-your-first-product-in-shopify-805fb192c247?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/805fb192c247</guid>
            <category><![CDATA[shopify]]></category>
            <category><![CDATA[side-hustle]]></category>
            <category><![CDATA[money]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[financial-independence]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Sun, 12 Feb 2023 19:31:52 GMT</pubDate>
            <atom:updated>2023-02-12T19:31:52.284Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*WOm-wzQj5x3EapwOelWSCw.jpeg" /></figure><p>So you have decided to do something new and exciting: open an eCommerce store on Shopify<em>. </em>It might sound scary for those who are not technologically savvy or do not know where to start. And that is okay! Instead of letting the learning experience become daunting, there are many Shopify experts, resources, and <a href="https://digital.com/best-ecommerce-platforms/shopify/tips/">Shopify tips</a> out in the Internet world that can help you along the way.</p><p>The first step towards managing an eCommerce store is to create your first product. With that said, you may or may not already have an idea for your product. If not, <a href="https://www.shopify.ca/blog/product-opportunities">you can check out this helpful article on finding the perfect product to sell.</a> Once you’ve got a product, you need to list it on your store.</p><p>Let’s go over what it takes to create the very first product on your store step-by-step:</p><p>Topics:</p><ul><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_1_Go_to_the_Products_section_on_your_Shopify_Admin">Step 1: Go to the Products section on your Shopify Admin.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_2_Add_a_Title">Step 2: Add a Title.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_3_Include_a_Description">Step 3: Include a Description.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_4_Add_Images">Step 4: Add Images.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_5_Include_Pricing">Step 5: Include Pricing.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_6_Enter_your_Inventory">Step 6: Enter your Inventory.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_7_Add_Shipping_Details">Step 7: Add Shipping Details.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_8_Enter_Variants">Step 8: Enter Variants.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_9_Create_a_Search_Engine_Listing_Preview">Step 9: Create a Search Engine Listing Preview.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_10_Enter_Product_Availability">Step 10: Enter Product Availability.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Step_11_Set_Up_Your_Product_Organization">Step 11: Set Up Your Product Organization.</a></li><li><a href="https://blog.getmesa.com/blog/step-by-step-guide-to-create-your-first-product-in-shopify/#Your_First_Product_is_Now_Complete">Your First Product is Now Complete</a></li></ul><h3>Step 1: Go to the Products section on your Shopify Admin.</h3><p>Navigate to the Products section via the side menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/0*bLVR6tNgqtGBbzzD.png" /></figure><p>Here, you’ll click on the Add product button (the purple button at the top left).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*HusUHpTvcSlIZ9-R.png" /></figure><p>Once you are on this page, you will see a lot of information that has yet to be filled. You do not have to fill out every little detail in order to add a product. As you take a look at the page, you will fill out the following information:</p><h3>Step 2: Add a Title.</h3><p>Your product’s title is a good place to add keywords to help improve your SEO. If you don’t know already, SEO (Search Engine Optimization) is a way to increase the visibility of a page on a search engine. (If you want to learn more about that, <a href="https://moz.com/beginners-guide-to-seo">this piece by Moz</a> is the perfect starting point.) By placing some keywords into your product’s title, potential customers will have a higher chance of finding your product on Google. The title will also appear in your store as well.</p><h3>Step 3: Include a Description.</h3><p>Your product’s description is the best way to explain and sell your product to your target audience and <a href="https://blog.theshoppad.com/7-common-copywriting-mistakes-in-ecommerce">grab their attention</a>. If you wish to read the best nine ways to create product descriptions, <a href="https://www.shopify.com/blog/8211159-9-simple-ways-to-write-product-descriptions-that-sell">click here for more information.</a> Shopify has provided a <a href="https://help.shopify.com/en/manual/productivity-tools/rich-text-editor">rich text editor</a> so you can customize your description.</p><p><a href="https://blog.getmesa.com/blog/gmv-meaning/"><strong>Related Post: What is GMV and How to Increase Your Gross Merchandise Value</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/0*E6mxEHrMDOfEWmNp.png" /></figure><p>If you are unfamiliar with any of the icons on top of the textbox, you can hover over the icons and read the icons’ descriptions.</p><h3>Step 4: Add Images.</h3><p>The very first image that you upload will be the product’s main image. You can simply click on Upload Image in the top right-hand corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*IkGSOMKZ-zxX-PYt.png" /></figure><p>Once you upload an image, you can hover over the image and find more settings: Preview, Alt Text, and Delete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/0*e7ihdhUj5xe7_1Ed.png" /></figure><p>Don’t forget your image’s Alt Text. This useful field allows you to add a description for customers that are visually impaired. It is another way to improve your SEO, as it makes the images crawlable for Google.</p><h3>Step 5: Include Pricing.</h3><p>There are a few options you can use to enter your pricing:</p><ul><li>Compare At Price: An optional field to grab your customer’s attention by telling them that your product is on sale. On your product page, there will be a for-sale price and an original price that is crossed off. This can influence your customers into thinking that your product is on sale for a limited amount of time. Therefore, they should purchase your product right now before your product is sold out.</li><li>Cost Per Item: This is how much the product is costing you to make and ship. This is simply an internal way to keep track of your product’s cost.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*lcvRUkr3tv_x-0XA.png" /></figure><h3>Step 6: Enter your Inventory.</h3><p>This one’s simple: it’s where you are able to keep track of inventory. So make sure you enter the right amount of the product from the beginning.</p><h3>Step 7: Add Shipping Details.</h3><p>This section enables Shopify to calculate a customer’s shipping automatically, so you don’t have to get on and manually calculate shipping costs everytime a customer makes an order. You’ll see the following sections available:</p><ul><li>Physical Product: Unselect the checkbox if the product is digital or does not need to be shipped</li><li>Weight: How much your product weighs. You can set the weight as pounds (lb), ounces (oz), kilograms (kg), and grams (g).</li><li>Country/Region of origin: The location where your product is manufactured or created. If you are shipping a product internationally, the shipping cost might include duties.</li><li>HS (Harmonized System) code: If you wish to sell this product overseas, you will need to enter a harmonized system code. By doing this, the appropriate tariffs will be applied to the customer’s order.</li><li>Fulfillment Service: If you are not using a fulfillment service, you can just select Shopify. However, if you have a fulfillment service, you can add one by going to Settings (from your Shopify Admin) → Shipping. Then, scroll down until you see Custom Order Fulfillment and click on Add Fulfillment Service. Discover <a href="https://blog.getmesa.com/solutions?role=operations">fulfillment workflows</a> to help streamline this process.</li></ul><p><a href="https://blog.getmesa.com/blog/7-best-erps-for-shopify-stores-in-2022/"><strong>Related Post: 7 Best Shopify ERPs for your stores in 2022</strong></a></p><h3>Step 8: Enter Variants.</h3><p>You can create up to one hundred variants that will allow you to sell different combinations to your customers. Also, you can create up to three different options for the same product. For example, the product can have different attributes: sizes, colors, and weight. Then, you are allowed up to one hundred different combinations among the different sizes, colors, and weight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/0*_LWoosghoneXYRzM.png" /></figure><p>To have more than one hundred variants, you will need to look into third-party applications. We’d suggest you use our app, Infinite Options, which is the most popular product option app on Shopify. You can also take it a step further with MESA and truly automate any product on your page.</p><h3>Step 9: Create a Search Engine Listing Preview.</h3><p>Throughout this guide, we have talked about SEO numerous times. Well, here is a helpful tool to customize the preview of your product in a search engine’s results. Click on Edit Website SEO to view your options: Page Title, Meta Description (your product’s description), and the Product’s URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/0*cWpBVpaijORjSaff.png" /></figure><h3>Step 10: Enter Product Availability.</h3><p>Product availability is useful for those who sell on multiple platforms (also known as sales channels). You can decide on whether you wish to sell your particular product on selective channels or if you want to sell the product at a certain time.</p><p>To publish the product at a later time and date, click on the calendar icon. This is most commonly used when you want to release the product at a certain time (like an anticipated and big release) or you just simply do not want to forget to publish the product in the future.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/0*3bxbibdi7uPaRdge.png" /></figure><h3>Step 11: Set Up Your Product Organization.</h3><p>Your products can be orders in a variety of methods.</p><ul><li>Product Type is a way to categorize your product. To create a product type, simply enter the text in the textbox and click on Save. Existing product types will auto populate under the text that you have entered.</li><li>Vendor is your product’s vendor, wholesaler, or manufacturer.</li><li>Collections are groupings of products. You can add your product to a manual or automated collection. An automated collection will look out for products that meet the collection’s conditions. <a href="https://help.shopify.com/en/manual/products/collections/automated-collections">Click here is more information about automated collections.</a></li><li>Tags allow you keep organized on your backend by enabling to search for products in related groups.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/0*p-h_396KTIIb3hqP.png" /></figure><h3>Your First Product is Now Complete</h3><p>That is all you need to create products on a Shopify store. You now have the ability to create your entire collection of products!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=805fb192c247" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A High-Level Technical Overview of SQL]]></title>
            <link>https://medium.com/@juniormarch48/a-high-level-technical-overview-of-sql-4ff9a7181d2e?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ff9a7181d2e</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Wed, 08 Feb 2023 01:38:50 GMT</pubDate>
            <atom:updated>2023-02-08T01:38:50.285Z</atom:updated>
            <content:encoded><![CDATA[<p>SQL: The Language of the Gods (or Just Really Smart People)</p><p>SQL, or Structured Query Language, is a powerful tool for organizing and manipulating data. It’s used by businesses, governments, and organizations all over the world to manage their vast stores of information. But for the rest of us mere mortals, SQL can be a confusing and intimidating language to learn.</p><p>But don’t worry, dear reader, I’ll do my best to make this technical article a little more enjoyable with some Jamaican jokes and sarcasm. So sit back, grab a Red Stripe, and get ready for a wild ride through the world of SQL.</p><p>First, let’s talk about what SQL actually does. Essentially, SQL allows you to manage your data by allowing you to create tables, add data to those tables, manipulate that data, and retrieve information from those tables. It’s like having a librarian who can organize your books and find the information you need in seconds, rather than having to search through stacks of books yourself.</p><p>Now, you may be thinking, “But I already use Google Sheets, why do I need SQL?” Well, while Google Sheets is great for managing small amounts of data, it quickly becomes difficult to manage large amounts of data in a spreadsheet format. Plus, SQL has many more advanced features such as data integrity, data security, and advanced querying options.</p><p>So, how does one actually use SQL? Well, it’s a little like learning a new language. Just like you need to learn the words and grammar of a new language, you need to learn the commands and syntax of SQL.</p><p>Let’s start with the basics. To create a table in SQL, you use the “CREATE TABLE” command. This is where you specify the name of the table and the columns that you want to include in the table. For example:</p><p>CREATE TABLE customers ( customer_id INT PRIMARY KEY, name VARCHAR(50), address VARCHAR(100), city VARCHAR(50), state CHAR(2), zip_code INT );</p><p>This code creates a table named “customers” with six columns: customer_id, name, address, city, state, and zip_code.</p><p>Next, let’s add some data to our table using the “INSERT INTO” command. For example:</p><p>INSERT INTO customers (customer_id, name, address, city, state, zip_code) VALUES (1, ‘Bob Marley’, ’56 Hope Road’, ‘Kingston’, ‘Jamaica’, 12345);</p><p>This code adds a new customer to the “customers” table with a customer_id of 1, name of Bob Marley, and the specified address, city, state, and zip code.</p><p>Now, let’s say we want to retrieve information from our table. This is where the “SELECT” command comes in. For example:</p><p>SELECT name, address, city, state, zip_code FROM customers;</p><p>This code retrieves all the information from the “name”, “address”, “city”, “state”, and “zip_code” columns in the “customers” table.</p><p>But wait, there’s more! You can also use the “WHERE” clause to filter the data you retrieve. For example:</p><p>SELECT name, address, city, state, zip_code FROM customers WHERE state = ‘Jamaica’;</p><p>This code retrieves only the information from customers who live in Jamaica.</p><p>SQL is a language that allows you to do so much more than just retrieve data from tables. You can also update existing data, delete data, and even join multiple tables together to create new, more complex tables.</p><p>For example, let’s say we want to update Bob Marley’s address in our “customers” table. We can use the “UPDATE” command like this:</p><p>UPDATE customers SET address = ’56 Hope Road, Kingston, Jamaica’ WHERE customer_id = 1;</p><p>This code updates the address for the customer with the customer_id of 1 to the specified new address.</p><p>And if we want to delete a customer from our table, we can use the “DELETE” command:</p><p>DELETE FROM customers WHERE customer_id = 1;</p><p>This code deletes the customer with the customer_id of 1 from the “customers” table.</p><p>Finally, let’s talk about joining tables. Let’s say we have another table named “orders” that contains information about orders placed by our customers. We can use the “JOIN” command to join this table to our “customers” table to get a combined view of both tables. For example:</p><p>SELECT customers.name, orders.order_id, orders.order_date FROM customers JOIN orders ON customers.customer_id = orders.customer_id;</p><p>This code retrieves the name of the customer, the order_id, and the order_date from the “customers” and “orders” tables, joining the two tables based on the customer_id.</p><p>And there you have it, a high-level overview of SQL and some of its most commonly used commands. It may seem overwhelming at first, but with practice and patience, anyone can master the language of the gods (or just really smart people).</p><p>So, if you’re ready to join the ranks of the SQL elite, grab another Red Stripe, hit the books, and start practicing. And remember, as a wise man (Bob Marley) once said, “Don’t worry ‘bout a thing, every little thing is gonna be alright.”</p><p>P.S. If you’re still struggling, just remember: “Mi no know ‘bout the technical stuff, but mi know how to find the data and get the job done mon.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ff9a7181d2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breaking the Chains of Colorism: Unpacking the Roots of Self-Hatred in the Black Community]]></title>
            <link>https://medium.com/@juniormarch48/breaking-the-chains-of-colorism-unpacking-the-roots-of-self-hatred-in-the-black-community-7252bc540ca9?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/7252bc540ca9</guid>
            <category><![CDATA[career-development]]></category>
            <category><![CDATA[black-history-month]]></category>
            <category><![CDATA[racism]]></category>
            <category><![CDATA[happiness]]></category>
            <category><![CDATA[blacklivesmatter]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Mon, 06 Feb 2023 12:22:27 GMT</pubDate>
            <atom:updated>2023-02-06T12:23:12.912Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*DtXBsnC_OrhNFLFVjqHMmg.jpeg" /></figure><p>In the spirit of Black History Month, let’s talk about a topic that is pervasive in our communities: colorism. Colorism is a form of discrimination where people are treated differently based on the shade of their skin tone. This problem is not just confined to the black community, but it is especially prevalent in the black community. The effects of colorism are damaging and lead to self-hatred in many black people.</p><h3><strong>Why Do We Hate Ourselves?</strong></h3><p>According to the article “Why Do We Hate Ourselves,” many black people have internalized the belief that lighter skin is more desirable, leading to a self-hate that is rooted in colonialism and slavery. The article states that “during the trans-Atlantic slave trade, lighter-skinned slaves were given preferential treatment and assigned to domestic work, while darker-skinned slaves were subjected to harsh manual labor in the fields.” This created a lasting impact on the black community, leading to a belief that lighter skin is more valuable and desirable.</p><p>As a result of this belief, many black people, particularly women, feel pressure to lighten their skin through various means, such as skin-lightening creams and procedures like skin bleaching. This only perpetuates the idea that lighter skin is better and reinforces the self-hatred that many black people feel. The article highlights that this self-hate is not just limited to physical appearance but extends to cultural beliefs and practices as well.</p><h3><strong>Colorism</strong></h3><p>The problem of colorism is not just about skin color, but about the systemic and institutionalized racism that continues to impact the black community. The belief in the superiority of lighter skin tones is rooted in a history of colonialism and slavery that has created a lasting impact on the black community. This has led to self-hatred and internalized racism in many black people, causing them to discriminate against others based on skin color.</p><p>To combat colorism and self-hate, it is important to address the systemic issues that contribute to it. This can be done by educating people on the history and impact of colorism and promoting positive self-image and self-love. It is also important to challenge and reject the beauty standards that perpetuate the belief that lighter skin is more desirable.</p><h3><strong>Hope for the future.</strong></h3><p>In addition to these efforts, it is also crucial to support and uplift black people who are marginalized and discriminated against due to their skin color. This includes supporting and promoting black-owned businesses and organizations that work towards promoting positive self-image and self-love in the black community.</p><h3><strong>Conclusion</strong></h3><p>In conclusion, colorism is a pervasive issue in the black community that has damaging effects on black people. The belief in the superiority of lighter skin tones is rooted in a history of colonialism and slavery that has created a lasting impact on the black community. To combat colorism and self-hate, it is important to address the systemic issues that contribute to it, educate people on the history and impact of colorism, promote positive self-image and self-love, and support and uplift black people who are marginalized and discriminated against due to their skin color.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7252bc540ca9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Blockchain and Cryptocurrency?]]></title>
            <link>https://medium.com/@juniormarch48/what-is-blockchain-and-cryptocurrency-e44e4784af87?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/e44e4784af87</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[future]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 14:38:26 GMT</pubDate>
            <atom:updated>2023-02-05T14:38:26.755Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*_lWl4E0tayu5Xi1mfgdKeA.jpeg" /></figure><h3>Ethereum, Ripple, and Dogecoin (yes, you heard that right, Dogecoin. Jamaican dog owners, beware!).</h3><p>Let’s take an example of a Jamaican man named Marcus who wants to buy some bananas from a farmer. Instead of using Jamaican dollars, Marcus decides to use Bitcoin. He transfers the equivalent amount of Bitcoin to the farmer’s digital wallet. The transaction is verified by the network, and a new block is added to the blockchain, recording the transaction. The farmer can now access his bananas and his newfound riches, while Marcus can enjoy his delicious and nutritious breakfast.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*ngdyNX44LQCelFfTagMn_w.jpeg" /></figure><h3><strong>Bitcoin Origins</strong></h3><p>Now, I know what you’re thinking. “But wait, isn’t Bitcoin just a bunch of computer code? How can it have value?” Well, my dear child, it’s all about trust and scarcity. People trust that they can use Bitcoin to buy goods and services, and that the value of their coins won’t suddenly drop to zero. And because there’s a limited supply of Bitcoin (only 21 million coins will ever be created), it makes it more valuable, much like gold or other precious metals.</p><h3>What is the Blockchain?</h3><p>So, there you have it, the basics of blockchain and cryptocurrency. It may seem like a lot to take in, but trust me, it’s much simpler than learning how to cook ackee and saltfish (which, by the way, is an art form in and of itself). Just remember, with blockchain and cryptocurrency, you’re in control of your own finances. No more banks or governments telling you what to do with your hard-earned coins. It’s like having your own personal piggy bank on steroids!</p><p>And now, let’s all take a break and go find some tasty Jamaican patties. After all, we deserve a reward for learning about such complicated technology.</p><p>As you may have noticed, I’ve been using a lot of sarcasm and humor throughout this article. But make no mistake, I take blockchain and cryptocurrency very seriously. It’s a revolutionary technology that has the potential to change the world as we know it. And that’s no laughing matter.</p><h3><strong>Python</strong></h3><p>Python is a high-level, interpreted programming language that was first released in 1991 by Guido van Rossum. It’s known for its readability and simplicity, making it a popular choice for beginners and experts alike. Python is used in a wide range of applications, from web development and data analysis to machine learning and scientific computing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/156/1*dXOSUzIQ8NzuWjpoTUdZfw.jpeg" /></figure><h3><strong>Cryptocurrency</strong></h3><p>Cryptocurrency is a digital or virtual form of currency that uses cryptography for security. It operates independently of a central bank and is decentralized, meaning that transactions are recorded on a public ledger (the blockchain) and verified by a network of computers. The first cryptocurrency, Bitcoin, was created in 2009 by an unknown person or group using the pseudonym Satoshi Nakamoto.</p><h3><strong>Origins of Crypto</strong></h3><p>The origins of cryptocurrency can be traced back to the 2008 financial crisis, when many people lost faith in the traditional banking system. Bitcoin was created as a decentralized alternative to traditional currencies, with the aim of providing a secure and transparent financial system.</p><h3><strong>Bitcoin</strong></h3><p>Since the creation of Bitcoin, many other cryptocurrencies have emerged, each with its own unique features and goals. Some, like Ethereum, aim to provide a platform for decentralized applications, while others, like Litecoin, aim to improve on the limitations of Bitcoin.</p><h3><strong>Future of Cryptocurrency</strong></h3><p>As for the future of cryptocurrency, it’s still a hotly debated topic. Some experts believe that it has the potential to replace traditional currencies and revolutionize the financial industry, while others are more skeptical and see it as a speculative bubble. Nevertheless, the popularity of cryptocurrency continues to grow, and it will be interesting to see how it evolves in the coming years.</p><p>But before we get too ahead of ourselves, let’s take a closer look at some of the code behind blockchain. Don’t worry, I’ll keep it simple for all you non-coders out there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*DfTSYpqB7oq6OGeXvsKa3g.png" /></figure><p>This is a basic implementation of a blockchain in Python. As you can see, it’s not rocket science (although, that would be pretty cool). The class Block has two instance variables: data and previous_hash. The data variable is simply the information that we want to store in the block (e.g. a transaction), and the previous_hash is a reference to the previous block in the chain. The calculate_hash method takes the data and previous hash and calculates a new hash value using the SHA-256 algorithm.</p><h3><strong>Blockchain Class</strong></h3><p>The Blockchain class is where all the magic happens. It keeps track of all the blocks in the chain and has methods for adding new blocks and getting the previous block. The create_genesis_block method creates the first block in the chain, also known as the &quot;Genesis Block&quot;.</p><p>In the example code, we create a Blockchain object and add three blocks to the chain. Finally, we loop through the chain and print out the data, previous hash, and hash for each block.</p><p>And there you have it! A simple, yet powerful implementation of a blockchain. It’s amazing what a few lines of code can do, isn’t it?</p><h3><strong>Conclusion</strong></h3><p>blockchain and cryptocurrency are changing the way we think about money, security, and privacy. It’s a complex technology, but with a little bit of understanding, you too can be a part of this revolution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e44e4784af87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A High-Level overview of the Internet of Things]]></title>
            <link>https://medium.com/@juniormarch48/a-high-level-overview-of-the-internet-of-things-c0691a98e27b?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0691a98e27b</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 13:44:28 GMT</pubDate>
            <atom:updated>2023-02-05T13:44:28.622Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Ah, the Internet of Things (IoT). A world where even yu fridge can have a WhatsApp account, where yu air conditioner can chat to yu car, and where yu smartwatch can take over the rule of yu life. Welcome to the future, mon!</p><p>IoT is essentially a bunch of inanimate objects that have suddenly developed opinions and desires. You heard it right, these objects now have the audacity to tell us how to live our lives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*zHe9MIp_KGaxkQ2bmtGSAA.jpeg" /></figure><p>Take the smart home system for example. In the olden days, we used to control our homes manually — turn off lights with our own two hands, adjust the thermostat with a simple twist. But now, we got all kinds of gadgets telling us what to do.</p><p>“Turn off the lights, mon!”, “Lower the temperature, mon!”, “Lock the door, mon!”. And we just blindly obey like robots.</p><p>But let’s not forget the real MVP of IoT, the code. Code is the language that these inanimate objects speak, and without it, they wouldn’t be able to boss us around.</p><p>Here’s a little code snippet for ya, just to show you how simple it is to control an IoT device:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*RHhCV1mfDpn-dRrAS-SMLA.png" /></figure><p>Don’t worry, it’s not rocket science. Even a Jamaican farmer can understand it. Just a few lines of code and you can control the world (or at least your IoT devices).</p><p>But before you get too excited about building your own IoT system, let me remind you that it’s not all sunshine and ganja smoke. IoT comes with its own set of challenges, such as security and privacy concerns.</p><p>Imagine if a hacker was able to gain access to yu smart home system and turn off yu alarm, unlock yu doors, and change the temperature in yu home. Scary, right? That’s why it’s important to prioritize security when building an IoT system, unless yu want to spend the rest of yu life sleeping in a barrel inna the market square.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*udndspGFU2mLg_C4MsZYnQ.jpeg" /></figure><p>But despite its challenges, IoT has the potential to make our lives better, more efficient, and more convenient. And let’s be honest, who doesn’t love a little convenience in their life?</p><p>Think about it, yu smartwatch can now remind you to drink water every hour, yu fridge can automatically order groceries when yu run low, and yu car can park itself. How cool is that?</p><p>But the real question is, who’s in charge now? Us or the IoT devices? Are we the masters or are we the servants? It’s a thin line, mon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*xYYg7dhxalM8bn0U5QBmbA.jpeg" /></figure><h3><strong>Conclusion</strong></h3><p>So in conclusion, IoT is more than just a bunch of inanimate objects with opinions. It’s a revolutionary technology that’s changing the way we live, work, and interact with the world around us. And while it may have its challenges, the benefits are too great to ignore.</p><p>Now, let’s end this article with a little Jamaican flavor. What do you call an IoT device that’s gone rogue? A rebellious robot, mon! What do you call an IoT device that’s always running late? A tardy tech!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0691a98e27b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I built a wind map with WebGL]]></title>
            <link>https://medium.com/@juniormarch48/how-i-built-a-wind-map-with-webgl-d74769282484?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/d74769282484</guid>
            <category><![CDATA[weather]]></category>
            <category><![CDATA[devlog]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 13:29:14 GMT</pubDate>
            <atom:updated>2023-02-05T13:29:14.688Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*yam8J1Ig7GoFvZsm.png" /></figure><p><em>Check out my </em><a href="https://mapbox.github.io/webgl-wind/demo/"><em>WebGL-based wind power simulation demo</em></a><em>! Let’s dive into how it works under the hood.</em></p><p>I avoided direct OpenGL/WebGL programming like a plague. For one reason: the OpenGL API and terminology deeply terrified me. It always looked so complex, confusing, ugly, and verbose that I could never take the plunge and dive into it. I would get an uneasy feeling simply hearing terms like stencil masks, mipmap, depth culling, blend functions, and normal maps.</p><p>Last year, I decided to finally confront my fears and build something non-trivial with WebGL on my own. 2D wind simulation looked like a perfect opportunity — it’s useful, visually stunning, and challenging, yet it still felt attainable in scope. I was surprised to discover that it was much less scary than it looked!</p><h3>Wind visualization on the CPU</h3><p>There are many examples of wind power visualization online, but the most popular and influential one is <a href="https://earth.nullschool.net/">earth.nullschool.net</a>, a famous project by <a href="https://twitter.com/cambecc">Cameron Beccario</a>. It’s not open source itself, but it has an old <a href="https://github.com/cambecc/earth">open source version</a> which most other implementations based their code on. One notable open source derivation is <a href="https://github.com/Esri/wind-js/">Esri Wind-JS</a>. Popular weather services that use the technique include <a href="https://www.windytv.com/">Windy</a> and <a href="https://www.ventusky.com/">VentuSky</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*T_5npCLzb7ZJTeiM.png" /></figure><p>Wind power simulation on <a href="https://earth.nullschool.net/">earth.nullschool.net</a></p><p>Typically, such a visualization in the browser relies on the Canvas 2D API and roughly works like this:</p><ol><li>Generate an array of random particle positions on screen and draw the particles.</li><li>For each particle, query the wind data to get the particle speed in its current location, and move it accordingly.</li><li>Reset a small portion of particles to a random position. This makes sure that areas the wind blows away from never become fully empty.</li><li>Fade the current screen a bit and draw newly positioned particles on top.</li></ol><p>This has subsequent performance limitations:</p><ul><li>The number of wind particles should be kept low (e.g. Earth uses ~5k).</li><li>There’s a big delay every time you update the data or the view (e.g. ~2 seconds for Earth) because data processing is expensive and happens on the CPU side.</li></ul><p>Moreover, to integrate it as a part of an interactive WebGL-based map like <a href="https://www.mapbox.com/maps/">Mapbox</a> is that you would have to upload the pixel contents of the Canvas element to the GPU on every frame, which would significantly reduce the performance further.</p><p>I was looking for a way to reimplement the full logic on the GPU side with WebGL, so that it would be fast, capable of drawing millions of particles, and possible to integrate into a Mapbox GL map without a big performance loss. Luckily, I stumbled upon a wonderful tutorial about <a href="http://nullprogram.com/blog/2014/06/29/">particle physics in WebGL</a> by Chris Wellons, and realized that the wind visualization can use the same approach.</p><h3>OpenGL Basics</h3><p>The confusing API and terminology make OpenGL graphics programming very intimidating to learn, but under the surface, the concept is extremely simple. Here’s a practical definition:</p><blockquote><em>OpenGL provides a 2D API for </em><strong><em>drawing triangles </em></strong><em>efficiently</em><strong><em>.</em></strong></blockquote><p>So basically, all you do with GL is draw triangles. The difficulty, besides the scary API, comes from the various math and algorithms required to do this. It can also draw dots and basic lines (without smoothing or round joins/caps), but those are rarely used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/0*h-ZUQQ_rTJ8SGe-2.png" /></figure><p>Illustration from <a href="https://users.soe.ucsc.edu/~pang/162/s12/labnotes/shaders.html">Brief Introduction to Shaders Using GLSL</a></p><p>OpenGL provides a special C-like language — GLSL — to write programs that are directly executed by the GPU. Each program is divided into two parts, called shaders — the vertex shader and the fragment shader.</p><p>The <strong>vertex shader</strong> provides the code for converting coordinates. For example, multiplying triangle coordinates by 2 so that our triangle appears twice as big. It will run once for every coordinate we pass to OpenGL when drawing. A basic example:</p><pre>attribute vec2 coord;<br>void main() {<br>    gl_Position = vec4(2.0 * coord, 0, 1);<br>}</pre><p>The <strong>fragment shader</strong> provides the code for determining the color of each drawn pixel. You can do a lot of cool math in it, but in the end it comes down to something like “draw the current pixel of the triangle as green”. Example:</p><pre>void main() {<br>    gl_FragColor = vec4(0, 1, 0, 1);<br>}</pre><p>One of the cool things you can do in both vertex and fragment shaders is adding an image (called texture) as a parameter, and then looking up pixel colors in any spot of this image. We’ll rely on this heavily in the wind visualization.</p><p>The fragment shader code execution is massively parallel and heavily hardware-accelerated, so it’s usually many orders of magnitude faster than an equivalent computation on the CPU.</p><h3>Getting the wind data</h3><p>Every 6 hours, the US National Weather Service publishes <a href="http://nomads.ncep.noaa.gov/">weather data for the whole globe</a>, known as GFS, in the form of a latitude/longitude grid with associated values (including wind velocities). It’s encoded in a special binary format called GRIB, which can be parsed into human-readable JSON with a special <a href="https://software.ecmwf.int/wiki/display/GRIB/Releases">set of tools</a>.</p><p>I wrote a few small scripts that <a href="https://github.com/mapbox/webgl-wind/blob/master/data/download.sh">download</a> and <a href="https://github.com/mapbox/webgl-wind/blob/master/data/prepare.js">convert</a> the wind data into a simple PNG image with wind velocities encoded as RGB colors — horizontal velocity as red and vertical as green in each pixel. It looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*nazUkZdH2OIGTpdd.png" /></figure><p>GFS wind power data encoded as an image.</p><p>There are higher resolution versions you can download (2x and 4x), but 360×180 grid is enough for a low-zoom visualization. PNG compression is quite a good fit for this kind of data, and the image above typically weights just about 80 KB.</p><h3>Moving particles on the GPU</h3><p>Existing wind visualizations stored particle state in JavaScript arrays. How do we store and manipulate this state on the GPU side? A new GL feature called <a href="https://www.khronos.org/opengl/wiki/Compute_Shader">compute shaders</a> (in OpenGL ES 3.1 and equivalent WebGL 2.0 specifications) allows you to run shader code on arbitrary data (without any rendering). Unfortunately, support for the new specifications across browsers and mobile devices is marginal, and so we’re left with only one practical option: textures.</p><p>OpenGL allows you to draw not only to the screen, but also to a texture (through a concept called framebuffer). So we can encode particle positions as RGBA colors of an image, load it to the GPU, calculate new positions based on wind velocities in the fragment shader, encode them back into RGBA colors and draw it into a new image.</p><p>To store enough precision for both X and Y, we store each component in two bytes — RG and BA respectively, giving us a range of 65536 distinct values for each.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/0*RSdVSLZ7RpZPUijg.png" /></figure><p>Illustration from <a href="http://nullprogram.com/blog/2014/06/29/">A GPU Approach to Particle Physics</a></p><p>An example 500×500 image would then hold 250,000 particles, and we would move every particle with the fragment shader. The resulting image would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*QtukEz255tefqT-i.png" /></figure><p>Illustration from <a href="http://nullprogram.com/blog/2014/06/29/">A GPU Approach to Particle Physics</a></p><p>Here’s how the position is decoded and encoded from RGBA and back in the fragment shader:</p><pre>// lookup particle pixel color<br>vec4 color = texture2D(u_particles, v_tex_pos);// decode particle position (x, y) from pixel RGBA color<br>vec2 pos = vec2(<br>    color.r / 255.0 + color.b,<br>    color.g / 255.0 + color.a);... // move the position// encode the position back into RGBA<br>gl_FragColor = vec4(<br>    fract(pos * 255.0),<br>    floor(pos * 255.0) / 255.0);</pre><p>On the next frame, we can take this new image as the current state and draw the new state into the other image, etc., swapping the two every frame. So, with the help of two particle state textures, we can move all the wind simulation logic to the GPU.</p><p>This approach is extremely fast — instead of updating only 5,000 particles 60 times per second on the browser, we can suddenly handle <strong>one million</strong>.</p><p>One thing to keep in mind is that near the poles, the particles should move much faster along the X axis compared to the ones on the equator, because the same number of longitude degrees represents a much smaller distance. This can be taken into account with the following shader code:</p><pre>float distortion = cos(radians(pos.y * 180.0 - 90.0));<br>// move the particle by (velocity.x / distortion, velocity.y)</pre><h3>Drawing the particles</h3><p>As I mentioned earlier, in addition to triangles, we can also draw basic points — rarely used, but perfect for 1-pixel particles like this.</p><p>To draw each particle, we’ll simply look up its pixel color on the particle state texture in the vertex shader to determine its position; then determine the particle color in the fragment shader by looking up its current velocity from the wind texture; and finally map it to a nice color gradient (I picked the colors from the trusty <a href="http://colorbrewer2.org/">ColorBrewer2</a>). At this point, it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*9ER7OuFz8vcYnQ4D.png" /></figure><p>That’s something, if a little empty. But it’s hard to get a sense of wind direction from particle movement alone. We need to add particle trails.</p><h3>Drawing particle trails</h3><p>The first approach to drawing the trails I tried is using preserveDrawingBuffer WebGL option, which makes the screen state persist between frames, so that we can draw particles over and over on top of each other every frame as they move. However, this WebGL feature is a big performance hit, and many WebGL articles recommend against using it.</p><p>Instead, similar to how we do with particle state textures, we can draw the particles into a texture (which is in turn drawn onto a screen), then use this texture on the next frame as the background (slightly dimmed), and swap the input/target textures every frame. In addition to better performance, an advantage of this approach is that we can port it directly to native code (which has no preserveDrawingBuffer equivalent).</p><h3>Interpolating wind lookups</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*oe3iHW7Bsc5TCj12.png" /></figure><p>Illustration from a <a href="https://en.wikipedia.org/wiki/Bilinear_interpolation">Wikipedia article on Bilinear interpolation</a></p><p>The wind data has values for specific points on a latitude/longitude grid, e.g. (50,30),(51,30),(50,31),(51,31)geographical points. How do we get an arbitrary intermediate value, e.g. (50.123,30.744)?</p><p>OpenGL comes with free interpolation when you look up texture colors. However, it’s still leads to blocky, pixelated patterns. Here’s an example of these artifacts in the wind texture when scaled:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/0*R86zmcgQ0YRXYbSk.png" /></figure><p>Native GL linear interpolation</p><p>Luckily, we can smooth out the artifacts by looking up 4 neighbor pixels in each wind probe, and doing manual <a href="https://en.wikipedia.org/wiki/Bilinear_interpolation">bilinear interpolation</a> math on them on top of the native one in the fragment shader. It’s more expensive, but fixes the artifacts and leads to a more fluid wind visualization. Here’s the same area with this technique:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/0*3Zm1QgS1JM0NfLFU.png" /></figure><p>Manual bilinear interpolation on the fragment shader</p><h3>Pseudo-random generator on the GPU</h3><p>There’s one tricky logic left to implement on the GPU — randomly resetting particle locations. Without this, even a huge number of wind particles degenerates into just a few lines on the screen, because areas the wind blows away from become empty with time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*cv8hyruzR8US0lLh.png" /></figure><p>The problem is that shaders don’t have a random number generator. How do we randomly decide if a particle needs to be reset?</p><p>I found a solution <a href="https://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl">on StackOverflow</a> — a GLSL function for pseudo-random number generation that accepts a pair of numbers as input:</p><pre>float rand(const vec2 co) {<br>    float t = dot(vec2(12.9898, 78.233), co);<br>    return fract(sin(t) * (4375.85453 + t));<br>}</pre><p>This curious function depends on sin result varying a lot with big values. Then we can do something like this:</p><pre>if (rand(some_numbers) &gt; 0.99) <br>    reset_particle_position();</pre><p>The challenge is picking an input for each particle that would be “random” enough so that the generated values are uniform across the screen and do not exhibit weird patterns.</p><p>Using current particle position as the seed is not perfect because the same particle positions will always generate the same random numbers, so some particles will disappear in the same area.</p><p>Using particle position in the state texture also doesn’t work because the same particles will always disappear.</p><p>What I ended up with eventually depends on both particle position and state position coupled with a random value that’s calculated on every frame and passed to the shader:</p><pre>vec2 seed = (pos + v_tex_pos) * u_rand_seed;</pre><p>But then we have another minor problem — areas where particles are very fast will look much more dense than areas where there’s not much wind. We can balance this out a bit by increasing the particle reset rate for faster particles:</p><pre>float dropRate = u_drop_rate + speed_t * u_drop_rate_bump;</pre><p>speed_t here is a relative speed value (from 0 to 1), and u_drop_rate and u_drop_rate_bump are parameters you can tweak in the final visualization. Here&#39;s an example of how it affects the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*M6sR9xQ869EHVDGq.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*KlPYJSHEnjtnxpXS.png" /></figure><p>High drop rate (reminds me of a Van Gogh painting)</p><h3>What’s next?</h3><p>The result is a <a href="https://mapbox.github.io/webgl-wind/demo/">fully GPU-powered wind visualization</a> that can render a million particles at 60fps. Try playing with the sliders in the demo and check out <a href="https://github.com/mapbox/webgl-wind">the final code</a> — it’s about 250 lines total, and I tried to make it as readable as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d74769282484" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Engineering Method to Problem Solving: A Journey Through Coding Interviews with a Jamaican…]]></title>
            <link>https://medium.com/@juniormarch48/the-engineering-method-to-problem-solving-a-journey-through-coding-interviews-with-a-jamaican-4d5acc9fabe2?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d5acc9fabe2</guid>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 13:22:48 GMT</pubDate>
            <atom:updated>2023-02-05T13:22:48.126Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Engineering Method to Problem Solving: A Journey Through Coding Interviews with a Jamaican Twist</h3><p>As a software developer, problem-solving is at the core of our daily work. We are constantly presented with various challenges, whether it’s fixing a bug, optimizing a process, or creating a new feature. How do we go about solving these problems? Enter the engineering method to problem-solving.</p><h3><strong>The Way of Coding Interviews</strong></h3><p>The engineering method is a systematic approach to problem-solving that consists of five steps: exploring the problem, brainstorming, planning, implementing, and verifying. Let’s delve into each step to understand how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*L0cyZF4o6V8Ci0RhPaMPyg.jpeg" /></figure><h3>Step 1:Explore the Problem</h3><p>The first step in the engineering method is to explore the problem. This step involves a deep understanding of the problem and its desired outcome. It’s crucial to ask clarifying questions and come up with best- and worst-case scenarios to ensure that you have a clear understanding of the problem.</p><p>For example, imagine you are asked to develop a software solution for a Jamaican restaurant that allows customers to place their orders online. In the exploring step, you would ask questions such as: What kind of food does the restaurant serve? Are there any special requirements for the online ordering system? What is the target audience?</p><p>By answering these questions, you gain a comprehensive understanding of the problem, which will help you to come up with better solutions in the next steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*MddvNNGJVBb2O20Vn3v1Fg.jpeg" /></figure><h3><strong>Step 2: Brainstorm</strong></h3><p>The next step is to brainstorm, where you generate a list of different ideas to solve the problem. This step is crucial as it allows you to be creative and come up with unique solutions. The goal is to come up with as many ideas as possible, regardless of their feasibility.</p><p>For the Jamaican restaurant problem, you might come up with ideas such as:</p><ul><li>Develop a mobile app for customers to place their orders.</li><li>Integrate the ordering system with popular delivery services such as UberEATS and Grubhub</li><li>Implement a chatbot to assist customers with their orders.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D3ZsGPycGYKin7QOEAOn9A.jpeg" /></figure><h3>Step 3: Planning</h3><p>After generating a list of ideas, it’s time to pick the best one and outline its implementation. This step involves breaking down the solution into smaller, manageable parts and creating a plan to implement it.</p><p>For the Jamaican restaurant problem, you may choose to develop a mobile app for customers to place their orders. The planning step would involve defining the requirements for the app, creating a user flow, and outlining the technical implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*6YSBlLHAUbdSILkA73rLTg.jpeg" /></figure><h3><strong>Step 4: Implement</strong></h3><p>With a clear plan in place, it’s time to implement the solution. This step involves turning your plan into a working software solution. Depending on the complexity of the solution, this step can take anywhere from a few hours to several weeks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/215/1*fl2aKv9WvtOCVUhDkF21DQ.jpeg" /></figure><h3><strong>Step 5: Verify</strong></h3><p>The final step is to verify the solution. This step involves testing the solution using examples to ensure that it works as expected. If the solution doesn’t work as expected, you go back to the planning step to refine your plan and try again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*PgKtafM37_1jnTFhY62i4g.jpeg" /></figure><h3>Technical Interviews</h3><p>Now that we have a good understanding of the engineering method, let’s talk about coding interviews. A coding interview is a technical interview where a potential employer assesses a candidate’s ability to solve software problems. During a coding interview, you are typically presented with a problem and given a limited amount of time to solve it. The interviewer assesses your problem-solving skills, coding abilities, and ability to communicate your solution.</p><h3><strong>Failure is Good!</strong></h3><p>I remember failing my first coding interview. I was nervous and intimidated, and I didn’t have a systematic approach to solving the problem. After that interview, I realized that I needed to improve my problem-solving skills. That’s when I discovered the engineering method to problem-solving and started incorporating it into my interview preparation.</p><h3><strong>What Changed?</strong></h3><p>By using the engineering method, I was able to approach problems in a structured and systematic way. I was able to break down problems into smaller parts and create a plan to solve them. I also became better at communicating my thought process and solution to the interviewer, which was critical to acing further interviews.</p><p>One aspect that sets the engineering method apart is its versatility. It can be applied to a wide range of problems, from software development to everyday life. In my personal experience, I’ve found that the engineering method has helped me to solve problems more efficiently and effectively, both in my professional and personal life.</p><h3>Conclusion</h3><p>In conclusion, the engineering method to problem-solving is a valuable tool for software developers. By breaking down problems into smaller parts and creating a plan to solve them, you can approach problems in a structured and systematic way. Whether you are preparing for a coding interview or just trying to solve a problem at work, the engineering method is an excellent tool to have in your arsenal.</p><p>So the next time you are faced with a problem, remember the five steps of the engineering method: explore the problem, brainstorm, plan, implement, and verify. With a little practice, you’ll be able to tackle any problem with ease and confidence. And who knows, you may just ace your next coding interview.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d5acc9fabe2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rendering big geodata on the fly with GeoJSON-VT]]></title>
            <link>https://medium.com/@juniormarch48/rendering-big-geodata-on-the-fly-with-geojson-vt-1d428c1a8e7b?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d428c1a8e7b</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mapping]]></category>
            <category><![CDATA[leafletjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 13:13:33 GMT</pubDate>
            <atom:updated>2023-02-05T13:13:33.535Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Ladies and gentlemen, let us talk ‘bout the amazing advancements in computing technology. Despite the sheer complexity of processin’ and displayin’ large amounts of data dynamically, a smart approach with a strong algorithmic foundation can make the impossible, possible.</p><p>And what do we have here? Mapbox GL JS can handle loadin’ a massive 106 MB GeoJSON dataset of US ZIP code areas with over 33,000 features shaped by more than 5 million points, directly in the browser without server support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*7QS0zhX7zryDl5TndKR-uw.png" /></figure><p>Can you believe it, brethren? With just a few seconds of loadin’ time, you can browse through the entire dataset with ease and smoothness. But how does it work? Let us delve deeper.</p><h3>Slicin’ Vector Tiles</h3><p>We can’t expect to render such a vast amount of data in its entirety with 60 frames per second, but thankfully, we don’t have to. At lower zoom levels, shapes don’t need to be as detailed, and at higher zoom levels, much of the data is off the screen.</p><p>The best way to optimize the data for all zoom levels and screens is to chop it up into vector tiles. Traditionally, this is done on the server, with tools such as Mapnik and PostGIS. But could we create these vector tiles on the fly, right in the browser?</p><p>Well, me bredren, specifically for this purpose, I wrote a new JavaScript library called geojson-vt. And let me tell you, it’s fast and efficient, with uses goin’ way beyond the browser. It powers the GeoJSON rendering in Mapbox GL JS, was ported to C++14 to power on-the-fly point and polyline rendering on mobile devices with Mapbox Mobile, and it even works on a server with Node.js. We’re experimentin’ with using it in our server-side data-processing pipeline, mon.</p><h3>How GeoJSON-VT works</h3><h3>Preprocessing</h3><p>Generating tiles involves many computationally expensive steps:</p><ul><li>projecting geographic coordinates into screen coordinates</li><li>optimizing polyline and polygon detail for each zoom level</li><li>filtering out features that are too small for a particular zoom</li><li>clipping data to tile extents</li></ul><p>GeoJSON-VT performs these steps in order: it projects the entire dataset and calculates simplification before creating tiles. This way, the creation of many tiles over many zoom levels can be run quickly and without duplication of work.</p><p>The first step of preprocessing is <strong>projecting all coordinates</strong> into [0..1, 0..1] range with the <a href="http://en.wikipedia.org/wiki/Web_Mercator">Web Mercator</a> projection. Later, we can get the tile screen coordinates with a simple multiplication plus rounding:</p><p>screen_x = [tile_size × (2^zoom x − tile_x)]<br>screen_y = [tile_size × (2^zoom y − tile_y)]</p><p>The next step is <strong>calculating simplification data</strong> that is later used to reduce detail in each tile. It uses a modified <a href="https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm">Ramer-Douglas-Peucker simplification algorithm</a> that recursively finds the most “significant” points in a polyline and discards unnecessary detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/0*rQIFaXkw2SxBI2i-.gif" /></figure><p>This is the same technique used in <a href="http://leafletjs.com/">Leaflet</a> and <a href="https://github.com/mourner/simplify-js">simplify-js</a>, but instead of immediately simplifying data, GeoJSON-VT marks each vertex with an importance value, so it can be quickly included or excluded at a zoom level.</p><p>Because pixel distances scale linearly with 2^zoom, we can run simplification once for the data and use the same values to optimize detail on every zoom level, filtering out unnecessary vertices almost instantly.</p><p>Then we calculate the <strong>area of each polygon</strong> ring and the <strong>length of each polyline</strong>. Areas and lengths are scaled with zoom level in the same way as distances, which allows us to filter out geometries that are too tiny to display on any particular zoom level using these pre-calculated values in linear time.</p><p>Finally, we save the <strong>bounding box of each feature</strong>, which will allow us to do clipping much faster.</p><h3>Slicing the data into tiles</h3><p>Slicing tiles involves clipping data to a square extent, but we can’t afford running a clipping algorithm on the whole dataset for every single tile — <a href="https://www.mapbox.com/blog/rendering-the-world/">that would be too slow</a>.</p><p>To make it fast, GeoJSON-VT uses a <strong>top-down, divide &amp; conquer</strong> approach to clipping:</p><ol><li>Slice the top z0 tile into four z1 tiles.</li><li>Slice each z1 tile into four z2 tiles.</li><li>Repeat recursively.</li></ol><p>This makes slicing extremely fast, because each tile only needs to clip the features in its parent tile, rather than the entire dataset. But we can do even better than that.</p><p>Here’s how the most common rectangle clipping algorithm, <a href="https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm">Sutherland-Hodgeman</a>, usually works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/0*xfWKpNOae18m0sV1.png" /></figure><p>To cut a tile out of a parent zoom tile, you need to cut the features by 4 half-planes formed by each of the axis-parallel red lines. For each line, we need to loop through all the points from the previous cut.</p><p>Note that the tile cut is not exactly a quarter of the parent tile, because each tile needs to have a small buffer that goes beyond what we display on a map to solve rendering issues (e.g. <a href="https://www.mapbox.com/mapbox-studio-classic/">Mapbox Studio Classic</a> buffers each 512px tile by 8 pixels in each direction by default).</p><p>Let’s roughly calculate how long it would take to clip out 4 tiles relative to the amount of data in the parent tile:</p><p>4 × (n + 1/2 n + 1/4 n + 1/4 n) = 8n</p><p>We can cut 4 tiles out of a parent tile in a smarter way. To do that, I made a <a href="https://github.com/mapbox/geojson-vt/blob/master/src/clip.js">simple modification</a> of the half-plane clipping algorithm, making it clip shapes between two parallel-axis lines in one go: cutting out a “stripe”. This way, we can cut two halves with two vertical stripes first, then cut 2 tiles out of each half with two horizontal stripes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/0*lL3s0a1QrI3XIfho.png" /></figure><p>Let’s see how this compares to the previous approach:</p><p>n + n + 4 × 1/2 n = 4n</p><p>So we now have roughly 2 times faster clipping of each tile.</p><p>Finally, we can use the <strong>feature bounding boxes</strong> to our advantage. Imagine cutting the sample ZIP code data above into tiles on low zoom levels — <br>for each tile, most zip code shapes will be either trivial accepts — included completely without clipping — or trivial rejects — throw away. If we have bounding boxes pre-calculated, we can handle trivial cases like this without rebuilding all geometries point-by-point, speeding everything up considerably.</p><h3>Slicing on the fly</h3><p>To serve vector tiles on the fly without a perceptible delay, ideally, we would generate all the vector tiles up to max zoom into cache, and then just serve the tiles instantly when requested. This may be fine for small datasets, but for anything bigger, the tile slicing routine will eventually run out of memory. On zoom level 15 alone, there are potentially ⁴¹⁵ = ~<strong>1 billion tiles</strong> — that’s just too much to handle, especially for the browser.</p><p>So we can’t slice tiles to the max zoom on initial data load, but we can slice them up to a point where subsequent on-demand slicing takes so little time that the loading delay is imperceptible. GeoJSON-VT tackles this in several ways:</p><ol><li>Initially, the tiles are generated to certain zoom level, leaving everything else for on-demand slicing.</li><li>When slicing tiles, we keep track of the number of points combined in every tile. Initial slicing stops when a tile goes below a certain threshold<br>(100,000 points by default). If a tile contains few geometries, then its children can be generated quickly as needed.</li><li>When drilling down to a particular tile, GeoJSON-VT only slices one tile into 4 children tiles per zoom through the zoom range, caching all sliced tiles. This way drilling down to neighboring tiles is very fast because a much smaller parent tile will be cached from the previous tile drill-down.</li></ol><p>I found the initial slicing defaults (z5 and 100k points) to be the sweet spot for most sample datasets I tested the algorithm on — initial processing is relatively fast, while subsequent drill-down is pretty much instant.</p><p>We also need to <strong>minimize the amount of memory</strong> used in each step of the algorithm. This is achieved by several things:</p><ol><li>The original geometry is only kept in the highest-zoom tiles and is thrown away once a tile has been cut into 4 tiles of the next zoom level,<br>keeping only the simplified data. This way the memory needed to store all the tiling data doesn’t grow exponentially when slicing deeper.</li><li>All recursion is eliminated with iterative algorithms. Both simplification and tile slicing (recursive in nature) are implemented using a simple array queue processed in a loop. This avoids the situation where geometry that you no longer need gets piled up in call stacks: it’s garbage-collected properly.</li><li>Transforming projected (0..1, 0..1) coordinates into screen coordinates always happens on demand, because building new arrays takes a lot of memory if done for all tiles as soon as they are sliced.</li><li>Solid squares filled to the tile extent (tiles fully inside a polygon) are never sliced further, because all of its children are identical to the parent regardless of zoom level.</li></ol><h3>Debugging and performance profiling</h3><p>To debug and optimize the library, I wrote a simple <a href="http://mapbox.github.io/geojson-vt/debug/">debug page</a> where you can drag and drop a GeoJSON file onto a barebones map where it is processed by GeoJSON-VT:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*co015jedUg5lMXGN.gif" /></figure><p>The library API also has a debug option with 2 logging levels, doing various levels of performance timings and logging during the tiling when specified.<br>The GIF above demonstrates level 1, with level 2 outputting debug info for each individual tile. This helped tackling all the bottlenecks and tracking issues tremendously.</p><h3>Jank-free rendering in Mapbox GL JS</h3><p>Despite the library being extremely fast, loading and processing big amounts of data still takes a significant amount of CPU time.</p><p>Browsers normally run JavaScript code in the same thread that handle all UI updates and user interaction. If JavaScript is busy doing heavy computation,<br>the page will freeze and won’t accept any user input.</p><p>To avoid lags and freezes when loading and processing data, Mapbox GL JS utilizes <a href="https://en.wikipedia.org/wiki/Web_worker">Web Workers</a>, a modern browser feature that permits running computationally-intensive code in the background without interrupting the main thread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*0gUayS6AbO4NUv2w.png" /></figure><p>There’s one more problem though — transferring big amounts of data between a web worker and the main thread usually involves copying the data in memory, also causing the main thread to freeze.</p><p>To avoid that bottleneck, we take advantage of another HTML5 feature — <a href="https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast">Transferable Objects</a>. It allows transferring data between threads instantly with zero copy if you pass the data in the form of typed arrays. This allows us to provide a smooth, jank-free experience despite plenty of heavy CPU work happening in the background.</p><h3>Using the library</h3><p>If you’re using Mapbox GL-based tools (either <a href="http://github.com/mapbox/mapbox-gl-js">GL JS</a> or <a href="http://mapbox.com/mobile">Mapbox Mobile</a>), you’re already using GeoJSON-VT under the hood.</p><p>You can use it manually for other applications too — all the complexity of the processing is hidden behind a very simple API:</p><p>var tileIndex = geojsonvt(data);<br>...<br>var tile = tileIndex.getTile(z, x, y);</p><p>The resulting tile is a simple JSON equivalent of <a href="https://github.com/mapbox/vector-tile-spec">Vector Tile</a>, and can be rendered with ease.</p><p>Try it! We’re curious to see what other creative uses of the library you can come up with. I also encourage you to check out the <a href="https://github.com/mapbox/geojson-vt">geojson-vt repository</a><br>and read through the code — it’s was carefully written to be as simple and clean as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d428c1a8e7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jamaican Breakdown of AI and Machine Learning (kids only)]]></title>
            <link>https://medium.com/@juniormarch48/jamaican-breakdown-of-ai-and-machine-learning-on-medium-kids-only-869f301d4398?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/869f301d4398</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[future-of-work]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Thu, 02 Feb 2023 04:17:07 GMT</pubDate>
            <atom:updated>2023-02-02T04:17:34.286Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*HfsG6b3ijVeku9rmJgzhDQ.jpeg" /></figure><h3>Introduction</h3><p>Jamaican humor is a great way to make learning about complex topics like AI and Machine Learning fun and engaging. By using humor, we can make sure the information is easy to understand, even for middle schoolers. This blog will cover the history of AI and Machine Learning and take us up to present day. So hold on to your cornmeal pudding, mon, we are going on a journey!</p><h3>Chapter 1: The History of AI</h3><p>A long, long time ago, in a land far, far away (just kidding, it was just in ancient Greece), philosophers like Aristotle believed that machines could never truly think like humans. Fast forward a few centuries and scientists started to get a little bit more curious about the idea of artificial intelligence.</p><p>In the mid-1950s, computer scientist John McCarthy came up with the term “Artificial Intelligence” and held the first conference on the topic in 1956. It was around this time that scientists started to work on creating machines that could actually “think” and make decisions on their own.</p><p>But even back then, mon, people were skeptical. Some thought that machines could never truly be intelligent and others believed that they would become too smart and take over the world (insert evil laugh here).</p><h3><strong>Chapter 2: The Early Days of AI</strong></h3><p>The early days of AI were a bit rocky. Scientists were still trying to figure out how to get machines to perform even basic tasks like playing checkers or solving simple math problems. But eventually, they started to make progress and machines began to get a little bit smarter.</p><p>In the 1970s and 80s, AI started to gain some traction and computer scientists started to develop programs that could solve more complex problems, like playing chess and diagnosing medical conditions.</p><p>But despite these advancements, people were still skeptical about the true potential of AI. They thought it was still a long way from truly being intelligent.</p><h3><strong>Chapter 3: AI Takes Off</strong></h3><p>In the 1990s, things started to really pick up for AI. The internet was invented, and suddenly, people had access to all sorts of information at their fingertips. This made it much easier for computer scientists to work on developing AI.</p><p>And then, in 1997, IBM’s Deep Blue computer defeated the world chess champion, Garry Kasparov, in a six-game match. This was a huge moment for AI and showed people that machines could actually be intelligent and make decisions on their own.</p><p>Suddenly, people started to take AI more seriously and companies started investing in research and development. AI was no longer just a sci-fi dream, it was becoming a reality.</p><h3><strong>Chapter 4: Machine Learning</strong></h3><p>Machine Learning is a type of AI that focuses on teaching machines to learn on their own. It’s all about using algorithms and statistical models to give machines the ability to learn from data, without being explicitly programmed.</p><p>In the early days of Machine Learning, computer scientists were still trying to figure out how to make it work. They were experimenting with different algorithms and trying to find the best ways to teach machines to learn.</p><p>But eventually, they started to make progress and Machine Learning began to take off. Companies started to realize the potential of this technology and began investing in research and development.</p><h3><strong>Chapter 5: AI Today</strong></h3><p>Today, AI is everywhere. From Siri on our phones to self-driving cars, AI is changing the way we live our lives. Companies are using AI to improve customer service, to make medical diagnoses, and even to predict the weather.</p><p>And Machine Learning is also continuing to advance. Companies are using it to analyze data and make predictions, improve marketing strategies, and even detect fraud. Machine Learning algorithms are now able to learn from massive amounts of data, making them incredibly accurate and useful for a wide range of industries.</p><p>But despite all of these advancements, people are still skeptical about AI and Machine Learning. Some worry that machines will take over our jobs, while others are concerned about the ethical implications of machines making decisions without human oversight.</p><h3>Conclusion</h3><p>AI and Machine Learning have come a long way since their humble beginnings. From simple checkers games to self-driving cars, these technologies are changing the way we live and work. And while there are still some concerns about their impact on society, there’s no doubt that they will continue to play a big role in our lives in the years to come.</p><p>So there you have it, mon, a Jamaican-style breakdown of AI and Machine Learning. Who would have thought learning about these complex technologies could be so much fun? I hope this blog has made it easier for you to understand what AI and Machine Learning are all about. And if you’re ever feeling skeptical about these technologies, just remember, we’re still here and we’re still in control (winks).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=869f301d4398" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why proficiency in Node Js is important for Full-Stack Developers?]]></title>
            <link>https://medium.com/@juniormarch48/why-proficiency-in-node-js-is-important-for-full-stack-developers-28b4193cd122?source=rss-28501ba74031------2</link>
            <guid isPermaLink="false">https://medium.com/p/28b4193cd122</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Jamaicancoder]]></dc:creator>
            <pubDate>Thu, 02 Feb 2023 04:07:44 GMT</pubDate>
            <atom:updated>2023-02-02T04:07:44.736Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I want to dive into the heart of Node.js that is responsible for managing modules. We all use modules in every Node.js application, but we might not know how it works under the hood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*U8ggcXEMaG_pEb8L.jpeg" /></figure><p>In the <a href="https://medium.com/@derakhshanfar.hossein/things-that-make-you-far-better-node-js-developer-part-1-60f585323bfc">last article,</a> I talked about how we can add new features and syntax to javascript with the help of V8 and C++, and finally, we understood that Node.js is nothing but this. We discussed that Node.js needed to address some issues to be able to manage a server. One of these issues was managing modules.</p><p>to understand this article better, you need to know these concepts in javascript: if you already know these concepts, you can skip the prerequisite part. If not, no worries. I talk about these concepts</p><ul><li>IIFE</li><li>prototype inheritance</li><li>constructed function</li><li>call by reference</li></ul><h3>prerequisite:</h3><h3>What is a module?</h3><p>the simplest definition of module for me is it is a technique to <strong>reuse codes</strong> without having <strong>any code collision</strong>. That’s it.</p><p>Most programming language has their own way of managing that, but At the time Node.js was created, javascript didn’t have any feature to manage modules; however, since javascript es5, this feature is a part of JS.</p><h3>What do I mean by code collision?</h3><p>Let’s assume we want to reuse some codes. we can create another file, eg utils.jsand put the related codes there like:</p><p>utils.js:</p><pre>var msg = &quot;Hello, World!&quot;;<br>var sayHi = function() {<br>    alert(msg);<br>};</pre><p>Now, let’s assume we have another file, eg app.jsthat have a variable named msg . as you can see in both file we have a same variable name msg</p><pre>var msg = &quot;stinky code&quot;;</pre><p>Let’s register these files in our HTML file and call sayHi() function there</p><pre>&lt;html&gt;<br> <br>&lt;head&gt;<br>  &lt;script src=&quot;js/utils.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;js/app.js&quot;&gt;&lt;/script&gt;<br>  &lt;script&gt;<br>    sayHi(); // it shows stinky code!! <br>  &lt;/script&gt;<br>&lt;/head&gt;<br> <br>&lt;body&gt;<br> <br>&lt;/body&gt;<br> <br>&lt;/html&gt;</pre><p>Based on the utils.js file, we have to get Hello, World! but we see stinky code. it seems code collision happened. We can fix this problem with a technique named IIFE in JS which we will learn it soon.</p><h3>What is passing by reference vs by value?</h3><p>This is a really important topic, and we might see many questions in interviews regarding this topic. When we talk about passing, we either pass this variable to another function or assign it to another variable.</p><p>When a variable is declared, it is assigned a memory address in the computer like this:</p><pre>var a = 10;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*VY3vSHhGW8tLqL13.png" /></figure><p>In javascript, we have two kinds of value:</p><p><strong>Primitive and reference</strong></p><p>Primitives value are:</p><p>boolean, string, number null undefined , Symbol</p><p>reference value are:</p><p>object or array</p><p>In many programming languages, if we want to pass the variable by reference or by value, they have their syntax to do this, but in javascript, it depends on the type of variable (<strong>Primitive and references</strong>) we are working with.</p><p><strong>By value:</strong></p><pre>var a = 1;<br>var b = a + 1;<br>console.log(a,b) // 1, 2</pre><p>As you can see, a and b have primitive value (number), and when we are working with Primitive types, javascript copies the value and assign it to another variable. So we have two variables that point to the different parts of memory with the same value.</p><p><strong>By reference:</strong></p><p>Let’s do this operation with an array</p><pre>var a = [1,2];<br>var b = a;<br>b.push(3);</pre><pre>console.log(a)<br>console.log(b)</pre><p>We expect that the a would be [1,2] and b would be [1,2,3] but if we run this code we see both of them have the same value which is [1,2,3]</p><p>This happens because, in non-primitive values, javascript doesn’t make a copy of the <strong>value</strong> when we assign or pass them to another variable or function. It makes a copy of the <strong>address</strong> of the variables in memory. So both of these variables are pointing to the same address in the memory</p><h3>What is first class function?</h3><p>First class function are part of javascript that makes this language amazing. let’s talk about them.</p><p>It means whatever you can do with string, boolean, or any other types in javascript, you can do it with function.</p><p>For example we can pass a function as an argument exactly like passing a string variable to another function:</p><pre>function sayHello() {<br>  return &quot;Hello, &quot;;<br>}<br>function greeting(helloMessage, name) {<br>  console.log(helloMessage() + name);<br>}<br>greeting(sayHello, &quot;JavaScript!&quot;);</pre><p>or you write a function that returns another function eg,</p><pre>function sayHello() {<br>  return () =&gt; {<br>    console.log(&quot;Hello!&quot;);<br>  };<br>}</pre><p>or you can assign a function to a variable like this:</p><pre>const foo = () =&gt; {<br>  console.log(&quot;foobar&quot;);<br>};<br>foo();</pre><p>We will see how this feature can help us to make modules guys. This is something that we don’t have in many programming languages and it is so powerful.</p><h3>What are IIFE (Immediately invoked function expression) and closure</h3><p>IIFE is a common JavaScript pattern that executes a function immediately after it’s defined.</p><pre>(function() {<br>    // Code that runs in your function<br>})()</pre><p>you can also assign this function to a variable like this:</p><pre>var func = (function() {<br>    return () =&gt; {<br>     console.log(&#39;Hey&#39;)<br>    }<br>})()<br>func() // Hey</pre><p>let’s talk about the use case of IIFE:</p><p>1- Avoid code collision:</p><p>If you define any kind of variables (let, const, var) within a function in javascript, we can not access those variables outside of the function, and also, if we have two variables with the same name outside, and inside the function (like the one that we saw in previous example) , this technique can help to avoid code collision. let’s see an example:</p><p>As you can see we have a variable named msg outside and inside of the function but by the help of IIFE we avoid code collision</p><pre>var msg = &#39;outside&#39;;<br>(function() {<br>  var msg= &#39;inside&#39;<br>  console.log(msg); // inside<br>})()<br>console.log(msg) // outside</pre><p>2- closure:</p><p>closure simply means when you define a function, it has access to all variables outside of the function <strong>when it was created</strong>. let’s assume we have a loop, and we want to log the index of the loop within setTimeout.</p><pre>for (var i = 0; i &lt; 6; i++) {<br>    setTimeout(() =&gt; {<br>      console.log(i)<br>    }, 100)<br> }</pre><p>if you run this code, you will see 666666 instead of 012345 .</p><p>The reason is when javascript sees an asynchronous code (in this casesetTimeout), first, it needs to execute all synchronous code. for loop here is synchronous code. so it executes for till the end and then executes all the callbacks that are provided for setTimeout. Now it’s time to execute setTimeout callbacks and at this moment, the index of the loop is 6.</p><p>That’s why it prints 666666. Now let’s fix this problem with closure:</p><pre>for (var i = 0; i &lt; 6; i++) {<br>    var innerFunction = (index) =&gt; {<br>      setTimeout(() =&gt; {<br>        console.log(index)<br>      }, 100)<br>    }<br>    innerFunction(i)<br> }</pre><p>if you run this code, you will see 012345 because when innerFunction is created, it captures all the variables at that moment. BTW we can write the above code with IIFE format like this</p><pre>for (var i = 0; i &lt; 6; i++) {<br>    ((index) =&gt; {<br>      setTimeout(() =&gt; {<br>        console.log(index)<br>      }, 100)<br>    })(i)<br> }</pre><p>Another use case of closure is we can define private and public variables inside the method. can you guess how? put a comment if you know :)</p><h3>What is object literal?</h3><p>If you’ve used javascript, you probably have used object literal and what object is, but maybe you don’t know its name. It is like a JSON. the only difference here is in JSON keys are covered in the double quote.</p><p>Object literal in javascript is a way of creating a group of different data. we can define as a name-value pairs inside of curly braces like this:</p><pre>var greeting = {<br>    fullname: &quot;Michael Jackson&quot;,<br>    greet: (message, name) =&gt; {<br>        console.log(message + &quot; &quot; + name + &quot;!!&quot;);<br>    },<br>    gender: &quot;Male&quot;,<br>    getFullData: () =&gt; {<br>      return this.fullname + this.gender;<br>    }<br>};</pre><p>now we can assign or access to any properties in the greeting object with . operator:</p><pre>greeting.greet();<br>greeting.fullname = &#39;Hey this is test&#39;;</pre><h3>what is constructed function?</h3><p>It is a normal function that creates an object. in javascript there are many other ways to create an object. constructed function is one of them.</p><pre>function Person(first, last, age, eye) {<br>  this.firstName = first;<br>  this.lastName = last;<br>  this.age = age;<br>  this.eyeColor = eye;<br>}</pre><pre>var obj = new Person(&#39;Hossein&#39;, &#39;Derakhshan&#39;, 33, &#39;Black&#39;);</pre><p>as you can see with new keyword, we can define a new object in js through constructed function. now if we logobj we will see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/0*YS_LBU6RC6_fC_nE.png" /></figure><p>there is another property named [[Prototype]] let’s see what it is</p><h3>What is prototype in Javascript?</h3><p>By the help of this feature, we can kind of implements inheritance in javascript. I’m saying kind of because JavaScript is not a class-based object-oriented language.</p><p>when we create a constructor function, javascript will add a property named prototype to that function. Then if you assign any property or methods to the prototype there will be available in instantiate object.</p><p>let’s see this example:</p><pre>function Person(first, last, age, eye) {<br>  this.firstName = first;<br>  this.lastName = last;<br>  this.age = age;<br>  this.eyeColor = eye;<br>  this.getFullName2 = function() {<br>    return this.firstName + this.lastName;<br>  } <br>}</pre><p>Now let’s add a method name getFullName to the prototype of this function:</p><pre>Person.prototype.getFullName = function() {<br>    return this.firstName + this.lastName;<br>}</pre><p>now let’s initiate Person by new keyword</p><pre>var hossein = new Person(&#39;hossein&#39; ,&#39;derakhshan&#39;, 32, &#39;black&#39;);<br>console.log(hossein.getFullName()); // hossein derakhshan</pre><p>as you can see when you create a new object from Person, that object has access to the getFullName method even though this method is not defined in Person function itself.</p><p>You might say that hey why not adding getFullName directly to the Person class itself just like getFullName2 . to get this answer let’s initiate another object from Person</p><pre>var ali = new Person(&#39;ali&#39; ,&#39;rezai&#39;, 32, &#39;black&#39;);</pre><p>now let’s see compare getFullName2 which is defined inside a Person function with getFullName which is assigned to the prototype</p><pre>console.log(hossein.getFullName2 === ali.getFullName2); // false<br>console.log(hossein.getFullName === ali.getFullName); // true</pre><p>as you can see in this code when we compare getFullName2, in both initiated objects (Ali and Hossein) the result is false meaning it takes another space of the memory ,but when we compare getFullName the result is true ,which means both objects are pointed to the same memory address. So we are saving memory. we must consider when JS was invented, computers had very low memory.</p><blockquote><em>PS: es6 classes, it is just a syntactic sugar or a convenient syntax over es5 syntax. under the hood, even if you use es6 classes, it is still using prototype and es5 syntax.</em></blockquote><h3>what is Reflect.apply?</h3><p>Reflect.apply is a build-in javascript method which is used to call a function using the specified argument. It works similar to the <strong>Function.prototype.apply()</strong> method to call a function, but in an efficient manner and easy to understand.</p><pre>Reflect.apply(targetFunction, thisArgument, argumentsList)</pre><p>Here is an example:</p><pre>function func (a, b, c) { <br>    this.x = a; <br>    this.y = b; <br>    this.z = c; <br>}</pre><pre>const obj = {};</pre><pre>Reflect.apply ( func , obj, [12,42,32] ); <br>console.log( obj );<br>{ x: 12, y: 42, z: 32 }</pre><p>Now that we know the basic concepts here, let’s back to the topic :)</p><h3>How Node.js fixed code collision?</h3><p>CommonJS is the way that Node.js address code collision. when we run node file.js we are passing the javascript file to the node.js. we know that Node.js at the end, will pass this javascript file to the v8 and then will give us the result.</p><p>let’s assume that this is our node.js application:</p><p>utils.js</p><pre>var msg = &quot;Hello, World!&quot;;<br>var sayHi = function() {<br>    console.log(msg);<br>};<br>module.exports = sayHi; // node.js has added this syntaxt to JS</pre><p>app.js</p><pre>var whatever = require(&#39;./utils.js&#39;) // node.js has added this syntaxt to JS<br>var msg = &#39;something&#39;<br>whatever();</pre><p>we can run it with node app.js . we know that If node.js forward this javascript to v8 directly, we will get some errors. let’s do it in chrome console to see the error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*nm8hQYRpr4nGKuaE.png" /></figure><p>we are getting this error because parser in v8 , can not understand this syntax. so how do we not get any error in node.js?</p><p>in order to understand better, let’s just run node without providing any file name in a directory that these files(app.js, utils.js) exist.</p><p>If you run node in the console, you should see something like this depending on the version of your node.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*rK0FkuJgMUNSiqlr.png" /></figure><p>Now, if you type this command in the CLI require(&#39;./app&#39;), you will see the same result as calling node ./app which means behind the scene node.js call the require function on the entry point.</p><p>The good news is require is a javascript function (it is not a pure C++ function), that’s why we can debug it :) let’s dive into the internal part of node.js and see what will happen after calling the require function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*o82O_b74Tzw2euhT.png" /></figure><p>On the right side, in scope section, we see some local variables like (exports, module, msg, require, __dirname, …) which is not exist in the app.js let’s step into the require function (you will get your answer).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*rYZRS8uCXQ8w-a0i.png" /></figure><p>depends on the version of your node.js, at the end you should see something like above picture.</p><p>let’s step into more:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*_oN3iTE0wcc5L9yu.png" /></figure><p>as you can see in line 1020 require attached to the Module through prototype (line 1020). we already know what prototype do.</p><p>This line once again proves that require function has been called on app.js when we ran node app.js , and it created a Module class, and this class has access to the require function.</p><p>if we step into the Module.load we will see a lot of codes, but I tried to delete the lines that are not related to this topic. so the simpler version of module.load should be something like this:</p><pre>Module._load = function(request, parent, isMain) {<br>  const filename = Module._resolveFilename(request, parent, isMain);<br>  <br>  const module = new Module(filename, parent);<br>  module.load(filename);</pre><pre>  return module.exports;<br>};</pre><p>let’s break down this function:</p><pre>const filename = Module._resolveFilename(request, parent, isMain);</pre><p>this line is going to get the full file path on the local drive. in my case:</p><p>/Users/hossein/Tools/Learning/testt/utils.js</p><p>then let’s move to the next line:</p><pre>const module = new Module(filename, parent);</pre><p>this is the constructed function that we are already familiar with its concept. So it should be a function with a name Module right? let’s see that</p><pre>function Module(id = &#39;&#39;, parent) {<br>  this.id = id;<br>  this.path = path.dirname(id);<br>  setOwnProperty(this, &#39;exports&#39;, {});<br>  moduleParentCache.set(this, parent);<br>  updateChildren(parent, this, false);<br>  this.filename = null;<br>  this.loaded = false;<br>  this.children = [];<br>}:</pre><p>if we run this function, it creates an object like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*WE_Yt0WX9krKOPwn.png" /></figure><p>as you can see, it creates an empty exports: {} and also it has access to a lot of methods (like require and …) through prototype</p><p>Now let’s check this section:</p><pre>module.load(filename);</pre><p>First of all, this line doesn’t return anything, meaning that it should add something to the module object itself. in other words, load should do some call-by-reference operation.</p><p>if we step into the load function we will see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*yXpKpP4UTelQrchj.png" /></figure><p>On the right side of this module, there is a variable named extention and the value is .js</p><p>this gives us the idea that this class can load other types of data like json or . and if we don’t provide the .js in the require function, the default value would be .js . let’s check this line</p><pre>Module._extensions[extension](this, filename);</pre><p>Based on this line,Module._extensions should be an object. here is its value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/0*1mm5U7VYGX4K-DM4.png" /></figure><p>what we are doing in that line is we are calling a function based on the extension. let’s dive more:</p><p>Simplified version of this function can be like this:</p><pre>Module._extensions[&#39;.js&#39;] = function(module, filename) {<br>  var content = fs.readFileSync(filename, &#39;utf8&#39;);<br>  module._compile(content, filename);<br>};</pre><p>This function is going to read the file from disk based on the filename. This is something that javascript can not do. but in Node.js there is a class named fs to work with files. fs.readFileSync is a combination of c++ and javascript, and now we don’t want to dive into this function. but all it does is it reads the file.</p><p>so content variable should be the content of the utils.js file:</p><p>‘var msg = “Hello, World!”;\nvar sayHi = function() {\n console.log(msg);\n};\nmodule.exports = sayHi;’</p><p>and finally, let’s step into the last and most interesting function guys. module._compile</p><p>this function is going to pass the compiled javascript into the v8 and execute it. I tried to simplify this function so the code should be something like this:</p><pre>Module.prototype._compile = function(content, filename) {<br>  const compiledWrapper = wrapSafe(filename, content, this);<br>  const dirname = path.dirname(filename);<br>  const require = makeRequireFunction(this, redirects);<br>  let result;<br>  const exports = this.exports;<br>  const thisValue = exports;<br>  const module = this;<br>  result = ReflectApply(compiledWrapper, thisValue,<br>    [exports, require, module, filename, dirname]);<br>  return result;<br>};</pre><p>let’s break down this function and check the first line:</p><pre>const compiledWrapper = wrapSafe(filename, content, this);</pre><p>based on the name (wrapSafe) , this function should add something to the currentcontent which was:</p><p>‘var msg = “Hello, World!”;\nvar sayHi = function() {\n console.log(msg);\n};\nmodule.exports = sayHi;’</p><p>I tried to simplify the wrapSafe function for you.</p><p>All it does is just add two strings into our script</p><pre>let wrap = function(script) {<br>  const wrapper = [<br>    &#39;(function (exports, require, module, __filename, __dirname) { &#39;,<br>    &#39;\n});&#39;,<br>  ];<br>  return wrapper[0] + script + wrapper[1];<br>};</pre><p>if we run this function, we will get this result:</p><pre>(exports, require, module, __filename, __dirname) {<br>  var msg = &quot;Hello, World!&quot;;<br>  var sayHi = function() {<br>    console.log(msg);<br>  };<br>  module.exports = sayHi;<br>})</pre><p>See? it just wraps our code with a function to avoid the code collision. but this function is not executed yet. in fact, ReflectApply is going to execute our codes by passing this function to v8 and get back the result.</p><pre>result = ReflectApply(compiledWrapper, thisValue,<br>    [exports, require, module, filename, dirname]);</pre><p>let’s jump back to the image that you already saw at the beginning of this article:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*0WscTL1oYMMN3oSi.png" /></figure><p>All the variables (exports, module, msg, require, __dirname) we saw in local scope come from the wrapFunction:</p><p>(exports, require, module, __filename, __dirname) {})</p><p>let’s see the module argument. as you might remember module was an object like this with exports = {}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*o07Vw-0cG2U_I3bm.png" /></figure><p>we are passing this object to this function and then we run the function with ReflectApply .</p><p>We are passing this object in the inner function because if we assign something to the module.exports in the inner function, we want access to it from outside of the wrapped function.</p><p>let’s simplify this:</p><pre>var obj = {<br>  exports: {}<br>}</pre><pre>((module) =&gt; {<br>  <br>  var msg = &quot;Hello, World!&quot;;<br>  var sayHi = function() {<br>    console.log(msg);<br>  };</pre><pre>  module.exports = sayHi;<br>})(obj)</pre><pre>if (obj.exports) {<br>   obj.exports()<br>}</pre><p>I just created an object named obj then I created an <strong>IIFE </strong>and I passed the obj object into IIFE and I put a name as a module. In the inner function, I assigned sayHi function in module.exports . since I’m changing the reference of exports, outside of the IIFE I still have access to the module.exports !</p><p>If we check the last line of require function, we will see that it returns the module.exports</p><pre>Module._load = function(request, parent, isMain) {<br>  const filename = Module._resolveFilename(request, parent, isMain);<br>  <br>  const module = new Module(filename, parent);<br>  module.load(filename);</pre><pre>  return module.exports; // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; this line<br>};</pre><p>That’s pretty much it! Love you and stay tuned :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28b4193cd122" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>