<?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 Ricardo Brazão on Medium]]></title>
        <description><![CDATA[Stories by Ricardo Brazão on Medium]]></description>
        <link>https://medium.com/@ricardobrazao?source=rss-a7688269ba77------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kgIFRCZQdlQOSM-Z.jpg</url>
            <title>Stories by Ricardo Brazão on Medium</title>
            <link>https://medium.com/@ricardobrazao?source=rss-a7688269ba77------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:03:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ricardobrazao/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[AWS API Gateway with Terraform]]></title>
            <link>https://medium.com/onfido-tech/aws-api-gateway-with-terraform-7a2bebe8b68f?source=rss-a7688269ba77------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a2bebe8b68f</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ricardo Brazão]]></dc:creator>
            <pubDate>Wed, 22 Aug 2018 13:45:20 GMT</pubDate>
            <atom:updated>2018-08-22T13:53:51.856Z</atom:updated>
            <content:encoded><![CDATA[<h4>Or, how a backend developer coded some infrastructure with zero DevOps knowledge</h4><p>Ever wanted to create something in AWS? Feel over amazed with the AWS interface? Do you cry a little bit inside every time you look at the AWS dashboard? Then stay tuned for something that can ease your life, more than sliced bread did 🍞.</p><p>In recent times I had the opportunity of diving (and might I had, it was head first in some shallow waters) into the world of <a href="https://www.terraform.io/">Terraform</a>. The objective was, in a very first step, to create a proxy gateway in front of our API. At first this will simply be a “passthrough” proxy were everything that comes into to the API Gateway will be passed to our API and sent back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ls4ntpANoDTx1u_G4GAMXQ.png" /><figcaption>How I imagine AWS looks</figcaption></figure><p>I can only imagine your face right now… “But that’s the same as having nothing at all..”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*dn2VB-laoIyd88sgWnDWAA.gif" /></figure><p>You’re correct but let me continue by saying that this will just be the first step to something greater.</p><p>Most of the projects start as a monolith and then, in time, comes the part where we start splitting it in the “microservices” we all love. With this change in architecture there will be a part of your code that will start to look like a router, where it receives some request from the outside world and proceeds to redirect it to whoever is responsible for answering it. The AWS API Gateway is here so, we can lift those concerns from your service. We can even add more cross-cutting concerns to it (like authentication or rate limiting). Having this approach will even help with the latency of your response as it will skip the step of interpreting code to know were it should go, because it’s doing it directly in the AWS API Gateway.</p><p>Enough chit-chat and let’s get some coding done, starting with the creation of the api entry:</p><pre>resource “aws_api_gateway_rest_api” “api” {<br> name = “api-gateway”<br> description = “Proxy to handle requests to our API”<br>}</pre><p>In here we are creating the REST API resource to where all the requests are going to hit. Next we will start to configure what we want this API to do:</p><pre>resource &quot;aws_api_gateway_resource&quot; &quot;resource&quot; {<br>  rest_api_id = &quot;${aws_api_gateway_rest_api.api.id}&quot;<br>  parent_id   = &quot;${aws_api_gateway_rest_api.api.root_resource_id}&quot;<br>  path_part   = &quot;{proxy+}&quot;<br>}</pre><pre>resource &quot;aws_api_gateway_method&quot; &quot;method&quot; {<br>  rest_api_id   = &quot;${aws_api_gateway_rest_api.api.id}&quot;<br>  resource_id   = &quot;${aws_api_gateway_resource.resource.id}&quot;<br>  http_method   = &quot;ANY&quot;<br>  authorization = &quot;NONE&quot;</pre><pre>  request_parameters = {<br>    &quot;method.request.path.proxy&quot; = true<br>  }<br>}</pre><pre>resource &quot;aws_api_gateway_integration&quot; &quot;integration&quot; {<br>  rest_api_id = &quot;${aws_api_gateway_rest_api.api.id}&quot;<br>  resource_id = &quot;${aws_api_gateway_resource.resource.id}&quot;<br>  http_method = &quot;${aws_api_gateway_method.method.http_method}&quot;</pre><pre>  integration_http_method = &quot;ANY&quot;<br>  type                    = &quot;HTTP_PROXY&quot;<br>  uri                     = &quot;http://your.domain.com/{proxy}&quot;<br> <br>  request_parameters =  {<br>    &quot;integration.request.path.proxy&quot; = &quot;method.request.path.proxy&quot;<br>  }</pre><pre>}</pre><p>Let’s do this in small steps so it’s clearer what is happening here.</p><h3><a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_resource.html"><strong>Resource</strong></a></h3><p>This is where we’ll configure on what endpoint are we listening for requests. The <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_resource.html#path_part">path_part</a> argument will contain a string that represents the endpoint path, as our case is a simple proxy, AWS provides a special handler to listen all the requests, the &quot;{proxy+}&quot;. This handler can also be applied to a more specific path, i.e &quot;users/{proxy+}&quot; where it will listen to anything starting with users ( i.e users/1/posts , users/3/notes , etc). The other values presented in there are related to where will this resource be applied, the <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_resource.html#rest_api_id">rest_api_id</a> will have the id of what API we are mounting this resource and the <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_resource.html#parent_id">parent_id</a> has the id of the parent on where are mounting this. This last one can be mounted directly on the root api (as we have) or mounted in another resource making it a child resource that will be composed by both parent and child. So if you have the path_part defined as &quot;active&quot; in the child resource and it’s mounted in the users resource, the child resource will listen to a users/active endpoint.</p><h3><a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_method.html">Method</a></h3><p>In the method resource is were we build the specification of the endpoint we are listening. The <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_method.html#http_method">http_method</a> argument will have the string with what HTTP method we’re interested, the &quot;ANY&quot; value is, again, a special handler where we’ll accept any HTTP method that comes our way. In the case we have in hands we won’t need any authorization done in our AWS API Gateway, and that’s why the value in <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_method.html#authorization">authorization</a> is &quot;NONE&quot; . The <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_method.html#request_parameters">request_parameters</a> argument, will state that we will have something in a proxy handler required for this method and that will passed to the integration resource (described next).This resource also has some arguments related to where it should be mounted, namely the rest_api_id that is the same as the one described in the Resource resource and the resource_id that represents to what resource it should be related to.</p><h3><a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_integration.html">Integration</a></h3><p>The integration resource is related to how are we going to react to the request that we just received, it could go from passing the request to a backend, run some lambda function or even doing nothing with it. Besides the arguments previously referenced ( rest_api_id and resource_id ), we have the http_method argument that will be the same as the method resource (that’s why we link both of them with the &quot;${aws_api_gateway_method.method.http_method}&quot; ), the <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_integration.html#integration_http_method">integration_http_method</a> argument represents the HTTP method that will be done from the integration to our backend (again the &quot;ANY&quot; value is a special one) and we have the <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_integration.html#type">type</a> argument where we configure what type of integration this is. As for the uri argument it will contain the endpoint to where we are proxying to, and the <a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_integration.html#request_parameters">request_paramenters</a> argument will map what we need from the method resource to our request to the backend, in our case we are are replacing the {proxy} handler present in the uri argument with the path that comes after the domain of our API Gateway.</p><p>The way that all of this can be grouped together is that a method and a integration are wrapped around a resource, the method will be responsible on how can the API Gateway be reached and the integration will be responsible in interacting with the backend. Kinda like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0ujDHUPajrqRTn85fsYSg.png" /><figcaption>How I understand all works</figcaption></figure><p>So with all this we’ll be able to apply this Terraform file and (hopefully) have our first AWS API Gateway all working!! 🎉 If we go to https://api-gateway.execute-api.<em>{region}.</em>amazonaws.com<em> </em>(the {region} is the region where you’ll deploy the API, i.e eu-west-1)<em> </em>we’ll be communicating with our API Gateway. But there’s something still bugging you, right? Do we really want to tell the our costumers to make requests to that URI? They’ll probably think it’s a scam..</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F11012853&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fbitconnect-carlos-carlosmatos-scam-crypto-gif-11012853&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2F01ee3be07a1198870c658b86f4a3899f%2Ftenor.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7938feed92843348aaacd0bc4a7326a9/href">https://medium.com/media/7938feed92843348aaacd0bc4a7326a9/href</a></iframe><p>Rest at ease because AWS have it covered, and so does Terraform. To accomplish that we need to add two resources to our file:</p><pre>resource &quot;aws_api_gateway_domain_name&quot; &quot;domain&quot; {</pre><pre>  domain_name = &quot;totallynotascam.com&quot;</pre><pre>  certificate_name <strong>=</strong> &quot;example-api&quot;</pre><pre>  certificate_body <strong>= &quot;</strong>${file(&quot;${path.<strong>module</strong>}<strong>/</strong>example.<strong>com/</strong>example.<strong>crt</strong>&quot;)}&quot;</pre><pre>  certificate_chain <strong>=</strong> &quot;${file(&quot;${path.<strong>module</strong>}<strong>/</strong>example.<strong>com/</strong>ca.<strong>crt</strong>&quot;)}&quot;</pre><pre>  certificate_private_key <strong>= </strong>&quot;${file(&quot;${path.<strong>module</strong>}<strong>/</strong>example.<strong>com/</strong>example.<strong>key</strong>&quot;)}&quot;  <br>}</pre><pre>resource &quot;aws_api_gateway_base_path_mapping&quot; &quot;base_path_mapping&quot; {<br>  api_id      = &quot;${aws_api_gateway_rest_api.api.id}&quot;<br>  <br>  domain_name = &quot;${aws_api_gateway_domain_name.domain.domain_name}&quot;<br>}</pre><h3><a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_domain_name.html">Domain</a></h3><p>Here is where we’ll create the configuration to the domain that we have. The domain_name attribute will have the string with the name that we want for our domain, the other attributes are all optional and just an example on how you can have the certificates to that domain. As stated in the Terraform documentation about this resource this is not the way of doing it, because it will store that information in clear text.</p><h3><a href="https://www.terraform.io/docs/providers/aws/r/api_gateway_base_path_mapping.html">Base_path_mapping</a></h3><p>There isn’t much to say about this resource, it’s purpose it’s only to map the domain configuration to our API. So the api_id will have the in for our API Gateway and the domain_name links to the domain domain name that we had chosen previously.</p><p>Having this all in place we’ll be able to reach https://totallynotascam.com and send all the money that the Nigerian prince is always asking 😄.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*0p7ffSOCL9TwiBOQXhr5XA.gif" /></figure><p>As usual if you find this useful smash that 👏 button, and if you have anything to say just leave a comment or drop it like it’s hot <a href="https://twitter.com/RicBrazao">@RicBrazao</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a2bebe8b68f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/onfido-tech/aws-api-gateway-with-terraform-7a2bebe8b68f">AWS API Gateway with Terraform</a> was originally published in <a href="https://medium.com/onfido-tech">Onfido Product and Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby superpowers — with great power comes a great prepend]]></title>
            <link>https://medium.com/onfido-tech/ruby-superpowers-with-great-power-comes-a-great-prepend-6c1ccd2a7205?source=rss-a7688269ba77------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c1ccd2a7205</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Ricardo Brazão]]></dc:creator>
            <pubDate>Wed, 15 Feb 2017 17:32:01 GMT</pubDate>
            <atom:updated>2017-05-04T09:09:04.021Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6d-HZ7Z2_m2vOZvxOLJvOg.jpeg" /></figure><p>You were walking into a science experiments lab, when suddenly you’re bitten by a radioactive spider. The next day you wake up feeling weird until you realised you’re given superpowers by that bite. You could control the way you position yourself in your hierarchical family tree! So you could make yourself your father’s father (basically your grandfather…), isn’t that amazing?!?</p><p>Well that’s not a real superpower, but that’s what happens when you use the ruby prepend method when handling a modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*k61V46wgYDc9sdE_OF3GhA.jpeg" /><figcaption>Wait…</figcaption></figure><p>One of the first things that we learn in ruby is that everything inherits from Object , and that’s totally true but the caveat here is what lies between our class and Object . Lets see the following code:</p><pre>class SomeClass<br>end</pre><pre>SomeClass.ancestors<br> =&gt; [SomeClass, Object, Kernel, BasicObject]</pre><p>With this example we prove that our previous assumption was right. But what will happen when we add a module to that class?</p><pre>module SomeModule<br>end</pre><pre>class SomeClass<br>  include SomeModule<br>end</pre><p>Will the hierarchy change? Where will the module be? So this is how the hierarchy looks like:</p><pre>SomeClass.ancestors<br> =&gt; [SomeClass, SomeModule, Object, Kernel, BasicObject]</pre><p>As you can see SomeModule will be placed between the class and the Object. This is all good until you have some requirements for that module that include doing something before the class, or even surround a call to a function in the class with some behaviour from the module.</p><p>Wait, I’m here to read about the prepend why are you still writing about the include? Well, we’ll get to the prepend in a moment, but for you to understand in what scenarios the prepend comes in hard for the kill, I’ll show you how things were done before it appeared.</p><p>Say we have the following class:</p><pre>class George<br>  def talk<br>    &quot;I&#39;m George.&quot;<br>  end<br>end</pre><p>To make George talk (without having to wire him to a car battery 😱) we just need to call George.new.talk and it would talk back just I’m George.. This is all good but it’s not very polite, is it? Lets create a module that will bring some politeness into this world.</p><pre>module Politizer<br>  def talk<br>    &quot;Hello. #{super}. How are you today?&quot;<br>  end<br>end</pre><p>Now lets make George more polite.</p><pre># Making George polite</pre><pre>George.include(Politizer)</pre><pre>george = George.new</pre><pre>george.talk # =&gt; &quot;I&#39;m George.&quot;</pre><p>But…but…I’ve made you more polite with my Politizer , what happened in here?! Well, as you must’ve guessed, we are not reaching the talk method that we redefine in the module due to it’s hierarchy:</p><pre>=&gt; [George, Politizer, Object, Kernel, BasicObject]</pre><p>So what can we do if the include will always add the module’s methods behind the class itself? To achieve that, we’ll need to use the alias_method method with a little magic.</p><p>Modules have a callback that is called when they are included, so we will work with that to achieve great things! That said, lets change our Politizer and make George polite.</p><pre>module Politizer<br>  def self.included(base)<br>    base.class_eval do<br>      alias_method :talk_without_polite, :talk<br>      alias_method :talk, :talk_with_polite<br>    end<br>  end<br>  <br>  def talk_with_polite<br>    &quot;Hello. #{talk_without_polite}. How are you today?&quot;<br>  end<br>end</pre><pre># Making George polite</pre><pre>George.include(Politizer)</pre><pre>george = George.new</pre><pre>george.talk # =&gt; &quot;Hello. I&#39;m George. How are you today?&quot;</pre><p>YEAH! George is now a polite fellow, but that code…damnnn it looks ugly as hell! That is why for these type of situations, in the Rails world, we have a alias_method_chain method that makes things a liiiiiiiiitttle bit better:</p><pre>class George<br>  def talk<br>    &quot;I&#39;m George&quot;<br>  end<br>end</pre><pre>module Politizer<br>  def self.included(base)<br>    base.class_eval do<br>      alias_method_chain :talk, :polite<br>    end<br>  end</pre><pre>  def talk_with_polite<br>    &quot;Hello. #{talk_without_polite}. How are you today?&quot;<br>  end<br>end</pre><pre># Making George polite</pre><pre>George.include(Politizer)</pre><pre>george = George.new</pre><pre>george.talk # =&gt; &quot;Hello. I&#39;m George. How are you today?&quot;</pre><p>But now lets get down to business and talk about the thing you’re here for: the prepend!! So, in ruby 2.0 (yes, I’m a little late to the hype train…) the prepend method was introduced as the saviour for all of the trouble we had to make George more polite.</p><p>With that in mind this is how we could add the Politizer module to George to achieve the behaviour that we want:</p><pre>class George<br>  def talk<br>    &quot;I&#39;m George&quot;<br>  end<br>end</pre><pre>module Politizer<br>  def talk<br>    &quot;Hello. #{super}. How are you today?&quot;<br>  end<br>end</pre><pre># For ruby 2.0<br>George.send(:prepend, Politizer)</pre><pre># For ruby 2.1<br>George.prepend(Politizer)</pre><pre># Making George polite<br>george = George.new<br>george.talk</pre><p>This code is cleaner and more understandable than the previous one, with the include magic, right? So you must be wondering how this works, and what is the difference between include and prepend . The diference is…drum roll…object hierarchy! This is what object hierarchy with the prepend method looks like:</p><pre>George.ancestors<br>=&gt; [Politizer, George, Object, Kernel, BasicObject]<br># George with include<br># =&gt; [George, Politizer, Object, Kernel, BasicObject]</pre><p>You see the diferences, right? So now when we call george.talk we are looking first in the module instead of the class itself, and with the wonders of hierarchies we can call super to call the methods on the parent class itself.</p><p>As usual if you find this useful smash that 💚 button, and if you have anything to say just leave a comment or drop it like it’s hot <a href="https://twitter.com/RicBrazao">@RicBrazao</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c1ccd2a7205" width="1" height="1" alt=""><hr><p><a href="https://medium.com/onfido-tech/ruby-superpowers-with-great-power-comes-a-great-prepend-6c1ccd2a7205">Ruby superpowers — with great power comes a great prepend</a> was originally published in <a href="https://medium.com/onfido-tech">Onfido Product and Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Systematize your database— The Ruby way to be the croupier of migrations.]]></title>
            <link>https://medium.com/hackernoon/systematize-your-database-the-ruby-way-to-be-the-croupier-of-migrations-7c9d56bc628d?source=rss-a7688269ba77------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c9d56bc628d</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[data-migration]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Ricardo Brazão]]></dc:creator>
            <pubDate>Mon, 02 Jan 2017 11:02:00 GMT</pubDate>
            <atom:updated>2019-05-13T10:19:30.041Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how the croupiers do that shuffle when they separate the card deck in two and just mix both piles into one? I’ve tried that multiple times and the cards just flew everywhere 😞. But now imagine that you could do that shuffling with your data and structure migrations, aligning them to run in the order they should…That would be a cool thing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*is15EmLbOlr5DRzvlG8k2w.gif" /></figure><p>While your application starts getting bigger and bigger, probably so does your migration folder and with that you’ll probably need to move some data around different tables, or even change such data because your structure changed as well.</p><p>When do you run your migrations? First the data migrations and then the structure migrations or the other way around?</p><p>With any of those approaches some errors are prone to happen:</p><ul><li>On the first approach (data → structure) what would you do, if the field that you need isn’t created yet (because the structure migration hasn’t run)?</li><li>On the second approach (structure → data) what would you do, if the field that you want to populate needs data from another field that is deleted on the structure migration?</li></ul><p>Let me show you an example:</p><ul><li>Let’s say you have a Post model with a boolean attribute named :deleted that represents the deleted Posts;</li><li>After some time, and some deleted Posts, you are asked to instead of just knowing that a Post was deleted we also need to know when the Post was deleted. So you create the :deleted_at field that will contain the date it was deleted;</li><li>Now you create the data migration that searches all the deleted Posts and timestamps the :deleted_at field. So far so good;</li><li>After that is done you can safely remove the old and obsolete :deleted field.</li></ul><p>So with this example we have 2 structural migrations (creating the :deleted_at field and deleting the :deleted field) and 1 data migration (populating the :deleted_at field). It’s all peachy and dandy until you run your migrations because when you finish running the structural ones you will not have a :deleted field to query the Posts that were deleted.</p><p>With this in mind let me introduce you to <a href="https://github.com/RicardoBrazao/systematize">Systematize</a>, the gem that will make that pain go away.</p><h3>How does it work?</h3><p>Just add it to your Gemfile:</p><pre>#Gemfile<br>gem &#39;systematize&#39;, &#39;~&gt; 0.0.1&#39;</pre><p>or install it via bundler</p><pre>bundle install &#39;systematize&#39;</pre><p>Surprise, surprise you have some shinny new tasks!</p><pre>$&gt; bundle exec rake -T<br>rake systematize:migrate       # Migrate the database<br>rake systematize:rollback      # Rollback the database (options: STEP=x, VERBOSE=false)<br>rake systematize:rollback_all  # Rollback all the database</pre><p>With this your migrations will be re-arranged and they will run in the timespan order to make sure that all goes peachy keen!</p><h3>It’s not all fun and games you know?</h3><p>For this to go smoothly as it should you just need to respect some rules:</p><ul><li>The migrations need to be in the correct folder, for structural migrations it should be db/migrate and the data migrations should live in db/data. Like this:</li></ul><pre>- app<br>  |<br>  |-db<br>    |-data<br>    |-migrate</pre><ul><li>The migrations need to follow the <a href="https://hackernoon.com/tagged/rails">Rails</a> convention YYYYMMDDHHMMSS_create_products.rb</li></ul><h3>Time to shine</h3><p>Now if you need to migrate the <a href="https://hackernoon.com/tagged/database">database</a> you just need to run:</p><pre>bundle exec rake systematize:migrate</pre><p>Needing to rollback the previous migration? No problem.</p><pre>bundle exec rake systematize:rollback</pre><p>Need to rollback 2/3/4 migrations? I got you.</p><pre>bundle exec rake systematize:rollback STEP=2</pre><p>Made a mess so big you need to start fresh? Do it. (the migrations need to be reversible 😅)</p><pre>bundle exec rake systematize:rollback_all</pre><p>Don’t forget to smash that 💚 button and if you have anything to say, just drop like it’s hot <a href="https://twitter.com/RicBrazao">@RicBrazao</a>!</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c9d56bc628d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/systematize-your-database-the-ruby-way-to-be-the-croupier-of-migrations-7c9d56bc628d">Systematize your database— The Ruby way to be the croupier of migrations.</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving to a new company — taking the bull by the horns.]]></title>
            <link>https://medium.com/@ricardobrazao/moving-to-a-new-company-taking-the-bull-by-the-horns-19db41bcdbd0?source=rss-a7688269ba77------2</link>
            <guid isPermaLink="false">https://medium.com/p/19db41bcdbd0</guid>
            <category><![CDATA[life]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[Ricardo Brazão]]></dc:creator>
            <pubDate>Thu, 10 Mar 2016 17:24:13 GMT</pubDate>
            <atom:updated>2016-03-15T10:40:31.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*JeQDIc-t4URh6bUYAHQXaw.jpeg" /></figure><p>Are you sick and tired of your workplace? Don’t like the people you got around you? Or do you simply want to move on? This is when you start looking for the new “<a href="https://en.wikipedia.org/wiki/Atlantis">Atlantis</a>”. Well that’s what happened to me recently, but as I was looking for companies trying to decide what my next step would be, something hit me really hard…the uncertainty of the future.</p><p>With this came the fear that on the other side of the fence the grass wouldn’t be so green, the <a href="https://medium.com/@alexmc/the-imposter-syndrome-215a93dc5b58#.tkeo8045h">imposter syndrome</a>, and all the concerns that make a person be out of breath. But you need to move on, you need to “take the bull by the horns” and take that leap of faith. With this in your mind, I can only show you some guidelines that made my choice easier and made the bull look like a little lamb:</p><ul><li><strong>Culture:</strong> You know what you would like to see in a company, so try to find out about the its culture. Go see the perks that they offer to their employees, try to find some photos or even try to check the surroundings;</li><li><a href="https://www.glassdoor.com/index.htm"><strong>Glassdoor</strong></a><strong>:</strong> Ok, they have table tennis and offer a fully stocked kitchen, but is it really like that? Check the company on glassdoor to see if some employee left a review there, because you never know what hides beneath all the doughnuts;</li><li><strong>Interview:</strong> I know that you’ll be nervous in the interview but try to check if the interviewer is interested in you and he’s not some robot shooting questions. This can be a red flag, because if he’s like a robot then the most likely reason is that he doesn’t like what he’s doing. And one of the reasons for that is… he doesn’t like it there;</li><li><strong>Improvement: </strong>One of worst things about a steady job is comfort zone, so if a company does not support the improvement of their employees it’s a “no no” for me;</li><li><strong>Enroll: </strong>As a software developer I like being involved in all the development cycle of a feature. So from the why it’s needed to the moment it’s handled to me I like to leave some feedback and participate in all the discussions. Why is it important? Because it makes me part of the whole process and not just some monkey pressing buttons.</li></ul><p>After all of this comes the all around important thing, the big bucks. But tell me, do you rather get more money and be around people that make you fell like “why did I get out of bed this morning?” or get a little less money at the end of the month but be around people that make your mondays feel like every other day of the week and arrive at the office with a smile on your face?</p><p>Don’t take this as the Holy Grail of moving to a new job, this is just my personal experience and how I tackled one big problem. There are a number of factors that will influence your decision when the time arises, establish your goals and the choice will be much easier.</p><p>If you have anything to say just leave a comment or hit me up <a href="https://twitter.com/RicBrazao">@RicBrazao</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19db41bcdbd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Amazon S3 and uploading into the cloud]]></title>
            <link>https://medium.com/hackernoon/amazon-s3-and-uploading-into-the-cloud-76a030be6686?source=rss-a7688269ba77------2</link>
            <guid isPermaLink="false">https://medium.com/p/76a030be6686</guid>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Ricardo Brazão]]></dc:creator>
            <pubDate>Sun, 15 Mar 2015 18:56:37 GMT</pubDate>
            <atom:updated>2019-05-13T10:19:13.175Z</atom:updated>
            <content:encoded><![CDATA[<p>In one of our applications we developed the possibility for our users to upload files they wanted to keep a registry of. On the first stage we are storing them in our file system but sooner or later, better sooner than later, as the users upload more and more files we will need to store them in some file system that is specialised in that matter. So with this in mind we came to the conclusion that a good way to go is to upload the files to <a href="https://hackernoon.com/tagged/amazon">Amazon</a> S3. Is this new functionality that this blog post will focus on, but first lets wear a sheep fur and take part in selling Amazon S3 to you.</p><p><strong>Why S3?</strong></p><p>Amazon S3 is designed so the developers don’t have to worry how will they store their data, if it’s going to be secure or if they’ll have enough storage available. With this S3 frees developers from the costs of setting their own object storage solution as well as the cost of <a href="https://hackernoon.com/tagged/maintaining">maintaining</a> and scaling their servers. Now developers can focus their time innovating with the data they have instead of figuring out how to store it.</p><p>Amazon S3 is built to fulfil these design requirements:</p><ul><li>Secure</li></ul><p>It provides the customers full control over who has access to their data. To the customers is also given the possibility to secure his data in transit and at rest.</p><ul><li>Reliable</li></ul><p>You can store data with 99.999999999% durability and 99.99% availability. All failures in the system must be tolerated or repaired without any downtime.</p><ul><li>Scalable</li></ul><p>Amazon S3 can scale in different forms. You can scale in terms of storage, request rates and users.</p><ul><li>Fast</li></ul><p>It must fast enough that the server-side latency must be insignificant compared with internet latency.</p><p>One of the most important design matter is that Amazon S3 must support all the functional requests of both Amazon internal applications and the external developers application of any kind. With this objective it means that it has to be fast enough and reliable enough to run Amazon’s websites, while flexible enough that any developer can use it for any data storage needed.</p><p><strong>Some specifications</strong></p><p>In Amazon S3 you can store objects from 1 byte to 5 terabytes of data and you can store an unlimited number of said objects. In where you store object is called a bucket, from this bucket you can only retrieve objects via an unique, developer-assigned key. A bucket can be stored in several regions across the globe, so you can choose the region that fits you the most to optimise latency and minimise costs.</p><p>Amazon provides authentication mechanisms to ensure that your data is secure from unauthorised access, you can make an objects private or public and even grant or revoke rights to the objects to specific users.</p><p>You have the option to make uploads or downloads form Amazon in a secure channel and also you can encrypt your data as an additional protection. For developers Amazon S3 uses REST and SOAP standards so it can work with any internet development kit.</p><p>OK, now that we talked a little about the insides of the S3 lets watch some kittens try to catch a red dot…ahahahahahahah damn cats. Ups sorry got distracted there, where were we? Oh yes…So now we’re gonna protect your data.</p><p><strong>Protecting your data</strong></p><p>In Amazon S3 only the bucket and object owner have access to the data they create, it supports multiple access control mechanisms and encryption for both a secure transit and a secure storage on disk. You have several mechanisms where you can control who can access your data, as well as how, when and even where they can access it. In Amazon S3 you have four different access control mechanisms:</p><ul><li>Identity and Access Management (IAM)</li></ul><p>With this mechanism an organisation with several employees is able to create and manage multiple users under a single AWS account. Having this mechanism you can grant users fine-grained control to your Amazon S3 bucket or objects.</p><ul><li>Access Control Lists (ACLs)</li></ul><p>This mechanism is used to grant certain permissions on individual objects.</p><ul><li>Bucket policies</li></ul><p>Bucket policies are used to add or deny permissions to a certain bucket applying them to all or just certain objects within that bucket.</p><ul><li>Query string authentication</li></ul><p>Having this mechanism will make the URLs that you share valid only for a predefined expiration time.</p><p>After you secured the access to your data you’ll probably want to secure the communication between you and Amazon S3, to do this you can make your requests to upload/download files via the SSL encrypted endpoints using the HTTPS protocol. As an additional measure of security you can use Amazon S3 to manage the encryption and decryption of data, if you prefer that Amazon S3 manage your encryption keys you can use Amazon S3 Server Side Encryption (SSE). On the contrary if you like to manage your own encryption keys, you can use the Amazon S3 Server Side Encryption with Customer-Provided Keys (SSE-C). In both options Amazon S3 will encrypt your data on write and will decrypt your data on retrieval.</p><p>And with this we end the selling part, so let’s get our gads dirty with some code!</p><p><strong>Uploading to Amazon S3</strong></p><p>When we started to search how are the uploads made to Amazon S3, we discover a Railscasts video (“Episode 383 — Uploading to Amazon S3”) where the author did exactly that but he was using the carrierwave gem to do the upload of the files, we use the dropzone javascript plugin with the paperclip gem to do the image processing part. Even so we used a helper that Ryan Bates created to help with the form to do the upload.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e22bdc32c325dc6547377eb85f500a5f/href">https://medium.com/media/e22bdc32c325dc6547377eb85f500a5f/href</a></iframe><p>The fields that matter for Amazon S3 are the ones in the ‘fields’ method, these ones are placed within the form as hidden fields that Amazon S3 will use to verify, process and respond to your request. They are as follows:</p><ul><li>acl</li></ul><p>This field represent the ACL mechanism for your objects.</p><ul><li>policy</li></ul><p>The policy field is a encrypted hash in which the fields that compose it represent some restrictions to be applied to the request that is going to be made. For example you have the expiration field that indicates for how many time is that form valid to make the requests.</p><ul><li>bucket</li></ul><p>Identifies in which bucket is the request going to be made.</p><ul><li>success_action_status</li></ul><p>Represents the HTTP Status code that is going to be used in the response.</p><ul><li>key</li></ul><p>In here you specify the path in where the file is going to be stored.</p><p>You can use this helper by simply doing this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/533c347f4a80078833efe683b441b5da/href">https://medium.com/media/533c347f4a80078833efe683b441b5da/href</a></iframe><p>One thing to have in mind is that you’ll need to configure your Amazon S3 bucket with the right CORS configuration to be able to make requests against that bucket. One example of said configuration is stated bellow.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea56756543ce9925990840814526c762/href">https://medium.com/media/ea56756543ce9925990840814526c762/href</a></iframe><p>After you successfully uploaded your files to Amazon S3, you may want to access your bucket and object directly from your code. For this you have the ‘aws-sdk’ gem, an example of usage of it is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5769f4fc7b83476b354fc42dbda493d/href">https://medium.com/media/f5769f4fc7b83476b354fc42dbda493d/href</a></iframe><p>As you can see with this gem you can easily make operations in your buckets, such as delete your objects or copy your object from a path to other.</p><p>Well that wasn’t that hard was it ? With this simple introduction you’ll be able to upload your files to Amazon S3 and you can proudly say that you’re using the cloud.</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><a href="https://goo.gl/Ahtev1"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76a030be6686" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/amazon-s3-and-uploading-into-the-cloud-76a030be6686">Amazon S3 and uploading into the cloud</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>