<?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 Renato Leon on Medium]]></title>
        <description><![CDATA[Stories by Renato Leon on Medium]]></description>
        <link>https://medium.com/@rleons?source=rss-49bf8e5e6246------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ooWMWg0cNQ2kQzt5.jpg</url>
            <title>Stories by Renato Leon on Medium</title>
            <link>https://medium.com/@rleons?source=rss-49bf8e5e6246------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:22:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rleons/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[Final project experience at Holberton’s first year]]></title>
            <link>https://rleons.medium.com/final-project-experience-at-holbertons-first-year-2e2aa1e25f0?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e2aa1e25f0</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Wed, 03 Nov 2021 19:51:38 GMT</pubDate>
            <atom:updated>2021-11-03T19:51:38.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M03GcjMSxsA6oTo_ZWDVxA.png" /></figure><p>Everything that starts, someday has to end, and the first year at Holberton has come to its end for us, this experience was a great one, not only for the things we’ve learned but also for the people we got to know, this journey had its ups and downs, but after all, we learned how to deal with it.</p><p>The final project our team worked on was a help-desk system to attend issues that could happen in a working environment, this system was required for a company we could be in touch with during the developing process, the key features they asked us to implement were that the system had to be able to manage 3 roles: admin, agent and user, giving each one of them specific actions like creating and attending tickets, updating profile information and showing a summary of the generated tickets.</p><p>The goal of this project was to give users the ability to report any issue that could happen during his/her working hours and create tickets explaining the incident, so an agent could take a ticket and attend the issue, solving it the quickest possible.</p><p>We as a team accepted the challenge and put to work into building this system, before going much deeper into the project detail let me introduce the team I worked with by giving a description of the roles each of us took during the project:</p><ul><li><strong>Joshua Enrico:</strong> Took care of front and back-end, he paid more attention to the database and managed to implement a chat feature to communicate users and agents.</li><li><strong>Renzo Perez: </strong>Took care of front-end design, he made sure to build all the templates needed for the user to interact with the system covering every feature available.</li><li><strong>Renato Leon(me):</strong> Took care of part of the API for ticket administration and also worked in a security feature involving authentication and authorization.</li></ul><p>As a team we divided the work in 3 weeks:</p><p><strong>Week 1:</strong></p><ul><li>Conversations with the product owner</li><li>Specify system requirements</li><li>System design</li><li>Architecture design</li><li>Technology selection</li></ul><p><strong>Week 2:</strong></p><ul><li>Select roles</li><li>Create GitHub repo</li><li>Dependencies installation</li><li>Implementation of core features</li></ul><p><strong>Week 3:</strong></p><ul><li>Implement API endpoints</li><li>Implement view controllers</li><li>Implement front-end views</li><li>Deploy App on AWS</li></ul><p>Personally my focus was on the system to be the most organized as possible, thinking about future changes, maintaining a good file organization makes adding new features easier than adding them in an unorganized project, so I talk about this with my peers, and we had to change and rename some files, create new folders and standardized the way of development if we wanted this project to be extensible, fortunately we could collaborate to make that happen, although it took almost a day to refactor all the files and code we had until that point.</p><p>The decision to work on this project came from the fact that the case or better, the challenge was proposed by a real company, so it made it attractive for our team, we thought of this as a way of start getting experience on what we could be doing once we graduate and start working, so the deal was to make the system the best we could, for me was the first time working in the development of a system like this, I though the complexity would be higher than it really was, so I was kind of obsessed with the final product to be more than just good, it had to be impeccable, easy to use and yet powerful, to cover all requirements, fortunately I always had the team support, and together we could accomplish to finish the project on time.</p><p>Put simply, this is how our application works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*3Eo9UoHm0JPd6CZNh8D73g.png" /><figcaption>App architecture</figcaption></figure><p>For the backend we chose to work with flask, due to its flexibility and also because all the team members knew this framework, this made it possible to accelerate the developing process, for the frontend we used jQuery, HTML, bulma and bootstrap, this decision was made by our frontend developer, as he explained to us, his choice was backed up by the fact that he had experience working with most of these libraries, and also because he wanted to try new libraries like bulma for example.</p><p>Some features we implemented:</p><ul><li>User authentication using tokens, allowing access only to authenticated users</li><li>Ticket creation, a user can create tickets for each issue they encounter during his/her working hours</li><li>User administration, the admin can mage user information, can allow and restrict user access to the system</li><li>Agent updates over tickets, an agent can take a ticket and mark it as solved also</li><li>Real-time chat, users and agents can have real-time chats over each created ticket.</li><li>The app is fully responsive, this makes our application compatible with phones, giving users easy access and navigation from their mobile devices</li></ul><p>Fortunately for this project, our team didn’t report any technical challenge, we knew the majority of the frameworks and libraries we chose, so no technical challenges appeared during the developing process.</p><p>By working on this project I learned how to combine different technologies and make them work together, even though I didn’t interact much with front-end, I also could learn something about the frameworks and libraries we can use to make front-end look awesome because at some point in the project I had to implement some pages and I did it by taking the already created pages as base model, other important thing I learned is to work with a team, maybe we could improve better at communication but he experience was fine.</p><p>If I have to do something different would be to work more as a team, maybe by having meetings more frequently, improve communication and also make better decisions to start with the project, agree on the standards to use, so each member knows what the others are doing and thus avoiding lose time trying to understand each other’s code when asked to implement new features.</p><p>After all, I consider that we made a good job, personally I’m interested on how applications work at higher level and try to grasp this knowledge by making diagrams, drawing components and make them interact with each other.</p><p>If you’re interested, <a href="https://ticket-system-landing.netlify.app/">here</a> is the project’s landing page, <a href="http://18.117.242.243:5000/">here</a>, the deployed application, and <a href="https://www.linkedin.com/in/rennleon/">here</a>, my LinkedIn profile.</p><p>This journey has come to its end, hope you learned something from this post, take care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e2aa1e25f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[STEM and Full-Stack Web Development]]></title>
            <link>https://rleons.medium.com/stem-and-full-stack-web-development-2ac40bf3d561?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ac40bf3d561</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Sun, 17 Oct 2021 17:31:58 GMT</pubDate>
            <atom:updated>2021-10-19T05:01:21.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D80gdGMuGZANSOh0.png" /></figure><p>STEM is one of those terms you’ve probably have heard before, so I bet you might know what we refer to when we talk about STEM, now, what about Full-Stack, if you have some experience in programming I can be 100% sure you’ve heard this before, but if you still don’t know about these terms or just want to remember and learn something new, join me, and let’s figure out together what all of this means is a simple and yet understandable way.</p><p>So, without further to do, let’s begin with STEM.</p><h4>What does “STEM” mean?</h4><p>STEM is an acronym for the fields of science, technology, engineering, and math.¹</p><p>The STEM <a href="https://www.merriam-webster.com/dictionary/acronym">acronym</a> was introduced in 2001 by scientific administrators at the U.S. <a href="https://www.britannica.com/topic/National-Science-Foundation">National Science Foundation</a> (NSF). The organization previously used the acronym SMET when referring to the career fields in those disciplines or a curriculum that <a href="https://www.merriam-webster.com/dictionary/integrated">integrated</a> knowledge and skills from those fields. In 2001, however, American biologist Judith Ramaley, then assistant director of education and human resources at NSF, rearranged the words to form the STEM acronym. Since then, STEM-focused curriculum has been extended to many countries beyond the United States, with programs developed in places such as Australia, China, <a href="https://www.britannica.com/place/France">France</a>, <a href="https://www.britannica.com/place/South-Korea">South Korea</a>, Taiwan, and the United Kingdom.²</p><p>In today’s post, the focus will be centered on Full-Stack development which is part of STEM careers. maybe you have some idea of what we mean when we say Full-Stack, or maybe you have a misconception of what a Full-Stack developer is and what he/she does. Commonly, Full-Stack development is divided into 2 parts, the first one being Fronted development and the last one being Backend development, meaning that a Full-Stack developer must take care not only with the part of the system that interacts with the user but also with the part that interacts with data and business logic, providing them with the ability to understand almost the entire system. To give a better understanding of what we mean with frontend and backend, pay attention to the following picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*DcPMkKijKZAtHyIM.png" /></figure><p>Just focus on the two parts the image is divided into, on the left side we can see a computer, which in this example is our client, and on the right side, we can see something that most people are not familiar with, which is a server, keep it simple, a server provides functionalities for clients to consume.</p><p><strong>Front end:</strong> This is the visible part of a website or web application that is responsible for user experience. The user directly interacts with the front-end portion of the web application or website.³</p><p><strong>Back end:</strong> Refers to the server-side development of web applications or websites with a primary focus on how the website works. It is responsible for managing the database through queries and APIs by client-side commands. This type of website mainly consists of three parts front end, back end, and database.³</p><p>So, as you might be thinking:</p><p><strong>Full-Stack Development:</strong> Refers to the development of both <strong>Front-End</strong>(client-side) and B<strong>ack-End</strong>(server-side) portions of web application³</p><p>Well, now you know what Full-Stack means, so, based on what we know now, let’s take a step further and solve some questions related to this developer position.</p><h4>Why is Full-Stack important?</h4><p>Internet is a powerful tool used by millions of people each day, it helps to connect users and businesses and it also supports thousands of thousands of transactions, giving users the ability to buy online, businesses know this and that’s why they’re getting online too, but to so, they need some help, the kind of help that a full-stack developer could give. Businesses always want to become better in their market, in the digital world that we live in now is essential that they have a digital presence to maintain the business competitiveness, because of his/her understanding of how a system and the internet works, a full-stack developer can help businesses to make that happen, keep them competitive and adapt their processes to the digital world.</p><p>Today, companies are looking for innovative and action-driven talent for website development. There are many web developers, but real and best Full Stack developers are harder to find. They are looking for highly talented employees who can bring flexibility and promise more efficiency. They want someone who can do multitasking tasks and save money on their business by investing in someone who does both web development tasks!⁴</p><h4>What makes Full-Stack interesting and unique?</h4><p>A full-stack developer is comfortable working in back-end and front-end, meaning that it knows enough to build entire apps by putting each part of the system together, this gives full-stack developers a whole range of opportunities and also the ability to put his/her skills on interesting projects, we could say that the imagination could be the limit for a good full-stack developer, the fact that a full-stack can work in front-end and back-end does not mean that he/she knows every single detail of each technology, it means that is a person that has a lot of experience in both parts and knows enough to understand what is going on with each of them.</p><h4>What makes this Full-Stack similar to others?</h4><p>Software engineers and full-stack developers are often used synonymously in the industry. Sometimes these job titles will mean the same thing. While at other employers, these two job titles may mean completely different things. Some employers designate back-end tasks to software engineers while keeping their full-stack developer a generalist who works with every layer of the web application. Some employers expect software engineers to work with local computer systems instead of web applications and websites. Then some companies assign software engineers to code-heavy tasks while putting full-stack developers on tasks like user experience research, front-end design, architecture planning, and deployment, along with some coding tasks. Long story short, read the job description before applying.⁵</p><h4>What specific programming languages and tools could one expect to work with being a Full-Stack developer?</h4><p><strong>Languages:</strong></p><ul><li><strong>Front-end: </strong>HTML, CSS, JS</li><li><strong>Back-end: </strong>Python, Ruby, Java, PHP, C#</li><li><strong>Database: </strong>PostgreSQL, MySQL, MongoDB</li></ul><p><strong>Other technologies:</strong></p><ul><li><strong>Frameworks and libraries: </strong>React, Vue, JQuery, Django, Flask, Laravel, ASP.net, Spring, Maven</li><li><strong>Version control:</strong> Git, Github</li></ul><h4>What is an example of a problem or a challenge a Full-Stack developer could solve or be asked to work on?</h4><p>As a Full-Stack developer, you must be prepared to take on huge challenges, for example, if someone asks you to put their business online, you have to be prepared to take that project and make the most out of it since gathering all the needed information about the business until deploying your solution and helping the business growth, you’ll learn that being a Full-Stack developer is much more than just knowing how to write code, besides from writing code, you must be able to ask the appropriate questions to develop a system that supports the business processes and also you must take into account adequate quality indicators that will ensure the success of the project, examples of this indicator could be: extensibility, maintainability, scalability, etc.</p><p>A simplified example of a challenge could be building an e-commerce app, for example, under this project, you can be asked to build an e-commerce for some business, the goal would be to develop a standard e-commerce website that displays products to be sold, allows users to purchase those products and give the owner some metrics of his/her business.</p><ul><li>The website should display the products and their stock</li><li>Users should be able to select products and add them to the cart</li><li>The app should be highly available, and allow users from different countries to purchase at any time.</li><li>The app should display content in the customer’s preferred language.</li><li>The owner should have a dashboard where he/she can see daily reports of income and products sold.</li><li>The system should give feedback and alerts to help to anticipate being out of stock.</li><li>The system should show recommendations for customers based on his/her preferences.</li><li>The system should allow making payments online.</li><li>The system should be secure and ensure customers&#39; data privacy.</li></ul><h4>What are some positives and negatives about Full-Stack?</h4><p>Develop apps is fun to do if you know what you’re doing, so if you enjoy the process of writing code and solving problems, believe when I say that you’ll have much fun working as a full-stack developer, but there are times when you could feel down, like everything in life, this work also has its ups and downs, positives and negatives, as you prefer to call it, so keep these facts in mind before you make a decision to become a full-stack developer.</p><p><strong>Positives:</strong></p><ul><li>Due to the responsibility the job requires, it helps improve not only your technical but also soft skills.</li><li>Can adapt to the working environment, if asked to work on back-end he/she can do it, the same for front-end</li><li>Able to work on multiple projects at the same time</li><li>Can develop an entire app from scratch</li></ul><p><strong>Negatives:</strong></p><ul><li>You could feel overwhelmed by the number of tasks that need to be done</li><li>A full-stack developer is not a specialist in any technology, he/she know enough to understand it by not master it</li><li>Sometimes, the deadline comes before expected because of bad time management</li><li>Only works with the technologies he/she knows, and forget about the trends</li><li>Responsibilities could not be well defined in some working environments</li></ul><p>Full-Stack development is an interesting job, sometimes could be demanding but that’s the key to improving your skills, I hope this blog post helped you learn something new, and as always, take care and see you!! … on the next one.</p><p>[1]: Homeland Security (September 30, 2011), What does STEM stand for, <a href="https://studyinthestates.dhs.gov/2011/09/what-does-stem-stand">https://studyinthestates.dhs.gov/2011/09/what-does-stem-stand</a></p><p>[2]: Britannica, STEM, <a href="https://www.britannica.com/topic/STEM-education">https://www.britannica.com/topic/STEM-education</a></p><p>[3]: GeeksForGeeks (June 27, 2019), What is full-stack development? <a href="https://www.geeksforgeeks.org/what-is-full-stack-development/">https://www.geeksforgeeks.org/what-is-full-stack-development/</a></p><p>[4]: Forcebolt (January 28, 2021), 6 Amazing Facts About Full Stack Development, <a href="https://www.forcebolt.com/6-amazing-and-useful-facts-about-full-stack-development/">https://www.forcebolt.com/6-amazing-and-useful-facts-about-full-stack-development/</a></p><p>[5]: LightHouseLabs, Web Developer Career Paths In 2021, <a href="https://www.lighthouselabs.ca/en/blog/coding-careers">https://www.lighthouselabs.ca/en/blog/coding-careers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ac40bf3d561" 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://rleons.medium.com/what-happens-when-you-type-a-url-in-your-browser-and-press-enter-c7a09b32f8ba?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7a09b32f8ba</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Thu, 02 Sep 2021 21:09:02 GMT</pubDate>
            <atom:updated>2021-09-05T22:19:26.107Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*Bi90Aihe5X9sif_f.png" /></figure><p>Have you ever wonder about all the stuff that goes behind the scenes when you type some URL in your browser and then press enter?, noup?, well then, in this blog post I’ll explain that process along with some web architecture related stuff, so, let’s begin.</p><p>Before diving in, let’s check some previous concepts:</p><ul><li><strong>Uniform Resource Locator (URL):</strong> In simple words, is a string that allows us to specify a web address. As we know if we want to visit or access some resource on the internet, we need a web address just as if we would want to visit someone, we may need his/her house address, the same applies on the web.</li><li><strong>Domain Name Service (DNS): </strong>This is a naming system for computers, we would mostly use it to relate domain names to IP’s using the record entry type ‘A’</li><li><strong>DNS request: </strong>A type of request made to get back some server IP, all we know is the domain and what we want to know is the IP of the server that domain refers to.</li><li><strong>Transmission Control Protocol / Internet Protocol (TCP/IP): </strong>Widely used protocols on the internet, provides end to end communication and specifies how data show be handled (packetized, addressed, transmitted, etc),</li><li><strong>Firewall: </strong>Security device that helps protect our network by filtering incoming and outgoing traffic.</li><li><strong>HyperText Transfer Protocol Secure (HTTPS): </strong>Extension of HTTP, is a secure version of the latter protocol, this protocol encrypts the communication using Transport Layer Security (TLS) formerly Secure Sockets Layer (SSL), when we request something using this protocol, that request gets send by default at port 443, and if we refer to HTTP then the port 80 is used.</li><li><strong>Secure Socket Layer (SSL): </strong>Predecessor of TLS, is an encryption-based security protocol that helps to establish authenticated and encrypted links between devices over the internet.</li><li><strong>Load balancer: </strong>Network device able to distribute network or application traffic across multiple servers.</li><li><strong>Web server: </strong>Software and hardware that communicates over HTTP, waiting for incoming requests and giving responses back to each one of them, can serve static content such as HTML, plain text files, images, video, etc.</li><li><strong>Application server: </strong>Hosts applications in the way of business logic and interacts with the database, can manage multiple protocols, and helps with the dynamic interaction between the apps and the clients.</li><li><strong>Database: </strong>An organized collection of data that can be easily managed, updated, and accessed.</li></ul><p>Knowing these concepts will help us understand better how the web world works, now, we’ll focus on what we are here, to explain what happens when we type some URL and then press enter.</p><p>For example, I’ll take the following URL: <a href="https://www.holbertonschool.com/">https://www.holbertonschool.com</a>, so, imagine you want to visit Holberton’s web page, so you type this URL in your browser, then a series of processes start one after the other.</p><p><strong>1. Your browser asks itself, do I know where to make the query, to get to this URL?</strong></p><p>If we want to go somewhere on the web, we must follow a direction that takes us to that place, in this case, we need to know the address of the server where the page we are searching for is hosted, this address is represented as a series .of numbers know as the IP, to help us find this IP address the use of DNS is needed, so a DNS request would take place, following are the DNS record types:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/0*d0_lhvSBb8Xtfb5Z.png" /></figure><p>The ones that are useful to us, for the example we’re working on, are:</p><ul><li><strong>A, AAAA:</strong> The ‘A’ in the name stands for address, this type of DNS record helps map domains to IP’s, the difference between the two is the IP version each one is intended for, A for version 4 while AAAA is intended for version 6.</li><li><strong>CNAME: </strong>The name stands for Canonical Name, and is used to map alias names to actual domains</li></ul><p>In this case, we are looking for ‘www.holbertonschool.com’, so the ‘A’ record could look something like:</p><pre><a href="http://www.holbertonschool.com/">www.holbertonschool.com</a> &lt;=&gt; 75.324.12.65</pre><p>To get this information, a series of queries had to happen:</p><ul><li>The browser checked its cache memory, if a similar entry was not found then it asked the operating system</li><li>The operating system checked its memory, if not found then it asked the resolver</li><li>The resolver (normally the Internet Service Provider), requests local DNS, if not found, then it asks the root server, then, to the top-level domain servers to finally get to the authoritative name servers, once the resolver gets the answer, it handles it to the web browser, so he can request the right IP.</li></ul><p><strong>2. The browser sends a request to the corresponding server IP</strong></p><p>Once the browser knows the IP, it sends a GET request, due we are requesting HTTPS, the port that will be used will be 443, for this request to be successful, the server must have an <a href="https://www.cloudflare.com/learning/ssl/what-is-an-ssl-certificate/">SSL certificate</a> to make encryption possible and start communicating securely.</p><p>Here are some common <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods">request methods</a> we can use on the web:</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET"><strong>GET</strong></a>: Requests a representation of the specified resource.</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST"><strong>POST</strong></a><strong>:</strong> Used to submit an entity to the specified resource, often causing a change in state or side effects on the server.</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT"><strong>PUT</strong></a><strong>:</strong> Replaces all current representations of the target resource with the request payload.</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH"><strong>PATCH</strong></a><strong>:</strong> Used to apply partial modifications to a resource.</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE"><strong>DELETE</strong></a><strong>:</strong> Deletes the specified resource.</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS"><strong>OPTIONS</strong></a><strong>:</strong> Used to describe the communication options for the target resource.</li></ul><p>We are searching for ‘https:www.holbertonschool.com’, so a request that looks like the following gets sent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*7vhJ9SRbJndUc94Q_sndvw.png" /></figure><p><strong>3. A TCP connection gets established</strong></p><p>To make the client and the server understand each other, a connection is needed, and this is where TCP comes to help, the basic connection establishment is made in 3 steps: SYN, SYN-ACK, ACK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*21WUZJV3O3nFl0B0" /></figure><p>Once the connection is established, another protocol takes place, the SSL/TLS, remember?, we are asking for HTTPS, then, the communication needs to be encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/0*MPeCedld3GLk0829.jpg" /><figcaption><a href="https://www.ibm.com/docs/en/cics-tg-zos/9.3.0?topic=ssl-how-connection-is-established">How an SSL connection is established</a></figcaption></figure><p>The complete process can be understood as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XY_YKJ509EYXpAxV.png" /></figure><p><strong>4. The server receives a new request, handles it, and gives back a response</strong></p><p>All set to start communicating!!, now the server can receive the request made by the browser, so, if you remember, the browser did a GET request to some IP address, for this example, let’s assume that the IP we got back, is some load balancer’s IP, then, what’ll happen could look something like:</p><ol><li>The request hits the load balancer</li><li>The firewall will examine the incoming request, if everything is ok, then it will allow it, else, the request will be denied.</li><li>The load balancer, using a balancing algorithm passes that request to a server that contains a webserver to handle the request</li><li>The web server attends the request and, if it needs some dynamic content, it will ask the app server for it, then the app server will make a query to the database to get the asked data.</li><li>Finally, a response will be sent back.</li></ol><p>The response the server sends could have one of the following <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status">status codes</a>:</p><ul><li>[100–199]: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#information_responses">Informational responses</a></li><li>[200–299]: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#successful_responses">Successful responses</a></li><li>[300–399]: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages">Redirects</a></li><li>[400–499]: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses">Client errors</a></li><li>[500–599]: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses">Server errors</a></li></ul><p>A 200 status code is expected if the request was successful, indicating that the specified resource was fetched and transmitted successfully in the response body.</p><p><strong>5. The browser takes the response and renders the content</strong></p><p>Finally, the browser gets the response and interprets the content, in this case, the corresponding HTML, subsequent calls are made to get the CSS styles, images, and another content present on the page, the result of it will be the HTML page rendered in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yLefWYU9POnQa2wjDaCvQ.png" /></figure><p>Wow, what a trip!!, as we saw, there is a lot of stuff going on when we request something on the internet, the full process can be simplified in the following diagram, considering a simple architecture: firewalls, load balancer, servers, web servers, app servers, and databases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*lWyABIooXKB300cL3CYj0Q.png" /></figure><p>Well, that’s it, now you know more about the web and how it works, hope this blog post helped you in some way, see you!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7a09b32f8ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding IoT, things that communicate with each other?]]></title>
            <link>https://rleons.medium.com/understanding-iot-things-that-communicate-with-each-other-488086739576?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/488086739576</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 01:59:19 GMT</pubDate>
            <atom:updated>2021-08-23T01:59:19.366Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7g_a9V8ytWAS-IxU.jpg" /></figure><p>So, I bet you’ve heard the term IoT before, maybe at work, in a family gathering, with friends in some social event, but, have you ever wonder what really is IoT, how it works and what is its importance in today’s world?. Well if you want to know all and more of this stuff, join me in my adventure of understanding “The Internet of Things”.</p><p>We as humans have this need inside, to be more connected, we’re a social specie after all, add up to this fact, there is also the need of doing more stuff in less time so we can enjoy with the people we love the most. To meet those needs we were able to create some technology that allowed us to break the space and time barriers.</p><p>As we know, in today’s world, if we want to talk to someone that is on the other side of the world, we can do it by call, by sending a message on any social media, by making a video call, by sending an email, etc. but this was not possible some time ago, it only became reality thanks to the human capacity of creating technology to meet those needs known now as the internet.</p><h4>What is the internet?</h4><p>The internet, as we know, is a enormous network that help us stay connected, this amazing technology has its beginnings in the 60’s, when computers were so big that could occupy an entire room, the uses and main focus of this technology was, to be able to share information.</p><p>What <a href="https://en.wikipedia.org/">wikipedia</a> says about the <a href="https://en.wikipedia.org/wiki/Internet">internet</a>:</p><blockquote>The <strong>Internet</strong> (<a href="https://en.wikipedia.org/wiki/Capitalization_of_Internet">or <strong>internet</strong></a>) is the global system of interconnected <a href="https://en.wikipedia.org/wiki/Computer_network">computer networks</a> that uses the <a href="https://en.wikipedia.org/wiki/Internet_protocol_suite">Internet protocol suite</a> (TCP/IP) to communicate between networks and devices. It is a <a href="https://en.wikipedia.org/wiki/Internetwork"><em>network of networks</em></a> that consists of private, public, academic, business, and government networks of local to global scope, linked by a broad array of electronic, wireless, and <a href="https://en.wikipedia.org/wiki/Optical_networking">optical networking</a> technologies. The Internet carries a vast range of information resources and services, such as the inter-linked <a href="https://en.wikipedia.org/wiki/Hypertext">hypertext</a> documents and <a href="https://en.wikipedia.org/wiki/Web_application">applications</a> of the <a href="https://en.wikipedia.org/wiki/World_Wide_Web">World Wide Web</a> (WWW), <a href="https://en.wikipedia.org/wiki/Email">electronic mail</a>, <a href="https://en.wikipedia.org/wiki/Internet_telephony">telephony</a>, and <a href="https://en.wikipedia.org/wiki/File_sharing">file sharing</a>.</blockquote><p>The internet, and the connection it offers is possible thanks to thousands of thousands of submarine cables that go around the world to power and support it, here’s what <a href="https://edition.cnn.com/">CNN</a> says about this <a href="https://edition.cnn.com/2019/07/25/asia/internet-undersea-cables-intl-hnk/index.html">cables</a>:</p><blockquote><a href="https://www2.telegeography.com/submarine-cable-faqs-frequently-asked-questions">Today</a>, there are around 380 underwater cables in operation around the world, spanning a length of over 1.2 million kilometers (745,645 miles).</blockquote><blockquote>Underwater cables are the invisible force driving the modern internet, with many in recent years being <a href="https://blog.telegeography.com/rising-tide-content-providers-investment-in-submarine-cables-continues">funded</a> by internet giants such as Facebook, Google, Microsoft and Amazon. They carry <a href="https://www.nec.com/en/global/about/mitatv/02/">almost all</a> our communications and yet — in a world of wireless networking and smartphones — we are barely aware that they exist.</blockquote><p>And here, an image taken from <a href="https://www.submarinecablemap.com/">submarinecablemap</a>, to show the submarine cable map through the world:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*A-yK-J9URodeVneFYLLOfA.png" /><figcaption>Submarine cable map</figcaption></figure><p>Awesome right?, as we were able to develop new technology such as mobile phones, smartphones, tables, and all sorts of devices, “The Internet of Things” began growing more and more. Without us even noticing, now our devices were connected to the internet, our cars, our thermostats, even our watches were connected to the internet so as more devices got connected the more the IoT became apparent.</p><h4>What is IoT?</h4><p><a href="https://en.wikipedia.org/wiki/Kevin_Ashton">Kevin Aston</a>, coined the “The Internet of Things”, as a way to describe the network connecting physical world devices to the internet, On the interview: <em>Kevin Ashton Describes “the Internet of Things”,</em> made by the <a href="https://www.smithsonianmag.com/">smithsonian magazine</a>, Ashton answered the following when asked to describe “The Internet of Things”:</p><blockquote>In the twentieth century, computers were brains without senses — they only knew what we told them. That was a huge limitation: there is many billion times more information in the world than people could possibly type in through a keyboard or scan with a barcode. In the twenty-first century, because of the Internet of Things, computers can sense things for themselves. It’s only been a few years, but we already take networked sensors for granted. One example is GPS-based location sensing. Civilian GPS was first authorized by congress in 2000, and the GPS systems in cellphones were not tested until 2004. Yet it’s already hard to imagine a world without GPS: it helps us find our way around. In the imminent future, it will enable things like self-driving cars, which will give us back the 20 days a year we spend doing nothing but driving, will save 40,000 lives a year in the U.S. alone, will reduce traffic and pollution, and will allow cities to grow without devoting as much land to roads.</blockquote><p>In simple words, The internet of Things or short IoT is a phrase that helps us describe the millions of millions of devices connected to the internet and that constantly are sending and receiving information thus allowing them to share, analyze, process, and even store this information thanks to the internet.</p><p>This image can help us understand this better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*De5bQi1YqKTCZUPp.png" /></figure><p><a href="https://www.zdnet.com/">zdNet</a> defines the <a href="https://www.zdnet.com/article/what-is-the-internet-of-things-everything-you-need-to-know-about-the-iot-right-now/">IoT</a> as:</p><blockquote>The Internet of Things, or IoT, refers to the billions of physical devices around the world that are now connected to the internet, all collecting and sharing data. Thanks to the arrival of super-cheap computer chips and the ubiquity of wireless networks, it’s possible to turn anything, from something as small as <a href="https://www.zdnet.com/article/how-sensors-enabled-eli-lilly-to-improve-the-patient-experience/">a pill </a>to something as big as <a href="https://www.zdnet.com/article/ten-examples-of-iot-and-big-data-working-well-together/">an aeroplane</a>, into a part of the IoT. Connecting up all these different objects and adding sensors to them adds a level of digital intelligence to devices that would be otherwise dumb, enabling them to communicate real-time data without involving a human being. The Internet of Things is making the fabric of the world around us more smarter and more responsive, merging the digital and physical universes.</blockquote><p><a href="https://www.ibm.com/">IBM</a> explains <a href="https://www.ibm.com/blogs/internet-of-things/what-is-the-iot/">IoT</a> as:</p><blockquote>In a nutshell, the Internet of Things is the concept of connecting any device (so long as it has an on/off switch) to the Internet and to other connected devices. The IoT is a giant network of connected things and people — all of which collect and share data about the way they are used and about the environment around them.</blockquote><blockquote>That includes an extraordinary number of objects of all shapes and sizes — from <a href="https://www.youtube.com/watch?v=1u4Mwn6BQyo">smart microwaves</a>, which automatically cook your food for the right length of time, to <a href="https://www.youtube.com/watch?v=K564rXrlZbc">self-driving cars</a>, whose complex sensors detect objects in their path, to wearable <a href="https://www.ibm.com/blogs/internet-of-things/watson-iot-sports/">fitness devices</a> that measure your heart rate and the number of steps you’ve taken that day, then use that information to suggest exercise plans tailored to you. There are even <a href="http://www.wilson.com/en-us/explore/football/wx.html">connected footballs</a> that can track how far and fast they are thrown and record those statistics via an app for future training purposes.</blockquote><p>So the IoT is present in our daily lives and growing more each time, imagine for example the following situation: Mark is a man that lives alone, he wakes up every morning and just by pressing a button on his phone, his coffee machine activates and prepares the coffee for breakfast, this machine keeps track of how much coffee Mark drinks, alerts him when its getting out of stock, so he could ask for more coffee, Marks also uses a heart rate monitoring bracelet that maintains him informed about his heart health; well, one day Mark goes to bed and at midnight its heart starts to beat faster and faster, the bracelet analyzes the heart beat rate and concludes that Mark is about to have a heart attack, so sends and alert to the hospital informing Mark’s health status and location, so an ambulance is sent to Mark’s place, then they take him to the hospital as fast as they can, in the way to hospital, thanks to the information send by the bracelet, the doctors are already analyzing Mark’s condition so when he gets there the adequate treatment gets applied. The ambulance arrives to the hospital, the doctors treat Mark and when he wakes up he realizes that everything is okay, all thanks to the IoT that predicted and informed at the right moment to take action.</p><p>Here is other example of IoT taken from <a href="https://www.postscapes.com/internet-of-things-examples/">postcapes</a>:</p><ul><li><strong><em>BeClose Elderly Monitoring:</em></strong><em> One of the goals of the system is to enable those living independently to continue doing so while still providing family and caregivers a peace of mind about their wellbeing. “Has there been no activity in the house for several hours? Has Mom been out of bed for a prolonged period at night?”. The system uses a range of sensors placed throughout the home to wirelessly and discreetly track a persons routines. Open/close sensors are attached to doors and cabinets to gauge activity levels and medication usage. Presence sensors are placed beneath mattresses, chairs and even under toilet mats to monitor sleeping, sitting and bathroom use, and finally wall mounted motion sensors are used to track general activity levels throughout a day. The sensors are all connected through a base station and transmitted via cellular networks to the cloud to be analyzed and tracked. The system can be setup to notify family members (or professional caregivers) in real time if a possible issue is detected, and an online dashboard gives an analysis of sleep and activity patterns over time. The BeClose system also offers traditional emergency response features like the “BeClose button” that can be placed in the home where accidents might occur and used to call emergency services (or if preferred just contact a family member for help).</em></li></ul><h4>But, how does it work?</h4><p>IoT devices have sensors that they use to collect data from the environment so they use this information to feed machine learning in order to understand the situation, learn and give feedback to its users, this information can be shared with other connected devices so they can also learn about people’s habit routines and preferences, and decide what to do based on this information. for example my home could have sensors that detect motion, and it can send this information to my thermostat to turn on and heat when I’m home and to turn off when I’m out, thus reducing the amount of energy that would be spend if I let the thermostat on all the time.</p><h4>Some concerns about security</h4><p>Due to the fact that things are continuously capturing information about us, some security concerns arises, specifically in the field of privacy, some may say, ok, the IoT is helping me, but, the I’m paying with information so personal, that if it lands in the wrong hands it would put me in jeopardy, taking the example of the house and the thermostat, if the data about the time I’m in or out my home gets in the hands of a thief, he’ll know when I’m not at home so he can enter and take everything he want. Cases like this one are also possible, that’s why, the security in IoT must be warrantied.</p><p><a href="https://www.internetsociety.org/">The internet society</a>, gives a thought on <a href="https://www.internetsociety.org/iot/?gclid=CjwKCAjw3_KIBhA2EiwAaAAlig7qRh2pmCvce0Y81KyVMm3olanmVs4I0P8Y926rRiv_f9JFarZr4xoCUX0QAvD_BwE">this</a> aspect:</p><blockquote>The Internet of Things has arrived and it’s going to introduce incredible opportunity over the next five years. And while smart things are exactly that, the IoT industry has a long way to go in terms of overall security. Many of today’s IoT devices are rushed to market with little consideration for basic security and privacy protections: “Insecurity by design.”</blockquote><blockquote>This puts you and everyone else at risk: from unwittingly being spied on or having your data compromised to being unable to lock your own home. You could even become part of a botnet that attacks the Internet. Your insecure webcam — along with millions of others — could be used to attack the power grid of an entire country.</blockquote><p>Following is a list of most common <a href="https://www.thalesgroup.com/en/markets/digital-identity-and-security/iot/magazine/internet-threats">security issues</a>, made by <a href="https://www.thalesgroup.com/">Thales group</a>:</p><ul><li><strong>Weak password protection: </strong>Hard-coded and embedded credentials are a danger for IT systems and as much hazardous for IoT devices. Guessable or hard-coded credentials are a windfall for hackers to attack the device directly. With default passwords, the attacker may already know the password to the machine!</li><li><strong>Lack of regular patches and updates and weak update mechanism: </strong>IoT products are developed with ease of use and connectivity in mind. They may be secure at the time of purchase but become vulnerable when hackers find new security issues or bugs. If they are not fixed with regular updates, the IoT devices become exposed over time.</li><li><strong>Insecure interfaces: </strong>All IoT devices process and communicate data. They need apps, services, and protocols for communication and many IoT vulnerabilities originate from insecure interfaces. They are related to web, application API, cloud, and mobile interfaces and can compromise the device and its data. Common issues include a lack of/or insufficient device authentication and authorization and weak encryption or none.</li><li><strong>Insufficient data protection (communication and storage): </strong>The most frequent concerns in the data security of IoT applications are due to insecure communications and data storage. One of the significant challenges for IoT privacy and security is that compromised devices can be used to access confidential data.</li><li><strong>Poor IoT device management: </strong>A study published in <a href="https://www.helpnetsecurity.com/2020/07/24/analysis-of-5-million-unmanaged-iot-and-iomt-devices/">July 2020</a> analyzed over 5 million IoT, IoMT (Internet of Medical Things), and unmanaged connected devices in healthcare, retail, and manufacturing as well as life sciences. It reveals an amazing number of vulnerabilities and risks across a stunningly diverse set of connected objects. They include shadow IoT (devices in active use without IT’s knowledge), compliance violations, and US Food and Drug Administration recalled (defective and risky) medical devices.</li><li><strong>The IoT skill gap: </strong>Companies are facing a vital IoT skills gap that is preventing them from exploiting new opportunities to the full, according to <a href="https://www.forbes.com/sites/danielnewman/2019/07/30/return-on-iot-dealing-with-the-iot-skills-gap">Forbes</a> (30 July 2019).</li></ul><p>To address this issues, <a href="https://www.internetsociety.org/">the internet society</a> gives a list of recommendations:</p><ul><li>Learn how to “shop smart” for connected devices.</li><li>Update your devices and its applications.</li><li>Turn on strong encryption.</li><li>Stop reusing passwords.</li><li>Review the privacy settings on your devices and their applications.</li><li>Use a strong password.</li><li>Turn off the device or disconnect it from the Internet when not in use.</li><li>Take steps to make your home network more secure.</li></ul><p>Up to this point we may have a clearer view on what IoT is, and what its potential could be, I hope this blog post help you in some way, see you!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=488086739576" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion, a little example]]></title>
            <link>https://rleons.medium.com/recursion-a-little-example-3c9656fbe3c8?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c9656fbe3c8</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Mon, 05 Jul 2021 04:07:36 GMT</pubDate>
            <atom:updated>2021-07-09T17:47:41.147Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xynrd1aNwW8-flQ_.jpeg" /></figure><p>Recursion is one of those things that at first seems a bit difficult, but, once you understand it, it becomes a great ability to use for problem solving, in this post I’ll explain in simple terms (or at least that’s what I’ll try) what recursion is, and how it works on the stack.</p><p><a href="https://www.sparknotes.com/">SparkNotes</a>, on the topic <a href="https://www.sparknotes.com/cs/recursion/whatisrecursion/section1/">What is Recursion?</a> states that:</p><blockquote>Recursion is a computer programming technique involving the use of a procedure, subroutine, function, or algorithm that calls itself in a step having a termination condition so that successive repetitions are processed up to the critical step where the condition is met at which time the rest of each repetition is processed from the last one called to the first.</blockquote><p>Now let’s see the example code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZ7XSjUv1mHZ969WGdOVEA.png" /></figure><p>The above code uses a recursive approach to find the power of a number ‘x’ raised to the ‘y’ power, the way it works is by dividing the problem into smaller problems each time the function calls itself, to understand why and how it works we need to know about ‘the stack’ or the ‘call stack’, as <a href="https://en.wikipedia.org/">wikipedia</a> says on this topic:</p><blockquote>In <a href="https://en.wikipedia.org/wiki/Computer_science">computer science</a>, a <strong>call stack</strong> is a <a href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)">stack</a> <a href="https://en.wikipedia.org/wiki/Data_structure">data structure</a> that stores information about the active <a href="https://en.wikipedia.org/wiki/Subroutine">subroutines</a> of a <a href="https://en.wikipedia.org/wiki/Computer_program">computer program</a>. This kind of stack is also known as an <strong>execution stack</strong>, <strong>program stack</strong>, <strong>control stack</strong>, <strong>run-time stack</strong>, or <strong>machine stack</strong>, and is often shortened to just “<strong>the stack</strong>”.</blockquote><p>Imagine we want to get the result of raising 2 to the power of 5, we can calculate it easily by multiplying 2 five times but in a recursive way we can think of it as multiplying 2 by 2 to the power of 4, and to calculate this, we can multiply 2 by 2 to the power of 3 and so on, like this:</p><pre>2⁵ = 2*2⁴<br>2⁴ = 2*2³<br>2³ = 2*2²<br>2² = 2*2¹<br>2¹ = 2*1</pre><p>This behavior could be simplified on the following graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*68SKIRXOfS5PpFZMxTtueQ.png" /></figure><p>In the stack this could be represented like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*Nl7GntwJ-XjyyTKUYlyLSQ.png" /></figure><p>So, that’s it, I hope this helped you, and see you, one the next one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c9656fbe3c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mutable and Immutable objects in Python]]></title>
            <link>https://rleons.medium.com/mutable-and-immutable-objects-in-python-d4ee9c2e5728?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4ee9c2e5728</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Mon, 31 May 2021 05:24:48 GMT</pubDate>
            <atom:updated>2021-05-31T05:24:48.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*C7kBLQ5fmUkwdMxszgf3Wg.jpeg" /></figure><p>Python, as you may know can get a little bit crazy sometimes for the easiness it gives to programmers to write code, in my path of learning this language I’ve encountered some cases when the expected output was different from the output that the code produces. To understand this better, let’s see what could happen when dealing with mutable and immutable objects when coding in python.</p><p>Mutable objects as the name suggests are object which values can change during the programs execution while immutable object values’ cannot, the understanding of these two concepts could help avoid unexpected behaviour in our program.</p><p>As the <a href="https://docs.python.org/3/reference/datamodel.html">python datamodel reference</a> says:</p><blockquote>The <em>value</em> of some objects can change. Objects whose value can change are said to be <em>mutable</em>; objects whose value is unchangeable once they are created are called <em>immutable</em>. (The value of an immutable container object that contains a reference to a mutable object can change when the latter’s value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value, it is more subtle.) An object’s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.</blockquote><h4>Id and Type</h4><p>In python ‘id’ is a function that will give back a unique identifier as a number for each object, depeding on the python implmentation this id can vary, for example in CPtyhon this function will give back the memory address at wich the object is stored. To quote the <a href="https://docs.python.org/3/reference/datamodel.html">datamodel reference</a> again:</p><blockquote>Every object has an identity, a type and a value. An object’s <em>identity</em> never changes once it has been created; you may think of it as the object’s address in memory. The ‘<a href="https://docs.python.org/3/reference/expressions.html#is">is</a>’ operator compares the identity of two objects; the <a href="https://docs.python.org/3/library/functions.html#id">id()</a> function returns an integer representing its identity.</blockquote><blockquote><strong>CPython implementation detail:</strong> For CPython, id(x) is the memory address where x is stored.</blockquote><p>Let’s take a look at some examples using ‘id’ function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/1*VpegzH9L_NP6c9rCM5iEOw.png" /></figure><p>As we can see each object has its own id, other function worth mentioning is ‘type’ which will return the object’s type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*LOCpxfm-X5sdkL5F2tNVhQ.png" /></figure><h4>Mutable objects</h4><p>We can think of mutable as something that can be changed, in OOP context, mutable objects’ value can be manipulated, thus changing the objects’ data but mantaining its identity, let’s take for example a list object which is mutable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*SzcQLc9W6WOKrwIf-WTXvA.png" /></figure><p>When we define the list, an id its given to it, an will be mantained as long as the list object lives in our program, we can see that the list value at the start contains the numbers from 1 to 3, then we append a new element ‘4’ thus changing or mutating the list, and even after this change, th list keeps it’s identity, thus we can say that the variable ‘ls’ is still refering to same object, in this case no new object was created.</p><h4>Immutable objects</h4><p>Immutable objects in the other hand are objects that cannot be changed and even if we try or thing about changing them what will happen is that a new object will be created instead, let’s see what I mean through an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*nvre4kxB7bgT7HNvIxy61w.png" /></figure><p>In this example we use a string object, which is immutable, to demonstrate what we said earlier, even though we can thing that we’re changing the object’s value, we can see that in this case tha’s not what happend, what really happened is that when ‘s’ was created an ‘id’ was assigned to it, next when we tried to modify it’s value, a new object got created and the ‘id’ of that object got assigned to ‘s’ variable, thus, the original object was not mutated, instead was replaced by another object wich contained the contatenation of the previous value with the new one, and that is why at the end the ‘id’ we got was different from the ‘id’ at the begining.</p><h4>How python treat mutable and Immutable objects</h4><p>As you may know, in python everything is an object, even a simple number as ‘1’ or ‘2’ is considered to be an object. Mutable and immutable objects can be a little tricky when dealing with them, let’s see what I mean, first let’s make a list of what objects are consider mutable and which ones are considered immutable:</p><ul><li>Mutable Objects: list, dict, set</li><li>Immutable objects: int, float, complex, string, tuple, frozen set, byte</li></ul><p>This first example will consist of a list wich will be referenced by two variables which wil be treated as aliased due they will refer to the same object, and because a list is mutable, it’s value can be modified from either of the aliases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*nYMYotjH-vL6HIMetVib5w.png" /></figure><p>As we can see the list was mutated because the variable aliased to it holded a reference to the exact same object and thus it was able to change it’s value, maybe the following picture will help clearing out what happened here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*jqt0dbNPu7Rf20VlXev8ag.png" /></figure><p>As the image shows, both variables reference the same object, any change to this object can be seen from any variable that holds a reference to it.</p><p>In python we can make use of the ‘is’ operator to check if two variables refer to same object or not:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*p0O6YvlGJiyIjGf1M76Dbg.png" /></figure><p>If we want to see if a value stored in one object is the same as other object we can use the &#39;==’ operator, let’s make a new example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/155/1*bzIek_q4LAwLd6zXTYNlfg.png" /></figure><p>The operation gives back ‘True’ because the contents of both lists are the same, now if we use the ‘is’ operator we’ll expect to give back False because each list is refering to a diferent object:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*my_V1qxHsktR_fJ9xZQIcA.png" /></figure><p>And get ‘False’ as expected.</p><p>For immutable objects this last behaviour is quite different, let’s take strings as example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*XInSbdQc3ieuGOpvkpLVgA.png" /></figure><p>In this case the ‘is’ operator gives back True due to the way python manages immutable types for memory efficiency thus not creating new objects and instead giving back the addresses at wich they are stored in memory.</p><p>We can see a similar behavior when using int types:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*xbJU-6eklTtsze4GDo_CRQ.png" /></figure><p>For int type, this behavior can be explained by something known asNSMALLPOSINTSandNSMALLNEGINTSwhich consists of an array of 262 integers defined in the python implementation to improve memory efficiency due to this integers are the most commonly used, and thus, creating a variable with value in a range from -5 to 256 inclusive will give back a reference to the number inside this array.</p><h4>How arguments are passed to functions</h4><p>In python as we know everything is an object, thus when we pass a variable as function argument, theoretically we’re passing a reference to that variable, knowing this, we can think that we could change any object’s value inside a function, but is not that simple, python handles this references differently depending if the object passed to a function is mutable or not, let’s see an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*ym3PQYswvLD7t8pPJxg5mg.png" /><figcaption>example code, passing a mutable object as function argument</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*wIoAHdB2QSHodim1nC-JRQ.png" /><figcaption>output</figcaption></figure><p>In this case the list object was mutated, it’s value was changed from inside the function due to a ‘list’ is a mutable object.</p><p>Now an example using an immutable object:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*m3Xb9iOvgfpWwDx7-Qka9g.png" /><figcaption>example code, passing an immutable object as function argument</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*3Lysbsa7pjOwUU9zB9rP8A.png" /><figcaption>output</figcaption></figure><p>As we can see the string didn’t change after the function was called, this is because strings, as we mentioned earier, are immutable objects and thus it ‘s value cannot be modified, what happend inside the funcion was that a new object was created and assigned to ‘s_ref’ variable, but this object will only exist until the function ends it’s execution thus not afecting the original object referenced by the ‘s’ variable.</p><p>That’s it for this post!!!, as always, hope this helped you in some way, take care and see you on the next one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4ee9c2e5728" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Oriented Programming in Python]]></title>
            <link>https://medium.com/analytics-vidhya/object-oriented-programming-in-python-2f2f6c68dca2?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f2f6c68dca2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Sun, 30 May 2021 21:00:13 GMT</pubDate>
            <atom:updated>2021-07-12T06:26:28.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nIoJaIeoQonky05Z.jpg" /></figure><p>I’ve recently been learning python and on this process I have encountered a something that caught my attention, Object Oriented Programming, this way of writing and structuring your code offers a new way of approaching a problem and that’s why today I’ll explain a few concepts related to it.</p><p>Let’s start imagining an object, could be whatever object you want, for example, I’m gonna choose a bike, so in this example, my bike would have some properties, for example, the brand, the color, the length, the height, etc. As my bike, any other bike could have its own brand, color, length, etc. So this properties that both bikes share could be defined in a class for this example would be the “Bike” class, and each bike would be an instance of this class, what we call objects, as we can see each object can have different values for the properties it has, so this is a pretty simplified example of what a class and object means, just to warm up!!!, hahaha.</p><p>Now let’s see how this can be translated to code using python, first let’s define our class Bike and then let’s create two object with different properties:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*mXzQYYj5A8dUfoFsucbQ_w.png" /><figcaption>Bike class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*8ZGbimNgQ0xgm_4xyj5S-Q.png" /><figcaption>Instance of Bike class (objects)</figcaption></figure><p>As we can see each instance has its own values for the same properties, if we execute this code we would have the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/135/1*S5IMAshw_O3MJ06De1ZeGw.png" /><figcaption>output</figcaption></figure><p>Awesome, right?, now let’s experiment a little more with this new concepts.</p><h4>Class attribute:</h4><p>A class attribute is a ‘property’ that all instances share, let’s say for example that all bikes created by the ‘Bike’ class will have always 2 wheels, if we translate this to code we would add ‘wheels’ attribute to our class as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*-8tt-6b19hLBL4QQ6b0p9w.png" /></figure><p>and to access this attribute we can either use the class itself, or any of it’s instances:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*PmCqeS86WcB92OvwdridEg.png" /><figcaption>Accesing ‘wheels’ class attribute</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*wfaPxWY2PanYzmMPy6cO-w.png" /><figcaption>Output</figcaption></figure><p>To demonstrate that the attribute is shared by all instances, let’s change its value and see if the change gets reflected in all instaces:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*VM7yHUgRs8_yusABcKlRoQ.png" /><figcaption>example code: changing class attribute value</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*6oBiw2GHTWgkvwaJ3HR93g.png" /><figcaption>output</figcaption></figure><p>And tada!, the value changed for all instances as expected.</p><h4>Instance attribute</h4><p>This kind of attribute is not shared by all instances as class attributes, but instead, it only belongs to one object, in our example we’ve already defined instance attributes: brand, color, length and height, this attributes defines the properties that each bike will have, if we change one of this attributes’ value, we’ll see that the change will only afect the object we selected the attribute from, lets see an example, imagine in our example that Mark wnat to change his bike’s color from blue to red, in code we can translte this as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*DWsLIrTaGVI7roBaQF1WrA.png" /><figcaption>changing object attribute values</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*jEW_O5xLfalvcgJctTZgWg.png" /><figcaption>output of changing attribute value</figcaption></figure><p>We can see that the value for property ‘color’ changed only for mark’s bike, if we print jhon bike’s color we’l see that it mantains its own color:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*6Psna5l-_PIze9wFDv1mQw.png" /><figcaption>Printing both bike’s color before and after color change</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*xdYjG6KXVm7P2cr9RL-M_g.png" /><figcaption>Bike’s colors after color change</figcaption></figure><p>As we can see, the color for jhon’s bike remains being yellow and for mark’s bike the color changed from blue to red.</p><p>Other thing worth mentioning is that attributes can be any of the following:</p><ul><li>Public (attr): Can be accessed from anywhere</li><li>Protected (_attr): Can be accessed from derived classes</li><li>Private (__attr): Can be accessed only using ‘self’</li></ul><h4>Ways to create class and instance attributes:</h4><p>Python offers us many ways to create both class and instace attributes, here are some examples:</p><p>Class Attributes:</p><ul><li>Defining the atribute on the class</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/1*MqvvoOc_EGnHynfiUJ5QUw.png" /></figure><ul><li>Using the class:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*UlSfpAndcrQ5PLfQGtW_Ew.png" /><figcaption>creating a new class attribute at runtime</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*sAqKsOCAimkv9ooF-tJqZw.png" /><figcaption>output</figcaption></figure><ul><li>Using class method:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*0M1WIBdAK_8qptz4Qnyl0A.png" /><figcaption>add class method for Bike class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*D3N0IocrUMqMb4EoDDczCw.png" /><figcaption>example code to test that attribute creation worked well</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*-OrI6O67FEr7b4wAj6VSpw.png" /><figcaption>output</figcaption></figure><ul><li>Using ‘__class__’:</li></ul><p>There is another way to create class attributes and is by using an instance, accesing to its class and then declaring the attribute, this is not a good way to create such attributes but it helps us explore the options python gives to us to achieve this, for this example we’ll define a new method in our class, and when this method gets called it will create a class attribute by accesing the ‘__class__’ attribute using ‘self’ from any instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*2PRXfm6b3EQCSt39aN3pqg.png" /><figcaption>add new method to thst defines a class attribute</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*olOJX9vaKsCVF07t36rKKA.png" /><figcaption>example code to explore class attribute creation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*G_xL9X_25CwO5h3DwELZJQ.png" /><figcaption>output</figcaption></figure><p>Instance attributes:</p><ul><li>Using ‘self’</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*X1gI0OkNwsbnWDNedSXgHg.png" /><figcaption>instance attributes declared using ‘self’</figcaption></figure><ul><li>Using ‘__dict__’</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*0EvrepciUv_E8uLvIa4Pjw.png" /><figcaption>instance attribute created using ‘__dict__’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*yuRM6zJEh2Kyoj4Y-E5eVw.png" /><figcaption>output</figcaption></figure><ul><li>Using the instance</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*ksn_vtUfsgvc216L1QvThw.png" /><figcaption>instace attribute created using the insance itself</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*iw2JLLdNWoMLhqXpBcKCxQ.png" /><figcaption>output</figcaption></figure><h4>Differences between class and instance attributes:</h4><ul><li>Class attributes are shared for all instances, if we change a class attribute value, this change will be reflected on every instance of the class</li><li>Instance attributes belongs to every individual object, if we change a value of any attribute of any instace, this change will only get reflected for the same object, the other instances will maintain it’s values.</li></ul><h4>Advantages and drawbacks:</h4><p>This depends on what you’re coding, in some cases class attributes will fit better than instance attributes an also the other way.</p><ul><li>Class attributes comes helpfull if you want to store relevant data for all objects of a certain class.</li><li>Instance attributes, on the other hand allows you to personalize each indivual object with custom values.</li><li>Class attributes can be accessed even if all instances of a class where deleted.</li><li>Instace attributes can only be access during an object lifetime.</li><li>Python allows us to dynamically create both kind of attributes.</li><li>If you declare an instance attribute with the same name of a class attribute, things can get mixed up and if you try to access a class instance from the object you’ll get the attribute instance value instead.</li></ul><h4>How does python deal with these attributes:</h4><p>Python manages attributes by the use of dictionary ‘__dict__’, instance attributes and class attributes are astored in different dictionaries, to see this let’s print out the ‘__dict__’ from any insance and from a class to the the output each one gives:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*OAanj32CKMjP91G0LklH-A.png" /><figcaption>print __dict__</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*vKUDCY4gXJiYx_KjGz3jgg.png" /><figcaption>output of printing __dict__</figcaption></figure><p>As we can see both dictionaries stores different values, the first one stores only insances attributesand the other one stores attributes related to the class ‘Bike’.</p><p>As always I hope this post helped you in some way, take care and see on the next one!!!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f2f6c68dca2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/object-oriented-programming-in-python-2f2f6c68dca2">Object Oriented Programming in Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use SDL2 library in a Vagrant environment]]></title>
            <link>https://rleons.medium.com/how-to-use-sdl2-library-in-a-vagrant-environment-ccd8d8872e78?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccd8d8872e78</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Mon, 10 May 2021 03:16:06 GMT</pubDate>
            <atom:updated>2021-05-10T03:16:06.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tpWkOsnx0721ooD6.jpg" /></figure><p>So I was willing to use a library in C that will allow me to make some graphics, this library is called SDL2, and I installed it on a vitual env in vagrant, but when I tried to use it, it was giving me an error, I searched some info online and then I figure out that SDL2 needed a desktop enviroment in order to run, hahaha, pretty obvious right!!. Well so this blog is about that, installing a lightweight desktop environment to use it on a Vagrant environment in order to run SLD2 library, let’s get started.</p><p>Keep in mind that this tutorial was made using Vagrant 2.2.14 running on Windows 10.</p><p>Let’s begin:</p><ol><li>Create adirectory that will hold your Vagrant file and cd into it:</li></ol><pre>c:\user\vagrant\&gt; mkdir new_env<br>c:\user\vagrant\&gt; cd new_env<br>c:\user\vagrant\new_env&gt;</pre><p>2. Create a new vagrant env, in my case ubuntu/trusyt64:</p><pre>c:\user\vagrant\new_env&gt; vagrat init ubuntu/trusty64<br>A `Vagrantfile` has been placed in this directory. You are now<br>ready to `vagrant up` your first virtual environment! Please read<br>the comments in the Vagrantfile as well as documentation on<br>`vagrantup.com` for more information on using Vagrant.</pre><pre>c:\user\vagrant\new_env&gt;</pre><p>3. On the explorer, open your newly created Vagrantfile and uncomment these lines:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*Z9GuzVzHaYbaqLVUvf3dow.png" /></figure><p>4. Also add these lines in order to allow your VM acces to internet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*_PPilGNNGrr3kdqzTbe2vg.png" /></figure><p>5. Save the file and go back to the command prompt to initialize your VM, and ssh into it:</p><pre>c:\user\vagrant\new_env&gt; vagrant up<br>...<br>c:\user\vagrant\new_env&gt; vagrant ssh<br>...<br>$</pre><p>6. Now that you are inside your VM, first update and then install <a href="https://en.wikipedia.org/wiki/Xfce#:~:text=Website,of%20modularity%20and%20re%2Dusability.">xfce4</a>, by typing the following:</p><pre>$ sudo apt update<br>$ sudo apt install xfce4<br>...</pre><p>7. Start the graphical environment:</p><pre>$ sudo startxfce4&amp;</pre><p>Great!!, after doing this, you should be able to see the GUI appearing, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MG1DpRZdERuqVz8HbKcg_Q.png" /></figure><p>Pretty awesome!!, right?. Well now that we have installed a desktop environment, now let’s install SDL2 and see if it works as spected:</p><h4>Installing SDL2:</h4><ol><li>Open a terminal on the desktop env, right click on the screen and select ‘open terminal here’</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*k4004jN9rnQxrRIIMG3JpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*kHwfZt4Ncqy4mi-bncc3tw.png" /></figure><p>2. In the terminal let’s create a folder called SDT2 and a file ‘install_sdl2.sh’.</p><pre>$ mkdir SDT2<br>$ cd SDT2<br>SDL2$ touch install_sdl2.sh</pre><p>3. Open the file install_sdl2.sh and copy the following.</p><pre>#!/usr/bin/env bash<br><br>GREEN=&#39;\033[0;32m&#39;<br>BLUE=&#39;\033[0;36m&#39;<br>NC=&#39;\033[0m&#39;<br><br>if [ &quot;$(id -u)&quot; != &quot;0&quot; ]; then<br>	echo &quot;Sorry, you are not root.&quot;<br>	exit 1<br>fi<br><br>echo -e &quot;Checking PATH...&quot;<br>if [[ ! &quot;$PATH&quot; =~ (^|:)&quot;/usr/local/bin&quot;(:|$) ]]; then<br>	export PATH=&quot;/usr/local/bin:$PATH&quot;<br>fi<br><br>if [ &quot;$(uname)&quot; == &quot;Darwin&quot; ]; then<br>	# Mac OS X<br><br>	echo -e &quot;\n${BLUE}Installing SDL2 !${NC}&quot;<br><br>	rm -fr /tmp/SDL2_install<br>	mkdir -p /tmp/SDL2_install<br>	cd /tmp/SDL2_install<br>	echo -e &quot;${BLUE}Downloading SDL sources...${NC}&quot;<br>	if ! curl https://libsdl.org/release/SDL2-2.0.4.tar.gz &gt; SDL2-2.0.4.tar.gz; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Unziping sources ...${NC}&quot;<br>	if ! tar -zxf SDL2-2.0.4.tar.gz; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	cd SDL2-2.0.4<br>	echo -e &quot;${BLUE}Downloading script...${NC}&quot;<br>	if ! curl https://hg.libsdl.org/SDL/raw-file/afd286e26823/build-scripts/gcc-fat.sh &gt; gcc-fat.sh; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	if ! chmod 755 gcc-fat.sh; then exit 1; fi<br>	mkdir build<br>	cd build<br>	echo -e &quot;${BLUE}Configure...${NC}&quot;<br>	if ! CC=/tmp/SDL2_install/SDL2-2.0.4/gcc-fat.sh /tmp/SDL2_install/SDL2-2.0.4/configure; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Building...${NC}&quot;<br>	if ! make; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Installing...${NC}&quot;<br>	if ! make install; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	rm -fr /tmp/SDL2_install<br><br>	echo -e &quot;\n${BLUE}Installing freetype2 !${NC}\n\n&quot;<br><br>	#Install freetype2<br>	rm -fr /tmp/freetype2_install<br>	mkdir -p /tmp/freetype2_install<br>	cd /tmp/freetype2_install<br>	echo -e &quot;${BLUE}Downloading freetype2 sources...${NC}&quot;<br>	if ! curl https://s3.amazonaws.com/intranet-projects-files/holbertonschool-low_level_programming/graphics_programming/freetype-2.6.5.tar.gz &gt; freetype-2.6.5.tar.gz; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Unziping sources ...${NC}&quot;<br>	if ! tar -zxf freetype-2.6.5.tar.gz; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	cd freetype-2.6.5<br>	echo -e &quot;${BLUE}Configure...${NC}&quot;<br>	if ! ./configure; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Building...${NC}&quot;<br>	if ! make; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Installing...${NC}&quot;<br>	if ! make install; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	rm -fr /tmp/freetype2_install<br><br><br>	echo -e &quot;\n${BLUE}Installing SDL2_ttf !${NC}\n\n&quot;<br><br>	#Install SDL2_ttf<br>	rm -fr /tmp/SDL2_ttf_install<br>	mkdir -p /tmp/SDL2_ttf_install<br>	cd /tmp/SDL2_ttf_install<br>	echo -e &quot;${BLUE}Downloading SDL2_ttf sources...${NC}&quot;<br>	if ! curl https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz &gt; SDL2_ttf-2.0.14.tar.gz; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Unziping sources ...${NC}&quot;<br>	if ! tar -zxf SDL2_ttf-2.0.14.tar.gz; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	cd SDL2_ttf-2.0.14<br>	echo -e &quot;${BLUE}Configure...${NC}&quot;<br>	if ! ./configure; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Building...${NC}&quot;<br>	if ! make; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	echo -e &quot;${BLUE}Installing...${NC}&quot;<br>	if ! make install; then exit 1; fi<br>	echo -e &quot;${GREEN}Done!${NC}&quot;<br>	rm -fr /tmp/SDL2_ttf_install<br><br>	echo -e &quot;\n${GREEN}All set!${NC}&quot;<br><br>	echo &quot;\n\n&quot;<br>	echo &quot;Don&#39;t forget to compile with: \`sdl2-config --cflags\`&quot;<br>	echo &quot;Don&#39;t forget to link with: \`sdl2-config --libs\` -lSDL2_ttf&quot;<br><br>elif [ &quot;$(expr substr $(uname -s) 1 5)&quot; == &quot;Linux&quot; ]; then<br>	# GNU/Linux<br><br>	if ! apt-get install libsdl2-dev; then exit 1; fi<br>	if ! apt-get install libsdl2-ttf-dev; then exit 1; fi<br><br>	echo -e &quot;\n${GREEN}All set!${NC}&quot;<br><br>	echo &quot;\n\n&quot;<br>	echo &quot;Don&#39;t forget to compile with: \`sdl2-config --cflags\`&quot;<br>	echo &quot;Don&#39;t forget to link with: \`sdl2-config --libs\` -lSDL2_ttf&quot;<br><br>elif [ &quot;$(expr substr $(uname -s) 1 10)&quot; == &quot;MINGW32_NT&quot; ]; then<br>	# Windows NT<br><br>	echo &quot;Can&#39;t be installed on Windows...&quot;<br>	echo &quot;Please visit SDL2 website for more informations&quot;<br>	exit 1<br>else<br>	echo &quot;Can&#39;t be installed on this operating system...&quot;<br>	echo &quot;Please visit SDL2 website for more informations&quot;<br>	exit 1<br>fi</pre><p>4. Assing this permissions to the file:</p><pre>SDL2$ chmod 755 install_sdl2.sh</pre><p>5. Execute the installation file:</p><pre>SDL2$ ./install_sdl2.sh<br>...<br><br>All set!<br>\n\n<br>Don&#39;t forget to compile with: `sdl2-config --cflags`<br>Don&#39;t forget to link with: `sdl2-config --libs` -lSDL2_ttf<br>SDL2$</pre><p>Great!!, the library have been installed succesfully.</p><p>Now le’ts create this library, to draw something, to do this we’ll create 2 files: main.c and my_sdl2.h</p><p>my_sdl2.h:</p><pre>#ifndef MY_SDL2_H</pre><pre>#define MY_SDL2_H</pre><pre>#include &lt;SDL2/SDL.h&gt;</pre><pre>typedef struct SDL_Instance</pre><pre>{</pre><pre>SDL_Window *window;</pre><pre>SDL_Renderer *renderer;</pre><pre>} SDL_Instance;</pre><pre>int init_instance(SDL_Instance *);<br>void draw_stuff(SDL_Instance instance);</pre><pre>#endif /* MY_SDL2_H */</pre><p>main.c:</p><pre>#include &quot;my_sdl2.h&quot;</pre><pre>int main()</pre><pre>{</pre><pre>SDL_Instance instance;</pre><pre>/* Only returns 0 when it succeeds */</pre><pre>if (init_instance(&amp;instance) != 0)</pre><pre>return (1);</pre><pre>while (1)</pre><pre>{</pre><pre>SDL_SetRenderDrawColor(instance.renderer, 0, 0, 0, 0);</pre><pre>SDL_RenderClear(instance.renderer);</pre><pre>draw_stuff(instance);</pre><pre>SDL_RenderPresent(instance.renderer);</pre><pre>}</pre><pre>return (0);</pre><pre>}</pre><pre>int init_instance(SDL_Instance *instance)</pre><pre>{</pre><pre>if (SDL_Init(SDL_INIT_VIDEO) != 0)</pre><pre>{</pre><pre>fprintf(stderr, &quot;Unable to initialize SDL: %s\n&quot;, SDL_GetError());</pre><pre>return (1);</pre><pre>}</pre><pre>instance-&gt;window = SDL_CreateWindow(&quot;SDL2 \\o/&quot;, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 300, 200, 0);</pre><pre>if (instance-&gt;window == NULL)</pre><pre>{</pre><pre>fprintf(stderr, &quot;SDL_CraeteWindow Error: %s\n&quot;, SDL_GetError());</pre><pre>SDL_Quit();</pre><pre>return (1);</pre><pre>}</pre><pre>instance-&gt;renderer = SDL_CreateRenderer(instance-&gt;window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);</pre><pre>if (instance-&gt;renderer == NULL)</pre><pre>{</pre><pre>SDL_DestroyWindow(instance-&gt;window);</pre><pre>fprintf(stderr, &quot;SDL_CreateRenderer Error: %s\n&quot;, SDL_GetError());</pre><pre>SDL_Quit();</pre><pre>return (1);</pre><pre>}</pre><pre>return (0);</pre><pre>}</pre><pre>void draw_stuff(SDL_Instance instance)</pre><pre>{</pre><pre>SDL_SetRenderDrawColor(instance.renderer, 0xFF, 0xFF, 0xFF, 0xFF);</pre><pre>SDL_RenderDrawLine(instance.renderer, 10, 10, 100, 100);</pre><pre>}</pre><p>All that this code code does is to draw a line, let’s compile and see if it works.</p><pre>$ gcc -c main.c `sdl2-config --cflags`<br>$ gcc -o draw main.o `sdl2-config --libs`</pre><p>Awesome!!, until this point, a ‘draw’ executable file has been created, now we need to execute it and see a new window with a white line in it:</p><pre>$ ./draw&amp;</pre><p>And you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OkND2NFP46mE9X0DxG7-9A.png" /></figure><p>Well this is just an alternative, if you think this can help you, then you can try this solution, also I want to mention that sometimes there are problems with the terminal in GUI, but you can overcome this by using the terminal from windows and using the Desktop environment on vagrant just to run the executables.</p><p>Hope this helped you in some way, take care, and, see you!!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccd8d8872e78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic and Static libraries in C]]></title>
            <link>https://rleons.medium.com/dynamic-and-static-libraries-in-c-7935ba88ee5b?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/7935ba88ee5b</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Sun, 09 May 2021 16:43:32 GMT</pubDate>
            <atom:updated>2021-05-09T16:43:32.931Z</atom:updated>
            <content:encoded><![CDATA[<p>What do you think of when you think of a library, is it a lot of books, information maybe, knowledge stored in old pages, hahaha, cause that’s what I think every time I think of a library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Wq19j0tB2i4vlbah.jpg" /></figure><p>Well as you may know, in programing or better, in programing languages, us programmers use libraries to make coding easy. But where does this easiness comes from?, that’s what I’ll try to explain in this post.</p><p>Imagine you’re programing an app, and in the process of developing it you realize that there is a lot of code that is not strictly linked to the app’s functionallity but is code needed to achieve certain requirements, also you realize that this code could be used in other projects due to it’s generality, and you think, what if could take this code, put it some place and reuse it whenever I need to. And tada!!, you think, of course: a library!!!.</p><p>Let’s take this code as an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*j3Ha4NkjTQ0kXpCZhkP4RA.png" /><figcaption>contents of main.c</figcaption></figure><p>In the code above, we are using functions to make arithmetic opertations using two numbers, and then prints these results to stdout. Based on these code we can asume that all functions related to arithmetic operations can be used in other programs too, say for example a calculator app. Thinking in cases like this one we can step further and create a file containing all these operations resulting in a library based on the code.</p><p>To do so we first separate the code and move it to a separate file like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*el8GPvzXEWHgONgQxIc4QQ.png" /><figcaption>contents of the file math.</figcaption></figure><p>Well , now comes the fun part, we’re going to use these functions in our main file without the need to declaring them in the source code, to do so we first need to create a library, in this case a static library.</p><p>We achieve this by running the following commands:</p><pre>$ gcc -Wall -Wextra -Werror -pedantic -c math.c<br>$ ar -rc libmath.a math.o<br>$ ranlib libmath.a</pre><p>The above commands will compile and assemble the file math.c, then the command ‘ar’ merges the contents into a file called “libmath.a” (which is in fact our library), finally ‘ranlib’ indexes the symbols to speed symbol lookup.</p><p>To display the list of symbols contained in our library we can use the command ‘nm’ like this:</p><pre>$ nm libmath.c<br><br>math.o:<br>0000000000000000 T add<br>000000000000003d T divide<br>000000000000002a T multiply<br>0000000000000014 T substract<br>$</pre><p>To use or library, we just need to include the header into our main file and then compile, our main file looks tike this now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*Q6YYhd5m0XCksMhFPNTTug.png" /><figcaption>contents of main.c</figcaption></figure><p>Notice that ‘lib_math.h’ contains the definitions of the functions, now we can use the library in our code, to do so, we have to compile our main file like:</p><pre>$ gcc main.c -L. -lmath -o static</pre><p>And that’s it, we can use this library every where we want to or need to, the dowside of static libraries is that every time we copile code using this library, the object code related to it gets copied to the final executable and thus increases the final executable’s size. Fortunally we other alternative, know as Dynamic libraries.</p><p>Dynamic libraries allows us to share the code between programs, this is achieved by storing a reference to the library code instead of copying its content.</p><p>To create a new dynamic library, we first need to compile our library code into an object code without linking it, we do this by executing the following.</p><pre>$ gcc -c -fPIC math.c</pre><p>Notice that:</p><ul><li>-c: Compiles and assembles the code but doesn’t links it</li><li>-fPIC: Tells the compiler to create a Position Independent Code</li></ul><p>A new file “main.o” was created, the next step is to create our dynamic library taking this object code as this:</p><pre>$ gcc -shared math.o -o libdynmath.so</pre><p>And finally we have to compile our program using this dynamic library:</p><pre>$ gcc main.c -L. -ldynmath -o dynamic</pre><p>And that’s it, not really, if we try to execute our program it will fail, let’s see:</p><pre>$ ./dynamic<br>./dynamic: error while loading shared libraries: libdynmath.so: cannot open shared object file: No such file or directory</pre><p>mhhh, so what happened, well, to underatand this let’s first look at the dependencies needed to run our code:</p><pre>$ ldd dynamic<br>        linux-vdso.so.1 =&gt;  (0x00007fffc47e1000)<br>        libdynmath.so =&gt; not found<br>        libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd3ccd8d000)<br>        /lib64/ld-linux-x86-64.so.2 (0x00007fd3cd156000)</pre><p>What??, it says that our library is not found but we now that the library has been created so, what happens is that even though we created the dynamic library and we compiled our code including that library, the liker doesn’t know were that library lives, and thus cannot find it, to fix this we can use an environment variable:</p><pre>$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/$PWD/libdynmath.so</pre><p>So, LD_LIBRARY_PATH env var contains a list of directories that willbe used for the dynamic linker to load dynamc libraries, now if we execute our program again, we’ll see that it works!!</p><pre>$ ./dynamic<br>a + b = 37<br>a - b = 9<br>a * b = 322<br>a / b = 1.64</pre><p>Great!!, there are other ways we can manage our code to work, let’s take a look, but first we need to unset the env variable that we created eralier.</p><pre>$ unset LD_LIBRARY_PATH</pre><p>Excelent!!, now we’ll use ‘ldconfig’ command, which will allow us to create a cache that will cointain all the directories from which the linker will load the libraries, as the manpage for ‘ldconfig’ says:</p><blockquote>ldconfig <strong>creates the necessary links and cache to the most recent shared libraries found</strong> in the directories specified on the command line, in the file /etc/ld. so. conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so.</blockquote><p>So now let’s try to use this command in order create the cache needed to load our library at runtime, so to do this we will create a directory that will contain our library, then we’ll create a “.conf” file that will contain the path to this directory, and finally we will run “ldconfig” in order to load cache this changes.</p><p>First enter as superuser:</p><pre>$ sudo su</pre><p>Now let the configuration start!!, first by creating a directory which will contain our library:</p><pre># mkdir /usr/local/lib/my_math</pre><p>Now copy the library into that directory:</p><pre># cp libdynmath.so /usr/local/lib/my_math</pre><p>Awesome!!, now let’s create the config file, this file will be placed into /etc/ld.so.config.d/</p><pre># cd /etc/ld.so.conf.d/<br># echo /usr/local/lib/my_math &gt; libmy_math.conf</pre><p>If we see the dynamic dependencies of our executable now, we’ll see that our library is still missing:</p><pre># exit<br>$ ldd dynamic<br>        linux-vdso.so.1 =&gt;  (0x00007ffce17f2000)<br>        libdynmath.so =&gt; not found<br>        libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0e0e2e4000)<br>        /lib64/ld-linux-x86-64.so.2 (0x00007f0e0e6ad000)</pre><p>That’s because there is one more step needed, run the ‘ldconfig’ to load this changes:</p><pre>$ sudo ldconfig</pre><p>Now if we list the dependencies again we’ll see that our library is found:</p><pre>$ ldd dynamic</pre><pre>linux-vdso.so.1 =&gt;  (0x00007ffee9b92000)<br>        libdynmath.so =&gt; /usr/local/lib/my_math/libdynmath.so (0x00007f816057a000)<br>        libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f81601b1000)<br>        /lib64/ld-linux-x86-64.so.2 (0x00007f816077c000)</pre><p>And if we run the exe, it will work:</p><pre>$ ./dynamic<br>a + b = 37<br>a - b = 9<br>a * b = 322<br>a / b = 1.64</pre><p>Pretty awesome ah!!.</p><p>So that was it for this blog, hope this helped you in some way, have a good day, and see you on the next one!!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7935ba88ee5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using two’s complement to store integers in memory]]></title>
            <link>https://rleons.medium.com/using-twos-complement-to-store-integers-in-memory-56ba982d3575?source=rss-49bf8e5e6246------2</link>
            <guid isPermaLink="false">https://medium.com/p/56ba982d3575</guid>
            <dc:creator><![CDATA[Renato Leon]]></dc:creator>
            <pubDate>Mon, 29 Mar 2021 17:43:13 GMT</pubDate>
            <atom:updated>2021-03-31T23:46:10.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/424/0*zGjEbqepNxRTlbkw.png" /><figcaption>2’s complement of a binary number</figcaption></figure><p>Have you ever wonder how a machine’s stores numbers?, if your answer is no but you would like to know, then this post can help.</p><p>Let’s start by something simple, we know that a machine understands ones and zeros, right?, then if we want to store a number lets say 5 for instance, we’ll do it binary notation, right?</p><pre>base 10: 5<br>base 2 : 101</pre><p>Everything ok until this point. So we also know that machines uses bytes to store information, and that a byte is 8 bits long, so to make things simple we’ll assume that our number is stored using only 1 byte:</p><pre>base 2: 00000101</pre><p>As we know we can use positive and negative numbers in a computer, we use those numbers to make arithmetic operations for example, so this numbers (positives and negatives) corresponds to the signed value numbers a computer can handle, those numbers are stored in a special way to allow a computer identify if the number it’s reading is positive or negative, to identify this, we need a ‘bit’, usually the most significant one, if the bit is set to 1, the number should be negative, but if the ‘bit’ is set to 0, the number should be positive. To understand this better, I wrote a c program to read a byte’s bits, let’s take a look:</p><pre>#include &lt;stdio.h&gt;</pre><pre>void print_bytes(char *ptr, int size)<br>{<br>  int i;</pre><pre>  printf(&quot;bytes: &quot;);<br>  for (i = 0; i &lt; size; i++)<br>    printf(&quot;%d &quot;, ptr[i]);<br>  printf(&quot;\n&quot;);<br>}</pre><pre>void print_bits(char *ptr, int size)<br>{<br>  int i, j;</pre><pre>  int num;<br>  printf(&quot;bits : &quot;);<br>  for (i = 0; i &lt; size; i++)<br>  {<br>    num = (int) ptr[i];<br>    for (j = 7; j &gt;= 0; j--)<br>      printf(&quot;%d&quot;, (num &gt;&gt; j) &amp; 1);<br>    printf(&quot; &quot;);<br>  }<br>  printf(&quot;\n&quot;);<br>}</pre><pre>int main(void)<br>{<br>  int n;</pre><pre>  n = 5;<br>  printf(&quot;num: %d\n&quot;, n);<br>  print_bytes((char *)&amp;n, sizeof(n));<br>  print_bits((char *)&amp;n, sizeof(n));</pre><pre>  n = -5;<br>  printf(&quot;num: %d\n&quot;, n);<br>  print_bytes((char *)&amp;n, sizeof(n));<br>  print_bits((char *)&amp;n, sizeof(n));</pre><pre>  return (0);<br>}</pre><p>This code looks inside the memory where a number is stored and prints the bytes and bits of each byte, let´s compile it and run it to see the output it gives:</p><pre>$ gcc main.c <br>$ ./a.out <br> num: 5<br> bytes: 5 0 0 0 <br> bits : 00000101 00000000 00000000 00000000 <br> num: -5<br> bytes: -5 -1 -1 -1 <br> bits : 11111011 11111111 11111111 11111111</pre><p>For simplicity we are just going to focus on 1 byte, in this case the first one. When the number is 5 we can see that the bits are the same we saw at the example at the beginnig, but when the number is negative, some weird number appears. Let’s find out why.</p><p>To store a negative number, computer’s use something known as 2’s complement, if we calculate the 2’s complement of 5 we’ll end up with the exact number we saw before, let’s separate the numbers to focus on the first’s byte of each one:</p><pre>num: 5<br>bits : 00000101</pre><pre>num: -5<br>bits : 11111011</pre><p>So let’s see what a 2’s complement is, following is a quote taken from wikipedia</p><blockquote><strong>Two’s complement</strong> is a <a href="https://en.wikipedia.org/wiki/Mathematical_operation">mathematical operation</a> on <a href="https://en.wikipedia.org/wiki/Binary_number">binary numbers</a>, and is an example of a <a href="https://en.wikipedia.org/wiki/Method_of_complements">radix complement</a>. It is used in <a href="https://en.wikipedia.org/wiki/Computing">computing</a> as a method of <a href="https://en.wikipedia.org/wiki/Signed_number_representation">signed number representation</a>.</blockquote><blockquote>The two’s complement of an <em>N</em>-bit number is defined as its <a href="https://en.wikipedia.org/wiki/Method_of_complements">complement</a> with respect to 2^N; the sum of a number and its two’s complement is 2^<em>N</em>. For instance, for the three-bit number 010, the two’s complement is 110, because 010 + 110 = 8 which is equal to 2^<em>3</em>. The two’s complement is calculated by inverting the bits and adding one.</blockquote><p>So as wikipedia says, to calculate a 2’s complement, we must:</p><ol><li>Invert all bits of the number (1’s complement)</li><li>Add one to the previous calculated number</li></ol><p>We start with 5 and after this process, we should end with -5, let’s see the process:</p><pre>num: 5<br>bits : 00000101</pre><pre>1.) Invert all bits: <br>    bits : 11111010  -&gt; 1’s complement</pre><pre>2.) Add one to this result<br>    11111010 + 1 = 11111011  -&gt; 2’s complement<br>    num: -5</pre><p>Wow!!, so this number is the same one we saw when printing the bits of -5, so this bits are gonna be stored in memory to represent a negative 5 using 2’s complement. As we saw, 2’s complement is a usefull way to store negative numbers.</p><p>That’s all for now , I hope this post helped you in some way, take care!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56ba982d3575" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>