<?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 Daniel Eduardo on Medium]]></title>
        <description><![CDATA[Stories by Daniel Eduardo on Medium]]></description>
        <link>https://medium.com/@ccdaniele?source=rss-6ceadbfe6e45------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_5mi0SO-_5Q0cwir.jpeg</url>
            <title>Stories by Daniel Eduardo on Medium</title>
            <link>https://medium.com/@ccdaniele?source=rss-6ceadbfe6e45------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 17:51:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ccdaniele/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[About forms and validations in ruby on rails]]></title>
            <link>https://ccdaniele.medium.com/about-forms-and-validations-in-ruby-on-rails-45315df9676c?source=rss-6ceadbfe6e45------2</link>
            <guid isPermaLink="false">https://medium.com/p/45315df9676c</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[form-validation]]></category>
            <dc:creator><![CDATA[Daniel Eduardo]]></dc:creator>
            <pubDate>Mon, 25 Jan 2021 23:58:08 GMT</pubDate>
            <atom:updated>2021-01-26T14:55:44.223Z</atom:updated>
            <content:encoded><![CDATA[<p>Validations in ruby ​​on rails help us to filter information from a form in order to store it in our database. By correctly validating and setting up our forms, we can ensure that only relevant data is going to be saved.</p><p>An example of this is when you are going to fill out an online form and the page does not allow you to submit the questionnaire until you correctly fill out certain fields, such as not leaving empty spaces, using numbers instead of letters, etc. Imagine that you have created an online casino application and you want to ensure that all underage users cannot have access to it.</p><p>In this case we can create a field where the user has to enter their date of birth. With this we can start to work on the following filters.</p><h4>1. Prevent incomplete information</h4><p>You can create a predefined active records validation <a href="https://guides.rubyonrails.org/active_record_validations.html#presence">presence</a> that prevents the user from continuing in the program until after fully completing the form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*KP-J4bIY4i86QGB01vO6sg.png" /></figure><pre>validates :title, presence: true</pre><p>We’ll see in a minute how these predefined elements work, they are pretty easy and fast to apply in your code.</p><h4>2. Make sure the user is filling out the form correctly</h4><p>Another easy way to keep your database free of wrong or broken data is to display the information through the specified elements in the field, for example in our case using “number_field” which is only going to allow you to insert numbers in that space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*qYkPVs-V97btLHQHEkVCcA.png" /></figure><pre>&lt;label&gt;Price:&lt;/label&gt;&lt;br&gt;</pre><pre>&lt;%= f.number_field :likes %&gt;&lt;br&gt;</pre><h4>3. Be sure that the user knows that it is a website that not allows under legal age people.</h4><p>Unless you develop a whole system with a scanner id that can run as a kind of security guard for your website, the only way to meet the legal requirements for access to this kind of site is by notifying the user that he or she must be over legal age to enter, and having the user declare that they are over legal age by selecting the age in your form.</p><p>Again active records have an excellent option with <a href="https://guides.rubyonrails.org/active_record_validations.html#numericality">numericality</a> (I know this sounds like a kind of Mortal Kombat fatality) which is going to restring the number that the user is typing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*KP-J4bIY4i86QGB01vO6sg.png" /></figure><pre>validates :age, numericality: { greater_than: 21 }</pre><h3>How do we use and where do we insert a validation?</h3><p>There are several places where we can insert validations: in the database, in the view, and in the models.</p><p>Although the validation in the models does not cancel the validation in the database or in the client, in this case we are going to demonstrate how it is more convenient to define the validations in the models.</p><pre>app/models/user.rb</pre><pre>class User &lt; ApplicationRecord</pre><pre>validates :age, numericality: { greater_than: 21 }<br>validates :name, presence: true</pre><pre>end</pre><p>Use predefined active records validation in your code is pretty simple, you just have to insert it into your model and call it from the controller using the “valid?” active record method.</p><h4>When do validations happen?</h4><p>We can usually use “valid?” to call the validations in the model from the controller and ask them if the object meets the requirements to be validated and stored in the database.</p><pre>def create</pre><pre>@user = user.new(blogger_params</pre><pre>if @user.valid?</pre><pre># Here we are calling the validations in the model. If the user information pass the validations is going to be stored in our database</pre><pre>@user.save</pre><pre>redirect_to user_path(@user)</pre><pre>else</pre><pre># if not it is going to render new page with the error message</pre><pre>render :new</pre><pre>end</pre><pre>end</pre><h4>What can we do if the object is not validated?</h4><p>There are several ways to show the model errors in a form. The one that I am going to show next is inserting the following code in the form, which will run only if the program detects that the object has not been validated.</p><pre>% if @user.errors.any? %&gt;</pre><pre>&lt;h2&gt;&lt;%= @user.errors.count %&gt; errors&lt;h2&gt;</pre><pre>&lt;% @user.errors.full_messages.each do |message|%&gt;</pre><pre>&lt;li&gt;&lt;%= message %&gt;&lt;/i&gt;</pre><pre>&lt;% end %&gt;</pre><pre>&lt;% end %&gt;</pre><p>This code is going to run first in your form. <br> If the new page is rendered because the user params wasn’t valid, “<a href="http://twitter.com/user">@user</a>.errors” is going to detect which validations have been activated and will assign the correct error message for it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45315df9676c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Educating a robot]]></title>
            <link>https://ccdaniele.medium.com/educating-a-robot-a3c45015ded3?source=rss-6ceadbfe6e45------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3c45015ded3</guid>
            <dc:creator><![CDATA[Daniel Eduardo]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 15:37:35 GMT</pubDate>
            <atom:updated>2021-01-07T15:37:35.595Z</atom:updated>
            <content:encoded><![CDATA[<p>I grew up thinking that the workings of any technological gadget were magic. Just like how ancient civilizations used to invent gods and myths to explain the natural phenomena around them, I grew up believing in works of the gods like “computers” and myths like “computers are smart and therefore they work.”</p><p>I wasn’t able to see that behind a computer lies code, or more importantly a programmer. However, some doubts did arise such as when the microwave or VHS (I’m old I know) would get disconnected and I’d have to reprogram the time. If the computer god was so smart, why did I have to keep teaching it how to tell time?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YO1ewKthUgdjvzO2RV2ZiQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@lorenzoherrera?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Lorenzo Herrera</a> on <a href="https://unsplash.com/s/photos/retro?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The pursuit of answering that question has led me down an interesting path, and recently to a career change to study programming. The first time I asked that question to an “expert” (an employee at an internet cafe in my hometown), his answer was so complex and convoluted that I thought he must be more lost than I was. Later on, I asked the same question to a friend of my older sister, who threw some sentences together about a “processor” that stored information on a “hard disk” via an “operating system.” Which of course led me to start watching 90’s-era YouTube documentaries to try to learn about how a microchip works, then transistors, punch cards, tubes, until I finally got to binary code. At that point I had just about given up, starting to think that I would need a masters of information sciences and a PhD in nuclear physics to finally understand, how does a computer work?</p><p>To continue, I’ll give a high-level, practical summary of how a computer works, and name what for me were the key milestones in getting to where we are today. We’ll delve into the myth of the magic computers and demonstrate that their magic is a product of centuries of evolution of the marvelous human brain all smashed into less than 100 years, culminating in what will probably be the most significant legacy (positive one at least) of our species.</p><h3><strong>1. The language of machines: Binary code</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*lZaGYN7cq5em4hh1.jpg" /></figure><p>Machines understand only in 0’s and 1’s, so the only way to communicate with them is using binary code. Every letter, number, or any other type of information that we want to input to a computer has its own translation into binary.</p><p>For example, the number 37 in binary looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*4_TKbohKPnikDjSR.png" /></figure><p>If we want to write a word in binary, we have to define every letter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/0*b3ia6wcdts0YgUcF.jpg" /><figcaption>instructables.com</figcaption></figure><p>So “Hi” would be:</p><pre>H = 0100 1000 <br>i = 0100 1001</pre><p>Even every color has its own numeric value, so to communicate with a computer which color we want, we would translate that color into binary like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*uak5MIIYVYAlwjEn.jpg" /></figure><pre>Yellow: #FFCC99  <br>F: 0100 0110<br>F: 0100 0110<br>C: 0100 0011<br>C: 0100 0011<br>9: 1001<br>9: 1001</pre><p>Even though modern computers can interpret sounds, at the core those computers still translate that information into 0’s and 1’s to process it.</p><h3>2. Communicating with machines: Electric circuit</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*3SyLa8VCEdQTDxFR.jpg" /><figcaption>The Talking Machine by Clare Briggs. !922</figcaption></figure><p>So how does a computer know what is a 0 and what is a 1? Behind binary code is the electric circuit.</p><p>Imagine that we have a lamp:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qEn_4yxAf5ppFntk43Vd6Q.jpeg" /></figure><h3>Every time we turn it on, that represents a 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*196uPPAjr5V4Z5Wwhj7ojw.jpeg" /></figure><h3>Every time we turn it off, that represents a 0</h3><p>If we want to translate “This it is a parallelepiped” into binary to go through an electric circuit, we have to turn the lamp off and on this many times</p><p>This is the essence of how an electric circuit transmits information, which is the primary function of a chip.</p><p>By turning off and on in particular patterns, it communicates information in a type of morse code that we know as binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1sGCFtLDo2NIO0J6.jpg" /><figcaption>Vacuum tube, the grand parent of the microchip</figcaption></figure><p>If we look at some of the early computers, we can see how their electric circuits were fitted inside large tubes with minimal capacity, which partly explains why in old movies the computers were so big and with flickering lights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*UHfCW2W61_n_XJFx.jpg" /></figure><p>Over the years as the electrical circuits got smaller, we could integrate more pieces into them to process even more information. Now, increasingly smaller and more efficient computers are universalizing access to programming, which in turn creates more people specializing in working with them. In the last few decades we have been able to create ever more complex methodologies, programs, and languages that enable us to reach even more impressive goals.</p><h3>3. Human code vs machine code</h3><p>In the 50’s, programmers used punch cards to indicate to a computer what they wanted it to do. A perforation meant a 1, and a space meant a 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*4fmuaSzpu2X_sePE" /><figcaption>Punched card</figcaption></figure><p>Using this format, if we wanted to know the result of 36772 times 278, we would need a lot of time (and a lot of space) to do the calculation. In 1951, Grace Hopper wrote the first compiler, A-0 . A compiler is a program that turns the language’s statements into 0’s and 1’s for the computer to understand. This lead to faster programming, as the programmer no longer had to do the work by hand.</p><p>This type of innovation saved programmers a lot of time and unified innovation around the ability of computers to process information (Moore’s law). As time passed, operations became more complex, and languages started to contain more methods and functions to condense information to be communicated to machines.</p><p>Lets see what does this simple code:</p><pre>x = 0<br>while x &lt; 5  do <br>  puts &quot;#{x + 3}&quot;<br>x += 1<br>end</pre><p>Ok, lets explain what it is happening here.</p><pre>x = 0   </pre><p>The value of “x” is 0.</p><pre>while x &lt; 5  </pre><p>As long as “x” is less than 5 do the following</p><pre>puts &quot;Hello world&quot; </pre><p>The word “puts” ask for display “Hello word” into the screen</p><pre>x += 1 #Here sum to &quot;x&quot; 1 and the value of &quot;x&quot; is 1<br>end</pre><p>After display the information in the screen, change the value of “x” from 0 to 1</p><p>so the next time “x” will represents 1. The “ends” represents the edge of the loop but the loops is going to be active until the condition x &lt; 5 is true.</p><h3>4. Educating a robot</h3><p>When I finally developed a basic understanding of how computers work, I could understand that computers aren’t super intelligent or magic. They’re just good students who follow the instructions they’re given by human teachers.</p><p>For this reason the human brain continues to be fundamental in the functioning of machines. Despite what we might think, imagination and creativity now more than ever are essential traits of human nature to create more complete technology. Because after all, the calculations can be left to computers.</p><p>As far as programmers — we are all programmers, from 5-year-old me inputting the correct time into the VHS, to a software engineer in Silicon Valley developing an advanced application. All of us, in some form or another, are teachers to computers. The difference only lies in the subject, the complexity, and the level of instruction, just like what happens in a conventional education system. Five-year-old me would be a kindergarten teacher, and the Silicon Valley engineer would be the university professor.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3c45015ded3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>