<?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 Leyan Lo on Medium]]></title>
        <description><![CDATA[Stories by Leyan Lo on Medium]]></description>
        <link>https://medium.com/@leyanlo?source=rss-5d175d6fc496------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TPP0t1OzrChxJmVY.jpeg</url>
            <title>Stories by Leyan Lo on Medium</title>
            <link>https://medium.com/@leyanlo?source=rss-5d175d6fc496------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:25:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leyanlo/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[How to Reset React Context]]></title>
            <link>https://leyanlo.medium.com/how-to-reset-react-context-473cb2e0fab6?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/473cb2e0fab6</guid>
            <category><![CDATA[react-context]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Sat, 30 Apr 2022 07:35:47 GMT</pubDate>
            <atom:updated>2022-04-30T07:35:47.559Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="React context code snippet" src="https://cdn-images-1.medium.com/max/1024/1*c9jeDSPK4AvTUcrlhx_nnw.png" /></figure><p><a href="https://reactjs.org/docs/context.html">React Context</a> is great for maintaining state among all your descendent components. Simply define the context with <strong>React.createContext()</strong> and pass the initial values via the <strong>value</strong> prop to the provider:</p><pre>const initialContext = {<br>  myData: null,<br>};<br><br>const MyContext = React.createContext(initialContext);<br><br>export function MyPage() {<br>  return (<br>    &lt;MyContext.Provider value={initialContext}&gt;<br>      &lt;MyPageChildren /&gt;<br>    &lt;/MyContext.Provider&gt;<br>  );<br>}</pre><p>But what if you needed a way to reset the context back to its initial value later on? In this example, the context values persist even if you unmount and remount the <strong>MyPage</strong> component, e.g. by navigating to a different route and back again. This is because <strong>initialContext </strong>is a global variable, and any updates we make will persist for the lifetime of the app.</p><h4>Create a copy?</h4><p>You could try to fix this by creating a copy of <strong>initialContext </strong>instead:</p><pre>export function MyPage() {<br>  return (<br>    &lt;MyContext.Provider value={<strong>{ ...initialContext }</strong>}&gt;<br>      &lt;MyPageChildren /&gt;<br>    &lt;/MyContext.Provider&gt;<br>  );<br>}</pre><p>This will guarantee a new object every time. But the problem with this approach is that any re-render from a prop or state update will also destroy the context values, which is not what we want. If we want to keep the values across re-renders, but reset the values on unmount, what can we do?</p><h4>useRef to the rescue!</h4><p>We can advantage of <strong>React.useRef() </strong>to make sure the context is maintained across updates, but is reset on unmount:</p><pre>export function MyPage() {<br>  const { current: myContext } = <strong><em>React</em></strong>.useRef({<br>    ...initialContext,<br>  });<br>  return (<br>    &lt;MyContext.Provider value={myContext}&gt;<br>      My page<br>    &lt;/MyContext.Provider&gt;<br>  );<br>}</pre><p>This will create a new context on mount, and will hold the copy for the lifetime of the <strong>MyPage</strong> component. If the page gets unmounted, e.g. by navigating to a different route, the context will be reset when you return. Problem solved!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=473cb2e0fab6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to format USB drives for Honda audio systems]]></title>
            <link>https://leyanlo.medium.com/how-to-format-usb-drives-for-honda-audio-systems-8aeb5c47078a?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aeb5c47078a</guid>
            <category><![CDATA[honda]]></category>
            <category><![CDATA[usb]]></category>
            <category><![CDATA[audio]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Thu, 17 Feb 2022 22:52:02 GMT</pubDate>
            <atom:updated>2022-02-17T22:52:02.044Z</atom:updated>
            <content:encoded><![CDATA[<p>USB audio is a great option for keeping your favorite music ready, without having to rely on the radio or Spotify on your phone. It is the spiritual successor to keeping CDs in the car, especially for cars that no longer have CD drives. However, there are a few problems that need to be addressed when loading mp3s onto a drive.</p><h3>1. Remove dotfiles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YHjanFR13tISLthjpwqxUw.jpeg" /><figcaption>Honda audio system showing dotfiles in the music directory</figcaption></figure><p>On macOS, when you open a drive in Finder, it will create hidden dotfiles in all directories. These will show up in the Honda audio system UI unless they are removed. Run the <a href="https://ss64.com/osx/dot_clean.html"><strong>dot_clean</strong></a><strong> </strong>command on the drive to remove these files, e.g.</p><pre>dot_clean /Volumes/Samsung USB</pre><p><em>(note: you may need to </em><a href="https://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/"><em>grant Full Disk Access to Terminal</em></a><em> if you run into permission errors)</em></p><h3>2. Sort files based on filename</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dc2zzSIQhu0l-7jyklwFcA.jpeg" /><figcaption>Honda audio system showing files in random order</figcaption></figure><p>Now that the dotfiles are removed, we see that the files appear in random order. This is because files are sorted by date rather than by filename. To fix this, we will need to install and run the utility, <a href="https://fatsort.sourceforge.io/"><strong>fatsort</strong></a>. If you have <a href="https://brew.sh/">Homebrew</a>, you can install with:</p><pre>brew install fatsort</pre><p>Then we need to run <strong>fatsort</strong> on the device path. Find the device path using <strong>mount</strong>:</p><pre>mount</pre><p>Now that we have the device path (/dev/disk4s1 on my machine), we can unmount the drive and run <strong>fatsort</strong> with sudo:</p><pre>diskutil unmount /dev/disk4s1<br>sudo fatsort -cfn /dev/disk4s1</pre><h3>3. Enjoy!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2kEHHgFMviv8zp7uazIzg.jpeg" /><figcaption>Honda audio system showing files sorted by name</figcaption></figure><p>Files should now be sorted and ready to go!</p><h3>4. (optional) Use a compact USB drive</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V1hNvSnPL-e_yU6TgaOT1Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_4WdhZgdqz181lD2S1nKw.jpeg" /><figcaption>Left: regular USB drive. Right: compact USB drive</figcaption></figure><p>I also recommend using a compact USB drive like with the <a href="https://www.amazon.com/SanDisk-64GB-Cruzer-Flash-Drive/dp/B07MDXBTL1/">SanDisk Cruzer Fit</a> to minimize chances of bumping into it and damaging the port.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aeb5c47078a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I got hacked and lost thousands of dollars through Coinbase]]></title>
            <link>https://leyanlo.medium.com/how-i-got-hacked-and-lost-thousands-of-dollars-through-coinbase-31158df8a41a?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/31158df8a41a</guid>
            <category><![CDATA[fraud]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[coinbase]]></category>
            <category><![CDATA[hacked]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Sun, 20 Jun 2021 21:37:23 GMT</pubDate>
            <atom:updated>2021-09-30T06:35:56.012Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Stock image of Bitcoin" src="https://cdn-images-1.medium.com/max/1024/1*8XgaMfF-weGmwQnjDW_Oeg.jpeg" /></figure><p>On the morning of April 16, 2021, a remote attacker accessed my machine using VNC and took advantage of my browser signed into Gmail to reset passwords and sign into Coinbase to transfer funds.</p><h3>Total stolen</h3><p><strong>$2,814</strong> was transferred to my Coinbase account to purchase Bitcoin. $500 was then transferred to a foreign account and is lost forever due to Coinbase’s lack of insurance. The remaining amount would only be worth $1,300 today, but unfortunately Coinbase disabled my login so I can no longer access my account. To add insult to injury, their support has been unresponsive, and it is unclear whether I will see those funds ever again 😢</p><p>The attacker also stole my Chase credit card reward points by redeeming a $200 gift card, but thankfully Chase was able to restore the points to my account.</p><h3>Timeline of the attack</h3><p>Since the attacker used my browsers, I have a record of all the sites they visited in Chrome and Safari:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*pQpYFw2s4fmn8emHJnSShg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*3OOFRwIZT7R9dygKandLtw.png" /><figcaption>Screenshots of Chrome browser history</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*em8veabd-vxC5ffVW8Oqlg.png" /><figcaption>Screenshot of Safari browser history</figcaption></figure><p><strong>8:10am</strong>: log into my computer</p><p><strong>8:25am</strong>: download and install TeamViewer</p><p><strong>8:38am</strong>: attempt to send $844 to Colm Gallagher &lt;<a href="/service/mailto:mecolmg@gmail.com">mecolmg@gmail.com</a>&gt; using Google Pay</p><p><strong>8:38am</strong>: attempt to send $844 to <a href="/service/mailto:mitchellinvestllc@gmail.com">mitchellinvestllc@gmail.com</a> using Google Pay</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eqNO4lOEF1J5kpu0woXR6A.png" /><figcaption>Screenshot of Google Pay transactions</figcaption></figure><p><strong>8:40am</strong>: search email for cryptocurrency and financial accounts, e.g. emails from Binance, Coinbase, Gemini, Chase, and Ally Bank</p><p><strong>8:43am</strong>: set up Gmail filters to immediately delete any emails from binance, coinbase, gemini, chase, or ally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*-LFQkBdCDiMFTmdlBNDyDg.png" /><figcaption>Screenshot of Gmail filters</figcaption></figure><p><strong>8:50am</strong>: transfer $500 (0.0079462 BTC) from Ally Bank to Coinbase</p><p><strong>8:52am</strong>: transfer $500 (0.0079462 BTC) from Coinbase to <a href="https://www.blockchain.com/btc/tx/ce09a60d2765c37e801226ee38ff0dd91dd1d8ad124dc43f215d82928a0bdca2">13JKFEjHDF9ZTEyd9XxDEs357Dvhve814d</a></p><p><strong>8:56am</strong>: transfer $2,314 (0.03673242 BTC) from Ally Bank to Coinbase</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*MS8HmybAg_8Xfbsv4esp-w.png" /><figcaption>Screenshot of Coinbase transactions</figcaption></figure><p><strong>9:30am</strong>: sign into Chase and purchase $200 Home Depot gift card using points</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*A78XqGKULPzoSNgyuml7mw.png" /><figcaption>Screenshot of Chase gift card order</figcaption></figure><h3>Suspects</h3><p>Because Bitcoin is on the blockchain, I am able to track the movement of the stolen $500:</p><ul><li>Sent from Coinbase to <a href="https://www.blockchain.com/btc/tx/ce09a60d2765c37e801226ee38ff0dd91dd1d8ad124dc43f215d82928a0bdca2">13JKFEjHDF9ZTEyd9XxDEs357Dvhve814d</a>, an empty account</li><li>Then sent to <a href="https://www.blockchain.com/btc/tx/fb6bbd186d986e3667c8c3180ed186f7a15eecfa9518bea40c843d135eb51123">3PLx7czKsHHsrqw8JFyknPxeaVKWpa37wd</a>, another empty account</li><li>Then sent to <a href="https://www.blockchain.com/btc/tx/bb1e6d185d407e3f607ee78a30fdef6de36f13b26736c26cc3e1557929890d9b">bc1qakh8d2n278n0zlc30yp9q0vr574faewwhepl0t</a>, an account containing over 174 BTC (over $6M USD).</li></ul><p>It’s unclear who owns this account.</p><p>The attacker also tried to send funds using Google Pay to Colm Gallagher and <a href="/service/mailto:mitchellinvestllc@gmail.com">mitchellinvestllc@gmail.com</a>. Not sure if these accounts belong to the attacker or another victim, but tried searching for these addresses.</p><p>Colm Gallagher is a software engineer at Google:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGV08vmeSoKYyMqqA6qBKQ.png" /><figcaption><a href="https://www.facebook.com/mecolmg">https://www.facebook.com/mecolmg</a></figcaption></figure><p><a href="/service/mailto:mitchellinvestllc@gmail.com">mitchellinvestllc@gmail.com</a> seems to have also stolen from this user on Reddit:</p><blockquote>I have had the same issues for the last two months. I had random charges for balances between $400–800. I didnt have money on it as I usually use cashapp for my subscriptions services and only load money immediately before a subscription such as SlingTV would come out. Anyway, I canceled my card and got a new number. Surprisingly, the new number has been compromised as well now and I’m not sure how. Not only that but I found out that one of my subscription which is Nvidea Go for game streaming service is still able to charge the old card number 🤔. How is that possible? During the same time last month that the cashapp had charges, I had GPay give me tons of notifications that there were failures to send money. I logged it and found that my gpay account tried to send money to a single number like 9 times for random amounts of money. Then the attempt was to a gmail address <strong>Mitchellinvestllc</strong>. Most of my cards had attempted to be charged but most did not go through due to the amount of funds in the accounts. They tried to send $498 to <strong>Mitchellinvestllc</strong>(bogus person) with the same card for my brokerage account twice and failed but somehow it was allowed to go through the last time.</blockquote><p><a href="https://www.reddit.com/r/CashApp/comments/nnt1m2/someone_stole_my_cash_card_somehow_and_spent_over/gzzuviw/">https://www.reddit.com/r/CashApp/comments/nnt1m2/someone_stole_my_cash_card_somehow_and_spent_over/gzzuviw/</a></p><h3>Key learnings</h3><ul><li>Do not leave VNC ports open secured only with a password. It will eventually be cracked.</li><li>Set up 2-factor authentication for all Coinbase transactions to prevent funds being transferred in case someone has access to your browser session.</li><li>Do not use Coinbase. They do not insure cryptocurrency transactions and their customer support is non-existent.</li><li>Link your financial accounts to apps like <a href="https://mint.intuit.com/">Mint</a> or <a href="https://www.truebill.com/">Truebill</a> and enable push notifications on your phone. I was first alerted to the unusual activity on my accounts via push notifications from these services.</li></ul><h3>September 25, 2021: Update</h3><p>Was finally granted access to my Coinbase account today. Sold the remaining BTC for <strong>$1,539.32</strong>, ultimately reducing my total loss to <strong>$1,275</strong>. Will transfer everything out of Coinbase and will never use again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31158df8a41a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Pixel-Perfect Minesweeper in React]]></title>
            <link>https://leyanlo.medium.com/building-pixel-perfect-minesweeper-in-react-51391c5a3061?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/51391c5a3061</guid>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[netlify]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 00:57:51 GMT</pubDate>
            <atom:updated>2020-05-08T13:04:30.876Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErbsoUlfCtN9SZBNdeBm6w.gif" /><figcaption>React Minesweeper gameplay</figcaption></figure><p>I built Minesweeper (pixel-perfect based on the Windows XP version) using React. I also added the ability to flag or chord on mobile using long-press. You can play with it here: <a href="https://leyanlo-minesweeper.netlify.app/">https://leyanlo-minesweeper.netlify.app/</a>. The code is on <a href="https://github.com/leyanlo/minesweeper">GitHub</a>.</p><p><a href="https://github.com/leyanlo/minesweeper">leyanlo/minesweeper</a></p><p>Building Minesweeper is a popular software engineering interview question (e.g. <a href="https://techdevguide.withgoogle.com/resources/coding-question-minesweeper/">Google</a>, <a href="https://leetcode.com/problems/minesweeper/">LeetCode</a>). I wanted to see how far I could take it building a pixel-perfect app, as well as use it as an excuse to play with some new technologies.</p><h4>Technologies I used</h4><ul><li><strong>TypeScript as language<br></strong>Fairly similar to Flow, except much more popular and well-supported. Nice that enum is both a type and an object.</li><li><strong>Emotion for styling<br></strong>Love how small and fast it is. Mainly used the css prop to style elements and avoided styled components altogether because I hate that as a pattern. (It adds an unnecessary layer of abstraction between the DOM and the styles). Didn’t get into theming, but it seems like it would have been pretty straightforward.</li><li><strong>React hooks for application state<br></strong>I love how I do not need to install redux and can store everything I need using hooks.</li><li><strong>Gatsby for generating the app<br></strong>Gatsby is the best. Compiles the React app and serves exactly the HTML/CSS/JS needed by the client, including all font and image assets, in under 200 KB.</li><li><strong>Netlify for automated deploys<br></strong>I can push a commit to GitHub, and Netlify will start a new build and deploy the app. Amazing.</li></ul><h4>Pixel-perfect based on what?</h4><p>When I started working on Minesweeper, I wanted to build it as accurately as possible. Unfortunately, there are tons of variations to choose from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*WNOnl2iLNUpnOC9XfBk0Jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*LaBWuSGS-N5MVNQF3Q0Zkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*MIejKrl-l_qLQcIUDZA-EA.png" /><figcaption>Minesweeper in Windows XP, Windows 7, and Windows 10</figcaption></figure><p>I ended up aiming for the Windows XP version. In order to make sure I was getting everything right, I installed a Windows XP virtual machine on my Mac. Luckily, I was able to follow <a href="https://helpdeskgeek.com/virtualization/how-to-set-up-a-windows-xp-virtual-machine-for-free/">this guide</a> to get up and running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3PnVLs-DXb4knlxDcdtyHA.png" /><figcaption>Minesweeper running in Windows XP in VirtualBox on macOS</figcaption></figure><h4>Things I learned about Minesweeper</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*CPfn7VD9D3ke9VhrTKfaXg.png" /><figcaption>React Minesweeper close-up</figcaption></figure><ul><li>There is a weird 3px white border on the top and left side of the game. I assume this would be to show depth, but there is no equivalent gray border on the bottom or right side. I never noticed this growing up, but it looks like a bug!</li><li>Clicking with both the left and right mouse buttons to open up the neighboring cells is called a <a href="http://www.minesweeper.info/wiki/Chord">Chord</a>.</li><li>There’s a technique called the <a href="http://www.minesweeper.info/wiki/1.5_Click">1.5 Click</a> where you flag, drag, and click in a continuous motion in order to save time.</li><li>It is impossible to lose on the first click.</li></ul><h4>Things I did</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*0Z7JXEq1Oq-hjHw9ja25SQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*10IR6h20pLEjbn7vPD8ZRw.png" /><figcaption>Emoji face button and digital font vs. pixel face and numbers</figcaption></figure><ul><li>At first, I tried being clever, using emoji for the face button and a special typeface for the numbers. This ended up with way too many inconsistencies across browsers and OSes, so I ended up drawing bitmaps based on the original. In order to avoid blurriness when zooming in, I converted all of the bitmaps into SVGs, which are resolution-independent.</li><li>The <a href="https://github.com/leyanlo/minesweeper/blob/master/src/components/WindowBodyHeading.tsx#L51">HeadingNumber</a> component takes in a number and returns the three SVGs used in the mine count or the timer. Found out that in Minesweeper, negative numbers are possible for the mine count if you misflag a few extra mines. Also, all numbers are clamped within the range from -99 to 999.</li><li>Started out storing game state with multiple useStates, but things got a little messy as I had to keep track of more and more things, e.g. the board, which cells are revealed, whether you’re in the middle of a click, the timer, whether you’ve won, etc. Updated to using useReducer in order to keep track of everything at once, but this ended up a little messy as well, having to pass the reducer and state to every component, leading to <a href="https://kentcdodds.com/blog/prop-drilling">Prop Drilling</a>. Finally ended up moving the reducer and state to a React context, which can be imported by any component using useContext.</li><li>I wanted to be able to play on my phone, so I added a couple of long-press enhancements for mobile, allowing players to flag or chord on mobile.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*CghlNz798oq4C11qg9svGQ.png" /><figcaption>Game menu</figcaption></figure><ul><li>Building the Windows XP UI is hard! I spent a ton of time on the Game menu. All menus have box shadows. They take 150ms to fade in, but disappear immediately. There’s also a bunch of keyboard support that I didn’t implement, like arrow keys or alt-key shortcuts.</li></ul><h4>Conclusion</h4><p>This was a fun project and I was glad to have an excuse to play with new technologies. If I come back to this, I would want to add the best times scoreboard, sounds, and maybe implement keyboard accessibility for the menu (essentially building Windows in JS).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51391c5a3061" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aligning git log into columns]]></title>
            <link>https://leyanlo.medium.com/aligning-git-log-into-columns-93e903ed46d8?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/93e903ed46d8</guid>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Thu, 31 May 2018 00:18:45 GMT</pubDate>
            <atom:updated>2018-05-31T00:27:45.705Z</atom:updated>
            <content:encoded><![CDATA[<p>Fun fact: The <a href="https://www.freebsd.org/cgi/man.cgi?query=column">column command</a> does not respect <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#Colors">ANSI color codes</a> and will flow layout around them as if they were written out, e.g. \033[31m. This of course takes up extra characters, which ruins the columns during output!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6T5gDrKmWZ-V3IFzE3Q6A.png" /><figcaption>git log with misaligned columns 😢</figcaption></figure><p>Regex to the rescue! The main culprit in git log --graph are the graph colors. We can target these specifically, by matching any color codes surrounding any of these characters: [|, \, /, _, -, .]. Unfortunately, I wasn’t able to figure out a way of doing this using sed, but was able to pipe the text into perl to get the job done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0vpX-PepumL9PU5ZNoCpPg.png" /><figcaption>git log with aligned columns 😄</figcaption></figure><p>Perl command:</p><pre>perl -pe &#39;s/\x1b\[[0-9;]*m([\|\\\/_\-\.])\x1b\[m/\1/g&#39;</pre><p><a href="https://github.com/leyanlo/dotfiles/commit/66e83439c7394cafb86decee1ec8d18f9a8d2cbc">[.githelpers] Remove colors from graph · leyanlo/dotfiles@66e8343</a></p><p>Of course, the proper solution would have been to fix/reimplement column, but that seemed like a lot more work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93e903ed46d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to convert an Amex or Visa gift card to your Amazon gift card balance in only 10 days]]></title>
            <link>https://leyanlo.medium.com/how-to-convert-an-amex-or-visa-gift-card-to-your-amazon-gift-card-balance-in-only-10-days-dd3b16b49030?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd3b16b49030</guid>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[gift-cards]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Thu, 19 Apr 2018 17:06:01 GMT</pubDate>
            <atom:updated>2018-04-19T17:06:01.167Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4M8kM6mNiRX1dcRE7SKKCg.jpeg" /></figure><p>You just received an Amex or Visa gift card! It is a physical card that you have to carry around to use! Or you could just convert it to an Amazon gift card since you buy things there anyway, so you won’t have to carry <em>yet another </em>card in your wallet. Unfortunately, this process can be tricky and will take 10 days to fully transfer your gift card balance, but hopefully this step by step guide will help!</p><h4>Step 1: Reload Your Balance</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*g-s78TZnnBarcHX_WQB34g.png" /></figure><p>First, you want to click Reload Your Balance, from the Gift Card Balance page in the Your Account page.</p><h4>Step 2: Set Payment Method to Gift Card</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*apgqZ70v8FRxsKonmD3owA.png" /></figure><p>On the Reload Your Balance page, Click the Edit link under Payment methods to add your gift card information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*wSpW-1uZExczqqviRHPWww.png" /></figure><p>When you add your card, it doesn’t matter if your name or address are not actually on the gift card. Amazon doesn’t check for that — only that the card number and expiration date are correct.</p><h4>Step 3: Do Not Enter the Full Amount on the Gift Card</h4><p>I repeat, <strong>do not enter the full amount on the gift card</strong> when reloading your Amazon gift card balance. This is crucial. Let me explain:</p><blockquote>Let’s say you have a $25 gift card and try reloading your balance for $25. What happens is Amazon first sends a $1 temporary charge to the gift card to verify the validity of the card. Then, once that goes through, Amazon immediately sends the $25 charge to the gift card. This $25 charge will be rejected because the card only has $24 on it left. You will receive a lovely rejection email, and have to wait 10 days before the $1 charge is reversed.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*sMyhSTbNoL6GfNrYd1KHbw.png" /><figcaption>Amazon rejection email</figcaption></figure><p>Instead, what I would recommend is charging $1 less than the full amount to your gift card. This has the benefit of actually working! Now your gift card balance has <em>mostly </em>been transferred to Amazon!</p><h4>Step 4: Wait 10 Days and Charge the Rest</h4><p>Now, we wait 10 days for that pesky $1 charge to reverse. It’s not an exact science, but in my experience, it took 10 days. Once the charge is reversed, you’re free to charge the $1 (or whatever amount is left), since Amazon has already verified the card. Now your card is fully drained, and you can throw it in the trash!</p><h4>Step 5: Remove the Gift Card from your Payment Options</h4><p>Don’t forget to remove the gift card from your payment options, since that card is empty now :-)</p><p>I hope this guide helps! I definitely had no idea what was going wrong the first time I tried this and had to go digging through some forums to figure it out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd3b16b49030" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to move one git repository into a subdirectory of another with rebase]]></title>
            <link>https://leyanlo.medium.com/how-to-move-one-git-repository-into-a-subdirectory-of-another-with-rebase-2b297b628c57?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b297b628c57</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Sat, 24 Feb 2018 01:31:10 GMT</pubDate>
            <atom:updated>2019-06-15T06:17:01.199Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s say you’re building a side project in a git repository but eventually decide it belongs inside your main git repository in a subdirectory. How would you go about moving all the files over while maintaining the history of all the changes?</p><p>This came up for me recently, but most search results give steps for merging. Since I am a fan of rebasing, I had to come up with something slightly different. Here are the steps I took:</p><h4>1. Move all files from all commits into a subdirectory</h4><p>In the side repo:</p><pre># Move to a new branch `side_proj_subdir` in case you don’t want to mess up master<br>git checkout -b side_proj_subdir</pre><pre># Move all files from all commits into a `side_proj` directory<br>git filter-branch --tree-filter &quot;mkdir -p side_proj; git mv -k * side_proj&quot; HEAD</pre><p>This will move all the files from all the commits into a new side_proj directory. For some reason, dotfiles like .gitignore are not included, so you will need to go back to those commits when they were created and make sure they are created in the proper subdirectory, amending the commits using interactive rebase. This can be tedious if you have a lot of these. Good luck.</p><h4>2. Prefix all commit messages</h4><p>To denote that all these commits pertain to a certain feature, I like prefixing the commit messages. In the side repo:</p><pre># Get the first commit hash<br>FIRST_COMMIT_HASH=$(git rev-list HEAD | tail -n 1)</pre><pre># Prefix `[side_proj] ` to all commits after the first one<br>git filter-branch -f --msg-filter &#39;sed &quot;1 s/^/[side_proj] /&quot;&#39; ${FIRST_COMMIT_HASH}..HEAD</pre><p>Note: this does not prefix the first commit unfortunately, but you can amend that one using your trusty interactive rebase:</p><pre>git rebase -i --root</pre><h4>3. Add side repo as a remote</h4><p>In your main repo, you’ll want to add your local side repo directory as a remote so that you can access all your fancy new commits:</p><pre># Add local side_proj directory as a remote<br>git remote add side_proj &#39;<a href="https://github.com/user/side_proj.git">.</a>./side_proj&#39;</pre><pre># Get all of those commits<br>git fetch side_proj</pre><h4>4. Rebase all the commits!</h4><p>Now the moment of truth. Since we are not merging, let’s grab all of those side project commits and put them on top of our main project. In the main repo:</p><pre># Get all your side repo commits. This may take a while as it will essentially wipe out all the main project files and create all the side project files.<br>git checkout side_proj/side_proj_subdir</pre><pre># Put all of these commits on top of your main project. This may also take a while since you are basically recreating your main project.<br>git rebase master</pre><h4>5. Cleaning up</h4><p>Hopefully everything went ok without any conflicts. You should be in a state with all of your side project commits on top of master, in its own subdirectory, and with all commit messages prefixed appropriately. If you want, at this point you can remove your remote we added in step 3with:</p><pre>git remote rm side_proj</pre><h3>Conclusion</h3><p>I hope you found this guide helpful. All of these steps could easily be found by Googling, but I thought it would be nice to put it in one place. The end result for me was hundreds of commits over the course of four years sitting on top of master in a non-conflicting way, which was kind of cool.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b297b628c57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Set Up Your New iPhone]]></title>
            <link>https://leyanlo.medium.com/how-to-set-up-your-new-iphone-27a021da5b97?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/27a021da5b97</guid>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Mon, 31 Oct 2016 01:39:36 GMT</pubDate>
            <atom:updated>2019-10-02T08:44:23.866Z</atom:updated>
            <content:encoded><![CDATA[<p>Transferring all your data from an old iPhone to a new iPhone can be a little tricky. There are a few pitfalls you could run into, and some things you should be aware of. These 7 steps should help you avoid most issues.</p><p><em>I just got a new iPhone 7 recently and wanted to document the process for transferring all of my data from my iPhone 6s. This process took me one hour and I was running iOS 10 and watchOS 3 at the time.</em></p><h3>Step 1 (Watch owners only): Unpair Apple Watch</h3><p>If you own an Apple Watch, it is important that you first unpair before switching to a new phone. This is, unintuitively, the only way to create a backup of your Watch data on your phone, which can then be migrated. If you forget this step you will have to reset your Watch when you pair with your new phone and lose all your Watch data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*UgstzOZugsFHqqRhs59BgA.png" /><figcaption>Unpair Apple Watch</figcaption></figure><h3>Step 2: Turn on airplane mode</h3><p>This is a personal preference of mine. I hate missing data and would rather avoid texts or calls during this process than get them and not have them show up on my new phone. If you do not turn on airplane mode and receive a text, that text won’t be on your new phone when you restore from backup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*fP9SbYoZ8fk6q_UEiM0TjQ.png" /><figcaption>Turn on airplane mode</figcaption></figure><h3>Step 3: Create encrypted backup in iTunes</h3><p>Connect your iPhone to your computer and create an encrypted local backup. I never backup to iCloud because restoring from iCloud is a huge pain for two reasons. First, it is slow to transfer gigabytes of data over WiFi rather than directly from your computer. And second, the encryption allows the backup to save all your passwords so you don’t have to sign into all your mail, calendar, Twitter, Facebook, and whatever other app accounts you have. If you have a lot of apps on your phone this could save you hours of hunting for logins and passwords.</p><p><em>Note that while your apps’ user data will be backed up, the apps themselves will not be backed up due to App Thinning introduced in iOS 9. Ever since iOS 9, your apps will all have to download from the cloud after restoring, to make sure that your device downloads the proper version of the app tailored to your particular device. Also note that apps download in the order they are on the home screen, so make sure your most important apps are on the earlier screens of your phone. More details about App Thinning </em><a href="https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html"><em>here</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ge0JSREmagPh8ORq7TW0Hg.png" /><figcaption>Create encrypted backup in iTunes</figcaption></figure><h3>Step 4: Restore from iTunes backup</h3><p>Congratulations on backing up all your data! Time to set up your new phone! Turn on your new phone and follow the setup instructions. When it asks about restoring data, connect it to your computer and follow the instructions in iTunes.</p><p><em>You may run into issues if your new phone’s iOS version doesn’t match your backup. If this happens, you should update your new phone before restoring:<br>1. Set up your new phone as new and skip as much of the welcome flow as possible (avoid signing in with your Apple ID).<br>2. Go into Settings and upgrade iOS over Wi-Fi.<br>3. After upgrading, reset the phone in Settings &gt; General &gt; Reset &gt; Erase All Content and Settings.<br>4. Now try restoring from iTunes.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3a-uxEDkYgveHFAOvRjlw.png" /><figcaption>Restore from backup</figcaption></figure><h3>Step 5 (unlocked iPhones only): Swap SIM cards</h3><p>Unlocked iPhones come without a SIM card and will need one in order to get cellular data. If you purchased a carrier version you will skip this step and deal with Apple or your carrier instead.</p><p>If you have trouble ejecting your SIM card with a paperclip or needle, I recommend finding a thumbtack. Being able to apply more pressure definitely helps when the SIM tray is being difficult.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*_rvdtbbb8HNZiDph4EKL7A.jpeg" /><figcaption>The perfect SIM eject tool</figcaption></figure><h3>Step 6 (Watch owners only): Pair and restore Apple Watch</h3><p>Time to restore your watch! Just launch the Apple Watch app on your new phone and begin the pairing process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*rLbyczzCp03GEipq9j1hZQ.png" /></figure><h3>Step 7: Finishing touches</h3><p>Almost done! Your apps should now be downloading from the cloud (see note in step 3). Unfortunately, there are a few things that do not transfer over and need to be set up manually:</p><ul><li>All credit cards in Apple Wallet need to be re-added.</li><li>All bluetooth devices will be forgotten and will need to be re-paired.</li><li>Any apps that sync to the cloud, like music, eBook, or podcast apps, will need to re-download content.</li><li>Any apps that use fingerprints like banking, credit card, or payment apps will ask you to sign in before allowing Touch/Face ID sign-in.</li><li>Any apps that use Motion Activity like pedometer apps need to be reauthorized.</li><li>Any apps that you want to receive notifications from need to be reauthorized.</li><li>If you use Google’s iOS app for authentication (<a href="https://support.google.com/accounts/answer/7026266">which you should</a>), then update your Google account(s) to use your new phone for <a href="https://myaccount.google.com/u/0/signinoptions/two-step-verification">2-step Verification</a>.</li><li>Any Duo accounts need to be reconnected.</li><li>For some reason Google Maps needed me to sign in again to know where I live and work.</li><li>If you are getting rid of your old iPhone, make sure to <a href="https://support.apple.com/en-us/HT201351">Sign out of iCloud and the iTunes &amp; App Store</a>.</li></ul><p>I hope this guide helps you. Enjoy your new phone!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27a021da5b97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Credit Card Workflow]]></title>
            <link>https://leyanlo.medium.com/credit-card-workflow-a4ccc66756d9?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4ccc66756d9</guid>
            <category><![CDATA[personal-finance]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[credit-cards]]></category>
            <category><![CDATA[money]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Tue, 23 Aug 2016 21:20:38 GMT</pubDate>
            <atom:updated>2017-08-28T07:55:56.487Z</atom:updated>
            <content:encoded><![CDATA[<h4>These are the steps I go through after receiving a new credit card in the mail.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3rKOhGP7i5q8RyMsk-ZBw.jpeg" /></figure><p>Over the years, I’ve accumulated a few habits with regard to financial accounts. Credit cards used to be straightforward to get up and running:</p><ul><li><strong>Activate the card</strong> by calling the number on the sticker.</li><li><strong>Sign the back</strong>.</li></ul><p>Now in the digital age, I try to keep my card information synced to all of my devices and accounts. I like having the ability to pay for things without actually having the card on me, or use Apple Pay with my iPhone or Apple Watch, or automatically pay bills and keep track of spending, or be alerted of any fraudulent charges right away. So here is my new and improved workflow for what I do when I get a new card:</p><ul><li><strong>Activate the card</strong> by visiting the website on the sticker.</li><li><strong>Sign the back</strong>.</li><li><strong>Enter the card’s information into </strong><a href="https://1password.com/"><strong>1Password</strong></a> so I never have to have the physical card to make payments at my computer or on my phone. Data is encrypted and synced through Dropbox (with two-step verification for security).</li><li><strong>Scan card into the iPhone Wallet app for use with </strong><a href="http://www.apple.com/apple-pay/"><strong>Apple Pay</strong></a>. Apple Pay is way more secure than swiping the card, and even more secure than chip cards because of the way all personal account numbers are hidden from vendors by randomly generated IDs for each transaction. I always prefer it and ask if it’s available if I see the little icon. (Note: You will have to do this separately for the Apple Watch and any other devices since secure data is not shared)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*zNiE8cdWo6DgFphYr3JeUg.png" /><figcaption>I get so happy seeing these icons at the register.</figcaption></figure><ul><li><strong>Create account on the credit card’s website</strong> and link it up with your checking account to auto-pay the balance each month.</li><li><strong>Add account information to </strong><a href="https://www.mint.com/"><strong>Mint</strong></a><strong> and </strong><a href="https://www.personalcapital.com/"><strong>Personal Capital</strong></a>. Mint is great for keeping track of all my accounts, including checking, savings, investments, and credit cards, and gives me a bird’s eye view of my financial situation. I started using Personal Capital more recently for added redundancy with Mint just in case Mint is ever inaccessible, and it also serves as a nice sanity check in case some numbers are ever off.</li><li><strong>Download the iOS app for the credit card company</strong> if there is one available (I have cards from Citi, Chase, and Capital One) so I can receive push notifications for each transaction. I like to know right away when I am charged for something and make sure that it’s correct. Also this is great for being aware of any monthly subscriptions you might have since a random notification during the day is a lot more jarring and grabs your attention more than if you just review all the charges on your bill at the end of the month (which I’ve since stopped doing).</li><li><strong>Add account information to </strong><a href="https://www.prosper.com/daily"><strong>Prosper Daily</strong></a><strong> (formerly BillGuard) on iOS</strong>. I love this app for keeping track of my credit card spending, and every few days, there is a little badge notification for all recent charges to verify. This forces you to go through the charges once again in case you missed it the first time or find something you need to follow up on.</li></ul><p>It may seem like a lot of work, but the convenience of having my cards synced makes it worthwhile to me. There are so many people who put their finances on autopilot, unaware of monthly subscriptions that they may no longer use, sometimes overcharged when shopping, or even taking a few billing cycles to discover fraudulent charges. I hope this article helps shed some light on how to stay on top of finances in the digital age and brings awareness to some of the tools out there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4ccc66756d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Useless UI]]></title>
            <link>https://leyanlo.medium.com/useless-ui-5bd00ceca0a4?source=rss-5d175d6fc496------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bd00ceca0a4</guid>
            <category><![CDATA[apple-watch]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Leyan Lo]]></dc:creator>
            <pubDate>Tue, 12 May 2015 00:08:07 GMT</pubDate>
            <atom:updated>2015-05-12T00:08:07.348Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*z0hNkYUH8uSMgQWG02_rYQ.gif" /></figure><p>As I was exploring the built-in apps for the Apple Watch, I stumbled across this little gem of UI in the Passbook application, shown above. The animation is both delightful and beautiful, probably taking many hours to design and build, but ultimately fails its original purpose: explaining to the user how to use Apple Pay.</p><p>I’ve shown this screen to dozens of others, including designers and engineers, hoping to disprove my gut instinct on how useless this screen is. Unfortunately, I was correct. Nearly every single person I showed this to tried tapping the screen, the card, the text, or even that pulsing white rectangle. This is not to say that these people were foolish, but that this screen failed its purpose to inform.</p><p>When building an application, it’s important to reach out to new users and find out how effective each component actually is. If you have an idea for how users will react to a certain screen, make sure reality matches your vision. And hopefully with rapid prototyping, you’d be able to save a ton of time not building the wrong thing.</p><p>Life is too short to be spent building useless UI.</p><p>PS. For those still scratching their head on how to use Apple Pay on the Watch: double click the Contacts button the side to open the Apple Pay screen.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bd00ceca0a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>