<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hameed Osilaja</title>
    <description>The latest articles on DEV Community by Hameed Osilaja (@osilaja78).</description>
    <link>https://dev.to/osilaja78</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F990691%2Ff1446576-5110-41bc-a85c-fd5f7f9264e0.jpg</url>
      <title>DEV Community: Hameed Osilaja</title>
      <link>https://dev.to/osilaja78</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/osilaja78"/>
    <language>en</language>
    <item>
      <title>Postmortem: Service Outage on MathEase Platform</title>
      <dc:creator>Hameed Osilaja</dc:creator>
      <pubDate>Sat, 11 Nov 2023 17:01:19 +0000</pubDate>
      <link>https://dev.to/osilaja78/postmortem-service-outage-on-mathease-platform-2i1d</link>
      <guid>https://dev.to/osilaja78/postmortem-service-outage-on-mathease-platform-2i1d</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In a world not so far away, where APIs responded happily until they didn't... 😥&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D0tT052x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p890jhyc2w2b4b6pgusm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D0tT052x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p890jhyc2w2b4b6pgusm.gif" alt="Rest in peace APIs" width="579" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Issue Summary.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Duration - 1 hour 25 minutes (Start: 07-10-2023 10:21 GMT, End: 07-10-2023 11:46 GMT), coincided with my coffee break, lol.&lt;/li&gt;
&lt;li&gt;Impact - unsuspecting and happy users were unable to get answers to math questions, it just keeps loading without returning a response (like bro, what the...).&lt;/li&gt;
&lt;li&gt;Root cause - too much API calls to the WolframAlpha API, due to an increase in traffic after our marketing campaign blew off, i guess WolframAlppha was like, bro, this is way too much than we signed up for 😂.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Timeline.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The issue was detected at 07-10-2023 10:21 GMT by automated monitoring systems triggering an alert for external API failure and unusually high traffic.&lt;/li&gt;
&lt;li&gt;Actions Taken - Assumed the issue might be related to a recent code deployment that introduced a performance regression, but then ran tests on the codebase and found out the WolframAlpha API was not responding. Took the issue to the backend team for further investigation.&lt;/li&gt;
&lt;li&gt;Misleading Investigation - Investigated recent code changes extensively, diverting attention from the actual cause (if it was, I would have completely roasted Folarin, cause he pushed the last code to deployment, lucky him 😐).&lt;/li&gt;
&lt;li&gt;Escalated -  The issue was escalated to the backend team.&lt;/li&gt;
&lt;li&gt;Resolution - Increased rate limit and paid for premium service of the WolframAlpha API. Also implemented  emergency scaling of server resources to handle the unexpected traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Root Cause and Resolution.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Root cause - The surge in number of external API calls and traffic was caused by a successful marketing campaign that brought in significantly more users than anticipated.&lt;/li&gt;
&lt;li&gt;Resolution - Upgraded the WolframAlpha external API service to a premium one. Reviewed and updated infrastructure capacity planning to accommodate sudden spikes in traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Corrective and Preventive Measures.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Enhanced monitoring to provide early warnings for external API failures.&lt;/li&gt;
&lt;li&gt;Conduct regular capacity planning exercises to anticipate and handle increased user loads.&lt;/li&gt;
&lt;li&gt;Tasks.&lt;/li&gt;
&lt;li&gt;Enhance communication strategies for informing users during service outages.&lt;/li&gt;
&lt;li&gt;Conduct a thorough review of the incident response process for better coordination.&lt;/li&gt;
&lt;li&gt;Implement the early warning alert system on DataDog.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>sre</category>
      <category>webdev</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What Happens When You Type 'www.google.com' and press Enter.</title>
      <dc:creator>Hameed Osilaja</dc:creator>
      <pubDate>Sun, 15 Oct 2023 19:52:59 +0000</pubDate>
      <link>https://dev.to/osilaja78/what-happens-when-you-type-wwwgooglecom-and-press-enter-4p</link>
      <guid>https://dev.to/osilaja78/what-happens-when-you-type-wwwgooglecom-and-press-enter-4p</guid>
      <description>&lt;p&gt;Have you ever wondered what happens behind the scene when you enter a URL like '&lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;' into your web browser and hit Enter?&lt;/p&gt;

&lt;p&gt;The process might appear as though it’s simple, but under the hood, so many complex operations take place to deliver the web page you requested. In this article, we’ll walk through the journey of a web request, explaining in detail each stage from the moment you press enter to the moment you see Google’s homepage.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bDGgET1l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyq1blj08lbmajpdu4ix.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bDGgET1l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyq1blj08lbmajpdu4ix.png" alt="Schema illustrating the flow of the request created when you type https://www.google.com in your browser and press Enter" width="800" height="452"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Schema illustrating the flow of the request created when you type &lt;a href="https://www.google.com"&gt;https://www.google.com&lt;/a&gt; in your browser and press Enter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here’s an overview of the things we’ll be discussing during the course of this article;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DNS Request.&lt;/li&gt;
&lt;li&gt;TCP/IP.&lt;/li&gt;
&lt;li&gt;Firewall.&lt;/li&gt;
&lt;li&gt;HTTPS/SSL.&lt;/li&gt;
&lt;li&gt;Load-balancer.&lt;/li&gt;
&lt;li&gt;Web server.&lt;/li&gt;
&lt;li&gt;Application server.&lt;/li&gt;
&lt;li&gt;Database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s take all these one after the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  DNS request.
&lt;/h2&gt;

&lt;p&gt;The moment you enter a website address in your web browser and hit Enter, your browser initiates a Domain Name System (DNS) request. The DNS server’s job is to translate human-readable URL such as '&lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;' into an IP address which is how computers identify websites on the internet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does this have to happen?
&lt;/h3&gt;

&lt;p&gt;Computers identify servers through IP addresses. An Internet Protocol (IP) address is the unique identifying number assigned to every device connected to the internet, they usually look something like this “192.168.123.132”. Imagine having to memorize numerical IP addresses of every single website you visit, a really challenging task given the vast number of websites available. So, that’s where DNS comes in, DNS simplifies the process, allowing you to use user-friendly domain names (which are easier to remember by the way), while it takes care of the translation behind the scenes. Now, let’s take a look at the behind the scenes process.&lt;/p&gt;

&lt;h3&gt;
  
  
  The DNS resolution process.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When you enter a URL like '&lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;' in your browser, and press enter, your device sends  a &lt;strong&gt;DNS query&lt;/strong&gt; to a local DNS &lt;strong&gt;resolver&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;resolver&lt;/strong&gt; checks its &lt;strong&gt;cache&lt;/strong&gt; to see if it has the IP address for '&lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;'.&lt;/li&gt;
&lt;li&gt;If not, it contacts the &lt;strong&gt;root server&lt;/strong&gt;. The root server does not have the specific IP address, but it directs the resolver to the &lt;strong&gt;authoritative name server&lt;/strong&gt; for .com &lt;strong&gt;TLD&lt;/strong&gt; (Top Level Domain).&lt;/li&gt;
&lt;li&gt;The .com TLD's authoritative name server in turn, guides the resolver to &lt;strong&gt;Google’s authoritative name server&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Google’s authoritative name server finally provides the IP address for '&lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;' to the resolver.&lt;/li&gt;
&lt;li&gt;The resolver then caches this information on your local system for future use. This way, it no longer has to go through this lengthy resolution process when next you want to visit '&lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;'. This also gravely increases speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  TCP/IP connection.
&lt;/h2&gt;

&lt;p&gt;After the DNS resolution process, the next crucial step in the journey of a web request is to establish a &lt;strong&gt;TCP/IP&lt;/strong&gt; (Transmission Control Protocol/Internet Protocol) connection. This step ensures that there is a &lt;strong&gt;reliable&lt;/strong&gt; and &lt;strong&gt;organized&lt;/strong&gt; exchange of data between your device and the web server. TCP/IP is the foundational protocol suite of the internet. It consists of two primary protocols;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Internet Protocol (IP)&lt;/strong&gt; - handles the routing and addressing of &lt;strong&gt;data packets&lt;/strong&gt;, ensuring they reach their intended destination.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transmission Control Protocol (TCP)&lt;/strong&gt; - manages the orderly and reliable transfer of data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What are Data Packets?
&lt;/h3&gt;

&lt;p&gt;In the digital world, data is divided into small units of information called packets, which can be transmitted over the internet. You can picture a packet as letters in the postal service, each one having addresses and content of the letter within the envelope, packets also contain &lt;strong&gt;data&lt;/strong&gt; (the data to be transferred) and &lt;strong&gt;metadata&lt;/strong&gt; (information such as source and destination IP address, port numbers and sequence numbers).&lt;/p&gt;

&lt;p&gt;The process of initiating a connection between your device (client) and the web server (server) involves a &lt;strong&gt;three-way handshake&lt;/strong&gt;;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SYN (Synchronize)&lt;/strong&gt; - the client sends a SYN packet to the server to request a connection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SYN-ACK (Synchronize Acknowledgement)&lt;/strong&gt; - the server acknowledges the request by sending a SYN-ACK packet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ACK (Acknowledgement)&lt;/strong&gt; - the client then sends back an ACK packet, confirming the connection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The above process is to ensure that both parties (i.e client and server) are ready to communicate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Firewall.
&lt;/h2&gt;

&lt;p&gt;After the TCP/IP connection, the next crucial layer of defense in the journey of your web request is the Firewall. A firewall acts as a &lt;strong&gt;digital gate keeper&lt;/strong&gt;, monitoring and controlling the flow of data packets to protect your device and network from potential threats. It examines data packets to determine whether they should be allowed or blocked based on predefined rules. These rules can include criteria such as source and destination IP addresses, port numbers, and the protocol being used (i.e TCP or UDP).&lt;/p&gt;

&lt;p&gt;Firewalls are also configured with &lt;strong&gt;security policies&lt;/strong&gt; which helps determine the level of access and permissions for different types of traffic. Common policies include allowing HTTP (port 80) and HTTPS (port 443) for web browsing, while blocking potentially harmful traffic.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTPS/SSL.
&lt;/h2&gt;

&lt;p&gt;Now, following the firewall’s role in securing your internet connection, another important layer of security is HTTPS (Hypertext Transfer Protocol Secure) and SSL (Secure Sockets Layer). These two technologies work alongside one another to protect the privacy and integrity of data exchanged between the client and the server. HTTPS is a secure version of HTTP which is used to transfer data between the client and the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why do we need HTTPS/SSL?
&lt;/h3&gt;

&lt;p&gt;The internet is a very wide and interconnected network where data travels across numerous routes. Some of these routes may not be entirely secure, making it very important to encrypt data so as to protect it from tampering or interception. HTTPS and SSL provides the encryption needed to transfer data over the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; SSL provides the encryption and secure connection used in HTTPS.&lt;/p&gt;

&lt;p&gt;To establish trust and verify the identity of a web server, HTTPS uses &lt;strong&gt;digital certificates&lt;/strong&gt; (SSL certificates). These digital certificates are issued by trusted Certificate Authorities (CAs). Examples of CAs include &lt;strong&gt;Comodo&lt;/strong&gt;, &lt;strong&gt;GeoTrust&lt;/strong&gt;, and &lt;strong&gt;Symantec&lt;/strong&gt;. So, when you visit an HTTPS-enabled website, your browser checks the digital certificate to ensure it is valid and signed by a trusted CA.&lt;/p&gt;

&lt;h2&gt;
  
  
  Load-balancer.
&lt;/h2&gt;

&lt;p&gt;Once a secure connection has been established between the client and the server through HTTPS/SSL, the next step in the journey of your web request is often managed by load-balancers. Although this part is not always in play because load-balancers are meant to improve performance, and enhance the reliability of web services, which might not be needed for a website with very little traffic. But for a big company like Google, it’s a very important aspect because as websites and web applications grow in popularity, they often experience a significant increase in traffic and this can strain a single web server's capacity and lead to performance issues or even downtime.&lt;/p&gt;

&lt;p&gt;Load balancers address these challenges by efficiently distributing incoming requests among multiple servers, preventing overloads, and improving responsiveness. Now, the client request is sent to the load balancer, which in turn directs this request to one of Google’s web servers for further processing of the request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web server.
&lt;/h2&gt;

&lt;p&gt;A web server is specialized software or hardware that listens for incoming HTTP or HTTPS requests from clients, such as web browsers. Web servers are a very essential component of the web infrastructure. They are responsible for receiving and responding to client requests, serving web pages, and processing dynamic content, etc.&lt;/p&gt;

&lt;p&gt;When a client's request arrives at the web server, the server identifies the requested resource, whether it's an HTML page, an image, a script, or any other web content.&lt;br&gt;
The web server retrieves the resource from its storage (if it's a static content) or generates it dynamically by executing scripts or querying databases (if it's a dynamic content). Then based on the request made, it sends whatever content requested back to the client (as a response) for display in the browser. All these sending of data back and forth (from client to server and back) occurs through either HTTP or HTTPS (since web servers can handle both unencrypted HTTP requests and secure, encrypted HTTPS requests).&lt;/p&gt;

&lt;h3&gt;
  
  
  There are various types of web server solutions, these two are the most popular.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Apache HTTP Server:&lt;/strong&gt; An open-source and widely used web server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nginx:&lt;/strong&gt; Known for its performance and scalability, often used as a reverse proxy server in combination with Apache.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Application server.
&lt;/h2&gt;

&lt;p&gt;Application servers are specialized software or frameworks that handle dynamic, data-driven web applications, providing the &lt;strong&gt;logic&lt;/strong&gt; and &lt;strong&gt;functionality&lt;/strong&gt; required to serve complex web services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Roles of an application server.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Application servers execute the business logic of web applications. This includes handling user authentication, managing sessions, processing form submissions, and enforcing security policies.&lt;/li&gt;
&lt;li&gt;They interact with web servers to process client requests, generate dynamic content, and communicate with databases and other resources.&lt;/li&gt;
&lt;li&gt;Application servers play a crucial role in the development and delivery of dynamic web applications. These applications generate content on-the-fly, responding to user interactions, database queries, and various forms of input.&lt;/li&gt;
&lt;li&gt;They also expose &lt;strong&gt;API endpoints&lt;/strong&gt; that allow external services, web applications, or mobile apps to interact with the system. These APIs are crucial for data exchange and integration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, basically, after the web server's role in delivering static and some dynamic content, the application server's role is to generate dynamic responses, process complex business logic, and deliver interactive and data-driven web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Databases.
&lt;/h2&gt;

&lt;p&gt;Databases are key foundational components of modern web applications, responsible for the secure storage, retrieval, and management of data. After the application server's role in presenting dynamic web applications, the journey of your web request takes an important step by interacting with a database. Databases are used to persistently &lt;strong&gt;store data&lt;/strong&gt;, such as user profiles, content, transaction records, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Most common types of databases.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Relational databases&lt;/strong&gt; (also known as SQL databases) - they use tables to organize data into rows and columns. They are excellent for structured data and transactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-relational databases&lt;/strong&gt; (also known as NoSQL databases) - are designed for unstructured or semi-structured data. They are often used for flexible data storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, after the application server processes dynamic content, databases store and manage the data required to drive web applications, making them essential for applications ranging from e-commerce websites to social media platforms and beyond.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion.
&lt;/h2&gt;

&lt;p&gt;The seemingly simple act of typing a URL and pressing Enter involves a beautiful and remarkable journey through various stages of internet technology. From DNS translation to security protocols, load balancing, and server-side processing, each step contributes to the seamless experience of accessing the web.&lt;/p&gt;

&lt;p&gt;Now that you understand this process, I hope you can now appreciate the complexity that goes into serving the web pages we use daily 🤗.&lt;/p&gt;

&lt;p&gt;Thanks for reading, cheers ✨🎉.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>networking</category>
      <category>devops</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>ChatGPT API is not free, here's an alternative.</title>
      <dc:creator>Hameed Osilaja</dc:creator>
      <pubDate>Mon, 04 Sep 2023 17:37:35 +0000</pubDate>
      <link>https://dev.to/osilaja78/chatgpt-api-is-not-free-heres-an-alternative-cgp</link>
      <guid>https://dev.to/osilaja78/chatgpt-api-is-not-free-heres-an-alternative-cgp</guid>
      <description>&lt;p&gt;If you have a natural curiosity, much like myself, you've probably always been eager to experiment with ChatGPT, I mean, to explore its capabilities by creating something with it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To get the API Key, developers need to log in to OpenAI’s website and select ‘View API Keys’. Although the API Key is not free, OpenAI provides a free credit of about $18 upon account creation. After the free credit expires, the cost is $0.002 per 1000 tokens. If the API Key is not working, it might be due to technical issues or the exhaustion of free tokens.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a developer interested in utilizing the ChatGPT API, you need to obtain an API key which is available on OpenAI’s website, but unfortunately, it comes at a price. In this article, we’ll be discussing a very simple alternative I use instead of investing in OpenAI's API.&lt;/p&gt;

&lt;p&gt;The OpenAI’s API was made available to developers on 1st of March 2023. At this time, they released a one month free trial to all API key holders where each user gets an $18.00 credit on their account which will be valid until 1st of April 2023. If you were able to benefit from the free trial, well congratulations to you, but I’m sure after the expiration date, your API key no longer works, and now you’re being asked to pay.&lt;/p&gt;

&lt;p&gt;Interestingly, you can generate an API key for free. However, when you attempt to use it, you'll encounter a &lt;code&gt;rate limit reached&lt;/code&gt; error, prompting you to purchase credits (a very clever selling strategy by OpenAI, lol 😁).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5AF1aH2o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dr1o6r1wrtro3jjh7wfk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5AF1aH2o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dr1o6r1wrtro3jjh7wfk.png" alt="OpenAI dashboard showing expired API credits" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s the way around this?
&lt;/h2&gt;

&lt;p&gt;While searching for a cost-effective alternative to OpenAI's API, I came across numerous open-source ChatGPT alternatives. However, one particular option that caught my attention is GPT4Free.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is GPT4Free?
&lt;/h2&gt;

&lt;p&gt;GPT4Free is a project developed by &lt;strong&gt;xtekky&lt;/strong&gt; on GitHub, that has integrated the structure of ChatGPT to create a revolutionary, user-friendly platform. I won’t take too much time giving details about the project,  you can check it out the GitHub repository &lt;a href="https://github.com/xtekky/gpt4free"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to use GPT4free.
&lt;/h3&gt;

&lt;p&gt;Now, let's delve into the coding part of this article. We'll write a basic Python script to illustrate how you can integrate GPT4Free into your upcoming project.&lt;/p&gt;

&lt;p&gt;There are two ways to this;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You can clone the GitHub repository, set up a virtual environment, and create your Python script. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Or you can simply install the official GPT4Free Python package.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, for the purposes of this tutorial, we will utilize the second option, so, lets go!&lt;/p&gt;

&lt;p&gt;First and foremost, let's create a virtual environment. I can't emphasize enough how crucial it is to establish a virtual environment for your Python projects. It aids in isolating your project's dependencies from your system's global dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# On macOS and Linux
&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt; &lt;span class="n"&gt;python3&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="n"&gt;venv&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;

&lt;span class="c1"&gt;# On windows
&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt; &lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="n"&gt;venv&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have our virtual environment setup, lets activate it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# On macOS and Linux
&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="n"&gt;venv&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nb"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;activate&lt;/span&gt;

&lt;span class="c1"&gt;# On windows
&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="n"&gt;venv&lt;/span&gt;\&lt;span class="n"&gt;Scripts&lt;/span&gt;\&lt;span class="n"&gt;activate&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, it’s time to install the gpt4free package &lt;code&gt;g4f&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install g4f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the package is done installing, create a new file, I'll name mine &lt;code&gt;gpt4free.py&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;g4f&lt;/span&gt;

&lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;userInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;User: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;g4f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ChatCompletion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;g4f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;gpt_4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;g4f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DeepAi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's break the code down.&lt;/p&gt;

&lt;p&gt;Firstly, we imported the &lt;code&gt;g4f&lt;/code&gt; package that we installed earlier. Then, we created a &lt;code&gt;messages&lt;/code&gt; list to hold the message, which will serve as a parameter for the &lt;code&gt;create&lt;/code&gt; function from &lt;code&gt;g4f&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, we established a &lt;code&gt;while&lt;/code&gt; loop. Although this step isn't strictly necessary, it only allows us to continue a chat with the chosen model.&lt;/p&gt;

&lt;p&gt;We then request &lt;code&gt;user input&lt;/code&gt;, which will serve as the prompt for the model. This input is added to the &lt;code&gt;messages&lt;/code&gt; list.&lt;/p&gt;

&lt;p&gt;Afterward, we invoke &lt;code&gt;g4f.ChatCompletion.create&lt;/code&gt; with three parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;model&lt;/code&gt;: this parameter specifies the model to be used for the chat. &lt;code&gt;g4f&lt;/code&gt; supports various models, and in this example, we selected the &lt;code&gt;gpt_4&lt;/code&gt; model. You can find other supported models on the official GitHub page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;provider&lt;/code&gt;: here, we specify the provider to be used for this chat. Multiple providers are available, including &lt;code&gt;OpenaiChat&lt;/code&gt;, &lt;code&gt;Bard&lt;/code&gt;, &lt;code&gt;Bing&lt;/code&gt;, and others. In this case, we've chosen &lt;code&gt;DeepAi&lt;/code&gt;. &lt;br&gt;
&lt;strong&gt;Note&lt;/strong&gt;: Not all providers may be operational, you can refer to the GitHub page for additional information.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;messages&lt;/code&gt;: this parameter takes our &lt;code&gt;messages&lt;/code&gt; list.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finally, we &lt;code&gt;print&lt;/code&gt; the response received.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s run our code.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# On macOS and Linux
&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt; &lt;span class="n"&gt;python3&lt;/span&gt; &lt;span class="n"&gt;gpt4free&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;

&lt;span class="c1"&gt;# On windows
&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt; &lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;gpt4free&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env) C:\Users\hameed\ai_test&amp;gt;python gpt4free.py

User: give me 5 tips to become a better developer

1. Continuous Learning: Technology is constantly evolving and as a developer, you should always be striving to learn new things. Take advantage of resources like online courses, tutorials, and other learning
materials to keep yourself up-to-date with the latest trends and best practices.

2. Write Clean and Efficient Code: Writing clean and efficient code is essential for becoming a good developer. This ensures that your code is easy to read, understand, modify, and maintain. Keep in mind the
SOLID principles and try to implement them in your code.

3. Collaborate with other Developers: Working with other developers on projects or open source repositories can provide valuable feedback, guidance, and help you learn from their experience. Consider joining
local developer groups or attending meetups to collaborate and learn from others in the industry.    

4. Adopt Best Practices: Adopting best practices for software development can improve the quality of your code and development process. Learn about software development methodologies, testing frameworks, and
version control to help ensure your code meets quality standards.

5. Experiment with New Technologies: Experimenting with new technologies and frameworks allows you to expand your knowledge and skill set as a developer. This helps you stay ahead of the curve and stay relevant in the ever-changing industry. Keep experimenting with new technologies and implementing interesting
concepts.


User: give me 3 more extra tips


Sure, here are three extra tips to become a better developer:

1. Practice regularly: Just like any skill, programming requires consistent practice to develop. Regular coding exercises and personal projects help you to learn new concepts and apply what you've learned in
practical settings.

2. Learn from others: Joining online communities, attending meetups and conferences, and collaborating with fellow developers will expose you to new ideas and perspectives. Learn from experienced developers and seek their feedback on your code.

3. Keep up with evolving technology: Technology is constantly evolving, and being able to stay up-to-date with new trends and tools is vital in the tech industry. Participate in online forums and subscribe to tech blogs and newsletters to stay informed about the latest developments in your field.

User: Traceback (most recent call last):
  File "C:\Users\USER\Desktop\CRAP\ai_test\test_g4f.py", line 7, in &amp;lt;module&amp;gt;
    userInput = input("\nUser: ")
KeyboardInterrupt
^C
(env) C:\Users\hameed\ai_test&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Wow, amazing isn't it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We first got a prompt asking us to enter an input (exactly what we asked the python script to do earlier), which I asked it to "give me 5 tips to become a better developer", then on clicking enter, our input was submitted to the &lt;code&gt;g4f&lt;/code&gt; chat completion model, then &lt;strong&gt;voila!!!&lt;/strong&gt;, we got our response printed out. I even went ahead to ask it to give me three more, and it did. Then finally exit the while loop using &lt;code&gt;CTRL + c&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion.
&lt;/h2&gt;

&lt;p&gt;Now that you have the power of using AI in any of your projects, feel free to explore more possibilities with the g4f package. Keep building amazing projects.&lt;/p&gt;

&lt;p&gt;Happy coding ✨.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>chatgpt</category>
      <category>programming</category>
    </item>
    <item>
      <title>Debugging Memory Leaks in C Using Valgrind.</title>
      <dc:creator>Hameed Osilaja</dc:creator>
      <pubDate>Wed, 31 May 2023 11:01:41 +0000</pubDate>
      <link>https://dev.to/osilaja78/debugging-memory-leaks-in-c-using-valgrind-ckd</link>
      <guid>https://dev.to/osilaja78/debugging-memory-leaks-in-c-using-valgrind-ckd</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Memory leaks can be one of the most frustrating and elusive bugs to track down in C programming. These leaks occur when allocated memory is not properly deallocated (or freed), leading to a loss of available memory over time. Fortunately, tools like &lt;code&gt;valgrind&lt;/code&gt; exist to help developers detect and debug memory leaks efficiently.&lt;/p&gt;

&lt;p&gt;Memory leaks are a common problem in C programs. They can cause a variety of problems, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Program crashes&lt;/li&gt;
&lt;li&gt;Slow performance&lt;/li&gt;
&lt;li&gt;Memory exhaustion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, we will explore how Valgrind can be used to identify and fix memory leaks in C programs.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Valgrind?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Valgrind&lt;/strong&gt; is an open-source dynamic analysis tool suite that is widely used for debugging and profiling. It provides a range of tools to detect memory leaks, invalid memory accesses, and other memory-related errors in C and C++ programs. It does this by running your program in a virtual environment, allowing it to monitor memory allocations and de-allocations, detect errors, and provide &lt;strong&gt;detailed reports on memory usage&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  How To Set-up Valgrind:
&lt;/h4&gt;

&lt;p&gt;Before diving in, you'll need to install valgrind on your system. Valgrind is available for most Linux distributions and can be installed using the package manager. For example, on Ubuntu, you can install Valgrind by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;valgrind
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once Valgrind is installed, you can run your C program with it by using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;valgrind &lt;span class="nt"&gt;--leak-check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;full ./your_program
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Valgrind will then run your program and report any memory leaks that it finds. The output will be displayed in the terminal.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example.
&lt;/h4&gt;

&lt;p&gt;Let's consider the following C program that contains a simple memory leak:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above program, we created a main function that allocates a memory of 4 bytes (size of an integer) using &lt;code&gt;malloc&lt;/code&gt;. Now let's compile this program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcc main.c &lt;span class="nt"&gt;-o&lt;/span&gt; test-valgrind
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; we explicitly set our output file to be &lt;code&gt;test-valgrind&lt;/code&gt;, you can name your output file whatever you like.&lt;/p&gt;

&lt;p&gt;Now, let's run our program using valgrind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;valgrind &lt;span class="nt"&gt;--leak-check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;full ./test-valgrind
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the program, here's the output that Valgrind produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==2896== Memcheck, a memory error detector
==2896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2896== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==2896== Command: ./my_program
==2896==
==2896== HEAP SUMMARY:
==2896==    in use at exit: 4 bytes in 1 blocks
==2896==   total heap usage: 1 allocs, 0 frees, 4 bytes allocated
==2896==
==2896== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==2896==   at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==2896==   by 0x40053E: main (in main.c:4)
==2896==
==2896== LEAK SUMMARY:
==2896==    definitely lost: 4 bytes in 1 blocks
==2896==    indirectly lost: 0 bytes in 0 blocks
==2896==    possibly lost: 0 bytes in 0 blocks
==2896==    still reachable: 4 bytes in 1 blocks
==2896==        suppressed: 0 bytes in 0 blocks
==2896== Rerun with --leak-check=full to see details of leaked memory
==2896==
==2896== For counts of detected and suppressed errors, rerun with: -v
==2896== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To fix memory leaks identified by Valgrind, carefully review the reported errors and follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify the specific lines of code where memory is allocated but not freed.&lt;/li&gt;
&lt;li&gt;Determine the appropriate location to free the allocated memory.&lt;/li&gt;
&lt;li&gt;Add the necessary &lt;code&gt;free()&lt;/code&gt; function calls to release the allocated memory.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;From the above output, we can see that we have lost 4 bytes of memory (equivalent to the size of an integer), Valgrind even went further, telling us where the memory leak is coming from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==2896== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==2896==   at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==2896==   by 0x40053E: main (in main.c:4)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it says the memory was allocated by &lt;code&gt;malloc&lt;/code&gt; in our &lt;code&gt;main.c&lt;/code&gt; file. Now that we've identified the source of the memory leak, it time to go ahead and fix it. We can fix the memory leak by adding &lt;code&gt;free(ptr)&lt;/code&gt; before the &lt;code&gt;return&lt;/code&gt; statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By analyzing the Valgrind report and applying the necessary fixes, you can eliminate memory leaks in your C programs and ensure optimal memory management.&lt;/p&gt;

&lt;h4&gt;
  
  
  More useful Valgrind arguments.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;--leak-check=full:  option to get more detailed information about the leaks that Valgrind finds.&lt;/li&gt;
&lt;li&gt;--show-leak-kinds=all: Show all leak kinds including definite, indirect, possible, and reachable in the full report.&lt;/li&gt;
&lt;li&gt;--track-origins=yes: option to track the origin of the memory that is being leaked. This can help you to find the code that is causing the leak.&lt;/li&gt;
&lt;li&gt;--verbose: option to show unusual behavior of your program.&lt;/li&gt;
&lt;li&gt;--log-file: option to write to a file (useful when output exceeds terminal space)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Valgrind is a powerful tool that can be used to debug memory leaks in C programs. It is easy to use and can help you to find and fix memory leaks quickly and easily. By following the tips in this article, you can use Valgrind to improve the quality of your C programs.&lt;/p&gt;

</description>
      <category>c</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Sending Automated Emails With Gmail Using Python.</title>
      <dc:creator>Hameed Osilaja</dc:creator>
      <pubDate>Sun, 21 May 2023 13:45:02 +0000</pubDate>
      <link>https://dev.to/osilaja78/sending-automated-emails-with-gmail-using-python-54hf</link>
      <guid>https://dev.to/osilaja78/sending-automated-emails-with-gmail-using-python-54hf</guid>
      <description>&lt;h2&gt;
  
  
  INTRODUCTION.
&lt;/h2&gt;

&lt;p&gt;In today's digital age, automated emails have become an essential part of many business and personal communication workflows. Whether it's sending notifications, updates, or personalized messages, automating the email-sending process can save a whole lot of time and effort. In this article, we will explore how to send automated emails with Gmail using Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  REQUIREMENTS.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A Gmail account.&lt;/li&gt;
&lt;li&gt;Python Installation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python provides powerful libraries and modules that make it relatively easy to automate email sending. We will be using the &lt;code&gt;smtplib&lt;/code&gt; and &lt;code&gt;email&lt;/code&gt; module. &lt;code&gt;smtplib&lt;/code&gt; is a built-in library in Python, along with the Gmail SMTP server to send emails. Python's &lt;code&gt;email&lt;/code&gt; module is a powerful library that provides functionalities to create, manipulate, and send email messages. It allows you to construct email messages with various components such as headers, subject, body, attachments and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONTENT.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Setting Up Gmail.
&lt;/h3&gt;

&lt;p&gt;Before we dive into the coding part, there are a few prerequisites and setup steps you need to follow to enable automated email sending through Gmail.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enable 2-Step Verification (just a security measure).&lt;/li&gt;
&lt;li&gt;Generate an App Password.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Enable 2-Step Verification.
&lt;/h4&gt;

&lt;p&gt;To ensure your Google account is safe, you need to enable 2-Step Verification. Go to your Google Account settings, navigate to the Security section, enable the "2-Step Verification" option.&lt;/p&gt;

&lt;h4&gt;
  
  
  Generate an App Password.
&lt;/h4&gt;

&lt;p&gt;This part is the most important. To enhance security, Google requires an app-specific password for programs like Python to access your Gmail account. To generate an app password;&lt;/p&gt;

&lt;p&gt;Go to your Google Account settings and navigate to the Security section, select “2-Step Verification” and scroll to the bottom, then select “App Passwords”.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A61HFZnY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5zcmdn6rrr2fv93lvl7a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A61HFZnY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5zcmdn6rrr2fv93lvl7a.png" alt="Navigate to Security section in Google account settings" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select “Other (custom name)” and give it any name of your choice, then click “Generate”.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nHVD3nFf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0ca7i3rae52lcaxll0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nHVD3nFf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0ca7i3rae52lcaxll0n.png" alt="Generate app password" width="665" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yay!!!, you’ve successfully generated your app password. Be sure to copy the generated password and save it somewhere safe because once you close the interface, you won’t be able to see the password anymore.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t4pg3m9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xzbbkf959y2uy3q1r3t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t4pg3m9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xzbbkf959y2uy3q1r3t.png" alt="Copy and save the generated password" width="702" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have the necessary setup in place, let's proceed to the coding part.&lt;/p&gt;
&lt;h3&gt;
  
  
  Writing the Python Code.
&lt;/h3&gt;

&lt;p&gt;To send automated emails using Python, you need to import the &lt;code&gt;smtplib&lt;/code&gt; and &lt;code&gt;email&lt;/code&gt; module, and configure it with your Gmail account credentials and the SMTP server settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from email.message import EmailMessage
import ssl, smtplib

def automated_email():

    email_sender = 'youremail@gmail.com'
    email_password = 'your-generated-password-here'
    email_reciever = 'reciever-email-here'

    subject = 'Your Email Subject'
    body = """
        This will contain the contents of your email.   
        This will contain the contents of your email.   
        This will contain the contents of your email.   
    """

    # Create an instance of EmailMessage
    em = EmailMessage()
    em['From'] = email_sender
    em['To'] = email_reciever
    em['Subject'] = subject
    em.set_content(body)

    # Create a secure SSL context
    context = ssl.create_default_context()

    # Connect to the SMTP server and send the email
    with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
        # Login to the email sender's account
        smtp.login(email_sender, email_password)
        # Send the email
        smtp.sendmail(email_sender, email_reciever, em.as_string())

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The email sender's address, password, and the recipient's email address are set in the &lt;code&gt;email_sender&lt;/code&gt;, &lt;code&gt;email_password&lt;/code&gt;, and &lt;code&gt;email_reciever&lt;/code&gt; variables, respectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Make sure to replace the placeholder values with your valid Gmail account information, including the email sender's address, password, and recipient's email address. Keep your email credentials secure and consider using environment variables to store sensitive information.&lt;/p&gt;

&lt;p&gt;If you would like to format the email content with HTML tags, this is an updated version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from email.message import EmailMessage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import ssl, smtplib

def send_mail():

    email_sender = 'youremail@gmail.com'
    email_password = 'your-generated-password-here'
    email_reciever = 'reciever-email-here'

    subject = 'Your Email Subject.'

        content = """
                &amp;lt;html&amp;gt;
                    &amp;lt;body&amp;gt;
                           &amp;lt;b&amp;gt;Hi&amp;lt;/b&amp;gt;&amp;lt;/br&amp;gt;
                           &amp;lt;p&amp;gt;This email is html formatted.&amp;lt;/p&amp;gt;
                    &amp;lt;/body&amp;gt;
                &amp;lt;/html&amp;gt;
                """

    # Create an instance of MIMEMultipart for composing the email
    em = MIMEMultipart()
    em['From'] = email_sender
    em['To'] = email_reciever
    em['Subject'] = subject

    # Attach the content as HTML to the email
    em.attach(MIMEText(content, "html"))

    # Create a secure SSL context
    context = ssl.create_default_context()

    # Connect to the SMTP server and send the email
    with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
        # Login to the email sender's account
        smtp.login(email_sender, email_password)
        # Send the email
        smtp.sendmail(email_sender, email_reciever, em.as_string())

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, an instance of &lt;code&gt;MIMEMultipart&lt;/code&gt; is created to compose the email. The email's sender, recipient, and subject are set using the corresponding headers in the &lt;code&gt;MIMEMultipart&lt;/code&gt; object. The content of the email, passed as the content argument, is attached to the email as HTML using &lt;code&gt;MIMEText&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The above codes provide a basic example of sending automated emails with Gmail using Python. However, you can enhance and customize the functionality based on your requirements. Here are a few ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Adding Attachments:&lt;/strong&gt; You can use the &lt;code&gt;email&lt;/code&gt; module in Python to create more complex email messages with attachments. This allows you to send files along with your automated emails.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Email Templates:&lt;/strong&gt; Instead of composing the email content within the code, you can utilize email templates to separate the content from the code. Libraries like &lt;code&gt;Jinja2&lt;/code&gt; can help you create and render email templates with dynamic data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling:&lt;/strong&gt; Implement robust error handling to handle exceptions and provide informative messages in case of any issues during the email sending process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduled Emails:&lt;/strong&gt; Use Python's &lt;code&gt;datetime&lt;/code&gt; module and scheduling libraries like schedule or &lt;code&gt;APScheduler&lt;/code&gt; to send automated emails at specific times or intervals.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Automating email sending using Python and Gmail can greatly streamline your communication processes. Whether it's sending notifications, updates, or personalized messages, the &lt;code&gt;smtplib&lt;/code&gt; module in Python makes it easy to connect to the Gmail SMTP server and send automated emails. Remember to ensure the security of your Gmail account by enabling less secure app access and generating an app password. With the power of Python and Gmail, you can save time and effort while effectively reaching your recipients.&lt;/p&gt;

</description>
      <category>python</category>
      <category>automation</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Deploy a FastAPI App on Deta Space</title>
      <dc:creator>Hameed Osilaja</dc:creator>
      <pubDate>Sat, 01 Apr 2023 09:34:48 +0000</pubDate>
      <link>https://dev.to/osilaja78/how-to-deploy-a-fastapi-app-on-deta-space-45ma</link>
      <guid>https://dev.to/osilaja78/how-to-deploy-a-fastapi-app-on-deta-space-45ma</guid>
      <description>&lt;h2&gt;
  
  
  Introduction.
&lt;/h2&gt;

&lt;p&gt;According to the documentation &lt;a href="https://fastapi.tiangolo.com/"&gt;here&lt;/a&gt;,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;FastAPI&lt;/strong&gt; is an easy to learn Python framework which I love best for building my APIs. If you would like to learn more about it, you can visit the documentation. In this article, we’re concerned with how to deploy your FastAPI app on &lt;a href="https://deta.space/"&gt;Deta Space&lt;/a&gt; so it can be available for use to anyone around the world.&lt;/p&gt;

&lt;p&gt;A little about Deta. Deta is a company that offers various services including cloud, Deta Base (Instantly usable database with a feature-rich API.), python and Node.js deployment, all for free.&lt;/p&gt;

&lt;p&gt;If you’re familiar with DETA, you would know that they used to be deta.sh (deprecated), but after more than 2 years, they decided to make an upgrade to DETA CLOUD (which is even way cooler) to give developers a free and easy way to get their ideas live on the internet.&lt;/p&gt;

&lt;p&gt;I remember then, I used to deploy my fastAPI app on DETA MICRO (deprecated), but since it’s now deprecated, in this article, you’ll learn with how to deploy your FastAPI app on DETA SPACE so it can be available for use to anyone around the world.&lt;/p&gt;

&lt;p&gt;But first things first, let’s create a simple FastAPI app for demonstration purposes.&lt;/p&gt;

&lt;h2&gt;
  
  
  REQUIREMENTS.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python.&lt;/li&gt;
&lt;li&gt;Deta Space account (remember, it’s totally free. You can create one here).
NOTE: if you have a deta.sh account before, you can still use that to login to Deta Space.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CREATE A SIMPLE APP.
&lt;/h2&gt;

&lt;p&gt;Let’s create a simple FastAPI app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a directory.
&lt;/h3&gt;

&lt;p&gt;Open a new terminal window and create a directory for your app, I’ll name mine &lt;code&gt;fastapi-tutorial&lt;/code&gt;, then &lt;code&gt;cd&lt;/code&gt; into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir fastapi-tutorial
$ cd fastapi-tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a virtual environment.
&lt;/h3&gt;

&lt;p&gt;This step is optional, but it makes sense. The importance of creating a virtual environment is to isolate your project dependencies from your global dependencies on your PC. For windows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python -m venv my-env
$ my-env\Scripts\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or on a mac PC.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python3 -m venv my-env
$ Source my-env\bin\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install FastApi.
&lt;/h3&gt;

&lt;p&gt;Now, you’ll need to install &lt;code&gt;fastapi&lt;/code&gt; and &lt;code&gt;uvicorn&lt;/code&gt;. Uvicorn is an ASGI server, for production.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(my-env) $ pip install fastapi
(my-env) $ pip install "uvicorn[standard]"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a simple route.
&lt;/h3&gt;

&lt;p&gt;Create a file &lt;code&gt;main.py&lt;/code&gt; and add the following code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"message": "Deploying FastApi to Deta Space"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a requirements.txt file.
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;requirements.txt&lt;/code&gt; file, this will contain all your dependencies so Deta will know which dependency to install for your app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(my-env) $ pip freeze &amp;gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the file, it should look something like this;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fastapi==0.89.1
uvicorn==0.20.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run the app.
&lt;/h3&gt;

&lt;p&gt;Now, run the app to be sure everything works fine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(my-env) $ uvicorn main:app --reload

INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [28720]
INFO:     Started server process [28722]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can visit &lt;a href="http://127.0.0.1:8000"&gt;http://127.0.0.1:8000&lt;/a&gt; to see your app.&lt;/p&gt;

&lt;p&gt;Yay 🎉, you’ve successfully created your app. Now let’s deploy.&lt;/p&gt;

&lt;h2&gt;
  
  
  DEPLOYMENT STEPS.
&lt;/h2&gt;

&lt;p&gt;Now that you’ve successfully created your app, let’s get to deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Deta Space CLI.
&lt;/h3&gt;

&lt;p&gt;To install the Space CLI on windows, open powershell and paste this command;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iwr https://get.deta.dev/space-cli.ps1 -useb | iex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for a Mac PC;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -fsSL https://get.deta.dev/space-cli.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Login to Deta Space.
&lt;/h3&gt;

&lt;p&gt;Once you’ve successfully installed the CLI, the next thing is to login to Deta Space. Back to your project terminal window, paste the following command;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ space login
? Enter access token &amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will ask for an “access token” to authenticate your CLI. Generate the token in the next step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate an access token.
&lt;/h3&gt;

&lt;p&gt;To generate an access token, login to your space dashboard (on the web), click on the search (command) bar, then click “Settings”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ajZVxcQ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rmyo7s5y9ueowjyqbw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ajZVxcQ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rmyo7s5y9ueowjyqbw9.png" alt="Click settings" width="437" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click “Generate token”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k4-1tsR---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/852xg6tx7jy5ybvp5i9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k4-1tsR---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/852xg6tx7jy5ybvp5i9k.png" alt="Generate access token" width="441" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll get a new token, copy it and save it somewhere safe, because you won't be able to view the token again. Paste the token in the CLI prompt, then click enter. You should see a success message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;👍 Login Successful!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a new Space project.
&lt;/h3&gt;

&lt;p&gt;Type the following command to create a new Space project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ space new
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be prompted to enter a name for your project. Next, the CLI will try to detect any existing applications in your directoriy. If found, the CLI will show a generated config for those applications.&lt;/p&gt;

&lt;p&gt;Once you confirm the generated config, the CLI will create a new project in Builder and generate a &lt;code&gt;Spacefile&lt;/code&gt; file in your local directory, which contains the configuration of your app, used by Deta Space to understand what your app looks like and how to run it. The whole process should look something like this;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PtqJYxk5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/thna6zfn51o5xj6qpyy1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PtqJYxk5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/thna6zfn51o5xj6qpyy1.png" alt="New space project steps" width="582" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Push your app to space.
&lt;/h3&gt;

&lt;p&gt;To do this run this command;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ space push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will validate your &lt;code&gt;Spacefile&lt;/code&gt;, then upload all the necessary files to Deta’s build pipeline.&lt;/p&gt;

&lt;p&gt;If for some reason you,re getting an error &lt;code&gt;! Failed to push code and create a revision. Please try again!&lt;/code&gt;, open your &lt;code&gt;Spacefile&lt;/code&gt; (usually at the root directory of your project), it should look like this;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Spacefile Docs: https://go.deta.dev/docs/spacefile/v0
v: 0
micros:
  - name: FastAPI
    src: .
    engine: python3.9
    primary: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure the &lt;code&gt;src&lt;/code&gt; is pointing to the directory where you have your &lt;code&gt;main.py&lt;/code&gt; and &lt;code&gt;requirements.txt&lt;/code&gt; files, then run the command again. You should get a success message&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✓ Successfully started your build!
✓ Successfully pushed your Spacefile!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations 🤩, you’ve successfully deployed your project. To see your new project live, go to your space dashboard, you’ll find the new app you created there, click on the app, and it’ll take you to the live app, where you can copy the link and share to others.&lt;/p&gt;

&lt;p&gt;Happy coding 😁!&lt;/p&gt;

</description>
      <category>python</category>
      <category>fastapi</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
