<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: April Skrine</title>
    <description>The latest articles on DEV Community by April Skrine (@aprilskrine).</description>
    <link>https://dev.to/aprilskrine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F815244%2Fb2c3893b-795f-41e5-be9d-4396434cc004.png</url>
      <title>DEV Community: April Skrine</title>
      <link>https://dev.to/aprilskrine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aprilskrine"/>
    <language>en</language>
    <item>
      <title>Simple, beginner steps: RegEx and strings.</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Fri, 29 Apr 2022 15:43:48 +0000</pubDate>
      <link>https://dev.to/aprilskrine/simple-beginner-steps-regex-and-strings-3epc</link>
      <guid>https://dev.to/aprilskrine/simple-beginner-steps-regex-and-strings-3epc</guid>
      <description>&lt;p&gt;I've been working on learning Regex the past couple days. Regular expressions (RegEx) are used in programming languages to match parts of strings. You create patterns to help you do that matching. Here's my beginner crash course:&lt;/p&gt;

&lt;h2&gt;
  
  
  Define your Regex
&lt;/h2&gt;

&lt;p&gt;Regex is annotated like: &lt;code&gt;/someRegExHere/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So let's say we wanted to find if 'Hello' existed in a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const someString = "Hello, World!"
let ourRegex = /Hello/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've got our string, and we've defined our Regex. There are multiple ways to use regex, but for now I've been using the Javascript &lt;code&gt;.test()&lt;/code&gt; method. The test method is going to take our regex and apply it to a string that we pass as an argument. It will return true or false if our defined pattern finds a match, or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const someString = "Hello, World!"
let ourRegex = /Hello/
let result = ourRegex.text(someString)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Test returns true!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I've also used &lt;code&gt;.match()&lt;/code&gt;, which actually extracts the matches found. The syntax is the opposite of &lt;code&gt;.test()&lt;/code&gt;-- you call .match on the string and pass the regex as the argument.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing regex patterns:
&lt;/h2&gt;

&lt;p&gt;There is A LOT to learn with Regex. Here's a cheatsheet of some I've learned (so far):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OR&lt;/strong&gt; Looking for multiple possible matches.&lt;br&gt;
&lt;code&gt;let ourRegex = /Hello|Goodbye/&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ignoring case&lt;/strong&gt; Matching different cases (i.e. A, a) The 'i' flag goes outside the //&lt;br&gt;
&lt;code&gt;let ourRegex = /Hello|Goodbye/i&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Finding multiple matches&lt;/strong&gt; Matching repeats of your regex. The 'g' (global) flag goes outside the //&lt;br&gt;
&lt;code&gt;let ourRegex = /Hello/ig&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Wildcard&lt;/strong&gt; Matches anything. Essentially a 'wildcard' character. This could match things like her, hen, etc&lt;br&gt;
&lt;code&gt;let ourRegex = /He./i&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Character sets&lt;/strong&gt; Allow you to define a group of characters we're trying to match, placing them inside square brackets.&lt;br&gt;
&lt;code&gt;let ourRegex = /b[ae]g/i&lt;/code&gt;&lt;br&gt;
This would match bag and beg, but not big, bug or bog.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Character sets with range&lt;/strong&gt; You can also define ranges, for letters or numbers.&lt;br&gt;
&lt;code&gt;let ourRegex = /[a-g]at/i&lt;/code&gt;&lt;br&gt;
&lt;code&gt;let ourRegex = /[0-9]/g&lt;/code&gt;&lt;br&gt;
Combine them, too as needed:&lt;br&gt;
&lt;code&gt;let ourRegex = /[0-9a-g]/gi&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;NON match - negated character sets&lt;/strong&gt; Use a carrot to define what you DON'T want to match. This would match everything NOT a number or vowel:&lt;br&gt;
&lt;code&gt;let ourRegex = /[^0-9aeiou]/gi&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Repeating characters&lt;/strong&gt; Use a + to match ONE or more repeating instances (consecutively).&lt;br&gt;
&lt;code&gt;let ourRegex = /s+/gi&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Repeating characters&lt;/strong&gt; Use a * to match ZERO or more repeating instances (consecutively).&lt;br&gt;
&lt;code&gt;let ourRegex = /Aa*/gi&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Quantity specifiers&lt;/strong&gt; Instead of + or * you can specify your own range with {}&lt;br&gt;
&lt;code&gt;let ourRegex = /Hell\syeah{3,10}/g&lt;/code&gt;&lt;br&gt;
This would match only strings of "Hell yeahhh" with 3-10 h's on the end&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quantity can also only have a lower limit:&lt;br&gt;
&lt;code&gt;let ourRegex = /Hell\syeah{3,}/g&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Start of string&lt;/strong&gt; Match something only in the beginning of string. Carrot goes outside of brackets, etc&lt;br&gt;
&lt;code&gt;let ourRegex = /^April/&lt;/code&gt;&lt;br&gt;
Would match April at the beginning of a string. (aka 'starts with')&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;End of string&lt;/strong&gt; Match something only at the end of string. $ at the end&lt;br&gt;
&lt;code&gt;let ourRegex = /end$/&lt;/code&gt;&lt;br&gt;
Would match if the string ends in 'end'. (aka ends with)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alphabet, number and _ shorthand&lt;/strong&gt;  &lt;code&gt;\w&lt;/code&gt; is equal to &lt;code&gt;[A-Za-z0-9_]&lt;/code&gt;&lt;br&gt;
&lt;code&gt;let ourRegex = /\w/&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OPPOSITE Alphabet, number and _ shorthand&lt;/strong&gt;  &lt;code&gt;\W&lt;/code&gt; is equal to everything BUT &lt;code&gt;[A-Za-z0-9_]&lt;/code&gt;&lt;br&gt;
&lt;code&gt;let ourRegex = /\W/g&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Digits&lt;/strong&gt; \d is the shorthand equal to [0-9] &lt;br&gt;
&lt;code&gt;let ourRegex = /\d/&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OPPOSITE Digits&lt;/strong&gt; \d is the shorthand equal to everything BUT [0-9] &lt;br&gt;
&lt;code&gt;let ourRegex = /\D/g&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Whitespace&lt;/strong&gt; \s matches whitespace, as well as form feed, new line characters and tab&lt;br&gt;
&lt;code&gt;let ourRegex = /\s/g&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OPPOSITE Whitespace&lt;/strong&gt; \s matches everything but whitespace&lt;br&gt;
&lt;code&gt;let ourRegex = /\S/g&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;All or none&lt;/strong&gt; Check for the possible existence of an element&lt;br&gt;
&lt;code&gt;let ourRegex = /colou?r/&lt;/code&gt;&lt;br&gt;
This would match 'color' and 'colour'&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;I'll definitely be adding more so keep checking back for the cheatsheet and tips to grow!&lt;/p&gt;

</description>
      <category>regex</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Simple, beginner steps: CSS animations!</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Wed, 27 Apr 2022 13:31:01 +0000</pubDate>
      <link>https://dev.to/aprilskrine/simple-beginner-steps-css-animations-55hh</link>
      <guid>https://dev.to/aprilskrine/simple-beginner-steps-css-animations-55hh</guid>
      <description>&lt;h2&gt;
  
  
  Let's talk about a fun (and sometimes functional) topic-- animating our CSS! Here's some of the basics:
&lt;/h2&gt;

&lt;p&gt;CSS animation is a really fun topic, and something I love to use to add some fun and life to my projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  1.The first step is specifying keyframes for the animation.
&lt;/h2&gt;

&lt;p&gt;Keyframes hold what styles the element will have at any given time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes example {
  from {background-color: blue;}
  to {background-color: red;}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we specify CSS styling inside the &lt;a class="mentioned-user" href="https://dev.to/keyframe"&gt;@keyframe&lt;/a&gt;, the animation will change from the current style to the new style over a time (that we specify).  &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Second, we have to bind the animation to some element, like an img, div, etc.
&lt;/h2&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  width: 300px;
  height: 100px;
  background-color: red;
  animation-name: example;
  animation-duration: 10s;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We 'bind' the animation to the div by calling it in the animation-name property. We also specify that it will take 10s for the animation to execute.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;!! Don't forget-- once the animation finishes, the element goes back to its original specifications. So if we had declared the background color blue, after the animation completes the div would go back to blue.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Deciding animation-duration property
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;animation-duration&lt;/code&gt; specifies how long it will take the animation to complete. If you don't specify this property the animation &lt;strong&gt;will not work&lt;/strong&gt; because the default value is 0, which is 0 seconds. &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Animation timing / breakdown
&lt;/h2&gt;

&lt;p&gt;In our example above, our start point was the 'from' value and the finish was our 'to' value. You can also use percentages to represent the completion percentage, which means we can break it down as much as we'd like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  60% {
    transform: rotate(1800deg);
  }

  80% {
    transform: rotate(2085deg);
  }
  100% {
    transform: rotate(2160deg);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example I was having a ball roll across the screen and come to a stop. This is the keyframe for the rotation aspect. The rotation from 0-60% completion is more, and then it slowly lessens until completion at 100%.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some other animation properties:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;animation-delay&lt;/code&gt; will specify a delay time before the animation executes. You can also do negative values, which will make the animation start as if it's already been playing for X number of seconds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;animation-direction&lt;/code&gt; decides the direction of the cycle. You can have values 'normal' (default/forward), 'reverse' (backwards, duh), 'alternate' (first forward, then backward), or 'alternate-reverse' (the opposite of alternate)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;animation-iteration-count&lt;/code&gt; is how many times the animation will execute from start to finish. You can use the value 'infinite' if you never want it to stop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;animation-timing-function&lt;/code&gt; can specify the speed curve of the animation. Values can be 'ease' (start slow, execute fast, end slow), 'linear' (same animation speed start to finish), 'ease-in' (slow start only), 'ease-out' (slow finish only), 'ease-in-out' (slow start and end)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CODING TIP:
&lt;/h2&gt;

&lt;p&gt;When writing out animations in CSS, sometimes I like to keep the properties separate, because for me it's easier to read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  animation-name: example;
  animation-duration: 20s;
  animation-timing-function: linear;
  animation-delay: 5s;
  animation-iteration-count: infinite;
  animation-direction: alternate-reverse;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you can also simplify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  animation: example 5s linear 2s infinite alternate;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those are some basic tips, have fun with your newfound powers!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>css</category>
      <category>react</category>
    </item>
    <item>
      <title>Simple, beginner steps: CSS Flexbox!</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Sun, 03 Apr 2022 14:52:11 +0000</pubDate>
      <link>https://dev.to/aprilskrine/simple-beginner-steps-css-flexbox-54b8</link>
      <guid>https://dev.to/aprilskrine/simple-beginner-steps-css-flexbox-54b8</guid>
      <description>&lt;h2&gt;
  
  
  Let's talk through the basics of one of the most versatile modules in CSS -- the flexbox!
&lt;/h2&gt;

&lt;p&gt;The flexbox has two elements: the parent element (the container that's 'flexing') and the child element (the flex items). It's amazingly versatile because it allows us to format, layout and organize even when the size of the space is unknown-- or it's dynamic!&lt;/p&gt;

&lt;h2&gt;
  
  
  Parent properties:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. display&lt;/strong&gt; This is the building block, that is going to define the flex container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: flex;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. flex-direction&lt;/strong&gt; This is going to dictate which axis your flexbox parent expands on, and which direction on that axis. &lt;br&gt;
&lt;em&gt;row:&lt;/em&gt; left to right&lt;br&gt;
&lt;em&gt;row-reverse:&lt;/em&gt; right to left&lt;br&gt;
&lt;em&gt;column:&lt;/em&gt; north to south&lt;br&gt;
&lt;em&gt;column-reverse:&lt;/em&gt; south to north&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  flex-direction: row (OR) row-reverse (OR) column (OR) column-reverse;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. flex-wrap&lt;/strong&gt; Flexbox will always try to fit items into one line-- this property can allow it to wrap to a new line.&lt;br&gt;
&lt;em&gt;nowrap:&lt;/em&gt; all on one line&lt;br&gt;
&lt;em&gt;wrap:&lt;/em&gt; wrap onto multiple lines (top to bottom)&lt;br&gt;
&lt;em&gt;wrap-reverse:&lt;/em&gt; multiple lines (bottom to top)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  flex-wrap: nowrap (OR) wrap (OR) wrap-reverse;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. justify-content&lt;/strong&gt; This property defines the alignment on the axis declared originally for the flex. &lt;br&gt;
&lt;em&gt;flex-start:&lt;/em&gt; items are packed toward the start of the flex-direction&lt;br&gt;
&lt;em&gt;flex-end:&lt;/em&gt; packed toward end of flex direction&lt;br&gt;
&lt;em&gt;start:&lt;/em&gt; packed toward start of writing-mode direction&lt;br&gt;
&lt;em&gt;end:&lt;/em&gt; packed toward end of writing-mode direction&lt;br&gt;
&lt;em&gt;left:&lt;/em&gt; left packed toward left edge of container&lt;br&gt;
&lt;em&gt;right:&lt;/em&gt; left packed toward right edge of container&lt;br&gt;
&lt;em&gt;center:&lt;/em&gt; centered&lt;br&gt;
&lt;em&gt;space-between:&lt;/em&gt; items are evenly spaced on line&lt;br&gt;
&lt;em&gt;space-around:&lt;/em&gt; items are evenly spaced, space around them is also even&lt;br&gt;
&lt;em&gt;space-evenly:&lt;/em&gt; spacing between items and edges is even&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  justify-content: flex-start (OR) flex-end (OR) center (OR) space-between (OR) space-around (OR) space-evenly (OR) start (OR) end (OR) left (OR) right (OR) you get the idea;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. align-items&lt;/strong&gt; This defines how the items are laid out on the crossing axis of the current line.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;stretch:&lt;/em&gt; (default) stretches to fill container&lt;br&gt;
&lt;em&gt;flex-start:&lt;/em&gt; start of the cross axis &lt;br&gt;
&lt;em&gt;flex-end:&lt;/em&gt; end of the cross axis&lt;br&gt;
&lt;em&gt;center:&lt;/em&gt; items are centered on cross axis&lt;br&gt;
&lt;em&gt;baseline:&lt;/em&gt; items are aligned so their baselines are aligned&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For this one, imagine your flex goes L--&amp;gt;R. Flex-start would mean all items align at the top (North). Flex-end would align them at the bottom (South). Center would center them along the center of North-South, centered by the item's center. Stretch would make them fill equal North-South space from the center. Baseline will center them North-South by baseline.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
 align-items: (value here)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. align-content&lt;/strong&gt; This aligns the lines of a flex container within the extra space on the cross axis. &lt;em&gt;This property only effects multi-lines flex containers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;normal:&lt;/em&gt; (default)&lt;br&gt;
&lt;em&gt;flex-start:&lt;/em&gt; items packed to start of container&lt;br&gt;
&lt;em&gt;flex-end:&lt;/em&gt; items packed to end of container&lt;br&gt;
&lt;em&gt;center:&lt;/em&gt; items centered in container&lt;br&gt;
&lt;em&gt;space-between:&lt;/em&gt; items evenly distributed from start to end of container&lt;br&gt;
&lt;em&gt;space-around:&lt;/em&gt; items evenly distributed with equal space around each line&lt;br&gt;
&lt;em&gt;space-evenly:&lt;/em&gt; items are evenly distributed with equal space around them&lt;br&gt;
&lt;em&gt;stretch:&lt;/em&gt; lines stretch to take up space&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  align-content: (value here)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. gaps&lt;/strong&gt; The gap property handles the space between flex items. It only applies between items, and doesn't affect edges.&lt;/p&gt;

&lt;p&gt;you can declare:&lt;br&gt;
&lt;em&gt;gap:&lt;/em&gt; 20px (default)&lt;br&gt;
&lt;em&gt;gap:&lt;/em&gt; 20px 20px (row-gap then column-gap)&lt;br&gt;
&lt;em&gt;row-gap:&lt;/em&gt; 20px&lt;br&gt;
&lt;em&gt;column-gap:&lt;/em&gt; 20px&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: flex;
  ...
  gap: 10px;
  gap: 10px 20px;
  row-gap: 10px;
  column-gap: 20px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Child properties:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. order&lt;/strong&gt; This can control the order items appear in the flex container. If items have the same order, they default to their source order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item {
  order: 5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. flex-grow&lt;/strong&gt; This defines the flex item's ability to grow if necessary. The value is a proportion. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example, if all items had a value of 1, the space would be distributed equally between the children. If one item had a 2, it would take up twice the allotted space of all other items.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item {
  flex-grow: 4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. flex-shrink&lt;/strong&gt; This is the opposite of grow, and allows items to shrink if necessary&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item {
  flex-shrink: 3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. align-self&lt;/strong&gt; This allows the default alignment (the one in align-items in the parent) to be overridden in a specific item&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item {
  align-self: auto (OR) flex-start (OR) flex-end (OR) center (OR) baseline (OR) stretch;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;It can take awhile to get a hang of the flexbox, but it's worth it!&lt;/p&gt;

&lt;p&gt;Check out this amazing visual guide to CSS flexbox &lt;a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/"&gt;here&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>css</category>
      <category>react</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Simple, beginner steps: API with Rails!</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Fri, 18 Mar 2022 18:17:34 +0000</pubDate>
      <link>https://dev.to/aprilskrine/simple-beginner-steps-api-with-rails-538j</link>
      <guid>https://dev.to/aprilskrine/simple-beginner-steps-api-with-rails-538j</guid>
      <description>&lt;h2&gt;
  
  
  Let's talk through some basics to building out an API in Rails.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Make sure you have rails installed first by running &lt;code&gt;gem install rails&lt;/code&gt;! This assumes you already have a rails directory started. If not, run &lt;code&gt;rails new [name] --api&lt;/code&gt; to start new.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Build out your resources
&lt;/h2&gt;

&lt;p&gt;For the sake of this example, we're going to work with the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Owner --&amp;lt; Pets &amp;gt;-- Pet Sitters&lt;/li&gt;
&lt;li&gt;An owner has many pets&lt;/li&gt;
&lt;li&gt;A pet sitter has many pets they take care of&lt;/li&gt;
&lt;li&gt;Through relationships apply&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's build out our resources. We're going to use &lt;code&gt;rails g resource&lt;/code&gt; because it will generate model, controller, migration and serializers for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g resource owner name phone:integer
rails g resource sitter name phone:integer active:boolean
rails g resource pet name age:integer sitter:references owner:references
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will build out our resources, and include the foreign keys in the pet migration. References will ensure the foreign keys cannot have a null value when we migrate and update the schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Add/confirm relationships
&lt;/h2&gt;

&lt;p&gt;Once we've created our resources with the generator, let's make sure our relationships are correct. The resource generator automatically generated the &lt;code&gt;belongs_to&lt;/code&gt; when we used references, but we need to go into the &lt;strong&gt;Owner&lt;/strong&gt; and &lt;strong&gt;Sitter&lt;/strong&gt; models and include:&lt;/p&gt;

&lt;p&gt;In Owner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;has_many :pets, dependent: :destroy
has_many :sitters, through: :pets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Sitter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;has_many :pets
has_many :owners, through: :pets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our relationships are confirmed. In the &lt;strong&gt;Pets&lt;/strong&gt; model you should see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;belongs_to :owner
belongs_to :sitter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This is also a good time to think about whether any relationships will need &lt;code&gt;dependent: :destroy&lt;/code&gt; . Obviously if an owner deletes their profile, the pets they own should be deleted as well. We included this in the Owner model.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Validations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that our models are linked, let's look at validations in our models. Let's assume an owner must be 16 or older to use our service, and a pet sitter must be 18 to be a pet sitter. Also, a pet cannot be created without a name.&lt;/p&gt;

&lt;p&gt;In Owner model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validates :age, numericality: {greater_than_or_equal_to: 16}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Sitter model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validates :age, numericality: {greater_than_or_equal_to: 18}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Pet model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validates :name, presence: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the validations we've added in each of the models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Routes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's take a look at our routes in Config &amp;gt;&amp;gt; Routes. Since we used the resource generator, we'll already see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :owners
resources :sitters
resources :pets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that all default routes are currently open. Let's clean up what's accessible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :owners, only: [:index, :show, :create, :destroy]
resources :sitters, only: [:index, :show, :create, :destroy]
resources :pets, only: [:index, :show]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can define the routes any way we want to, but this is what we'll arbitrarily use for now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Controllers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we've got the routes, let's head for the Controllers and get some of the routes defined. Let's just look at an example of OwnersController:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def index
        render json: Owner.all, status: :ok
end

def show
        render json: Owner.find(params[:id]), status: :found
end

def create
        render json: Owner.create!(owner_params), status: :created
end

def destroy
        Owner.find(params[:id].destroy
        head :no_content
end

private

def owner_params
        params.permit(:name, :phone, :age)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure each Controller has routes defined for each route we've specified in our Config &amp;gt;&amp;gt; Routes. Technically, we didn't really need strong params for this, but I wanted to show an example. In the private methods of the controller, I've defined the strong params, which are the only params that will allowed to be passed.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;!!!&lt;/em&gt; I've used &lt;code&gt;find&lt;/code&gt; because it throws an error. I've also added the bang operator in the create method. In our ApplicationController, you would find something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; ActionController::API
  include ActionController::Cookies

  rescue_from ActiveRecord::RecordNotFound, with: :not_found
  rescue_from ActiveRecord::RecordInvalid, with: :render_unprocessable_entity

  private

  def not_found(error)
    render json: {error: "#{error.model} not found"}, status: :not_found
  end

  def render_unprocessable_entity(invalid)
    render json: {errors: invalid.record.errors.full_messages}, status: :unprocessable_entity
  end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of our controllers inherit from ApplicationController, so we can write these rescues only once and they will be applicable for any of our Controllers that need them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Serializers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, you need to ensure that the serializer gem is in the Gemfile. If it's not, add &lt;code&gt;gem "active_model_serializers", "~&amp;gt; 0.10.12"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Our resource generator already generated serializers for each model when we used the resource generator. We can use those serializers to limit what we receive in our responses. &lt;em&gt;Anything in the related Controller will default to the serializer with the matching name, unless you specify otherwise.&lt;/em&gt; In our OwnerController, that would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;render json: &amp;lt;something&amp;gt;, serializer: &amp;lt;CustomSerializerName&amp;gt;, status: :ok
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you'll be using the default serializer with the corresponding name, you can omit the serializer specification in the Controller. However, let's say we have two serializers for Owners. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One default for &lt;code&gt;index&lt;/code&gt;, so we see all owners with their :id, :name, :age, :phone like so:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class OwnerSerializer &amp;lt; ActiveModel::Serializer
     attributes :id, :name, :age, :phone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;One custom serializer for &lt;code&gt;show&lt;/code&gt;, so when we access individual owner info their pets are also returned:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class OwnerIdSerializer &amp;lt; ActiveModel::Serializer
     attributes :id, :name, :age, :phone
     has_many :pets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we call that custom serializer in our &lt;code&gt;show&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def show
     render json: Owner.find(params[:id]), serializer: OwnerIdSerializer, status: :ok

end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Rails Generators - the basics.</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Mon, 14 Mar 2022 16:23:14 +0000</pubDate>
      <link>https://dev.to/aprilskrine/rails-generators-the-basics-2lpm</link>
      <guid>https://dev.to/aprilskrine/rails-generators-the-basics-2lpm</guid>
      <description>&lt;h2&gt;
  
  
  RAILS GENERATORS
&lt;/h2&gt;

&lt;p&gt;Let's talk generators in Rails. They save us time, AND they provide us with some awesome benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;They can set up some basic specs for an application's test suite. They won't write our complex logic tests for us, but they will provide some basic examples.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They are set up to work the same way each time. This helps standardize your code and enables your development to be more efficient since you don't have to worry as much about bugs related to spelling, syntax errors, or anything else that can occur when writing code manually.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They follow Rails best practices, which includes utilizing RESTful naming patterns, removing duplicate code, using partials and a number of other best of breed design patterns. (If you don't know what all of these are, don't worry — we will cover them shortly.)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;SOURCE: &lt;a href="https://learn.co/lessons/rails-generators-readme"&gt;LEARN.CO&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;FUN FACT&lt;/strong&gt; &lt;em&gt;- when you're creating an application with &lt;code&gt;rails&lt;/code&gt;, you're actually already using a Rails generator.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once you've created a Rails application, you can show a list of all available generators by running:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bin/rails generate&lt;/code&gt; OR &lt;code&gt;bin/rails generate helper --help&lt;/code&gt; (The latter will give you detailed descriptions)&lt;/p&gt;




&lt;h2&gt;
  
  
  CREATING GENERATORS
&lt;/h2&gt;

&lt;p&gt;Entering the basic command into the terminal will follow syntax like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g &amp;lt;generator name&amp;gt; &amp;lt;options&amp;gt; --no-test-framework&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are many generators, but the 4 we'll focus on here are:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Migrations&lt;/li&gt;
&lt;li&gt;Models&lt;/li&gt;
&lt;li&gt;Controllers&lt;/li&gt;
&lt;li&gt;Resources&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Model
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Model will create a model &amp;amp; migration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;rails g model Pet name breed&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This would generate a Pet model, and a migration to create a pets table with two columns, name and breed. String is the default input for a table column, so we don't need to put name:string when using the generator&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Controller
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Controller will create a controller&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;rails g controller admin dashboard stats financials settings --no-test-framework&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This will generate a controller file that inherits from ApllicationController, a set of routes to each of the arguments/options (dashboard, stats, financials, settings), a new directory for all of the view templates along with a view template file for each of the controller actions that we declared in the generator command, a view helper method file, a Coffeescript file for specific JavaScripts for that controller &amp;amp; an scss file for the styles for the controller&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Migration
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Migration will create a migration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;rails g migration add_published_status_to_posts published_status:string --no-test-framework&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This would generate a migration that looks something like this:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AddPublishedStatusToPosts &amp;lt; ActiveRecord::Migration
  def change
    add_column :posts, :published_status, :string
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Resource
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Resource will create a model, controller, migration &amp;amp; views directory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;rails g resource Account name payment_status --no-test-framework&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This would generate a migration file with the passed atrributes, a model file that inherits from ApplicationRecord, a controller file inheriting from ApplicationController, a view directory (with no view template files), a view helper, a Coffeescript file for specific JavaScripts for that controller &amp;amp; an scss file for the styles for the controller and a full resources call in the routes.rb file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The last item is a &lt;strong&gt;MAGIC ROUTE&lt;/strong&gt;! It shows the full set of RESTful routes that'll you'll need to perform CRUD. If you run &lt;code&gt;rake routes&lt;/code&gt; (optional filter) you'll see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rake routes | this account
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accounts      GET    /accounts(.:format)          accounts#index
              POST   /accounts(.:format)          accounts#create
new_account   GET    /accounts/new(.:format)      accounts#new
edit_account  GET    /accounts/:id/edit(.:format) accounts#edit
account       GET    /accounts/:id(.:format)      accounts#show
              PATCH  /accounts/:id(.:format)      accounts#update
              PUT    /accounts/:id(.:format)      accounts#update
              DELETE /accounts/:id(.:format)      accounts#destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Sources: &lt;a href="https://learn.co/lessons/rails-generators-readme"&gt;Learn.co&lt;/a&gt; &lt;a href="https://guides.rubyonrails.org/generators.html"&gt;Rails Guide&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>rails</category>
      <category>ruby</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Cheat Sheet: ActiveRecord QueryMethods</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Tue, 08 Mar 2022 17:11:24 +0000</pubDate>
      <link>https://dev.to/aprilskrine/cheat-sheet-common-activerecord-querymethods-2dh5</link>
      <guid>https://dev.to/aprilskrine/cheat-sheet-common-activerecord-querymethods-2dh5</guid>
      <description>&lt;h2&gt;
  
  
  .count
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value:&lt;/strong&gt; integer&lt;/li&gt;
&lt;li&gt;Counts total of instances, or # of values in an array&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Order.count&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  .create
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value:&lt;/strong&gt; New created instance of a class
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order.create(name: "Americano", price: 5.55)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  .pluck
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value:&lt;/strong&gt; an array of values grabbed that match the plucked column names&lt;/li&gt;
&lt;li&gt;Extremely helpful when used with other selectors
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person.pluck(:name)
# SELECT people.name FROM people
# =&amp;gt; ['David', 'Jeremy', 'Jose']

Person.pluck(:id, :name)
# SELECT people.id, people.name FROM people
# =&amp;gt; [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]

Person.distinct.pluck(:role)
# SELECT DISTINCT role FROM people
# =&amp;gt; ['admin', 'member', 'guest']

Person.where(age: 21).limit(5).pluck(:id)
# SELECT people.id FROM people WHERE people.age = 21 LIMIT 5
# =&amp;gt; [2, 3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  .sum
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value&lt;/strong&gt;: integer&lt;/li&gt;
&lt;li&gt;Calculates the sum of a column &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Person.sum(:age) # =&amp;gt; 4562&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  .maximum &amp;amp; .minimum
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value:&lt;/strong&gt; integer&lt;/li&gt;
&lt;li&gt;Finds the max/min value of a table column&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Person.maximum(:age) # =&amp;gt; 93&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Person.minimum(:age) # =&amp;gt; 93&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  .where
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value:&lt;/strong&gt; Instance(s) of class&lt;/li&gt;
&lt;li&gt;Can take various arguments, including a string, array or hash. A single string is often 1 argument, and an array can be used for multiple arguments, where the first element in the array is treated as a template. It can also accept a hash, with the key/value pairs you're looking for.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;String example: &lt;br&gt;
&lt;code&gt;Client.where("orders_count = '2'")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Array example: &lt;br&gt;
&lt;code&gt;User.where(["name = :name and email = :email", { name: "Joe", email: "joe@example.com" }])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Hash example: &lt;br&gt;
&lt;code&gt;User.where({ name: "Joe", email: "joe@example.com" })&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  .max_by &amp;amp; min_by
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value:&lt;/strong&gt; enumerator&lt;/li&gt;
&lt;li&gt;Good to use in methods, as its return value by itself is not a common wanted value. Looks for either the min/max values
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Coffee.all.max_by{ |c| c.orders.size}
Coffee.all.min_by{ |c| c.orders.size}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  .first &amp;amp; .last
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Return value:&lt;/strong&gt; Instance of class&lt;/li&gt;
&lt;li&gt;Very useful in conjunction with .sort&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Order.all.sort.last&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Sources: rubydoc.info&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>activerecord</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>3 ways to code CSS in React</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Mon, 21 Feb 2022 22:10:59 +0000</pubDate>
      <link>https://dev.to/aprilskrine/3-ways-to-code-css-in-react-23co</link>
      <guid>https://dev.to/aprilskrine/3-ways-to-code-css-in-react-23co</guid>
      <description>&lt;p&gt;Getting comfortable with React can be a bear. And once you're comfortable... unfortunately, there's no guarantee you know how to give your components any sort of unified styling. &lt;/p&gt;

&lt;p&gt;CSS can become a convoluted process in React, so here are the 3 most common ways you can implement CSS:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. STYLESHEET
&lt;/h2&gt;

&lt;p&gt;The most recognizable way to implement CSS in React is a .css stylesheet. Though the easiest to navigate-- especially if you're already familiar with CSS-- it can get complicated rather quickly with a large application and be difficult to reference as the size increases. &lt;/p&gt;

&lt;p&gt;Another potential drawback to a .css stylesheet in React is that it interacts in a very specific matter with Bootstrap/Semantic UI, and getting your CSS to override the defaults in either requires making sure you're being more specific, or using &lt;code&gt;!important&lt;/code&gt; , which isn't always best practice.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Also, make sure where you're bringing in class from your stylesheet, make sure to use &lt;code&gt;className=&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. IN-LINE STYLING
&lt;/h2&gt;

&lt;p&gt;My favorite method, inline styling can be organized quite nicely as long as you pay attention to indentation and 'hamburger-style' HTML elements.&lt;/p&gt;

&lt;p&gt;In-line styling has a few specific rules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;label style={{
  color: '#C1BBDA', 
  fontSize: '20px', 
  fontFamily: 'shizuru'}}
&amp;gt;
 NAME
&amp;lt;/label&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in this example, the 'style' code is added directly into the HTML element that exists in the JSX. Inside of the opening tag (or the main, if it's self-closing) you'll add &lt;code&gt;style={{}}&lt;/code&gt;, where the outer set of brackets refer to JSX. Inside the brackets indicating CSS, you'll add your CSS styling, with the following rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;a colon follows all separately, i.e. 'color:'&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;if the styling has multiple words, camel case will be used, rather than the traditional CSS stylesheet format. &lt;code&gt;fontSize&lt;/code&gt; would be used in in-line styling, rather than &lt;code&gt;font-size&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;all styling following the ':' will be encased in a string. i.e. &lt;code&gt;color: '#C1BBDA'&lt;/code&gt; &lt;em&gt;(The hex code is inside quotes)&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;commas are still to implemented between style, if there are multiple styles applied. See the above example, where commas exist between each applied style&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. STYLED-COMPONENTS
&lt;/h2&gt;

&lt;p&gt;The final alternative to applying CSS in React is styled components. In order to use styled components, you must import them into a component:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import styled from 'styled-components'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once imported into the component, the syntax for styled components varies slightly from the previous two examples. Outside of your component's function, you will declare an HTML element styled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const div = styled.div`
  margin-top:40px;
  margin-bottom:20px
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Declare a variable and set it equal to &lt;code&gt;styled.${someHTMLelement}&lt;/code&gt;, immediately followed by an backtick. On the next lines, the indented code will look extremely similar to stylesheet CSS, with colon and semi-colon format. When you have applied all styling, the end line of the styled component should end with an backtick, as shown above.&lt;/p&gt;

&lt;p&gt;After declaration, calling the styled component looks exactly similar to calling a imported component anywhere else in your React application. For example, to code the above styled component, we would use&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Div&amp;gt;&amp;lt;/Div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;to call the styled component. &lt;em&gt;(Make sure to capitalize, just as with any component.)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  BONUS: CSS MODULES
&lt;/h2&gt;

&lt;p&gt;I'm not very knowledgeable about CSS Modules, so if you're interested in learning more about CSS Modules, pop over to &lt;a href="https://css-tricks.com/css-modules-part-1-need/"&gt;this helpful article &lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>css</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>So, what is Monkey Patching?</title>
      <dc:creator>April Skrine</dc:creator>
      <pubDate>Tue, 15 Feb 2022 02:33:03 +0000</pubDate>
      <link>https://dev.to/aprilskrine/so-what-is-monkey-patching-3lp2</link>
      <guid>https://dev.to/aprilskrine/so-what-is-monkey-patching-3lp2</guid>
      <description>&lt;p&gt;Along the banks of the learning river I stumbled on 'monkey patching' during a particularly convoluted Javascript lecture...&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;WHAT IS MONKEY PATCHING?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Monkey patching is a way to extend, change or modify something (library, supporting system software, plugin) locally. This means applying a monkey patch won't change the library itself, but rather just the local copy of the library on your machine. 'Monkey Patching' is a term that merely means changing code at runtime. Most often this is done to work around a bug or feature.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Oftentimes when an update comes out there are minor bugs that aren't devastating, but they make it a lot more frustrating to work through... hence the monkey patch.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monkey patching can be used to:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Replace methods / classes / attributes / functions at runtime (e.g. to stub out a function during testing)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modify/extend behavior of a third-party product without maintaining a private copy of the source code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apply the result of a patch at runtime to the state in memory, instead of the source code on disk&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Distribute security or behavioral fixes that live alongside the original source code (an example of this would be distributing the fix as a plugin for the Ruby on Rails platform)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But monkey patching isn't only used to work around bugs. It can also be a way to modify behavior that isn't quite doing what we want. It's possible to make changes to said code using monkey patching.&lt;/p&gt;

&lt;p&gt;FYI -- this only applies a &lt;em&gt;patch&lt;/em&gt; to any original code. (Hence, 'monkey patching'.) It only applies to YOUR copy of it. Meaning, if you install a npm library, the monkey patch would only work on the library for you, and not directly modify the library npm has access to.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Here's an example of monkey patching, courtesy of Max Heiber:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqkqk7m82e8n3rspx5xj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqkqk7m82e8n3rspx5xj.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They've monkey-patched 'Array' to add a 'last' method, which returns the last item in the array. Potential problems with this? Definitely. The author could change the implementation of 'last', which would break your code since yours relies on your implementation. Elsewhere in your code you (or someone else) will always have to remember that 'Array' has been patched. See how we're getting into little headaches?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;So is it... wrong?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I knew I had to write a blog topic on it when I heard how it was discussed. Was it... &lt;em&gt;horrible&lt;/em&gt;? In the end it's not... wrong, per se. Nor is it a particularly niche technique. But-- 9/10 times-- there's a better way to solve the issue. It's only in rare cases that monkey patching is the only (and best!) solution. Its rarity as 'best-use' is why it's discussed in such a taboo way.&lt;/p&gt;

&lt;p&gt;Patches made to a module might not work after methods have changed and the module is updated. If monkey patches aren't applied conditionally, this can lead to crashes and bugs that are a headache to fix later on.&lt;/p&gt;

&lt;p&gt;Also, if 2+ components apply a monkey patch to the exact same method-- depending on which component runs last-- the other monkey patch will be completely useless.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Monkey Patching Issues&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Poorly documented or badly written patches can lead to a lot of possible problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Whenever a monkey patch relies on an assumption about the patched object, an upgrade can lead to problems if that assumption is no longer true after the upgrade is applied. Monkey patches should be made conditional, and then they can be applied only when appropriate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"If two modules attempt to monkey patch the same method, one of them (whichever one runs last) "wins" and the other patch has no effect, unless monkey patches are written with a pattern like&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias_method_chain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;They can create inconsistency between observed behavior of the application and the actual source code, which can lead to time wasted trying to debug an unfixable problem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And-- obviously-- they can be written with malicious code inside.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;References:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"New in Rails: Module#alias_method_chain". 2006-04-26.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/Monkey_patch" rel="noopener noreferrer"&gt;Wikipedia: Monkey Patching&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;a href="https://maxheiber.medium.com/safe-monkey-patching-with-es2015-symbol-e36fb01ab794" rel="noopener noreferrer"&gt;Max Heiber&lt;/a&gt;&lt;/em&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
