Author: mattchung

  • Creating my own digital library

    After reading Daniel Wessel’s post1 on creating a virtual library, I’ve decided take the leap and convert the majority of my books — classic literature will remain sitting on my book shelf — into digital form. To accomplish this, I invested in a Fujitsu ScanScan IX500.  The scanner runs for about $400.00. I selected this model based off of the many reviews2 touting that this scanner scans fast (duplex scan takes about 1 second for front and back), produces high-quality documents, and provides an easy to use intuitive touch screen interface. And after receiving and unpacking the equipment last night, I agree wholeheartedly.

    (more…)

  • I’m a messy person: it’s time for a change.

    I’m pretty embarrassed of how disorganized and messy our house looks and feels. I forget the color of the bathroom tile since its hidden from view due to dirty clothes sprawled out across the entire floor. I’m afraid of raising my standing desk for fear of a monitor toppling over due a caught wire and afraid of one of the many mugs spilling four day old tea. I cannot wipe down the kitchen counter because of the mega sized Maggi Soy Sauce (super delicious, by the way) towering over the stacked, dirty (or maybe clean) plates. By living this way, we’re sort of disrespecting our house, not taking care of it and looking after it in the way we should.

    It’s time for a change.

    My messy desk. Just one example of how disorganized the house is.

    (more…)

  • Guitar practice journal #1

    Today I practiced my guitar for 20 minutes, a generous amount of time these days (if you are parent you’ll understand). During this practice session, I worked ear training: I looped the song The Funeral (Band of Horses) on my iPhone and played along, plucking the individuals notes in chord progression on my Traveler’s acoustic guitar.

    Just before my 20 minute practice guitar session: jamming with Elliott
    Just before my 20 minute practice guitar session: jamming with Elliott

    During the practice session, I was able to nail down all the notes from the first two chords (triads) and was also able to determine that song was written in the key of G# (thanks music theory). However, I am a bit confused because the 2 of a major key, normally a minor chord, was played as a major. Is this swap of minor and major chord an example of modal mixture?

    Ultimately, I was unable to play the entire chord progression by ear and ended up finding a guitar tutorial1; uploaded on YouTube. Despite that, I’m happy with the progress I’ve made over the last two years of working on my music craftsmanship.

    References

  • Logical Writing & Steven Pinker’s Coherence Relations

    Have you ever read a passage that flows (i.e. has cohesion) but it just … doesn’t make any sense, no matter how many times you read it? You can lexically parse the passage (i.e. makes grammatically sense) but you cannot grasp the meaning? If so, the passage probably lacks coherence.

    What is coherence?

    According to Joseph Williams2, author of Style – Ten Lessons in Clarity & Grace, a passage is coherent when the sentences merge into a unified passage. The passage’s author not only needs to link pairs of individual sentences, but they need to sequence the sentences so that together, the sentences are unified. To this end, Joseph Williams suggests focusing the topics to a limited number of concepts. By doing so, the author helps prevent scattering the reader’s sense of what a passage is globally about. Moreover, Joseph Williams suggests using “connectives”, helper words that link one sentence to the next, words such as: and, but, or, therefore, nonetheless, however, even though, despite.

    But it’s … not that simple. Should connectives always be sued? According to Steven Pinker1, using too many connectives will belabor the obvious and potentially water down the material, patronizing the reader. On the other side of the spectrum, using an insufficient number of connectives can leave the reader puzzled and confused as to how one statement follows from the last.

    Wanting to better understand how to achieve a coherence, I read the chapter “Coherence” in Steven Pinker’s book. In the section that follows, I’ll share the 13 of the different ways one sentence can flow to another. These different methods are also known as coherence relations.

    (more…)

  • A healthy (no oil), quick (15 minutes prep, 15 minutes cook), plant based instant pot dish

    If you are looking for a quick, delicious, healthy (no oil), plant based meal that takes only 30 minutes (15 of those minutes are waiting for the dish to cook in an instant pot) to whip up, look no further. Check out Jill McKeever’s video on “The Red Lentil Stew From Instant Pot”:

    I’ve taken her recipe and slightly modified it, changing the proportions of the ingredients. More specifically, I kick up the number of potatoes. In the video, you’ll see she tosses only in 1 potatoes or so; I like my dish a little more starchy and tend to chop up and throw in in twice the amount (about 4 or 5 potatoes). And occasionally, I’ll mix it up with a zucchini (or as my British wife calls it: “Courgettes”).

    So the modified recipe is as follows:

    • 4 carrots
    • 4 potatoes
    • 1 teaspoon of paprika
    • 1 tablespoon of coriander
    • 1 medium-sized yellow onion
    • 2 garlic
    • 6 cups of vegetable stock
    • 1 cup of lentils (I don’t wash them but she does)
    • 3 ounces of tomato paste

    Definitely try this out. It’s so easy and so delicious! Bon Appetit!

  • A No-Excuses Guide to Blogging – Excuse #5 – “I don’t want to be wrong”

    Many people (including myself) fear that we will be perceived as a fool if we publish on a post blog that contains a mistake, a public mistake. Nobody wants to be humiliated publicly. This fear is encapsulated inside of a quote that Sacha shares:

    “Better to remain silent and be thought a fool than to speak and remove all doubt.”

    But like Sacha, I’d rather know when I’m being a fool. At work, I never shy away from asking “dumb questions”. I’ve come to realize that there’s normally at least one other person who has the same question but they often shy away from asking it for fear of looking stupid. I’ve been that person and I later kick myself in my butt for not speaking up.

    If you don’t put your thoughts into words — verbally or written — then its very easy to convince yourself that you understand something, when you really don’t. So many times in both my career and personal life I thought I understood some topic but when I started forming those thoughts into my own words, I realized I had gaping holes in my understanding. For example, my co-worker asked how and why we prefetch in our code base, and when I started explaining, I realized I had to refresh my memory on the cost of certain instructions and CPU pipelining.

    In summary, do yourself a favor and when you are learning something, try and explain it someone. You might discover gaps in your understand. And that’s perfectly okay because your writing becomes a “history of change and learning”. This allows us to take a step back and honor our progress and allow us to remember our mistakes and lessons learned along the way.

    References

    Chua, Sacha. 2014. A No-Excuses Guide to Blogging.

  • What vacation looks like with a 10 month year old

    Summary

    I never could’ve imagine what being a parent (to a 10 month year old) looks like while on a vacation at the Suncadia Hotel (in the midst of a pandemic). When our daughter sleeps sprawled out on the cloud like king size bed, us two parents are quietly scarfing down our cold dinner while watching an episode of “Westworld” off an iPhone that’s balanced behind the bathroom sink.

    Our lives revolve around Elliott’s sleeping schedule

    Before becoming parents, my wife and I lived a life with almost no constraints. If we wanted to spontaneously watch a movie at the theaters, we’d pop open our laptops, check the next show time, and then walk downhill for literally 5 minutes to the local theater. It was that simple.

    But those days are gone.

    Life is a little more complicated nowadays. Our schedules tend to revolve around Elliott’s sleeping schedule. This strict adherence applies even when we are away for a vacation.

    But why do we follow a sleeping schedule to begin with?

    It’s quite simple, actually. The bi-conditional logical connectivity is as follows: If and only if Elliott sleeps well can we (her parents) sleep well. And a night with lack of quality sleep makes everyone miserable. Therefore, it is in our best interest to ensure that Elliott clocks enough sleep.

    Sleeping environment at a hotel

    To that end, we need to transform our hotel room to an environment that’s conducive for sleeping. That means rendering the room pitch black by covering all the windows with the curtains, allowing no single ray of sun to shine through. This combined with a white noise machine — blasted at max volume that penetrates even the deaf — soothes the baby to sleep.

    On top of blackening out the room and pumping the sound machine, we need to remove as many distractions as possible. And at Elliott’s age (and probably moving forward), pretty much everything in sight is a distraction: including me. So while Jess puts Elliott down, I tip toe out of the hotel room, flicking off the lights on my way out, and then make my way down to the hotel communal area (still wearing a mask), my laptop in hand. And for this short period of time, about 30-45 minutes, I double down and focus and chip away at writing on my blog (like this post). And then I sneak back into the room once Elliott hits her deep sleep.

    Dinner in the bathroom

    What does dinner look like while at a hotel resort? Well, that depends. If Elliott is awake, then we take the opportunity and eat an early dinner (around 5:00 pm), the three of us squatting over a wooden dining table that’s a shoulder height of Elliott. But if Elliott is asleep, then dinner takes a different turn.

    In this scenario, you’ll find (as mentioned above) the room blacked out and two parents (Jess and myself) huddling in the hotel bathroom, the door shut closed so that we can whisper to one another without fear of waking Elliott up. While in the bathroom, we both pop in our air pods, sync them to an iPhone (since the wifi signal sucks in our room), and proceed to watch an episode of “Westworld” while slurping down our noodles:

    Jess and I quietly eating our dinner while Elliott is sleeping in the bedroom
  • Swapping values of two variables with XOR

    As programmers, we know that we can swap two variables by using a temporary variable. That’s fairly simple and intuitive: given two variables (x and y) that you want to swap, you store x in a temporary variable z, copy y to x, then finally copy z (the temporary) to y. But I learned recently (in my compiler’s course) that you can swap two variables without allocating a temporary variable, by using three xor operations. Here’s a little C program that demonstrates that idea:

    # include<stdio.h>
    void
    swap(int *x, int *y)
    {
         *x ^= *y;
         *y ^= *x;
         *x ^= *y;
    }
    
    int
    main(int argc, char *argv[])
    {
        int x = 123;
        int y = 234;
        printf("x=%d;y=%d\n", x, y);
        swap(&x, &y);
        printf("x=%d;y=%d\n", x, y);
    }
    ./xor-swap
    x=123;y=234
    x=234;y=123

    Neat, right?! But why would you ever want to take this approach? Especially if the underlying CPU instructions are more expensive with the xor approach. That is, the typical process for swapping two variables consists of 3 MOV instructions and the total number of cycles is 3 — one cycle per MOV instruction. Whereas 3 XOR instructions takes 9 cycles (3 cycles per instruction).

    Well, one explanation is that compiler writer is making a tradeoff: we’re sacrificing CPU cycles but in return we free up a register, which is especially important for the register allocator. In other words, we’re reducing register allocation pressure.

    Anyways, the last thing I want to demonstrate for you (and really, for myself) is to see 3 XOR operations at the binary level

    XOR at the binary level

    Although the code (above) proves that we can swap two variables using three XOR operations without a temporary variable, I wanted to actually carry out the XOR operations at the binary level to see for myself (cause seeing is believing, right?)

    For the example below, assume that we have two registers ebx (1101)and eax (0001).

    First operation – xor %ebx, %eax

    1101
    0001
    ====
    1100

    The xor operation yields 1100 and is then store into ebx.

    Second operation – xor %eax, ebx

    0001
    1100
    ====
    1101

    This operation yields 1101 which is then stored eax.

    Third operation – xor %ebx, %eax

    1100
    1101
    ====
    0001

    And hooray — the final xor yields: 0001.

    References

    http://www.asciitable.com
    https://c9x.me/x86/html/file_module_x86_id_330.html

  • Waiting for one day …

    “If you want to be successful, find out what the price is and then pay it.”

    Scott Adams

    I agree with that Scott Adams wholeheartedly. I also think this rule can be more broadly applied: “If you want something — anything — find out what the price is and then pay it.”

    This quote reminds me of a story that my therapist recently shared with me. During this Covid-19 shelter in place, he’s participating in an online workshop lead by a poet named David Whyte. During the most recent workshop, one of of the other students in the program shared their life long dream: becoming an anthropologist. It’s something they always dreamed of but before they make that giant leap, they are first going to build a financial foundation and work in tech for another 8 years.

    David Whyte’s response? “You’re probably not going to become an anthropologist.” Ouch — brutal honesty. But David Whyte softens the below and elaborates, stating that when we do something on a daily basis, we assume that identity and that activity — in this case being a tech worker — becomes part of our fabric. He’s right.

    This short story struck a chord with me. And over the last couple days, I’ve been reflecting on my own one day dreams and aspirations, askingmyself what are some things in my life that I’ve been wanting to do but have been waiting for something — something in the distant future, only after I do x and do y.

    And the first thing that surfaced was writing. Writing on my blog. I used to write much more frequently but every since I started my masters program in computer science, I’ve pretty much abandoned writing all together convincing myself that I have zero time to commit to writing. That’s nonsense.

    So instead of waiting to graduate from the program — which is another 1.5 years — I’m going to chip away at my writing. Every day. Even if it’s for 5 minutes. Even if it’s just collecting field stones or existing content. Whatever it is, I’m making tiny incremental progress: and I’m happy with that. Little wins.

    Now I want to turn the table and ask you if there is anything you want to do one day? Is there something you are waiting for? Or waiting for someone to give you their approval? Or for the stars to align?

  • Week 1 and Week 2 of compilers

    Last week, I couldn’t carve out enough time to write a post on my reflections for week 1 of my compiler’s course so I’ll do the next best thing: write a post that combines week 1 and week 2. The quarter kicked off on January 10th and since then, I’ve felt a range of emotions, from excitement to anxiety. Meanwhile, I’ve been scarfing down a ton of knowledge about compilers (previously, I viewed the compiler as an elusive, magical and mysterious black box). On top of all this, I’ve been experimenting with Cornell Note taking system, switching back and forth between typing up notes on my laptop, writing notes down on my iPad, and using the good old pen and paper.

    Study Habits

    I’m constantly refining the way I study, optimizing my sessions for increased understanding and maximizing long term retention. Last quarter, I had taken notes using LaTex, generating aesthetically beautiful documents. The idea behind this was that that I would one day look back at them in awe. But in reality, I haven’t looked back at any previously taken notes, not for any of the four prior classes, so there’s really no point (as of right now) to continue precious cycles on typing out LaTex notes when (I think) I’m more actively engaged when scribbling notes down with pen and paper.

    Emotions and feelings

    A couple things make have been making me feel anxious. First, the sheer number of hours required for the course. According to the omscentral reviews, students estimate roughly 20-25 hours per week. To compare against these estimations, I’ve been tracking the hours I put into this course. So far, on average, I’m studying — watching lectures, reading the textbook, creating flash cards — in roughly 2.5 hours a day; same applies for the weekends. That means, in given week, I’m putting in roughly 17.5 hours, give or take. Will the number of hours increase once the first project is announced (two days from now) ? Perhaps. One way would be to reduce the number of commitments (e.g. singing, writing music, writing blog posts like this one) or sacrifice some sleep — not ideal at all. Instead, I think I’ll just accept that, given the finite number of hours in a week, I may be only able to pull off a B, which I’m totally fine with.

    What have I learned so far

    As mentioned before, I have zero prior background with compilers. But in just the past two weeks, I’ve discovered that a compiler is not just a black box. It actually consists of three major components: front end, optimizer, back end.

    The front end’s job is to scan and parse text and convert that text into a format (intermediate representation) that’s consumable by the backend (more on this below). And if we drill down a bit further, we’ll see that the front end actually consists of subcomponents: scanner, parser, and semantic analyzer. The scanner reads one character a time and then groups them into tokens. These tokens (tuple of type and value) are passed back to the parser (who initially requested them), which then calls the semantic analyzer to ensure that the generated tokens adhere to the semantic rules, ensuring that they are meaningful and make sense.

    How does the compiler know whether something is both syntactically and semantically correct? Based off of the rules of the language: the grammar. These are the set of rules that specify the language and can be formalized using finite automata and represented as state machines. What I found most interesting is that we can express the grammar using a human readable format called regular expressions.

    Regular Expressions

    If you are a programmer, you certainly used regular expressions (in your favorite language like Python) for searching text. But regular expressions are much more powerful than just creating search patterns. They are fundamental to compiler design.

    By using regular expressions, we can create a formal language, which consists of the following:
    • Alphabet – finite set of allowed characters
    • Transition Function
    • State – finite set of states
    • Accepted State – finite set of accepted states
    • Starting State – initial state of the state machines

    State Machines

    As mentioned above, regular expressions can be converted into state machines (similarly, state machines can be converted back into regular expressions) that fall into one of two categories: deterministic and non-deterministic. Next week will cover this topic in more detail.

    Summary

    So that about wraps it up. I’m looking forward to next week (I.e. Week 3) !