<?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 Gary Cordero Rosa on Medium]]></title>
        <description><![CDATA[Stories by Gary Cordero Rosa on Medium]]></description>
        <link>https://medium.com/@garycordero1690?source=rss-ed54fa267554------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fAUn5cNPWHymaNbux6VTFw.png</url>
            <title>Stories by Gary Cordero Rosa on Medium</title>
            <link>https://medium.com/@garycordero1690?source=rss-ed54fa267554------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 04:52:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@garycordero1690/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My uptake on SDLC Methodologies]]></title>
            <link>https://garycordero1690.medium.com/my-uptake-on-sdlc-methodologies-98d40faf81df?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/98d40faf81df</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[sdlc]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Sun, 18 Apr 2021 04:28:46 GMT</pubDate>
            <atom:updated>2021-04-18T04:28:46.641Z</atom:updated>
            <content:encoded><![CDATA[<p>Every developer early on in the career gets introduce to the term Software Development Life Cycle Methodology therefore I decided to look deeper into it. We can define an SDLC as a set of steps followed in order to produce high-quality software applications. It goes through a series of phases that ensures its proper executions.</p><p>Different sources have different numbers of phases for an SDLC Methodology but regardless of source, you will find the following main phases.</p><p><strong>Planing:</strong> It’s the phase where the “what to do, how to do it, and who does it.” is defined. It includes the scope of the project, the structure of the team, the budget, and any other resource required.</p><p><strong>Analysis: </strong>During this phase, we discover and understand the details of the problem. The “What we need the solution to do?” is answered here. This phase is usually divided into two subsets.</p><ul><li>Requirement phase: During this period with capture information on the problem using several techniques but the most popular as of the time is to capture User Stories to get the user requirements from them. A User Story is, as defined by Wikipedia “an informal, natural language description of features of a software system”.</li><li>Elicitation phase: During this period the user requirements captured are distilled and transformed into <strong>software requirements specifications. </strong>Use Case, Domain Classes, are found together with their workflow usually represented with a or several diagrams.</li></ul><p><strong>Design: </strong>During this phase, the high-level design of the software and system is specified. It goes deeper into the software detailing, Domain Classes are detailed with attributes, methods, and relationships, markups for the software views are developed, the structure of the database is defined, technology to be used, etc… Every detail of the future implementation of the solution to be implemented is defined here.</p><p><strong>Development &amp; Testing:</strong> You guessed it right! During this phase, all the coding and testing happens. Lots of coding, testing, and iterating after testing. I like to call it “Code and test, test, and test”. Testing is essential and also the reason I wrote it thrice. During this phase, you will find three different kinds of tests that will invite you to revisit your code and sometimes your design. These are Unit Testing, Integration Testing, and Acceptance Testing.</p><p><strong>Implementation &amp; Maintainance</strong>: Your code is running well in development it has passed all of the tests and now it&#39;s time to deploy it, calling the DevOps team!. This phase is all about deploying and making a smooth transition to the new system and giving software maintenance without interrupting business continuity. It also includes migrating data from the old system all the way to training users and offering support.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98d40faf81df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Closure in Javascript]]></title>
            <link>https://garycordero1690.medium.com/understanding-closure-in-javascript-a8dede892042?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8dede892042</guid>
            <category><![CDATA[module-pattern]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[closures-functions]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Mon, 12 Apr 2021 03:09:53 GMT</pubDate>
            <atom:updated>2021-04-12T03:09:53.101Z</atom:updated>
            <content:encoded><![CDATA[<p>As you go along the way of learning javascript you hit the concept of closure. Unfortunately for me, it was in the beautiful learning process you go through during an interview. So I write this blog in hopes of increasing my understanding of the topic and hopefully that of my fervent readers.</p><h3>What is a closure?</h3><p>A closure in javascript is when functions are bundled together inside another function with references to its surrounding state similar to the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*Mi2wVwF0BPLC1ASVtwrl6w.png" /></figure><p>At first look, this brought confusion to me not because it was my first time seeing nested functions but because at first look I thought that once the function executed is would return the function but the variable “name” would cease to exist but one I execute the code it was not the case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*BWKqI6tRNYLIsgcBVfCUVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*QmR6Rsek4C7ANStorz32Qg.png" /></figure><p>This is the magic of closure since it bundles together functions with references to its surrounding state it means it saves the value and reference of the “name” variable. This space where functions are all bundled together is called <strong>the lexical environment, </strong>in this case, it refers to the whole body of function1().</p><p>Immediately I started wondering about the powers of closures and my research led me to a more practical example for this would be the adder function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*nTgpibYfUoTVlAcMlPz9gQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*4I8D0I-KayFLljNEnhUgqw.png" /></figure><p>This is a widely known example on the internet but it serves as a good base for understanding the practical approach. Another one would be a function that changes the background color of your website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*pR31DBW-Fj0C-sFTHU5b6w.png" /></figure><p>I made a JSfiddle sample of this code at this <a href="https://jsfiddle.net/gary1690/ebu8xf5m/3/">link</a>.</p><p>A way to see this kind of closure is pretty much like a blueprint to create functions with a similar purpose.</p><p>Closures also allow us to emulate private methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*mKwGWNMJx5w5HsvQslwbUQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*urWUbh9Lc14AGwIzYxIldw.png" /></figure><p>This is called the Module Pattern in Javascript and if you look very closely it resembles the concept of classes in many other programming languages.</p><h3>More resources about closure</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures</a></li><li><a href="https://scotch.io/tutorials/understanding-javascript-closures-a-practical-approach">https://scotch.io/tutorials/understanding-javascript-closures-a-practical-approach</a></li><li><a href="http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html">http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8dede892042" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Class Variables VS Instance Variables]]></title>
            <link>https://garycordero1690.medium.com/class-variables-vs-instance-variables-874b63e231a4?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/874b63e231a4</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Sun, 04 Apr 2021 18:30:39 GMT</pubDate>
            <atom:updated>2021-04-04T18:41:57.151Z</atom:updated>
            <content:encoded><![CDATA[<p>This a topic everybody runs into while learning to code, and that sometimes brings some confusion into this process. Although as confusing as it may seem, it is also quite simple, and learning it can help you take your coding to another level.</p><h3>What are instance and Class Variables?</h3><p><strong>A class variable </strong>is a variable defined in a class body that can be interacted with without an instance of such class. Class variables are shared among all instances of the class and its subclasses.</p><p><strong>An instance variable</strong> is also a variable defined in a class body but belongs to a specific instance. Its value is not shared between instances of a class or its subclasses. Let say that each instance has variables with the same name but refer to different values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axRkrkV0erk1dbNlTQ-q6g.png" /></figure><h3><strong>Class Variables</strong></h3><p>Let&#39;s explore how class variables behave in Java with the following example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ufia04sI1QbKmc7XguoERA.png" /></figure><p>As you can see the classes Goblin and Troll inherit from the class Monster which has a count class variable that is incremented every time a Goblin or a Troll created. Let’s create some of them and see the behavior</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*zK8pJs8-IGGZy1jfIdVn7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*5hD26H7hYlrWAWtxGNEhgQ.png" /></figure><p>As you can see whenever a monster was created the Class variable count in the Monster class was increased. Since we created 2 monsters its value was 2 and we could access its value using the name of the class directly without the need for an instance. Although using an instance of any of these classes to access this variable will produce the same result.</p><p>A good use case for class variables following the previous example would be to imagine you are creating a video game in which you spawn different kinds of monsters on a field and the clearing condition is to kill all of them. How would you do that? You could keep track of the number of monsters spawn with a class variable and decrease its value whenever a monster is slain until it reaches zero.</p><h3>Instance Variable</h3><p>Let’s explore the behavior of instance variables this time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*q3C5WXFqZKyyQP_KmK2LzQ.png" /></figure><p>I modified the previous example and added an instance variable attack the would reflect the attack power of our monster. Let’s try using it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fkgCNfGmOWvzc8Ps7TG3xw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*35Lm6Snpw_V2BGCKlQDH0g.png" /></figure><p>As you can see the attack power of both is different even though they are sharing the same name variables and accessor methods name. If try to access this variable as a class variable you will see the following error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0q5ACg5FZWw-jnpGIbUCBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*lzjf6Ro3rcX-M7yhi-USUQ.png" /></figure><p>Since its value belongs to a specific instance and not the class.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=874b63e231a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby Modules]]></title>
            <link>https://garycordero1690.medium.com/ruby-modules-8db0545c07e3?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/8db0545c07e3</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[mixin]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Sun, 28 Mar 2021 04:54:41 GMT</pubDate>
            <atom:updated>2021-03-28T04:54:41.697Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the concepts that you find along the way to becoming a great Rubyist is the concept module. A module is a way to wrap methods, classes, constant in a unit, in a way similar to a Class with the difference that a module can’t be instantiated.</p><p>You are probably wondering “If they can be instantiated then what is the use of an module?”. Well, modules have two main uses.</p><ol><li>Namespacing</li><li>Utilizing Ruby Mixin</li></ol><h3><strong>Namespacing</strong></h3><p>Namespacing is in a way a kind of container for functions, classes, constants, modules, etc … The idea of this is to used this container as an unique identifier for everything contained in it, to avoid clashes. Imagine you are using to gems with the same two classes, how would the compiler know which of the classes diffinition you are referring to.</p><p>An example of two identical classes existing with the same name and same methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*Y3ERJl17f3PEi6Zs_AqWnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*vw6L2V3gV424UlefjW6CYA.png" /></figure><p>As you can see the first class definition was completely overlooked by the compiler and the latter definition overshadowed the former. Now let’s apply a namespace to solve this problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*tSJDxCpqLfX7Pg577qkn4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*9CdWPXsy7c3gDCWaBVTzmA.png" /></figure><h3>Ruby Mixin</h3><p>In order to understand ruby mixin, we need some understanding of object-oriented programming concepts and principles. Ruby mixings allows to do several thing like implement multiple inheritance which ruby doesn&#39;t support directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*xGL5V3shQPlKhDmfF2WVtg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*77X_YkdMxqhB0-DEkugMjg.png" /></figure><p>As we can see that the class Dog inherits from the two modules and shows a behavior similar to multiple inheritance or so to say a mixin.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8db0545c07e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Object in Rails Using SimpleCommand Gem.]]></title>
            <link>https://garycordero1690.medium.com/service-object-in-rails-using-simplecommand-gem-def3bb6a5633?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/def3bb6a5633</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[service-object]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[simplecommand]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Sun, 21 Mar 2021 18:29:16 GMT</pubDate>
            <atom:updated>2021-03-21T18:29:16.822Z</atom:updated>
            <content:encoded><![CDATA[<p>While continuing on working on my skills and developing applications on ruby I got introduce to the service object model. The service object model helps you reduce the complexity of your controllers and code repetition.</p><p>The job of a service object is to encapsulate functionality, execute one service, and provide a single point of failure. A service object is just a Plain Old Ruby Object (“PORO”) that follows the following structure.</p><ul><li>Has an initialization method with a params argument.</li><li>Has a single public method named call.</li><li>Returns a payload or an error.</li></ul><p><a href="https://github.com/nebulab/simple_command">SimpleCommand</a> is a Ruby Gem that makes it simple to create Service Objects. The basic structure of a Service Object Class using Simple Command is as follows.</p><pre># define a command class<br>class AuthenticateUser<br>  # put SimpleCommand before the class&#39; ancestors chain<br>  prepend SimpleCommand<br>  <br><br>  # optional, initialize the command with some arguments<br>  def initialize(params...)<br>   ##...<br>  end<br><br>  # mandatory: define a #call method. its return value will be available<br>  #            <br>  def call<br>    # logic ....  returns payload or error<br>  end<br>end</pre><p>With this, we can create an example to reduce logic in the controller. Let’s observe an example of a login method and how the controller code looks cleaner. An example to use Simplecommand Service Object to authenticate users would be as follows.</p><pre>class AuthenticateUser<br>  prepend SimpleCommand</pre><pre>  def initialize(email, password)<br>    @email = email<br>    @password = password<br>  end</pre><pre>  def call<br>   JsonWebToken.encode(user_id: user.id) if user<br>  end</pre><pre>  private<br>  attr_accessor :email, :password<br>  <br>  def user<br>    user = User.find_by_email(email)<br>    return user if user &amp;&amp; user.authenticate(password)<br>    errors.add :user_authentication, &#39;invalid credentials&#39;<br>    nil<br>  end<br>end</pre><p>Then in the controller, our logic would be much simpler since finding the User and Encoding the token all happened in the Service layer.</p><pre>class AuthenticationController &lt; ApplicationController</pre><pre>  def authenticate<br>    command = AuthenticateUser.call(params[:email], params[:password])<br>    if command.success?<br>      render json: { auth_token: command.result }<br>    else<br>      render json: { error: command.errors }, status: :unauthorized<br>    end<br>  end<br>end</pre><h4>Conclusion</h4><p>Service objects that are designed to execute one single action in your domain logic and do it well. This allows your controllers to be leaner and your code to be easy to reuse, test, and debug.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def3bb6a5633" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Chrome Developer’s Tools To Detect End-Points.]]></title>
            <link>https://garycordero1690.medium.com/using-chrome-developers-tools-to-detect-end-points-9b43ad4fdccd?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b43ad4fdccd</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[chrome-developer-tools]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Sat, 13 Mar 2021 21:15:19 GMT</pubDate>
            <atom:updated>2021-03-13T21:15:19.599Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently had the amazing opportunity to of being interview for a customer support engineer position where I met amazing people and had the opportunity to learn new tricks for debugging using the developer’s tools. One of them was detecting the end-points a web page is connecting to fetch data and I decided to do a step by step on how to do that.</p><p>For the purpose of this tutorial, I am going to use one of the websites I have built since most websites in production can have a lot of information and could be a little difficult for starters.</p><p>The first thing that you have to do is visit the website you want to observe, in my case, I will go to <a href="http://localhost:3001/customers">http://localhost:3001/customers</a>. I will see something as follow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rC9owD6VHrKkrcY2KqzaOQ.png" /></figure><p>Once there we can open the developer tools, and go to the network section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_iAWn3it3BmKfTxyODnrg.gif" /></figure><p>The network feature of google chrome only tracks network activity while is open therefore once there you can refresh the page to see all the resources that are being delivered to the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BySINMbwZMJWekgoCyhKHw.png" /></figure><p>Here you can see all the resources sent from the server, third-parties, etc. to the browser in order to deliver the content. That includes HTTPRequest, CSS files, javascript files, and others. All the resources are together but we can filter them using the option on the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJw8DGiBktjXL58wrKFjBQ.png" /></figure><p>The one of interest is the XHR option. XHR stands for XMLHttpRequest which is a JavaScript API to create AJAX requests. Its methods provide the ability to send network requests between the browser and a server. In the case of the chrome developer tools, this option allows us to filter and visualize XHR or fetch requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQAn8Ue5QN-drMcRDeBWzQ.png" /></figure><p>From there you can click on the name of the end-point and get further details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5iRe-4ANnGlK9Sk6g9IWsQ.png" /></figure><p>You can see the headers&#39; general information and more information on both, the request and response headers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDp2TZeRWakKngg5ckBmXA.png" /></figure><p>You can preview the response body</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3sPU4EjrbZu0HuSLDMcf3Q.png" /></figure><p>or see the response raw body</p><p>See where the fetch request was initialize</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2kHJw_73liCV2H-BVWswg.png" /></figure><p>Finally, see the timeline between the request and response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z2wSyittYxVoMAAxHKRQdg.png" /></figure><h3><strong>Conclusion</strong></h3><p>The network section of the chrome developers’ tool is a good place to investigate if resources are being downloaded or uploaded as expected. The most common use cases for the Network panel are:</p><ul><li>Making sure that resources are actually being uploaded or downloaded at all.</li><li>Inspecting the properties of an individual resource, such as its HTTP headers, content, size, and so on.</li></ul><p>So it is a perfect place to start looking at how those requests are behaving and how resources are flowing through your application. You can learn more about Chrome Developers Tools at this <a href="https://developers.google.com/web/tools/chrome-devtools/network">link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b43ad4fdccd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Token Authentication with JWT and BCrypt Gems]]></title>
            <link>https://garycordero1690.medium.com/rails-token-authentication-with-jwt-and-bcrypt-gems-ce5b4d3337ef?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce5b4d3337ef</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Mon, 08 Mar 2021 00:39:50 GMT</pubDate>
            <atom:updated>2021-03-08T00:39:50.756Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most popular ways of authentication use in rails 5 and higher is the token-based authentication, where a generated created when an user logs in and such token is pass with every request the user make to as a proof of identity to authorize access to resources in the server. In this guide I am going to show you how to quickly set up a token-base authentication API in Rails 6 using JWT and BCrypt gems.</p><p>Lets start by creating a new project</p><pre>rails new api-app --api</pre><p>Them let’s modify the cors.rb file so it can take cors.rb to allow <a href="https://medium.com/@Nicholson85/handling-cors-issues-in-your-rails-api-120dfbcb8a24#:~:text=For%20anyone%20unaware%2C%20CORS%20refers,an%20origin%20other%20than%20itself.">Cross origin resource sharing</a>. More info about rack-cors in ruby <a href="https://github.com/cyu/rack-cors">https://github.com/cyu/rack-cors</a></p><pre>//config/initializers/cors.rb<br># Be sure to restart your server when you modify this file.<br># Avoid CORS issues when API is called from the frontend app.</pre><pre># Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.</pre><pre># Read more: https://github.com/cyu/rack-cors</pre><pre>Rails.application.config.middleware.insert_before 0, Rack::Cors do<br>  allow do<br>     origins &#39;*&#39;<br>     <br>     resource &#39;*&#39;,<br>       headers: :any,<br>       methods: [:get,:post,:put,:patch,:delete,:options,:head]<br>  end<br>end</pre><p>Then in your gem file uncomment rack-cors gem</p><pre>//Gemfile<br># Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible<br>gem &#39;rack-cors&#39;</pre><p>Then in the terminal run</p><pre>Bundle install</pre><p>You will notice that the change was just to uncomment a couple of lines of code and change origins to *. This will allow access to all the resources regardless of where the request is coming from.</p><p>Now lets enable BCrypt and Add JWT gem. In your gem file let’s uncomment the BCrypt gem.</p><pre>//Gemfile<br># Use Active Model has_secure_password<br>gem &#39;bcrypt&#39;, &#39;~&gt; 3.1.7&#39;</pre><p>Now let’s add the jwt gem by running the following command in your terminal.</p><pre>Bundle add JWT</pre><p>Now that we have basic setup, lets create the user model to login</p><pre>rails g model user username:string password_digest:string </pre><p>let’s run the new migration in the terminal</p><pre>rails db:migrate</pre><p>and in the User model</p><pre>//app/models/user.rb<br>class User &lt; ApplicationRecord<br>  has_secure_password<br>end</pre><p>let’s create an authentication controller</p><pre>rails g controller Authentication</pre><p>Before continuing working in our authentication controller, lets create the some methods that we are going to need in our application_controller.rb</p><pre>class ApplicationController &lt; ActionController::API<br>before_action :authorize</pre><pre>def authorize<br> @headers = request.headers<br>  if @headers[&#39;Authorization&#39;].present?<br>    token = @headers[&#39;Authorization&#39;].split(&#39; &#39;).last<br>    decoded_token = decode(token)<br>    @user = User.find_by(id:decoded_token[:user_id])<br>    render json:{ error: &#39;Not Authorized&#39; }, status:401 unless @user<br>  else<br>    render json: { error: &#39;Not Authorized&#39; }, status: 401<br>  end<br> end<br> <br> private<br> def encode(payload, exp = 24.hours.from_now)<br>   payload[:exp] = exp.to_i<br>   JWT.encode(payload, Rails.application.secrets.secret_key_base)<br> end</pre><pre> def decode(token)<br>  body = <br>  JWT.decode(token,Rails.application.secrets.secret_key_base)[0]<br>  HashWithIndifferentAccess.new body<br>  rescue<br>    nil<br> end<br>end</pre><p>In here we have three methods:</p><ol><li>encode, use to create the token, it takes a payload which is a hash where we are going to be passing the user id, and expiration time that sets the lifespan of the token.</li><li>decode, use te decode the token and extract the user id that was previously encode.</li><li>authorize, we are going to run before almost every action to access resources. It would take the token and decode it get the user id and validate if such user id exist in the database to allow access to all resources</li></ol><p>The before_action makes sure to run the authorize method before every action of all the controllers that inherit from ApplicationController.</p><p>Now we can continue on working in our authentication controller. Inside our authentication method</p><pre>class AuthenticationController &lt; ApplicationController<br>  skip_before_action :authorize<br>  <br>  def authenticate<br>    user = User.find_by(username:params[:username])<br>    if user &amp;&amp; user.authenticate(params[:password])<br>      token = encode(user_id: user.id)<br>      render json: {token:token,user:user}<br>    else<br>      render json: {error:&quot;An Error Happened&quot;}<br>    end<br>  end<br>end</pre><p>Now that we have all the code,we can test it out. Let’s create an user in the rails console, username: gary1690 and password:12345</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwvyVivPaKkxQ6xm6hly1A.png" /></figure><p>Now that our new user is created we can authenticate it. I will be using postman for this. I will send a request to <a href="https://localhost:3000/authenticate">https://localhost:3000/authenticate</a> and send the username and password of the user we previously created. The result is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60XVKp6O_fjubeVQbFnCPA.png" /></figure><p>Now that we authenticate our user, let’s create son resources to access with our token</p><pre>rails g reources Items name:string</pre><p>then run our migration</p><pre>rails db:migrate</pre><p>and create our index action in the ItemsController.rb</p><pre>class ItemsController &lt; ApplicationController<br> def index<br>  render json: Item.all<br> end<br>end</pre><p>Now we can request our resources using the token</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_m7cN0JBUnstVrg9tmzRw.png" /></figure><p>We successfully got the list of items back, you can try creating items to get a full list instead of an empty array.If you do you will get something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*br8oTxULtJ1NpUSOkVJFAQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce5b4d3337ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Scraping in Python]]></title>
            <link>https://garycordero1690.medium.com/web-scraping-in-python-998ad1c42608?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/998ad1c42608</guid>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[selenium-webdriver]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Mon, 01 Mar 2021 01:13:13 GMT</pubDate>
            <atom:updated>2021-03-01T01:13:13.379Z</atom:updated>
            <content:encoded><![CDATA[<p>As I advance in my knowledge of python I decided to apply to a data engineer position at a prestigious finance company. Luckily I was selected from the pool of candidates and was entrusted with learning how to web scrap and use basic libraries like pandas to process the information scraped from the web. Today I’ve come to share what I learned during that process, and we are going to be web scrapping for data and creating pandas data frames to easily manipulate and present the data in the future.</p><p>The python library and Selenium WebDriver and we are going to focus on using it to scrape a table from <a href="https://www.the-numbers.com/market/2019/top-grossing-movies">www.the-numbers.com/market/2019/top-grossing-movies</a> and get the information of the top 30 movies in this table and create a dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9SPEjQM0PQlLfjzP" /></figure><p>The first step to take in order to start web scrapping the table is to import all the dependencies needed. It includes Selenium WebDriver to navigate through the webpage. WebDriverWait to wait for dynamic content to be loaded, ChromeDriverManager to provide the WebDriver control over a browser in order to navigate to the website, Options to set extra configurations to our Webdriver, and finally Pandas to create our dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*kKaFqbMM3ijQMgOJ" /></figure><p>After loading our dependencies, we need to configure and instantiate our WebDriver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*umE_MZKyV4M9FW9p" /></figure><p>The option “ — headless” is to prevent the driver from opening a browser window and do the web scraping in the background. We create the instance of the WebDriver on the last line, webdriver.Chrome() receives two parameters the first one is the browser driver it is going to use in this case, we are passing the ChromeDriverManager().install() method which returns an appropriate version of the ChromeDriver for the version of Google Chrome installed on your computer. The second parameter is the configuration options for the driver in this case the “ — headless”.</p><p>After that, all we need to do is tell the driver to open the URL of the website we are going to scrape and make the driver wait for 5 seconds for all the dynamic content to be loaded before starting transversing the DOM</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SzhblLib0cSlk82I" /></figure><p>The next step would be to transverse the DOM and retrieve the information we want but before that, we need to understand how our data is spread across the DOM. Let’s have a closer look by visiting the website in the chrome browser and open the developers’ tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*-vtGXrUjQlZeCYq2" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*4-OhdrH-E3mfkcoN" /></figure><p>Here you can explore the structure of the DOM, if you look closer the data we want is inside the cells within the rows of a table. Some of them are withing anchor tags inside the cells. In order to retrieve those values, we are going to used several methods provided by Selenium WebDriver.</p><ul><li><strong>find_element_by_tag_name( “tag_name”)</strong>, retrieves the first element with the maching tag.</li><li><strong>find_elements_by_tag_name(‘tag_name’)</strong>, retrieves all elements with the maching tag.</li><li><strong>get_attribute(‘attribute_name’)</strong>, retrieves the value within a particular attribute associated with a particular tag.</li></ul><p>here are many other methods that can be used to achieve this, you can visit Selenium WebDriver to be more familiar with them at the following link <a href="https://selenium-python.readthedocs.io/installation.html">https://selenium-python.readthedocs.io/installation.html</a>.</p><p>Now that we are familiar with the structure of the DOM and with the methods needed, we would need to find the table with the information we want. Luckily since it is the only table on the site we can easily locate it using find_element_by_tag_name( “table”).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*OrGpqrStPATcmjiq" /></figure><p>After we get the table we retrieve all the rows within it as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*c-nhCnix7lfuiBfM" /></figure><p>Now that we have all the table rows, we are going to iterate over them get all cells and retrieve all the data within the cells, create a dictionary, and saving it in a list. While iterating over the rows the first row is skipped since it only contains the header and not the information we are looking for. After retrieving all the information we close the driver using driver.quit() closing all browsers and terminating the driver session and clearing the memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*56W7s7cp7cW8KOE5" /></figure><p>Now that we have our list of dictionaries with all the information we can create a dataset using pandas the following way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7XiHmnSt0dbyqvjh" /></figure><p>The final result would be a dataset we the information of the top 30 movies of 2019.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f7_yKKT62dkwCKhh" /></figure><h3>Conclusion</h3><p>Web scraping is a great way to acquire data. Web Scraping is used for <a href="https://en.wikipedia.org/wiki/Contact_scraping">contact scraping</a>, and as a component of applications used for <a href="https://en.wikipedia.org/wiki/Web_indexing">web indexing</a>, <a href="https://en.wikipedia.org/wiki/Web_mining">web mining</a> and <a href="https://en.wikipedia.org/wiki/Data_mining">data mining</a>, online price change monitoring and <a href="https://en.wikipedia.org/wiki/Comparison_shopping_website">price comparison</a>, product review scraping (to watch the competition), gathering real estate listings, weather data monitoring, <a href="https://en.wikipedia.org/wiki/Change_detection_and_notification">website change detection</a>, research, tracking online presence and reputation, <a href="https://en.wikipedia.org/wiki/Web_mashup">web mashup</a> and, <a href="https://en.wikipedia.org/wiki/Web_data_integration">web data integration</a> and many more things, therefore a must-have tool for software engineer and data scientist.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=998ad1c42608" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby Enumerator]]></title>
            <link>https://garycordero1690.medium.com/ruby-enumerator-74b84615f4e8?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/74b84615f4e8</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[enumerators]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Sun, 21 Feb 2021 22:10:25 GMT</pubDate>
            <atom:updated>2021-02-21T22:10:25.965Z</atom:updated>
            <content:encoded><![CDATA[<p>An enumerator is a class in ruby that supports internal and external iteratoration, although it looks more like a function that behaves like an iterator. The best part of an enumerator is that they are highly customizable.</p><blockquote>(Full definition from <a href="http://en.wikipedia.org/wiki/Generator_(computer_programming)">Wikipedia</a>): “A generator is a special routine that can be used to control the iteration behaviour of a loop. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an array containing all the values and returning them all at once, a generator yields the values one at a time, which requires less memory and allows the caller to get started processing the first few values immediately. In short, a generator <em>looks</em> like a <em>function</em> but behaves like an <em>iterator</em>.”</blockquote><p>We can build an example of an enumerator in many ways, it could be one that iterates over the Fibonacci sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*M5M8Vl48xHczWDOV_C2-fw.png" /></figure><p>We can move over the series, using the next() method. That means that we can call the next element in the enumerator anytime we want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*Kl3zdckJmKEEvELrTajR5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*mwWXp4EFCSezGcvSjKIhvQ.png" /></figure><p>Or we can take the first Nth elements from</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*62iu9iZGxMmfMEO3BCyc4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*TbacIkLPeJ-Jn6fY1wV-vw.png" /></figure><p>We add the lazy call because otherwise, ruby would wait for all elements in the series to be generated before slicing the first 5 elements, luckily enumerators have been built smart enough to defer loading of elements until needed if specified with the <strong>lazy</strong> call in the chain.</p><p>We can even take it a little further and do something more advance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u02X5SJ-nSaI65UcX97D1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdwaW5PXOQt4WVXfIIKcrg.png" /></figure><h3>Conclusion</h3><p>Enumerators are a must-have under your ruby developer toolkit, they take iteration to the next level, letting you have more control over it. You can find more info about<a href="https://ruby-doc.org/core-2.6/Enumerator.html"> enumerator in the ruby documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74b84615f4e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Emmet Tips and Tricks]]></title>
            <link>https://garycordero1690.medium.com/emmet-tips-and-tricks-8736c1715d36?source=rss-ed54fa267554------2</link>
            <guid isPermaLink="false">https://medium.com/p/8736c1715d36</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[emmet]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Gary Cordero Rosa]]></dc:creator>
            <pubDate>Fri, 12 Feb 2021 17:13:09 GMT</pubDate>
            <atom:updated>2021-02-12T17:13:09.682Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rgj7TVMDpqKoX6Ip.jpg" /><figcaption>Making HTML and CSS code easy</figcaption></figure><p>Emmet is a web-developer’s toolkit that can greatly improve your HTML &amp; CSS workflow by using abbreviations. Abbreviations are the heart of this tool, these special expressions are parsed in runtime and transformed into structured code block increasing productivity by helping you save coding time. It’s available for most text editors and IDEs, therefore wildly use.</p><p>The idea of this post is to give you a headstart with emmet and go over some basic but very important abbreviation.</p><h3>Emmet Abbreviations</h3><h4>HTML Structure</h4><p>Emmet provides a very easy way to write the basic structure of your HTML documents by using the ! abbreviation. What could be more exciting than that?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rr1kD_9qCFXPwjsK_1Xa_w.png" /></figure><h4>Elements Tag</h4><p>Emmet also provides an abbreviation for creating elements in many ways.</p><p><strong>Single Element</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5GlCqaFHD4nI5uSLn7Eiw.png" /></figure><p><strong>Single Element with a class</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_31VOAY4av3eIUgAGaoNjQ.png" /></figure><p><strong>Single Element with an Id</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JH-a-K8H7c83Vr2F9_X6FA.png" /></figure><p><strong>Single Element with attribute</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C94L6SIxuQb_1f96L8yKDg.png" /></figure><h4>Children</h4><p>Emmet abbreviation also includes creating elements with their children.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VaokJBe-ZBsB7eGQwUEwNw.png" /></figure><h4>Multiplication</h4><p>Emmet also allows multiplication using * keyword, very useful when creating a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lrkdxFzBqG008XipV214hw.png" /></figure><h4><strong>Siblings</strong></h4><p>Emmet also provides a way to create sibling elements using the + keyword.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EGFQc80QDtEVrXfyvCWWQw.png" /></figure><h4>Grouping</h4><p>Emmet allows grouping, in order to use the multiplication technique in several elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PidBYi5PBRMHESwX3oHDEQ.png" /></figure><h4>Climbing Up</h4><p>After creating nested elements you might want to climb back up in the hierarchy of your document, Emmet allows you to do that by using ^ keyword.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ynrUcnZ7mExJh2FPt4m0ew.png" /></figure><h3>Text</h3><p>You can insert text in your abbreviations by using {}.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DfJoRuBh2qYnnACBOcWYQQ.png" /></figure><h4>CSS</h4><p>Emmet also facilitates the CSS work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*kfzt6zXXzu5FlKdSrvimEw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8736c1715d36" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>