<?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: Victor Joseph</title>
    <description>The latest articles on DEV Community by Victor Joseph (@captainvee).</description>
    <link>https://dev.to/captainvee</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%2F930300%2F3f5af9c6-4219-4ac5-806c-7e6cf2b5cf2e.jpeg</url>
      <title>DEV Community: Victor Joseph</title>
      <link>https://dev.to/captainvee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/captainvee"/>
    <language>en</language>
    <item>
      <title>How to deploy a Django app on an AWS EC2 instance</title>
      <dc:creator>Victor Joseph</dc:creator>
      <pubDate>Fri, 21 Apr 2023 09:47:04 +0000</pubDate>
      <link>https://dev.to/captainvee/how-to-deploy-a-django-app-on-an-aws-ec2-instance-2hnk</link>
      <guid>https://dev.to/captainvee/how-to-deploy-a-django-app-on-an-aws-ec2-instance-2hnk</guid>
      <description>&lt;p&gt;Today I'll be writing on how to deploy a Django app on an AWS EC2 instance. Ofcourse there are many ways to deploy a Django app to AWS so therefore we will be looking at one of the ways to do that.&lt;/p&gt;

&lt;p&gt;The first thing you need to do is to log in to your AWS account and search for EC2. Click on it and it would take you to your EC2 dashboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create security group
&lt;/h2&gt;

&lt;p&gt;Next thing you need to do is to create a security group. &lt;br&gt;
A security group is a virtual firewall that controls the inbound and outbound network traffic for one or more instances. It acts as a filter for the traffic that can reach the instances and specifies the types of traffic, such as HTTP, HTTPS, SSH, etc., that are allowed to access the instances.&lt;br&gt;
To create a security group, on your EC2 dashboard under the resources section, click on security group&lt;/p&gt;

&lt;p&gt;At the top right corner, click the "create security group" button and then give your security group a name and description. Scroll down and add your inbound rules as shown in the picture&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KWAmYnwm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j2ppkin6w4hxsqrc1zzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KWAmYnwm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j2ppkin6w4hxsqrc1zzw.png" alt="image of security groups to add to EC2 instance" width="800" height="417"&gt;&lt;/a&gt;&lt;br&gt;
Once you've added that you can scroll down and create the security group. Do well to keep in mind the name of your just created security group we'll be needing it shortly&lt;/p&gt;
&lt;h2&gt;
  
  
  Create EC2 Instance
&lt;/h2&gt;

&lt;p&gt;Now we have gotten that out of the way, it's now time to create our first EC2 instance. Head back to your EC2 dashboard and click on &lt;em&gt;instances (running)&lt;/em&gt; and then click on &lt;em&gt;launch instance&lt;/em&gt; at the top right corner. Give your instance a name and then select Ubuntu as your Application and OS Images (Amazon Machine Image). Make sure it's the free tier eligible one you selected. scroll down and double check that your instance type (either t2 or t3) is also a free tier eligible one. For the sake of simplicity of this tutorial, well leave out creating a key pair so just ignore that section and scroll down.&lt;br&gt;
Now under &lt;strong&gt;Network settings&lt;/strong&gt;, click on &lt;em&gt;Select existing security group&lt;/em&gt; and then select the security group you created earlier from the first section of this post (hope you still remember the name?) from the drop down. Leave every other setting in default and click on &lt;em&gt;launch instance&lt;/em&gt; at the bottom right. If you did every thing right, your instance should be up and running in a few seconds.&lt;/p&gt;
&lt;h2&gt;
  
  
  Connect to your instance
&lt;/h2&gt;

&lt;p&gt;Back on your EC2 dashboard, click on &lt;em&gt;instances&lt;/em&gt; and you should see your just created instance, ensure that the status of your instance is &lt;em&gt;running&lt;/em&gt; before you proceed to the next steps. Now to connect to your instance, select the instance you want to connect to and the click on &lt;em&gt;connect&lt;/em&gt;. Click on the connect button again and you should be redirected to a new tab that has connected to your instance.&lt;/p&gt;
&lt;h2&gt;
  
  
  Now the main work 😅
&lt;/h2&gt;

&lt;p&gt;Now that we have connected to our EC2 instance, we can now start the dirty work. First we have to install some packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install python3-venv python3-dev libpq-dev postgresql postgresql-contrib nginx curl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will install a necessary packages you need to create virtual environments for your Python projects, build Gunicorn, create a Postgres database system and the libraries needed to interact with it, and the Nginx web server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the PostgreSQL Database and User
&lt;/h2&gt;

&lt;p&gt;Next we have to create a PostgreSQL database for our django application. If you are fine using the default sqlite database, feel free to skip this section&lt;/p&gt;

&lt;p&gt;Log into an interactive Postgres session by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo -u postgres psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a database for your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE djangodb;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you have to create a database user for your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE USER djangouser WITH PASSWORD 'put_a_secure_password';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Django needs the following parameters for its database connections so let's add them&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER ROLE djangouser SET client_encoding TO 'utf8';
ALTER ROLE djangouser SET default_transaction_isolation TO 'read committed';
ALTER ROLE djangouser SET timezone TO 'UTC';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, give the new user access to control the new database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GRANT ALL PRIVILEGES ON DATABASE djangodb TO djangouser;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a Python Virtual Environment for your Project
&lt;/h2&gt;

&lt;p&gt;Up next to create a virtual environment and install the Python requirements within the virtual environment for easier management.&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 venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next you activate the virtual environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up Your django project.
&lt;/h2&gt;

&lt;p&gt;After that the virtual environment has been activated, the next thing is to clone the github repository you want to deploy. You can do that using the following commands below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/sampleusername/myproj.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is to install some necessary packages in other to run a basic django app.&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 django gunicorn psycopg2-binary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also install other libraries and packages in your requirements.txt file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd myproj/
pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure the Project Settings
&lt;/h2&gt;

&lt;p&gt;You should make sure that you have setup your database variables in your &lt;code&gt;settings.py&lt;/code&gt; for the database connection to the postgres database you created earlier. And example configuration is shown below. Open the settings file in a text editor. You can do that using nano&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano myproj/myproj/settings.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you look for the database connection and make the necessary changes using your own details&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'djangodb',
        'USER': 'djangouser',
        'PASSWORD': 'put_a_secure_password',
        'HOST': 'localhost',
        'PORT': '',
    }
}

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

&lt;/div&gt;



&lt;p&gt;You should also set your allowed hosts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALLOWED_HOSTS = ['Your_Public_IPv4 address', 'domain_name', . . ., 'localhost']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are using a custom domain name, after you have added the domain name to your allowed host, you would also need to add a host record. You can use the sample picture below to guide you on how to set it up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GY9KaI5X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34jsqtvw2stf0k2ye6tp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GY9KaI5X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34jsqtvw2stf0k2ye6tp.png" alt="picture of adding your host records to namecheap" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can also use also decide to use Route 53 and set up an elastic IP address if you wish. It is actually the recommended way to setup your custom domain name. you can check out this &lt;a href="https://techgenix.com/namecheap-aws-ec2-linux/"&gt;tutorial&lt;/a&gt; on how to do that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Migrate your django migrations
&lt;/h2&gt;

&lt;p&gt;Now, you can migrate the initial database schema to our PostgreSQL database using the management script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Set up Supervisor
&lt;/h2&gt;

&lt;p&gt;The next thing we would want to do is to install supervisor. Now supervisor is there to ensure that our application keeps on running smoothly in the background.&lt;br&gt;
First let's install it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install supervisor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we need to configure a Gunicorn process to ensure that our server (Gunicorn) starts automatically with the system and that it can automatically restart if for some reason it exits unexpectedly. To do that, we need to change directory to where the configuration files should be placed. You can do that by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/supervisor/conf.d 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create a &lt;code&gt;guincorn.conf&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano gunicorn.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;paste 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;[program:gunicorn]
directory=/home/ubuntu/myproj
command=/home/ubuntu/venv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/myproj/app.sock myproj.wsgi:application 
autostart=true
autorestart=true
stderr_logfile=/var/log/gunicorn/gunicorn.err.log
stdout_logfile=/var/log/gunicorn/gunicorn.out.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Make sure to change all instances of myproj to your actuall project name&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;save and close the file once you're done. You can do so by pressing &lt;code&gt;ctrl o&lt;/code&gt; then press enter. To close the file press &lt;code&gt;ctrl x&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once we have done that, we'll need to create the log file directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir /var/log/gunicorn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally we then need to notify the supervisor of the changes we just made using &lt;code&gt;supervisorctl&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;sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start all
sudo supervisorctl status all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Make sure that when you check for your status it shows &lt;code&gt;running&lt;/code&gt;. It it's not, you'll need to debug your code for errors. You can check for errors in your log file in &lt;code&gt;/var/log/gunicorn&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Below are some useful commands you can use to debug your code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# to check the status of our processes
sudo supervisorctl status &amp;lt;program_name&amp;gt;

# example
sudo supervisorctl status gunicorn
my_proj                          RUNNING   pid 1412, uptime 7:59:29

# to check status of all running process 
sudo supervisorctl status all


# to start, stop, restart all or some of the processes
sudo supervisorctl start &amp;lt;program_name|all&amp;gt;
sudo supervisorctl restart &amp;lt;program_name|all&amp;gt;
sudo supervisorctl stop &amp;lt;program_name|all&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup Nginx
&lt;/h2&gt;

&lt;p&gt;First of we need to make some changes to the nginx conf file in other to avoid permission denied errors. To that change directory to where the file is stored&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/nginx

#then open the conf file
sudo nano nginx.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the file is opened, change the &lt;code&gt;www-data&lt;/code&gt; in the first line of the file to &lt;code&gt;root&lt;/code&gt;. Close and save.&lt;/p&gt;

&lt;p&gt;With that out of the way we can now go ahead to create a configuration file for our django application in the &lt;code&gt;sites-available&lt;/code&gt; directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/nginx/sites-available/django.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then paste the settings below&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;replace appropriately with your aws public ip address and custom domain name if you have and change all instances of my proj to your actual project name&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server{
    listen 80;
    server_name your_public_ip your_custom_domain;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ubuntu/myproj;
    }
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/myproj/app.sock;

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

&lt;/div&gt;



&lt;p&gt;Let's do some explanations &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The first &lt;code&gt;location&lt;/code&gt; tells Nginx to ignore any problems with finding a favicon. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second &lt;code&gt;location&lt;/code&gt; tells where to find the static assets that you collected in your &lt;code&gt;/myproj/static&lt;/code&gt; directory. All of these files have a standard URI prefix of &lt;code&gt;/static&lt;/code&gt;, so you can create a location block to match those requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The third finally creates a location / {} block to match all other requests. Inside of this location, includes the standard proxy_params file included with the Nginx installation which then passes the traffic directly to the Gunicorn socket&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can close the file and save it.&lt;br&gt;
Next you need to test our Nginx configuration for syntax errors&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nginx -t
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, you need to enable the file by linking it to the sites-enabled directory. To do that,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And last but not the least you can go ahead to restart your nginx server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now open your website by visiting your public ip address or using your custom domain link and your site should be live&lt;/p&gt;

&lt;h2&gt;
  
  
  Securing connections with HTTPS
&lt;/h2&gt;

&lt;p&gt;start by installing certbot&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install python-certbot-nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;next you need to obtain an SSL Certificate&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot --nginx -d myawesomedomain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will then be prompted to provide an email, then press [ENTER]&lt;br&gt;
Next you will need to accept the terms of service.&lt;br&gt;
Next you will need to decide if you want to opt into some digital marketing.&lt;/p&gt;

&lt;p&gt;Let’s Encrypt’s certificates are only valid for ninety days, this is meant to force users to automate renewal of the certificates. Luckily certbot takes care of this for us. However we still need to verify this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot renew --dry-run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading.&lt;/p&gt;

</description>
      <category>django</category>
      <category>aws</category>
      <category>namecheap</category>
      <category>nginx</category>
    </item>
    <item>
      <title>Palindrome Number</title>
      <dc:creator>Victor Joseph</dc:creator>
      <pubDate>Fri, 23 Sep 2022 09:56:01 +0000</pubDate>
      <link>https://dev.to/captainvee/palindrome-number-360g</link>
      <guid>https://dev.to/captainvee/palindrome-number-360g</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution:
    def isPalindrome(self, x: int) -&amp;gt; bool:
        x_copy = x
        array_x = []
        inversed_x = 0

        while x &amp;gt; 0:
            array_x.append(x % 10)
            x = x // 10

        for num in array_x:
            inversed_x *= 10
            inversed_x += num

        if inversed_x == x_copy:
            return True
        return False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Day 3 of 10. Leet code problem can be found &lt;a href="https://leetcode.com/problems/palindrome-number/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To solve this problem, i had to reverse the given number by applying the divide (/) and mod (%) operations on it which is then stored in a list (array_x). Now because it is in a list, it cannot be compared with the initial array (x). So i had to convert it to an integer back and then compare the reversed number with original number to see if it is a palindrome. If both original and reversed numbers are equal, then the given number is a palindrome, otherwise it is not a palindrome.&lt;/p&gt;

&lt;p&gt;thanks for reading :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Remove Element</title>
      <dc:creator>Victor Joseph</dc:creator>
      <pubDate>Thu, 22 Sep 2022 09:29:37 +0000</pubDate>
      <link>https://dev.to/captainvee/remove-element-ncj</link>
      <guid>https://dev.to/captainvee/remove-element-ncj</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution:
    def removeElement(self, nums: List[int], val: int) -&amp;gt; int:
        while val in nums:
            nums.remove(val)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Day 2 of 10. Leet code problem can be found &lt;a href="https://leetcode.com/problems/remove-element/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I looped through the entire array while checking if the val is in the array. if it is found, i remove that particular value.&lt;/p&gt;

&lt;p&gt;tada :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Remove Duplicates from Sorted Array</title>
      <dc:creator>Victor Joseph</dc:creator>
      <pubDate>Wed, 21 Sep 2022 20:31:33 +0000</pubDate>
      <link>https://dev.to/captainvee/remove-duplicates-from-sorted-array-1dbd</link>
      <guid>https://dev.to/captainvee/remove-duplicates-from-sorted-array-1dbd</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution:
    def removeDuplicates(self, nums: List[int]) -&amp;gt; int:
        a = 0
        for i in range(len(nums)):
            if nums.count(nums[a])&amp;gt;1:
                del nums[a]
            else:
                a+=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So i solved this leetcode problem which can be found &lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-array/"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;My thought process was simple. I initialized a counter variable (called 'a') that would index the entire array (starting from zero) then i looped through the array while counting each variable. I then check if the count of the variable is greater than 1. If yes, then i delete that particular variable and if no, then i increment the counter variable to move to the next index.&lt;br&gt;
At the end of the day, what is left are numbers whose count are equal to 1.&lt;/p&gt;

&lt;p&gt;Hope you enjoyed reading, bye :)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
