<?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>Forem: Mehran Kader</title>
    <description>The latest articles on Forem by Mehran Kader (@kmehran1106).</description>
    <link>https://forem.com/kmehran1106</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%2F47988%2F6c884e96-bf19-498b-be1d-0c7d8bdc2067.jpg</url>
      <title>Forem: Mehran Kader</title>
      <link>https://forem.com/kmehran1106</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kmehran1106"/>
    <language>en</language>
    <item>
      <title>A simple guide to use PostgreSQL</title>
      <dc:creator>Mehran Kader</dc:creator>
      <pubDate>Wed, 29 Jul 2020 17:53:41 +0000</pubDate>
      <link>https://forem.com/kmehran1106/a-simple-guide-to-use-postgresql-206c</link>
      <guid>https://forem.com/kmehran1106/a-simple-guide-to-use-postgresql-206c</guid>
      <description>&lt;p&gt;I’ve been working with PostgreSQL for the last year, and the experience has honestly been amazing. However, every time I wanted to setup PostgreSQL on a machine, it was like trying to move through a labyrinth of blogs, documentations etc. I actually started using docker to run PostgreSQL in my mac, just to avoid the whole ordeal of navigating through psql and the Postgres command shell utilities.&lt;/p&gt;

&lt;p&gt;Now, if you want to use docker for this, it’s as simple as the running 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;docker run --name &amp;lt;container-name&amp;gt; \
-e POSTGRES_PASSWORD=&amp;lt;password&amp;gt; \ 
-e POSTGRES_USER=&amp;lt;username&amp;gt; \
-d &amp;lt;database name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, sometimes installing docker just for a simple project might seem overwhelming. In which case, depending on your choice of OS, you might need to follow different steps. Here, I’ll be discussing how to install PostgreSQL on Ubuntu and MacOS. Now, there are lots of ways to do this, apart from the methods I will mention below, and feel free to follow any of them. These methods have worked for me with consistency, and I personally haven’t faced any major problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing on MacOS
&lt;/h2&gt;

&lt;p&gt;For MacOS, we’ll be using the homebrew package manager. If you haven’t installed it yet, run the following command to get it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, use the following commands to download and start PostgreSQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew update &amp;amp;&amp;amp; brew install postgresql
brew services start postgresql
postgres -V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, now we have installed PostgreSQL on MacOS! However, we need to do a few more things to start using PostgreSQL properly, like creating a user, creating a database etc. We’ll get to that in a minute, let’s first wrap up on how to install PostgreSQL in Ubuntu.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing on Ubuntu
&lt;/h2&gt;

&lt;p&gt;Even though I say Ubuntu, this should work on any Debian/Ubuntu based distributions as is. However, if you are using anything other than Ubuntu, I would suggest to reference another blog or article where the distribution/os you use has been worked with.&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 wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" &amp;gt;&amp;gt; /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using PostgreSQL After Setup
&lt;/h2&gt;

&lt;p&gt;If you’re on a linux system, postgres will create a system user postgres, and you will need that user to use postgres. It can be done simply by switching from your current user using &lt;code&gt;sudo su - postgres&lt;/code&gt; &lt;br&gt;
Now, to login to the PostgreSQL shell (also known as psql), you need to run &lt;code&gt;psql&lt;/code&gt;. And that’s it! You’ll be logged into psql and you can now do the basic things to start. &lt;br&gt;
First, I would suggest creating a new superuser using the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE ROLE &amp;lt;username&amp;gt; WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD '&amp;lt;password&amp;gt;';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create the user with your given username and password. Now, you can login to psql with this user using the command &lt;code&gt;psql postgres -U &amp;lt;username&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Before we go any further, I think it’s prudent to mention a couple of things. Firstly, to login using psql, if you don’t give any extra parameters, psql will connect with the default database postgres with the default user. The default user will be postgres for Linux and your username of you MacOS. If you want to login using a specific user, you have to provide the database as well.&lt;/p&gt;

&lt;p&gt;Now, I’ll mention a few commands which usually gets the starting done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# to create a database
CREATE DATABASE &amp;lt;database name&amp;gt;;

# to access a database using a specific user
GRANT ALL PRIVILEGES ON DATABASE &amp;lt;database name&amp;gt; TO &amp;lt;username&amp;gt;;

# change user password. note that you cannot change the password of 
# the user you are currently logged into 
ALTER USER &amp;lt;username&amp;gt; WITH ENCRYPTED PASSWORD '&amp;lt;password&amp;gt;';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reference and Credits
&lt;/h2&gt;

&lt;p&gt;The following blogs and sites have been quite helpful for installing and working with PostgreSQL.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.codementor.io/@engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb"&gt;Getting Started with PostgreSQL on Mac OSX&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://computingforgeeks.com/install-postgresql-11-on-ubuntu-linux/"&gt;Install PostgreSQL 11 on Ubuntu 20.04/18.04/16.04&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://devopspy.com/linux/allow-remote-connections-postgresql/"&gt;Allow Remote Connections to PostgreSQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://axiomq.com/blog/backup-and-restore-a-postgresql-database/"&gt;Backup and Restore a PostgreSQL Database&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>postgres</category>
      <category>database</category>
    </item>
    <item>
      <title>Need suggestion on how to create a CI/CD pipeline for my dockerized app</title>
      <dc:creator>Mehran Kader</dc:creator>
      <pubDate>Sat, 28 Sep 2019 21:01:52 +0000</pubDate>
      <link>https://forem.com/kmehran1106/need-suggestion-on-how-to-create-a-ci-cd-pipeline-for-my-dockerized-app-1ek</link>
      <guid>https://forem.com/kmehran1106/need-suggestion-on-how-to-create-a-ci-cd-pipeline-for-my-dockerized-app-1ek</guid>
      <description>&lt;p&gt;Hi all, I've been working as a Python based backend engineer for quite a while and recently I've become obsessed with DevOps and SRE related technology. I have started learning docker and also dockerized my first django app using docker-compose. But now I'm a bit lost on how to make this better. &lt;/p&gt;

&lt;p&gt;As far as my limited knowledge goes, I should at least set up a CI/CD pipeline and try for a zero downtime deployment using Kubernetes. However I don't have any clue about any of these things apart from a few names (e.g Ansible, Terraform, Kubernetes, Docker Swarm etc.) &lt;/p&gt;

&lt;p&gt;Can any courageous adventurer help this lost wanderer to find his way? :p &lt;/p&gt;

</description>
      <category>devops</category>
      <category>docker</category>
      <category>help</category>
    </item>
    <item>
      <title>Some of git aliases I use to speed up my work</title>
      <dc:creator>Mehran Kader</dc:creator>
      <pubDate>Sat, 21 Sep 2019 20:10:38 +0000</pubDate>
      <link>https://forem.com/kmehran1106/some-of-git-aliases-i-use-to-speed-up-my-work-1lbp</link>
      <guid>https://forem.com/kmehran1106/some-of-git-aliases-i-use-to-speed-up-my-work-1lbp</guid>
      <description>&lt;p&gt;Hi everyone! I have read a lot of articles on git (most of them from dev.to) where many of you shared you git tips and tricks. There were also a few cool ones where the concepts of version controlling and how git actually does these things were mentioned. I am really grateful to the wonderful developer community that just keeps growing! In this post I thought to share some of my git aliases that I use which helps me avoid repetitive commands and also enables to maintain a clean git tree. So here goes!&lt;/p&gt;

&lt;p&gt;I have bound this command to "lg", and it shows my git commit history in a nice and easy to read one line format. I've forgotten where I took it from but it's either from stackoverflow or here!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use rebase a lot to update my feature branches with master. This takes a few commands where I used to update my local master branch and then go back to my feature branch and rebase the updates. There are probably better or different ways to do this, but I just use this since it works without issues! If anyone has any suggestions on this feel free to comment!&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;!git checkout master &amp;amp;&amp;amp; git pull --rebase &amp;amp;&amp;amp; git checkout - &amp;amp;&amp;amp; git rebase --interactive master&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Although I wrote this one on my own but I must thank the writer of this post for putting git rebase in such an easy to understand way!&lt;br&gt;
&lt;a href="https://dev.to/maxwell_dev/the-git-rebase-introduction-i-wish-id-had"&gt;The Git Rebase Introduction I Wish I'd Had&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This one is a niche command that comes in handy sometimes! Basically it reverts the last changes that I did to my git tree (I think :p), and can even revert rebases!&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;reset --hard ORIG_HEAD&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Sometimes I just need to update my last commit with a few new changes. I use this command to do that in a jiff!&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;commit --amend --no-edit&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Ez commits!&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;!git add -A &amp;amp;&amp;amp; git commit -a&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Well that's it for this post! These are the git aliases I found most useful in my day to day work. Thanks to everyone in the dev community (from dev.to or not) for all the help that I receive day to day (not just for git!)! &lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>What should I be doing as a backend Django developer?</title>
      <dc:creator>Mehran Kader</dc:creator>
      <pubDate>Mon, 21 May 2018 05:13:22 +0000</pubDate>
      <link>https://forem.com/kmehran1106/what-should-i-be-doing-as-a-backend-django-developer-27mf</link>
      <guid>https://forem.com/kmehran1106/what-should-i-be-doing-as-a-backend-django-developer-27mf</guid>
      <description>&lt;p&gt;I am working as a backend Django developer for the past year (10 months or so), and mostly specialize in using the django-rest-framework to provide api endpoints for the frontend. My HTML/CSS skills suck, while I'm an absolute newbie in Javascript. I have worked with celery (for async tasks), have meddled around with a bit of logging using elastic, while I haven't worked with some of the advanced stuff like caching (I should be working on redis-caching soon), django-channels etc.&lt;br&gt;
Currently I'm in a bit of a slump on what I should be learning next or how I should proceed in the near future (1-2 months). I have quite a bit of free time now (most of which I waste -_-) and would like to ask what should I be trying to learn, or if there are any books which I should read to broaden my experiences.&lt;br&gt;
Books I've read on django/development in general:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tangoing with django&lt;/li&gt;
&lt;li&gt;Two scoops of django&lt;/li&gt;
&lt;li&gt;Lightweight django&lt;/li&gt;
&lt;li&gt;Test driven development with python - O'reilly&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Any thoughts will be appreciated :)&lt;/p&gt;

</description>
      <category>django</category>
      <category>backend</category>
      <category>python</category>
    </item>
  </channel>
</rss>
