<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Goran Aviani on Medium]]></title>
        <description><![CDATA[Stories by Goran Aviani on Medium]]></description>
        <link>https://medium.com/@goranaviani?source=rss-3ade16c9bf1c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Trimu9RbkPd8z_cfC_sI0A.jpeg</url>
            <title>Stories by Goran Aviani on Medium</title>
            <link>https://medium.com/@goranaviani?source=rss-3ade16c9bf1c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:52:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@goranaviani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My dear son]]></title>
            <link>https://medium.com/@goranaviani/my-dear-son-7a3b2c3aeb92?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a3b2c3aeb92</guid>
            <category><![CDATA[friendship]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[love]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Sat, 16 Sep 2023 10:47:50 GMT</pubDate>
            <atom:updated>2023-09-16T16:34:52.543Z</atom:updated>
            <content:encoded><![CDATA[<p>To help you navigate life’s challenges I want to share some of my stories and advice which I hope you’ll take to heart. But, honestly, I understand that you’re a lot like me, and you probably won’t pay much attention to these words. You’ll likely go your own way and learn from your own experiences, just as I did when I received this advice. It’s a common thing; most people tend to learn best through their own mistakes rather than taking lessons from others.</p><h4><strong>Learning…</strong></h4><p>You’ll come to understand that learning doesn’t stop once school is over. Acquiring new skills can be essential, as someday it might provide for your family. Whether you read, take courses, or engage with a community, the method doesn’t matter as long as you keep learning consistently.</p><blockquote><em>Maintain a curious mindset and keep seeking answers. This will help prevent you from becoming stagnant and will keep you moving forward in life.</em></blockquote><h4>Be kind…</h4><p>Don’t criticize or mock those who are unlike you. Don’t follow the crowd if it promotes intolerance. Every time you make fun of someone, you could be causing them to feel insecure, fearful, and hurt by your unkind actions. These individuals may carry this pain with them throughout their lives.</p><blockquote><em>Instead, consider taking a stand for what’s right. Sometimes, all it takes is one person to bring about positive change.</em></blockquote><h4><strong>Acceptance…</strong></h4><p>Throughout your life, you’ll find yourself striving to make others happy. But don’t go over your head to do so. Live your life and follow what brings you joy, because there will always be some who won’t accept you. Keep in mind that while you may wish to have everyone’s approval, it’s not a necessity.</p><blockquote>Focus on surrounding yourself with kind-hearted people who appreciate you for who you are.</blockquote><h4><strong>Friends…</strong></h4><p>You will meet many people, and some of them will become your friends. Your whole world will revolve around them. They will be your everything, your greatest treasure, they will become more important than me. I already understand you will love to spend time with them, whether that means going to a beach, a club or discovering new movies and music tastes. You will laugh at their jokes, travel together and do all kinds of things. All these activities will become your precious memories.</p><p>One day you will discover that there is no such thing as a friend. Friendship isn’t drinking, eating or having common interests.</p><blockquote>Many of these friends will become nothing more than people with the same interests you happened to meet during your journey. Many of these people will not stand up for you, will not help you or be there when you go through the hardest moments of your life. They will just become people that criticized you.</blockquote><h4><strong>Fear of rejection…</strong></h4><p>One of our most basic instincts is to avoid risks, and the mere thought of taking a risk creates primal human fear. Most people’s lives are dominated by being afraid of rejection, being cautious and staying in their comfort zones. They often choose to play it safe, and settle for average. Unfortunately, this kind of life will never be exciting, fulfilling, or even worth living. It will never give you interesting experiences or help you reach your full potential.</p><blockquote>Fear is an emotion experienced by everyone. It is important to cast aside caution and stop seeking safe zones and comfort. Instead, go all in, follow your instincts and pursue your desires.</blockquote><h4><strong>Love…</strong></h4><p>One day, you’ll experience falling in love, and it will be with a person who captivates your every thought. You’ll feel butterflies in your stomach whenever she crosses your mind. You’ll believe this is the greatest love of your life, and it will seem like no one else exists in your world.</p><p>But eventually, that love story will come to an end. You’ll realize you were blindly in love, and when it’s over, you’ll feel emptiness. Your whole world may crumble.</p><p>In life, there are only a few people truly meant for you.</p><blockquote>One day, you’ll meet that special one. Trust your instincts and make sure you both truly understand each other.</blockquote><h4><strong>Listen to others…</strong></h4><p>You’ll encounter people who want to share their stories with you. When they do, listen attentively, take your time, and don’t rush through it. It’s not always easy to hear someone’s story, but it’s even more challenging to share it.</p><blockquote>If you listen genuinely, the reward you gain is beyond measure.</blockquote><h4>Always remember</h4><blockquote>Rarely in life, you’ll meet someone where your instincts tell you they’re the right person for you. When that happens, consider making them a core part of your inner circle, as such individuals are few and far between. Invest your time and effort in nurturing these connections, and when you can’t give as much attention as needed at a certain point, be honest about it to show your ongoing interest. Be a good listener, embrace their quirks, and be kind. Nobody is flawless, but these special people will come pretty close to it. If your instincts are correct, they’ll become your friends, and all this advice won’t matter because they’ll naturally become everything you need.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a3b2c3aeb92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Set Up Python Virtual Environment on Ubuntu 20.04]]></title>
            <link>https://itnext.io/how-to-set-up-python-virtual-environment-on-ubuntu-20-04-a2c7a192938d?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2c7a192938d</guid>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[virtualenv]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Fri, 12 Jun 2020 15:21:00 GMT</pubDate>
            <atom:updated>2024-07-03T07:51:55.973Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjWRycdM-1DNy0QCSsw7dw.jpeg" /></figure><p>Just like the last time I’ve once again got myself a “new” laptop, a x270 yay! x270 is a last model of the x series having 1 internal and 1 external battery or so called “Power bridge” (12+ hours of battery time) allowing a battery swap without turning off the laptop.</p><p>And once again I was in a need to set up a Python virtual environment and once again I googled for a solution, just to find my own article!</p><p>Continuing on my previous article that dealt with the same situation on Ubuntu 18.04, I have decided to update the knowledge base with newly learned info.</p><p>Old Article:<br>freeCodeCamp: <a href="https://www.freecodecamp.org/news/virtualenv-with-virtualenvwrapper-on-ubuntu-18-04/">https://www.freecodecamp.org/news/virtualenv-with-virtualenvwrapper-on-ubuntu-18-04/</a></p><p>Medium ITNEXT: <a href="https://itnext.io/virtualenv-with-virtualenvwrapper-on-ubuntu-18-04-goran-aviani-d7b712d906d5">https://itnext.io/virtualenv-with-virtualenvwrapper-on-ubuntu-18-04-goran-aviani-d7b712d906d5</a></p><p>And let me tell you that it’s easier than before because we are going to do only the next two things:</p><ul><li>Install virtualenvwrapper</li><li>Edit .bashrc file</li></ul><h4><strong>Prerequisites</strong></h4><p>In this text I will show you how to set up virtualenvwrapper with pip3 (pip for Python 3). We are not doing it anymore with Python 2 because at this moment Python 2 is dead : <a href="https://www.python.org/doc/sunset-python-2/">https://www.python.org/doc/sunset-python-2/</a></p><p>To complete this tutorial you will need a computer with Ubuntu 20.04 installed and a internet connection :) Also some knowledge in terminals and Vim editor would be useful.</p><h4>Setting up a Virtual Environment</h4><p>Now open your terminal in the home directory by right clicking and choosing the option “Open in Terminal” or you can press the <em>CTRL</em>, <em>ALT</em>, and <em>T</em> keys on your keyboard at the same time to open the Terminal application automatically.</p><p>You first need to create a special directory that will hold all of your virtual environments so proceed with creating a new hidden directory called virtualenv.</p><pre>mkdir .virtualenv</pre><h4><strong>pip3</strong></h4><p>Now you should install pip for Python3.</p><pre>sudo apt install python3-pip</pre><p>Confirm the pip3 installation.</p><pre>pip3 -V</pre><h4><strong>virtualenvwrapper</strong></h4><p>virtualenvwrapper is a set of extensions to virtualenv. It provides commands like mkvirtualenv, lssitepackages, and especially workon for switching between different virtualenv environments.</p><p>Install virtualenvwrapper via pip3:</p><pre>pip3 install virtualenvwrapper</pre><h4><strong>Bashrc file</strong></h4><p>We are going to modify your .bashrc file by adding a row that will adjust every new virtual environment to use Python 3. We will point virtual environments to the directory we created above (.virtualenv) and we will also point to the locations of the virtualenv and virtualenvwrapper.</p><p>Now open the .bashrc file using Vim editor.</p><pre>vim .bashrc</pre><p>If you still haven’t used Vim editor or you don’t have it installed on your computer you should install it now. It is one of the widely used Linux editors and for a good reason.</p><pre>sudo apt install vim</pre><p>After you installed Vim open the file .bashrc file by typing in the <em>vim .bashrc</em> command in your terminal. Navigate to the bottom of the .bashrc file, press the letter <em>i</em> to enter the insert mode of Vim and add these rows:</p><pre>#Virtualenvwrapper settings:</pre><pre>export WORKON_HOME=$HOME/.virtualenvs</pre><pre>VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3</pre><pre>. /usr/local/bin/virtualenvwrapper.sh</pre><p>After you are done, press the <em>esc </em>key then type:wq and press enter, this command will save and exit the Vim editor. <br>Now you need to reload the bashrc script, there are two ways of doing it: close and reopen your terminal or execute source ~/.bashrc command</p><p>To create a virtual environment in Python3 and activate it immediately use this command in your terminal:</p><pre>mkvirtualenv name_of_your_env</pre><p>To deactivate the environment use the deactivate command.</p><pre>deactivate</pre><p>To list all available virtual environments use the command <em>workon </em>or <em>lsvirtualenv </em>(Same result as workon but shown in a fancy way) in your terminal:</p><pre>workon</pre><pre>lsvirtualenv</pre><p>To activate one specific environment use workon + name of your environment:</p><pre>workon name_of_your_env</pre><p>There are several useful command you might need to use someday:</p><p>Rmvirtualenv will remove a specific virtual environment located in your .virtualenv directory.</p><pre>rmvirtualenv name_of_your_env</pre><p>Cpvirtualenv will copy the existing virtual environment to a new virtual environment and activate it.</p><pre>cpvirtualenv old_virtual_env new_virtual_env</pre><p>Well done!</p><p>You have now created your first isolated Python 3 environment!</p><p>Thank you for reading! Check out more articles like this on my freeCodeCamp profile: <a href="https://www.freecodecamp.org/news/author/goran/">https://www.freecodecamp.org/news/author/goran/</a>, Medium profile:<a href="https://medium.com/@goranaviani"> https://medium.com/@goranaviani</a> and other fun stuff I build on my GitHub page:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2c7a192938d" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-set-up-python-virtual-environment-on-ubuntu-20-04-a2c7a192938d">How to Set Up Python Virtual Environment on Ubuntu 20.04</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtualenv with Virtualenvwrapper on Ubuntu 18.04]]></title>
            <link>https://itnext.io/virtualenv-with-virtualenvwrapper-on-ubuntu-18-04-goran-aviani-d7b712d906d5?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7b712d906d5</guid>
            <category><![CDATA[virtualenv]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[virtual-environment]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Tue, 30 Jul 2019 13:44:00 GMT</pubDate>
            <atom:updated>2019-07-30T13:44:00.970Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aMYnl2Ctt9Y-RZ5bodNF2g.jpeg" /></figure><p>Before we start with the tutorial I would like to tell you the story how I realized that I need a reminder on how to set up virtualenvwrapper on top of virtualenv in Ubuntu 18.04. I have done this process several of times on different computers and every time it seemed to be just a little bit different than before.</p><p>Recently I got myself a new laptop and I on my way home I have read several tutorials on “How to set up virtualenvwrapper on Ubuntu 18.04”. And let me tell you that it seems really easy because all of those tutorials are pretty straight forward and basically explain how to do the next three 3 things:</p><ul><li>Install virtualenv</li><li>Install virtualenvwrapper</li><li>Edit .bashrc/.bash_profile or both</li></ul><p>But even though all these tutorials are meant to help us set up virtualenvwrapper on a modern Ubuntu 18.04 installation non of them worked for me.</p><p>I had several errors while trying to figure out what went wrong while following these tutorials. First I’ve had some of “<em>mkvirtualenv: command not found</em>”, then a little of “<em>-bash: /usr/bin/virtualenvwrapper.sh: No such file or directory</em>”, and then a touch of “<em>ERROR: virtualenvwrapper could not find virtualenv in your path</em>”.</p><p>After some research I realized that all virtualenvwrapper Ubuntu 18.04 tutorials are copies an old text written before April 2016 (release date of Ubuntu 16.04).<br>And I know it to be true because from Ubuntu 16.04 and onward the location for the vritualenvwrapper’s pip installation has changed from /usr/local/bin/virtualenvwrapper.sh to ~/.local/bin/virtualenvwrapper.sh.Note that the local directory is hidden.</p><p>So let’s start by writing a tutorial that will show you how to avoid all those issues mentioned above.</p><h4>Prerequisites</h4><p>In this text I will show you how to set up virtualenvwrapper with pip3 (pip for Python 3). I chosen this version of pip instead of a Python 2 version because Python’s 2 end of life is January 1. 2020.</p><blockquote>Python 2 will retire in… <a href="https://pythonclock.org/">https://pythonclock.org/</a></blockquote><p>To complete this tutorial you will need a computer with Ubuntu 18.04 installed and a internet connection :) Also some knowledge in terminals and Vim editor would be useful. We will assume you already updated and upgraded the system.</p><h4>Setting up a Virtual Environment</h4><p>Now open your terminal in the home directory by right clicking and choosing the option “Open in Terminal” or you can press the CTRL, ALT, and T keys on your keyboard at the same time to open the Terminal application automatically.</p><p>You first need to create a special directory that will hold all of your virtual environments so proceed with creating a new hidden directory called virtualenv.</p><pre>mkdir .virtualenv</pre><p>Now you should install pip for Python3.</p><pre>sudo apt install python3-pip</pre><p>Confirm the pip3 installation.</p><p>pip3 --version</p><p>Now install virtualenv via pip3.</p><pre>pip3 install virtualenv</pre><p>To find out the location where your virtualenv was installed type:</p><pre>which virtualenv</pre><p>Install virtualenvwrapper via pip3:</p><pre>pip3 install virtualenvwrapper</pre><p>We are going to modify your .bashrc file by adding a row that will adjust every new virtual environment to use Python 3. We will point virtual environments to the directory we created above (.virtualenv) and we will also point to the locations of the virtualenv and virtualenvwrapper.</p><p>Now open the .bashrc file using Vim editor.</p><pre>vim .bashrc</pre><p>If you still haven’t used Vim editor or you don’t have it installed on your computer you should install it now. It is one of widely used Linux editors and for a good reason.</p><pre>sudo apt install vim</pre><p>After you installed Vim open the file .bashrc file by typing in the <em>vim .bashrc</em> command in your terminal. Navigate to the bottom of the .bashrc file, press the letter <em>i</em> to enter the insert mode of Vim and add these rows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e651071863c526cad028df098032912/href">https://medium.com/media/4e651071863c526cad028df098032912/href</a></iframe><p>After you are done, press the <em>esc </em>key then type:wq and press enter, this command will save and exit the Vim editor. Close and reopen your terminal when you’re done.</p><p>To create a virtual environment in Python3 and activate it immediately use this command in your terminal:</p><pre>mkvirtualenv name_of_your_env</pre><p>You should confirm that this environment is set up for Python3:</p><pre>Python -V</pre><p>To deactivate the environment use the deactivate command.</p><pre>deactivate</pre><p>To list all available virtual environments use the command <em>workon </em>or <em>lsvirtualenv </em>(Same result as workon but shown in a fancy way) in your terminal:</p><pre>workon</pre><pre>lsvirtualenv</pre><p>To activate one specific environment use workon + name of your environment:</p><pre>workon name_of_your_env</pre><p>There are several useful command you might need to use someday:</p><p>Rmvirtualenv will remove a specific virtual environment located in your .virtualenv directory.</p><pre>rmvirtualenv name_of_your_env</pre><p>Cpvirtualenv will copy the existing virtual environment to a new virtual environment and activate it.</p><pre>cpvirtualenv old_virtual_env new_virtual_env</pre><blockquote>Well done!</blockquote><blockquote>You have now created your first isolated Python 3 environment!</blockquote><p>Thank you for reading! Check out more articles like this on my Medium profile: <a href="https://medium.com/@goranaviani">https://medium.com/@goranaviani</a> and other fun stuff I build on my GitHub page:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7b712d906d5" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/virtualenv-with-virtualenvwrapper-on-ubuntu-18-04-goran-aviani-d7b712d906d5">Virtualenv with Virtualenvwrapper on Ubuntu 18.04</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create, read, update and search through Excel files using Python]]></title>
            <link>https://medium.com/free-code-camp/how-to-create-read-update-and-search-through-excel-files-using-python-c70680d811d4?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c70680d811d4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Mon, 08 Apr 2019 10:35:08 GMT</pubDate>
            <atom:updated>2024-07-03T07:53:33.850Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*REWATbNLWv5uvpB0UKedEQ.jpeg" /><figcaption>Blooming agave overlooking the main port in Split, Croatia</figcaption></figure><p>This article will show in detail how to work with Excel files and how to modify specific data with Python.</p><p>First we will learn how to work with CSV files by reading, writing and updating them. Then we will take a look how to read files, filter them by sheets, search for rows/columns, and update cells of xlsx files.</p><p>Let’s start with the simplest spreadsheet format: CSV.</p><h3>Part 1 — The CSV file</h3><p>A CSV file is a comma-separated values file, where plain text data is displayed in a tabular format. They can be used with any spreadsheet program, such as Microsoft Office Excel, Google Spreadsheets, or LibreOffice Calc.</p><p>CSV files are not like other spreadsheet files though, because they don’t allow you to save cells, columns, rows or formulas. Their limitation is that they also allow only one sheet per file. My plan for this first part of the article is to show you how to create CSV files using Python 3 and the standard library module CSV.</p><p>This tutorial will end with two GitHub repositories and a live web application that actually uses the code of the second part of this tutorial (yet updated and modified to be for a specific purpose).</p><h3>Writing to CSV files</h3><p>First, open a new Python file and import the Python CSV module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bddf1a96f84a7e44b4e7e7d1fc839767/href">https://medium.com/media/bddf1a96f84a7e44b4e7e7d1fc839767/href</a></iframe><h4>CSV Module</h4><p>The CSV module includes all the necessary methods built in. These include:</p><ul><li>csv.reader</li><li>csv.writer</li><li>csv.DictReader</li><li>csv.DictWriter</li><li>and others</li></ul><p>In this guide we are going to focus on the writer, DictWriter and DictReader methods. These allow you to edit, modify, and manipulate the data stored in a CSV file.</p><p>In the first step we need to define the name of the file and save it as a variable. We should do the same with the header and data information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2f4349581817a5f3efca33dd37e7acc/href">https://medium.com/media/a2f4349581817a5f3efca33dd37e7acc/href</a></iframe><p>Now we need to create a function named <em>writer </em>that will take in three parameters: <em>header</em>, <em>data </em>and <em>filename</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c07445b86fd830fa2401f559f9d5ab95/href">https://medium.com/media/c07445b86fd830fa2401f559f9d5ab95/href</a></iframe><p>The next step is to modify the <em>writer </em>function so it creates a file that holds data from the <em>header </em>and <em>data </em>variables. This is done by writing the first row from the <em>header </em>variable and then writing four rows from the <em>data</em> variable (there are four rows because there are four tuples inside the list).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d79140f4faa8dce224586e1b04994ce/href">https://medium.com/media/7d79140f4faa8dce224586e1b04994ce/href</a></iframe><blockquote>The <a href="https://docs.python.org/3/library/csv.html#dialects-and-formatting-parameters">official Python documentation</a> describes how the csv.writer method works. I would strongly suggest that you to take a minute to read it.</blockquote><p><strong>And voilà!</strong> You created your first CSV file named imdb_top_4.csv. Open this file with your preferred spreadsheet application and you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*DuYsqu8EFzU15u_0HgNDKg.png" /><figcaption>Using LibreOffice Calc to see the result.</figcaption></figure><p>The result might be written like this if you choose to open the file in some other application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*Q0U_MBj6mr3ekidC299lbQ.png" /><figcaption>Using SublimeText to see the result.</figcaption></figure><h3>Updating the CSV files</h3><p>To update this file you should create a new function named <em>updater </em>that will take just one parameter called <em>filename</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1029728ab01e69a509178e0a2846bd3a/href">https://medium.com/media/1029728ab01e69a509178e0a2846bd3a/href</a></iframe><p>This function first opens the file defined in the <em>filename </em>variable and then saves all the data it reads from the file inside of a variable named <em>readData</em>. The second step is to hard code the new value and place it instead of the old one in the <em>readData[0][‘Rating’] </em>position.</p><p>The last step in the function is to call the <em>writer</em> function by adding a new parameter <em>update </em>that will tell the function that you are doing an update.</p><blockquote>csv.DictReader is explained more in the official Python documentation <a href="https://docs.python.org/3/library/csv.html#dialects-and-formatting-parameters">here</a>.</blockquote><p>For <em>writer </em>to work with a new parameter, you need to add a new parameter everywhere <em>writer </em>is defined. Go back to the place where you first called the <em>writer</em> function and add “write” as a new parameter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b87de6d927de388cac935baca70272aa/href">https://medium.com/media/b87de6d927de388cac935baca70272aa/href</a></iframe><p>Just below the writer function call the<em> updater</em> and pass the <em>filename</em> parameter into it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c9de916b28ef3579ca538258bd9a47c/href">https://medium.com/media/9c9de916b28ef3579ca538258bd9a47c/href</a></iframe><p>Now you need to modify the <em>writer</em> function to take a new parameter named <em>option</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/975bbf231284220b329ac472da3473ba/href">https://medium.com/media/975bbf231284220b329ac472da3473ba/href</a></iframe><p>From now on we expect to receive two different options for the <em>writer </em>function (<em>write and update</em>). Because of that we should add two if statements to support this new functionality. First part of <em>the function under “if option == “write:”</em> is already known to you. You just need to add the “<em>elif option == “update”:</em> section of the code and the <em>else</em> part just as they are written bellow:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3edff5406b4a0e6af7f9f20c7ab7ace/href">https://medium.com/media/f3edff5406b4a0e6af7f9f20c7ab7ace/href</a></iframe><p><strong>Bravo!</strong> Your are done!</p><p>Now your code should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/0*vPoREgLGJU8VmB5k" /><figcaption>The code.</figcaption></figure><p>You can also find the code here:</p><p><a href="https://github.com/GoranAviani/CSV-Viewer-and-Editor">https://github.com/GoranAviani/CSV-Viewer-and-Editor</a></p><p>In the first part of this article we have seen how to work with CSV files. We have created and updated one such file.</p><h3>Part 2 — The xlsx file</h3><p>For several weekends I have worked on this project. I have started working on it because there was a need for this kind of solution in my company. My first idea was to build this solution directly in my company’s system, but then I wouldn’t have anything to write about, eh?</p><p>I build this solution using Python 3 and <em>openpyxl </em>library. The reason why I have chosen <em>openpyxl </em>is because it represents a complete solution for creating worksheets, loading, updating, renaming and deleting them. It also allows us to read or write to rows and columns, merge or un-merge cells or create Python excel charts etc.</p><h3>Openpyxl terminology and basic info</h3><ul><li>Workbook is the name for an Excel file in Openpyxl.</li><li>A workbook consists of sheets (default is 1 sheet). Sheets are referenced by their names.</li><li>A sheet consists of rows (horizontal lines) starting from the number 1 and columns (vertical lines) starting from the letter A.</li><li>Rows and columns result in a grid and form cells which may contain some data (numerical or string value) or formulas.</li></ul><blockquote>Openpyxl in nicely documented and I would advise that you take a look <a href="https://openpyxl.readthedocs.io/en/stable/">here</a>.</blockquote><p>The first step is to open your Python environment and install <em>openpyxl </em>within your terminal:</p><pre>pip install openpyxl</pre><p>Next, import <em>openpyxl </em>into your project and then to load a workbook into the <em>theFile </em>variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f4ae976d04fab5273b2926e8d71a0ec/href">https://medium.com/media/3f4ae976d04fab5273b2926e8d71a0ec/href</a></iframe><p>As you can see, this code prints all sheets by their names. It then selects the sheet that is named “customers 1” and saves it to a <em>currentSheet </em>variable. In the last line, the code prints the value that is located in the B4 position of the “customers 1” sheet .</p><p>This code works as it should but it is very hard coded. To make this more dynamic we will write code that will:</p><ul><li><em>Read the file</em></li><li><em>Get all sheet names</em></li><li><em>Loop through all sheets</em></li><li><em>In the last step, the code will print values that are located in B4 fields of each found sheet inside the workbook.</em></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5777677b631fdb5d6a0b69e7590ae370/href">https://medium.com/media/5777677b631fdb5d6a0b69e7590ae370/href</a></iframe><p>This is better than before, but it is still a hard coded solution and it still assumes the value you will be looking for is in the B4 cell, which is just silly :)</p><p>I expect your project will need to search inside all sheets in the Excel file for a specific value. To do this we will add one more for loop in the “ABCDEF” range and then simply print cell names and their values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b29367f026e25c8b3c65c2ab1fac6835/href">https://medium.com/media/b29367f026e25c8b3c65c2ab1fac6835/href</a></iframe><p>We did this by introducing the “<em>for row in range..</em>” loop. The range of the for loop is defined from the cell in row 1 to the sheet’s maximum number or rows. The second for loop searches within predefined column names “<em>ABCDEF</em>”. In the second loop we will display the full position of the cell (column name and row number) and a value.</p><p>However, in this article my task is to find a specific column that is named “telephone” and then go through all the rows of that column. To do that we need to modify the code like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c837b13a0654635d02c36adc2da2cbf/href">https://medium.com/media/2c837b13a0654635d02c36adc2da2cbf/href</a></iframe><p>This modified code goes through all cells of every sheet, and just like before the row range is dynamic and the column range is specific. The code loops through cells and looks for a cell that holds a text “telephone”. Once the code finds the specific cell it notifies the user in which cell the text is located. The code does this for every cell inside of all sheets that are in the Excel file.</p><p>The next step is to go through all rows of that specific column and print values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d22a957cb13f9689de067a261888f0bb/href">https://medium.com/media/d22a957cb13f9689de067a261888f0bb/href</a></iframe><p>This is done by adding a function named <em>get_column_letter </em>that finds a letter of a column. After the letter of the column is found we loop through all rows of that specific column. This is done with the <em>get_all_values_by_cell_letter</em> function which will print all values of those cells.</p><h3>Wrapping up</h3><p><strong>Bra gjort!</strong> There are many thing you can do after this. My plan was to build an online app that will standardize all Swedish telephone numbers taken from a text box and offer users the possibility to simply copy the results from the same text box. The second step of my plan was to expand the functionality of the web app to support the upload of Excel files, processing of telephone numbers inside those files (standardizing them to a Swedish format) and offering the processed files back to users.</p><p>I have done both of those tasks and you can see them live in the Tools page of my <em>Incodaq.com</em> site:</p><blockquote><a href="https://tools.incodaq.com/">https://tools.incodaq.com/</a> (deprecated)</blockquote><p>Also the code from the second part of this article is available on GitHub:</p><blockquote><a href="https://github.com/GoranAviani/Manipulate-Excel-spreadsheets">https://github.com/GoranAviani/Manipulate-Excel-spreadsheets</a></blockquote><p>Thank you for reading! Check out more articles like this on my Medium profile: <a href="https://medium.com/@goranaviani">https://medium.com/@goranaviani</a> and other fun stuff I build on my GitHub page:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c70680d811d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-create-read-update-and-search-through-excel-files-using-python-c70680d811d4">How to create, read, update and search through Excel files using Python</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Git: basics, commands, tips & tricks]]></title>
            <link>https://faun.pub/understanding-git-basics-commands-tips-tricks-da0c05db411f?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/da0c05db411f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Wed, 09 Jan 2019 16:25:35 GMT</pubDate>
            <atom:updated>2019-07-18T15:14:24.160Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6LFCHug7gQ_Y7INjPdIFQ.jpeg" /><figcaption>How I imagine a proper Git project.</figcaption></figure><p>Recently I’ve became a mentor to a colleague of mine. And my mentee asked me about Git on several occasions. This is for you colleague! P.S. I should have written this article when we started but I hope it will help now!</p><blockquote>And remember: The best way to learn anything is to do it by yourself! And as my mentor always says to me: Udaraj!</blockquote><h3>Basics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2GkM1pvDmnI2ksUM.png" /></figure><h3>So why is Git so important?</h3><p>Lets first start by quoting the first line on the Git’s Wikipedia page: “<strong><em>Git</em></strong><em> (</em><a href="https://en.wikipedia.org/wiki/Help:IPA/English"><em>/ɡɪt/</em></a><em>) is a</em><a href="https://en.wikipedia.org/wiki/Version-control"><em> version-control</em></a><em> system for tracking changes in</em><a href="https://en.wikipedia.org/wiki/Computer_file"><em> computer files</em></a><em> and coordinating work on those files among multiple people.</em>”</p><p>So that means that basic and most important function of Git is to allow teams to add (and merge) code at the same time to the same project. By adding this ability to projects it makes teams more efficient and gives them abilities to work on bigger projects and more complex problems.<br>There are also many other things Git does really well: it allows us to revert changes, create new branches for adding new features, resolve merge conflict etc.</p><p>Git works like this: Git stores project in a <strong>repository</strong>. <strong>Commits </strong>are made to the project and they tell Git that you are satisfied with the new or changed code you created. New code/changes are committed on branches. Most of work is committed on other branches and then merged with master branch. All this is stored in the same directory as the project but in a sub-folder called <strong>.git</strong>. To share the code with your colleagues you <strong>push </strong>the changes to the repository, and to get the new code from you colleagues you <strong>pull </strong>changes from the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*SBz94SjR2tbvFY6n" /></figure><h3>Then what is GitHub, GitLab or Bitbucket?</h3><p>Well, I am glad you asked! This kind of applications are called repository management services and they play a crucial role in the modern software development. Even though Git is the go-to version control solution for most companies just as well as GitHub, GitHub has some strong competitors such as GitLab and Bitbucket. However, if you know how to use GitHub, you won’t have any problem working with GitLab or Bitbucket.</p><blockquote><em>Git is the tool, GitHub is the service for projects that use Git.</em></blockquote><h4>Where can I discover interesting projects and connect to other developers?</h4><p>GitHub, GitLab and Bitbucket have public repository search options and the ability to easily follow other users.</p><p>Can you now see why is it important to know Git and Github (GitLab/Bitbucket)? Only thing left before writing the commands is to tell you few simple rules to always follow when using Git:</p><ul><li><strong>Rule 1:</strong> Create a Git repository for every new project</li><li><strong>Rule 2:</strong> Create a new branch for every new feature</li></ul><h3>Commands</h3><p>To get started with Git you must have it on your computer. If you don’t already have it you can go to <a href="https://git-scm.com/">https://git-scm.com/</a> and follow the instructions.</p><h4><strong>Initialize a new Git repository: Git init</strong></h4><p>Everything you code is tracked in the repository. To initialize a git repository, use this command while inside the project folder. This will create a .git folder.</p><pre>git init</pre><h4><strong>Git add</strong></h4><p>This command adds one or all changed files to the staging area.</p><p>To just add a specific file to staging:</p><pre>git add filename.py</pre><p>To stage new, modified or deleted files:</p><pre>git add -A</pre><p>To stage new and modified files:</p><pre>git add .</pre><p>To stage modified and deleted files:</p><pre>git add -u</pre><h4>Git commit</h4><p>This command records the file in the version history. The -m means that a commit message follows. This message is a custom one and you should use it to let your colleagues or yourself sometime in the future know what was added in that commit.</p><pre>git commit -m &quot;your text&quot;</pre><h4>Git status</h4><p>This command will list files in green or red colors. Green files have been added to the stage but not committed yet. Files marked as red are the ones not yet added to the stage.</p><pre> git status</pre><h3>Working with branches</h3><h4>Git branch branch_name</h4><p>This will create a new branch:</p><pre>git branch branch_name</pre><h4>Git checkout branch_name</h4><p>To switch from one branch to another:</p><pre>git checkout branch_name</pre><h4>Git checkout -b branch_name</h4><p>To create new branch and switch to it automatically:</p><pre>git checkout -b branch_name</pre><p>This is shot for:</p><pre>git branch branch_name<br>git checkout branch_name</pre><h4>Git branch</h4><p>To list all the branches and see on what branch you currently are:</p><pre>git branch</pre><h4>Git log</h4><p>This command will list the version history for the current branch:</p><pre>git log</pre><h3>Push &amp; Pull</h3><h4>Git push</h4><p>This command sends the committed changes to remote repository:</p><pre>git push</pre><h4>Git pull</h4><p>To pull the changes from the remote server to your local computer:</p><pre>git pull</pre><blockquote>For more commands and detail explanation of listed ones I would recommend you check the official Git documentation: <a href="https://git-scm.com/docs/">https://git-scm.com/docs/</a></blockquote><h3>Tips &amp; Tricks</h3><h4>Trow away all you uncommitted changes</h4><p>Just as it says, this command will trow away all your uncommitted changes:</p><pre>git reset --hard</pre><h4>Remove a file from git without removing it from computer</h4><p>Sometime using “git add” command you might end up adding files that you didn’t want to add.</p><p>If you are not careful during a “git add”, you may end up adding files that you didn’t want to commit. You should remove the staged version of the file, and then add the file to .gitignore to avoid making the same mistake a second time:</p><pre>git reset file_name<br>echo filename &gt;&gt; .gitignore</pre><h4>Edit a commit message</h4><p>It is very easy to fix a commit message</p><pre>git commit --amend -m &quot;New message&quot;</pre><p>Thank you for reading! Check out more articles like this, and other fun stuff I do on my GitHub page:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Join our community Slack and read our weekly Faun topics ⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da0c05db411f" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/understanding-git-basics-commands-tips-tricks-da0c05db411f">Understanding Git: basics, commands, tips &amp; tricks</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP and everything you need to know about it]]></title>
            <link>https://faun.pub/http-and-everything-you-need-to-know-about-it-8273bc224491?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8273bc224491</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Sun, 07 Oct 2018 15:06:03 GMT</pubDate>
            <atom:updated>2019-07-16T15:26:41.777Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6aNxPVn2fqCP_033WzUwXA.jpeg" /></figure><p>HTTP stands for Hypertext Transfer Protocol, and HTTP is the communication protocol used for browsing the web. This protocol uses a message based model where your client makes an HTTP request to a web server and that server responds with a resource which is displayed in the browser.</p><blockquote>Every HTTP interaction includes a request and a response. By its nature, HTTP is stateless.</blockquote><p><strong>Stateless </strong>means that all requests are separate from each other so every request must contain enough information on their own to fulfill the request. That means that each transaction of message based model of HTTP is processed separately from each other.</p><h4>URL</h4><p>The URL (Uniform Resource Locator) is probably the most known concept of the Web. It is also one of most important and useful concepts. URL is a web address used to identify resources on the Web.</p><blockquote>The idea of the web is structured around the resources, from its beginnings the Web was the platform for sharing text/HTML files, documents, images etc, and as such it can be considered a collection of resources.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*DTR8JpFZo31ht-Kd" /><figcaption>Example of an URL</figcaption></figure><p><strong>Protocol </strong>— Most often they are HTTP (or HTTPS for a secure version of HTTP).</p><p>Other notable protocols are:</p><ul><li>File Transfer Protocol (FTP) — is a standard<a href="https://en.wikipedia.org/wiki/Network_protocol"> </a>protocol used for transfering of<a href="https://en.wikipedia.org/wiki/Computer_file"> </a>files between a client and a server over a network.</li><li>Simple Mail Transfer Protocol (SMTP) is an standard for email transmission.</li></ul><p><strong>Domain </strong>— Name that is used to identify one or more IP addresses where the resource is located.</p><p><strong>Path </strong>—Specifies the resource location on the server. It uses the same logic as a resource location used on the device you are reading this article (i.e. /search/cars/VWBeetle.pdf or C:/my cars/VWBeetle.pdf).</p><p><strong>Parameters </strong>— Additional data used to identify or filter the resource on the server.</p><blockquote><strong>NOTE</strong></blockquote><blockquote>When searching for articles and more information about HTTP you may encounter the term URI (or uniform resource identifier). URI is sometimes being used instead of URL but mostly in formal specifications and by people who want to show off :)</blockquote><h4><strong>HTTP Requests</strong></h4><p>In HTTP, every request must have an URL address. Additionally, request needs a method. The four main HTTP methods are:</p><ul><li>GET</li><li>PUT</li><li>POST</li><li>DELETE</li></ul><p>I will explain these methods, and more, in HTTP Methods section of this article.</p><p>And these methods directly correspond to actions:</p><ul><li>read</li><li>update</li><li>create</li><li>delete</li></ul><p>All HTTP messages have one or more headers, followed by a optional message body. The body contains the data that will be sent with the request or the data received with the response.</p><p>First part of every HTTP request holds three items:</p><p><em>Example:</em></p><ul><li><em>GET /adds/search-result?item=vw+beetle HTTP/1.1</em></li></ul><p><em>When a URL contains a “?” sign means it contains a query. That means it sends parameters of the requested resource.</em></p><ol><li>First part is a method which tells which HTTP method is used. Most commonly used is the GET method. GET method retrieves a resource from the web server and since GET doesn’t have a message body nothing after the header is needed.</li><li>Second part is a requested URL.</li><li>Third part is a HTTP version being used. Version 1.1. is the most common version for most browsers, however, version 2.0 is taking over.</li></ol><p>There are also some other interesting things in a HTTP request:</p><p><strong>Referer header</strong> — tell the URL from which the request has originated.</p><p><strong>User-Agent header</strong> — additional information about the browser being used to generate the request.</p><p><strong>Host header </strong>— uniquely identify a host name, it is necessary when multiple web pages are hosted on the same server.</p><p><strong>Cookie header</strong> — submit additional parameters to the client.</p><h4><strong>HTTP Responses</strong></h4><p>Just like in HTTP requests HTTP responses also consist of three items:</p><p><em>Example:</em></p><p><em>HTTP/1.1 200 OK</em></p><ol><li>First part is the HTTP version being used.</li><li>Second part is the numeric code of the result for the request.</li><li>Third part is a textual description of the second part.</li></ol><p>There are some other interesting things in a HTTP response:</p><p><strong>Server header</strong> — information which web server software is being used.</p><p><strong>Set-Cookie header</strong> — issues the cookie to the browser.</p><p><strong>Message body</strong> — it is common for a HTTP response to hold a message body.</p><p><strong>Content-Length header</strong> — tells the size of the message body in bytes.</p><h4>HTTP Methods</h4><p>Most common methods are GET and POST, however there are more of them.</p><p><strong>GET</strong> — used to request data from a specified resource where data is not modified it in any way as GET requests do not change the state of resource.</p><p><strong>POST</strong> — used to send data to a server to create a resource.</p><p><strong>PUT — </strong>method to update existing resource on a server by using the content in body of the request.</p><p><strong>HEAD </strong>— this method has the same function as GET method but with a difference that the return of a HEAD method should not contain body in the response. However, the return will contain same headers as if GET was used. HEAD method is used to check if the resource is present prior of making a GET request.</p><p><strong>TRACE — </strong>method designed for diagnostic purposes. Response will contain in its body the exact content of the request message.</p><p><strong>OPTIONS</strong> — this<strong> </strong>method is used to describe the communication options (HTTP methods) that are available for the target resource.</p><p><strong>PATCH — </strong>The PATCH method is used to apply partial modifications to a resource.</p><p><strong>DELETE — </strong>The DELETE method deletes the specified resource.</p><h4><strong>REST</strong></h4><p>Representational state transfer (REST) is a architecture style where request and responses contain representation of the current state of the systems resource.</p><p><em>“Normal” way:</em></p><ul><li><a href="http://carapp.com/search?make=wv&amp;model=beetle"><em>http://carapp.com/search?make=wv&amp;model=beetle</em></a></li></ul><p><em>REST-style:</em></p><ul><li><a href="http://carapp.com/search/vw/beetle"><em>http://carapp.com/search/vw/beetle</em></a></li></ul><p>I’ll be talking more about REST APIs in my other article so please feel free to check it out.</p><h4><strong>HTTP Headers</strong></h4><p>There are three main components that make up the request/response structure. This includes:</p><ul><li>First line</li><li>Headers</li><li>Body/Content</li></ul><p>We already talked about the first line in HTTP requests and responses, body function was mentioned and now we will talk about HTTP headers.</p><p>The HTTP headers are added after the First line and are defined as name: value pairs separated by a colon. HTTP headers are used to send additional parameters along with the request or response.</p><p>As we already said, the body of the message includes the data to be sent with the request or the data received along with the response.</p><p>There are different types of headers we group based on their usage into 4 broad categories:</p><ul><li><strong>General header</strong> — Headers that can be used in both requests and response messages and that are independent of the data being exchanged.</li><li><strong>Request header</strong> — These headers define parameters for the data requested or parameters that give important information about the client making the request.</li><li><strong>Response header</strong> — These headers contain information about the incoming response.</li><li><strong>Entity header</strong> — The entity headers describe the content that makes up the body of the message.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/0*0BI1BEJpajUiJ_4R" /><figcaption>Types of headers</figcaption></figure><h4><strong>HTTP status codes</strong></h4><p>Every HTTP response message must contain a HTTP status code in its first line, telling us the result of the request.</p><p>There are five groups of status codes which are grouped by the first digit:</p><ul><li>1xx — Informational.</li><li>2xx — The request was successful.</li><li>3xx — The client is redirected to a different resource.</li><li>4xx — The request contains an error of some kind.</li><li>5xx — The server encountered an error fulfilling the request.</li></ul><blockquote>Full list of HTTP Status Response Codes and their explanation: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status">https://developer.mozilla.org/en-US/docs/Web/HTTP/Status</a></blockquote><h3>HTTPS (Hypertext Transfer Protocol Secure)</h3><p>Secure version of HTTP protocol is HyperText Transfer Protocol Secure (HTTPS). HTTPS provides encrypted communication between a browser (client) and the website (server).</p><p>In HTTPS, the communication protocol is encrypted using Transport Layer Security (TLS) or Secure Sockets Layer (SSL).</p><p>Protocol is therefore also often called as HTTP over TLS, or HTTP over SSL.</p><p>Both the TLS and SSL protocols use an asymmetric encryption system. Asymmetric encryption system uses a public key (encryption key) and a private key (decryption keys) to encrypt a message. Anyone can use the public key to encrypt a message. However, private keys are secret, and that means that only the intended receiver can decrypt the message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*pB_y5GVIF_O_z4lw.gif" /><figcaption>Example of asymmetric encryption system</figcaption></figure><h4>SSL/TLS handshake</h4><p>When you request a HTTPS connection to a website, the website sends its SSL certificate to your browser. That proces where your browser and website initiate communication is called the “SSL/TLS handshake”. The SSL/TLS handshake involves a series of steps where browser and website validate each other and start communication through the SSL/TLS tunnel.</p><p>As you probably noticed, when a trusted secure tunnel is used during in a HTTPS connection, the green padlock icon is displayed in the browsers address bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/0*g7q-rF8JTGp7fs19" /><figcaption>Example of one of my secure pages</figcaption></figure><h4><strong>Benefits of HTTPS</strong></h4><p>The major benefits of a HTTPS are:</p><ul><li>Customer information, like credit card numbers and other sensitive information, is encrypted and cannot be intercepted.</li><li>Visitors can verify you are a registered business and that you own the domain.</li><li>Customers know they are not suppose to visit sites without HTTPS, and therefore, they are more likely to trust and complete purchases from sites that use HTTPS.</li></ul><p>Thank you for reading! Check out more articles like this, and other fun stuff I do on my Github profile:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*BXSslt9YvJYE1d2R" /></figure><p><strong>Join our community Slack and read our weekly Faun topics ⬇</strong></p><p><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmedium">Join a Community of Aspiring Developers.Get must-read articles, learn new technologies for free, chat with like-minded people, get job offers, listen to podcasts and more</a></p><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8273bc224491" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/http-and-everything-you-need-to-know-about-it-8273bc224491">HTTP and everything you need to know about it</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up a local debugging environment in PHP]]></title>
            <link>https://medium.com/free-code-camp/set-up-xdebug-phpstorm-in-php5-7-6a8386304fc6?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a8386304fc6</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Tue, 28 Aug 2018 19:18:43 GMT</pubDate>
            <atom:updated>2018-11-14T17:14:41.916Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PPymPtLj4ITAaE_ei9ulw.jpeg" /></figure><p>Recently I started focusing more on PHP, and I needed to set up a local debugging environment. Since there aren’t many tutorials on how to do it, I’ve encountered some problems on how to get the setup up and running.</p><p>By combining a few tutorials and spending a few hours on several forums, I came up with this text. The app I am working on runs inside of a Vagrant box which is shaky somehow. It collapses from time to time so I have to redo this setup, and therefore I know this setup works :).</p><blockquote><em>The goal of this tutorial is to get the Xdebug working on your server and then point PhpStorm to Xdebug.</em></blockquote><p>Let’s get started.</p><h4>Prerequisites</h4><p>If you don’t have Xdebug installed on your server but are using PHP7, you can do it by using Tailored Installation Instructions from the official Xdebug site <a href="https://xdebug.org/wizard.php">here</a>.</p><p>However, as my project is using PHP5, I’ve had to do it the old fashioned way: <em>looking it up on forums</em>.</p><p>In this tutorial I will assume you have Xdebug installed.</p><h3>Getting started</h3><p>First you need to find the location of the xdebug.so file on your server. Copy the location somewhere as you will use it later on.</p><pre>locate xdebug.so</pre><p>Now you need to navigate inside your server to a location: /etc/php5/apache2/conf.d/ and check if the file 20-xdebug.ini exists there. If it doesn’t exist, create one. You can create one using commands such as touch, vim, vi, nano and so on.</p><p>You can see my project is made in PHP5, so change your folder name/location according to your version of PHP.</p><p>Now open the 20-xdebug.ini file and paste this in:</p><pre><strong>zend_extension=”location to your xdebug.so file”</strong></pre><pre>xdebug.remote_enable=1</pre><pre>xdebug.remote_port=9000</pre><pre><strong>xdebug.remote_host=”your localhost address”</strong></pre><pre>xdebug.remote_autostart=1</pre><pre>xdebug.remote_connect_back=0</pre><pre>xdebug.remote_handler=”dbgp”</pre><pre>xdebug.remote_mode=req</pre><pre>xdebug.remote_cookie_expire_time=-9999</pre><pre>xdebug.remote_log=”/tmp/xdebug.log”</pre><pre>xdebug.var_display_max_depth=15</pre><pre>xdebug.profiler_enable=0</pre><pre><strong>xdebug.idekey=”phpstorm”</strong></pre><p>From the explanation of the 20-xdebug.ini file that is written bellow, you will see that some of these settings are not needed, or that they are set to a default value. I keep these values in the 20-xdebug.ini file because they are good to know.</p><h4><strong>Explanation of the 20-xdebug.ini file:</strong></h4><ul><li>xdebug.remote_enable — controls whether Xdebug should try to contact a debug client which is listening on the host and port as set with the settings</li><li>xdebug.remote_port — The port to which Xdebug tries to connect on the remote host. Default is 9000.</li><li>xdebug.remote_host — Selects the host where the debug client is running. Default is localhost.</li><li>xdebug.remote_autostart — when this setting is set to 1, Xdebug will attempt to start a remote debugging session and try to connect to a client.</li><li>xdebug.remote_connect_back — If enabled, the <a href="https://xdebug.org/docs/all_settings#remote_host">xdebug.remote_host</a> setting is ignored and Xdebug will try to connect to the client that made the HTTP request. Default is 0.</li><li>xdebug.remote_handler — Can be either ‘php3’ which selects the old <a href="http://www.php.net/manual/en/debugger.php">PHP 3 style debugger</a> output, ‘gdb’ which enables the GDB like debugger interface or ‘dbgp’ — the <a href="http://xdebug.org/docs-dbgp.php">debugger protocol</a>. The DBGp protocol is the only supported protocol. Default is dbgp.</li><li>xdebug.remote_mode — Selects when a debug connection is initiated. This setting can have two different values: req — Xdebug will try to connect to the debug client as soon as the script starts. jit — Xdebug will only try to connect to the debug client as soon as an error condition occurs.</li><li>xdebug.remote_cookie_expire_time — This setting can be used to increase (or decrease) the time that the remote debugging session stays alive via the session cookie. Default is 3600.</li><li>xdebug.remote_log — If set to a value, it is used as filename to a file to which all remote debugger communications are logged.</li><li>xdebug.var_display_max_depth — Controls how many nested levels of array elements and object properties are when variables are displayed with either <a href="https://xdebug.org/docs/all_functions#xdebug_var_dump">xdebug_var_dump()</a>, <a href="https://xdebug.org/docs/all_settings#show_local_vars">xdebug.show_local_vars</a> or through <a href="https://xdebug.org/docs/execution_trace">Function Traces</a>. Default is 3.</li><li>xdebug.profiler_enable — Enables Xdebug’s profiler which creates files in the <a href="https://xdebug.org/docs/all_settings#profiler_output_dir">profile output directory</a>. Default is 0.</li><li>xdebug.idekey — Controls which IDE Key Xdebug should pass on to the DBGp debugger handler. The default is based on environment settings.</li></ul><p>Save the file and restart the Apache server:</p><pre>sudo service apache2 restart</pre><h3>Xdebug and PhpStorm</h3><p>First you need to open PhpStorm and select Run &gt; Edit Configuration. There you should select + (Add new configuration) and choose “PHP Remote Debug”.</p><p>Change the name of the configuration from “Unnamed” to something else. I’ve chosen the name “Tutorial” for obvious reasons ;) Then check the “Filter debug connection by IDE key”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1haOPxcvIE8H-z1n" /></figure><p>Select the Servers button (…) and then select + (Add new Server).</p><ul><li>Rename your Server to something more soothing. I’ve chosen “localbackend1” in this example.</li><li>In Host field type in your localhost. Set Debugger to Xdebug.</li><li>Select “Use path mapping” and point to the folder of your app.</li></ul><p>Click on Apply. You will be returned to the previous window where you will see that the IDE key is editable, and now you need to enter a key. I always put “phpstorm” or something similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*WoQahiQhIuCNjbIs" /></figure><p>You will notice that the IDE key “phpstorm” is already in your 20-xdebug.ini file:</p><pre>xdebug.idekey=”phpstorm”</pre><p>You should also select Single instance only as it will stop you from launching more than one instance of the same project.</p><p>Click on to Apply and Voilà!</p><p>You are done with the setup!</p><h3><strong>Testing and wrapping up</strong></h3><p>Now you are complete. You should see the Tutorial configuration we created in the upper right corner of PhpStorm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/0*tY0aIcfOHQqO_1Ck" /></figure><p>You can test it by setting a breakpoint in your project. Click on the “bug” button in the configuration window of Tutorial and then run your app.</p><p>That should be all, if everything is OK you should hit the breakpoint.</p><p>And remember, nothing beats the feeling of seeing run time values while debugging.</p><p>Thank you for reading! Check out more articles like this, and other fun stuff I make on my Github profile:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a8386304fc6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/set-up-xdebug-phpstorm-in-php5-7-6a8386304fc6">How to set up a local debugging environment in PHP</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Threat modeling]]></title>
            <link>https://faun.pub/threat-modeling-317b375548da?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/317b375548da</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 08:20:36 GMT</pubDate>
            <atom:updated>2019-07-16T15:03:45.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ifhHAX50eGNx801vofFtPQ.jpeg" /></figure><p>Digital attacks are more and more frequent, and the first step in securing your app is to understand the threats and how to counter them.</p><p>Threat modeling is an approach that analyses the security of an application. It is a structured way to identify, quantify and mitigate the security risks in an application.</p><p>You are about to read a short briefing I wrote for myself some time ago, made up from information I’ve collected by dissecting several other articles. The idea behind this article is for it to act as an reminder and to be as short as possible but still hold relevant information.</p><p>So with that being said let’s write the most common definition of threat modeling:</p><blockquote>Threat modeling is a security process with goals to identify objectives and vulnerabilities and then define countermeasures to prevent or lessen the effects of threats to the system.</blockquote><p>I’ve also read somewhere that threat modeling gives answers to these four questions:</p><ul><li><em>What are we working on?</em></li><li><em>What can go wrong?</em></li><li><em>What are we going to do about it?</em></li><li><em>Did we do a good job?</em></li></ul><p>And I couldn’t agree more. That’s why threat modeling is composed of four parts, where each part answers one question:</p><ul><li><em>Decomposing the application.</em></li><li><em>Determining the threats.</em></li><li><em>Determine counter measures and mitigations (reducing the danger).</em></li><li><em>Rank threats.</em></li></ul><h3>Decomposing the application</h3><p>Goal of this step is to understand the application by decomposing it into parts and seeing how those parts interact with external entities. Way to do this is to gather information and documentation by mapping application’s entry points, elements/assets and dependencies.</p><ul><li>Decompose the application by drawing a diagram of various components in the application. You can do this with Data Flow Diagrams.</li><li>Identifying entry points — Software entry points may serve as entry points of an attacker( login pages, search fields, HTTP requests etc.). It is essential that all entry points are identified and documented.</li><li>Identifying the elements/assets — that have a value, and therefore a risk of being attacked. An asset can be in a form of data like a list of customer information, it can also be in different forms: overall application availability, organizations reputation.</li><li>Dependencies are parts of the app that lay outside of the application’s code. As these items are outside of your control they may pose a threat if they are not properly maintained so identifying these dependencies will minimize the application’s overall risk.</li></ul><h3>Determining threats</h3><p>Determining threats can be done by threat categorization STRIDE. STRIDE is an approach from the attackers perspective, and it is used to determine threats. While there are other approaches such as ASF (Application security framework — an approach from the defenders perspective to determine countermeasures), in this article I will be focusing on STRIDE.</p><blockquote>STRIDE categorization outlines six most common types of threats and their countermeasures.</blockquote><h4>STRIDE</h4><ol><li><strong>S</strong>poofing identity — Impersonating someone or something else.</li><li><strong>T</strong>empering with data — Modifying some data on disk, network, memory.</li><li><strong>R</strong>eputation — Denial of proof of some action.</li><li><strong>I</strong>nformation disclosure — Exposing information to someone not authorized to see it.</li><li><strong>D</strong>enial of service — Deny or degrade service to users.</li><li><strong>E</strong>levation of privileges — Unauthorized gaining of more rights than originally intended.</li></ol><h3>Determining countermeasures</h3><p>Every threat from STRIDE has a countermeasure.</p><ol><li>Authentication (for Spoofing) — Establishing a verifiable identity.</li><li>Data protection (for Tempering with data) — Maintaining data and ensuring consistency of data and methods that work on data.</li><li>Confirmation (for Reputation) — Every action against the application must be logged.</li><li>Confidentiality ( for Information disclosure) — Restricting access to system and data.</li><li>Availability(for Dos) — Leverage levels of redundancies.</li><li>Authorization (for Elevation of privileges) — Limiting access to data, actions and services.</li></ol><h3>Rank Threats</h3><p>To tackle the problem of ranking threats Microsoft devised a risk assessment model called DREAD, a model which provides five rating categories for each threat. In the beginning they used the rating from 1 to 10, ex. for every threat in each category a rating from 1 do 10 would be given.</p><p>However, as different people selected very different numbers, there was a shift away from DREAD ratings within high number ranges towards some simpler classification with 4 different levels of risk:</p><ul><li>1: low</li><li>2: medium</li><li>3: high</li><li>4: critical</li></ul><p>Sum of all ratings for a given threat is used to prioritize it among other threats.</p><p>The categories to rank for every threat are:</p><ul><li><strong>D</strong>amage — how bad would an attack be?</li><li><strong>R</strong>eproducibility — how easy is it to reproduce the attack?</li><li><strong>E</strong>xploitability — how much work is it to launch the attack?</li><li><strong>A</strong>ffected users — how many people will be impacted?</li><li><strong>D</strong>iscoverability — how easy is it to discover the threat?</li></ul><blockquote>For every threat in each category a rating from 1 do 4 is given and the sum of all ratings for a given threat is used to prioritize it among other threats.</blockquote><p>Up until now we decomposed the application, analysed functionalities, determined possible risks and identified weak points that could be exploited. Then we determined the countermeasures and used DREAD to rank the risks. The only thing left is to act accordingly in solving those risks.</p><p>Check out more articles like this, and other fun stuff I do on my Github profile:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*QvYdq9pp5sXwyBum" /></figure><p><strong>Join our community Slack and read our weekly Faun topics ⬇</strong></p><p><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmedium">Join a Community of Aspiring Developers.Get must-read articles, learn new technologies for free, chat with like-minded people, get job offers, listen to podcasts and more</a></p><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=317b375548da" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/threat-modeling-317b375548da">Threat modeling</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An introduction to testing in Python]]></title>
            <link>https://medium.com/@goranaviani/testing-in-python-c6b903eb247d?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6b903eb247d</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Mon, 25 Jun 2018 14:11:46 GMT</pubDate>
            <atom:updated>2019-01-21T23:47:44.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQQFG3SfXfX6VkkmC3quiQ.jpeg" /></figure><p><em>You have just finished writing a piece of code and you are wondering what to do. Will you submit a pull request and have your teammates review the code, or will you manually test the code? You should do all these things but with an additional step: you need to unit test your code to make sure that the code works as intended.</em></p><p>Unit tests can pass or fail, and that makes them a great technique to check your code. In this tutorial I will demonstrate how to write unit tests in Python and how easy it is to get them going in your own project.</p><h3>Getting started</h3><p>The best way you can understand testing is if you do it hands-on. For that purpose, in a file named name_function.py, I will write a simple function that takes a first and last name, and returns a full name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73ecc9e63a3eaacd298ae0b8b3aaaf49/href">https://medium.com/media/73ecc9e63a3eaacd298ae0b8b3aaaf49/href</a></iframe><p>The function formatted_name() takes the first and the last name and combines them with a space between to form a full name. It then capitalizes the first letter of every word. To check that this code works, you need to write some code that uses this function. In names.py I will write some simple code that lets users enter their first and last names:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/809c69a75b36042a3582c82409b86d45/href">https://medium.com/media/809c69a75b36042a3582c82409b86d45/href</a></iframe><p>This code imports formatted_name() from name_function.py and on running, allows the user to enter a series of first and last names and shows the formatted full names.</p><h3>Unit test and Test cases</h3><p>There is a module in Python’s standard library called unittest which contains tools for testing your code. Unit testing checks if all specific parts of your function’s behavior are correct, which will make integrating them together with other parts much easier.</p><p>Test case is a collection of unit tests which together proves that a function works as intended, inside a full range of situations in which that function may find itself and that it’s expected to handle. Test case should consider all possible kinds of input a function could receive from users, and therefore should include tests to represent each of these situations.</p><h3>Passing a test</h3><p>Here’s a typical scenario for writing tests:</p><p>First you need to create a test file. Then import the unittest module, define the testing class that inherits from unittest.TestCase, and lastly, write a series of methods to test all the cases of your function’s behavior.</p><p>There’s a line by line explanation below the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/790c636f6e131733bd1de2b0834d3382/href">https://medium.com/media/790c636f6e131733bd1de2b0834d3382/href</a></iframe><p>First, you need to import a unittest and the function you want to test, formatted_name() . Then you create a class, for example NamesTestCase, that will contain tests for your formatted_name() function. This class inherits from the class unittest.TestCase.</p><p>NamesTestCase contains a single method that tests one part of formatted_name() . You can call this method test_first_last_name().</p><blockquote>Remember that every method that starts with “test_” will be run automatically when you run test_name_function.py.</blockquote><p>Within test_first_last_name() test method, you call the function you want to test and store a return value. In this example we are going to call formatted_name() with the arguments “pete” and “seeger” , and store the result in the resulting variable.</p><p>In the last line we will use the assert method. The assert method verifies that a result you received matches the result you expected to receive. And in this case we know that formatted_name() function will return full name with capitalized first letters, so we expect the result “Pete Seeger”. To check this, the unittest’s assertEqual() method is being used.</p><pre>self.assertEqual(result, “Pete Seeger”)</pre><p>This line basically means: Compare the value in the resulting variable with “Pete Seeger” and if they are equal it’s OK, but if they are not let me know.</p><p>On running test_name_function.py you are expected to get a OK meaning that the test has passed.</p><pre>Ran 1 test in 0.001s</pre><pre>OK</pre><h3>Failing a test</h3><p>To show you what a failing test looks like I’m going to modify a formatted_name() function by including a new middle name argument.</p><p>So I’m going to rewrite the function to look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66a4ffd806edc3f11d76d319aa83acce/href">https://medium.com/media/66a4ffd806edc3f11d76d319aa83acce/href</a></iframe><p>This version of formatted_name() will work for people with middle names, but when you test it you will see that the function is broken for people who don’t have a middle name.</p><p>So when you run the test_name_function.py you will get the output that looks something like this:</p><pre>Error<br>Traceback (most recent call last):</pre><pre>File “test_name_function.py”, line 7, in test_first_last_name<br>    result = formatted_name(“pete”, “seeger”)</pre><pre>TypeError: formatted_name() missing 1 required positional argument: ‘middle_name’</pre><pre>Ran 1 test in 0.002s</pre><pre>FAILED (errors=1)</pre><p>In the output you will see information that will tell you all you need to know where the test fails:</p><ul><li>First item in the output is the Error telling you that at least one test in test case resulted in an error.</li><li>Next you’ll see the file and method in which the error occurred.</li><li>After that you will see the line in which the error occurred.</li><li>And what kind of error it is, in this case we are missing 1 argument “middle_name”.</li><li>You will also see the number of run tests, the time needed for the tests to complete, and a textual message that represents the status of the tests with number of errors that occurred.</li></ul><h3>What to do when the test has failed</h3><blockquote>A passing test means the function is behaving according to what’s expected from it. However, a failing test means there’s more fun ahead of you.</blockquote><p>I’ve seen couple of programmers that prefer to change the test instead of improving the code — but don’t to that. Spend a little more time to fix the issue, as it will help you to better understand the code and save time in the long run.</p><p>In this example, our function formatted_name() first required two parameters, and now as it is rewritten it requires one extra: a middle name. Adding a middle name to our function broke the desired behavior of it. Since the idea is not to make changes to the tests, the best solution is to make middle name optional.</p><p>After we do this the idea is to make the tests pass when the first and last name are used, for example “Pete Seeger”, as well as when first, last and middle names are used, for example “Raymond Red Reddington”. So let’s modify the code of formatted_name() once again:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/718af69b7843e8c0d0d8ca532de9fac8/href">https://medium.com/media/718af69b7843e8c0d0d8ca532de9fac8/href</a></iframe><p>Now the function should work for names with and without the middle name.</p><p>And to make sure it still works with “Pete Seeger” run the test again:</p><pre>Ran 1 test in 0.001s</pre><pre>OK</pre><blockquote>And this is what I intended to show you: It’s always better to make changes to your code to fit your tests than other way around. Now the time has come to add a new test for names that do have a middle name.</blockquote><h3>Adding new tests</h3><p>Write a new method to the NamesTestCase class that will test for middle names:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bc992f9442f37613ff579ad7834b7df/href">https://medium.com/media/3bc992f9442f37613ff579ad7834b7df/href</a></iframe><p>After you run the test, both tests should pass:</p><pre>Ran 2 tests in 0.001s</pre><pre>OK</pre><blockquote>Bra gjort!</blockquote><blockquote>Well done!</blockquote><p>You have written your tests to check if the function works using names with or without a middle name. Stay tuned for part 2 where I’ll talk more about testing in Python.</p><p>This and other fun stuff I do can be found on my Github: <a href="https://github.com/GoranAviani">https://github.com/GoranAviani</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6b903eb247d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to document your Django project using the Sphinx tool]]></title>
            <link>https://medium.com/free-code-camp/sphinx-for-django-documentation-2454e924b3bc?source=rss-3ade16c9bf1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2454e924b3bc</guid>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Goran Aviani]]></dc:creator>
            <pubDate>Fri, 08 Jun 2018 06:26:25 GMT</pubDate>
            <atom:updated>2018-10-22T22:46:55.734Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBjEUaDShrMB9RFqbl_saQ.jpeg" /></figure><p>I recently visited a company where I had a nice talk with one of its employees. We talked about technology and programming. Then we touched the subject of project documentation. Specifically how React does it automatically but Django doesn’t. That made me think I should do some automatic documentation for my Django projects.</p><p>I couldn’t find any relevant documentation on how its done, so it took me a little longer than I originally planned. Not because it was hard, but because I found that the Sphinx official documentation and other resources to be outdated or obscure.</p><p>So today I have made a simple but comprehensive tutorial that explains how to make Django documentation using the Sphinx documentation tool in Ubuntu.</p><h4><strong>Install Sphinx</strong></h4><p>First you should enter the virtual environment for your Django project.</p><p>Installing Sphinx is quite straightforward using pip3 (pip for Python 3):</p><pre>pip3 install sphinx</pre><h4>Create a documentation directory</h4><p>Once you’ve installed Sphinx, you will need to create the document root folder. This folder will hold your documentation and other files you will need (images, about pages, and so on…).</p><p>Create your document root folder in your project main folder and name it /docs.</p><p>To start Sphinx, run this command inside your /docs folder:</p><pre>sphinx-quickstart</pre><p>You’ll have a lot of options now. In most cases you can simply retype the default option, but there are some options you need to pay attention to.</p><p>This is how I answered:</p><pre>Welcome to the Sphinx 1.7.5 quickstart utility.</pre><pre>Please enter values for the following settings (just press Enter to</pre><pre>accept a default value, if one is given in brackets).</pre><pre>Selected root path: .</pre><pre>You have two options for placing the build directory for Sphinx output.</pre><pre>Either, you use a directory “_build” within the root path, or you separate</pre><pre>“source” and “build” directories within the root path.</pre><pre>&gt; Separate source and build directories (y/n) [n]: <strong>n</strong></pre><pre>Inside the root directory, two more directories will be created; “_templates”</pre><pre>for custom HTML templates and “_static” for custom stylesheets and other static</pre><pre>files. You can enter another prefix (such as “.”) to replace the underscore.</pre><pre>&gt; Name prefix for templates and static dir [_]: <strong>_</strong></pre><pre>The project name will occur in several places in the built documentation.</pre><pre>&gt; Project name: <strong>Your_project_name</strong></pre><pre>&gt; Author name(s): <strong>Goran Aviani</strong></pre><pre>&gt; Project release []: <strong>1.0</strong></pre><pre>If the documents are to be written in a language other than English,</pre><pre>you can select a language here by its language code. Sphinx will then</pre><pre>translate text that it generates into that language.</pre><pre>For a list of supported codes, see</pre><pre><a href="http://sphinx-doc.org/config.html#confval-language.">http://sphinx-doc.org/config.html#confval-language.</a></pre><pre>&gt; Project language [en]: <strong>en</strong></pre><pre>The file name suffix for source files. Commonly, this is either “.txt”</pre><pre>or “.rst”. Only files with this suffix are considered documents.</pre><pre>&gt; Source file suffix [.rst]:<strong> .rst</strong></pre><pre>One document is special in that it is considered the top node of the</pre><pre>“contents tree”, that is, it is the root of the hierarchical structure</pre><pre>of the documents. Normally, this is “index”, but if your “index”</pre><pre>document is a custom template, you can also set this to another filename.</pre><pre>&gt; Name of your master document (without suffix) [index]: <strong>index</strong></pre><pre>Sphinx can also add configuration for epub output:</pre><pre>&gt; Do you want to use the epub builder (y/n) [n]: <strong>n</strong></pre><pre>Indicate which of the following Sphinx extensions should be enabled:</pre><pre>&gt; autodoc: automatically insert docstrings from modules (y/n) [n]: <strong>y</strong></pre><pre>&gt; doctest: automatically test code snippets in doctest blocks (y/n) [n]: <strong>y</strong></pre><pre>&gt; intersphinx: link between Sphinx documentation of different projects (y/n) [n]: <strong>n</strong></pre><pre>&gt; todo: write “todo” entries that can be shown or hidden on build (y/n) [n]: <strong>y</strong></pre><pre>&gt; coverage: checks for documentation coverage (y/n) [n]: <strong>y</strong></pre><pre>&gt; imgmath: include math, rendered as PNG or SVG images (y/n) [n]: <strong>y</strong></pre><pre>&gt; mathjax: include math, rendered in the browser by MathJax (y/n) [n]: <strong>n</strong></pre><pre>&gt; ifconfig: conditional inclusion of content based on config values (y/n) [n]: <strong>n</strong></pre><pre>&gt; viewcode: include links to the source code of documented Python objects (y/n) [n]: <strong>n</strong></pre><pre>&gt; githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: <strong>n</strong></pre><pre>A Makefile and a Windows command file can be generated for you so that you</pre><pre>only have to run e.g. `make html’ instead of invoking sphinx-build</pre><pre>directly.</pre><pre>&gt; Create Makefile? (y/n) [y]: <strong>y</strong></pre><pre>&gt; Create Windows command file? (y/n) [y]: <strong>y</strong></pre><pre>Creating file ./conf.py.</pre><pre>Creating file ./index.rst.</pre><pre>Creating file ./Makefile.</pre><pre>Creating file ./make.bat.</pre><pre>Finished: An initial directory structure has been created.</pre><pre>You should now populate your master file ./index.rst and create other documentation</pre><pre>source files. Use the Makefile to build the docs, like so:</pre><pre>make builder</pre><pre>where “builder” is one of the supported builders, e.g. html, latex or linkcheck.</pre><h4>Django connection</h4><p>In your project folder, find /docs/conf.py and inside it, somewhere near the top of the file, find “#import os”. Just below it, write this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/521f6f509014c428b0a9ae4165cfa52f/href">https://medium.com/media/521f6f509014c428b0a9ae4165cfa52f/href</a></iframe><p><strong>Now there are two ways you can proceed:</strong></p><ol><li>You can use <em>sphinx-apidoc</em><strong> </strong>to generate completely automatic documentation, or</li><li>You can build your own modules that will show in the documentation.</li></ol><p>In this tutorial I am going to show you how to do it both ways.</p><h4>1. Sphinx-apidoc</h4><p>This is the simpler method where you just need to navigate to your /docs folder and execute:</p><pre>sphinx-apidoc -o . ..</pre><p>Now you need to build your documentation by running the command:</p><pre>make html</pre><p>Navigate to <em>Your_project_folder/docs/_build/html </em>and open<em> index.html. </em>This is the index page of your documentation.</p><h4>2. Building your own modules</h4><p>This is the slightly more complicated way, but will give you much more freedom in organizing your documentation.</p><p>Now you’ll want to make documentation about your views, modules etc. But first let me show you an easy example, just so you understand the logic of this part:</p><p>Go in your /docs folder and create a new folder named “/modules”. Inside it create a file named all-about-me.rst:</p><pre>mkdir modulesf<br>touch modules/all-about-me.rst</pre><p>Inside all-about-me.rst write something like this:</p><pre>############<br>All about me<br>############<br><br>I’m Goran Aviani, a Django developer.</pre><p>Now you’ve created something to show in your documentation, but still you don’t have an actual place to show it. Go back to the /docs folder and open index.rst and just bellow this code</p><pre>.. toctree::<br>   :maxdepth: 2<br>   :caption: Contents:</pre><p>Add this:</p><pre>modules/all-about-me.rst</pre><p>Make it so there is a blank line between the upper code and the added line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9e1678fb073d664ed96ab97ad675924/href">https://medium.com/media/b9e1678fb073d664ed96ab97ad675924/href</a></iframe><p>Now you need to build your documentation. Change the location to the folder that contains the Makefile ( that is the /docs folder). Then run in the terminal:</p><pre>make html</pre><p>You will find your documentation in</p><blockquote>Your_project_folder/docs/_build/html and open index.html</blockquote><p>You can do the same for your Django views:</p><p>Inside the /modules folder, create the views.rst file.</p><pre>touch views.rst</pre><p>Inside the views.rst file write this:</p><pre>Views<br>======</pre><pre>.. automodule:: yourapp.views<br>   :members:<br>   :undoc-members:</pre><p>Inside index.rst, just under modules/all-about-me.rst, add this:</p><pre>modules/views.rst</pre><p>Now you again need to build your documentation by running “make html” inside your /docs folder:</p><pre>make html</pre><p>Get the idea? First you create the .rst file and then you put it inside index.rst so it can be displayed on index.html page.</p><p>You can make same thing for your models. Go in your /modules folder and create models.rst file.</p><pre>touch models.rst</pre><p>You can add something like this in your models.rst file:</p><pre>Models<br>=======</pre><pre>.. automodule:: yourapp.models<br>   :members:<br>   :undoc-members:</pre><p>Inside index.rst just under modules/views.rst paste:</p><pre>modules/models.rst</pre><p>Inside your /docs folder run:</p><pre>make html</pre><h4>Documentation test</h4><p>You can test your documentation by running this code inside your /docs folder:</p><pre>make linkcheck</pre><p>Voilà! You are done!</p><p>This is my first public tutorial, so give me a few claps if you like it :)</p><p>Check out more articles like this, and other fun stuff I do on my Github profile:<a href="https://github.com/GoranAviani"> https://github.com/GoranAviani</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2454e924b3bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/sphinx-for-django-documentation-2454e924b3bc">How to document your Django project using the Sphinx tool</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>