<?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 Deyber Castañeda on Medium]]></title>
        <description><![CDATA[Stories by Deyber Castañeda on Medium]]></description>
        <link>https://medium.com/@garzondeiber6?source=rss-3c327c0ccbc5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3B8AKNR62a6pODOcFLjJ3A.jpeg</url>
            <title>Stories by Deyber Castañeda on Medium</title>
            <link>https://medium.com/@garzondeiber6?source=rss-3c327c0ccbc5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 11:48:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@garzondeiber6/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[Mentor Matching Machine: Holberton Final Project]]></title>
            <link>https://garzondeiber6.medium.com/mentor-matching-machine-holberton-final-project-b5853fa15b2a?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5853fa15b2a</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Thu, 25 Mar 2021 06:38:13 GMT</pubDate>
            <atom:updated>2021-03-25T17:50:07.515Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*HO9UVTJW29gBUL3RS8vKaQ.jpeg" /></figure><p>These past 9 months at <a href="https://www.holbertonschool.com/co/en">Holberton</a> have been one of toughest and most exciting experience I have ever had thus far. I have achieved a lot of goals and nothing better to end this process than applying the knowledge obtained in a final project.</p><blockquote>Tell me and I forget; Teach me and I may remember; Involve me and I learn.<br>-Confucius</blockquote><p>For this final project I was part of an amazing team named MVD composed by:</p><ul><li>Valentina Jaramillo: Front-end</li><li>Marcos Pimienta: Front-end</li><li>David Arias: Back-end and DevOps</li><li>Deyber Castañeda(me): Back-end</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*4_kTdJ0D7jJexjbySECj3g.jpeg" /></figure><p>Since our project is integrated with other one from the same company, it was also fundamental the presence of our two peers:</p><ul><li>Ana Ruth Morales</li><li>Sebastian Orozco</li></ul><h3>Motivation</h3><p>From the beginning we all as a team were looking for a project that would allows us to learn new things and create a positive impact in the company that we were looking to work with in this stage. One of our main options was <a href="https://www.techstars.com/">Techstars</a>, a company that we had heard before and that had great projects offered. I personally identified myself with this company for their believing that great ideas can come from anywhere and that collaboration drives innovation.</p><p>After matching with Techstars we started to work on our Mentor Matching Machine, a web application to optimize the matching between mentors and companies. Our mission was to automate this process with a simple algorithm and a super minimalist interface to free up staff time from data entry to activities that add more value to the startups.</p><h3>Minimalist Design</h3><p>“Less is more” approach was fundamental in the UX/UI of the application. For the user interface were used ReactJS and CSS3. These technologies was selected because guarantee quickly rendering, facilitate advanced maintenance and boost productivity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*03vZKzgG1VeGpXtN2ZcCog.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vr0yjBqVW-ETYySt0xI0bw.jpeg" /></figure><h3>Optimal API</h3><p>To manage the data and implement the matching algorithm a Rest API was built using ExpressJS and PostgreSQL. For email sending we used the Sendgrid SMTP service provider, this is one of the companies that Techstars works with.</p><h3>Deployment</h3><p>At first the deployment was done using Heroku since this is easy to use, allows to focus in code instead of infrastructure and enhance the productivity of development team, but later for performance reasons we decided to use DigitalOcean that is also a company from the Techstars program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*ALEVSdDwpq1N9qdltoPg4A.jpeg" /></figure><h3>Challenges</h3><p>At the beginning it was challenging for me to understand the big picture of the project and how all things connected each other using a language and environment that I did not know, but white-boarding came for rescue. Understanding and using Sequelize was also hard for me since there were a lot of functions pretty similar to others and select which to use took me some time, here was very useful to look at other API’s implementation using this ORM.</p><h3>Conclusion</h3><p>This project was a really amazing experience. I learnt a lot of things, not just technical ones, but also how to work in team and several things from my peers. I would like to thank them and the techstars tutors Camilo Morales and Heimer Rojas for their support.</p><p>If you want to get in touch with this project you can check it in these github repositories: <a href="https://github.com/devarias/techstars-backend">Backend</a> — <a href="https://github.com/devarias/techstars-app">Frontend</a></p><p>Check our landing page <a href="https://mm-techstars.herokuapp.com/">here</a> and access it from <a href="http://techstars-app.herokuapp.com/">here</a></p><p>We are open for any recommendation or feedback. You can contact me on <a href="https://www.linkedin.com/in/deybercastaneda/">LinkedI</a>n or <a href="https://twitter.com/Deibercastaeda2">Twitter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*N_gvmrDfYAcHGCO8fr7Mbw.jpeg" /></figure><p>Thanks for reading !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5853fa15b2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structures Used in Git Implementation.]]></title>
            <link>https://medium.com/swlh/data-structures-used-in-git-implementation-a2c95bf4135e?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2c95bf4135e</guid>
            <category><![CDATA[trees]]></category>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[implementation]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Sat, 30 Jan 2021 19:00:02 GMT</pubDate>
            <atom:updated>2021-02-02T09:18:42.725Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*kMt6XD3_o4M_hnxB.png" /></figure><p>Git is a <a href="https://git-scm.com/about/free-and-open-source">free and open source</a> distributed version control system designed to handle everything from small to very large projects with speed and efficiency.<br>Clearly, Git have changed the world of software development.</p><p>But, what is behind of this amazing tool and why it is so powerful?</p><p>Linus Torvalds, the mind behind Git and Linux OS have a famous quote:</p><blockquote>“Bad programmers worry about the code. Good programmers worry about data structures and their relationships.”</blockquote><p>Well, what if we go deeper in the implementation of it and the data structures used behind the scenes?</p><p>There are several different data structures used in git.</p><p>Object storage (under .git/obects/) is a shallow <strong>trie</strong> — the root is a directory containing 256 subdirectories, one for each possible value of the high-order byte of the 20 byte blob ID.</p><p>Pack files use a <strong>hash table</strong> to keep track of the blobs in the pack; this structure is also used in memory — blobs and pack files are memory-mapped using the mmap(2) system call.</p><p>Finally, commits, tags, and directory blobs comprise a <a href="https://medium.com/@hamzasurti/advanced-data-structures-part-1-directed-acyclic-graph-dag-c1d1145b5e5a"><strong>directed acyclic graph</strong></a> (DAG), linked together by their object IDs. The directory structure is represented as a <strong>tree</strong>, but commits and tags form a more complicated structure because of branching and merging. The acyclic nature of the DAG is a natural consequence of the fact that links are represented by hashes.</p><p><strong>Commit, Branch and Head</strong><br>Git works mainly via Linked Lists. Here, <strong>Commit </strong>means to permanently store a <em>changeset</em>. A changeset indicates the changes in the files/source-codes etc. changesets include addition,modification and deletion of files. When you make a commit in Git, Git takes every file present in the changeset, makes a new node(in terms of linked lists), creates a new copy of those files into the new node(other version control systems just copy the changes) and makes the new node point to the previous node. Git supports branches. The default branch is <strong>Master. </strong>The Head pointer represents the current snapshot(version) of your files. When you change the Head, the current snapshot is changed to the snapshot of the current Head. <em>The other versions are hidden and you would only be able to view the current snapshots of the files</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*pyh9X9fQcNZyuxxo" /></figure><p>In the above diagram, you can see that A,B and C are commits and represent Linked List nodes. Here, we can see that there are two pointers, the branch pointer(master) and the Head pointer. The branch pointer is fixed and act as an identification and entry point to a branch. Head pointer indicates the current snapshot(node) of your work in git. Your changes gets added on top of the Node pointed to by the Head. Here, the commit A was made first followed by B and then C. Note, Head pointer can be moved to any node(commit) whereas the branch pointer remains fixed.</p><p>e.g. We can make another branch as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*qleQPUmDRCWp6q9c" /></figure><p>In the above figure, we first move the Head to point to B. You can do that by <strong><em>checking out</em></strong> into a particular commit manually. The next thing is to make a new commit which points back to D and make it a new branch. Thus, Head is now on D and we also create a new branch pointer called <em>Branch_Temp.</em></p><p><strong>Index/Reset Head</strong></p><p>Before you make a commit in git, there is something called the <strong>Index</strong> or the <strong>Staging Area</strong>. You need to add files into the staging area(new files/modified files) which can then go for commit. Think of Staging area as a stage. The performers need to be present in the stage and only then can begin to perform. Only files added in the staging area can be part of the new commit. Reset Head is used to remove the files from the staging area.</p><p><strong>Merge</strong></p><p>These are some of the advanced topics and makes Git extremely powerful. Think of a scenario when two different groups are working on two separate components of a program and once done they intend to merge their work into the master branch. For the sake of simplicity, lets assume there are no conflicts between the codes. We merge their work via Merge/Rebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*Ji9V3AWm0l_rpPkI" /></figure><p>In the above figure, D is on<em> Branch_Temp</em> and C is on <em>master.</em> Now when you want to merge them (merge Branch_Temp on master) and use the “git merge” option a new Node E is created on top of master and contents on the HEAD of Branch_Temp is copied onto E(It occurs smoothly if there are no conflicts) and Head and master now point to E. Now, notice what happens when we delete <em>Branch_Temp</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*PGdV8aEqGbUGwIqN" /></figure><p>The above figure indicates what happens when we <strong>delete</strong> the branch <em>Branch_Temp. <br>We can see that E still points back to both D and C. D now forms a part of the history of your current repository even after we delete the Branch.</em></p><p><strong>Rebase</strong></p><p>Rebase is another utility to merge two separate branches while keeping the history clean.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*XOSIxY0B2DcaiFSS" /></figure><p>In the above figure, we wish to <strong>rebase</strong> <em>Branch_Temp</em> into <em>master. </em>Rebase first obtains the lowest common ancestor of both the branches and replays the commits from the Branch_Temp till the lowest Ancestor on top of Master. Here, D and E belong to Branch_Temp. When we rebase, git calculates B as the lowest common ancestor of Branch_Temp and master. Now git rewinds E and D on top of Master as it is. <strong>This results in a cleaner version of history when we delete Branch_Temp.</strong></p><h3>Conclusion</h3><p>I hope that in this point you have a better point of view of how Git works and that it is more than just execute series of commands in your terminal and prying that it works. Understand what is happening under the hood can make you more versatile when you are working with this tool.</p><h3>Resourses</h3><ul><li><a href="https://inpsyde.com/en/understanding-git/">https://inpsyde.com/en/understanding-git/</a></li><li><a href="https://git-scm.com/">https://git-scm.com/</a></li><li><a href="http://shafiul.github.io/gitbook/1_the_git_index.html">http://shafiul.github.io/gitbook/1_the_git_index.html</a></li><li><a href="https://medium.com/@hamzasurti/advanced-data-structures-part-1-directed-acyclic-graph-dag-c1d1145b5e5a">https://medium.com/@hamzasurti/advanced-data-structures-part-1-directed-acyclic-graph-dag-c1d1145b5e5a</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2c95bf4135e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/data-structures-used-in-git-implementation-a2c95bf4135e">Data Structures Used in Git Implementation.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Web Server From Scratch With Python.]]></title>
            <link>https://medium.com/swlh/build-web-server-from-scratch-with-python-60188f3b162a?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/60188f3b162a</guid>
            <category><![CDATA[web-server]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[socket-programming]]></category>
            <category><![CDATA[sockets]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Sat, 23 Jan 2021 22:36:41 GMT</pubDate>
            <atom:updated>2021-01-25T00:19:19.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ce3Ea-CA1f8tHrec5cdJDg.jpeg" /></figure><p>If you are reading an article with this kind of title so maybe your are involved in the world of Web Development and have at least an idea of how web works, if not you can get an overview of it in this <a href="https://garzondeiber6.medium.com/what-happens-when-you-type-a-url-in-your-browser-and-press-enter-17d22e9a0560">article </a>.</p><p>The first thing that might come to your head is “Why to create a Web Server from scratch? What inventing the wheel again for?”</p><p>A famous thinker used to say: <em>I hear and I forget; I see and I remember; I do and I understand.<br></em>I believe to become a better developer you must get a better understanding of the underlying software systems you use on a daily basis and that includes programming languages, compilers and interpreters, databases and operating systems, web servers and web frameworks. And, to get a better and deeper understanding of those systems you must re-build them from scratch, brick by brick, wall by wall.</p><p>I hope at this point you’re convinced that it’s a good idea to start re-building different software systems to learn how they work.</p><p>But, What is a Web Server then?</p><p>It is basically a networking server that sits on a physical server (yeah, a server on a server lol) and waits for a client to send a request. When it receives a request, it generates a response and sends it back to the client. The communication between a client and a server happens using HTTP protocol. A client can be your browser or any other software that speaks HTTP.</p><p>Before the client can send a HTTP request though, it first needs to establish a <a href="https://www.khanacademy.org/computing/computers-and-internet/xcae6f4a7ff015e7d:the-internet/xcae6f4a7ff015e7d:transporting-packets/a/transmission-control-protocol--tcp">TCP </a>connection with the Web server. Then it sends an HTTP request over the TCP connection to the server and waits for the server to send an HTTP response back.</p><p>To establish the TCP connection we will so-called <a href="https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html"><em>sockets</em></a><em>:</em></p><pre>import sockets</pre><pre>HOST, PORT = &#39;&#39;, 8888<br><br>listening_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</pre><p>Here we made a socket instance and passed it two parameters. The first parameter is <strong>AF_INET</strong> and the second one is <strong>SOCK_STREAM</strong>. AF_INET refers to the address family ipv4. The SOCK_STREAM means connection oriented TCP protocol.</p><pre>listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)<br>listen_socket.bind((HOST, PORT))<br>listen_socket.listen(1)</pre><p>Then we set the <a href="http://poincare.matf.bg.ac.rs/~ivana/courses/ps/sistemi_knjige/pomocno/apue/APUE/0201433079/ch16lev1sec6.html">socket option</a> to SOL_SOCKET to manipulate options at the sockets API level. With this done now we can bind the host and port before start to listen from them.</p><pre>while True:<br>    client_connection, client_address = listen_socket.accept()<br></pre><p>The socket must be bound to an address and listening for connections. For that we use the socket.accept() property, The return value is a pair (conn, address) where <em>conn</em> is a <em>new</em> socket object usable to send and receive data on the connection, and <em>address</em> is the address bound to the socket on the other end of the connection.</p><pre>while True:<br>    client_connection, client_address = listen_socket.accept()<br>    request_data = client_connection.recv(1024)<br>    print(request_data.decode(&#39;utf-8&#39;))</pre><p>To receive the data from the socket we use the socket.recv() method, The return value is a bytes object representing the data received. The maximum amount of data to be received at once is specified by its argument. Decode to utf-8 can help us to avoid problems with the data received.</p><pre>http_response = b&quot;&quot;&quot;\<br>HTTP/1.1 200 OK<br><br>Hello, World!<br>&quot;&quot;&quot;<br>    client_connection.sendall(http_response)<br>    client_connection.close()</pre><p>Then we set the response and send it using the <em>sendall method</em> and close the connection.</p><p>Now let’s try it…</p><p>The entire code would be:</p><pre>import socket<br><br>HOST, PORT = &#39;&#39;, 8888<br><br>listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br>listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)<br>listen_socket.bind((HOST, PORT))<br>listen_socket.listen(1)<br>print(&#39;Serving HTTP on port {PORT} ...&#39;)<br>while True:<br>    client_connection, client_address = listen_socket.accept()<br>    request_data = client_connection.recv(1024)<br>    print(request_data.decode(&#39;utf-8&#39;))<br><br>    http_response = b&quot;&quot;&quot;\<br>HTTP/1.1 200 OK<br><br>Hello, World, I just created a Web Server...!<br>&quot;&quot;&quot;<br>    client_connection.sendall(http_response)<br>    client_connection.close()</pre><p>If you execute this program and check in your browser you should get something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*xnvqM63uoOGA8_wfrw97QA.png" /></figure><p>You can also simulate a web browser running the Web server fire up a telnet session on the command line specifying a host to connect to <em>localhost</em> and the port to connect to <em>8888</em> and then press Enter:</p><pre>$ telnet localhost 8888<br>Trying 127.0.0.1 …<br>Connected to localhost.</pre><p>At this point you’ve established a TCP connection with the server running on your local host and ready to send and receive HTTP messages. In the picture below you can see a standard procedure a server has to go through to be able to accept new TCP connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gYqF2nNusnxTiE0T.png" /></figure><h3>Conclusion</h3><p>And that’s the basic model of how a Web server works. To sum it up: The Web server creates a listening socket and starts accepting new connections in a loop. The client initiates a TCP connection and, after successfully establishing it, the client sends an HTTP request to the server and the server responds with an HTTP response that gets displayed to the user. To establish a TCP connection both clients and servers use <em>sockets</em>.</p><h3>Resources</h3><ul><li><a href="https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html">https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html</a></li><li><a href="https://docs.python.org/3/library/socket.html#socket.socket.listen">https://docs.python.org/3/library/socket.html#socket.socket.listen</a></li><li><a href="https://docs.oracle.com/javase/tutorial/networking/sockets/index.html">https://docs.oracle.com/javase/tutorial/networking/sockets/index.html</a></li><li><a href="https://garzondeiber6.medium.com/what-happens-when-you-type-a-url-in-your-browser-and-press-enter-17d22e9a0560">https://medium.com/r/?url=https%3A%2F%2Fgarzondeiber6.medium.com%2Fwhat-happens-when-you-type-a-url-in-your-browser-and-press-enter-17d22e9a0560</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60188f3b162a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/build-web-server-from-scratch-with-python-60188f3b162a">Build Web Server From Scratch With Python.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Style your Data Analysis]]></title>
            <link>https://garzondeiber6.medium.com/style-your-data-analysis-b219d72f1bd7?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b219d72f1bd7</guid>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[style]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Sun, 10 Jan 2021 20:06:34 GMT</pubDate>
            <atom:updated>2021-01-10T20:06:34.504Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeodkCT2EF7g7CpHoczG5Q.jpeg" /><figcaption>Panda with “style”.</figcaption></figure><p>Have you ever feel that table output looks boring and very simple when you check it in Jupyter Notebooks?.<br>Tables allow your data consumers to gather insight by <em>reading</em> the underlying data. However, there are often instances where leveraging the <em>visual</em> system is much more efficient in communicating insight from the data. Knowing this, you may often find yourself in scenarios where you want to provide your consumers access to the underlying data by means of a table, while still providing <em>visual representations</em> of the data so that they can quickly and effectively gather the insight they need.<br>In this article I would like to share with you some ways to improve the gathering data experience with pandas native styling functionality. This styling functionality allows you to add conditional formatting, bar charts, supplementary information to your dataframes, and more.</p><h3>Options/Settings API</h3><p>Pandas allows us to customize some parts of its behavior through its Option/Setting API. It our case we will use display-related options to improve our pandas experience when we have certain issues:</p><ul><li>There are too many columns/rows in the dataframe and some columns/rows in the middle are omitted on display. <br>For example, if one would like to show at most 7 rows and at most 7 columns one would:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*-POqpsM2EYCLZCfN.png" /></figure><ul><li>Columns containing long texts get truncated and columns containing floats display too many / too few digits only on display:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/0*c9HOLzXejMXN9q5m.png" /></figure><p>You can check more use cases <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html#available-options">here</a>.</p><h3><strong>Time to style !</strong></h3><p>In a lot of cases for example the fact of have a way to know if a value is negative or positive can represent an advantage when analyzing data. To accomplish this we are going to use the dataframes’s <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html"><em>style</em></a> property.</p><p>Let’s build a function that colors values in a dataframe column green or red depending on their sign:</p><pre>def color_negative_red(value):<br>  &quot;&quot;&quot;<br>  Colors elements in a dateframe<br>  green if positive and red if<br>  negative. Does not color NaN<br>  values.<br>  &quot;&quot;&quot;<br><br>  if value &lt; 0:<br>    color = &#39;red&#39;<br>  elif value &gt; 0:<br>    color = &#39;green&#39;<br>  else:<br>    color = &#39;black&#39;<br><br>  return &#39;color: %s&#39; % color</pre><p>Yeah !, we are returning a CSS style. Now let’s apply this method to our dataframe. DataFrame.style property returns a Styler object that have some useful methods to formatting and displaying dataframes. One of those methods is <em>applymap </em>that allows to apply our function to the respective dataframe.</p><pre>df.style.applymap(color_negative_red)</pre><p>If your data set have non-numeric values you can select the columns to which the function will be applied using the <em>subset</em> argument passed to <em>applymap</em> method i.e subset=[“column1”, “column2”].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*eTEhRf-NA47KkO2QBmpcsw.png" /><figcaption>Housig prices dataset</figcaption></figure><p>You can also apply arbitrary CSS to the dataframe elements using the Styler object’s <a href="https://pandas.pydata.org/pandas-docs/stable/style.html#Table-Styles">set_table_styles()</a> method:</p><pre># Set CSS properties for th elements in dataframe<br>th_props = [<br>  (&#39;font-size&#39;, &#39;11px&#39;),<br>  (&#39;text-align&#39;, &#39;center&#39;),<br>  (&#39;font-weight&#39;, &#39;bold&#39;),<br>  (&#39;color&#39;, &#39;#6d6d6d&#39;),<br>  (&#39;background-color&#39;, &#39;#f7f7f9&#39;)<br>  ]<br><br># Set CSS properties for td elements in dataframe<br>td_props = [<br>  (&#39;font-size&#39;, &#39;11px&#39;)<br>  ]<br><br># Set table styles<br>styles = [<br>  dict(selector=&quot;th&quot;, props=th_props),<br>  dict(selector=&quot;td&quot;, props=td_props)<br>  ]<br><br><br>(df.style<br>    .applymap(color_negative_red, subset=[&#39;longitude&#39;,&#39;latitude&#39;])<br>    .set_table_styles(styles))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*6APet-7azGB_bpvunmNXjw.png" /></figure><p>Great ! we are styling, but this is just a small part of what you can do using pandas dataframe styling functionality. Other ways to style include apply custom background color gradients and custom captions, amongst other things:</p><pre># Set colormap equal to seaborns light green color palette<br>cm = sns.light_palette(&quot;green&quot;, as_cmap=True)<br><br>(df.style<br>  .background_gradient(cmap=cm, subset=[&#39;latitude&#39;,&#39;longitude&#39;])<br>  .highlight_max(subset=[&#39;longitude&#39;,&#39;latitude&#39;])<br>  .set_caption(&#39;This is a custom caption.&#39;)<br>  .set_table_styles(styles))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*ZDM090PWPnODqZnJ_S8SBA.png" /></figure><p>I you have seen the data set that I am using there are some columns that represent currency values, a good idea would be to add a dollar sign and a comma to this data. To do it we can use the <em>format</em> method of<em> Styler</em> property.</p><pre>df.head().style.format({&quot;median_house_value&quot;: &quot;$<strong>{:20,.0f}</strong>&quot;, <br>                          &quot;median_income&quot;: &quot;$<strong>{:20,.4f}&quot;})</strong><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*ABv4cftPMo1mxSWB595IdQ.png" /></figure><h3>Conclusion:</h3><p>The above examples are just simple cases, I invite you to go deeper and style your dataframes so that you can gather data easier from your tables and give more color to your data analysis.<br>I am open for any suggestion or correction, Thanks a lot for reading.</p><h3>Resources:</h3><ul><li><a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html">https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html</a></li><li><a href="https://seaborn.pydata.org/">https://seaborn.pydata.org/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b219d72f1bd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Big bit tips and tricks…]]></title>
            <link>https://garzondeiber6.medium.com/big-bit-tips-and-tricks-61ac6cefb05?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/61ac6cefb05</guid>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[bit]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Sat, 09 Jan 2021 18:46:24 GMT</pubDate>
            <atom:updated>2021-01-09T18:46:24.800Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8vbrqotukHkHv0M1.png" /></figure><p>Manipulate bits is an amazing way to solve a lot of problems, but sometimes we don’t use this powerful tool in our problems either because require to think in very specific application or because a very tiny mistake could lead into a catastrophic error in the expected solution.</p><p>That’s why in this opportunity I would like to share with you some tips and tricks that you may or not know or maybe it could help you to refresh them.</p><p>But before that let’s to review some concepts just for the sake of completeness.</p><blockquote>Bit manipulation is the process of applying logical operations on a sequence of bits to achieve a required result.</blockquote><p>First of all, we need to be aware of the basic operators:</p><ul><li><strong><em>&amp;</em></strong> (and)</li><li><strong><em>|</em></strong> (or)</li><li><strong>^</strong> (xor)</li><li><strong>~</strong> (not)</li><li><strong>&gt;&gt;</strong> (right shift)</li><li><strong>&lt;&lt;</strong> (left shift)</li></ul><h3>&amp;</h3><p>It’s only true if both are true.<br>0 &amp; 0 = 0<br>0 &amp; 1 = 0<br>1 &amp; 0 = 0<br>1 &amp; 1 = 1</p><h3>|</h3><p>It’s true if any of the inputs is true<br>0 | 0 = 0<br>0 | 1 = 1<br>1 | 0 = 1<br>1 | 1 = 1</p><h3>^</h3><p>It’s true in case of odd numbers<br>0 ^ 0 = 0<br>0 ^ 1 = 1<br>1 ^ 0 = 1<br>1 ^ 1 = 0</p><h3>~</h3><p>Flips the input<br>~ 0 = 1<br>~ 1 = 0</p><h3>Right shift</h3><p>divides by two</p><h3>Left shift</h3><p>multiplies by two</p><h3>Bit Facts</h3><pre>x ^ 0s = x<br>x ^ 1s = ~x<br>x ^ x = 0x &amp; 0s = 0<br>x &amp; 1s = x<br>x &amp; x = xx | 0s = x<br>x | 1s = 1<br>x | x = xx ^ 0 = x<br>x ^ 1 = x<br>x ^ x = 0</pre><blockquote>Keep in mind that bit-wise operation help to make your <a href="https://graphics.stanford.edu/~seander/bithacks.html">programs faster </a>(No so much) but it contributes its grain of sand.</blockquote><p>Well, time to move forward…</p><h3>1. Use AND (&amp;) operator to check even or odd number</h3><p>We usually use division and modulo to check if a number is odd or even. This can be also accomplished by using the AND operator. The last bit of a number is which determines if a number is odd or even (10 → 00001010), so we can use 1 (00000001) as mask (This can be also done with 0 and other operators, now you have a task).</p><p>00001010 &amp;<br>00000001<br> — — — — — <br>00000000</p><pre>#include &lt;stdio.h&gt;<br><br>int main()<br>{<br>    int num1 = 10, num2 = 21;<br>    <br>    // Check even odd<br>    if (num1 &amp; 1)<br>        printf(&quot;%d is an ODD number.\n&quot;, num1);<br>    else<br>        printf(&quot;%d is an EVEN number.\n&quot;, num1);<br><br>    if(num2 &amp; 1)<br>        printf(&quot;%d is an ODD number.\n&quot;, num2);<br>    else<br>        printf(&quot;%d is an EVEN number.\n&quot;, num2);<br><br>    return 0;<br>}</pre><p>output:</p><pre>10 is an EVEN number.<br>21 is an ODD number.</pre><h3>2. Store multiple flags in a single variable</h3><p>We usually use boolean flags variables in our solutions, for example: isEven, isMarried, isGoal_of_yepes (Well, this not), etc.<br>Suppose a case where you need to use several boolean flags variables, so maybe your first approach would be to create several 4 bytes integers, but in this case the amount of space will be n*4 bytes. What if we could use a single variable to accomplish that?. If fact, it is possible:</p><p>You can use bit masking to store multiple flag values in a single variable. A 4 byte unsigned integer can store 32 flags.</p><p>We use bitwise OR | operator to set flag. To <a href="https://codeforwin.org/2016/01/c-program-to-clear-nth-bit-of-number.html">unset</a> or check flag status we use bitwise AND &amp; operator. At a high level it is known as bit masking, but you can think it as set, unset and check a bit status.</p><pre>#include &lt;stdio.h&gt;<br><br>int main()<br>{<br>    // Make all bits off.<br>    unsigned char flag = 0;<br><br>    // Set marital status YES, i.e. 0th bit 1<br>    // (flag =&gt; 0000 0001 = 1)<br>    flag = flag | 1;<br><br>    // Set voting status YES, i.e. 1st bit 1 <br>    // (flag =&gt; 0000 0011 = 3)<br>    flag = flag | 2;<br><br>    // Set VISA eligibility status YES, i.e. 2nd bit 1<br>    // (flag =&gt; 0000 0111 = 7)<br>    flag = flag | 4;    <br>    // Set Goal_of_yepes status YES, .i.e. 3th bit 1<br>    // (flag =&gt; 000 1111 = 15)<br>    flag = flag | 8;</pre><pre>    // Print flag value <br>    printf(&quot;flag, DECIMAL = %d, HEX = %x\n\n&quot;, flag, flag);<br><br>    // Check if married<br>    if(flag &amp; 1)<br>        printf(&quot;You are married.\n&quot;);<br>    else<br>        printf(&quot;You are not married.\n&quot;);<br><br>    // Check voting eligibility<br>    if(flag &amp; 2)<br>        printf(&quot;You are eligible for voting.\n&quot;);<br>    else<br>        printf(&quot;You are not eligible for voting.\n&quot;);<br><br>    // Check VISA status<br>    if(flag &amp; 4)        <br>        printf(&quot;You are eligible to get VISA.\n&quot;);<br>    else<br>        printf(&quot;You are not eligible to get VISA.\n&quot;);<br>    if (flag &amp; 8)<br>        printf(&quot;It was Yepes&#39; goal. \n&quot;);</pre><pre>// Unset or set all flags to false.<br>    flag = flag &amp; (~(1 &lt;&lt; 0));<br>    flag = flag &amp; (~(1 &lt;&lt; 1));<br>    flag = flag &amp; (~(1 &lt;&lt; 2));<br>    flag = flag &amp; (~(1 &lt;&lt; 3));<br>    // Print flag value<br>    printf(&quot;\nflag, DECIMAL = %d, HEX = %x\n&quot;, flag, flag);<br><br>    return 0;<br>}</pre><p>output:</p><pre>flag, DECIMAL = 7, HEX = 7<br><br>You are married.<br>You are eligible for voting.<br>You are eligible to get VISA.<br>It was Yepes&#39; goal.</pre><pre>flag, DECIMAL = 0, HEX = 0</pre><h3>3. Quickly convert character to lowercase and uppercase.</h3><p>The common way to convert characters to lowercase or uppercase is using the ASCII code but bit operation also provides a way to do it. <br>You can use bitwise OR and AND operator to convert a character to lowercase and uppercase respectively.<br>To convert a character ch to lowercase use ch = ch | &#39; &#39;. Whether ch is uppercase or lowercase. Result of this is always a lowercase character.</p><p>To convert a character ch to uppercase use ch = ch &amp; &#39;_&#39;. It always return uppercase character, doesn&#39;t matter whether ch is uppercase or lowercase.</p><pre>A -&gt; 01000001                a -&gt; 01100001<br>B -&gt; 01000010                b -&gt; 01100010<br>C -&gt; 01000011                c -&gt; 01100011<br>.                               .<br>.                               .<br>Z -&gt; 01011010                z -&gt; 01111010</pre><p>As we can see if we clear 5th bit of lower case characters, it will be converted into upper case character. We have to prepare a mask having 5th bit 0 and other 1 (10111111). This mask is bit representation of underscore character (‘_‘). The character ‘ch’ then AND with mask.<br> Example-<br> ch = ‘a’ (01100001)<br> mask = ‘_ ‘ (11011111)<br> ch &amp; mask = ‘A’ (01000001)<br>The same logic apply to convert to lowercase.</p><pre>#include &lt;stdio.h&gt;<br><br>int main()<br>{<br>    // Convert to lowercase<br>    printf(&quot;&#39;a&#39; ==&gt; &#39;%c&#39;\n&quot;, (&#39;a&#39; | &#39; &#39;));<br>    printf(&quot;&#39;A&#39; ==&gt; &#39;%c&#39;\n&quot;, (&#39;A&#39; | &#39; &#39;));<br><br>    // Convert to uppercase<br>    printf(&quot;&#39;a&#39; ==&gt; &#39;%c&#39;\n&quot;, (&#39;a&#39; &amp; &#39;_&#39;));<br>    printf(&quot;&#39;A&#39; ==&gt; &#39;%c&#39;\n&quot;, (&#39;a&#39; &amp; &#39;_&#39;));<br><br>    return 0;<br>}</pre><p>output:</p><pre>&#39;a&#39; ==&gt; &#39;a&#39;<br>&#39;A&#39; ==&gt; &#39;a&#39;<br>&#39;a&#39; ==&gt; &#39;A&#39;<br>&#39;A&#39; ==&gt; &#39;A&#39;</pre><h3>4.Quick conditional assignment hack</h3><p>What if a tell you that you can use a single line to represent the following block:</p><pre>if (x == a)<br>    x = b;<br>if (x == b)<br>    x = a;</pre><p>You can use bitwise XOR operator for these type of assignments:</p><pre>#include &lt;stdio.h&gt;<br><br>int main()<br>{<br>    int a = 10, b = 20, x;<br>    <br>    // Original value<br>    x = a;<br>    printf(&quot;x = %d\n&quot;, x);<br><br>    // if (x == a) x = b;<br>    x = a ^ b ^ x;<br>    printf(&quot;x = %d\n&quot;, x);<br><br>    // if (x == b) x = a;<br>    x = a ^ b ^ x;<br>    printf(&quot;x = %d\n&quot;, x);<br><br>    // x = 0<br>    x = x ^ x;<br>    printf(&quot;x = %d\n&quot;, x);<br><br>    return 0;<br>}</pre><pre><strong>Output:</strong></pre><pre>x = 10<br>x = 20<br>x = 10<br>x = 0</pre><h3>5.Find maximum or minimum without if…else</h3><p>A common task when we are solving problems is to find a maximum or minimum and a common approach to use if…else to do it.<br>Let’s try it using bits:</p><p>#include &lt;stdio.h&gt;</p><p>int main()<br>{<br> int x = 10, y = 20;</p><p>int min = (y ^ (x ^ y) &amp; -(x &lt; y));<br> int max = (x ^ (x ^ y) &amp; -(x &lt; y));</p><p>printf(&quot;Minimum(10, 20) =&gt; %d\n&quot;, min);<br> printf(&quot;Maximum(10, 20) =&gt; %d\n&quot;, max);</p><p>return 0;<br>}<br><strong>Output:</strong></p><pre>Maximum(10, 20) =&gt; 20<br>Minimum(10, 20) =&gt; 10</pre><h3>6.Use bitwise XOR (^) operator to quickly swap two number without third variable</h3><p>One of the first things that amazed me about Python when I started with it was that I could swap to variables values because of the tuple data structure definition in this language without using a third variable (This a common problem in interview questions).<br>Let’s do the same in C using our amazing tool:</p><pre>#include &lt;stdio.h&gt;<br><br><br>int main()<br>{<br>	int a, b;<br><br>	// Input two numbers<br>	printf(&quot;Enter two numbers to swap: &quot;);<br>	scanf(&quot;%d%d&quot;, &amp;a, &amp;b);<br><br>	// Print original values.<br>	printf(&quot;Original value: a=%d, b=%d\n&quot;, a, b);<br><br>	// Swap a with b<br>	a ^= b;<br>	b ^= a;<br>	a ^= b;<br><br>	// Swapped values.<br>	printf(&quot;Swapped value: a=%d, b=%d\n&quot;, a, b);<br><br>	return 0;<br>}<br><strong>Output:</strong></pre><pre>Enter two numbers to swap: 10 20<br>Original value: a=10, b=20<br>Swapped value: a=20, b=10</pre><h3>7. Increment by 1 (num + 1)</h3><p>Maybe this trick will not be so handy, but it’s good keep in mind if some day you find it in a code:</p><p>Let’s increment by one using bit manipulation:</p><pre>#include&lt;stdio.h&gt;<br>int main() <br>{<br>	int num = 16;<br>	<br>	num = -~num;<br>	printf(&quot;num = %d&quot;, num);<br>	<br>	return 0;<br>}</pre><h3>8. Decrement by 1 (num — 1)</h3><p>Decrement is very similar to increment, we just have to change the order of the signs:</p><pre>#include&lt;stdio.h&gt;<br>int main() <br>{<br>	int num = 16;<br>	<br>	num = ~-num;<br>	printf(&quot;num = %d&quot;, num);<br>	<br>	return 0;<br>}</pre><p>I hope that with this article you realize how useful and beautiful is working with bit operations and that you start to use them in your problems. I am open to any suggestion.</p><p>Some useful resources:</p><ul><li><a href="https://graphics.stanford.edu/~seander/bithacks.html">https://graphics.stanford.edu/~seander/bithacks.html</a></li><li><a href="https://codeforces.com/blog/entry/21858">https://codeforces.com/blog/entry/21858</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61ac6cefb05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type a URL in your browser and press ENTER?]]></title>
            <link>https://codeburst.io/what-happens-when-you-type-a-url-in-your-browser-and-press-enter-17d22e9a0560?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/17d22e9a0560</guid>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[firewall]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[browsers]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 23:38:26 GMT</pubDate>
            <atom:updated>2021-05-08T03:27:49.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*lT3n7frt-lTzYXrZZui4Cw.jpeg" /></figure><p>It does not matters what profession or occupation you come from it is likely that you once have used your browser to search something, either a concept, how to fix something or simply check your favorite social network.<br>But, What is happening under the hood?<br>What is really our computer doing when we type the URL of the site we want to get?</p><p>The answers to those questions are the aim of this article.</p><p>Let’s go through the process step by step.<br>Suppose that you want to access holbertonschool.com from your browser:</p><h3>Get input from Keyboard</h3><p>When you type holbertonschool.com in the browser, you type it from your computer’s keyboard, and as you are typing it, your keyboard emits an event — that is, it signals the operating system (OS) that a state has been changed, and your OS records this change and responds to it. It’s like the moment you touch a hot pan — Your brain processes this and prepares your body for response (move hand away).</p><h3>Event Handling</h3><p>There are flags and keycodes to detect when a key is pressed, map which key is pressed and generate a response accordingly. Different keys on your keyboard evoke different responses. So when a key is pressed, the kernel signals the OS that it needs its immediate attention and resources. The OS makes the CPU (or central processing unit, a.k.a., the brain of the computer) respond to it by suspending its current activities, saving its state and executing the interrupt handler function. If you had typed “<a href="https://sweetcode.io/what-happens-when-you-type-in-the-browser/www.holbertonschool.com">holbertonschool.com</a>” in a text editor, your OS would have let the dedicated text editor program handle your interactions with it. But since you typed in the browser, it will let the browser application handle it.</p><h3>What is a browser?</h3><p>Let’s say you want to order food, and you choose to use Rappi (A famous company of food delivery in Colombia). While your food is getting ready, the Rappi driver goes to the restaurant — then grabs your food and delivers it to you. Voila! In minutes, you have your food.</p><p>But who is actually serving you — the restaurant or Rappi? In this case, Rappi is the middleman, letting the restaurant serve you.</p><p>Similarly, the browser is the medium that allows you to make a request and lets a server serve you. It’s software installed and running on your computer that lets you search the Internet. It takes your input, creates and sends a request, gets the response and serves you.</p><p>But wait — How does a Rappi driver know which restaurant to go to and how to find it? (Of course, Google Maps.) Now, how does your browser know which server to send the request to? Yes, you guessed it right, it needs to find its address. So, it queries the DNS (Domain Name Server) to find the IP.</p><h3>DNS lookup</h3><p>The DNS is the Internet’s version of Google Maps. It routes you to your destination. Your computer or your router knows the address of the DNS server. When you type the URL in a browser for the first time, it sends a request to the DNS server, which responds back with the IP address of the web server hosting, for example, holbertonschool.com. This value is usually then cached or gets added into the list of known hosts, so your browser doesn’t have to do this lookup every time.</p><p>DNS(Domain Name System) is a database that maintains the name of the website (URL) and the particular IP address it links to. Every single URL on the internet has a unique IP address assigned to it. The IP address belongs to the computer which hosts the server of the website we are requesting to access. For example, <a href="http://www.google.com/">www.google.com</a> has an IP address of 209.85.227.104. So if you’d like, you can reach <a href="http://www.google.com/">www.google.com</a> by typing <a href="http://209.85.227.104/">http://209.85.227.104</a> on your browser. DNS is a list of URLs, and their IP addresses, like how a phone book is a list of names and their corresponding phone numbers.</p><p>The primary purpose of DNS is human-friendly navigation. You can easily access a website by typing the correct IP address for it on your browser, but imagine having to remember different sets of numbers for all the sites we regularly access? Therefore, it is easier to remember the name of the website using a URL and let DNS do the work for us by mapping it to the correct IP.</p><p>To find the DNS record, the browser checks four caches.</p><p>● First, it checks the browser cache. The browser maintains a repository of DNS records for a fixed duration for websites you have previously visited. So, it is the first place to run a DNS query.</p><p>● Second, the browser checks the OS cache. If it is not in the browser cache, the browser will make a system call to your underlying computer OS to fetch the record since the OS also maintains a cache of DNS records.</p><p>● Third, it checks the router cache. If it’s not on your computer, the browser will communicate with the router that maintains its’ own cache of DNS records.</p><p>● Fourth, it checks the <a href="https://en.wikipedia.org/wiki/Internet_service_provider">ISP</a> cache. If all steps fail, the browser will move on to the ISP. Your ISP maintains its’ own DNS server, which includes a cache of DNS records, which the browser would check with the last hope of finding your requested URL.</p><p>You may wonder why there are so many caches maintained at so many levels. Although our information being cached somewhere doesn’t make us feel very comfortable when it comes to privacy, caches are essential for regulating network traffic and improving data transfer times.</p><h3>OSI model</h3><p>Now that your browser knows the IP address of the server, it needs to find a way to pass this request all the way to the server. When you place the order, it’s not just you interacting with Rappi. There’s another end being managed — with the need to check that the restaurant is ready to accept the order, handle billing and payments, find the most reliable driver, and so on. Similarly, there’s a lot of stuff that needs to be managed for smooth communication between browser and server.</p><p>There’s something called an <a href="https://www.networkworld.com/article/3239677/the-osi-model-explained-and-how-to-easily-remember-its-7-layers.html">OSI</a> (Open System Interconnection) model that standardizes communication between different computing machines. It describes the flow of information from one computer to another. It defines seven layers, and the interplay of these layers magically brings, for example, holbertonschool.com from server to your machine. At both ends (client and server), these layers are followed, but there is a difference in the flow of which layer kicks in first. When your browser sends the request, communication starts at the application layer and goes down to the physical layer — whereas in the server, while receiving the request, it would start at the physical layer, going up. On the other hand, when a server is responding to your browser’s request, it would go from application layer to physical layer — and when your computer receives the response, it would first go to the physical layer all the way back to the application layer.</p><p>7. <strong>Application layer</strong>: consists of protocols that directly interact with the end user. A protocol defines how different applications across machines communicate with each other. If you are requesting a web page, HTTP (Hyper Text Transfer Protocol) will handle it, and if you are sending an email, SMTP (Simple Mail Transfer Protocol) will handle it. So in the case of holbertonschool.com, your browser generates a HTTP request. Don’t confuse the browser as part of the application layer. The role of application layers comes in when your browser creates a HTTP request. This HTTP request is part of the application layer.</p><p>6.<strong> Presentation layer</strong>: Depending on your request (image, video, text, GIF, etc.), this layer converts and presents the data in readable format. In the case of holbertonschool.com, when your machine received it, the presentation layer would kick in to render it as a HTML page.</p><p>5. <strong>Session layer</strong>: responsible for establishing, maintaining, and terminating the session between devices. For example, when you are doing video chat, the time you enter into the chat to the time you leave it is one complete session, given there were no interruptions during that interval. However, in the case of holbertonschool.com, HTTP uses lower layer protocol, instead of session layer protocols.</p><p>4. <strong>Transport layer</strong>: takes care of the reliability, safety and security of the path taken between the request and response. Here, the transportation, delivery and assembling of data takes place. When you are requesting holbertonschool.com, essentially, you are not sending any data, but the role of this layer is more evident when you receive the data. The data your machine receives comes divided into packets with a sequence number assigned to each packet, called data payloads. This layer makes sure that you have received all packets and reassembles them in order. As I mentioned above, HTTP uses the TCP(Transfer Control Protocol) transport layer protocol instead of session layer protocols for establishing and maintaining a connection from your machine to the server to ensure reliable delivery. For security, it uses SSL (Secure Sockets Layer), which encrypts all data passed between browser and the web server, making all communications private and integral. In HTTP requests, it’s the job of TCP protocols to ensure fast and efficient delivery. In a similar way, Rappi has to make sure that all the requests are served well and are distributed across drivers.</p><p>3.<strong> Network layer</strong>: This organizes and routes the data. It also decides which transfer protocols to use. So in the case of holbertonschool.com, the best path to route the data between your machine and web server is determined by the IP (Internet Protocol).</p><p>2. <strong>Data link layer</strong>: In this layer, data is broken down into pieces. So when the server sends holbertonschool.com, it doesn’t send the entire page all at once; rather, the data link layer segments it, encapsulates it and transmits it as packets (data payloads) through the physical layer. It is not necessary that the packets be delivered directly to your machine. It may travel from network to network, passing through many machines before reaching you. So in this case, IP addresses with all of these hops are translated to hardware addresses, at the data link layer.</p><p>1.<strong> Physical layer</strong>: The physical layer deals with the actual connectivity between your machine and the server. The hardware and signaling and encoding mechanisms required to form the actual connection are defined at this layer, and the data received from the server is in the form of raw bits. Try <em>ifconfig </em>command in your terminal to check out the network interface configuration of your system.</p><p>So far, I have mainly talked from the client perspective. It’s time to understand what happens at the server end.</p><p>Once the browser receives the correct IP address, it will build a connection with the server that matches the IP address to transfer information. Browsers use internet protocols to build such connections. There are several different internet protocols that can be used, but TCP is the most common protocol used for many types of HTTP requests.</p><p>To transfer data packets between your computer(client) and the server, it is important to have a TCP connection established. This connection is established using a process called the TCP/IP three-way handshake. This is a three-step process where the client and the server exchange SYN(synchronize) and ACK(acknowledge) messages to establish a connection.</p><p>1. The client machine sends a SYN packet to the server over the internet, asking if it is open for new connections.</p><p>2. If the server has open ports that can accept and initiate new connections, it’ll respond with an ACKnowledgment of the SYN packet using a SYN/ACK packet.</p><p>3. The client will receive the SYN/ACK packet from the server and will acknowledge it by sending an ACK packet.</p><p>Then a TCP connection is established for data transmission!</p><h3>Web server</h3><p>This might mean a physical machine or software. In the case of holbertonschool.com, both work together to make sure that the website is accessible (up and running). At the hardware level, a web server is a machine (or collection of machines) that stores a website’s component files (e.g. HTML documents, images, videos, stylesheets, and JavaScript files) and delivers them to you. This is called hosting. At the software level, a web server, known as the HTTP server, controls how users access these hosted files. It processes and answers incoming requests. When you request holbertonschool.com, the HTTP server checks whether the requested URL matches any existing files, and if found, sends the files’ content back to the browser, or sends a “404 Not Found” error.</p><p>The server response contains the web page you requested as well as the status code, compression type (<em>Content-Encoding)</em>, how to cache the page (<em>Cache-Control</em>), any cookies to set, privacy information, etc.</p><p>Example HTTP server responses:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*9jUxdlDwAlhtcSIoqC0c5Q.png" /></figure><p>If you look at the above response, the first line shows a status code. This is quite important as it tells us the status of the response. There are five types of statuses detailed using a numerical code.</p><p>● 1xx indicates an informational message only</p><p>● 2xx indicates success of some kind</p><p>● 3xx redirects the client to another URL</p><p>● 4xx indicates an error on the client’s part</p><p>● 5xx indicates an error on the server’s part</p><p>So, if you encountered an error, you can take a look at the HTTP response to check what type of status code you have received.</p><h3>Load balancing</h3><p>Popular websites have to serve several thousands of concurrent requests and return correct text, image and video responses to them. To serve a large number of requests, the content is usually distributed across multiple servers. A load balancer sits in front of these servers and acts as a traffic cop to direct traffic to the right server. It makes sure that no server is overloaded, and provides high availability and reliability by ensuring all requests are served. If a server goes down, it starts redirecting the requests to different servers that are online.</p><h3>Firewall</h3><p>Web servers use a firewall to protect the system against breaches and attacks. For example , if a bad source starts flooding the web server with a large number of concurrent requests, the firewall will detect the problem and block requests from that IP address to keep them from reaching the web server.</p><h3>Application Server</h3><p>An application server is a <a href="https://techterms.com/definition/server">server</a> specifically designed to run <a href="https://techterms.com/definition/application">applications</a>. The “server” includes both the <a href="https://techterms.com/definition/hardware">hardware</a> and <a href="https://techterms.com/definition/software">software</a> that provide an environment for programs to run.</p><p>A web server is designed — and often optimized — to serve webpages. Therefore, it may not have the resources to run demanding web applications. An application server provides the processing power and memory to run these applications in real-time. It also provides the environment to run specific applications. For example, a cloud service may need to process data on a Windows machine. A Linux-based server may provide the web interface for the cloud service, but it cannot run Windows applications. Therefore, it may send input data to a Windows-based application server. The application server can process the data, then return the result to the web server, which can output the result in a web browser.</p><h3>Database</h3><p>A database is an organized collection of structured information, or data, typically stored electronically in a computer system. A database is usually controlled by a <a href="https://www.oracle.com/database/what-is-database/#WhatIsDBMS">database management system (DBMS)</a>. Together, the data and the DBMS, along with the applications that are associated with them, are referred to as a database system, often shortened to just database.<br>In the case of the Rappi example, the database is like the storage warehouse of the restaurant that is serving you.</p><h3>Conclusion</h3><p>I hope that with this overview you have more clarity about what happen when you type something in your browser and see that it is not like a magic box.</p><p><strong>Some useful resourses:</strong></p><ul><li><a href="https://www.oracle.com/database/what-is-database/">https://www.oracle.com/database/what-is-database/</a></li><li><a href="https://www.forcepoint.com/cyber-edu/osi-model">https://www.forcepoint.com/cyber-edu/osi-model</a></li><li><a href="https://www.f5.com/services/resources/glossary/load-balancer">https://www.f5.com/services/resources/glossary/load-balancer</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17d22e9a0560" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/what-happens-when-you-type-a-url-in-your-browser-and-press-enter-17d22e9a0560">What happens when you type a URL in your browser and press ENTER?</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning for my Grandpa…]]></title>
            <link>https://medium.com/swlh/machine-learning-for-my-grandpa-349823bae24d?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/349823bae24d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Mon, 09 Nov 2020 00:25:47 GMT</pubDate>
            <atom:updated>2020-11-09T00:25:47.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*QkihN2zGj35MRTP94StB6Q.jpeg" /></figure><p>Grandparents are amazing, we love them so much. They have a lot of knowledge and almost an answer for everything. It’s easy to talk with them about any topic except when you try to talk with them about how does FaceApp works, since this App works with machine learning algorithms.<br>¿How to explain such a complex topic to your grandfather that have not a background in STEM?<br>The first part is to use a not too technical language in order to avoid that you stay talking alone.</p><p>The second part is to clarify what is and what is not machine learning. For the sake of this article I’ll be referring to you, the reader, as my grandpa.</p><h3>What is Machine Learning?</h3><p>Machine learning is the field of study that gives computers the ability to learn without being explicitly programmed. Remember that computers are very dumb, since we must give instructions to them in order to do something. Basically what machine learning is looking for is to create programs so that we don’t need to give each instruction to our computer, if we achieve this so we say that we are creating an artificial intelligence since we got an entity that take information and do some “rational” thing by itself. It is a very exciting and growing field as it makes computers more similar to humans.<br>Do you remember Netflix and Facebook? Well, they use a lot of this kind of things. For example, when you upload a photo to your Facebook account they can suggest you to tag someone that might be in the photo, or when you are are looking for a movie to watch in Netflix they can suggest you some movie that you might like. So you don’t need necessarily someone that tell you who is in the photo or tell you about a new movie that could enjoy. Hopefully this is making a lot of sense because we haven’t got into the best parts of machine learning. One thing is for sure though, it will play a huge role in our lives going forward.</p><p>Machine Learning is very similar to human learning. Think about the way as children learn, you give them information and when they do or say something wrong you make them an advise. In the case of Machine Learning the child is a program to which a programmer give data, this data should be structured. When the program receives feedback it try to verify or correct the model.</p><p>Through data input and certain commands, the computer is enabled to “learn” to identify certain objects (persons, objects, etc.) and to distinguish between them. For this purpose, the software is supplied with data and trained. For instance, the programmer can tell the system that a particular object is a human being and another object is not a human being . The software receives continuous feedback from the programmer. These feedback signals are used by the algorithm to adapt and optimize the model. With each new data set fed into the system, the model is further optimized so that it can clearly distinguish between “humans” and “non-humans” in the end.</p><p>Machine Learning is a sub-area of artificial intelligence, whereby the term refers to the ability of IT systems to independently find solutions to problems by recognizing patterns in databases. In other words: Machine Learning enables IT systems to recognize patterns on the basis of existing algorithms and data sets and to develop adequate solution concepts. Therefore, in Machine Learning, artificial knowledge is generated on the basis of experience.</p><p>In order to enable the software to independently generate solutions, the prior action of people is necessary. For example, the required algorithms and data must be fed into the systems in advance and the respective analysis rules for the recognition of patterns in the data stock must be defined. Once these two steps have been completed, the system can perform the following tasks by Machine Learning:</p><ul><li>Finding, extracting and summarizing relevant data</li><li>Making predictions based on the analysis data</li><li>Calculating probabilities for specific results</li><li>Adapting to certain developments autonomously</li><li>Optimizing processes based on recognized patterns</li></ul><h3>What is no Machine Learning?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*ovaMCpIPEZL2UchgPZSpqA.jpeg" /></figure><p>Machine learning is not robots out coming to destroy humans like you see in the movies. Terminator is the first thing you may think of when the words artificial intelligence or AI come to mind. That’s another thing I want to talk about to you. Machine learning is not artificial intelligence, but a subset of AI. This field has been around for quite some time, with the roots going back to the late 1950s. During that time period IBM’s Arthur L. Samuel created the first machine learning application, which played chess.</p><p>You always need a Terminator picture when explaining evil A.I.</p><p>Another buzz word you probably heard, which often gets confused with machine learning as much as AI — that is, deep learning. Deep learning has been around just as long as machine learning, but it wasn’t until the 1980s that the field gained traction. Eventually the big companies like Facebook, Google, and Microsoft would invest heavily in the technology. The result has been a revolution for AI. For example, things like Google Translate or Apple’s Siri are examples of the power of the technology. I won’t get into what AI or deep learning is as machine learning is already a big subject to cover by itself. Just know there is no threat with machine learning, maybe with AI though if it gets out of hand.</p><h3>How To Get Machines To Learn</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*mRWUrBRil0goxj3bqyChqg.png" /></figure><p>So you might be thinking how exactly do we get these machines to learn? How does a computer collect all this information and make sense of it? Well I can tell you that there’s a lot of math involved and computer algorithms to help produce the desired results. Alright grandpa, I’m gonna break it down a simple as I can for you, but at the same time explain in detail what is under the hood of a learning machine.</p><h4>The Math That Comes With Machine Learning</h4><p>Math was never my favorite subject, but we’ve all come across linear algebra. Linear algebra is a field of mathematics that is universally agreed to be a prerequisite to a deeper understanding of machine learning. Although linear algebra is a large field with many esoteric theories and findings, the nuts and bolts tools and notations taken from the field are practical for machine learning practitioners. With a solid foundation of what linear algebra is, it is possible to focus on just the good or relevant parts. Math is important in this field because you need to know which algorithms to include when considering accuracy, training time, and a bunch of other stuff.</p><p>The math just helps us find a way to help the machine learn and make sure it does it in the best way possible. Other than linear algebra a scientist/engineer will also need to know the mathematical concepts of Calculus, algorithms, probability theory and statistics. Python is the most used programming language in this field as well. A beginner doesn’t actually need a whole lot of math to get started in this field.</p><h4>Think how does brain works</h4><p>The world has a lot of information and our brain takes it all in to form our view of reality. A computer has to be able to do the same and that’s where a neural network comes into play. <strong>Neural networks</strong> is the most popular way to get a computer to mimic a human brain. Our brains are really good at solving problems, but each neuron is responsible for solving a tiny part of that big problem. Think of it as an assembly line where each neuron in your brain has a certain job to do to solve a problem. So their inspired by the brain, but in neurons in our brain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*o8skjrMqsDajppEPfP-o-A.png" /></figure><p>what way are neurons linked together? Your brain is made up of approximately 100 billion nerve cells and those are called neurons. They have this cool ability to collect and send signals. Think of it like a network with a bunch of wires.</p><p>A neuron takes in inputs and produces outputs. The input nodes (input layer) provide information from the outside world to the network. Similar to how your eyes sees and collects information and sends it to the brain. The output nodes (output layer) are the ones responsible for communicating that information back to the outside world. Let’s say that the network below is trained to recognize digits. So if give a number in the input layer that will go through the hidden layer and then come out the output layer as the number being recognized. The neurons in the hidden layer are going to communicate the information they got from each other to best piece together what number they think is being passed. Each layer influences the next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*UO4Ca9_f_na7Ycbd2RUCrw.jpeg" /></figure><p>Things can get even cooler when you are training to network for other things like audio recognition. Parsing speech or breaking down audio and picking out distinct sounds, which combines to make certain syllables, to certain words, phrases, and etc. This is how you wanna think of it when building your own network.</p><ul><li>convolutional network — for image recognition</li><li>long short-term memory network- good for speech recognition</li></ul><p>Machine learning uses two types of techniques: <strong>supervised learning</strong>, which trains a model on known input and output data so that it can predict future outputs, and <strong>unsupervised learning</strong>, which finds hidden patterns or intrinsic structures in input data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*zbN__o8nP5Xhnr6fRdYpcA.png" /><figcaption>Figure 2. Graphic representation of Supervised and Unsupervised lerning</figcaption></figure><h3>Supervised Learning</h3><p><a href="https://www.mathworks.com/discovery/supervised-learning.html">Supervised machine learning</a> builds a model that makes predictions based on evidence in the presence of uncertainty. A supervised learning algorithm takes a known set of input data and known responses to the data (output) and trains a model to generate reasonable predictions for the response to new data. Use supervised learning if you have known data for the output you are trying to predict.</p><p>Supervised learning uses classification and regression techniques to develop predictive models.</p><p><strong>Classification techniques</strong> predict discrete responses — for example, whether an email is genuine or spam, or whether a tumor is cancerous or benign. Classification models classify input data into categories. Typical applications include medical imaging, speech recognition, and credit scoring.</p><p>Use classification if your data can be tagged, categorized, or separated into specific groups or classes. For example, applications for hand-writing recognition use classification to recognize letters and numbers. In image processing and computer vision, <a href="https://www.mathworks.com/discovery/pattern-recognition.html">unsupervised pattern recognition</a> techniques are used for object detection and image segmentation.</p><p>Common algorithms for performing classification include <a href="https://www.mathworks.com/help/stats/support-vector-machine-classification.html">support vector machine (SVM)</a>, <a href="https://www.mathworks.com/help/stats/classification-ensembles.html">boosted</a> and <a href="https://www.mathworks.com/help/stats/classification-ensembles.html">bagged</a> <a href="https://www.mathworks.com/help/stats/classification-trees.html">decision trees</a>, <a href="https://www.mathworks.com/help/stats/classification-nearest-neighbors.html"><em>k</em>-nearest neighbor</a>, <a href="https://www.mathworks.com/help/stats/classification-naive-bayes.html">Naïve Bayes</a>, <a href="https://www.mathworks.com/help/stats/classification-discriminant-analysis.html">discriminant analysis</a>, <a href="https://www.mathworks.com/help/stats/generalized-linear-regression-1.html">logistic regression</a>, and <a href="https://www.mathworks.com/help/deeplearning/pattern-recognition-and-classification.html">neural networks</a>.</p><p><strong>Regression techniques</strong> predict continuous responses — for example, changes in temperature or fluctuations in power demand. Typical applications include electricity load forecasting and algorithmic trading.</p><p>Use regression techniques if you are working with a data range or if the nature of your response is a real number, such as temperature or the time until failure for a piece of equipment.</p><p>Common regression algorithms include <a href="https://www.mathworks.com/help/stats/multiple-linear-regression-1.html">linear model</a>, <a href="https://www.mathworks.com/help/stats/nonlinear-models.html">nonlinear model</a>, <a href="https://www.mathworks.com/help/stats/regularization-1.html">regularization</a>, <a href="https://www.mathworks.com/help/stats/stepwise-regression-1.html">stepwise regression</a>, <a href="https://www.mathworks.com/help/stats/classification-ensembles.html">boosted</a> and <a href="https://www.mathworks.com/help/stats/classification-ensembles.html">bagged</a> <a href="https://www.mathworks.com/help/stats/classification-trees.html">decision trees</a>, <a href="https://www.mathworks.com/help/deeplearning/function-approximation-and-nonlinear-regression.html">neural networks</a>, and <a href="https://www.mathworks.com/help/fuzzy/anfis.html">adaptive neuro-fuzzy learning</a>.</p><h3>Unsupervised Learning</h3><p><a href="https://www.mathworks.com/discovery/unsupervised-learning.html">Unsupervised learning</a> finds hidden patterns or intrinsic structures in data. It is used to draw inferences from datasets consisting of input data without labeled responses.</p><p><strong>Clustering</strong> is the most common unsupervised learning technique. It is used for exploratory data analysis to find hidden patterns or groupings in data. Applications for <a href="https://www.mathworks.com/discovery/cluster-analysis.html">cluster analysis</a> include gene sequence analysis, market research, and object recognition.</p><p>For example, if a cell phone company wants optimize the locations where they build cell phone towers, they can use machine learning to estimate the number of clusters of people relying on their towers. A phone can only talk to one tower at a time, so the team uses clustering algorithms to design the best placement of cell towers to optimize signal reception for groups, or clusters, of their customers.</p><p>Choosing the right algorithm can seem overwhelming — there are dozens of supervised and unsupervised machine learning algorithms, and each takes a different approach to learning.</p><p>There is no best method or one size fits all. Finding the right algorithm is partly just trial and error — even highly experienced data scientists can’t tell whether an algorithm will work without trying it out. But algorithm selection also depends on the size and type of data you’re working with, the insights you want to get from the data, and how those insights will be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/0*QU0v6x4u-MY20Ukk.png" /></figure><p>Figure 3. Machine learning techniques.</p><h3>Advantages of Machine Learning</h3><p>Machine Learning undoubtedly helps people to work more creatively and efficiently. Basically, you also can delegate quite complex or monotonous work to the computer through Machine Learning — starting with scanning, saving and filing paper documents such as invoices up to organizing and editing images.</p><p>In addition to these rather simple tasks, self-learning machines can also perform complex tasks. These include, for example, the recognition of error patterns. This is a major advantage, especially in areas such as the manufacturing industry: the industry relies on continuous and error-free production. While even experts often cannot be sure where and by which correlation a production error in a plant fleet arises, Machine Learning offers the possibility to identify the error early — this saves downtimes and money.</p><p>Self-learning programs are now also used in the medical field. In the future, after “consuming” huge amounts of data (medical publications, studies, etc.), apps will be able to warn a in case his doctor wants to prescribe a drug that he cannot tolerate. This “knowledge” also means that the app can propose alternative options which for example also take into account the genetic requirements of the respective patient.</p><h3>Machine Learning: The technology leaders</h3><p>In addition to Microsoft, Google, Facebook, IBM and Amazon, Apple also spends enormous financial resources on the use and further development of Machine Learning. IBM’s Watson supercomputer is still the best-known appliance for Machine Learning. Watson is mainly used in the medical and financial sectors. As already mentioned, Facebook uses Machine Learning for image recognition, Microsoft for the speech recognition system Cortana, Apple for Siri. Of course, Machine Learning is also used at Google, both in the area of image services and search engine ranking.</p><p>Cloud providers such as Google, Microsoft, Amazon Webservice and IBM have now created services for Machine Learning. With their help it is also possible for developers who do not have specific Machine Learning knowledge to develop applications. These applications are able to learn from a freely definable set of data. Depending on the provider, these platforms have different names:</p><ul><li>IBM: Watson</li><li>Amazon: Amazon Machine Learning</li><li>Microsoft: Azure ML Studio</li><li>Google: Tensorflow</li></ul><h3>Disadvantages of Machine Learning</h3><p>With all those advantages to its powerfulness and popularity, Machine Learning isn’t perfect. The following factors serve to limit it:</p><h3>Data Acquisition</h3><p>Machine Learning requires massive data sets to train on, and these should be inclusive/unbiased, and of good quality. There can also be times where they must wait for new data to be generated.</p><h3>Time and Resources</h3><p>ML needs enough time to let the algorithms learn and develop enough to fulfill their purpose with a considerable amount of accuracy and relevancy. It also needs massive resources to function. This can mean additional requirements of computer power for you.</p><h3>Interpretation of Results</h3><p>Another major challenge is the ability to accurately interpret results generated by the algorithms. You must also carefully choose the algorithms for your purpose.</p><h3>High error-susceptibility</h3><p><a href="https://en.wikipedia.org/wiki/Machine_learning">Machine Learning</a> is autonomous but highly susceptible to errors. Suppose you train an algorithm with data sets small enough to not be inclusive. You end up with biased predictions coming from a biased training set. This leads to irrelevant advertisements being displayed to customers. In the case of ML, such blunders can set off a chain of errors that can go undetected for long periods of time. And when they do get noticed, it takes quite some time to recognize the source of the issue, and even longer to correct it.</p><h3>The Challenges And Limitations</h3><p>As awesome as machine learning is there are limitations to it. I’ll bring up the biggest ones I think need to be overcome for this technology to continue to move forward. So machine learning algorithms require massive stores of training data and labeling that data is a tedious process. You need to make sure that the data being fed into the machine is labeled. If not, it is not going to get smart over time. An algorithm can only develop the ability to make decisions and behave in a way that is consistent with the environment which is required to navigate. Machines also can not explain themselves and that can be difficult when you want to know why that particular decision was made and how. Lastly, and I think this one is the most important, is to avoid bias. Transparency is important and unbiased decision making builds trust. For example, facial recognition has a large part in social media, law enforcement, and other applications. But biases in the data sets provided by facial recognition can lead to inexact outcomes. If bias finds its way into an algorithm and data sets and the training data is not neutral the outcomes will inherently amplify the discrimination and bias that lies in those data sets.</p><h3>Summary</h3><p>As we saw above Machine Learning is a broad field of study and it will have an important roll in our future. Maybe everyday you use machine learning but now is time understand it. <br>Do you think that your grandfa could understand this way of show the amazing world of Machine learning? <br>Tell me in the comments.<br>Here are some resources where I found elements for this article:</p><ul><li><a href="https://www.investopedia.com/terms/n/neuralnetwork.asp">What Is a Neural Network?</a></li><li><a href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-867-machine-learning-fall-2006/">Machine Learning</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=349823bae24d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/machine-learning-for-my-grandpa-349823bae24d">Machine Learning for my Grandpa…</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python3: Mutable, Immutable…]]></title>
            <link>https://codeburst.io/python3-mutable-immutable-858c28096e9a?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/858c28096e9a</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[type]]></category>
            <category><![CDATA[mutable]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Wed, 30 Sep 2020 01:54:06 GMT</pubDate>
            <atom:updated>2020-10-08T18:29:51.607Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*JHbMT7_x7PxsSuhFlqSoqg.jpeg" /><figcaption>Photo by Chris Ried on unplash</figcaption></figure><h3>Introduction:</h3><p>For a lot of us, Python is a beautiful programing language. It’s easy to pick up, very readable, and easy to maintain. But the main reason why it’s so easy is that there’s so much under the hood. While many people are satisfied with being aware of the complexity of a language without needing to be well acquainted with those complexities, understanding the in’s and out’s of Python will help prevent you from creating major bugs in your programs. The aim of this article is to familiarize you with these details.</p><h4>Objects</h4><p>Let’s start off with the glue that holds everything together: objects. Literally everything is an object. Your module is an object, a function is an object, an integer is an object. Objects are simply instances of classes. We can think of objects as individuals while classes are the groups to which they belong. We are all humans (class human), but I am a unique individual (an instance of class human).</p><p>In Python, everything is an object. Every object has its own data type and internal state (data). Let us first try to understand how data is stored in the memory with below two examples.</p><p><strong>Example 1:</strong> When Python executes a = 1000, this creates an integer object at some memory location say 0x1111 &amp; stores value 1000. Here a doesn’t contain value 1000 but just holds the reference (memory address) to this object. When the next statement a=1500 is executed, another integer object is created at memory location 0x2222 with value 1500 and a now references this new object.</p><p>a = 100<br> a = 1500</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*FXlnSMUk1QaP5b4KEty5Ag.png" /></figure><p><strong>Example 2: </strong>When Python executes a = 2000, as explained in the above example, it creates an integer object at memory location 0x3333 and a will now point to this object. After the execution of b = a, now b also points to the same memory location a is referring to. Note that the value of a is not copied to b but the reference (address) is copied to b.</p><pre>a = 2000<br>b = a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*qN3uv2XfQfrziCEBSy7MRA.png" /></figure><h3>Identity and Type:</h3><p>Before we dive into the intricacies of objects in Python, let’s start off with some background on the two built-in functions: <em>id()</em> and <em>type()</em>. These two functions can give us crucial information about a variable in question. The type function will return the data type of the object, which is most often the same as the class that the object belongs to. For example, if I have a list <em>l</em>, performing <em>type(l)</em> will return the class <em>list</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*0HH83_EJ0laauJEf8uNtpQ.png" /></figure><p>The id function will return the variable identifier of the variable of your choosing. All variables in Python refer to an object and the variable identifier is an integer number that refers to a specific object. In the CPython implementation, this number is the memory address of the object. The id of an object is used to help differentiate between two variables being identical and them being linked to the same object. We can use “==” to determine if they are identical, while “is” can be used to determine if both variables are pointing to the same object. If we have two lists x and y, we can see their ids are unique:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*Yjf2W7puFDnjg8MRetkCDQ.png" /></figure><p>Therefore:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*zO9784cIkWBfAHvGiZKlqw.png" /></figure><p>But if we do this, things start to look weird:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*YMS7cYyESD-GDTBtZm3YzQ.png" /></figure><p>“Wait wait wait !!! What??” you might say, “Two seconds ago I thought those two lists were considered to be different. Why are these the same?” To answer that question, we must go deeper into the subject of mutability.</p><h3>Mutable Objects:</h3><p>So, what is mutability? Simply said it is the ability to mutate — or alter — an object. Some built-in mutable types in Python include lists, sets, dicts, and bytearrays. Let’s look at an example with our good friend the list. We can append items to our list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*QDZ-k3hvNH7e4C8ogb1y3A.png" /></figure><p>We can remove items from our list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*iNvc6ThibhcneSSEvxY7-w.png" /></figure><p>Like I said before, <strong>everything</strong> in Python is an object. So every element in the list is <strong>also</strong><em> </em>an object. If we start looking a little closer, things start to get weird again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*WWGHYwnNhcZ-LEgzfftojA.png" /></figure><p>Why did <em>l[1]</em>’s id change? The list’s id didn’t change when we altered its values, so why would its element? It’s because integers and strings are <strong>not</strong> mutable.</p><h3>Immutable Objects:</h3><p>Immutability is exactly what it sounds like: the opposite of mutability. This means that you cannot change the contents of the object. Some built-in immutable types include ints, floats, complexes, strings, tuples, frozensets, and bytes. So in the above example, the list object initially contained references to the objects “1”, “2”, and “3”. Since we cannot change the object itself, the list changed which <em>reference</em> it held, such that it now contains a reference to the object “Hello”. In other words, a reassignment occurred. While we cannot append an immutable object, we can still do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*YeQzoXQ6lsFWWw4X3TZVGA.png" /></figure><p>While it seems like we appended “Hello” to “ World”, what actually happened was something more along the lines of:</p><blockquote><em>s = s + “ World”</em></blockquote><p>The value of s, “Hello”, plus “ World” was calculated and s was given the reference to this new object. A similar process happens when adding numbers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*dmxzSXVM3JqD0awf7fUXkA.png" /></figure><p>If you try to change an element in an immutable set, however, the interpreter will raise an exception:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*RQ20hFIriyeM0fhI_5_7iw.png" /></figure><p>Similarly, while you cannot actually remove an element in an immutable object, you can slice the object, which will return a new object containing the desired values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*5YE_m0j_ACA4KDQB8J5iQw.png" /></figure><p>Since Python must create a separate object for each unique immutable value (which takes up a lot of memory) the interpreter cleverly optimizes its creation of objects. It does so by using the same reference number for objects that cannot change, such as strings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*YMS7cYyESD-GDTBtZm3YzQ.png" /></figure><p>In the CPython interpretation, it goes one step further and stores all common small int objects (-5(inclusive) to 257(exclusive)) in an array for easy reference. Unlike other objects, which are created as needed and destroyed once there are no more variables referencing that object, these small int objects remain throughout the program.</p><h3>Preallocation in Python</h3><p>Now, some homework for you:<br>1. Create two variables with values between -5 and 256 and then check if they reference the same object.<br>2. Do the same as above but use values for the variables out of the range above.<br>What happened?</p><p>In Python, upon startup, Python3 keeps an array of integer objects, from -5 to 256. For example, for the int object, macros called NSMALLPOSINTS and NSMALLNEGINTS are used. Let’s go check the source code:</p><pre>#ifndef NSMALLPOSINTS<br>#define NSMALLPOSINTS           257<br>#endif<br>#ifndef NSMALLNEGINTS<br>#define NSMALLNEGINTS           5<br>#endif<br>#if NSMALLNEGINTS + NSMALLPOSINTS &gt; 0<br>/* References to small integers are saved in this array so that they<br>   can be shared.<br>   The integers that are saved are those in the range<br>   -NSMALLNEGINTS (inclusive) to NSMALLPOSINTS (not inclusive).<br>*/<br>static PyIntObject *small_ints[NSMALLNEGINTS + NSMALLPOSINTS];<br>#endif<br>#ifdef COUNT_ALLOCS<br>Py_ssize_t quick_int_allocs;<br>Py_ssize_t quick_neg_int_allocs;<br>#endif</pre><p>What does this mean? This means that when you create an int from the range of -5 and 256, you are actually referencing the existing object.<br>This is done so as to avoid to creating objects that are commonly used and because — in this way — you can represent any ASCII character.</p><h3>Why Does It Matter?</h3><p>When assigning variables, understanding the differences between mutable and immutable objects is key. Mutable objects have quite some tricks up their sleeves. In an earlier example we showed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*Yjf2W7puFDnjg8MRetkCDQ.png" /></figure><p>However, if we assign y like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*NjS-FqublszmBSoWRG9yTQ.png" /></figure><p>How is y the same object as x? I thought they were different objects before? Well, the way in which assignments occurs in Python is crucial. In this case, we have not assigned a new object to y, but instead <em>aliased</em> it to x; meaning that we gave it the same <em>reference </em>as x. Since both now point to the same object, a change in one will affect a change in another:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*D7VQZKvjXfFWrAaAtabShw.png" /></figure><p>But what if you want to make a copy of your object without worrying about altering your original? Just like how slicing of immutable objects returns a new object, so does the slicing of lists:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*gv9Q_Dfd96vPH-L5aRdnZQ.png" /></figure><p>Appending to lists can be a bit tricky as well. In Python, whatever is evaluated on the right side of the assignment expression is then referenced by whatever is on the left side of the expression. Therefore:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*nUrileCO3B5oPLsvjhacXg.png" /></figure><p>A new list is created since the right side of the assignment was evaluated as [1, 2, 3, 4, 5] and that new object was made referenced by l. However, if we do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*aMZTCiyp6SrwFWEtoG7LhA.png" /></figure><p>We can see that the object remains the same. This is called assignment in-place, and is equivalent to appending to the list. However, since immutable objects cannot be changed, the expressions a<em>+= b </em>and <em>a = a + b</em> would function the same, similar to our “Hello World” example above.</p><h3>Passing Arguments to Functions:</h3><p>In other programming languages, arguments are often said to be passed one of two ways: by <em>value </em>(wherein a new variable is given the same value as the argument passed) or by <em>reference </em>(wherein a variable holds a reference to the data such that it could be changed). Python, however, is unique. Python passes the reference to the object. Similar to how we aliased x = y, the function’s argument is aliased to the object reference by the variable passed to the function. This means that if a reassignment occurs inside of the function, it will not alter the original variable passed to the function. Since immutable types cannot be altered any change to the variable inside of the function will not persist:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*jr9ev70l94HgRF48fVgSRQ.png" /></figure><p>However, since lists are mutable, you can alter their contents:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*OGuP4QOJMzDMhijZE1AGZA.png" /></figure><p>Notice how the reference to the list remained the same throughout the program. If we were to reassign l inside the function, however, it would not affect the original list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*v8ERuop4f_XjIMstvZTFZQ.png" /></figure><h3>Exceptions in immutability</h3><p>Not all of the immutable objects are actually immutable. Confused? Let me explain.</p><p>As discussed earlier, Python containers liked tuples are immutable. That means value of a tuple can&#39;t be changed after it is created. But the &quot;value&quot; of a tuple is infact a sequence of names with unchangeable bindings to objects. The key thing to note is that the <em>bindings</em> are unchangeable, not the objects they are bound to.</p><p>Let us consider a tuple <strong>t = (‘holberton’, [1, 2, 3])</strong></p><p>The above tuple <strong>t</strong> contains elements of different data types, the first one is an immutable string and the second one is a mutable list.The tuple itself isn’t mutable (i.e. it doesn’t have any methods for changing its contents). Likewise, the string is immutable because strings don’t have any mutating methods. But the list object does have mutating methods, so it can be changed. This is a subtle point, but nonetheless important: the “value” of an immutable object <em>can’t</em> change, but it’s constituent objects <em>can</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*mlY6TNtXby36WGuMVPLp6w.png" /></figure><h3>Conclusion</h3><p>Having a grasp of the ins and outs of a language can be immensely helpful. While many programmers won’t take the time to become familiar with the languages they use on a daily basis, taking the time to become acquainted with Python is a great way to avoid bugs and get a leg up on the competition. In addition to this, having the discipline to sit down and learn about what goes on under the hood of a language is a great skill that will stand you in good stead as you progress on your coding journey. I hope this article has been helpful, please leave any feedback you have in the comments section!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=858c28096e9a" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/python3-mutable-immutable-858c28096e9a">Python3: Mutable, Immutable…</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type ls -l ?]]></title>
            <link>https://garzondeiber6.medium.com/what-happens-when-you-type-ls-l-1ba0ce4077af?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ba0ce4077af</guid>
            <category><![CDATA[wait]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[fork]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[syscalls]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Thu, 20 Aug 2020 03:15:41 GMT</pubDate>
            <atom:updated>2020-08-20T03:15:41.569Z</atom:updated>
            <content:encoded><![CDATA[<h3>What happens when you type ls -l ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*hPGTclNCpKumKATF9Pt9MA.png" /></figure><p>Before carry up with the content of this article, if you are familiar with the shell and command ls -l you can skip the first part.<br>If you aren’t, then the introduction is for you ;).<br>***</p><h3>INTRODUCTION</h3><p>So, What is the shell?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*LH1le-hnryYJ5cGvIiUX7w.png" /></figure><p>The shell is a program that takes commands from the keyboard via the terminal and gives them to the operating system to perform.</p><p>A terminal is simply a program that opens a window and lets you interact with the shell.</p><p>An operating system is the software that runs the computer. It manages the computer’s memory and processes, as well as all of its software and hardware.</p><p>The kernel is the core of the operating system.</p><p>HOW DOES THIS WORK?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*RmJa1r0E0LGavjF49BnwpQ.png" /></figure><p>Since the most common operating system is Windows, It’s usual for us to use our mouse and click on whathever we like . For example, when we wnat to open a file we just do double click on it.<br>BUT when you interact with the shell, You can’t use your mouse, you instead:</p><p>1- Open the terminal in order to interact with the shell.</p><p>2- Type your command to tell your shell what you want to do.</p><p>3- The shell receives your command and gives it to the operating system to perform.</p><p>4- Your command is executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*mkx5TBUQiSrZ2q_4zwFrTA.png" /></figure><h3>What is ls? (it is “LS”, not “is”!!)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*3m9ASK55Hy0eUT7DfH1Wgg.jpeg" /></figure><p>With this command we use to print the content of a directory. It means that you list the names of the files that are in your current directory.</p><p>For this example above, in my home directory, I typed the command ls Then I pressed ENTER. The result is: the directories and files that are in my root directory.</p><h3>What does -l refer to?</h3><p>“-l” is an argument of the ls command that means Long Listing Format.</p><p>In other words, when we enter “ls –l” to the shell, we will get a file listing that contains the filename, modification time, size, group, owner and permissions of each file per line.</p><h3>So , What does the shell actually do?</h3><p>PROMP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*n668HXCAnpsn23YLr3xsmg.png" /></figure><p>Berofe you type anything, the shell prints a prompt to you which normally ends with an “$” sign. The prompt or command line is where you’ll type your command.</p><h3>Read entered line</h3><p>Second, after you type your command, the shell reads what you typed using the getline function.</p><p>The getline function reads the entered line as one string, from the standard input and stores it in a buffer.</p><h3>About getline:</h3><pre>ssize_t getline(char **lineptr, size_t *n, FILE *stream);</pre><p>The function getline reads using the system call read. It receives a file pointer (stream) which is the file to be read, an address of a pointer to a string (*lineptr), which will be used to store the read line, and a pointer to an unsigned int/size_t (*n), which is the size of the buffer (*lineptr).</p><p>If the buffer doesn’t point to any allocated memory area, then getline allocates memory area. Also, If the buffer is not large enough to hold the line, getline() resizes it with realloc, updating *lineptr and *n as necessary.</p><p>After reading the line and storing it in the buffer, the getline returns an int/ssize_t which is equal to:</p><ol><li>The number of characters read, on success, without including the terminating null byte of the string.</li></ol><p>2. -1, on failure to read a line (including end-of-file condition).</p><p><em>The programmer must free the allocated memory of the buffer at the end of the program.</em></p><h3>Split line to array of words</h3><p>After having the whole command in a single string, the shell splits the string into an array of words using the function strtok and the delimiters “ “ (space) and “\n” (the newline character). That means, if we entered “ls –l /bin”, the string becomes this array: {“ls” , “-l”, “/bin”}.</p><ul><li>First element of array = “ls”</li><li>Second element of array = “-l”</li><li>Third element of array = “/bin”</li><li>Forth element of array = NULL</li></ul><p>You can see here that, the first word in our array, is the entered command, which is “ls” and the rest of words are (generally) the arguments of that same command.</p><p>Now, it’s easy for the shell to know what command we entered.</p><h3>Types of commands</h3><p>Before moving to the next steps is important to see the 4 types of commands:</p><p>Commands can be one of 4 different kinds:</p><p>1- An alias. Commands that you can define, built from other commands.</p><p>2- A command built into the shell itself. The cd and exit commands, for example, are shell built-ins.</p><p>3- An executable program like the ls command.</p><p>4- A shell function. These are miniature shell scripts incorporated into the environment.</p><p>After putting the command as the first element in the array of words, the shell checks the type of the command. If the command is an executable program, then the shell needs to parse the PATH.</p><h3>What is the PATH?</h3><p>The PATH is an environmental variable that tells the shell which directories to search for executable files. The directories are written separated by colons ‘:’</p><p>You can print all of your environmental variables using the command “env” or “printenv”.</p><p>In the picture below we use the echo command to print the value of PATH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*bN6Mq1uc1Rkzf6xntRSa9Q.jpeg" /></figure><p>When the command is an executable program, the shell parses the directories in PATH, one after another, in order to find which directory is the container of the given command. For example, the directory that contains “ls” is “/bin”. So the pathname of “ls” is “/bin/ls”.</p><h3>Stat system call</h3><p>For more details, the shell takes the name of the directory and concatenates it to “/” and to the command name then uses the “stat” system call to check if the result string is a valid pathname.</p><pre>int stat(const char *pathname, struct stat *statbuf);</pre><p>For example, the first directory in our PATH variable is /usr/local/sbin. The Shell concatenates the 3 strings: “/usr/local/sbin” + “/” + “ls” together and the result string is “/usr/local/sbin/ls”. Then, the shell passes the result to the stat system call.</p><p>The stat system call returns 0 if the pathname is valid or -1 if the directory is wrong.</p><p>In our example, the stat returns -1 because the command ls exists in the directory /bin, NOT in /usr/local/sbin.</p><p>The shell keeps parsing PATH directories and testing with stat each time, till it finds the right directory for “ls”.</p><h3>Command execution/ fork, execve and wait</h3><p>After finding the location/pathname of the command, the shell executes it.</p><p>The execution of commands happens using the system calls: fork(), execve() and wait().</p><p>The function execve executes the program referred to by the pathname. The pathname must be either a binary executable, or a script starting with a line of the form: #!interpreter [optional-arg]</p><p>The function execve receives 3 arguments:</p><pre>int execve(const char *pathname, char *const argv[], char *const envp[]);</pre><p>1- The pathname of the program. For example, “/bin/ls”</p><p>2- The array of argument strings of the program while the first element of the array should be the pathname of the program. For example, {“/bin/ls”, “-l”, “/tmp”, NULL}</p><p>3- Array of environment variables</p><p>If there’s an error, For example, if execve is given an invalid command, execve returns -1.</p><p>On success, execve() does not return. That means the current process EXITS !</p><h3>What is fork() and why do we need it?</h3><p>In order to avoid exiting the shell after running the function execve, the role of system call “fork()” comes into play.</p><pre>d = fork();</pre><p>The fork() creates a new process by duplicating the calling process. The new process is referred to as the child process. The calling process is referred to as the parent process.</p><p>The need for child process is when we want the child to do some tasks and exits without having the parent process exiting.</p><p>So before using the execve function, the shell creates a child process, using fork(). Then, uses the execve function only inside the child process. When the execve succeeds and exits the process, only the child process exits while the parent process keeps on running.</p><p>In the meanwhile, the parent process uses the wait() system call in order to suspends its execution until its child process terminates.</p><pre>Wait(&amp;status);</pre><h3>What happens after execution?</h3><p>After the execution of the command with its arguments, the shell frees the allocated memory areas and reprints the prompt again waiting for the next command.</p><p><em>The process is repeated over and over till the user exits the shell.</em></p><h3>Time to exit the shell</h3><p>Exiting the shell can happen in 3 ways:</p><p>1- Typing the command “exit” OR “exit n” (while n is an integer)</p><p>2- Pressing on Ctrl + D (which marks the EOF, end of standard input file)</p><p>3- Pressing on Ctrl + C (which is defined as a signal to exit)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ba0ce4077af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type ls *.c?]]></title>
            <link>https://garzondeiber6.medium.com/what-happens-when-you-type-ls-c-ef7b28d50d9f?source=rss-3c327c0ccbc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef7b28d50d9f</guid>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[unix]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[type]]></category>
            <dc:creator><![CDATA[Deyber Castañeda]]></dc:creator>
            <pubDate>Thu, 11 Jun 2020 03:10:38 GMT</pubDate>
            <atom:updated>2020-06-11T03:10:38.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*m8yiTFHL0JAlncOdbnIyqA.jpeg" /></figure><p>If you are starting to use Linux or Unix-like operating sistems maybe you want to know what are the things that you have in your machine.<br>The terminal allow us to know that through a command and their options, <br>This command is <strong>ls <br></strong>This list the content of the current directory. Some options of this command are the following.<br><strong>-l</strong> Show the content in long format<br><strong>-a</strong> This allow us to see the hidden files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*miGQt44W4H3WON6NAA32VA.png" /></figure><p>Like these are a lot of option to list the content of directory.</p><p>Also there is a concept that is nessesary to undestand the answer to the tittle of this publication and are the wilcard characteres.</p><p>Wildcard characters:<br>The three main wildcard characters are,</p><p>Star or Asterisk (*)<br>Question mark (?)<br>Square brackets ([])<br>Asterisk (*) is used to search for particular character(s) for zero or more times. Question mark (?) is used to search for a fixed number of characters where each question mark (?) indicates each character. Square brackets are used to match with the characters of a defined range or a group of characters.</p><p>So, If we combine the ls command with the * wildcard character we will have an excellent way to list the files or directories that have a .c extension.<br>In this case this extension means that the file is a c program.</p><p>I hope that you get undestand what does the ls *.c command and you can apply it in your projects. Good luck.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef7b28d50d9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>