<?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 Seb Gonzales on Medium]]></title>
        <description><![CDATA[Stories by Seb Gonzales on Medium]]></description>
        <link>https://medium.com/@seb_5882?source=rss-ead6dfdebd02------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*O3puEQFpckftriI82C7ezw.jpeg</url>
            <title>Stories by Seb Gonzales on Medium</title>
            <link>https://medium.com/@seb_5882?source=rss-ead6dfdebd02------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:50:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@seb_5882/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[HiTone : Personalized AI speech trainer using GPT-4 and Whisper API]]></title>
            <link>https://medium.com/@seb_5882/hitone-personalized-ai-speech-trainer-using-gpt-4-and-whisper-api-85ebfaad3ac7?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/85ebfaad3ac7</guid>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Sun, 26 Nov 2023 12:39:17 GMT</pubDate>
            <atom:updated>2023-11-26T12:39:17.741Z</atom:updated>
            <content:encoded><![CDATA[<h3>HiTone : <strong>Personalized AI speech trainer using GPT-4 and Whisper API</strong></h3><p>In the rapidly evolving tech landscape, technical prowess alone doesn’t cut it anymore. The ability to articulate ideas clearly and confidently is equally crucial, whether it’s acing a job interview, presenting at a conference, or collaborating with a team. Enter HiTone AI, your personalized AI speech trainer, harnessing the power of OpenAI’s GPT-4 and Whisper API to transform the way developers communicate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cM7oggE4RFQ-ZlKOtJD2w.png" /></figure><h3>Bridging the Gap with HiTone AI</h3><p>HiTone AI isn’t just another AI tool; it’s a revolutionary approach to mastering communication skills. By integrating advanced AI technologies, HiTone AI offers a unique platform where users can generate scripts, record their speech, and receive instant, personalized feedback.</p><h3>The Role of GPT-4</h3><p>At the heart of HiTone AI is GPT-4, OpenAI’s latest generative model known for its remarkable language understanding and generation capabilities. Users can leverage GPT-4 to create compelling, contextually relevant scripts for practice sessions, ensuring they’re equipped with content that resonates with their audience, be it technical or non-technical.</p><h3>Whisper API: Listening and Improving</h3><p>What sets HiTone AI apart is its use of the Whisper model for speech recognition and analysis. This powerful tool listens to the user’s speech, offering constructive feedback on various aspects such as clarity, pace, and articulation. It’s like having a personal speech coach who’s available 24/7.</p><h3><strong>Generating Speech</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n6pj8kC662Jf_uK8WBpgNg.png" /></figure><p>HiTone AI leverages GPT-4 to generate a speech/script tailored to the details you provided. The more descriptive your input are, the more accurate the generated script will be.</p><h3>Recording Yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l3Fu_V6v0moIevwvHvAh0A.png" /></figure><p>After generating your script, you will be re-directed to a page where you can press the record button and start recording yourself speaking the speech.</p><p>In here, HiTone leverages a react recording library to allow users to record themselves then the recording is sent to Whisper API to be converted into text. GPT-4 analyzes your recording, where it evaluates your overall performances and deducts points on filler words (eg. hmmm, uhhh and etc)</p><h3>Getting Personalized Feedback</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bVxC_BXyrzh4LYyWUtSv1g.png" /></figure><p>After recording, you will be receive instant feedback for the recording you’ve sent to HiTone.</p><p><strong>Summary:</strong></p><p>You are given a form to fill-up with the details you need for the Speech. OpenAI API will generate it for you.</p><p>Step by step process</p><ul><li>Receive inputs from user</li><li>OpenAI API will generate the script</li><li>You are to record yourself speaking the speech provided</li><li>The recording is converted into a supported format and transcripted by Whisper API</li><li>OpenAI API receives the transcript and provide a feedback</li><li>Stream feedback back to the user</li></ul><h3>Note: This is an open source project where you can contribute into.</h3><p>Here are some ideas for how to improve HiTone:</p><ul><li>Provide better UI by creating a separate route for the analytics</li><li>Provide accurate script generation by improving prompt</li><li>Allow users to add more inputs to make the script more personalized and descriptive</li><li>Improve feedback by having accurate transcriptions</li><li>Train own model for transcription and analysis</li><li>Contribute your ideas by reaching out to me!</li></ul><p><strong>Contribute:</strong></p><p>Github: <a href="https://github.com/DevgenX/Hitone-app">https://github.com/DevgenX/Hitone-app</a></p><p>Inspired by <a href="https://orai.com/">Orai</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85ebfaad3ac7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DappChat : A multi-chain and fully on-chain decentralized messaging.]]></title>
            <link>https://medium.com/@seb_5882/dappchat-a-multi-chain-and-fully-on-chain-decentralized-messaging-61d7bd3dcef3?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/61d7bd3dcef3</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[social-media]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Tue, 27 Jun 2023 14:24:23 GMT</pubDate>
            <atom:updated>2023-07-02T18:13:16.020Z</atom:updated>
            <content:encoded><![CDATA[<h3>DappChat : <strong>A Multi-Chain and Fully On-chain Decentralized Messaging.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ZavOLnmySEDJySCZdsHGA.png" /></figure><p>In the era of centralized social media platforms, there has been a growing demand for decentralized alternatives that prioritize user privacy, data ownership, and censorship resistance. Inspired by visionaries like Elon Musk, who aim to create decentralized social media platforms, I set out to develop a fully on-chain decentralized messaging application using modern technologies such as Typescript, Next.js, Tailwind CSS, Web3.js, Ethers.js, and Solidity. This blog post highlights the key features and technologies used in the development of the application and explores the potential of decentralized messaging in a multi-chain environment.</p><p><strong>Decentralized Messaging and its Advantages</strong></p><p>Decentralized messaging applications offer several advantages over traditional centralized platforms. By leveraging blockchain technology, these applications prioritize <strong>user privacy</strong>, <strong>data security</strong>, and <strong>control</strong>. Messages, user profiles, and other critical data are stored on the blockchain, ensuring immutability, transparency, and resistance to censorship. Furthermore, decentralized messaging allows users to communicate directly without intermediaries, reducing the risk of data breaches and unauthorized access. It empowers individuals to have full <strong>ownership</strong> and <strong>control</strong> over their <strong>conversations</strong> and<strong> personal information</strong>.</p><p><strong>Decentralized Messaging and its Disadvantages</strong></p><p>While decentralized applications offer numerous benefits, it’s important to acknowledge some of the challenges they may face. One of the main drawbacks is the potential impact on <strong>speed</strong> and <strong>transaction costs</strong>. Since decentralized applications rely on blockchain networks, transaction processing times can be slower compared to centralized systems. Additionally, users may encounter <strong>higher gas fees</strong> associated with executing transactions and interacting with smart contracts. These factors can present hurdles in terms of <strong>user experience</strong> and <strong>scalability</strong>, requiring continuous optimizations and advancements in blockchain technology to address these limitations. Nonetheless, the advantages of decentralization in terms of privacy, security, and data ownership often outweigh these drawbacks, paving the way for a more transparent and resilient digital ecosystem.</p><p><strong>Technologies Used</strong></p><p>To build this decentralized messaging application, I utilized a stack of powerful technologies:</p><ol><li><strong>Typescript</strong>: Typescript provides a strong and static type system, enabling safer and more robust code development.</li><li><strong>Next.js</strong>: Next.js, a popular React framework, offered server-side rendering (SSR), routing, and optimized performance, making the application fast and SEO-friendly.</li><li><strong>Tailwind CSS</strong>: Tailwind CSS provided a utility-first CSS framework that enabled rapid UI development with pre-defined styles and responsive design.</li><li><strong>Web3.js and Ethers.js</strong>: Web3.js and Ethers.js libraries facilitated interaction with the Ethereum blockchain, allowing users to connect their wallets, send transactions, and interact with smart contracts.</li><li><strong>Solidity</strong>: Solidity, the programming language for Ethereum smart contracts, allowed me to define the business logic of the decentralized messaging application.</li></ol><p><strong>Deployment on Multiple Blockchain Networks</strong></p><p>To ensure accessibility and decentralization, I deployed the application on multiple blockchain networks, including <strong>Sepolia</strong>, <strong>Goerli</strong>, <strong>BSC</strong> (Binance Smart Chain), <strong>Polygon</strong>, and <strong>Polygon</strong> <strong>Mumbai</strong>. This approach allowed users to choose their preferred network based on factors such as transaction fees, network congestion, and interoperability with other applications. Deploying the application on various networks expanded its reach and provided a seamless user experience regardless of the chosen blockchain network.</p><p><strong>Key Features and Functionality</strong>:</p><p>The decentralized messaging application offers a range of features that empower users in their communication and interactions:</p><ol><li><strong>Account Creation</strong>: Users can create their accounts securely using their Ethereum wallets, ensuring authenticity and eliminating the need for traditional username-password combinations.</li><li><strong>Friend Management</strong>: Users can add friends within the application, establishing connections and enabling direct messaging.</li><li><strong>Messaging</strong>: Through the application’s intuitive user interface, users can send messages to their friends, fostering private and secure conversations.</li><li><strong>Block and Unblock Users</strong>: To maintain control over their interactions, users can block and unblock specific individuals as needed, ensuring a safe and personalized messaging experience.</li></ol><p><strong>Summary</strong></p><p>The development of a multi-chain and fully on-chain decentralized messaging application represents a significant step towards a decentralized and censorship-resistant social media landscape. By leveraging blockchain technology and the power of Ethereum, the application prioritizes user privacy, data ownership, and secure messaging. As we move closer to Elon Musk’s vision of a decentralized social media, this application serves as an example of the potential of decentralized technologies to revolutionize communication in a trustless and secure manner. Embracing decentralized messaging opens new doors for user empowerment, data privacy, and the democratization of information flow.</p><p>By building a decentralized messaging application, we are contributing to the ongoing evolution of the internet, shaping a future where users have control over their data, connections, and online experiences. Let us embrace this shift towards decentralized technologies and work together to create a more inclusive and user-centric digital world.</p><p><strong>Official Links</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fjnu7UGOoiEM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Djnu7UGOoiEM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fjnu7UGOoiEM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/92293e219e1519c1df84c5a594a9d7f9/href">https://medium.com/media/92293e219e1519c1df84c5a594a9d7f9/href</a></iframe><ul><li><a href="https://www.dappchat.io/">DappChat</a></li><li><a href="https://sebgonzales.dev/">Seb Gonzales</a></li></ul><p>Contribute</p><p><a href="https://github.com/DevgenX/dappchat">GitHub - DevgenX/dappchat: A multi-chain and fully-on chain decentralized messaging application.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61d7bd3dcef3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NextJs  13.4 : Using Context API in App router]]></title>
            <link>https://medium.com/@seb_5882/nextjs-13-4-using-context-api-in-app-router-a1198a61c5c8?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1198a61c5c8</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Sun, 28 May 2023 23:25:31 GMT</pubDate>
            <atom:updated>2023-11-26T13:00:38.743Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Next.JS 13.4 : Using Context API in App router</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*zQLMWTCbNNHEd02u9MEyVw.png" /></figure><p>Are you getting this error even though you declared the<strong> <em>‘use client’</em></strong><em> </em>directive on top of your context component?</p><pre>&quot;use client&quot;;<br><br>import React, { useEffect, useState, createContext, useContext } from &quot;react&quot;;</pre><p>Well … after trying a lot of solutions from Bard, ChatGPT and youtube videos. I wasn’t able to find a fix.</p><p>So what’s this ‘use client’ or ‘use server’ stuff going on?</p><p><strong>Next.js 13.4</strong> introduces a notable improvement by separating <strong>server-side</strong> and client-side <strong>components</strong>, allowing developers to explicitly distinguish between components that should be rendered on the server and those that should be rendered on the client. This separation enhances performance and reduces the amount of JavaScript sent to the client, resulting in faster initial page loads. By selectively rendering components on the server or the client based on their requirements, <strong>Next.js</strong> enables more efficient resource utilization and optimizes the overall user experience.</p><p>But transitioning from the traditional <strong>React.js</strong> template into N<strong>ext.js</strong> template may give you headaches, specially with this new file-based routing and client-server side component separation.</p><p>It happened to me … specifically on trying to use Context API. I declared ‘use client’ almost everywhere to solve but nothing happened.</p><p>Here’s the initial code from the Layout.tsx file in my <strong>app directory</strong></p><pre>import &quot;@/styles/globals.css&quot;;<br>import Navbar from &quot;@/components/Navbar&quot;;<br>import Footer from &quot;@/components/Footer&quot;;<br>import { Toaster } from &quot;@/components/ui/Toast&quot;;<br>import { ContextProvider } from &quot;@/context/ContextProvider&quot;;<br>import { ThemeProvider } from &quot;next-themes&quot;;<br><br>export default function RootLayout({<br>  children,<br>}: {<br>  children: React.ReactNode;<br>}) {<br>  return (<br>    &lt;html lang=&quot;en&quot;&gt;<br>      &lt;body className=&quot;min-h-screen dark:bg-slate-900 antialiased&quot;&gt;<br>        &lt;ThemeProvider enableSystem={true} attribute=&quot;class&quot;&gt;<br>          &lt;ContextProvider&gt;<br>            &lt;Navbar /&gt;<br>            &lt;Toaster position=&quot;bottom-right&quot; /&gt;<br>            {children}<br>            &lt;Footer /&gt;<br>          &lt;/ContextProvider&gt;<br>        &lt;/ThemeProvider&gt;<br>      &lt;/body&gt;<br>    &lt;/html&gt;<br>  );<br>}</pre><p>I’m still getting an error from this file structure saying that I need to declare a ‘use client’ directive cause <strong>createContext</strong> only works on client-side components, note that in the code snippet above I declared ‘use client’ on top of the <strong>Context</strong> Component.</p><p>Here’s how I solved it</p><p>Inside my components folder, I created a file called<strong> </strong>‘<strong>Provider.tsx</strong>’</p><pre>&quot;use client&quot;;<br><br>import { ThemeProvider } from &quot;next-themes&quot;;<br>import { ContextProvider } from &quot;@/context/ContextProvider&quot;;<br><br>export function Providers({ children }: { children: React.ReactNode }) {<br>  return (<br>    &lt;ThemeProvider attribute=&quot;class&quot; defaultTheme=&quot;system&quot; enableSystem&gt;<br>      &lt;ContextProvider&gt;{children}&lt;/ContextProvider&gt;<br>    &lt;/ThemeProvider&gt;<br>  );<br>}</pre><p>In this file, I declare a directive ‘<strong>use client</strong>’ to specify that this is a client-side component. And combined the two providers into a single file.</p><p>After that, I modified my main <strong>Layout.tsx </strong>and wrapped the whole application using the <strong>Providers</strong> component.</p><pre>import &quot;@/styles/globals.css&quot;;<br>import Navbar from &quot;@/components/Navbar&quot;;<br>import Footer from &quot;@/components/Footer&quot;;<br>import { Toaster } from &quot;@/components/ui/Toast&quot;;<br>import { Providers } from &quot;@/components/Providers&quot;;<br><br>export default function RootLayout({<br>  children,<br>}: {<br>  children: React.ReactNode;<br>}) {<br>  return (<br>    &lt;html lang=&quot;en&quot;&gt;<br>      &lt;body className=&quot;min-h-screen dark:bg-slate-900 antialiased&quot;&gt;<br>        &lt;Providers&gt;<br>          &lt;Navbar /&gt;<br>          &lt;Toaster position=&quot;bottom-right&quot; /&gt;<br>          {children}<br>          &lt;Footer /&gt;<br>        &lt;/Providers&gt;<br>      &lt;/body&gt;<br>    &lt;/html&gt;<br>  );<br>}</pre><p>After doing this, the errors are gone.</p><p>Github: <a href="https://github.com/DevgenX">https://github.com/DevgenX</a></p><p>Website : <a href="https://sebgonzales.dev/">https://sebgonzales.dev/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1198a61c5c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Review on AWS Networking: IPv6, VPCs, IPv4 in IGW, Bastion/Jumpbox, and More]]></title>
            <link>https://medium.com/@seb_5882/review-on-aws-networking-ipv6-vpcs-ipv4-in-igw-bastion-jumpbox-and-more-b305460c4ee8?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/b305460c4ee8</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Thu, 18 May 2023 12:56:35 GMT</pubDate>
            <atom:updated>2023-05-18T12:56:35.980Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xllEmw70-33NUfBlCvw2YQ.png" /></figure><p>As an aspiring AWS Associate Solutions Architect, it is crucial to have a comprehensive understanding of networking concepts within the AWS ecosystem. In this blog post, we will explore important topics such as IPv6, Virtual Private Clouds (VPCs), IPv4 in Internet Gateways (IGWs), and the role of Bastion/Jumpbox instances in securing access to resources.</p><ol><li><strong>Understanding IPv6</strong>: IPv6 (Internet Protocol version 6) is the latest version of the Internet Protocol, addressing the limitations of IPv4. Key aspects include:</li></ol><ul><li><strong>Expanded Address Space</strong>: IPv6 uses 128-bit addresses, providing a significantly larger pool of unique addresses compared to IPv4’s 32-bit addresses.</li><li><strong>Addressing Scheme</strong>: IPv6 addresses are represented as eight groups of four hexadecimal digits separated by colons. For example, 2001:0db8:85a3:0000:0000:8a2e:0370:7334.</li><li><strong>Transition Mechanisms</strong>: Dual-stack, tunneling, and translation mechanisms enable the coexistence and migration from IPv4 to IPv6 networks.</li></ul><p>2. <strong>Virtual Private Cloud (VPC)</strong>: A VPC is a virtual network dedicated to your AWS account, offering control over network settings and isolated environments for resources. Key points include:</p><ul><li><strong>Subnets</strong>: VPCs are divided into subnets, logical divisions of IP address ranges that enable better organization and segmentation of resources.</li><li><strong>Internet Gateway (IGW)</strong>: An IGW allows communication between your VPC and the internet, serving as a bridge for internet access within the VPC.</li></ul><p>3.<strong> IPv4 in Internet Gateways (IGWs)</strong>: While IPv6 is gaining popularity, IPv4 remains widely used and can be integrated with VPCs and IGWs. Key concepts include:</p><ul><li><strong>Elastic IP (EIP)</strong>: EIPs are static, public IPv4 addresses that can be associated with EC2 instances or NAT (Network Address Translation) gateways, providing consistent public IP addresses.</li><li><strong>NAT Gateways</strong>: NAT gateways enable outbound internet connectivity for resources within private subnets, translating private IPv4 addresses to public addresses using EIPs.</li></ul><p>4. <strong>Bastion/Jumpbox Instances</strong>: Bastion or Jumpbox instances are dedicated servers used as a secure entry point to access resources within a VPC. Key points to understand include:</p><ul><li><strong>Purpose</strong>: Bastion instances act as a gateway for secure remote access to private instances within a VPC. They provide a controlled access point, minimizing the exposure of private instances to the internet.</li><li><strong>Security</strong> <strong>Considerations</strong>: Bastion instances should be hardened and configured with stringent security measures, including strong authentication mechanisms, strict access control, and regular patching.</li><li><strong>Configuration</strong>: Bastion instances are typically placed within a public subnet, allowing inbound SSH/RDP access from authorized IP addresses. They have access to private subnets for managing and administering resources.</li></ul><p>5<strong>. Data Flow in VPCs</strong>: Understanding how data flows within a VPC is essential for architecting network architectures. Key elements of VPC data flow include:</p><ul><li><strong>Routing</strong> <strong>Tables</strong>: Each subnet has an associated routing table controlling traffic flow. By default, the main routing table routes traffic to the IGW for internet access.</li><li><strong>Security</strong> <strong>Groups</strong>: Security groups act as virtual firewalls, controlling inbound and outbound traffic at the instance level based on port numbers, protocols, and IP ranges.</li><li><strong>Network</strong> <strong>Access</strong> <strong>Control</strong> <strong>Lists</strong> (<strong>NACLs</strong>): NACLs provide an additional layer of security at the subnet level, filtering both inbound and outbound traffic.</li></ul><p><strong>Summary</strong></p><p>Mastering networking concepts within AWS is vital for an AWS Solutions Architect. In this blog post, we explored essential topics such as IPv6, VPCs, IPv4 in IGWs, and the role of Bastion/Jumpbox instances. Understanding these concepts empowers you to design secure, scalable, and efficient network architectures within the AWS ecosystem.</p><p><strong>IPv6</strong> provides an expanded address space and introduces new addressing schemes, enabling the growth of the internet while mitigating address exhaustion. VPCs offer control and isolation, allowing you to create customized virtual networks for your resources. By leveraging IGWs, you can connect your VPC to the internet seamlessly, incorporating IPv4 connectivity through EIPs and NAT gateways.</p><p><strong>Bastion/Jumpbox</strong> instances act as a secure entry point, providing controlled access to private resources within a VPC. Proper configuration and security measures ensure secure remote access while minimizing exposure to potential threats.</p><p>Understanding the <strong>flow of data </strong>within a VPC, including routing tables, security groups, and NACLs, allows you to design robust and secure network architectures. By applying appropriate rules and configurations, you can optimize traffic flow and enforce granular security controls.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b305460c4ee8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript Basics : A code-focused guide]]></title>
            <link>https://medium.com/@seb_5882/typescript-basics-a-code-focused-guide-a120123d6f25?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/a120123d6f25</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Sun, 16 Apr 2023 17:19:04 GMT</pubDate>
            <atom:updated>2023-04-16T17:19:04.931Z</atom:updated>
            <content:encoded><![CDATA[<h3>TypeScript Basics : A code-focused guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qjXZCutSFOOUNH2w" /><figcaption>Image from google</figcaption></figure><p>If you’re a developer who’s looking to enhance your JavaScript projects with stronger typing and more robust code, then TypeScript may be just the tool you need. TypeScript is a superset of JavaScript that adds optional static typing, classes, interfaces, and other features to make your code more predictable and easier to maintain. In this guide, we’ll take you through the basics of TypeScript, starting with installing and setting up the TypeScript compiler, and moving on to key concepts like types, functions, interfaces, classes, and modules.</p><p>Along the way, we’ll use practical examples to demonstrate how TypeScript can help you catch errors before they become bugs, improve code readability and scalability, and accelerate development workflows. Whether you’re a seasoned JavaScript developer or new to the language, this guide will give you the foundational knowledge you need to start using <strong>TypeScript</strong> in your projects. Let’s get started!</p><ol><li><strong>Typing a function with number as argument</strong></li></ol><pre>// JavaScript <br>const addTwoNumbers = (a, b) =&gt; {<br>  return a + b;<br>};<br><br>// TypeScript <br>const addTwoNumbers = (a: number, b: number) =&gt; {<br>  return a + b;<br>};</pre><p>The first code snippet is JavaScript, which is a dynamically typed language. It defines a function called addTwoNumbers that takes two arguments, a and b, and returns their sum using the + operator. Because JavaScript is dynamically typed, the types of a and b are not explicitly declared, and can be any type at runtime.</p><p>The second code snippet is TypeScript, which is a statically typed language that is a superset of JavaScript. It defines a function called addTwoNumbers that takes two arguments, a and b, both of which are explicitly declared as number types using the : syntax. This means that TypeScript will check at compile time that the types of a and b are indeed numbers, and will flag an error if they are not. By providing type annotations, TypeScript enables developers to catch errors earlier in the development process and write more robust code.</p><p>2. <strong>Typing a function with an object as parameters</strong></p><pre>// JavaScript<br>const addTwoNumbers = (params) =&gt; {<br>  return params.first + params.second;<br>};<br><br>// TypeScript <br>interface newParams {<br>  first: number;<br>  second: number;<br>}<br><br> const addTwoNumbers = (params: newParams) =&gt; {<br>  return params.first + params.second;<br>};</pre><p>The JavaScript code defines a function called addTwoNumbers that takes an object params as an argument, and returns the sum of its first and second properties. Since JavaScript is dynamically typed, the params object could have any number of properties and the function would still run.</p><p>In the TypeScript code, an interface called newParams is defined, which describes the shape of an object that must have two properties, first and second, both of which must be of type number. This interface is then used to specify the type of the params argument of the addTwoNumbers function, ensuring that only objects with the correct properties and types can be passed in. This makes the code more robust and easier to reason about, as type errors can be caught earlier in the development process.</p><p>3.<strong> Typing a function with optional parameters</strong></p><pre>// JavaScript <br>const getName = (params) =&gt; {<br>  if (params.last) {<br>    return `${params.first} ${params.last}`;<br>  }<br>  return params.first;<br>};<br><br>// TypeScript<br>interface getNames {<br>  first: string;<br>  last?: string;<br>}<br><br>const getName = (params: getNames) =&gt; {<br>  if (params.last) {<br>    return `${params.first} ${params.last}`;<br>  }<br>  return params.first;<br>};</pre><p>The JavaScript code defines a function called getName that takes an object params as an argument. If the last property of the params object is defined, the function returns a string that concatenates the first and last properties separated by a space. Otherwise, the function returns just the first property. Because JavaScript is dynamically typed, the function can accept an object with any properties, which makes it flexible but also more error-prone.</p><p>In the TypeScript code, an interface called getNames is defined, which describes the shape of an object that must have a required first property of type string and an optional last property of type string. The getName function is then defined to take an argument of type getNames, ensuring that the input object conforms to the expected shape. This makes the code more reliable and easier to understand, as it ensures that the object passed to the function has the required properties with the correct types.</p><p>4. <strong>Typing a function with union type</strong></p><pre>// TypeScript <br>interface User {<br>  id: number;<br>  firstName: string;<br>  lastName: string;<br>  role: &quot;admin&quot; | &quot;user&quot; | &quot;super-admin&quot;;<br>}<br><br> const defaultUser: User = {<br>  id: 1,<br>  firstName: &quot;Seb&quot;,<br>  lastName: &quot;Degen&quot;,<br>  // @ts-expect-error<br>  role: &quot;I_SHOULD_NOT_BE_ALLOWED&quot;,<br>};</pre><p>In TypeScript, a union type allows a variable to have one of multiple possible types. In the code provided, the role property of the User interface is defined as a union type of &quot;admin&quot;, &quot;user&quot;, and &quot;super-admin&quot;. This means that any variable or parameter that is typed as User can only have one of these three string values for the role property, and any other value will be considered invalid by the TypeScript compiler. The use of a union type provides more strict type checking, which can help catch errors and make the code more robust.</p><p>5. <strong>Typing an array</strong></p><pre>interface User {<br>  id: number;<br>  firstName: string;<br>  lastName: string;<br>  role: &quot;admin&quot; | &quot;user&quot; | &quot;super-admin&quot;;<br>  posts: Post[]; // We passed-in Post to be the data type (an array of objects)<br>}<br><br>interface Post {<br>  id: number;<br>  title: string;<br>}<br><br> const defaultUser: User = {<br>  id: 1,<br>  firstName: &quot;Matt&quot;,<br>  lastName: &quot;Pocock&quot;,<br>  role: &quot;admin&quot;,<br>// Here&#39;s the posts array, with id and title keys.<br>  posts: [ <br>    {<br>      id: 1,<br>      title: &quot;How I eat so much cheese&quot;,<br>    },<br>    {<br>      id: 2,<br>      title: &quot;Why I don&#39;t eat more vegetables&quot;,<br>    },<br>  ],<br>};</pre><p>The code above defines an interface called User which has properties for id, firstName, lastName, and role as well as an array of Post objects called posts. The Post interface has properties for id and title. The defaultUser object is then created based on the User interface, with values assigned to all of its properties including an array of Post objects.</p><p>6. <strong>Typing a function that returns a promise</strong></p><pre>interface LukeSkywalker {<br>  name: string;<br>  height: string;<br>  mass: string;<br>  hair_color: string;<br>  skin_color: string;<br>  eye_color: string;<br>  birth_year: string;<br>  gender: string;<br>}<br><br> const fetchLukeSkywalker = async (): Promise&lt;LukeSkywalker&gt; =&gt; {<br>  const data = await fetch(&quot;https://swapi.dev/api/people/1&quot;).then((res) =&gt; {<br>    return res.json();<br>  });<br><br>  return data;<br>};</pre><p>This code defines an interface LukeSkywalker which specifies the properties of an object representing Luke Skywalker&#39;s personal information. The fetchLukeSkywalker function uses the async/await syntax to retrieve data from the Star Wars API (SWAPI) and return a promise of a LukeSkywalker object. The fetch method returns a promise that is resolved with a Response object, which is then parsed into JSON format and returned as the result of the function.</p><p>7. <strong>Typing an object that accepts parameters using Record</strong></p><pre>const createCache = () =&gt; {<br>  const cache: Record&lt;string, string&gt; = {};<br><br>  const add = (id: string, value: string) =&gt; {<br>    cache[id] = value;<br>  };<br><br>  const remove = (id: string) =&gt; {<br>    delete cache[id];<br>  };<br><br>  return {<br>    cache,<br>    add,<br>    remove,<br>  };<br>};<br><br>// alternative solution <br>// We use interface and indexing instead of Record<br>interface Keys {<br>  [index: string]: string;<br>}<br><br>const createCache = () =&gt; {<br>  const cache: Keys = {};<br><br>  const add = (id: string, value: string) =&gt; {<br>    cache[id] = value;<br>  };<br><br>  const remove = (id: string) =&gt; {<br>    delete cache[id];<br>  };<br><br>  return {<br>    cache,<br>    add,<br>    remove,<br>  };<br>};</pre><p>In TypeScript, Record is a utility type that allows you to create a type with keys of a specific type and values of another specific type. In this code snippet, createCache is a function that creates a simple cache object with an underlying JavaScript object where keys are strings and values are also strings. The add method allows you to add key-value pairs to the cache, while remove removes a specific key-value pair. The function returns an object with the cache, add, and remove methods that can be used to interact with the cache.</p><p>8. <strong>Typing a try/catch block inside a function</strong></p><pre>const tryCatchDemo = (state: &quot;fail&quot; | &quot;succeed&quot;) =&gt; {<br>  try {<br>    if (state === &quot;fail&quot;) {<br>      throw new Error(&quot;Failure!&quot;);<br>    }<br>  } catch (e) {<br>    if (e instanceof Error) return e.message;<br>  }<br>};</pre><p>This code declares a function named tryCatchDemo that takes in a parameter called state of type &quot;fail&quot; | &quot;succeed&quot;. The function tries to execute a block of code, and if it fails, it throws an error with the message &quot;Failure!&quot;. In the catch block, it checks if the caught error is an instance of Error, and if it is, it returns the message of the error. The code uses TypeScript to ensure that the state parameter can only have the values &quot;fail&quot; or &quot;succeed&quot;, and that the returned value is a string.</p><p>9. <strong>Typing a function with omit or pick(only the properties we want)</strong></p><pre>interface User {<br>  id: string;<br>  firstName: string;<br>  lastName: string;<br>}<br><br>// Here are the two solutions <br>// Omit excludes id from the properties<br>type MyType = Omit&lt;User, &quot;id&quot;&gt;;<br>// Picks includes only those that are defined<br>type MyType = Pick&lt;User, &quot;firstName&quot; | &quot;lastName&quot;&gt;;<br><br>type tests = [Expect&lt;Equal&lt;MyType, { firstName: string; lastName: string }&gt;&gt;]</pre><p>This code defines an interface called User that has three properties: id, firstName, and lastName. Two new types are then defined using the Omit and Pick utility types provided by TypeScript. Omit is used to create a new type MyType that has all the properties of User except for id. Pick is used to create another type MyType that only has the firstName and lastName properties of User. TypeScript checking is useful here to ensure that the properties being picked or omitted actually exist on the User interface.</p><p>10. <strong>Typing a function with a function as an argument</strong></p><pre>type onFocusFunction = (a: boolean) =&gt; void;<br><br>const addListener = (onFocusChange: onFocusFunction) =&gt; {<br>  window.addEventListener(&quot;focus&quot;, () =&gt; {<br>    onFocusChange(true);<br>  });<br><br>  window.addEventListener(&quot;blur&quot;, () =&gt; {<br>    onFocusChange(false);<br>  });<br>};<br><br>addListener((isFocused) =&gt; {<br>  console.log({ isFocused });<br><br>  type tests = [Expect&lt;Equal&lt;typeof isFocused, boolean&gt;&gt;];<br>});</pre><p>This code defines a type alias onFocusFunction for a function that takes a single boolean argument and returns nothing (i.e., void). Then, the function addListener is defined that takes an argument of the onFocusFunction type and sets up two event listeners on the window object. When these events are fired (when the window gains or loses focus), the corresponding function passed to addListener is called with the appropriate boolean value, and console.log is called with the same value. The TypeScript compiler checks that the type of isFocused is correctly inferred as boolean.</p><p>That’s it for the basics!</p><p>There’s so much to learn about TypeScript, but once you dive into the rabbit hole, you can never go back into using JavaScript.</p><p><strong>Note : This blog was a summary of what I learned on TypeScript fundamentals.</strong></p><p>If you want to learn more, you can view the exercises and solutions in my repository :</p><p><a href="https://github.com/DevgenX/TypeScripting/tree/main/typescript-starter/src">Github</a></p><p><a href="https://www.linkedin.com/in/sebgonzales/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a120123d6f25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Short Guide to React’s Powerful Duo : useReducer and UseContext]]></title>
            <link>https://medium.com/@seb_5882/a-short-guide-to-reacts-powerful-duo-usereducer-and-usecontext-23cea6f9ab35?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/23cea6f9ab35</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 15:47:40 GMT</pubDate>
            <atom:updated>2023-03-29T15:52:58.399Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Short Guide to React’s Powerful Duo : <strong>useReducer and UseContext</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FNwvV2kKrJia8BCc.jpg" /></figure><p><strong>useReducer</strong> and <strong>useContext</strong> are two powerful hooks in React that can be used together to manage the state for your entire application. <strong>useReducer</strong> provides a way to manage complex state transitions in a more predictable and manageable way, while <strong>useContext</strong> allows you to pass data down the component tree without having to pass props manually through each level simply, making your <strong>data</strong> globally available.</p><p>For this blog, we’ll apply the code best practices that I’m aware of at the moment.</p><p>In your app, create a folder called “<strong>context</strong>”, and inside that folder, create a file called “<strong>IncrementContext</strong>” .</p><pre>import { createContext, useContext, useReducer } from &#39;react&#39;;<br><br>// Create a context to hold the state<br>const IncrementContext = createContext();<br><br>// Define the initial state<br>const initialState = {<br>  count: 0<br>};<br><br>// Define the reducer function to handle state transitions<br>const reducer = (state, action) =&gt; {<br>  switch (action.type) {<br>    case &#39;increment&#39;:<br>      return { count: state.count + 1 };<br>    case &#39;decrement&#39;:<br>      return { count: state.count - 1 };<br>    default:<br>      throw new Error();<br>  }<br>}<br><br>// Create a component that will provide the context<br>// IncrementProvider takes in an argument called children<br>const IncrementProvider = ({ children ) =&gt; {<br>  const [state, dispatch] = useReducer(reducer, initialState);<br><br>// In this return value, we passed-in children as the CONSUMER of the PROVIDER<br>// This will able children components to access the data inside the context<br>  return (<br>    &lt;IncrementContext.Provider value={{ ...state, dispatch }}&gt;<br>      {children}<br>    &lt;/IncrementContext.Provider&gt;<br>  );<br>}<br><br>// Create a function that invokes the context <br>export const useIncrementContext = () =&gt; {<br>  return useContext(IncrementContext)<br>}<br></pre><p>Let this code snippet above, be the guide throughout the blog.</p><ol><li><strong>Writing your context component and initialState variables</strong></li></ol><pre>import { createContext, useContext, useReducer } from &#39;react&#39;;<br><br>// Create a context to hold the state<br>const IncrementContext = createContext();<br><br>// Define the initial state<br>const initialState = {<br>  count: 0<br>}</pre><p>In this code snippet above, we imported three react hooks, <strong>createContext</strong>, <strong>useContext</strong> and <strong>useReducer</strong>.</p><ul><li><strong>CreateContext</strong> is to create the context to hold the state</li><li><strong>useContext</strong> is used to invoke the context</li><li><strong>useReducer</strong> to manage the state variables and functionalities</li></ul><p>We also declared the initialState object with a key-value pair, count with a default value of 0.</p><p>We will be passing this code into the useReducer hook, to build the functionalities.</p><p><strong>2. Writing your reducer function</strong></p><pre>const reducer = (state, action) =&gt; {<br>  switch (action.type) {<br>    case &#39;increment&#39;:<br>      return { count: state.count + 1 };<br>    case &#39;decrement&#39;:<br>      return { count: state.count - 1 };<br>    default:<br>      throw new Error();<br>  }<br>}<br><br>//Together with the reducer and initialState, we will be declaring both <br>//of this components inside the useReducer hook <br><br>// This will be declared inside the IncrementProvider<br>const [state, dispatch] = useReducer(reducer, initialState);</pre><p>A <strong>reducer</strong> function is a pure function that takes in the current state and an action object, and returns a new state based on the action type and payload. It is used with the <strong>useReducer</strong> hook to manage complex state logic in a React application. The reducer function should always return a new state object rather than modifying the current state directly.</p><p>In the provided code snippet, the reducer function takes in the current state object and an action object with a type property. Depending on the action type, the reducer returns a new state object with the count property incremented or decremented accordingly. If an action type is not recognized, the reducer throws an error to indicate that an invalid action was dispatched.</p><p>3. <strong>Writing the context provider and making the data globally accessible</strong></p><pre>// use useReducer to access both the reducer and initialState<br>const IncrementProvider = (props) =&gt; {<br>  const [state, dispatch] = useReducer(reducer, initialState);<br><br>  return (<br>    &lt;IncrementContext.Provider value={{ ...state, dispatch }}&gt;<br>      {props.children}<br>    &lt;/IncrementContext.Provider&gt;<br>  );<br>}<br><br>// Wrapped the whole application, in the index.js with IncrementProvider<br>// This makes the context object be globally accessible<br>const root = ReactDOM.createRoot(document.getElementById(&quot;root&quot;));<br>root.render(<br>  &lt;React.StrictMode&gt;<br>    &lt;IncrementProvider&gt;<br>      &lt;App /&gt;<br>    &lt;/IncrementProvider&gt;<br>  &lt;/React.StrictMode&gt;<br>);<br><br></pre><p>The <strong>IncrementProvider</strong> is a custom provider component that uses <strong>useReducer</strong> to manage state and creates a context using <strong>createContext</strong>. The provider component accepts props as an argument and returns a provider component that wraps the child components.</p><p>The provider component uses the IncrementContext.Provider to provide the state and dispatch function to the child components via the context. It does this by passing an object containing the state and dispatch function as the value to the IncrementContext.Provider.</p><p>In the example code, the IncrementProvider is wrapped around the App component in index.js. This makes the state and dispatch function available to all child components of the App component.</p><p>By wrapping the whole application in the IncrementProvider, we ensure that all components have access to the state and can dispatch actions to modify it. This is a common pattern in React applications to manage global state using context and the <strong>useReducer</strong> hook.</p><p>4. <strong>Accessing the data with your components</strong></p><pre>import { useIncrementContext } from &#39;IncrementContext&#39;<br><br><br>const MyComponent = () =&gt; {<br>// No need to use useContext to invoke the context <br>// Since we wrote a useIncrementContext function that invokes the context<br>  const { state, dispatch } = useIncrementContext()<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {state.count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;increment&#39; })}&gt;+&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;decrement&#39; })}&gt;-&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>The useIncrementContext is a custom hook that is used to consume the context created by the IncrementContext.Provider. This hook abstracts away the boilerplate code of using the useContext hook and makes it easier to access the context values.</p><p>In the example code, useIncrementContext is imported from the IncrementContext file. The MyComponent component uses the useIncrementContext hook to access the state and dispatch function from the context.</p><p>By using the useIncrementContext hook, we don&#39;t need to use the <strong>useContext</strong> hook directly in the component. Instead, we can simply invoke the useIncrementContext function to access the state and dispatch function from the context.</p><p>The MyComponent component renders a paragraph displaying the current count value from the state object. It also renders two buttons that dispatch an increment or decrement action when clicked.</p><p>This code snippet demonstrates how to use a custom hook to consume context values in a React component. It simplifies the process of using context and makes it easier to access the state and dispatch function from multiple components in the application.</p><p>Hope this blog helps!</p><p>Github : <a href="https://github.com/DevgenX">https://github.com/DevgenX</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23cea6f9ab35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your own ChatGPT using Python.]]></title>
            <link>https://medium.com/@seb_5882/build-your-own-chatgpt-using-python-c6378971897c?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6378971897c</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 15:24:59 GMT</pubDate>
            <atom:updated>2023-03-02T15:24:59.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5TAwx6hz35fBEKd2" /></figure><p>ChatGPT has taken the world by storm, having able to generate accurate responses based on user prompts, from summarizing research, providing code snippets and even generating a good starter application. ChatGPT got it all for you!</p><p>In this short blog, I’ll be providing the code on how to build your own ChatGPT and run it on your terminal with less than 20 lines of code!</p><p><strong>Note</strong>: We will be using thecode-davinci-002 model, a free GPT model.</p><p><a href="https://github.com/DevgenX/Random-Python-Stuff/blob/main/chatgpt.py"><strong>Github</strong></a></p><pre>import openai <br><br>openai.api_key =&#39;Your API key in here&#39;<br><br>model = &#39;code-davinci-002&#39;<br>prompt = input(&#39;Ask anything: &#39;)<br><br><br>completion = openai.Completion.create(<br>    engine = model,<br>    prompt = prompt,<br>    max_tokens = 120,<br>    temperature = 0.0,<br>    n=1,<br>    stop=[&quot;###&quot;],<br>    <br>)<br><br><br>response = completion.choices[0].text<br>print(response)</pre><p>First, you need to ensure that you have the openai library installed. If you don&#39;t have it installed, you can install it by running !pip install openai in your Python environment.</p><p>Once done, the next step is getting your API keys <a href="https://platform.openai.com/overview">here</a>.</p><p><strong>Step by step process :</strong></p><ul><li>Create an account if you don’t have one</li><li>On the upper right tab, click on ‘Personal’ then go to view API keys</li><li>Create your API keys, copy and paste it on the code snippet.</li></ul><p>And then you’re good to go!</p><p>To run the code, paste the code snippet on your chosen IDE. I used <a href="https://code.visualstudio.com/">Visual Studio Code</a> to run the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SUXHLbRBajlWrCkLPSt2kg.jpeg" /></figure><p>Run: <strong>python3 file_name.py</strong></p><p>The prompt will ask you to enter any input you want to search, in this case I asked the bot to define ReactJS</p><p><strong>Input</strong> : What is ReactJS?</p><p><strong>Response</strong> : ReactJS is a JavaScript library that is used to build user interfaces. It is maintained by Facebook and a community of individual developers and companies. React can be used as a base in the development of single-page or mobile applications.</p><p><strong>Note</strong> : This is a simple tool built on top of ChatGPT-3 and is nowhere good or better than their model.</p><p>I’ll be building more random stuff as I progress in my learning to code process.</p><p>Hope you learned something!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6378971897c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Metaprogramming : Code That Writes Code.]]></title>
            <link>https://medium.com/@seb_5882/rails-metaprogramming-code-that-writes-code-f7b2d2880c95?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7b2d2880c95</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 20:36:14 GMT</pubDate>
            <atom:updated>2023-02-15T20:36:14.363Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails Metaprogramming : Code That Writes Code.</h3><p>Using the metaprogramming technique, you can create programs that can alter other programs while they are running. This implies that you can create, change, or remove other code using code. Metaprogramming, then, is the act of creating code that creates code.<br>In the context of programming languages, metaprogramming refers to the use of linguistic constructs that let you change the structure and behavior of a program while it is running. Reflection, introspection, and dynamic code creation are a few examples of such functionalities.</p><h3>Metaprogramming in Rails</h3><p>Rails is a powerful web app development framework. Its usage of metaprogramming is one factor in its popularity. Rails takes advantage of metaprogramming to offer a robust and adaptable API that can be altered and expanded in a variety of ways.<br>Metaprogramming is a technique used in Rails to generate dynamic code that may be tailored to meet the specific needs of your application. You can write more compact, modular, and reusable code as a result.</p><h3>Examples of Metaprogramming in Rails</h3><p>Here are some examples of how metaprogramming is used in Rails:</p><h3>Dynamic Finders</h3><p>Rails provides a set of dynamic finder methods that allow you to find records in the database based on their attributes. These methods are created dynamically at runtime using metaprogramming.</p><p>For example, if you have a User model with an email attribute, you can find a user with a specific email address like this:</p><pre>User.find_by_email(&#39;user@example.com&#39;)</pre><p>Rails creates this method at runtime based on the name of the attribute (email). You can also use other dynamic finder methods, such as find_by_id and find_all_by.</p><h3>Callbacks</h3><p>Rails provides a powerful set of callbacks that allow you to trigger custom code at specific points in the lifecycle of a model. These callbacks are defined using metaprogramming.</p><p>For example, you can define a before_save callback that sets a default value for a field:</p><pre>class User &lt; ActiveRecord::Base<br>  before_save :set_default_value<br><br>  def set_default_value<br>    self.field = &#39;default&#39;<br>  end<br>end</pre><p>Rails creates the before_save method dynamically based on the name of the callback (set_default_value). You can also define other callbacks, such as before_create, after_save, and around_update.</p><h3>Scopes</h3><p>Rails provides a way to define named scopes that allow you to create reusable queries. These scopes are defined using metaprogramming.</p><p>For example, you can define a scope that finds all active users:</p><pre>class User &lt; ActiveRecord::Base<br>  scope :active, -&gt; { where(active: true) }<br>end<br></pre><p>Rails creates the active method dynamically based on the name of the scope (active). You can also define other scopes that accept parameters, such as scope :created_since, -&gt;(time) { where(&#39;created_at &gt; ?&#39;, time) }.</p><h3>Associations</h3><p>Rails provides a powerful set of associations that allow you to define relationships between models. These associations are defined using metaprogramming.</p><p>For example, you can define a `has Many-to-Many association between a User and Group model:</p><pre>class User &lt; ActiveRecord::Base<br>  has_many :memberships<br>  has_many :groups, through: :memberships<br>end<br><br>class Group &lt; ActiveRecord::Base<br>  has_many :memberships<br>  has_many :users, through: :memberships<br>end<br><br>class Membership &lt; ActiveRecord::Base<br>  belongs_to :user<br>  belongs_to :group<br>end</pre><p>Many-to-Many association between a User and Group model:</p><pre>rubyCopy code</pre><pre>class User &lt; ActiveRecord::Base<br>  has_many :memberships<br>  has_many :groups, through: :memberships<br>end</pre><pre>class Group &lt; ActiveRecord::Base<br>  has_many :memberships<br>  has_many :users, through: :memberships<br>end</pre><pre>class Membership &lt; ActiveRecord::Base<br>  belongs_to :user<br>  belongs_to :group<br>end</pre><p>Rails creates the has_many and belongs_to methods dynamically based on the names of the associations (memberships, groups, and users). You can also define other types of associations, such as has_one, has_and_belongs_to_many, and polymorphic.</p><h3>Class Methods and Instance Methods</h3><p>Rails allows you to define both class methods and instance methods dynamically using metaprogramming.</p><p>For example, you can define a class method that returns the total number of users:</p><pre>class User &lt; ActiveRecord::Base<br>  def self.total_count<br>    count<br>  end<br>end=</pre><p>Rails creates the total_count method dynamically as a class method. You can also define instance methods dynamically, such as:</p><pre>class User &lt; ActiveRecord::Base<br>  def full_name<br>    &quot;#{first_name} #{last_name}&quot;<br>  end<br>end=</pre><p>Rails creates the full_name method dynamically as an instance method.</p><h3>Pros and Cons of using Metaprogramming</h3><p>Metaprogramming can be a powerful technique for building flexible and reusable code. It allows you to write code that can adapt to different scenarios and customize behavior based on specific needs.</p><p>However, metaprogramming can also make your code more complex and harder to maintain. It can be difficult to debug code that is generated dynamically, and it can be hard to understand how the code works without reading the source code.</p><p>In addition, metaprogramming can have a negative impact on performance. Dynamic code generation can be slower than static code, and it can consume more memory.</p><h3>Conclusion</h3><p>While metaprogramming can be a powerful tool, it’s important to use it meticously and to consider the potential tradeoffs in terms of readability, maintainability, and performance. By using metaprogramming strategically, you can build more flexible and reusable code that adapts to the changing needs of your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7b2d2880c95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Best Practices : Optimizing your React Application]]></title>
            <link>https://medium.com/@seb_5882/react-best-practices-optimizing-your-react-application-562b67bc1b22?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/562b67bc1b22</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Wed, 25 Jan 2023 17:03:50 GMT</pubDate>
            <atom:updated>2023-01-25T17:03:50.388Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Best Practices : Optimizing your React Application</h3><p>Optimization, organization and well-written code are some of the skills that every developers should have when building applications. In Javascript, react provided developers a front-end framework that is simple, easy to optimize but some times can be hard to understand due to its complexity in the rendering process.</p><p>In this blog, I will be pointing out a few of many react best practices to make your applications faster and understand it’s structure better.</p><ol><li><strong>Dividing your project into multiple components</strong></li></ol><p>Majority of you, who have seen or have written applications in react knows that breaking your project into components is a good practice for organization purposes. But that’s not the only case here.</p><p>Let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bn5P9SI5c7bXg1wiWe-TwQ.png" /><figcaption>App component</figcaption></figure><p>In this App component, I declared a state variable and a button with an onClick event that changes the color of text from green(initial color) into red.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*PY1LNNWGcquK5xzlYLWlzg.gif" /></figure><p>After clicking the button, the text turned into color red as the result of the function. But if you check the console, you’ll see that the app was re-rendered<strong> TWICE </strong>for no reason. This is because whenever a state variable is changed, it causes the app to re-render. This will affect the child components of a component and it is completely not ideal that affects the performance of your application.</p><p>So here comes the benefit of dividing your project into multiple components,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*mwjiCymI3TdP-k27nUYpKw.gif" /></figure><p>As you can see, I transferred the functionalities of clicking the button then changing the color of the text into a separate component called <strong><em>ChangeColor </em></strong>then<em> </em>it was passed-in as a child component of <strong><em>App</em></strong>. And as you can see, there were no re-renders that happened. Perfect!</p><p>2.<strong> Understanding Data types and useEffect</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*iw00NgKR52RWRT1hbDEVwQ.gif" /><figcaption>Relationship between Objects and State</figcaption></figure><p>In this component, I declared a <strong><em>useState</em></strong> that contains <strong><em>name</em></strong> and a boolean <strong><em>added</em></strong> which has an initial value set to <strong><em>false</em></strong>. Then two buttons with onClick handler that adds the input name and flips the value of added into true.</p><p>Notice that once I clicked the button, and appended the data into the DOM, the <strong><em>useEffect</em></strong> fires. And it should fire whenever the state is changed. But even though we are passing-in the same values, still the useEffect runs.</p><p>Let’s first understand primitive vs non-primitive data types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*MWFAgac-XE_VJ2E9NHGrVw.png" /></figure><p><strong>Strings, numbers, booleans, null </strong>and<strong> undefined</strong> are primitive data types, where when compared, returns true as they point to the same location in the memory.</p><p><strong>Objects </strong>and<strong> arrays </strong>are non-primitive data types, they may have the same content but they refer to different points in the memory thus, returning <em>false</em> when compared.</p><p>So how to avoid this unlimited “firing” from useEffect?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NC7Ae93OATAUswthZeh_mw.gif" /></figure><p>A simple solution is by passing-in the primitive data types into the <strong><em>dependency array</em></strong><em> </em>of the useEffect. In that way, the function knows what you are specifically referring to on changes.</p><p>3.<strong> Optimizing rendering performance with memoization and useCallback</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wNT0NuclTGhPc_eK2wa2MQ.gif" /></figure><p>In react, whenever the parent component re-renders, the child component re-renders. The solution to this problem is by <strong><em>Memoization</em></strong>. A component in react called <strong><em>memo</em></strong> is used to <strong>memoize</strong> and skips re-rendering if there are no changes made in the prop of the component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*BB0Id2Lgru6rxc_owPUl_w.gif" /></figure><pre>import { memo } from &quot;react&quot;;<br><br>const searchBox = memo(({ onChangeHandler, placeholder, className }) =&gt; {<br>  console.count(&quot;Re-render :  &quot;);<br>  return (<br>    &lt;input<br>      className={`search-box ${className}`}<br>      type=&quot;search&quot;<br>      placeholder={placeholder}<br>      onChange={onChangeHandler}<br>    /&gt;<br>  );<br>});<br><br>export default searchBox;</pre><p>In here, we wrapped the function with <strong><em>memo</em></strong> to remember the values of prop changes and skips the re-render. But it seems not working and still having the re-rendering issues.</p><p>Here comes the <strong><em>useCallback</em></strong> hook,</p><p><strong>useCallback</strong> like <strong><em>useMemo</em></strong>(memo), is a memoization technique but specifically for functions while useMemo is used to memoize certain values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*x9ydEzjByfLnUQLgd3spiA.gif" /></figure><pre>import { useCallback } from &quot;react&quot;;<br><br>const handleInputChange = useCallback((e) =&gt; {<br>    const searchField = e.target.value.toLowerCase();<br>    setSearchBy(searchField);<br>  }, []);</pre><p>In the App, the page re-renders whenever we passed-in a value in the input box that filters the monsters accordingly. This creates a new set of data that causes the re-render. So we want to memoize the callback function to stop the rendering.</p><p>Once I wrapped the function with <strong><em>useCallback</em></strong>, it stopped from re-rendering the page.</p><p>And that’s it for blog!</p><p>Hope you learned something :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=562b67bc1b22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript : Basics of Async/Await vs Native Promises]]></title>
            <link>https://medium.com/@seb_5882/javascript-basics-of-async-await-vs-native-promises-581e1fe0cbc4?source=rss-ead6dfdebd02------2</link>
            <guid isPermaLink="false">https://medium.com/p/581e1fe0cbc4</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Seb Gonzales]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 19:17:37 GMT</pubDate>
            <atom:updated>2023-01-03T21:13:58.899Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript : Basics of <strong>Async/Await vs Native Promises</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G12tkZJl67dn43jDgFJ5kw.png" /></figure><p><em>Async/await</em> and <em>Promises </em>are both ways to execute asynchronous code in Javascript. They are written and structured in different ways and have their own certain advantages and disadvantages when it comes to use cases.</p><p><strong>Promises</strong></p><p><em>Promises</em> was introduced in ECMAScript 2015 and been utilized to handle asynchronous code. It uses the <em>.then and .catch </em>keyword which handles both success and failures in the code, it also able developers to chain multiple asynchronous operation in a single interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07815c5519d89f962e74167807728cb5/href">https://medium.com/media/07815c5519d89f962e74167807728cb5/href</a></iframe><p>Looks pretty straightforward?</p><p>What if we can make it more understandable?</p><p><strong>Async/await</strong></p><p><em>async/await </em>was introduced in ECMAScript 2017 and is supported in all modern browsers. It is used to run asynchronous code but is written and structured like a synchronous-style code using <em>async</em> and <em>await </em>keyword.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cbc2be66792f3c32027835bf004c554/href">https://medium.com/media/8cbc2be66792f3c32027835bf004c554/href</a></iframe><p>Looks better ? right.</p><p>Why <strong><em>Async/await</em></strong> is better?</p><p>For the reasons below, we can use this code snippet :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80e0e5e1f72886bcb2a657ac1b2959f9/href">https://medium.com/media/80e0e5e1f72886bcb2a657ac1b2959f9/href</a></iframe><ol><li><strong>Readability</strong></li></ol><p>Code written in async/await are in synchronous-like structure that makes it easier working with asynchronous code. One of the most important skill to have as a developer is to be able to write clean, optimized and readable code.</p><p><em>Async/await</em> provides a more concise and straightforward lines of code of which are assigned to a variable, makes them accessible without the need of promise chain. Also, they are easier to debug and maintain.</p><p>2. <strong>Error handling and Debugging</strong></p><p><em>Async/await </em>needs to be wrapped inside the <em>try/catch</em> block to handle both success and failures in the code. You can also use debugger to pause the execution of a function at a specific point to understand how the promise is being resolved or rejected.</p><p>While for promises, it allows us to put the error handler at the end of promise chain. A huge disadvantage of using debugger in the promise chain is the scope as the execution will only stop where<em> “debugger”</em> is encountered.</p><p>It’s a mess to use debugger in native promises, as you have to be specific on putting breakpoints in the promise chain.</p><p>By just looking at the code, the approach in using async/await wrapped in try/catch block is more organized, therefore easier to debug.</p><p>3. <strong>Handling multiple values</strong></p><p><strong>Native promise</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0a614f9603bfd2d6893c66c3104d003/href">https://medium.com/media/f0a614f9603bfd2d6893c66c3104d003/href</a></iframe><p>Handling multiple values in this promise chain is pretty straightforward but it’s very easy to get lost in the code with so much indentations, brackets and stuff. And harder to identify breakpoints to execute the debugger on.</p><p><strong>Async/await</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/283fbc4e468dd72090a84a309432bd92/href">https://medium.com/media/283fbc4e468dd72090a84a309432bd92/href</a></iframe><p>Using async/await to handle multiple values makes the lines of code straightforward, organized and readable.</p><p><strong>Pitfalls</strong></p><ol><li><strong>Browser Compatibility</strong>: Async/await is a relatively new language feature of Javascript and may only be supported by modern browsers. While Promises, have been around for longer and more widely utilized.</li><li><strong>Error/Stack traces</strong>: Handling errors in async/await may not be as accurate as handling errors with Promises. Errors in async/await function are thrown in different context while Promises uses catch at end of the promise chain which is more flexible and accurate.</li><li><strong>Handling multiple asynchronous operations</strong>: Native promises provide a cleaner syntax on handling multiple asynchronous operations using the method Promise.all . Async/await in this case may become too verbose.</li></ol><p><strong>Conclusion</strong> :</p><p>The use of async/await instead of the native promise depends on the preference of every developer. There maybe older codebases that are still written in the native promise method as async/await are new and may only be supported by modern browsers.</p><p>If you aren’t handling multiple asynchronous operations and thinking of efficiency and organization, it’s better for you to use async/await.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BiKkPcpDt5V6kFrl.jpg" /><figcaption>CTTO</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=581e1fe0cbc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>