<?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 Bill Fienberg on Medium]]></title>
        <description><![CDATA[Stories by Bill Fienberg on Medium]]></description>
        <link>https://medium.com/@BillFienberg?source=rss-b70e7e5ddb69------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hI356vcieIZ_lu9_Ha-VEw.jpeg</url>
            <title>Stories by Bill Fienberg on Medium</title>
            <link>https://medium.com/@BillFienberg?source=rss-b70e7e5ddb69------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:12:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@BillFienberg/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[Soft Skills for Software Developers]]></title>
            <link>https://medium.com/@BillFienberg/soft-skills-for-software-developers-f7314cb72d6e?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7314cb72d6e</guid>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Wed, 15 Apr 2020 08:22:33 GMT</pubDate>
            <atom:updated>2020-04-15T08:22:33.422Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been working as a software developer since 2015, and in that time, I’ve heard a bunch of different stereotypes about software developers. A common theme throughout many of those stereotypes focuses on software developers’ people skills, or lack thereof. As is the case with most stereotypes, I’ve met far more people that shatter the stereotype than I have that reinforce it.</p><p>That being said, there are some social skills I’ve learned (often the hard way) that I think might be helpful to view through the perspective of a software developer.</p><p>For context, I’ve had an assortment of jobs before I started my career as a coder, and many of them were customer-facing. The list includes:</p><ul><li>Food service</li><li>Roofer</li><li>Unloader/sorter/loader at a shipping company</li><li>Retail</li><li>Lab tech</li><li>Baby photographer</li><li>Brand ambassador at promotional events</li><li>Business intern</li><li>Tech support</li><li>Software developer</li></ul><p>In addition to working a variety of customer-facing jobs, I also attempted standup comedy for a couple years during college, read dozens of self-help books, and my partner is a therapist. So for better or worse, I’ve had a unique combination of social experience.</p><p>Without further ado, here are some of the social skills I think most people, but especially software engineers, could benefit from.</p><h3>Know your audience</h3><p>This skill is likely the most obvious, but it’s worth reminding. As a struggling open mic comedian, I learned first hand how important it is to know your audience. My jokes about college experiences failed to entertain blue-collar open mic crowds, just like my jokes about learning Brazilian Jiu Jitsu failed to entertain people that had never seen UFC.</p><p>I think knowing your audience is so important as a software developer because you often have to work directly with teammates from many different functions (design, product management, scrum, QA, sales, customer service, marketing, etc).</p><p>Hypothetical software examples</p><ul><li>A product owner likely doesn’t care what patch version of a dependency is being used.</li><li>A designer likely doesn’t care that you used an &lt;a&gt; element instead of a &lt;button&gt; element on the call to action that takes to the user to a different page.</li><li>A junior dev may not know what SOLID or Gang of Four means.</li><li>A backend dev may not care whether you’re using hooks or class components.</li><li>An executive may not care about tech debt unless you can assign a dollar value to it.</li></ul><h3>The “7%-38%-55% Rule” of communication</h3><blockquote>According to Mehrabian, the three elements account differently for our liking for the person who puts forward a message concerning their feelings: words account for 7%, tone of voice accounts for 38%, and body language accounts for 55% of the liking. — <a href="https://en.wikipedia.org/wiki/Albert_Mehrabian#Attitudes_and_congruence">https://en.wikipedia.org/wiki/Albert_Mehrabian#Attitudes_and_congruence</a></blockquote><p>I first heard about the 7–38–55 rule in community college, and I was blown away by it. The rule essentially says that your nonverbal communication often conveys more information than your word choice.</p><p>Since then, I’ve learned that there is some valid criticism of the experiment. However, I no longer focus as much on the specific percentages, and instead see the 7–38–55 rule as a valuable reminder to consider your tone, body language, and/or facial expressions, as much as your word choice.</p><p>Conversely, working as a software developer often involves communicating exclusively via text (Slack/text/email/PR comments/etc), which means it can be helpful to spend extra time on your word choice when tone, body language, and/or facial expressions are unavailable. If you’ve ever tried to convey sarcasm in a text message, you likely know how difficult it is to do without tone.</p><h3>I-statements and You-statements</h3><blockquote>In interpersonal communication, an <strong>I-message</strong> or <strong>I-statement</strong> is an assertion about the feelings, beliefs, values, etc. of the person speaking, generally expressed as a sentence beginning with the word “I”, and is contrasted with a “<strong>you-message</strong>” or “<strong>you-statement</strong>”, which often begins with the word “you” and focuses on the person spoken to. — <a href="https://en.wikipedia.org/wiki/I-message">https://en.wikipedia.org/wiki/I-message</a></blockquote><p>I forget how I learned about I-statements and You-statements, but being aware of the difference has helped me be more considerate with my word choice in both my personal and professional life.</p><p>When my partner would get frustrated with me for not cleaning enough, she’d often say, “You never clean the house!”. My initial reaction used to be taking it too literally, and replying with a more emotional response like, “What about when I cleaned the kitchen last weekend?!” However, when she says something like, “I get frustrated when I end up doing the majority of the cleaning around the house,” it feels less like an attack on me, and more like a subtle reminder of what I can do to help.</p><p>It took me a long time to learn that healthy conflict is an essential aspect of relationships, both personal and professional. And I’ve found that rephrasing my frustrations as I-statements helps me reduce the chance that my frustrations come off as attacks, which hopefully helps me keep those relationships in a healthy state.</p><p>Hypothetical software example</p><p><strong>You-statement</strong>: “You didn’t write any tests for your code!”<br><strong>I-statement</strong>: “I get frustrated when I have to write tests for code that should have already had tests.”</p><h3>Features and benefits</h3><p>I learned about the difference between features and benefits when working at a retail electronics store. I once helped a customer that wanted blurry backgrounds in the pictures of her kids (this was before smartphones were ubiquitous, and long before portrait mode). After learning about her photography experience, I realized she didn’t know about aperture or its impact on depth of field. So it would have been pointless for me to highlight the aperture specs of various lenses. Instead, I grabbed a couple different lenses, and took a handful of pictures of the same subject so she could see for herself the benefit of a lens with a lower aperture.</p><p>As a software developer, there are lots of technical concepts that are obvious to me, but completely unfamiliar to people I work with. Communicating specific features often means there are a lot of assumptions about what the recipient knows. However, communicating the benefits of those features often helps the recipient better understand why those features are worthwhile.</p><p>Hypothetical software example</p><p><strong>Feature</strong>: Prettier has a VS Code extension.<br><strong>Benefit</strong>: If you use Prettier’s VS Code extension, then you don’t have to manually fix annoying formatting problems, like semicolons or indentation, in your JavaScript.</p><h3>“You catch more flies with honey than you do with vinegar.”</h3><p>I think I first heard this quote as a little kid, and I’m aware that a quote is not technically a social skill. If anything, I would classify this quote as positivity.</p><p>I understand that some people are more introverted, and would prefer to be left alone while working in isolation, but most people have to work with other people. And not only is working with other people pretty much inevitable, but it’s likely you may have to work with the same people frequently. And even after people move on to other opportunities, it’s possible you might work with the same person at a future job. Therefore, it’s in your best interest to make at least a little effort to maintain a positive relationship with the people you work with.</p><p>Hypothetical software example</p><p><strong>Neutral relationship</strong>: I asked DevOps to spin up a separate environment for that long-lived feature branch so we don’t have to keep deploying to it manually, and they added a ticket to the backlog. <br><strong>Positive relationship</strong>: I asked DevOps to spin up a separate environment for that long-lived feature branch so we don’t have to keep deploying to it manually, and it was up and running by the end of the day.</p><h3>Cite your sources</h3><p>Technically, I learned to cite my sources whenever I started bibliographies for school papers. But I don’t think I fully embraced the concept of citing my sources until I started working as a software developer.</p><p>Citing your sources as a software developer can have many benefits. It can increase your credibility. It’s often easier to include the source when it’s right in front of you than it is if somebody asks you for it later. It can spark discussions about conflicting and/or outdated sources. And it gives people a chance to continue learning on their own.</p><p>While it may not always be practical to cite a source in verbal communication, I’ve found it very helpful to include links in much of my written communication.</p><p>Hypothetical software example</p><p><strong>Bad</strong>: You’re modifying your React state directly. Don’t do that!<br><strong>Good</strong>: Are you aware that this line directly modifies the React state? According to the <a href="https://reactjs.org/docs/state-and-lifecycle.html#do-not-modify-state-directly">React docs</a>, “Do Not Modify State Directly.”</p><h3>Open-ended questions vs closed-ended questions</h3><blockquote>A closed-ended question is made up of pre-populated answer choices for the respondent to choose from; while an open-ended question asks the respondent to provide feedback in their own words. — <a href="https://www.surveymonkey.com/mp/comparing-closed-ended-and-open-ended-questions/">https://www.surveymonkey.com/mp/comparing-closed-ended-and-open-ended-questions/</a></blockquote><p>I first learned about open-ended and closed-ended questions while working retail. Once I understood the difference between open and closed questions, I realized that some of the awkward pauses I encountered in conversations were due to closed-ended questions. By asking more open-ended questions, I was able to learn more about the person I was communicating with, which often helped identify the root problem they were hoping to solve.</p><p>As a software developer, open-ended questions often help identify bugs , uncover missing requirements, and/or envision better solutions.</p><p>Hypothetical software example</p><p><strong>Closed-ended</strong>: Do you like Redux?<br><strong>Open-ended</strong>: What are your thoughts about Redux?</p><h3>Rephrase objections</h3><blockquote>Take your time and keep asking questions until you truly understand the reason for the objection and they’ve satisfied your curiosity. Finally, restate what you heard in your own words and ask them to confirm that you’ve understood them correctly. — <a href="https://www.salesforce.com/blog/2013/03/6-techniques-for-effective-objection-handling.html">https://www.salesforce.com/blog/2013/03/6-techniques-for-effective-objection-handling.html</a></blockquote><p>I learned about rephrasing objections while working retail, and I’ve found this skill to be helpful at identifying root causes and/or broadening the scope of communication.</p><p>As a software developer, it’s possible that your approach is technically correct, while your teammates objection is equally valid. In those situations, one or more parties might be operating under assumptions that haven’t been communicated, and/or with different contexts. By rephrasing objections instead of challenging them, you have a better chance at achieving a shared understanding.</p><p>Hypothetical software example</p><p><strong>Objection</strong>: We can roll our own version of this. We don’t need to install another dependency.<br><strong>Defensive response</strong>: It’s not a big deal. It’s only 12.7 kB!<br><strong>Rephrased objection</strong>: I agree that we are capable of rolling our own version of this without installing another external dependency. That being said, how do you think the long-term costs of building and maintaining our own solution compare to the long-term costs of adding 12.7kB to our bundle size?</p><h3>Under-promise, over-deliver</h3><p>I think I first internalized the concept of under-promise, over-deliver while working in tech support. If I told a customer to expect the best-case timeline, and it actually took longer, then the customer was understandably upset. If I told a customer that their issue should definitely be resolved by a certain point, and would be likely resolved earlier than that, then the customer would be less likely to be upset when it actually got resolved before the worst-case timeline.</p><p>It’s worth mentioning that perfect accuracy may be preferred over faster timelines. While working as a logistics intern, I learned that a truck arriving several hours early wasn’t always a good thing because the workers that would unload the truck may not start work until the expected arrival time. Obviously, perfect accuracy is not possible 100% of the time.</p><p>Additionally, I’ve encountered people that have a negative perception of under-promise, over-deliver. I’ve heard people refer to it as sandbagging. I acknowledge that sandbagging is a thing, and acknowledge that extreme under-promising is a form of sandbagging. However, I think there’s a big difference between a cautious commitment and a suspiciously low commitment.</p><p>Hypothetical software example</p><p><strong>Over-promise, under-deliver</strong>: I was torn between estimating this ticket at a 3 or a 5, but I felt optimistic about it, so I went with a 3. Unfortunately, it ended up being more complex than I expected, so I wasn’t able to get to that extra ticket we committed to this sprint. <br><strong>Under-promise, over-deliver</strong>: I was torn between estimating this ticket at a 3 or a 5, and I wanted to err on the side of caution, so I went with a 5. It ended up being complex, but I think a 5 was accurate. If we had estimated this at a 3, and committed to an extra ticket, I don’t think we would have completed the extra ticket this sprint.</p><h3>Conclusion</h3><p>Thank you for making it this far. Hopefully, at least one of these ideas was valuable to you. Feel free to leave a comment, and/or follow me on <a href="https://twitter.com/billfienberg">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7314cb72d6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Avoiding Unit Test Whac-A-Mole]]></title>
            <link>https://medium.com/@BillFienberg/avoiding-unit-test-whac-a-mole-2d0ca71bc1b1?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d0ca71bc1b1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Tue, 17 Apr 2018 14:15:56 GMT</pubDate>
            <atom:updated>2018-04-17T14:15:56.613Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jest, Reducers, and Named Imports/Exports</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FJJYY0pe9xVcru%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FJJYY0pe9xVcru%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FJJYY0pe9xVcru%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="328" frameborder="0" scrolling="no"><a href="https://medium.com/media/4899d79daef7723859d2d7465a8722de/href">https://medium.com/media/4899d79daef7723859d2d7465a8722de/href</a></iframe><p>I started using React in 2015, but I didn’t begin habitually testing my React code until I started using <a href="https://github.com/facebook/create-react-app">Create React App</a> (CRA).</p><p>For a long time, I treated writing tests as something that I knew I should do, but didn’t actually do in practice. Prior to CRA, my excuse was “But I only have limited time to code, and I don’t want to spend my free time configuring infrastructure for testing.” On one hand, it wasn’t completely invalid. On the other, it was still unacceptable.</p><p>However, when I saw that <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests">CRA shipped with testing configured out of the box,</a> I both cursed and praised it. I simultaneously thought, “Oh cool, now I have no reason not to write tests,” and “Oh crap, now I have no reason not to write tests.”</p><p>I also started learning <a href="https://github.com/reactjs/redux/">Redux</a> via <a href="https://egghead.io/instructors/dan-abramov">Dan Abramov’s courses on Egghead.io</a> around that time, and was happy to try out my new testing knowledge on a popular library that is known for being easy to test.</p><p>Fast forward to today, and I have observed a small annoyance with my unit tests concerning a reducer’s default state. For this blog post, I have repurposed the <a href="https://redux.js.org/basics/example-todo-list">todos example from the Redux documentation</a> to illustrate the problem.</p><p>Normally, the default state for the todos reducer was [], and the default state for the visibilityFilter reducer was &#39;SHOW_ALL&#39;. And I wrote unit tests to assert that those default states were correct.</p><pre>// todos.test.js<br>import reducer from &quot;./todos&quot;;<br>describe(`the todos reducer`, () =&gt; {<br>  it(`should return the default state`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = [];<br>    expect(reducer(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><pre>// visibilityFilter.test.js<br>import reducer from &quot;./visibilityFilter&quot;;<br>describe(`the visibilityFilter reducer`, () =&gt; {<br>  it(`should return the default state`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = &#39;SHOW_ALL&#39;;<br>    expect(reducer(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><pre>// index.test.js<br>import index from &quot;./index&quot;;<br>describe(`the index reducer`, () =&gt; {<br>  it(`should return the default state for both`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = {<br>      todos: [],<br>      visibilityFilter: &#39;SHOW_ALL&#39;<br>    };<br>    expect(index(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><p>However, sometimes when I was working locally, I added temporary todos to speed up my workflow so I didn’t have to manually create them via the UI.</p><pre>// normal<br>const defaultState = []<br>const todos = (state = defaultState, action) =&gt; {...};</pre><pre>// temporary<br>const defaultState = [<br>  { text: &quot;Consider using Redux&quot;, completed: true },<br>  { text: &quot;Keep all state in a single tree&quot;, completed: false }<br>];<br>const todos = (state = defaultState, action) =&gt; {...};</pre><p>When those temporary todos were added, it caused my unit tests for the default state to fail. I knew why it failed, and I knew how to fix it, but I still wasn’t happy to see that my tests was failing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ow0_5qv4fD3Tg55e_yhtBQ.gif" /></figure><p>Initially, I temporarily modified the test assertion to match the default value in the reducer.</p><pre>// todos.test.js<br>import reducer from &quot;./todos&quot;;<br>describe(`the todos reducer`, () =&gt; {<br>  it(`should return the default state`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = [<br>      { text: &quot;Consider using Redux&quot;, completed: true },<br>      { text: &quot;Keep all state in a single tree&quot;,completed: false }<br>    ];<br>    expect(reducer(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><pre>// index.test.js<br>import index from &quot;./index&quot;;<br>describe(`the index reducer`, () =&gt; {<br>  it(`should return the default state for both`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = {<br>      todos: [<br>        { text: &quot;Consider using Redux&quot;, completed: true },<br>        { text: &quot;Keep all state in a single tree&quot;,completed: false }<br>      ],<br>      visibilityFilter: &#39;SHOW_ALL&#39;<br>    };<br>    expect(index(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><p>However, that proved extremely inconvenient because I had to make the same change in two different places, and I would have to remember to revert it when I was done.</p><blockquote>I wish I could use the same value in the test that I use in the code… Oh wait, I can.</blockquote><p>I realized that I could use an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_named_exports">ES6 named export</a> to export the defaultState that I defined in the reducer, and import it in the tests. By doing that, I was able to comment out the sample todos for production, and uncomment them for local. And then I was able to import the defaultState in the test, while the test passed even with the sample data.</p><pre>// todos.js (PROD)<br>export const defaultState = [<br>  //  { text: &quot;Consider using Redux&quot;, completed: true },<br>  //  { text: &quot;Keep all state in a single tree&quot;, completed: false }<br>];</pre><pre>// todos.js (LOCAL)<br>export const defaultState = [<br>  { text: &quot;Consider using Redux&quot;, completed: true },<br>  { text: &quot;Keep all state in a single tree&quot;, completed: false }<br>];</pre><pre>// todos.test.js<br>import reducer, { defaultState } from &quot;./todos&quot;;<br>describe(`the todos reducer`, () =&gt; {<br>  it(`should return the default state`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = defaultState;<br>    expect(reducer(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><p>That approach worked for the individual reducer tests, but it did not work for the index reducer test.</p><pre>// index.test.js<br>import index from &quot;./index&quot;;<br>import { defaultState } from &quot;./todos&quot;;<br>import { defaultState } from &quot;./visibilityFilter&quot;; // Duplicate declaration &quot;defaultState&quot;</pre><pre>describe(`the index reducer`, () =&gt; {<br>  it(`should return the default state for both`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = {<br>      todos: defaultState,<br>      visibilityFilter: defaultState<br>    };<br>    expect(index(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><p>Since both reducers exported a variable named defaultState, the test threw a Duplicate declaration “defaultState” error. To fix it, I needed to use an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Import_an_export_with_a_more_convenient_alias">ES6 named import with an alias</a>.</p><pre>// index.test.js<br>import index from &quot;./index&quot;;<br>import { defaultState as defaultTodosState } from &quot;./todos&quot;;<br>import { defaultState as defaultVisibilityFilterState } from &quot;./visibilityFilter&quot;;</pre><pre>describe(`the index reducer`, () =&gt; {<br>  it(`should return the default state for both`, () =&gt; {<br>    const state = undefined;<br>    const action = {};<br>    const expectedOutput = {<br>      todos: defaultTodosState,<br>      visibilityFilter: defaultVisibilityFilterState<br>    };<br>    expect(index(state, action)).toEqual(expectedOutput);<br>  });<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t8_94OaaT5ZDwBSiOTyIEA.gif" /></figure><p>I did consider that it may not be a good idea to let the tests pass when I have local data in the default state. However, that is a risk I was willing to accept for a small, personal project.</p><p>The full code for the blog post can be found on <a href="https://github.com/billfienberg/blog-about-testing-default-reducer-state/">GitHub</a> and/or <a href="https://codesandbox.io/s/wykjx9nq0k">CodeSandbox</a>.</p><p>Feel free to leave a comment and/or follow me on <a href="http://instagram.com/billfienberg">Instagram</a> or <a href="https://twitter.com/billfienberg/">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d0ca71bc1b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[D’oh: That’s not supposed to be in my PR]]></title>
            <link>https://medium.com/@BillFienberg/doh-that-s-not-supposed-to-be-in-my-pr-8c2c1fffe381?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c2c1fffe381</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Thu, 15 Mar 2018 17:55:42 GMT</pubDate>
            <atom:updated>2018-03-15T18:18:44.178Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been using git since 2014, and I try to use the command line as much as possible because it gives me a false sense of competency. However, there have been a handful of occasions where I opened a Pull Request, and realized that I included changes to a file that I didn’t intend to push. In every instance, I was able to remove the modified file from the PR, but I felt like it took way more effort than necessary… Until now.</p><pre>Syntax:<br>git checkout {branch} -- {path/to/file}</pre><pre>Actual Example:<br>git checkout origin/master -- src/index.js</pre><p>I’m pretty sure I tried to google it previously, but gave up after I couldn’t figure it out in less than five minutes. Fortunately, this time I must have searched for the right phrase because I found a StackOverflow question titled “<a href="https://stackoverflow.com/questions/39459467/remove-a-modified-file-from-pull-request">Remove a modified file from pull request</a>.”</p><p>I opened the link and skimmed the question to make sure it was trying to address the same problem I was experiencing. Then I scrolled down, and found <a href="https://stackoverflow.com/a/44355701/3343716">a simple answer with a reasonable number of upvotes</a>.</p><p>I ran the command with my branch and file name, and sure enough, it generated a staged change to revert that file back to the state of the specified branch. I committed that staged change, and pushed it up to my PR. When I refreshed my PR, that file was no longer listed under the Files Changed tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*4IWlgP_s2k93Tp86yqpKYg.gif" /></figure><p>I’m bummed that it took me so long to learn something so simple, but I’d rather learn the hard way that not learn at all.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c2c1fffe381" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tunnels and Proxies and Headers, Oh My!]]></title>
            <link>https://medium.com/@BillFienberg/tunnels-and-proxies-and-headers-oh-my-5088e1ee11fa?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/5088e1ee11fa</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ngrok]]></category>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Mon, 23 Oct 2017 13:23:19 GMT</pubDate>
            <atom:updated>2017-10-23T13:23:19.136Z</atom:updated>
            <content:encoded><![CDATA[<p>Using ngrok to tunnel to a local client that is proxied to a local server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*uTkHSOzZFxT6YEgTLe9ubA.gif" /></figure><p>After using <a href="https://github.com/facebookincubator/create-react-app">Facebook’s Create React App</a> for several months on multiple projects, I think it is as awesome as I am lazy.</p><p>I started using it to build simple front-end prototypes of whatever came out of my ADD-powered lottery ball dispenser of a brain.</p><p>Once I became familiar with how to use it on the front-end, I wanted to learn how to connect it to a server. Fortunately, the internet already had some solutions to that problem (<a href="https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/">article from Fullstack React</a>, <a href="https://daveceddia.com/create-react-app-express-backend/">blog from Dave Ceddia</a>, <a href="https://medium.com/@bryantheastronaut/react-getting-started-the-mern-stack-tutorial-feat-es6-de1a2886be50">blog from Bryan Gilbraith</a>, etc).</p><p>After I completed <a href="https://daveceddia.com/create-react-app-express-production/">Dave Ceddia’s second blog post on the topic</a>, I created my own app that would closely follow the same pattern.</p><p>I decided to create an app to display the current and forecasted weather for multiple cities — wait for it — at the same time. And since I was going to have to think of a subdomain for this thing eventually (because I can never remember the random subdomains that <a href="https://www.heroku.com/">Heroku</a> generates during a deploy), I settled on <a href="http://multiweather.herokuapp.com/">MultiWeather</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Kv8a18x6FWTlu6StiHYSVg.gif" /></figure><p>Now that I had an idea of what (made up) problem I wanted solve, and what I would call my solution, I had to figure out what it would look like and/or do.</p><p>Despite design not being a proficiency of mine, I envisioned each city would have its own card, and all the cards would live in a responsive grid. And it seemed like a good opportunity to use <a href="https://medium.com/@BillFienberg/dissecting-an-app-e874275222be">CSS Grid Layout</a>, simply because I didn’t need to worry about <a href="http://caniuse.com/#feat=css-grid">browser support</a> on a side project.</p><p>After building the basic card layout, I decided to use <a href="https://openweathermap.org/">Open Weather Map</a> for my data. I created an account, and generated an API key. However, I made a rookie mistake, and tried to call the API directly from my client-side code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*31x-tArEFx0hXHovi3w6hg.jpeg" /></figure><p>I forgot about <a href="https://daveceddia.com/access-control-allow-origin-cors-errors-in-angular/">CORS</a>, so then I moved my Open Weather Map API call into the server file. However, it still wasn’t working. Since my Webpack dev server was running on port 3000, and my Express API server was running on port 5000, I was still violating CORS. In the Fullstack React article, there is a great diagram of this in a section called <a href="https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/#the-rub-">The Rub</a>.</p><p>The solution was to <strong>proxy</strong> the request from the Webpack dev server to Express API Server. Fortunately, that only took one line of code in client/package.json.</p><pre>{<br>  ...<br>  ”proxy”: “<a href="http://localhost:5000/">http://localhost:5000</a>&quot;<br>}</pre><p>After configuring the client to properly proxy the request to the server, the API call started working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*HNhyM_sn8e-jStAptPVAwA.gif" /></figure><p>Now that I had the app working locally, I wanted to see what it looked like on my actual phone, instead of <a href="https://developers.google.com/web/tools/chrome-devtools/device-mode/">Chrome’s Device Mode</a>.</p><p>Several years ago, I learned about a tool called <a href="https://ngrok.com/">ngrok</a> from a <a href="https://www.twilio.com/blog/2013/10/test-your-webhooks-locally-with-ngrok.html">Twilio blog post</a>. According to the website, “ngrok creates a secure public URL to a local webserver on your machine.”</p><p>I tried to use the same command (ngrok http 3000) that I used on previous projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cBFJTSUFqHVy7aZbJ64GA.png" /><figcaption>Invalid Host Header</figcaption></figure><p>However, it didn’t work this time. And I had no idea why. So I did what I normally do when I have no idea why my code isn’t working; Google.</p><p>I typed “ngrok invalid host header” into Google, and the first result was a <a href="https://stackoverflow.com/questions/45425721/invalid-host-header-when-ngrok-tries-to-connect-to-react-dev-server">Stack Overflow question</a>. I opened the link, scanned the question, and scrolled to the <a href="https://stackoverflow.com/a/45494621/3343716">answer</a>. And then I felt a wave of relief when the answer was brief, and had a reasonable number of upvotes.</p><pre>ngrok http --host-header=rewrite 3000</pre><p>I typed that into <a href="https://www.iterm2.com/">iTerm2</a>, and then navigated to the URL generated by ngrok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tLT4AsBACu6aKOyhmXDH4w.png" /><figcaption>Success</figcaption></figure><p>While I’m bummed that it took me as long as it did to grasp tunnels/proxy requests, I’d rather learn the hard way than not learn at all.</p><p>Feel free to leave comment (please don’t be a jerk), follow me on <a href="https://twitter.com/billfienberg">Twitter</a>, and/or <a href="https://www.instagram.com/billfienberg/">Instagram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5088e1ee11fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bitwise Operator? I Hardly Know Her!]]></title>
            <link>https://medium.com/@BillFienberg/bitwise-operator-i-hardly-know-her-b7951c3a3a59?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7951c3a3a59</guid>
            <category><![CDATA[bitwise]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[bitwise-operator]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Wed, 30 Aug 2017 13:47:22 GMT</pubDate>
            <atom:updated>2017-08-30T13:47:22.016Z</atom:updated>
            <content:encoded><![CDATA[<p>NOT</p><blockquote>“Tilde?! What does that even mean?”</blockquote><p>I was recently working on the following coding challenge in <a href="https://codefights.com/signup/7fZ8GNv8NQvhAKMf8/main">CodeFights</a>:</p><blockquote>Given a string s, find and return the first instance of a non-repeating character in it. If there is no such character, return &#39;_&#39;. Write a solution that only iterates over the string once and uses O(1) additional memory.</blockquote><p>Here was my naive solution:</p><pre>function firstNotRepeatingCharacter(s) {<br>  const record = {}<br>  for (let i = 0; i &lt; s.length; i++) {<br>    if (record[s[i]]) {<br>      record[s[i]] += 1<br>    } else {<br>      record[s[i]] = 1<br>    }<br>  }<br>  for (let key in record) {<br>    if (record[key] === 1) {<br>      return key<br>    }<br>  }<br>  return &#39;_&#39;<br>}</pre><p>After all my tests passed, I wanted to see how other people solved it. I clicked on the tab to see other solutions, and found the JavaScript solution with the most votes.</p><pre>firstNotRepeatingCharacter = s =&gt; {<br>    r = {}<br>    for (e of s)<br>        r[e] = -~r[e]<br>    for (e in r)<br>        if (r[e] == 1)<br>            return e<br>    return &#39;_&#39;<br>}</pre><p>I read the solution, got confused by the fourth line, and then had that bittersweet moment where I thought, “It looks like I get to learn something new.”</p><p>I didn’t recognize the tilde, so I immediately Googled “js tilde.” I was relieved when I saw a result from MDN Web Docs.</p><p>Apparently, this sorcery had a name, and that name is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators">Bitwise Operators</a>. When the page loaded, I read the summary at the top of the page:</p><blockquote><strong>Bitwise operators</strong> treat their operands as a sequence of 32 bits (zeroes and ones), rather than as decimal, hexadecimal, or octal <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">numbers</a>. For example, the decimal number nine has a binary representation of 1001. Bitwise operators perform their operations on such binary representations, but they return standard JavaScript numerical values.</blockquote><blockquote>“That’s cool, but I still don’t know what the tilde is/does.”</blockquote><p>Below the description, there was a chart of a bunch of operators that I pretty much never use on a daily basis. I scanned the chart, and clicked on the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT">Bitwise NOT link</a> next to the tilde example. The description read:</p><blockquote>Performs the NOT operator on each bit. NOT a yields the inverted value (a.k.a. one&#39;s complement) of a.</blockquote><blockquote>“Again, that’s cool, but I still don’t know what the tilde is/does.”</blockquote><p>Then there was the following code sample:</p><pre> 9 (base 10) = 00000000000000000000000000001001 (base 2)<br>               --------------------------------<br>~9 (base 10) = 11111111111111111111111111110110 (base 2) = -10 (base 10)</pre><blockquote>“I don’t know if you’re trying to confuse me, but if you are, it’s working. I’m going to sleep. I’ll try again tomorrow.”</blockquote><p>I read that code sample, and decided that was a good stopping for that night (I think it was around 1am). The following day, I decided to try another approach.</p><blockquote>“Instead of reading the docs and scary code samples, I’m just going to go play in the browser.”</blockquote><p>I opened up a <a href="/service/about:blank">blank browser tab</a>, opened the JavaScript console, and pasted the solution where I originally saw the tilde. I then slowly analyzed each line one at a time.</p><pre>firstNotRepeatingCharacter = s =&gt; { // define function and args<br>    r = {} // declare object to keep track of counts<br>    for (e of s) // iterate through each character of the string<br>        r[e] = -~r[e] // ¯\_(ツ)_/¯<br>    for (e in r)<br>        if (r[e] == 1)<br>            return e<br>    return &#39;_&#39;<br>}</pre><blockquote>“When in doubt, add some logging.”</blockquote><p>I added a bunch of console.log&#39;s to see what was happening.</p><pre>firstNotRepeatingCharacter = s =&gt; {<br>    r = {}<br>    for (e of s) {<br>        console.log(&quot;--------------&quot;)<br>        console.log(&quot;r: &quot;, r)<br>        console.log(&quot;e: &quot;, e)<br>        console.log(`r[${e}]: `, r[e])<br>        r[e] = -~r[e]<br>    }<br>    console.log(&quot;r: &quot;, r)<br>    for (e in r)<br>        if (r[e] == 1)<br>            return e<br>    return &#39;_&#39;<br>}</pre><p>Then I called the function with the input from the first test case.</p><pre>firstNotRepeatingCharacter(&#39;abacabad&#39;)<br>--------------<br>r:  {}<br>e:  a<br>r[a]:  undefined<br>--------------<br>r:  {a: 1}<br>e:  b<br>r[b]:  undefined<br>--------------<br>r:  {a: 1, b: 1}<br>e:  a<br>r[a]:  1<br>--------------<br>r:  {a: 2, b: 1}<br>e:  c<br>r[c]:  undefined<br>--------------<br>r:  {a: 2, b: 1, c: 1}<br>e:  a<br>r[a]:  2<br>--------------<br>r:  {a: 3, b: 1, c: 1}<br>e:  b<br>r[b]:  1<br>--------------<br>r:  {a: 3, b: 2, c: 1}<br>e:  a<br>r[a]:  3<br>--------------<br>r:  {a: 4, b: 2, c: 1}<br>e:  d<br>r[d]:  undefined<br>r:  {a: 4, b: 2, c: 1, d: 1}</pre><blockquote>“Somehow, that tilde is building up a count of occurrences.”</blockquote><p>After looking at the logs, the tilde started making a little bit of sense.</p><p>I logged a line of dashes to easily differentiate between the iterations, the state of the object, r, the current character of the string, e, and the value r[e]. Then after the loop was completed, I logged the ending state of the object, r.</p><p>Iteration #1: r is {}, e is &#39;a&#39;, and r[a] is undefined. Makes sense.<br>Iteration #2: r is {a: 1}, e is &#39;b&#39;, and r[b] is undefined. Makes sense.<br>Iteration #3: r is {a: 1, b: 1}, e is &#39;a&#39;, and r[a] is 1. Why is it 1?</p><p>So then I added another console.log to understand why r[a] equals 1.</p><pre>firstNotRepeatingCharacter = s =&gt; {<br>    r = {}<br>    for (e of s) {<br>        console.log(&quot;--------------&quot;)<br>        console.log(&quot;r: &quot;, r)<br>        console.log(&quot;e: &quot;, e)<br>        console.log(`r[${e}]: `, r[e])<br>        console.log(`~r[${e}]`, ~r[e])<br>        r[e] = -~r[e]<br>    }<br>    console.log(&quot;r: &quot;, r)<br>    for (e in r)<br>        if (r[e] == 1)<br>            return e<br>    return &#39;_&#39;<br>}</pre><p>Then I called the function with the same input as the previous run.</p><pre>firstNotRepeatingCharacter(&#39;abacabad&#39;)<br>--------------<br>r:  {}<br>e:  a<br>r[a]:  undefined<br>~r[a] -1<br>--------------<br>r:  {a: 1}<br>e:  b<br>r[b]:  undefined<br>~r[b] -1<br>--------------<br>r:  {a: 1, b: 1}<br>e:  a<br>r[a]:  1<br>~r[a] -2<br>--------------<br>r:  {a: 2, b: 1}<br>e:  c<br>r[c]:  undefined<br>~r[c] -1<br>--------------<br>r:  {a: 2, b: 1, c: 1}<br>e:  a<br>r[a]:  2<br>~r[a] -3<br>--------------<br>r:  {a: 3, b: 1, c: 1}<br>e:  b<br>r[b]:  1<br>~r[b] -2<br>--------------<br>r:  {a: 3, b: 2, c: 1}<br>e:  a<br>r[a]:  3<br>~r[a] -4<br>--------------<br>r:  {a: 4, b: 2, c: 1}<br>e:  d<br>r[d]:  undefined<br>~r[d] -1<br>r:  {a: 4, b: 2, c: 1, d: 1}</pre><blockquote>“~undefined === -1? What a country?!” — Dr. Nick</blockquote><p>The new logs let me clearly see what the tilde was doing.</p><pre>~undefined === -1 // true<br>~1 === -2         // true<br>~2 === -3         // true<br>~3 === -4         // true</pre><p>When applied to an int, the tilde seemed like it was incrementing the int by one, and then multiplying the incremented int by -1.</p><p>I now realize that if I had read the entire section from the documentation, instead of giving up and going to bed, I would have seen this explanation much sooner.</p><blockquote>Bitwise NOTing any number x yields -(x + 1). For example, ~5 yields -6.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*83xwLNyPtCOkRcKXl4fXhA.gif" /></figure><p>Once I understood that, I was able to understand where the character counts were coming from.</p><p>If ~1 === -2, then -(~1) === 2.</p><p>And once I understood where the character counts were coming from, I was able to understand where the return value was coming from.</p><pre>for (e in r)       // iterate through each character:count pair<br>  if (r[e] == 1)   // if that character&#39;s count equals 1<br>    return e       // return that character<br>return &#39;_&#39;         // if no character counts equal 1, return &#39;_&#39;</pre><p>While I understood the solution, I wanted to try rewriting it to see if I could make it cleaner.</p><p>I pasted the solution in my text editor, and saved the file. Since I recently started using <a href="https://github.com/prettier/prettier">prettier</a>, the code style automatically updated to match the style defined in my configuration (mostly default).</p><p>Here is the output after running the original solution through prettier:</p><pre>firstNotRepeatingCharacter = s =&gt; {<br>  r = {};<br>  for (e of s) r[e] = -~r[e];<br>  for (e in r) if (r[e] == 1) return e;<br>  return &#39;_&#39;;<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*ZtWsiy07GVNUwq-y5pukDQ.gif" /></figure><p>On one hand, I really like how short the solution is. But on the other hand, I don’t think it’s immediately clear what’s going on, especially if you’re not familiar with the Bitwise NOT operator. Additionally, it feels like a <a href="https://en.wikipedia.org/wiki/Code_golf">Code Golf</a> solution.</p><p>Bonus Learning: I showed this solution to two of my coworkers that are way smarter than me, and they immediately informed me about a thing called <a href="https://en.wikipedia.org/wiki/Two%27s_complement">Two’s complement</a>.</p><p>While I’m bummed that it took me as long as it did to understand what the tilde does in JavaScript, I’d rather learn the hard way than not learn at all.</p><p>Feel free to leave a comment, follow me on <a href="https://twitter.com/billfienberg">Twitter</a>, and/or follow me on <a href="https://www.instagram.com/billfienberg/">Instagram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7951c3a3a59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Grid Layout]]></title>
            <link>https://medium.com/@BillFienberg/dissecting-an-app-e874275222be?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/e874275222be</guid>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[codepen]]></category>
            <category><![CDATA[css-grid]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[grid-layout]]></category>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Fri, 25 Aug 2017 15:21:17 GMT</pubDate>
            <atom:updated>2017-10-11T04:29:17.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>Because Flexbox and Prime Numbers Don’t Get Along</h3><p>I recently deployed a tiny application to rip apart into several blog posts. You can see the app live on <a href="http://multiweather.herokuapp.com/">Heroku</a>, and you can read the code (some of which I’m ashamed of) on <a href="https://github.com/billfienberg/multiweather/">GitHub</a>.</p><p>After I made the decision to start blogging, I had to find something to write about. Instead of writing about any of my unfinished side projects, I decided to start yet another side project specifically for this blog because my brain is erratic.</p><p>I wanted to find a balance between stuff I’m familiar with, stuff I’m interested in, and stuff that doesn’t have many educational resources. For me, that Venn Diagram (TIL: there are two ‘n’s in Venn) might include Facebook’s create-react-app, JavaScriptPromise&#39;s, and CSS Grid Layout, respectively.</p><p>Once I decided what technologies/concepts I wanted to include in my app, I had to think of an idea that uses said technologies/concepts, AKA a solution in search of a problem.</p><p>I realized that this app would exist specifically for a blog, and I accepted that it would probably deliver little-to-no real-world value. In retrospect, that wasn’t the best way to motivate myself for a new project.</p><blockquote>¯\_(ツ)_/¯</blockquote><p>I tried to think of a trivial app that solves a problem, even if it was a negligible, 1st-world problem. And as a person that frequently checks the weather in other cities, I decided that it was annoying that I didn’t know of an app that displayed the current weather and 5-day forecast for multiple cities at the same time. So instead of Googling to see if it already existed, like a reasonable person, I did what many developers do, and immediately began building it.</p><p>I started by trying to imagine what it would look like*.</p><blockquote>*Full Disclosure: I am a developer, and not a designer.</blockquote><p>I imagined looking at my laptop screen, and seeing cards for each city. And then I imagined seeing those same cards stacked on top of each other on my phone and/or tablet screen. And then I scolded myself for being a hypocrite for designing the desktop view first when I claim to be an advocate for mobile-first design.</p><p>I started building the basic layout with my go-to layout technology; <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/">flexbox</a>.</p><p>You know that “I<a href="https://en.wiktionary.org/wiki/if_all_you_have_is_a_hammer,_everything_looks_like_a_nail">f all you have is a hammer, everything looks like a nail</a>” saying? Flexbox was my hammer. It’s not that flexbox was all I had, but more that I was trying to justify all the time I spent playing <a href="https://github.com/billfienberg/flexbox-froggy">Flexbox Froggy</a>.</p><p>Anyways, it didn’t take long before I hit a common flexbox speed bump; grid layouts.</p><blockquote>You can’t turn a flexbox into a responsive grid. — Tupac</blockquote><p>I imagine that it is technically possible to achieve a responsive grid layout using flexbox without media queries. But the more I tried, the more it felt like I was trying to force a round peg into a square hole.</p><p>Here is a .gif of the problem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ph5loD3t5oUtUXG4DglKpw.gif" /><figcaption>Flexbox and prime numbers don’t get along</figcaption></figure><p>Notice how there are seven cards, and how the last card flexes too much, thus filling the last row.</p><p>It worked when I only had one card… or two… or four, six, eight, nine, or ten. But it did not work well with three, five, seven, or eleven. Basically, it didn’t work for prime numbers greater than two.</p><p>You can see for yourself on <a href="https://codepen.io/billfienberg/full/jLpvZw">CodePen</a>. And if you get it working, please let me know.</p><p>I spent a little more time attempting to get it work. I even made a spreadsheet to calculate how many cards should fit per row for a given screen size, which I then used to calculate a dynamic max-width that would prevent the cards in the last row from over-flexing… And then I remembered that I don’t have access to the exact screen width inside the CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*epyMEhhr3SVU49kfbUgC4Q.gif" /></figure><p>Then I had an even dumber idea:</p><blockquote>Maybe I can get the screen width via JavaScript, calculate the max-width in the JavaScript, and set the max-width as an inline style for each card.</blockquote><p>Before I stopped to think about the merits of that idea, I already started implementing it.</p><p>Unsurprisingly, it didn’t work at all on my first attempt. I realized that it was not automatically recalculating when the browser was resized. So I Googled some solutions for browser resizing, and I found a cool npm package; <a href="https://github.com/FezVrasta/react-resize-aware">react-resize-aware</a>.</p><p>I read the documentation, imported the package, and wrapped my app with the component that passed the screen size to my code. And it worked… kind of.</p><p>The page would load with the initial styles from the CSS. And then the inline styles would kick in after the JavaScript ran, thus causing the cards to instantly change to the correct width. So it technically worked, but it was effectively unusable due to the surprise width change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*Kkv9aE1Ab9oDGfxDBSAhTA.gif" /></figure><p>By that point, I was confident that I was making everything more difficult than it needed to be. So I deleted all of that code and returned to the drawing board.</p><p>And then I had a crazy idea:</p><blockquote>Maybe flexbox isn’t the right tool for this job.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*jqQKtsY5wCV-09fuDx1H5g.gif" /></figure><p>I convinced myself that I didn’t just commit heresy, and began reviewing my options. And then I remembered that I completed all the exercises for <a href="https://github.com/billfienberg/grid-garden">CSS Grid Garden</a>, but forgot how to use it because I never actually applied it anywhere (<a href="http://caniuse.com/#feat=css-grid">because it’s not currently supported by modern Internet Explorer/Edge</a>).</p><blockquote>Maybe CSS Grid Layout would work for a responsive grid layout.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*sNvTfbPsjFFbU34cjM5wVQ.gif" /></figure><p>So while CSS Grid Layout isn’t a good fit for my job (we support modern Internet Explorer), it was a good fit for what I needed… because side project.</p><p>I made a couple earnest attempts to implement it on my own. However, I quickly decided I had wasted enough time on a layout for a side project that was only going to be used for a blog.</p><p>I found a <a href="https://stackoverflow.com/questions/43662552/getting-columns-to-wrap-in-css-grid">StackOverflow question</a> that looked relevant to the problem I was having. And I pretty much copy-pasted the <a href="https://stackoverflow.com/a/43664701/3343716">answer</a> into my code, and it worked.</p><p>You can view the basic layout on <a href="https://codepen.io/billfienberg/full/zdLEYX/">CodePen</a>.</p><p>While I’m bummed it took me as long as it did to get a responsive grid layout working, I would rather learn the hard way than not learn at all.</p><p>Feel free to leave comments (don’t be a jerk), follow me on <a href="https://twitter.com/billfienberg">Twitter</a> and/or follow me on <a href="https://www.instagram.com/billfienberg/">Instagram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e874275222be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Don’t Know SQL as Well as I Thought I Did]]></title>
            <link>https://medium.com/@BillFienberg/i-dont-know-sql-as-well-as-i-thought-i-did-3f592c7d2ea2?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f592c7d2ea2</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 17:59:35 GMT</pubDate>
            <atom:updated>2017-08-14T17:59:35.543Z</atom:updated>
            <content:encoded><![CDATA[<h4>“Oh yea, ORDER BY accepts multiple arguments?!”</h4><p>I think I wrote my first SQL query in 2013. Since then, I’ve used SQL for work, side-projects, curiosity, and sometimes even boredom.</p><blockquote>How many rows in that table contain profanity? 🤔. To SQL!</blockquote><p>Since I’ve employed this technology on a regular basis for several years now, I assumed that I had a decent understanding of how to use SQL, and more specifically, the ORDER BY keyword… Until recently.</p><p>A few months ago, I started using coding challenge sites, such as <a href="https://codefights.com/signup/7fZ8GNv8NQvhAKMf8/main">CodeFights</a> and <a href="https://www.hackerrank.com/">HackerRank</a>, as video game replacements. Instead of solving puzzles in Fallout, I thought I might as well solve puzzles in code. Since I already found a job that will pay me to write code, and I haven’t yet found a job that will pay me to play Skyrim (if you find one, please let me know), it seemed like a better use of my time.</p><p>I saw that there are database/SQL challenge series (<a href="http://grammarist.com/usage/series/">TIL: the word series can be either singular or plural depending on the context</a>), but I had always skipped them. Then I hit a speed bump on an algorithm for generating filenames, and decided to mix it up.</p><p><strong>The challenge: </strong>Given a table of products, return the name of the product that cost the most money (price multiplied by quantity) with the lexicographically smallest name.</p><p>Here is the explanation of lexicographic comparisons provided by the challenge:</p><blockquote>String A is lexicographically smaller than string B either if A is a prefix of B (and A ≠ B), or if there exists such index i (0 ≤ i &lt; min(A.length, B.length)), that Ai &lt; Bi, and for any j (0 ≤ j &lt; i) Aj = Bj. The lexicographic comparison of strings is implemented by operator &lt; in modern programming languages.</blockquote><blockquote>…Maybe it will make more sense if I look at the test cases.</blockquote><p>For the following table, Products, the output should be Cucumber.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fairtable.com%2Fembed%2FshrXc50Dc6DQngZnT&amp;url=https%3A%2F%2Fairtable.com%2FshrXc50Dc6DQngZnT&amp;image=https%3A%2F%2Fstatic.airtable.com%2Fimages%2Foembed%2Fairtable.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=airtable" width="800" height="533" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5e5ff2cd59eb1221fde1c9cda1c8d03/href">https://medium.com/media/f5e5ff2cd59eb1221fde1c9cda1c8d03/href</a></iframe><p>Here is the explanation of the output:</p><blockquote>While the total cost for each product was 40, Cucumber has the lexicographically smallest name.</blockquote><blockquote>So… alphabetical order? If they wanted alphabetical order, why didn’t they just say alphabetical order?! …Maybe I should <a href="https://www.quora.com/Whats-the-difference-between-lexicographical-and-alphabetical-order/answer/Jesse-Mao?srid=xYE5">Google it</a> just to be safe.</blockquote><p>Once I read the test case and output explanation, I understood what the challenge was asking. And once I understood what the challenge was asking, I started trying to solve it.</p><p><strong>Attempt #1: FAIL</strong></p><p>Since the total cost wasn’t stored directly in the table, I started by adding a calculated field, total_cost, to each row in my query.</p><p>SELECT *, (price * quantity) total_cost FROM Products;</p><p>Once each row had a total_cost, I tried to use the MAX function to exclude all records where the total cost was less than the maximum total cost.</p><p>SELECT *, MAX((price * quantity) total_cost) FROM Products;</p><p>That did not work at all (syntax error), and I realized that I didn’t want to select the maximum value. I wanted to extract records that met a specific condition (total_cost equals MAX(total_cost)).</p><blockquote>This sounds like a job for the WHERE clause!</blockquote><p><strong>Attempt #2: FAIL</strong></p><p>SELECT *, (price * quantity) total_cost <br>FROM Products <br>WHERE total_cost = MAX(total_cost);</p><p>That also did not work (Unknown column ‘total_cost’ in ‘where clause’).</p><blockquote>Maybe I need to rethink my approach.</blockquote><p><strong>Attempt #3: FAIL</strong></p><p>I started having two thoughts around this time:</p><blockquote>1. I see why this challenge wasn’t in the first round of the database series.</blockquote><blockquote>2. It seems like this shouldn’t be this difficult.</blockquote><p>I tried Googling hyper-specific combinations of SQL terms, such as:</p><ul><li>sql select column from max calculated field</li><li>sql return entire row of max calculated field</li></ul><p>I found some results that looked promising, but they all seemed to be increasing in complexity (variables, nested select statements, temporary tables, etc). And I started to doubt myself.</p><blockquote>This seems like it would be basic SQL functionality. There’s no way it has to be this complicated!</blockquote><p>By that point, I was certain I was making this challenge more difficult than it needed to be. And since I didn’t want to be stubborn/waste any additional time, I checked the challenge comments. Sure enough, one of the first comments contained the solution in pseudocode.</p><blockquote>select name from Products order by quantity*price desc, name asc limit 1;</blockquote><p>Here is the actual end result:</p><p>SELECT name<br>FROM Products<br>ORDER BY quantity * price DESC, name ASC<br>LIMIT 1;</p><p>You can see it in action on <a href="http://sqlfiddle.com/#!9/72e9a6/8">SQLFiddle</a>.</p><p>Once my test passed, I immediately felt foolish because I either forgot/didn’t know that:</p><ol><li>ORDER BY can sort on a calculated value</li><li>ORDER BY accepts multiple arguments</li></ol><p>I’m ashamed that it took me as long as it did, but I’d rather learn the hard way than not learn at all.</p><p>Feel free to leave a comment, follow me on <a href="https://twitter.com/billfienberg">Twitter</a>, and/or follow me on <a href="https://www.instagram.com/billfienberg/">Instagram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f592c7d2ea2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Sampler]]></title>
            <link>https://medium.com/@BillFienberg/css-sampler-building-a-header-for-web-on-desktop-using-flexbox-positioning-and-pseudoelements-c3bc96663f46?source=rss-b70e7e5ddb69------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3bc96663f46</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Bill Fienberg]]></dc:creator>
            <pubDate>Sun, 02 Jul 2017 05:19:21 GMT</pubDate>
            <atom:updated>2017-08-26T20:50:58.613Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Header for Web on Desktop using Flexbox, Positioning, and Pseudoelements</h3><p>My team was asked to rebuild our site-wide header. The vast majority of our new front-end code is written in React. However, since the header would be used on every page of the site, we chose to build it with native HTML/CSS/JavaScript. We decided that it didn’t make sense to add a React dependency to every page of the site when many of our legacy pages don’t currently use React.</p><p>Before I get started, here is a screenshot of the finished prototype for your reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Hyl3q7dsQEXj962AqBD1A.jpeg" /><figcaption>A journey of 1,000 miles…</figcaption></figure><p>When I first saw the design, I immediately recognized some fun CSS challenges, like vertical centering, relative positioning, and CSS triangles. There are many resources about those topics individually. However, I couldn’t find any resource that included all three. So this is my attempt to consolidate them all in one place.</p><h3>Step 1: Build a Basic Header</h3><p>I started by building a basic header. I split the header into three visual sections (.logo, .middle, .help). I gave .logo and .help an explicit width (130px), and set display: flex; flex: 1 1 auto; on .middle. Then I added a div inside .middle to contain both the user’s name (.name) and a button with an icon (.iconButton) to toggle the dropdown menu. You can see the end result of step one on <a href="https://codepen.io/billfienberg/pen/WxXpEO">Codepen</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ci20rE8zuk8GFjD5Fw1k2Q.jpeg" /><figcaption>Gotta start somewhere.</figcaption></figure><h3>Step 2: Add the Dropdown</h3><p>I added another div (.dropdown) inside the middle section as a sibling to the div containing the name with icon (.nameWithIcon). This new div contained three generic links (Inbox, Settings, Sign Out). For the prototype, I set those links to href=&quot;#&quot;. However, it didn’t look right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-icrRAIx6Pibqu74lf0TA.jpeg" /><figcaption>Nope.</figcaption></figure><p>Notice how .dropdown is inline with .nameWithIcon, and how you can still see the bottom border behind the div. It should be positioned on top, and have a solid white background. First, I added background-color: white so you would no longer see the bottom border of the header. Then I added position: absolute; top: 60px; right: 20px; thinking it would it appear on top of .nameWithIcon. Again, it still didn’t look right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ULW8e0BJv1Tmt4kYG3HVbg.jpeg" /><figcaption>Close, but no cigar.</figcaption></figure><p>I assumed that .dropdown was going to appear on top of .nameWithIcon. However, that clearly didn’t happen. So now I needed to figure out how to get it positioned over .nameWithIcon instead of .help. After some Googling, I found the answer in a 2008 blog post from <a href="https://chriscoyier.net/">Chris Coyier</a> titled <a href="https://css-tricks.com/absolute-positioning-inside-relative-positioning/">Absolute Positioning Inside Relative Positioning</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INMtnuiada5rBWC-tJzEmw.jpeg" /><figcaption>That’s the ticket.</figcaption></figure><p>You can see the end result of step two on <a href="https://codepen.io/billfienberg/pen/pbarKR">Codepen</a>.</p><h3>Step 3: Toggle the Dropdown</h3><p>Since design didn’t ask for .dropdown to permanently float on top of the header, I still had some more work to do.</p><p>I checked <a href="http://youmightnotneedjquery.com/">YouMightNotNeedjQuery</a> to remember how to <a href="http://youmightnotneedjquery.com/#on">add an event listener to an element using pure JavaScript</a>. I added a <a href="http://youmightnotneedjquery.com/#toggle_class">toggleClass</a> function to toggle the .dropdown--isOpen class when .iconButton is clicked. And then I updated the CSS so .dropdown defaulted to display: none, and moved the visible styles to the .dropdown—-isOpen class. The --* class suffix comes from the <a href="https://css-tricks.com/bem-101/">Block, Element, Modifier (BEM) methodology.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lB00W-1inns2cUVs6DgvSQ.jpeg" /><figcaption>Wax off.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GxmkwlGWa9FKd0xk1awtA.jpeg" /><figcaption>Wax on.</figcaption></figure><p>Here is the ending <a href="https://codepen.io/billfienberg/pen/rwdmKX">Codepen</a> for step three.</p><h3>Step 4: Add the Triangle</h3><p>My final task was to add the triangle to .dropdown. Since I didn’t memorize how to build a triangle using CSS, I stopped by Google to see what the internet had to offer. I found a <a href="http://www.cssarrowplease.com/">tool to generate CSS arrows</a>, and realized I could use that as a starting point. After some trial and error, I shifted the triangle from the center of .dropdown to the right until it aligned it with the <a href="https://material.io/icons/#ic_keyboard_arrow_down">keyboard_down_arrow</a> Google font icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Hyl3q7dsQEXj962AqBD1A.jpeg" /><figcaption>:woohoo:</figcaption></figure><p>The final prototype can also be found on <a href="https://codepen.io/billfienberg/pen/PjRmWj">Codepen</a>.</p><h3>But wait… There’s more!</h3><p>For extra credit, I decided to implement the prototype in React. I spun up an app using Facebook’s <a href="https://github.com/facebookincubator/create-react-app">create-react-app</a>. I created a repo on <a href="https://github.com/billfienberg/css-sampler-blog-post">Github</a>, created branches for each step, and ported the code from the various Codepens to their corresponding <a href="https://github.com/billfienberg/css-sampler-blog-post/branches">branches</a>. And once everything was working, I used <a href="https://surge.sh/">Surge</a> to publish the prototype as a <a href="http://css-sampler.surge.sh/">static app</a>.</p><p>Feel free to leave comments and/or contact me on <a href="https://twitter.com/billfienberg">Twitter</a> and <a href="https://www.instagram.com/billfienberg/">Instagram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3bc96663f46" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>