<?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: Micah Gilbert</title>
    <description>The latest articles on DEV Community by Micah Gilbert (@micahsgilbert).</description>
    <link>https://dev.to/micahsgilbert</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%2F181562%2F34048dfe-46d6-4745-b06f-d460f4a60e21.png</url>
      <title>DEV Community: Micah Gilbert</title>
      <link>https://dev.to/micahsgilbert</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/micahsgilbert"/>
    <language>en</language>
    <item>
      <title>Python's enumerate function</title>
      <dc:creator>Micah Gilbert</dc:creator>
      <pubDate>Wed, 18 Sep 2019 19:11:06 +0000</pubDate>
      <link>https://dev.to/micahsgilbert/python-s-enumerate-function-2ji3</link>
      <guid>https://dev.to/micahsgilbert/python-s-enumerate-function-2ji3</guid>
      <description>&lt;p&gt;This is just a quick post because I've seen some python beginners make some functions that are really in need of &lt;code&gt;enumerate&lt;/code&gt;, but they don't know it and turn to odd solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does it do?
&lt;/h2&gt;

&lt;p&gt;Put simply, &lt;code&gt;enumerate&lt;/code&gt; is a function that takes in an iterable (typically an array) and, for each item, gives both its index in the array and the item itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  When should I use it?
&lt;/h2&gt;

&lt;p&gt;I've seen this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array = ["a","b","c","b"]
for index in range(len(array)):
    item = array[i]
    # code continues using both `index` and `item`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This really doesn't hurt too much but &lt;code&gt;enumerate&lt;/code&gt; can make this a bit cleaner.&lt;/p&gt;

&lt;p&gt;In my early days of Python I created a monstrosity like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array = ["a","b","c","b"]
for item in array:
    index = array.index(item)
    # code continues using both `index` and `item`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is actively bad code, and my thinking "There must be a better way to do this" finally led me to &lt;code&gt;enumerate&lt;/code&gt;.&lt;br&gt;
The main issue with this, other than possible performance issues if the array is quite long, is that &lt;code&gt;array.index&lt;/code&gt; only returns the &lt;em&gt;first&lt;/em&gt; index of the item. That means that the second &lt;code&gt;"b"&lt;/code&gt; in the array will never get its index (3) run in the rest of the &lt;code&gt;for&lt;/code&gt; loop. Instead, &lt;code&gt;array.index&lt;/code&gt; will return 1 for both &lt;code&gt;"b"&lt;/code&gt;s.&lt;/p&gt;
&lt;h2&gt;
  
  
  How should I use it?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;enumerate&lt;/code&gt; is incredible easy. All that is needed is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array = ["a","b","c","b"]
for index, item in enumerate(array)
    # code continues using both `index` and `item`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Look at how clean that is. That uses fewer lines than both code blocks above, and is arguably the most explicit and easiest to understand.&lt;/p&gt;

&lt;p&gt;List comprehensions can also be used for filtering lists.&lt;/p&gt;

&lt;p&gt;Let's say that we want all odd-indexed items that are vowels.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test_letters = ["a", "e", "i", "q", "c"]
vowels = ('a','e','i','o','u')

# Not using `enumerate`, just plain old logic
# This ca be confusing, especially if it wasn't documented.

new_arr = []
for i in range(len(test_letters)):
    if i % 2 == 0 and test_letters[i] in vowels:
        new_arr.append(test_letters[i])


# With enumerate
# It's only one line and still makes a ton of sense.

new_arr = [letter for index,letter in test_letters if index % 2 == 0 and letter in enumerate(vowels)]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;enumerate&lt;/code&gt; is an incredibly useful function, and anyone learning Python should be using it.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What has been your worst "How did I forget that!?" moment?</title>
      <dc:creator>Micah Gilbert</dc:creator>
      <pubDate>Wed, 03 Jul 2019 18:51:07 +0000</pubDate>
      <link>https://dev.to/micahsgilbert/what-has-been-your-worst-how-did-i-forget-that-moment-2jel</link>
      <guid>https://dev.to/micahsgilbert/what-has-been-your-worst-how-did-i-forget-that-moment-2jel</guid>
      <description>&lt;p&gt;Any time where you made some mistake or forgot some crucial and obvious thing you should have done. &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Some of the (slightly) lesser known CSS features</title>
      <dc:creator>Micah Gilbert</dc:creator>
      <pubDate>Wed, 19 Jun 2019 18:05:40 +0000</pubDate>
      <link>https://dev.to/micahsgilbert/some-of-the-slightly-lesser-known-css-features-3jjj</link>
      <guid>https://dev.to/micahsgilbert/some-of-the-slightly-lesser-known-css-features-3jjj</guid>
      <description>&lt;p&gt;The features listed here are from &lt;a href="https://2019.stateofcss.com/features/"&gt;The State of CSS 2019&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scroll Snap
&lt;/h2&gt;

&lt;p&gt;Scroll snap is just what the name says. It makes the user scrolling "snap" to certain points on the page.&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/micahsgilbert/embed/Yopxze?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
More info &lt;a href="https://css-tricks.com/practical-css-scroll-snapping/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  overscroll-behavior
&lt;/h2&gt;

&lt;p&gt;Normally, when an element with a scrollbar is scrolled all the way down or up, then a parent element will begin to scroll as well. &lt;code&gt;overscroll-behavior&lt;/code&gt; can prevent this by not allowing the parent element to scroll.&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/micahsgilbert/embed/qzqXoo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
(The demo here is somewhat finnicky. You have to be scrolling on an area without text, and stop scrolling when you hit the bottom, then start again.)&lt;/p&gt;

&lt;p&gt;More info &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  will-change
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;will-change&lt;/code&gt; is a strange one. It is a way to tell browsers that a property of an element will change. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/will-change"&gt;Mozilla documentation&lt;/a&gt; states that it should only be used when performance problems are seen, and not in anticipation of a performance issue.&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/micahsgilbert/embed/EBNwxL?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
This is probably a useless demo, but it shows that sometimes rapid changes could require a will-change tag.&lt;/p&gt;
&lt;h2&gt;
  
  
  @supports
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;@supports&lt;/code&gt; is a query that checks if a browser supports a certain feature.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@supports (display: grid) {
  /* code here that gives the grid display instructions */
}

@supports not (overscroll-behavior) {
  /* If it doesn't support overscroll-behavior */
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;More info &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@supports"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing modes
&lt;/h2&gt;

&lt;p&gt;This is simply used to change the direction of the text in an element. It's an alternative to rotation of a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag. &lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/micahsgilbert/embed/OebxBp?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
More info &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;I hope you learned a new thing or two with some of the newer CSS features that are out there. If there were any I missed or that you want to add, put them in the comments!&lt;/p&gt;

</description>
      <category>css</category>
    </item>
  </channel>
</rss>
