<?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 António Fernandes on Medium]]></title>
        <description><![CDATA[Stories by António Fernandes on Medium]]></description>
        <link>https://medium.com/@tofernandes67?source=rss-301e86277135------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*k-ZdY7mE3n-rrnY85fQAIA.jpeg</url>
            <title>Stories by António Fernandes on Medium</title>
            <link>https://medium.com/@tofernandes67?source=rss-301e86277135------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 18:43:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tofernandes67/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[Selection Sort Algorithm]]></title>
            <link>https://medium.com/@tofernandes67/selection-sort-algorithm-20943bbdcd7f?source=rss-301e86277135------2</link>
            <guid isPermaLink="false">https://medium.com/p/20943bbdcd7f</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[selection-sort]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[António Fernandes]]></dc:creator>
            <pubDate>Wed, 15 Jul 2020 10:48:40 GMT</pubDate>
            <atom:updated>2020-07-15T10:48:40.810Z</atom:updated>
            <content:encoded><![CDATA[<p>Selection Sort Algorithm is one of the simplest sorting algorithms.</p><p>The selection sort algorithm sorts by repeatedly finding the minimum element of an array and putting that element at the beginning of the array or pushing it to a new array.</p><h3>Video</h3><p>If you don’t feel like reading, you can watch the video here.</p><p><a href="https://www.youtube.com/watch?v=vgGXklVflsw">https://www.youtube.com/watch?v=vgGXklVflsw</a></p><h3>The unsorted array</h3><p>Let’s imagine that we have an unsorted array like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*fOJc0Z37rko7SL2rgBfeTw.jpeg" /><figcaption>Unsorted array</figcaption></figure><p>Now, we create an empty array that will always save the minimum value of the unsorted array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*VLFhijzloEcTSKUdkxNn-Q.jpeg" /><figcaption>Sorted Array</figcaption></figure><h3>Starting to push elements to the sorted array</h3><p>We just need to find the minimum value of the unsorted array and push it to the sorted array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*LWzRQxUMkCozBvhwRLQFUw.jpeg" /><figcaption>Unsorted Array</figcaption></figure><p>The minimum value at the unsorted array is 1.</p><p>So we just need to push it to the sorted array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*gXrmfcB0oD8dnn3yFn0cIQ.jpeg" /><figcaption>Sorted Array</figcaption></figure><p>Now we need to change the value of 1 in the unsorted array to the largest possible value in a 32-bit integer.</p><p>After we do this, we do the same thing again, we find the minimum element in the unsorted array, in the second case, it will be 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*CXv_jbiLnRyoExaS9mXSGw.jpeg" /><figcaption>Unsorted Array</figcaption></figure><p>And we push it to the unsorted array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*zrbsfD0dParSYLW_pKetUQ.jpeg" /><figcaption>Sorted Array</figcaption></figure><p>Can you see how the sorted array is already sorted?</p><p>We just need to repeat this process over and over again until we have this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*a46VguCvyI6UEDqYY7gftg.jpeg" /><figcaption>Final result</figcaption></figure><h3>Working with only one array</h3><p>If you want to work with only one array, the same principle applies. For the first iteration(0), we find the minimum element</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*r2FzWTLzmIk1J9gDLfsomw.jpeg" /><figcaption>Minimum element</figcaption></figure><p>And we swap the minimum with the index of the iteration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*PGnUcF_TW5_JbWbCs8-NhQ.jpeg" /><figcaption>Swapping element</figcaption></figure><p>Now we just repeat the same process until we reach the last element of the array.</p><p>The final result will be this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*AzG9t8_46bexqCC3LZD8Dg.jpeg" /><figcaption>Sorted Array</figcaption></figure><h3><em>The Code</em></h3><pre>def selection_sort(a)<br>  n = a.length<br> <br>  for i in 0...n<br>    min = i<br>    for j in (i+1)...n<br>      if a[j]&lt;a[min]<br>        temp =a[j]<br>        a[j]=a[min]<br>        a[min] = temp<br>      end<br>    end<br>  end<br>  return a<br> end<br> <br> print(selection_sort([5,3,1,8,0]))</pre><p>Hope you find this useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20943bbdcd7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JornalApp or How Microverse Improved my Girlfriend Life]]></title>
            <link>https://medium.com/@tofernandes67/jornalapp-or-how-microverse-improved-my-girlfriend-life-1f8eb7735a85?source=rss-301e86277135------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f8eb7735a85</guid>
            <category><![CDATA[humor]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[life]]></category>
            <dc:creator><![CDATA[António Fernandes]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 22:15:46 GMT</pubDate>
            <atom:updated>2020-07-20T11:07:31.942Z</atom:updated>
            <content:encoded><![CDATA[<h3>JornalApp</h3><p>My girlfriend is a TV reporter and she writes for a national newspaper. I am trying to become a developer and also struggling with rails. So how do these two things match?</p><p>Let me tell you how is a day of a Reporter:</p><p>Day of a reporter:</p><p><strong>8:00 AM</strong> — Get up.</p><p><strong>8:05</strong> — Check the website for traumas or accidents while in the bathroom.</p><p><strong>8:06</strong> — this website does not work on mobile.</p><p><strong>8:10</strong> — Turn on the computer and check if there was an accident or so that should make it to the news.</p><p><strong>8:20</strong> — The website is large and a mess, better call them and see if I missed something.</p><p><strong>8:25</strong> — Call the Civil Protection.</p><p>“Hello I am António Fernandes girlfriend and I work for the national tv news, was there some occurrence important this night?”</p><p>“No. only a car crash but nothing to worry about”</p><p><strong>8:30</strong>- thinking: How do I miss this car crash?</p><p><strong>8:31</strong> — Let me check the website to see if there are any trials in the courthouse.</p><p><strong>8:32</strong>- Hmmm. District of Bragança.</p><p><strong>9:00</strong> — Oh my god the courthouses are not organized by district.</p><p><strong>9:30 </strong>— Check the website for traumas or accidents.</p><p><strong>10:30</strong> — I finished the check for those 6 courthouses nothing big today. At least nothing that I have seen on that messy table.</p><p><strong>10:30</strong>- Check the website for traumas or accidents.</p><p><strong>10:40</strong> — Breakfast</p><p><strong>11:00</strong>- Check the website for traumas or accidents.</p><p><strong>11:30</strong> — Receiving a phone call.</p><p>“Hi, do you go to the trial today on Vila Flor Courthouse? “</p><p>“oh… hmmm. yes, sure. See you there”</p><p><strong>11:31</strong>- How do I miss that trial??</p><p><strong>11:35</strong> — Check the website for traumas or accidents.</p><p><strong>11:45</strong> — Going to take a coffee with my boyfriend.</p><p><strong>11:50</strong> — Firefighter car passes by.</p><p><strong>11:51</strong> — Need to go home and check the website to see if it is something bad (because the website does not work on mobile).</p><p>(Repeat all of this)</p><p>Ufff. It’s only noon and I am already tired.</p><p>What if…</p><p>What if I can do a Rails app?</p><p>For what?</p><p>For my girlfriend to use.</p><p>Cool an app for just one person.</p><p>Not just one person, I am struggling with rails, and since there are no apps for this I could do one to solve her problems and to learn rails. So actually is an App for two.</p><p>Solving problems.</p><p>What should this application do?</p><p>First of all, it needs to be responsive!</p><p>Scrap the website and show a table with traumas, accidents, and wildfires.</p><p>Organize the data by districts.</p><p>Do you know what would be cool? If I implemented some notifications systems for suspicious occurrences. (yeah right)</p><p>She has limited chars when writing to a newspaper, what if I put a text box that counted the chars (real-time).</p><p>And save the articles so she can view them later and edit them, and copy them and send to her editor. hmm, that’s cool.</p><p>And scrap al the courthouses showing the trials in an organized way.</p><p>And it would be nice if she could add them to her Gcal. (oh my god)</p><p>Now, I have many tasks to do. But do I know how to do any of those things? Well, thanks to microverse I do know how to do some of them but, I don’t know how to do the most part. But thanks to microverse too, I do know how to study it and I know the basics to get me started and start to solve one problem at a time.</p><p>1- <a href="https://medium.com/@tofernandes67/building-the-application-and-start-scrapping-rails-3ef60385b4f1">Building the Application and Scrapping a Website</a></p><p>2 — <a href="https://medium.com/@tofernandes67/building-the-application-and-start-scrapping-rails-3ef60385b4f1">Showing Tables on Desktop and Mobile</a></p><p>3 — The problem with Tables on Mobile</p><p>4 — Making it a PWA</p><p>5 — Push Notifications on a Rails Application</p><p>6 — Counting chars of a Text Box.</p><p>Right on this point, I’ve got asked to share this application with some co-workers of my girlfriend from other newspapers, and radio stations so I needed to do a Login system.</p><p>7- Login System</p><p>8 — Implementing Login, Register with Devise.</p><p>9 — Saving the written Articles.</p><p>10 — Scrap through courthouses and present them to the website.</p><p>11 — Scrap through Facebook Events and present them. (I don’t know if you tried to search for some events that you could be interested without knowing the city or the exact place or day. But is one of the hardest things)</p><p>TODO:</p><p>12 — Make it like a social network where reporters could share information although usually, they are not a sharing kind of people (only with the news).</p><p>13 — Connection with Gcal.</p><p>14 — Connection with stripe, just in case somebody wants to buy me a coffee :-)</p><p>A day of a reporter now:</p><p><strong>8:00 AM</strong> — Get up</p><p><strong>8:05</strong> <strong>AM</strong>- Check the <strong>JornalApp</strong> for traumas, accidents, and trials while in the bathroom, and oh I have 3 car crashes notifications.</p><p><strong>8:15 AM — </strong>Added trials to my calendar, and there was 3 car crashes tonight. 2 of them had only 1 ambulance so they are probably minor injuries. but there is one with 9 ambulances, better make a call<strong>.</strong></p><p><strong>8:16 AM- </strong>“Hello I am António Fernandes’s girlfriend and I work for the national tv news, the car crash at 3 AM on National Road — 235 was something serious?”</p><p>“It was a false alarm lady”**Confused because she had the exact location (I could grab the coordinates from a JSON that I was able to scrap, and thanks to geocoder gem, I am giving more information than the actual site)</p><p>“Thank God, better this way.”</p><p><strong>8:20 AM — </strong>Breakfast.</p><p><strong>9:00 AM — </strong>Coffe with my boyfriend</p><p><strong>9:05 AM — </strong>A fire Truck. Let me check on my phone what happened. Oh let it be if it is something serious, I will get a notification.</p><p><strong>END</strong></p><p>Here are some images of the work in progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XXF7Cl7uAJewlxX6c3DHzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hpCaAmkztB7vWcTZnnTS3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YyXzFn4UWVfSjIdVTtIj6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*g3Lm3Yh56EdkoSKskJ3vHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*tazPybpY2TIB84zkulTjLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eENAPrpw8liASYshBAQY3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNJa_tjOIhUPSw2jZEkaGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yiYq31andw47B84t-kshaw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f8eb7735a85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building the application and start Scrapping — rails]]></title>
            <link>https://medium.com/@tofernandes67/building-the-application-and-start-scrapping-rails-3ef60385b4f1?source=rss-301e86277135------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ef60385b4f1</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[scrap]]></category>
            <dc:creator><![CDATA[António Fernandes]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 22:13:14 GMT</pubDate>
            <atom:updated>2019-10-16T22:24:04.629Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building the application and start Scrapping — rails</h3><p><a href="https://medium.com/@tofernandes67/jornalapp-or-how-microverse-improved-my-girlfriend-life-1f8eb7735a85">Why I built this project</a></p><p>So first things first. To get started, with this application, I need to learn how to scrap a website.</p><p>I need to have a target, which I do, I need to scrape through the presented table and I need to present the data on my website.</p><p>This is only a story about the difficulties that I have encountered building the <a href="https://medium.com/@tofernandes67/jornalapp-or-how-microverse-improved-my-girlfriend-life-1f8eb7735a85">JornalAPP</a> so if you want the Technical stuff, go directly to the article that I wrote that is. <a href="https://medium.com/@tofernandes67/one-easy-way-to-scrap-a-website-with-rails-f59bc9350a4d">One (easy) way to scrap a website with rails.</a></p><h3>The Target</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ZCcXIM2UBFsSPDOv12XJQ.png" /></figure><p>This is the target website. I need to scrape through him and get all his data. Keep in mind that this website does not work on mobile.</p><h3>The objective</h3><p>Show the data table on my website.</p><h3>The steps</h3><p>There are a lot of online tutorials, all teaching methods to scrape through a website. But I went with Nokogiri, again if you want to know more about this, <a href="https://medium.com/@tofernandes67/one-easy-way-to-scrap-a-website-with-rails-f59bc9350a4d">read the other article</a>.</p><p><strong>Step 1 </strong>— Making a connection with the website and see all his contents.</p><p>So I had my rails in place, for the layout I just used the one from the rails tutorial. I put the file in place and I got this from the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbywcKIXT4Q795NP_G0n2g.png" /></figure><p>Yeah, that error but why?</p><p>I don’t know, I lost 4 hours trying to figure it out but no success, I could scrap other websites, but not this.</p><p>After some searching, I found that it was because the content was generated dynamically via javascript.</p><p>Now that I know why this was happening, I could find for an answer, I have worked a lot and finally, I could find the answer.</p><p>I used Postman, a free tool that makes everything easier.</p><p>After that, I had my HTML file in place so I can start start the scrapping with the help of Nokogiri.</p><p>In the end, I got this result and I am happy with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xb1ubDZmBFwWAd7_QwD6kQ.png" /></figure><p>The problem is with mobile, the mobile looks like this:</p><p>Although is better than the original, I think that I should make it even better. That was a problem that I already solved, but we have so many ways that I will write another article about that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*x55oOT-kE_EsT-IlPUjU0Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ef60385b4f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One (easy) way to scrap a website with rails]]></title>
            <link>https://medium.com/@tofernandes67/one-easy-way-to-scrap-a-website-with-rails-f59bc9350a4d?source=rss-301e86277135------2</link>
            <guid isPermaLink="false">https://medium.com/p/f59bc9350a4d</guid>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[António Fernandes]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 20:47:10 GMT</pubDate>
            <atom:updated>2019-10-16T20:52:35.479Z</atom:updated>
            <content:encoded><![CDATA[<p>I know it’s 2019 but there are still websites that do not provide an API.</p><p>Occasionally you may want to scrap data from another website and display it on your rails application.<br>Here is a tutorial on how to do it.</p><p>First thing first, you want to generate your application. So write on your terminal.</p><pre>rails new app</pre><p>Then</p><pre>bundle install</pre><p>After that, you need to generate the controller and views,</p><pre>rails generate static_pages index</pre><p>After you run that command it will automatically generate the controller and views for static pages.</p><p>Here is the controller</p><p><strong>Warning: </strong>I do use VIM and I love it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*43_yqdyU-4VgBvWaTHfrTw.png" /></figure><p>Here is the view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*oX_vwXJbLzVxvphvghl1rQ.png" /><figcaption>Static pages Index view</figcaption></figure><p>After this, we need to change the routes so we can see our table, and I promise that we will start getting our hands dirty after this. But first write in your routes file.</p><pre>root ‘static_pages#index’</pre><h3>Getting your Hands Dirty</h3><p>You probably already know your target but for the sake of this article, I will use a table from the Portuguese soccer league from the website <a href="http://zerozero.pt/">zerozero.pt</a> .</p><p>we have to install the <a href="https://nokogiri.org/tutorials/installing_nokogiri.html">nokogiri gem</a> (if don’t want to read just put “gem ‘nokogiri’ ” on your gem file)and run again.</p><pre>bundle install</pre><p>After that, we are ready to scrap things.</p><p>Write on your static_pages helper.</p><pre>pagetovisit = ‘<a href="https://www.zerozero.pt/edicao.php?id_edicao=135717&#39;">https://www.zerozero.pt/edicao.php?id_edicao=135717&#39;</a><br> content = open(pagetovisit).read<br> html_doc = Nokogiri::HTML(content)</pre><pre>print html_doc</pre><p>If you run it and check your terminal you will see all the HTML code of our target page.</p><p>But you want to select only the rankings table. So, what should you do?</p><p>You want to check for a unique identifier, if you check the image, you can easily see that in this case, I will use the class zztable but you can use an id or any other thing, just use your developer tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKHFxcP1Eqrhl0Vo7PAQow.png" /></figure><p>Your helper should look like this now:</p><pre>pagetovisit = ‘<a href="https://www.zerozero.pt/edicao.php?id_edicao=135717&#39;">https://www.zerozero.pt/edicao.php?id_edicao=135717&#39;</a><br> content = open(pagetovisit).read<br> html_doc = Nokogiri::HTML(content)</pre><pre>table = html_doc.css(‘table.zztable’)<br> data = []<br>print table</pre><p>You can see that now, we have all the HTML from the table, we will now start saving all the information that we want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oNKlTBsNAoL7UnZmYzDv4Q.png" /></figure><p>Now we grab the rows, we know that the rows are a &lt;tr&gt; so that becomes easy.</p><pre>rows = table.css(‘tr’)</pre><p>Your helper looks like this now.</p><pre>pagetovisit = ‘<a href="https://www.zerozero.pt/edicao.php?id_edicao=135717&#39;">https://www.zerozero.pt/edicao.php?id_edicao=135717&#39;</a><br> content = open(pagetovisit).read<br> html_doc = Nokogiri::HTML(content)</pre><pre>table = html_doc.css(‘table.zztable’)<br> data = []<br> rows = table.css(‘tr’)</pre><p>After that, if we want we can save the rows on an array for display later. Supposing that we want, the team name, the games won, the lost games and the total points, we want to save the rows 3 , 6 ,8 ,4.</p><pre>rows.map do |row|<br> data.push([row.at_css(‘td:nth-child(3)’).try(:text), row.at_css(‘td:nth-child(6)’).try(:text), row.at_css(‘td:nth-child(8)’).try(:text), row.at_css(‘td:nth-child(4)’).try(:text)])<br> end</pre><p>I use the try(:text), because if there is something that is nill and not text, it won’t throw an error, and since I will return the array.compact, it does not matters for this example.</p><p>Your full helper should look like this now. Please pay attention to the headers on the bottom, because we will use that on the view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b1f2b6cbcfac57a7ae83e9185938f5f/href">https://medium.com/media/1b1f2b6cbcfac57a7ae83e9185938f5f/href</a></iframe><h3>Passing the scrapped data to the view</h3><p>Just do what you want with the code. I made a simple table, you are free to style it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35a6efe35337ae2ea04f4f27e29c75a8/href">https://medium.com/media/35a6efe35337ae2ea04f4f27e29c75a8/href</a></iframe><h3>Final Result</h3><p>This is how it all looks. If you are trying to scrap a website with dynamic generated content by JS it’s a little more difficult, but in the end it all goes the same way.</p><p>Have fun scraping websites.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFXL3OrdCps5iWwkbMQ_1A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f59bc9350a4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Save time using SASS to create classes with variations]]></title>
            <link>https://medium.com/@tofernandes67/save-time-using-sass-to-create-classes-with-variations-95aaf4101eb8?source=rss-301e86277135------2</link>
            <guid isPermaLink="false">https://medium.com/p/95aaf4101eb8</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[sass]]></category>
            <dc:creator><![CDATA[António Fernandes]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 17:48:52 GMT</pubDate>
            <atom:updated>2019-10-17T01:54:15.103Z</atom:updated>
            <content:encoded><![CDATA[<p>Last week, I had a problem.</p><p>I needed to define a class in HTML that would give me the margin according to the last char. But this last char wasn’t always the same, nor the place was the margin would be applied.</p><p>I wanted a class that would be margin-top-1, or bottom,or left or right and the last number would go from 1 to 5 rem.</p><p>I was using SCSS already but, I didn’t know how to do it.</p><p>God knows that I searched for an answer, but still could not find how that should be done.</p><p>Maybe I googled it wrong but I know the answer now, and I was not limited to the margin.</p><p>Now I use this everywhere.</p><p>Let’s see how I’ve done it.</p><p>How to save your time using SASS to create classes with variations.</p><p>We have all been there. We need to create a class with different variations so that we can use them in HTML. Although SCSS can save us a lot of work, it is still repetitive, it’s still boring.</p><p>Sometimes the best way to avoid repetitive tasks is by doing a repetitive function.</p><p>How? You ask.</p><p>Through a @for directive.</p><p>So let’s say that you need to define a CSS class to use in your HTML with some variables. Let’s say you wanted to define the class margin-(number) and the number would be the value in rem. Something like this:</p><figure><img alt="Defining margin in CSS" src="https://cdn-images-1.medium.com/max/852/1*bmrkMg4aP80Y4bBAVnKEMg.png" /></figure><p>Well if you only wanted to define .margin-1 there is no need to make a loop. You can simply write it like this but, let’s say for the sake of this article that you would want to define margin all the way to the 100rem. That is the beauty of SAAS.</p><p>You can define a starting point, an ending point and a @for directive to iterate through the numbers.</p><p>So, let’s see how does it look!</p><figure><img alt="Defining classes with variables in SCSS" src="https://cdn-images-1.medium.com/max/852/1*w7TAujXQgb5IxKCXwDDStg.png" /></figure><p>And that’s it. after you compile it, it’s like if you have written 300 + lines of code.</p><figure><img alt="Classes defined in CSS" src="https://cdn-images-1.medium.com/max/852/1*VpEaUm9q0wbaXaYsWP16rQ.png" /></figure><p>And that’s it. after you compile it, it’s like if you have written 300 + lines of code.</p><p>Won’t post the full CSS here because it’s too large,but you get the idea if not open your text editor and try it yourself.</p><p>And now you can use the margin class on your HTML as you like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*7mHZA6ap2o0gL7DLv0O5JQ.png" /></figure><p>But what if I want to define the top or bottom or any other?</p><p>Well, in that case, you should define the variables, and create other classes.</p><p>Still can use the same directive.</p><p>The only difference is that you need to define top, bottom, left, right and auto. But in the end it is the same that we have done above. You can use this for everything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*1TdInSl9Y2NlqMLacKjNKA.png" /></figure><p>Here you go, with approximately 30 lines of code, you have compiled a CSS file with more than 2000 lines.</p><p>And the possibilities are endless, you can use this with almost all attributes, width, height, you name it.</p><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95aaf4101eb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>