<?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 Danny Guo on Medium]]></title>
        <description><![CDATA[Stories by Danny Guo on Medium]]></description>
        <link>https://medium.com/@dannyguo?source=rss-14b9ce6433d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aQrtHdEpplGxawwXcT_mpQ.jpeg</url>
            <title>Stories by Danny Guo on Medium</title>
            <link>https://medium.com/@dannyguo?source=rss-14b9ce6433d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 09:42:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dannyguo/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[What I Learned by Relearning HTML]]></title>
            <link>https://dannyguo.medium.com/what-i-learned-by-relearning-html-5db56f94f2d7?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5db56f94f2d7</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Fri, 07 May 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-05-27T13:50:11.172Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>I’ve worked on websites for several years, both professionally and for side projects. One day, I reflected on the fact that all of my web development education had come from actually making websites. In most cases, I’d have a specific problem, Google how to solve it, and learn something new in the process.</p><p>I wondered what I was missing by never learning HTML in a comprehensive way. Forget CSS and JavaScript. I’m just talking about raw HTML. It might seem silly to go back to such a basic aspect of web development after a decent amount of experience, but it’s easy to become overconfident with a skill just because you know enough to do a few useful things.</p><p>So I decided to relearn HTML and discover my <a href="https://en.wikipedia.org/wiki/There_are_known_knowns">unknown unknowns</a>.</p><h3>Experience</h3><p>For context, I made my first website in middle school for a class project. We learned basic HTML, and embedding a MP3 song felt like magic. But I didn’t touch web development again until college. I made a lightweight news aggregator called <a href="https://www.dailylore.com/">The Daily Lore</a> that’s still running (I preserved the <a href="https://www.dailylore.com/legacy">original version</a>).</p><p>Since then, I’ve worked on two websites professionally, one website for a <a href="https://sublimefund.org/">nonprofit</a>, my <a href="https://www.dannyguo.com/">personal website</a>, and a few small websites for side projects, such as <a href="https://www.makeareadme.com/">Make a README</a>.</p><h3>Introduction to HTML5</h3><p>I don’t consider myself to be a web development expert based on just that experience, but I surely had far more knowledge than the typical student for <a href="https://www.coursera.org/">Coursera</a>’s <a href="https://www.coursera.org/learn/html">Introduction to HTML5</a> course. I started the course expecting to know a lot of the content already, since it was designed for complete beginners with no programming backgrounds.</p><p>As I went through the material, I did in fact know a lot of it already, but it was still a good refresher for two points in particular: the importance of using semantic elements and what to think about in terms of accessibility.</p><p>I’ve always had a bad habit of using generic &lt;div&gt; elements to make what I need, rather than semantic elements that represent specific content, like the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header">header</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer">footer</a> elements.</p><p>Accessibility was also something I had never considered in depth. I knew that images should have alt descriptions, and that was about it. One of the course&#39;s key points is that using the appropriate semantic elements is important to making a site more accessible.</p><p>For example, people who use screen readers can jump around using <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements">heading</a> elements (&lt;h1&gt; through &lt;h6&gt;), so it&#39;s important to use them and make sure they&#39;re in the correct order. It&#39;s wrong to use them only to make text bigger because their real purpose is to define the structure of the content. They&#39;re like a table of contents.</p><p>Instead of headings, we could use &lt;p&gt; elements and alter their font sizes with CSS to create a website that looks identical, but it&#39;d be less semantic and less accessible. There is more to web development than making websites look the way we want. It&#39;s important to make the content <em>mean</em> what we want as well.</p><p>Accessibility isn’t just about improving how websites work with screen readers. We should think about font size, font style, and color contrast for people who have visual impairments or color blindness. We should consider that people who have hearing loss may have a harder time recognizing that audio or video is playing. We should make tab navigation work well for people who rely primarily on the keyboard, perhaps because they have a difficult time using a mouse. When we add animations, we should take care to avoid ones that make it more difficult for someone to actually use the website, such as animations that change the page layout in the middle of interactions. And we should consider when a page is overloaded with too much information or too many elements, making it hard for people to understand things or how to actually use the website.</p><p>It’s easy to forget about accessibility, but we should strive to make websites work well for as many people as possible. Accessibility also goes hand in hand with usability and search engine optimization. The course points out that improving one frequently means improving all the others.</p><h3>Reading the Documentation</h3><p>I have a <a href="https://azeemba.com/">friend</a> who is probably the only person I know who has read the entire <a href="https://operations.nfl.com/the-rules">NFL rulebook</a> (the 2020 version is 87 pages long). Watching football with him was fun because he was so good at understanding nuances to the game and weird situations. I figured there was a similar opportunity for me with HTML.</p><p>The strict equivalent would have been to read the <a href="https://html.spec.whatwg.org/">HTML standard</a> for every HTML element, but I decided to read the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element">MDN documentation</a> for every element instead since MDN has a lot of information about browser compatibility and using elements in practice. I read the entire page for each element, took notes, and made <a href="https://apps.ankiweb.net/">Anki</a> cards for the bits that I wanted to commit to memory.</p><p>There were many deprecated elements that I only skimmed through, and I didn’t bother to take notes for those, but dozens of standardized elements and attributes were totally new to me.</p><p>I didn’t intend to come out of this experience as a master of HTML, and I still have to apply what I’ve learned (including to this website), but I find it useful just to be aware of what is available. Even though I can’t recall all the details about using a <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture">picture</a> element, I know it exists now, and I can always look up the details later during implementation. It’s a categorical difference from not being aware of it at all and using a plain&lt;img&gt; for all cases because I don&#39;t know any better.</p><h3>Observations</h3><p>As I read the documentation, some things were particularly interesting to me, and I had some observations.</p><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/address">address</a> element is for contact information in general, not just physical mailing addresses.</p><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dfn">definition</a> element represents the term that is being defined, rather than the definition itself.</p><p>There is a whole set of <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby">ruby</a> elements that are primarily used to show the pronunciations of East Asian characters.</p><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track">track</a> element provides a standard way to embed timed text tracks for video and audio. I had never heard of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API">WebVTT</a> (Web Video Text Tracks) format before.</p><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map">map</a> element seems like an anachronism, especially considering that it isn’t responsive.</p><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data">data</a> element provides a machine-readable translation for content. This seems likes it could help screen scraping, which some websites like <a href="https://www.theverge.com/2019/9/10/20859399/linkedin-hiq-data-scraping-cfaa-lawsuit-ninth-circuit-ruling">LinkedIn have been actively trying to prevent</a>.</p><p>There’s subtlety when it comes to correctly choosing to use <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strong">strong</a> versus <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em">em</a> versus <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i">i</a> versus <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/u">u</a> versus <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b">b</a> versus <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark">mark</a>.</p><p>There are a few elements that seem redundant. The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/legend">legend</a> element represents a caption for a <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset">fieldset</a> element, the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption">caption</a> element represents a caption for a <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table">table</a> element, and the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption">figcaption</a> element represents a caption for a <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure">figure</a> element. I don’t know why one element couldn’t do the job for all three, since the meaning could be derived from the parent element.</p><h3>The Future of HTML</h3><p>As I read through the documentation, it kept making me consider the question of how HTML should evolve. Browsers keep gaining more and more functionality, to the point that they are becoming more like operating systems. There’s even an experimental <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API">API for connecting to Bluetooth devices</a>.</p><p>Wikipedia is the perfect website for what HTML was originally designed for: mostly static documents that are connected through hyperlinks. But now we use the browser to deliver full on applications, like <a href="https://www.figma.com/">Figma</a>, which is a design tool that <a href="https://www.figma.com/blog/webassembly-cut-figmas-load-time-by-3x/">effectively runs C++ code in the browser by compiling it to WebAssembly</a>.</p><p>HTML has added a few elements and attributes that make interactivity possible without JavaScript. For example, the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details">details</a> element creates a widget that can be toggled between open and closed states.</p><p>But as your use case become more advanced, it quickly becomes difficult to rely solely on what HTML provides. For example, <a href="https://getbootstrap.com/">Bootstrap</a>’s progress bar <a href="https://getbootstrap.com/docs/5.0/components/progress/">doesn’t use</a> the HTML <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress">progress</a> element.</p><blockquote><em>We don’t use the HTML5 &lt;progress&gt; element, ensuring you can stack progress bars, animate them, and place text labels over them.</em></blockquote><p>Another example is the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table">table</a> element. Pure HTML tables <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr#advanced_styling">can be pretty sophisticated</a> in terms of displaying data, but there’s no built-in support for interactive functionality like sorting, filtering, and pagination.</p><p>Browser support also becomes an issue when an element does become more advanced. The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input">input</a> element is one of the most complex elements because it supports so many combinations of input types and attributes. In theory, you could use it to easily collect a date and a time, using the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local">datetime-local type</a>. But not all browsers support it, and there is variation in how it works even among those that do.</p><p>Some elements are also difficult to style, such as the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select">select</a> element. So website developers may want to rely on standard functionality instead of using a library or implementing a feature themselves, but then they have to worry about it not working well in certain browsers or stylistic inconsistency with the rest of the website.</p><p>I’m eager to see if <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components">Web Components</a> become more popular and provide a good solution to these problems. If they do, the situation could become similar to programming languages, where different languages take difference stances on the question of how much functionality should be included in the standard library (HTML) so that the community has a lesser or greater tendency to rely on third party libraries (Web Components).</p><p>Web Components do seem to be picking up some momentum. <a href="https://github.com/">GitHub</a> has <a href="https://github.blog/2021-05-04-how-we-use-web-components-at-github/">started to use them</a>, and they publish their components to <a href="https://www.webcomponents.org/">WebComponents.org</a>.</p><h3>Conclusion</h3><p>It was easy to feel confident with HTML after doing web development for several years. Yet I found plenty of value in going back to learn it in a more rigorous manner. I learned about many improvements I can make to the websites I work on, and I have a better big picture view of HTML and how it might develop. While I still think learning by doing is highly effective, this experience has made me want to go back and relearn other things with a bottom up approach.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/what-i-learned-by-relearning-html/"><em>https://www.dannyguo.com</em></a><em> on May 7, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5db56f94f2d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Fix instanceof Not Working For Custom Errors in TypeScript]]></title>
            <link>https://dannyguo.medium.com/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript-1df978100a27?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1df978100a27</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Sat, 17 Apr 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-05-12T14:04:22.327Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>In JavaScript, you can create custom errors by extending the built-in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error">Error object</a> (ever since <a href="https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_%E2%80%93_ECMAScript_2015">ES 2015</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f00a571b49d6cee71828135c9003eda3/href">https://medium.com/media/f00a571b49d6cee71828135c9003eda3/href</a></iframe><p>You can do the same thing in <a href="https://www.typescriptlang.org/">TypeScript</a>, but there is an important caveat if your tsconfig.json has a compilation <a href="https://www.typescriptlang.org/tsconfig#target">target</a> of ES3 or ES5. In that case, instanceof doesn&#39;t work, which breaks any logic that is based on whether or not an error is a case of the custom error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0260e1b7f3c78586dbb74e8fff4da0f5/href">https://medium.com/media/0260e1b7f3c78586dbb74e8fff4da0f5/href</a></iframe><p>You can try <a href="https://www.typescriptlang.org/play?target=1&amp;ts=4.2.3#code/MYGwhgzhAEAiYBcwCNIFMCiAnLB7L0aAHgmgHYAmM2eBA3gL4BQTwuZEChO+0AvNDJoA7nEQp0NfAAoARAFUyASwCOAVzTQ2HBFjBKyXAG5Lc4BKbKyAlAG4WAegfQADlgMIYs3Rtmt2EGZoAHQguADm0mg8BAacYGTAaLgAZtBSWHZMTtAGbDhowAggAJ6u7oZeKWAgEGh+2oEgIWGR0bS5OglJqWJIqHUZdkA">this out yourself</a> in the TypeScript playground. This is a <a href="https://github.com/microsoft/TypeScript/issues/13965">known issue</a> that started with <a href="https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work">TypeScript version 2.1</a>. The recommended fix is to manually set the prototype in the constructor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7d4fbc826adb1249f5474e40323284f/href">https://medium.com/media/b7d4fbc826adb1249f5474e40323284f/href</a></iframe><p>Any custom errors which further extend DatabaseError still need the same adjustment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f13a31c988d0c650cf695d302d012c5/href">https://medium.com/media/9f13a31c988d0c650cf695d302d012c5/href</a></iframe><h3>Upgrade the Compilation Target</h3><p>Remember that this is only an issue if your compilation target is ES3 or ES5. Instead of having to remember to set the prototype, you could consider upgrading your target to ES 2015 or even later. ES 2015 has <a href="https://caniuse.com/es6">over 97% browser support</a>, so it may be a reasonable choice for you, especially if you are okay with dropping support for Internet Explorer.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/"><em>https://www.dannyguo.com</em></a><em> on April 17, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1df978100a27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Concatenate Strings in Lua]]></title>
            <link>https://dannyguo.medium.com/how-to-concatenate-strings-in-lua-d2164cc5922f?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2164cc5922f</guid>
            <category><![CDATA[string-concatenation]]></category>
            <category><![CDATA[lua]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Mon, 28 Dec 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-12-29T14:18:11.222Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>The most straightforward way to concatenate (or combine) strings in <a href="https://www.lua.org/about.html">Lua</a> is to use the dedicated <a href="https://www.lua.org/pil/3.4.html">string concatenation operator</a>, which is two periods (..).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae9a5ff4701b64939cd8db26d871a305/href">https://medium.com/media/ae9a5ff4701b64939cd8db26d871a305/href</a></iframe><p>Numbers are coerced to strings. For fine-grained control over number formatting, use <a href="https://www.lua.org/manual/5.4/manual.html#pdf-string.format">string.format</a>, which behaves mostly like C’s <a href="https://www.cplusplus.com/reference/cstdio/printf/">printf</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/338de8b514d527d883495151b90c28eb/href">https://medium.com/media/338de8b514d527d883495151b90c28eb/href</a></iframe><p>Trying to concatenate other <a href="https://www.lua.org/pil/2.html">types</a>, like nil or a table, will result in an error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1418407c65fb0c3757ba9e478046bf8f/href">https://medium.com/media/1418407c65fb0c3757ba9e478046bf8f/href</a></iframe><p>Note that Lua <a href="https://stackoverflow.com/q/20091779/1481479">doesn’t have</a> syntactic sugar for <a href="https://en.wikipedia.org/wiki/Augmented_assignment">augmented assignment</a>. The following is invalid syntax.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b99fc1e56a4b191a065c875c71fd227c/href">https://medium.com/media/b99fc1e56a4b191a065c875c71fd227c/href</a></iframe><p>Strings in Lua are <a href="https://www.lua.org/pil/2.4.html">immutable</a>, so the concatenation result (message in this example) is a brand new string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31c847d9afd692fcbaae8c0ea5e05c79/href">https://medium.com/media/31c847d9afd692fcbaae8c0ea5e05c79/href</a></iframe><h3>table.concat</h3><p>If you need to perform many concatenation operations, using the concatenation operator can be slow because Lua has to keep reallocating memory to create new strings.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69e1ed2ddb2e63e719f6cdc0b8e7d8a0/href">https://medium.com/media/69e1ed2ddb2e63e719f6cdc0b8e7d8a0/href</a></iframe><p>As a result, it <a href="https://www.reddit.com/r/lua/comments/1t6ois/tableconcat_is_fast/">can be much faster</a> to use <a href="https://www.lua.org/manual/5.4/manual.html#6.6">table.concat</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/495cc6cc2e66196bc15504786ddaf005/href">https://medium.com/media/495cc6cc2e66196bc15504786ddaf005/href</a></iframe><p>Here’s a benchmark comparsion (using <a href="https://github.com/sharkdp/hyperfine">hyperfine</a>) from running the .. example as slow.lua and running the table.concat example as fast.lua.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e507c5ad48e4cfb65dd67c21977d9bd6/href">https://medium.com/media/e507c5ad48e4cfb65dd67c21977d9bd6/href</a></iframe><p>The difference probably doesn’t matter in most cases, but it’s a good optimization to be aware of.</p><p>table.concat can also be easier to use because it can take a separator argument to add between elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e2fd5c9b08f5968d50bba331904cce5/href">https://medium.com/media/9e2fd5c9b08f5968d50bba331904cce5/href</a></iframe><p>It can also take start and end indexes. Keep in mind that Lua arrays <a href="https://www.lua.org/pil/11.1.html">start with index 1</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5117712e1a7920b571c5654f58699f33/href">https://medium.com/media/5117712e1a7920b571c5654f58699f33/href</a></iframe><h3>Direct Approach</h3><p>Depending on your use case, you might be able to save some memory usage over table.concat by generating the result directly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f77fada7caa46fc7ef5b72e34ba3217/href">https://medium.com/media/2f77fada7caa46fc7ef5b72e34ba3217/href</a></iframe><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/how-to-concatenate-strings-in-lua/"><em>https://www.dannyguo.com</em></a><em> on December 28, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2164cc5922f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Morning Joy]]></title>
            <link>https://dannyguo.medium.com/morning-joy-e42f46433728?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e42f46433728</guid>
            <category><![CDATA[twilio]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[reddit]]></category>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Sat, 15 Aug 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-08-16T14:32:10.126Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>This past April, <a href="https://dev.to/">DEV</a> hosted a <a href="https://dev.to/devteam/announcing-the-twilio-hackathon-on-dev-2lh8">hackathon</a> in conjunction with <a href="https://www.twilio.com/">Twilio</a> (here’s a <a href="https://www.twilio.com/referral/fX7XpV">referral link</a> for a $10 credit). This seemed like a good chance to play around with the Twilio API, so I created a small project called <a href="https://github.com/dguo/morning-joy">Morning Joy</a>. It lets you start each day on a good note by texting you an uplifting news story and a picture of something cute.</p><p>Following the news can be stressful or even depressing. This is one small way to remember that good things are happening too.</p><p>Here’s an example from the first day:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/0*lbHxzHSFwAlHn5rk.jpg" /></figure><h3>How I Built It</h3><p>I signed up for Twilio and followed their <a href="https://www.twilio.com/docs/sms/quickstart/node#install-nodejs-and-the-twilio-module">quickstart guide for Node.js</a>. I bought a phone number and tested sending a text to myself. This was painless. I probably spent more time picking the phone number than I did writing the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac30db74e8b539e5e6fc1c9a6e4c739c/href">https://medium.com/media/ac30db74e8b539e5e6fc1c9a6e4c739c/href</a></iframe><h4>Reddit JSON</h4><p>Next, I needed to find a content source that I can count on to be renewed on a daily basis and to be of high quality. I decided to use Reddit’s <a href="https://www.reddit.com/r/aww/">r/aww</a> and <a href="https://www.reddit.com/r/UpliftingNews/">r/UpliftingNews</a> subreddits. They are two of the largest subreddits, so I should never get duplicate content. I also wanted to grab the first post when sorting by top for today, which means the community has heavily upvoted the post.</p><p>I looked into the best way to fetch posts from Reddit. I initially planned to use their <a href="https://www.reddit.com/dev/api/">API</a>, but it <a href="https://www.reddit.com/r/javascript/comments/8yg6ig/adding_json_onto_the_end_of_most_reddit_urls/">turns out</a> that Reddit has a convenient feature where you can simply append.json to the end of a subreddit URL to receive the data as JSON: <a href="https://www.reddit.com/r/aww.json">https://www.reddit.com/r/aww.json</a>.</p><p>This worked well, but I didn’t know how to sort the results by the top posts for today rather than hot (trending posts right now). I <a href="https://www.reddit.com/r/redditdev/comments/1470nj/what_is_the_json_link_for_getting_differently/">discovered</a> that a query parameter does the trick: <a href="https://www.reddit.com/r/aww/top.json?t=day">https://www.reddit.com/r/aww/top.json?t=day</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7892087425816370823537a337e5bcce/href">https://medium.com/media/7892087425816370823537a337e5bcce/href</a></iframe><p>I wrote a <a href="https://github.com/dguo/morning-joy/blob/master/index.js">script</a> to grab the top post for r/UpliftingNews and the top image post for r/Aww and then text them to myself using Twilio.</p><h4>Hosting</h4><p>Lastly, I needed a way to schedule the script to run every morning. To keep it simple, I converted my script into an <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> function and set up a <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html">CloudWatch Events</a> rule that <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-Scheduled-Rule.html">triggers on a schedule</a> to fire the function every day at 10 a.m. UTC. The schedule expression is: cron(0 10 * * ? *). I also added <a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html">environment variables</a> to pass DESTINATION_PHONE_NUMBER, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_PHONE_NUMBER to the function.</p><p>This was a relatively simple project, and it has been fun getting the text every morning.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/morning-joy/"><em>https://www.dannyguo.com</em></a><em> on August 15, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e42f46433728" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing MacBook Pro Thermal Performance Issues]]></title>
            <link>https://dannyguo.medium.com/fixing-macbook-pro-thermal-performance-issues-ce01f8ee0490?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce01f8ee0490</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[macbook-pro]]></category>
            <category><![CDATA[macbook]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Sun, 02 Aug 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-08-08T16:30:05.825Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>I may earn commissions from purchases made through affiliate links in this post.</em></p><p>Over the past several months, my 2018 15&quot; MacBook Pro developed thermal performance issues. Here’s what I did to fix the problem. The two key changes were that I switched to using the right side <a href="https://en.wikipedia.org/wiki/Thunderbolt_(interface)#Thunderbolt_3">Thunderbolt 3</a> ports instead of the left side ones, and I cleaned the dust buildup in the internal fans.</p><h3>The Problem</h3><p>The problem first started when I noticed my CPU usage spiking to near 100%. In the process list, I saw kernel_task taking up most of the CPU.</p><p>I <a href="https://support.apple.com/en-us/HT207359">learned</a> that macOS does this intentionally to prevent the CPU from overheating.</p><blockquote><em>One of the functions of kernel_task is to help manage CPU temperature by making the CPU less available to processes that are using it intensely. In other words, kernel_task responds to conditions that cause your CPU to become too hot, even if your Mac doesn’t feel hot to you. It does not itself cause those conditions. When the CPU temperature decreases, kernel_task automatically reduces its activity.</em></blockquote><h3>Fan Speed</h3><p>For many years, I’ve used <a href="https://github.com/hholtmann/smcFanControl">smcFanControl</a> to manually increase my fan speed because I don’t mind fan noise, especially if it means getting better performance out of my laptop or being able to comfortably put it on my lap.</p><p>However, it stopped working reliably after a macOS update. I purchased <a href="https://bjango.com/mac/istatmenus/">iStat Menus</a>, which comes with a well supported fan control feature. Note that you have to buy it from their own website to get fan control. The Mac App Store version <a href="https://bjango.com/help/istatmenus6/macappstore/">doesn’t include that particular feature</a> for some reason.</p><p>I turned the fans up to max regularly in an attempt to preempt the kernel_task issue, but it still kept popping up.</p><h3>Thunderbolt 3</h3><p>I found <a href="https://apple.stackexchange.com/a/363933/275342">this excellent StackExchange answer</a> that recommends using the right side Thunderbolt 3 ports instead of the left side ones. Apparently the ports aren’t equal. The left ones can cause thermal issues. Also, using both ports on either side can be problematic.</p><p>I use a <a href="https://www.amazon.com/CalDigit-TS3-Plus-Thunderbolt-Dock/dp/B07CZPV8DF/ref=as_li_ss_tl?crid=223U28DX1402C&amp;dchild=1&amp;keywords=caldigit+ts3+plus&amp;qid=1595940705&amp;sprefix=caldigit+,aps,223&amp;sr=8-2&amp;th=1&amp;linkCode=ll1&amp;tag=thdalo00-20&amp;linkId=016d783904cae8cac9d952a3c58d816b&amp;language=en_US">Thunderbolt 3 dock</a> for a single cable solution that handles charging and all my peripherals, including monitors. I tended to plug it into a left port. I switched it over to a right port and saw an immediate difference in temperature. iStat Menus reports the temperatures from various sensors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/0*gRbiSNsxOAAOML1P.png" /></figure><p>I tested and verified that using a left port caused the CPU temperature to go up much higher than using a right port.</p><p>For a few months, this simple change was enough to resolve the issue. Luckily, I was able to continue using a single cable, and I didn’t have to plug in my dock on one side and then a separate charger on the other side.</p><h3>Resolution Scaling</h3><p>Then the problem started happening again. I also experienced issues playing <a href="https://en.wikipedia.org/wiki/Tabletop_Simulator">Tabletop Simulator</a>, <a href="https://en.wikipedia.org/wiki/Counter-Strike:_Global_Offensive">Counter-Strike</a>, and <a href="https://en.wikipedia.org/wiki/Valorant">Valorant</a> (on Windows through Boot Camp), all games that my machine should be able to handle without any problems. It would stutter even after I turned the resolution and graphical settings all the way down.</p><p>I thought it might have something to do with my monitors. In my desk setup, I have two external monitors that I run at a scaled resolution that looks like 2560 x 1440.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QFWAd31aXeg3BU7e.png" /></figure><p>Note the warning that “Using a scaled resolution may affect performance.” The problem is that macOS <a href="https://github.com/kovidgoyal/kitty/issues/1043">achieves this resolution</a> by rendering everything in double the size and then scaling it down. So my MacBook is essentially doing the rendering work for two 5K monitors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/0*LX1kpfqjeQKuISxs.png" /></figure><p>See <a href="https://forums.macrumors.com/threads/4k-monitor-at-1440p-scaling-performance.2232164/">this thread</a> or <a href="https://apple.stackexchange.com/a/338581/275342">this StackExchange answer</a> for more details.</p><p>I considered turning the resolution down to look like 1920 x 1080, which isn’t a scaled resolution, but then everything looked too big.</p><p>I was pretty frustrated at this point, especially because <a href="https://zoom.us/">Zoom</a> video calls started freezing up on me. I got into the habit of unplugging my monitors before joining video calls.</p><h3>Dust</h3><p>This entire time, I thought the problem was my MacBook producing too much heat. Beyond making the fans run at max more often, I never considered that the problem could be that it stopped being able to get rid of heat.</p><p>Then I read <a href="https://quanticdev.com/articles/cleaning-macbook-after-16800-hours-of-use/">this post</a> from someone who cleaned the inside of a MacBook after 7 years of use. I was initially skeptical that clogged fans were my problem because my MacBook was only about a year and a half old. But the more I thought about it, the more it made sense, and I didn’t have anything to lose by trying to clean it.</p><p>To open my MacBook, I followed <a href="https://www.ifixit.com/Guide/MacBook+Pro+15-Inch+Touch+Bar+2018+Lower+Case+Replacement/121426">this iFixit guide</a>.</p><h3>AutoBoot</h3><p>I learned that by default, macOS turns on the MacBook when you press any button (not just the power button) or open the lid. This was very surprising to me. I did recall being confused in the past when my MacBook turned on even though I didn’t press the power button. When it first happened, I thought there was something wrong. At least from Apple’s perspective, it turns out <a href="https://www.wired.com/story/its-not-a-bug-its-a-feature/">this is a feature, not a bug</a>.</p><p>So to make sure the MacBook stays off through the process, you have to run this in a terminal to turn off booting on lid open.</p><pre>sudo nvram AutoBoot=%00</pre><p>To turn the setting back on later, run this. Though I just left mine off after I was done.</p><pre>sudo nvram AutoBoot=%03</pre><h3>Removing the Bottom</h3><p>The next step was to take off the screws. Apple uses <a href="https://en.wikipedia.org/wiki/Pentalobe_security_screw">pentalobe screws</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_zj9n1nBzzgnCuir.jpg" /></figure><p>I’ve opened MacBooks before to replace <a href="https://www.reddit.com/r/spicypillows">swollen batteries</a>, so I was prepared with an <a href="https://www.amazon.com/gp/product/B072HNBL9Z/ref=as_li_ss_tl?ie=UTF8&amp;psc=1&amp;linkCode=ll1&amp;tag=thdalo00-20&amp;linkId=09c787c5245a192a816fd263da8ad7ea&amp;language=en_US">electronics screwdriver set</a> that includes pentalobe bits. I also had a <a href="https://www.amazon.com/Endust-Electronics-Compressed-bitterant-11407/dp/B00HX7VZ5M/ref=as_li_ss_tl?dchild=1&amp;keywords=endust+duster&amp;qid=1596317241&amp;sr=8-4&amp;th=1&amp;linkCode=ll1&amp;tag=thdalo00-20&amp;linkId=4bb9cd9f61cc6a4a158ec8dfbfb00e3d&amp;language=en_US">can of compressed air</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IXrLQ_ZboPtl5uYQ.jpg" /></figure><p>I removed the screws and learned that Apple has made the bottom harder to open because now you need a suction cup. I repurposed the suction cup from my <a href="https://www.amazon.com/gp/product/B07GKXPL6M/ref=as_li_ss_tl?ie=UTF8&amp;psc=1&amp;linkCode=ll1&amp;tag=thdalo00-20&amp;linkId=a201bd337a2a7814cff67674269ea94f&amp;language=en_US">car dash cell phone holder</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZDr-mkSldzqVzm60.jpg" /></figure><p>You have to use the suction cup to lift part of the bottom enough to slide in something to release a few internal latches. I used a library card.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fmMkCzaH0Db9fSX2.jpg" /></figure><h3>Cleaning the Dust</h3><p>Once I got my MacBook open, it was obvious that dust was the main cause of my performance issues. Just taking the bottom off caused a cloud of dust to come out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O-tvsbLYoD4dF0Z3.jpg" /></figure><p>There was also cat hair from this troublemaker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kdtFANC3t99K3AUr.jpg" /></figure><p>Both fans were totally gunked up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*290c_XdOw0W0begU.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gAjwF7SvW7acgiuf.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*REcXEXVdxqgVUXVm.jpg" /></figure><p>I used compressed air to blow out the dust. I also used a toothpick to get some off the fans that wouldn’t come off from blowing alone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XbC320apwq_FZarL.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zV97jlID5GBPdnOS.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lj7yrVsl14Ro1HSz.jpg" /></figure><p>I put the cover back on and haven’t had any more thermal performance issues.</p><h3>Retrospective</h3><p>It would be nice if macOS could provide some actionable advice when kernel_task is trying to stop the MacBook from overheating. I would have appreciated an OS suggestion to use the right side Thunderbolt 3 ports.</p><p>But I also never considered that my laptop fans could require cleaning. In retrospect, that’s foolish because I’ve seen how dirty it can get in desktop PCs, and I know that heat is an inhibitor to computer performance. It’s just like running in humid weather. Your body starts shutting down because its main mechanism for getting rid of heat (sweating) stops working because humidity prevents sweat from evaporating.</p><p>It would be cool if the machine could detect and alert when the fans are no longer effective, perhaps with a sensor that looks for a lack of airflow at the vents.</p><p>To prevent the issue from occurring again, I’ve set up a recurring task in <a href="https://todoist.com/r/danny_guo_xlyrub">Todoist</a> to remind me to clean my computers once a year.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/fixing-macbook-pro-thermal-performance-issues/"><em>https://www.dannyguo.com</em></a><em> on August 2, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce01f8ee0490" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clearing Mac Storage Space]]></title>
            <link>https://dannyguo.medium.com/clearing-mac-storage-space-8aff532b82c3?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aff532b82c3</guid>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[hard-drive]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Wed, 15 Jul 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-08-08T16:06:16.671Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>I recently needed to clear a large amount of space on my Mac’s hard drive in order to install Windows through <a href="https://en.wikipedia.org/wiki/Boot_Camp_(software)">Boot Camp</a>. After deleting files and applications, I still had large amounts of space taken up in ways that I didn’t understand. Here is what I did to fix the problem.</p><h3>Easy Methods</h3><p>The obvious thing to start with was deleting known files and applications. In particular, I removed some built-in macOS applications, like GarageBand, that I can always re-download from the Mac App Store.</p><p>I also cleared the trash. As a tip, you probably want to set it to <a href="https://support.apple.com/guide/mac-help/delete-files-and-folders-on-mac-mchlp1093/mac">automatically delete items after 30 days</a>. I don’t understand why that’s considered an advanced feature in Finder when it seems like it should be the default setting. It <a href="https://osxdaily.com/2017/02/10/automatically-empty-trash-mac/">wasn’t even an option</a> until <a href="https://en.wikipedia.org/wiki/MacOS_Sierra">Sierra</a>.</p><p>Then I went into my Google Backup and Sync (for <a href="https://www.google.com/drive/">Google Drive</a>) settings and <a href="https://www.remosoftware.com/info/how-to-configure-google-drive-sync-settings-to-sync-specific-folders-or-file-types">unsynced some folders</a> that I don’t need to be available locally.</p><h3>Other Storage</h3><p>After those easy wins, I wanted to get a better idea of what was taking up space. macOS has a built in storage analyzer, but it’s pretty basic. The overview gives a rough breakdown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JG0zmhBO0OGoWAGA.png" /></figure><p>Clicking manage gives you a more detailed view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SQ9401LA29y2xg9w.png" /></figure><p>But note that “System” is greyed out! There’s no way to drill down into it to see what’s actually taking up space.</p><p>This was on <a href="https://en.wikipedia.org/wiki/MacOS_Mojave">Mojave</a>. At least <a href="https://www.apple.com/macos/catalina/">Catalina</a> splits it up into “System” and “Other,” though you still can’t drill down into either.</p><h3>Disk Space Analysis Programs</h3><p>I’m familiar with using du -sh in the terminal to show folder sizes, but I thought a GUI program might be better for this task. I looked into third party programs to find out what folders and files were taking up space. The first one I tried was <a href="http://www.derlien.com/">Disk Inventory X</a>.</p><p>It was useful but took a while (around 10 minutes) to produce results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uloXH4XMZ_LQw2IT.png" /></figure><p>I looked into alternatives. The most helpful resources were this <a href="https://apple.stackexchange.com/q/81568/275342">Stack Exchange question</a> and this <a href="https://macpaw.com/how-to/best-disk-space-analyzers-mac">article</a>.</p><p>I tried <a href="https://www.omnigroup.com/more">OmniDiskSweeper</a>. It doesn’t have a tree view like Disk Inventory X does, but I didn’t find that very useful anyway. OmniDiskSweeper was able to show results as they came, rather than all at once at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zdz6jdvdrerKV8qA.png" /></figure><p>It doesn’t update in real time, so I did have to re-analyze the disk after deleting files.</p><h3>Docker</h3><p>The first thing I noticed was Docker’s <a href="https://docs.docker.com/docker-for-mac/space/">disk image file</a>. Docker for Mac stores containers and images in that single, large file. I ran <a href="https://docs.docker.com/engine/reference/commandline/system_prune/">docker system prune</a> to delete unnecessary containers and images.</p><p>Then I decreased the size limit for the disk image file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_I9qwL_PslqIZME5.png" /></figure><h3>Spotify</h3><p>The biggest surprise to me was discovering that Spotify can take a large amount of space to cache files. Mine was over 6 GB. Even Firefox’s cache was only 2 GB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lmsNxV_92d41ZMiJ.png" /></figure><p>Furthermore, there doesn’t seem to be a way to control this cache size in Spotify settings, not even buried in some advanced settings. This setting <a href="https://community.spotify.com/t5/Social/What-happened-to-the-cache-limit-setting-on-Mac-desktop-player/td-p/4658524">might have existed before</a>, but it doesn’t now. Luckily, <a href="https://community.spotify.com/t5/Desktop-Mac/How-to-limit-cache-size/td-p/2907725">someone discovered</a> that you can set a limit manually by editing the Spotify preferences file at~/Library/Application\ Support/Spotify/prefs and adding a line like storage.size=2048.</p><p>I set the limit to 2048 MB, restarted Spotify, and confirmed that the cache folder dropped to the expected size, saving me over 4 GB.</p><pre>$ du -sh ~/Library/Caches/com.spotify.client/Data<br>6.4G Data </pre><pre># restart Spotify</pre><pre>$ du -sh ~/Library/Caches/com.spotify.client/Data<br>2.0G Data</pre><h3>Yarn</h3><p><a href="https://yarnpkg.com/">Yarn</a> seemed to have old cache folders.</p><pre>$ cd ~/Library/Caches/Yarn &amp;&amp; ls <br>v2 v4 v6</pre><pre>$ du -sh v2 v4 v6<br>  0B   v2 <br>1.2G   v4 <br>1.2G   v6 </pre><pre>$ yarn cache dir<br>/Users/dguo/Library/Caches/Yarn/v6</pre><p>I deleted the v2 and v4 folders. My cache is fairly small, but <a href="https://github.com/yarnpkg/yarn/issues/6037">other people</a> have ended up with gigantic caches.</p><h3>Git</h3><p>I found some <a href="https://git-scm.com/">Git</a> repositories that I didn’t need anymore. Deleting these saved around 1 GB in total. Git repos can take up a large amount of space since by default, they contain the entire history of a project. Though in my case, most of the space savings was due to deleting node_modules with each one.</p><h3>Conclusion</h3><p>For years, I’ve used <a href="https://freemacsoft.net/appcleaner/">AppCleaner</a> to uninstall applications because I knew most of them leave files behind if you only delete the application itself. This experience reminded me that when I install an application, I generally have no idea where it’s going to write files and how large they can get. It would be nice if operating systems could make it easier for users to be more in control of hard drive usage, instead of letting applications treat the hard drive like an unlimited resource.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/clearing-mac-storage-space/"><em>https://www.dannyguo.com</em></a><em> on July 15, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aff532b82c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating From Authy to Bitwarden for 2FA Codes]]></title>
            <link>https://dannyguo.medium.com/migrating-from-authy-to-bitwarden-for-2fa-codes-8f18c18195a4?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f18c18195a4</guid>
            <category><![CDATA[bitwarden]]></category>
            <category><![CDATA[authy]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[totp]]></category>
            <category><![CDATA[2fa]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Wed, 25 Mar 2020 00:00:00 GMT</pubDate>
            <atom:updated>2020-03-25T23:55:43.673Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>I’ve used <a href="https://authy.com/">Authy</a> for several years to generate my time-based one-time passwords (<a href="https://en.wikipedia.org/wiki/Time-based_One-time_Password_algorithm">TOTP</a>) for two-factor authentication (<a href="https://en.wikipedia.org/wiki/Multi-factor_authentication">2FA</a>). For various reasons, I recently migrated to using <a href="https://bitwarden.com/">Bitwarden</a> instead.</p><h3>Google Authenticator Issues</h3><p>Many services recommend using <a href="https://en.wikipedia.org/wiki/Google_Authenticator">Google Authenticator</a> for 2FA. I originally used it before switching to Authy, but I switched for a reason that is still valid today: it doesn’t have any sort of backup or syncing functionality.</p><p>Check out the <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;showAllReviews=true">reviews</a> to get a sense of how often people get burned by switching to a new phone for whatever reason and realizing they’ve lost all their codes or need to go through each service one by one and set up 2FA again.</p><p>Google Authenticator is also a neglected app. The <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2">Android app</a> was last updated on September 27, 2017, and the <a href="https://apps.apple.com/us/app/google-authenticator/id388497605">iOS app</a> was last updated on September 12, 2018. You could argue that these are relatively simple apps that don’t need frequent updates, but take a look at what other apps like <a href="https://play.google.com/store/apps/details?id=org.shadowice.flocke.andotp">andOTP</a> and <a href="https://getaegis.app/">Aegis</a> offer in terms of functionality that Google Authenticator doesn’t have, like being able to search for a service instead of having to scroll though the entire list to find it.</p><h3>Authy Issues</h3><p>While I have happily used Authy for several years, I also have some issues with it that caused me to look for a replacement.</p><h3>No Browser Extension</h3><p>Authy doesn’t have a browser extension for <a href="https://www.mozilla.org/firefox/">Firefox</a>, my primary browser. This is a problem because an extension can offer some protection against <a href="https://en.wikipedia.org/wiki/Phishing">phishing</a>, one of the main <a href="https://www.scottbrady91.com/Authentication/Software-Tokens-Wont-Save-You">security weaknesses</a> of using TOTP for 2FA. If the extension fails to find an entry that matches the current domain, that can alert me to a possible phishing attempt.</p><p>The <a href="https://chrome.google.com/webstore/detail/authy-chrome-extension/fhgenkpocbhhddlgkjnfghpjanffonno">Chrome extension</a> also hasn’t been updated in two and a half years and will <a href="https://authy.com/blog/authy-chrome-app-extension-end-life/">no longer be supported</a> going forward.</p><h3>No Web Client</h3><p>Authy doesn’t have a web client. While this could be considered a security feature, I’d rather have the option to access my codes through any browser in an emergency. It’s a security vs. usability tradeoff that I’m willing to make.</p><h3>No CLI Client</h3><p>Authy doesn’t have a <a href="https://en.wikipedia.org/wiki/Command-line_interface">CLI</a> client. I have some ideas for personal browser automation projects that could be easier to implement with programmatic access to my TOTP codes.</p><h3>Mac CPU Usage</h3><p>I use the Mac desktop program, but when it has a code open, the program uses significantly more CPU. Here’s the CPU usage when it’s just displaying the list of services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*65ZzJ-IX72lRrRmt.png" /></figure><p>And here’s the CPU usage when it’s showing the TOTP code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u1Vs_EGUeLtydPTR.png" /></figure><p>Since I don’t want the program to unnecessarily drain my laptop battery, I try to remember to press the back button after copying the code. There’s no option to automatically go back on copy or to just copy the code from the list view without even seeing the code.</p><h3>Authentication and Recovery</h3><p>When you create an Authy account, you have to provide a phone number rather than an email address or username. I didn’t like this to begin with since I want as few things tied to my phone number as possible, given how often phone numbers <a href="https://www.wired.com/story/sim-swap-attack-defend-phone/">get hijacked</a>.</p><p>Authy then <a href="https://support.authy.com/hc/en-us/articles/360016317013-Enable-or-Disable-Authy-Multi-Device">encourages</a> you to add the app to your other devices and then disable the multi-device feature. This means that your codes will keep working on your existing devices, but to add Authy to a new device, you need access to one of your old ones to temporarily re-enable multi-device and to grant access to the new device. If you don’t have access to an old device, you have to go through a 24 hour <a href="https://support.authy.com/hc/en-us/articles/115012672088-Restoring-Authy-Access-on-a-New-Lost-or-Inaccessible-Phone#new_app">account recovery process</a>.</p><p>However, I want to be able to regain access to my 2FA codes, even if I’ve lost access to all my devices. For example, I could be in a foreign country without my laptop and then lose my phone. I want to have a good contingency plan for this kind of situation.</p><p>Note that Authy doesn’t support an account level password. It does support a password for your encrypted backups, but you don’t enter that until after you log in.</p><p>Authy also doesn’t support TOTP codes or <a href="https://en.wikipedia.org/wiki/Universal_2nd_Factor">U2F</a> security keys for protecting itself. Its sole authentication mechanism (beyond account recovery processes) is access to an old device.</p><h3>Yubico Authenticator</h3><p>I considered using my <a href="https://www.yubico.com/">YubiKeys</a> to generate TOTP codes using <a href="https://www.yubico.com/products/services-software/download/yubico-authenticator/">Yubico Authenticator</a>, but a YubiKey <a href="https://www.reddit.com/r/yubikey/comments/ataxt3/only_32_oathtotp_entries/">can only store 32</a> TOTP secrets, and I already have 49 of them since I enable TOTP-based 2FA whenever possible.</p><h3>Bitwarden</h3><p>I currently use <a href="https://www.lastpass.com/">LastPass</a> to manage my passwords, but I am going to switch to <a href="https://1password.com/">1Password</a> soon. I decided to use Bitwarden as well but solely for TOTP codes. 1Password can also <a href="https://support.1password.com/one-time-passwords/">handle TOTP codes</a>, but I am willing to deal with the hassle of having two password managers to avoid using the same service for both passwords and 2FA.</p><p>By using a password manager for TOTP, I get broad cross-platform support with a web client, browser extensions, desktop programs, mobile apps, and even a CLI client. I also get standard authentication mechanisms, including 2FA support.</p><p>This does mean that I am treating my TOTP codes more like secondary passwords (<a href="https://en.wikipedia.org/wiki/Multi-factor_authentication#Knowledge_factors">something I know</a>) rather than as <a href="https://en.wikipedia.org/wiki/Multi-factor_authentication#Possession_factors">something I have</a>. Authy’s requirement to have access to an old device better fits the latter principle. This is a deliberate choice on my part.</p><p>Note that Bitwarden requires a premium account that costs $10 a year in order to generate TOTP codes. A premium account also adds U2F support, which I wanted as well.</p><h3>Authentication Strategy</h3><p>U2F support is the last component of my authentication strategy. Going forward, it will be like this: I’ll store passwords in 1Password and TOTP secrets in Bitwarden. I’ll use separate, <a href="https://xkcd.com/936/">high entropy</a> master passwords that will only exist in my head.</p><p>1Password requires a <a href="https://support.1password.com/secret-key/">secret key</a> in conjunction with the master password in order to log in on a new device. Since I can’t memorize it, I plan to store my secret key as a <a href="https://support.yubico.com/support/solutions/articles/15000006480-understanding-core-static-password-features">static password</a> on my YubiKeys. This means that if I touch the metal contact for a few seconds, it will type out the secret key for me.</p><p>For both services, I’ll add all my YubiKeys for 2FA. This means that all I need is one of my YubiKeys (one of which is on my keychain) and the master passwords in my head to regain full access to all of my accounts.</p><p>However, I can’t guarantee that I’ll be able to use my YubiKey on every device. For example, Bitwarden <a href="https://help.bitwarden.com/article/setup-two-step-login-u2f/">doesn’t support</a> U2F in its mobile apps. I would also be paranoid about feeling like I need two YubiKeys when I travel in case I lose one.</p><p>My plan to deal with these issues is to also set up TOTP-based 2FA for both 1Password and Bitwarden. I’ll print those TOTP secrets, along with the 1Password secret key, on a small card and laminate it. I can make multiple copies to put in my wallet and my bag. Sometimes being overly prepared is fun in itself, even though it might be overkill.</p><h3>Migration</h3><p>To migrate to Bitwarden, I went through my Authy list one by one. In theory, I’d be able to just copy the TOTP secret to Bitwarden, but Authy doesn’t expose the secret.</p><p>For each account, I logged in and reset 2FA to add the secret to Bitwarden. Then I deleted the account from Authy. Authy marks it for deletion and then waits 48 hours before actually deleting it in case you made a mistake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/0*hN7tmMydgbhgFWbP.png" /></figure><p>I did have trouble with adding some services, such as <a href="https://www.algolia.com/">Algolia</a> and <a href="https://www.npmjs.com/">npm</a>, that only show the QR code and don’t have an option to display the TOTP secret. The QR codes encode URIs that look like this, as <a href="https://github.com/google/google-authenticator/wiki/Key-Uri-Format">documented</a> in the Google Authenticator wiki:</p><pre>otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&amp;issuer=Example</pre><p>I tried using my phone camera’s built-in QR scanner, but I couldn’t see the full URI and opening it would open Authy, with no other option. I used <a href="https://lens.google.com/">Google Lens</a> instead to grab the secret. In retrospect, I was only having trouble because I was adding the services to Bitwarden through the browser extension. I should have installed the mobile app from the beginning and used that because it has an option to scan QR codes.</p><p>I also had trouble with adding <a href="https://www.twitch.tv/">Twitch</a>, which has a specific integration with Authy instead of providing a generic QR code. To get around the issue, I followed <a href="https://medium.com/@dubistkomisch/set-up-2fa-two-factor-authentication-for-twitch-with-google-authenticator-or-other-totp-client-f19af32df68a">this guide</a>. You can use the deprecated <a href="https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb/related">Authy Chrome app</a> to retrieve the TOTP secrets and configurations. This method entails using Chrome’s developer tools to execute <a href="https://gist.github.com/gboudreau/94bb0c11a6209c82418d01a59d958c93">custom code</a> to print the information.</p><p>This revealed that Twitch uses 7 digit codes instead of the standard 6 and 10 second intervals instead of the standard 30.</p><pre>otpauth://totp/Twitch?secret=XXXXXXXX&amp;digits=7&amp;period=10</pre><p>At this point, I thought I hit a Bitwarden limitation because I mistakenly assumed that the extension would only take the TOTP secret in the authenticator key field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*ZErGm6IO75Lk5c3r.png" /></figure><p>However, I discovered that Bitwarden <a href="https://community.bitwarden.com/t/support-totp-auth-parameters/37">supports</a> putting the full URI with configuration into that field. I tested it and was able to log in to Twitch using the code generated by Bitwarden.</p><h3>Conclusion</h3><p>Migrating to Bitwarden took me about a full day, but I’m happy with the result. I’ve been using the Bitwarden browser extension to log in to accounts for the past week, and it is much nicer than using the Authy desktop program. Next up is migrating from LastPass to 1Password.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/migrating-from-authy-to-bitwarden-for-2fa-codes/"><em>https://www.dannyguo.com</em></a><em> on March 25, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f18c18195a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Add Copy to Clipboard Buttons to Code Blocks in Hugo]]></title>
            <link>https://dannyguo.medium.com/how-to-add-copy-to-clipboard-buttons-to-code-blocks-in-hugo-6b383430850f?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b383430850f</guid>
            <category><![CDATA[hugo]]></category>
            <category><![CDATA[static-websites]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Sat, 23 Mar 2019 02:55:05 GMT</pubDate>
            <atom:updated>2019-03-24T03:39:26.505Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>A small quality of life improvement for programming-related websites is to add copy to clipboard buttons to code blocks. When a visitor wants to copy a code example or a shell command, it’s nice to be able to just hit a button rather than manually select the text, right click, and press copy.</p><p>I use <a href="https://gohugo.io/">Hugo</a> to build my <a href="https://www.dannyguo.com/">personal website</a>. While Hugo has built-in support for <a href="https://gohugo.io/content-management/syntax-highlighting/">syntax highlighting</a>, it doesn’t support copy buttons. Here is how I added the feature to my website. The end result looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/0*3_a77MyarIZ0XBAk.png" /></figure><h3>Adding the buttons</h3><p>I inspected the source of a page with code blocks and found that Hugo generates each block with markup like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4dccddf52317381cdfe99044cec20f1d/href">https://medium.com/media/4dccddf52317381cdfe99044cec20f1d/href</a></iframe><p>Code blocks without syntax highlighting have the same structure but without the surrounding highlight div. To account for both cases, I selected for <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code">code</a> elements that are children of <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre">pre</a> elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da6cf5b28c0b2eddfa7629263cf4da40/href">https://medium.com/media/da6cf5b28c0b2eddfa7629263cf4da40/href</a></iframe><p>For many implementations of copy code buttons that I’ve seen, the button is located in the top right or bottom right corner of the code block. However, I’ve noticed that the button can cover up some of the code if the line is too long, especially on mobile. To avoid this possibility, I placed each button before the entire code block.</p><p>Some implementations only show the button when the user hovers over the code block, but for discoverability, I left the buttons always visible.</p><p>For styling the buttons, I used this CSS:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8552dc8ce618dab78f1597650d75211/href">https://medium.com/media/c8552dc8ce618dab78f1597650d75211/href</a></iframe><h3>Interacting with the clipboard</h3><p>Next, I investigated how to <a href="https://stackoverflow.com/q/400212/1481479">copy to the clipboard using JavaScript</a>. The most popular library for doing so is <a href="https://clipboardjs.com/">clipboard.js</a>, but I wanted to avoid bringing in a dependency if possible.</p><p>One way is to use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand">execCommand</a> with document.execCommand(&#39;copy&#39;), which copies the current text selection. <a href="https://github.com/zenorocha/clipboard.js">Under the hood</a>, clipboard.js uses this method.</p><p>However, there is a newer approach, the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API">Clipboard API</a>. It has <a href="https://developers.google.com/web/updates/2018/03/clipboardapi">several advantages</a>: it’s asynchronous, takes arbitrary text/data (so it doesn’t have to already exist on the page), and has a better story for dealing with permissions. Chrome, Firefox, and Opera <a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API#Browser_compatibility">support it</a> already. For other browsers, there is a <a href="https://github.com/lgarron/clipboard-polyfill">polyfill</a>.</p><p>I put the code in a function and added click handlers. I used <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText">innerText</a> to get the code to be copied. After the copy operation, the button displays either an error message or a success message that lasts for two seconds.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/089b8228dfaa5127a16d0f7943884384/href">https://medium.com/media/089b8228dfaa5127a16d0f7943884384/href</a></iframe><p>Next, I added a check for whether or not the browser supports the Clipboard API. If not, the script loads the polyfill from <a href="https://cdnjs.com/libraries/clipboard-polyfill">CDNJS</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff3b9f0aa6a7f20104d4ab93837bc30d/href">https://medium.com/media/ff3b9f0aa6a7f20104d4ab93837bc30d/href</a></iframe><p>After the Clipboard API becomes ubiquitous, I’ll remove the polyfill code.</p><h3>Smart loading with Hugo</h3><p>After I got the functionality to work, I thought about how to include the script. I had three options. The first was to indiscriminately include it on every page. The script is small, but for optimization, I wanted to only include it when it’s actually needed, saving a bit of bandwidth and a network request (or two, if the polyfill is needed).</p><p>The second option was to use a <a href="https://gohugo.io/content-management/front-matter/#user-defined">custom Hugo front matter variable</a>. With this method, I’d set a flag on every post that has a code block. The template could then check for this flag. However, this approach involves manual work and runs the risk of me forgetting to do it.</p><p>The third option was to find a way to use Hugo to figure out which pages have at least one code block. A regex seemed like the way to go. I used Hugo’s <a href="https://gohugo.io/functions/findre/">findRE</a> function to determine if the HTML seems to contain a pre element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18a88c133cad27cd235f7f21a733ae65/href">https://medium.com/media/18a88c133cad27cd235f7f21a733ae65/href</a></iframe><p>I passed it a limit parameter of 1 because I only care if the page <em>has</em> a code block or not, not the total number of code blocks.</p><p>Keep in mind that this script should be loaded after the page content, preferably at the end of the body so that it doesn’t block rendering. Otherwise, the selector might run before the code blocks actually exist.</p><h3>Non-Hugo websites</h3><p>This solution should easily work for non-Hugo websites as well. The only part of the script that is specific to Hugo is the pre &gt; code selector. Modifying the selector and possibly where the button is inserted should be all that is needed.</p><h3>CodeCopy</h3><p><a href="https://github.com/zenorocha/codecopy">CodeCopy</a> is a browser extension for <a href="https://chrome.google.com/webstore/detail/codecopy/fkbfebkcoelajmhanocgppanfoojcdmg">Chrome</a> and <a href="https://addons.mozilla.org/en-US/firefox/addon/codecopy/">Firefox</a> that adds copy buttons to code blocks on many websites that are likely to have them, such as <a href="https://github.com/">GitHub</a> and <a href="https://stackoverflow.com/">Stack Overflow</a>. It’s made by the <a href="https://zenorocha.com/">same person</a> behind clipboard.js.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/how-to-add-copy-to-clipboard-buttons-to-code-blocks-in-hugo/"><em>www.dannyguo.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b383430850f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animated Multiline Link Underlines with CSS]]></title>
            <link>https://dannyguo.medium.com/animated-multiline-link-underlines-with-css-abe07f3d6aee?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/abe07f3d6aee</guid>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 23:19:01 GMT</pubDate>
            <atom:updated>2019-09-14T14:37:02.713Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>One benefit of building my <a href="https://www.dannyguo.com/">personal website</a> from scratch instead of using a <a href="https://themes.gohugo.io/">theme</a> made by someone else is that I can start from the browser’s defaults and gradually add my own flourishes. I strive to keep my site lean, but making it personal is also kind of the point. There is a spectrum of gratuitous touches between the spartan pages of <a href="https://news.ycombinator.com/">Hacker News</a> and <a href="https://newyork.craigslist.org/">Craigslist</a> on one end and the sensory overload of <a href="https://news.codecademy.com/myspace-coding-legacy/">old MySpace</a> on the other.</p><p>I ran across a site that had fancy, animated underlines for links, and I wanted to add a similar effect to my site. It was important to me to use a pure CSS solution. For something as frivolous as this, I didn’t want to add JavaScript that has a risk of causing a performance issue or frustrating behavior (see <a href="https://envato.com/blog/scroll-hijacking/">scroll hijacking</a>).</p><p>Here’s what the effect looks like now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*dknxfGPkevrlrGFNFoGykw.gif" /></figure><h3>Implementation</h3><p>The topic of drawing lines under text on the web can be <a href="https://medium.design/crafting-link-underlines-on-medium-7c03a9274f9">surprisingly complicated</a>, depending on how far you are willing to <a href="https://css-tricks.com/styling-underlines-web/">stray</a> from text-decoration: underline and which details (like <a href="https://stackoverflow.com/q/40008990/1481479">clearing descenders</a>) you care about.</p><p>I investigated a few approaches:</p><ul><li><a href="http://tobiasahlin.com/blog/css-trick-animating-link-underlines/">Animating Link Underlines</a></li><li><a href="http://www.cssportal.com/blog/css-animated-underline-links/">CSS Animated Underline Links</a></li></ul><p>Both of them essentially remove the default <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration">text-decoration</a> and add a simulated border using <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements">pseudo-elements</a>. The border is then animated by <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions">CSS transitions</a>. Unfortunately, these solutions have one drawback: they don’t work properly if the link spans more than one line. The underline only appears on the first line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*pYs0BAQ6n85GTE7RHynpLg.gif" /></figure><p>I eventually found a <a href="https://codepen.io/shshaw/pen/pdyJBW">CodePen</a> by <a href="https://twitter.com/shshaw">Shaw</a> that doesn’t have this flaw. I modified the CSS until I got to a solution that looks good to me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*cwhn_A79jgSqEJO5WUNoug.gif" /></figure><p>Here is the relevant code. You can use <a href="https://repl.it/@dyguo/animated-multiline-link-underlines">this repl</a> to play around with it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a91c3fb43981b874a01793c7b94aa6e2/href">https://medium.com/media/a91c3fb43981b874a01793c7b94aa6e2/href</a></iframe><p>Let’s go through this approach part by part. First, we turn off the default text-decoration for links.</p><p>We want to use <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-image">background-image</a> because it can span multiple lines. While we could supply an actual image, we only want to draw a line, so we use <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient">linear-gradient</a>, which generates an image for us. Normally, it’s used to create a gradient between two different colors, but I want the underline to just be the same color as the link, so I use <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentColor_keyword">currentColor</a> for both the beginning and the end of the gradient. currentColor tells the browser to use the element’s computed <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/color">color</a> property.</p><p>We use <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-position">background-position</a> to place the image in the bottom left corner. 0% sets the horizontal position, and 100% sets the vertical position.</p><p>We turn off <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat">background-repeat</a> to prevent it from creating multiple instances of the image to fill the entire background of the link.</p><p>We use <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-size">background-size</a> to make the image zero pixels wide and two pixels tall. It has zero width because the underline should only appear on hover.</p><p>We set a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transition">transition</a> on background-size, so any change to the property will take 0.3 seconds to complete.</p><p>On link <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:hover">hover</a>, we change the width of the image to 100%, creating a full underline, and transition takes care of the animation. As <a href="https://www.reddit.com/r/web_design/comments/a7y701/animated_multiline_link_underlines_with_css/ec6pwel/">nickels55 suggests</a>, we also want the effect to happen on focus for those who use keyboard navigation. Thanks to nickels55 for keeping <a href="https://en.wikipedia.org/wiki/Web_accessibility">accessibility</a> in mind.</p><p>And that’s it! I was very happy with how small the <a href="https://github.com/dguo/dannyguo.com/commit/14e51391329163fa414ac55d77fdf6da521ab644">commit</a> ended up being. If you’d like to add something similar to your site, feel free to take this implementation, or check out some other <a href="https://speckyboy.com/underline-text-effects-css/">animated underline effects</a> for inspiration.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/animated-multiline-link-underlines-with-css/"><em>www.dannyguo.com</em></a><em>.</em></p><p><em>Found an error or typo? Feel free to open a pull request on </em><a href="https://github.com/dguo/dannyguo.com/blob/master/content/blog/animated-multiline-link-underlines-with-css.md"><em>GitHub</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abe07f3d6aee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Mailgun for a Free Custom Domain Email Address]]></title>
            <link>https://dannyguo.medium.com/using-mailgun-for-a-free-custom-domain-email-address-a6bc4e7e1336?source=rss-14b9ce6433d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6bc4e7e1336</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[email]]></category>
            <dc:creator><![CDATA[Danny Guo]]></dc:creator>
            <pubDate>Fri, 07 Dec 2018 23:37:37 GMT</pubDate>
            <atom:updated>2019-09-14T14:42:51.878Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>I’ve been using <a href="https://www.google.com/gmail/about/">Gmail</a> for my primary email address for over 13 years. I should thank my sister for making me use my name and not my now embarrassing <a href="https://en.wikipedia.org/wiki/AIM_(software)">AIM</a> username. Here’s a look at the welcome email back in 2005. Gmail wasn’t even a year old yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*EqELDS2tR9krFsd_.png" /></figure><p>Gmail has served me well since then, but mostly for fun (and partly because of <a href="https://theoatmeal.com/comics/email_address">vanity</a>), I recently set up an email address on <a href="https://dannyguo.com/">my own domain</a>. I ended up going with a free solution that involves <a href="https://www.mailgun.com/">Mailgun</a> and is good enough for my purposes. I wanted to still use my Gmail account to actually receive and send the custom domain emails. It isn’t important to me right now to actually have a separate inbox or to stop using Google for email.</p><h3>Options</h3><p>Several years ago, a common choice was Google Apps (now known as <a href="https://gsuite.google.com/">G Suite</a>) because it was free for up to five users. G Suite <a href="https://support.google.com/a/answer/2855120">got rid</a> of the free edition and <a href="https://gsuite.google.com/pricing.html">costs</a> $5 per month now, so I investigated alternatives.</p><p>I’ve read about <a href="https://www.zoho.com/mail/">Zoho Mail</a> as a free alternative. Unfortunately, it stopped offering <a href="https://en.wikipedia.org/wiki/Post_Office_Protocol">POP</a> and <a href="https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol">IMAP</a> access for its free plan <a href="https://help.zoho.com/portal/community/topic/zoho-free-tier-pop-imap-activesync-no-longer-free">earlier this year</a>, so the only way to access my email would be through Zoho’s website or apps. It would <a href="https://www.zoho.com/workplace/pricing.html">cost</a> $3 per month to add POP and IMAP support. I don’t fault Zoho for making this change, but I would prefer to access all my email through my Gmail account. I have also read some anecdotes that Zoho Mail can be slow in sending and receiving emails.</p><p>Next, I looked at <a href="https://www.fastmail.com/">FastMail</a> and <a href="https://protonmail.com/">ProtonMail</a>, which are frequently cited by people who have chosen to <a href="https://nomoregoogle.com/">avoid Google services</a>. FastMail <a href="https://www.fastmail.com/pricing/">costs</a> $5 per month or $50 per year for a plan that includes custom domain support. ProtonMail <a href="https://protonmail.com/support/knowledge-base/custom-domain-support/">requires a paid plan</a> for the feature, and the cheapest <a href="https://protonmail.com/pricing">paid plan</a> is $5 per month or $48 per year.</p><p>Another option was to use <a href="https://domains.google/">Google Domains</a>. It includes a free <a href="https://support.google.com/domains/answer/3251241">email forwarding feature</a> that allows for sending an email from the alias as well. However, the feature is only available when you <a href="https://support.google.com/domains/answer/3251241">use Google’s name servers</a>. My site runs on <a href="https://www.netlify.com/">Netlify</a>, and I use their <a href="https://www.netlify.com/docs/dns/">DNS service</a>.</p><p>I also looked at mailboxes from other domain registrars. <a href="https://www.gandi.net/">Gandi</a> includes <a href="https://www.gandi.net/en/domain/email">two mailboxes</a> with every domain, but Gandi’s domain prices also <a href="https://tld-list.com/">seem more expensive</a> than elsewhere, especially when considering that <a href="https://www.cloudflare.com/">Cloudflare</a>’s <a href="https://blog.cloudflare.com/cloudflare-registrar/">at-cost domain registrar service</a> is scheduled to be available soon.</p><p><a href="https://www.namecheap.com/">Namecheap</a> has very affordable <a href="https://www.namecheap.com/hosting/email.aspx">email hosting</a> that only costs $9.88 a year. I was ready to set it up when I stumbled upon one last solution, deep in search results for “custom domain email.” Some people use <a href="https://www.mailgun.com/">Mailgun</a>.</p><h3>Mailgun</h3><p>Essentially, incoming emails go to Mailgun. With a routing rule, I can forward those emails to my Gmail, and with some additional configuration, I can also send emails from my Gmail but have them appear as if they are sent from my custom domain.</p><p>Mailgun’s <a href="https://www.mailgun.com/pricing">free tier</a> is way more than enough. It allows for 10,000 emails per month. That includes both incoming and outgoing emails, but for a personal email account, I’ll never even come close to that limit. Even if I do manage to go over, it only costs $0.50 for every additional thousand emails.</p><p>The plan does restrict you from sending to email addresses that you haven’t explicitly added to an “authorized recipients” list. However, Mailgun lifts this restriction if you provide a payment method, which puts you on the “concept” <a href="https://help.mailgun.com/hc/en-us/articles/203068914-What-are-the-differences-between-the-free-and-concept-plans-">plan</a>. I was happy to do so.</p><p>Do note that Mailgun <a href="https://help.mailgun.com/hc/en-us/articles/203306710-Can-I-use-Mailgun-for-my-personal-email-address-">does not officially recommend</a> using the service for personal email, but they do not forbid it. They recommend using hosted email services like G Suite instead, which I would definitely do for something like a business.</p><h3>Instructions</h3><p>Here are the step by step instructions. <a href="https://signup.mailgun.com/">Sign up</a> for a Mailgun account, and provide a payment method unless you’re okay with the sending restriction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/0*PofxeC-tUrDtWOcf.png" /></figure><p>Go the “<a href="https://app.mailgun.com/app/domains">Domains</a>” tab to <a href="https://app.mailgun.com/app/domains/new">add a new domain</a>. The page recommends using a subdomain, like “mail.yourdomain.com” instead of just “yourdomain.com”. The reason for this recommendation is that in general, you don’t want to risk hurting your root domain’s <a href="https://www.sparkpost.com/resources/email-explained/email-sender-reputation/">email sender reputation</a>. Companies will sometimes <a href="https://help.mailgun.com/hc/en-us/articles/202256730-How-do-I-pick-a-domain-name-for-my-Mailgun-account-">use different domains or subdomains</a> for sending transactional versus marketing emails.</p><p>For the purpose of a personal email address, use the root domain if you want to receive email there (ben@yourdomain.com) rather than at a subdomain (ben@mail.yourdomain.com). The risk of harming your sender reputation is much lower because you presumably aren’t going to use your personal email to email tons of strangers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*4YrGaCNAZnMOmkaI.png" /></figure><p>Next, go to wherever you manage your website’s DNS settings (like your domain registrar), and add the DNS records provided by Mailgun. The <a href="https://en.wikipedia.org/wiki/MX_record">MX records</a> are for setting Mailgun’s servers as the recipient for emails. The <a href="https://en.wikipedia.org/wiki/TXT_record">TXT records</a> are for setting up <a href="https://en.wikipedia.org/wiki/Sender_Policy_Framework">SPF</a> and <a href="https://en.wikipedia.org/wiki/DomainKeys_Identified_Mail">DKIM</a>, which are two ways for recipients to verify an email’s authenticity. You don’t need to add the <a href="https://en.wikipedia.org/wiki/CNAME_record">CNAME record</a> unless you want to track what your recipients do with your emails, like opening them and clicking links inside them.</p><p>It might take a while for the DNS changes to propogate, though mine only took about a minute. Tell Mailgun to check the DNS records. Once they are verified, you can go to the “<a href="https://app.mailgun.com/app/routes">Routes</a>” tab to <a href="https://app.mailgun.com/app/routes/new">create</a> a <a href="https://mailgun-documentation.readthedocs.io/en/latest/api-routes.html#routes">routing rule</a>.</p><p>Change the expression type to “Match Recipient,” and set the custom domain address that you want to use. Then check the “Forward” action, and set the address where you actually want to receive the emails (like a Gmail account). You could set up more sophisticated rules, or even add additional addresses that all forward to the same email address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/0*cPLS6zfjGAQyjtSP.png" /></figure><p>At this point, receiving emails should work. Go ahead, and try it out. I also created a <a href="https://support.google.com/mail/answer/118708">Gmail label</a>, and set up a <a href="https://support.google.com/mail/answer/6579">filter</a> so that all emails from my custom domain get tagged with it, making it easy for me to view only those emails if I want to.</p><p>To make sending work, you’ll need some additional information from Mailgun. Go back to the domains tab, and open your domain. You’ll need the values for “SMTP Hostname,” “Default SMTP Login,” and “Default Password.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/0*j3HmRd84QDK0RQrM.png" /></figure><p>Go to Gmail settings, and open the “Accounts and Import” tab. In the “Send mail as” section, add the custom domain email address. I unchecked the “Treat as an alias” option because I want to automatically reply with whichever address is the intended recipient. I don’t want to have to manually change the sender. Normally, <a href="https://support.google.com/a/answer/1710338">unchecking the option</a> means that emails sent to the other address won’t show up in Gmail, but in this case, Mailgun is handling that part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/0*u9tTof-JkSMkOk0R.png" /></figure><p>Go to the next step, and fill in the info from Mailgun. The Mailgun “SMTP Hostname” corresponds to the Gmail “SMTP Server” field, and the “Default SMTP Login”” corresponds to the “Username” field. Leave the SMTP port as 587, and make sure to fill in the password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/0*NKXz8-sK-2htk8A1.png" /></figure><p>Press the “Add Account” button, and you should get a confirmation email from Gmail that contains a link you can use to verify the request. At this point, sending emails should work too! When you compose an email, you can click on the “From” field to change who you are sending as.</p><p>Try it out. Your recipient should receive the email, and the email details should have both the “mailed-by” and “signed-by” fields set to your custom domain. From their perspective, they don’t know that you actually used Gmail to send the email.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/0*m-pQXaWTPzYDkJPG.png" /></figure><p>One last thing you can do is to set a monthly sending limit with your Mailgun account. The option is in your <a href="https://app.mailgun.com/app/account/settings">account settings</a>. Look for the “Custom Message Limit” field. Just in case someone manages to get access to your Gmail and tries to use your custom domain address to send email, Mailgun will stop processing emails once the limit is hit.</p><h3>Conclusion</h3><p>If Mailgun does change in a way that makes it an unreasonable solution, I will probably switch to a Namecheap or ProtonMail mailbox. Until then, I’m happy to have found a free solution for a custom domain email address.</p><p><em>Originally published at </em><a href="https://www.dannyguo.com/blog/using-mailgun-for-a-free-custom-domain-email-address/"><em>www.dannyguo.com</em></a><em>.</em></p><p><em>Found an error or typo? Feel free to open a pull request on </em><a href="https://github.com/dguo/dannyguo.com/blob/master/content/blog/using-mailgun-for-a-free-custom-domain-email-address.md"><em>GitHub</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6bc4e7e1336" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>