RSSAmplifier

Blog

Oliver Nguyen

Recent content in Oliver Nguyen

iolivernguyen.github.ioRSS feed ↗45 posts

Latest posts

Working with Stacked PRs using jj

A while back I wrote about working with stacked PRs using git-branchless, git-autofixup, and
git-pr . It worked well. But since then I switched to
 jj — and I’m not going back. 
 jj is a new version control system that is compatible with git. It can use an existing git repo as its backend. I
started using it as a drop-in replacement for git and expected it to feel roughly…

Game theory: A quick introduction

I have recently read a book called “Game Theory in Everyday Life” by Len Fisher. It is a great book that explains concepts of game theory in a simple and easy to understand way. It opens up a new perspective on how to look into familiar situations. 
 Let’s start with a very usual story from our software engineering work. 
 
 A Flaky CI Test 
 You submit a PR.…

TIL: Quick note on introduction to group theory (vietnamese)

Hôm nay tôi xem kỹ hơn một video về group theory của tác giả 3b1b . 
 Và thử diễn đạt lại theo cách hiểu của mình. 
 Bắt đầu từ symmetry (đối xứng) 
 Hiểu nôm na thì nó là nói về tính chất của một vật (entity) 
(hiểu là một cái gì đấy trừu tượng của toán học, có thể xuất phát từ việc trừu tượng hoá những vật cụ thể trong cuộc sống thực hoặc không).

TIL: Dim white pages to not burn eyes

I’m using dark mode everywhere. But many websites, including Google Docs, Apple Support, etc. still have white background without any option to turn on dark mode. 
 This is a simple Tampermonkey script to dim white pages a bit, so it won’t burn my eyes. Basically, it applies an overlay div with background rgba(20, 10, 0, 0.12) .The page will be a bit yellow. If you prefer gray, you…

Commit your code in style with git.emoji 🎉

Have you ever get bored with the same old commit messages, all starting with “update”, “fix” or “feat”? Do you know that emojis are the latest advancement in human language and communication? They can convey emotions and ideas in a single character and make your messages alive! Think about it, even when aliens come to Earth, they will quickly understand the…

The power of diff in testing - Part 1: SQL queries and mocks

A new day at work 
 Suppose that you, a good software engineer, just got hired by an e-commerce business. And you are joining a team to work on the profile service to manage customers and their addresses. 
 There are a Customer and an Address struct, with a couple of gorm tags for the database schema: 
 type Customer struct { 
 ID uuid . UUID `gorm:'type:uuid;primaryKey' json:'id'`…

ezpkg.io/conveyz: Understanding the Implementation of FConvey

The FConvey function is a standout feature of ezpkg.io/conveyz , designed to simplify focused testing in Go. Unlike the original smartystreets/goconvey framework, which requires developers to set FocusConvey at every nested block level, FConvey is smarter. It ensures that focusing on a single block propagates to all relevant nested and parent blocks, streamlining the debugging process. 
 In…

iter.json: A Powerful and Efficient Way to Iterate and Manipulate JSON in Go

Have you ever needed to modify unstructured JSON data in Go? Maybe you’ve had to delete password and all blacklisted fields, rename keys from camelCase to snake_case , or convert all number ids to strings because JavaScript does not like int64 ? If your solution has been to unmarshal everything into a map[string]any using encoding/json and then marshal it back… well, let’s face it, that’s…

Errors, Errors Everywhere: How We Centralized and Structured Error Handling

Handling errors in Go is simple and flexible – yet no structure! 
 It’s supposed to be simple, right? Just return an error , wrapped with a message, and move on. Well, that simplicity quickly turns into chaotic as our codebase grows with more packages, more developers, and more “quick fixes” that stay there forever. Over time, the logs are full of “failed to do…

Welcome to my blog!

Hi! I’m Oliver Nguyen, a software engineer working with Go & JS. 👋 
 I enjoy writing code and building tools to make writing code even faster! I love working in start-up environments, where I get to build everything from the ground up and improve them as companies grow. 
 Along the way, I share my knowledge and write about best practices in software development, covering topics like…

Implement a Distributed State Machine with Redis to Migrate Billions of Records

As a start-up company, we started with a simple architecture: All data were stored in a single centralized Postgres instance, shared by a few services. It has been working well and allows us to move fast, deliver features, enter the market, acquire clients, and grow exponentially. 
 Fast forward a couple of years, today we have thousands of clients and billions of records, it’s time to…

How to live on 24 hours a day – by Arnold Bennett

“How to Live on 24 Hours a Day” is a classic self-help book written by Arnold Bennett, first published in 1910. The book is a practical guide on time management and personal development, emphasizing the importance of making the most out of each day. 
 Bennett argues that time is the most valuable resource we have and that many people waste it without realizing it. He suggests simple but…

Upgrade your scripts using 'direnv' and 'run' script

In JavaScript/Node world, we usually store scripts in package.json and run them using npm. In other worlds, we use
Makefile or create a directory and put all our scripts there. But there is a better way to manage and run scripts for
your team. No, I’m not talking about Warp or other pricey fancy tools. 
 I will share about direnv and our old friend bash : How we are using them…

Refactor: GoroutineTracker with unnecessary usage of reflect

Today, I encountered this code in my company codebase (the code and comments are rewritten for demo purpose and do not include any proprietary code) : 
 type GoroutineTracker struct { 
 wg sync . WaitGroup 
 // ... some other fields 
 } 
 // Go starts a new goroutine and tracks it with some metrics. 
 func ( g * GoroutineTracker ) Go ( ctx context . Context , name string ,…

ezpkg.io - Collection of packages to make writing Go code easier

As I work on various Go projects, I often find myself creating utility functions, extending existing packages, or developing packages to solve specific problems. Moving from one project to another, I usually have to copy or rewrite these solutions. So I created ezpkg.io to have all these utilities and packages in one place. Hopefully, you’ll find them useful as well. 
 
 
…

GitHub PRs on MacOS Menu Bar

I usually push a lot of PRs in form of stacked PRs to GitHub. It’s quite annoying to go through each PR to see the check status. So I
created this plugin to show my PRs on the menu bar. — Now, everything is just a click away! 
 
 Features 
 1. Top PRs section 
 
 List of your chosen PRs, sorted by your order. 
 You can customize the list of PRs in this section by…

TIL: String type with a specific length in TypeScript

We&rsquo;ll declare a Phantom Type: &#xA; type StringN < N > = string & { &#xA; length : N ; &#xA; readonly X : unique symbol ; &#xA; } &#xA; &#xA; const isStringN = < N extends number >( length : N , s : string ) : &#xA; s is StringN < N > => s . length == length ; &#xA; &#xA; export const stringN = < N extends number >( length : N , s : string ) : StringN < N > => { &#xA; if ( ! isStringN (…

TIL: console.log with color

We can use this pattern to output log with color in browser by adding CSS: &#xA; const logger = ( name ) => ({ &#xA; info : console.info.bind ( console , `%c ${ name } : %s` , 'color: #56d74b' ), &#xA; verbose : console.debug.bind ( console , `%c ${ name } : %s` , 'color: #70818e' ), &#xA; }) &#xA;

Building flow compiler for sending campaigns and auto reply

At work, I&rsquo;m working on the flow compiler, which compile from flow documents into ETA flow descriptors. The use cases&#xA;are to provide our users the ability to automatically response to their customers&rsquo; messages. Users can define their own&#xA;flow and customize auto reply behaviours. This article gives a look into my work. Also see related article . &#xA; &#xA; Package flow…

TIL: Auto-reload a command when files changed using entr

While working with Go and JavaScript, we have tools available for auto reloading the server when the code changes. For&#xA;JavaScript, we even have hot reload which reloads part of the page without reloading the whole page. But for Python, we&#xA;don&rsquo;t have such tools, I tried livereload, but it does not work well for nested directories. So I decided to do it&#xA;myself. And there is a tool…

Pull data from HackerNews API and dump to JSON files

I wrote a simple script to download the HackerNews data from&#xA; HackerNews API . It downloads the data in JSON format and stores it as a collection&#xA;of files. The first time it runs, it will create the directory data to store the data. Subsequent runs will update the&#xA;data in the directory. &#xA; At the time of this writing, the HackerNew database has about 35 million items. &#xA; Usage…

Visualize flow documents and ETA flow descriptors

At work, I&rsquo;m working on the flow compiler, which compile from flow documents into ETA flow descriptors. You can read more details in this article . &#xA; Flow documents are a collection of nodes and edges, which are JSON objects. They are used to describe the flow of an&#xA;automation chatbot. The flow compiler takes a flow document and compile it into an ETA flow descriptor, that is used…

Working with Stacked PRs using git-branchless, git-autofixup, and git-pr

I usually work with stacked PRs. It is a great way to organize my work and keep my commits small. This empowers&#xA;separation of concern and limit scope of each PR. Reviewers can go through each PR and review them one by one.&#xA;Smaller changes, better feedback! &#xA; &#xA; I was using sapling . It worked really well in the first month, but the honeymoon ended too soon. Read more... &#xA; Using…

TIL: Where does Github CLI store its credentials?

When using sapling, it can access my github with my credentials by asking me to gh auto login . I was wondering where&#xA;it stores these credentials: in the keychain, in a file, in the environment? It&rsquo;s here: &#xA; $ cat ~/.config/gh/hosts.yml&#xA; github.com:&#xA; user: iOliverNguyen&#xA; oauth_token: gho_████████████████████████████&#xA; git_protocol: https&#xA;

Make goconvey work with gomega assertion

At work, we use gomega for testing. It works well, until one day it becomes too&#xA;verbose and goconvey becomes a better fit. To prevent the repository&#xA;from using two different sets of assertion functions, I decided to write an adapter to make goconvey work with&#xA; gomega assertion functions. &#xA; gomega &#xA; gomega is a testing framework for Go. Here&rsquo;s what it looks like: &#xA;…

Make sapling work with direnv

In the last post , I shared my experience with Sapling, Meta’s new Git client. It requires some workaround with direnv. This post explains the change in details. &#xA; At work, we are using direnv for quickly managing environment variables on our repository. When we&#xA; cd into a directory, or a subtree, it automatically detects the file .envrc in the current directory (or the nearest&#xA;parent…

My first impressions of Sapling — Meta’s new Git client

Sapling is a new source control system developed by Meta. Recently, it&#xA;gains the ability to work with GitHub. I&rsquo;m curious about how it works, so I decided to give it a try and end up using it&#xA;daily on my company&rsquo;s repositories. If you want to try it out, check their documentation&#xA;here . &#xA; Stacked PRs &#xA; &#xA; When developing, I usually create a single commit for each…

The Immune System: What happens when you get a small cut?

We know that our blood contains white blood cells. And we probably heard of macrophages and T-Cells. But the immune&#xA;system has so much more. The book Immune &#xA;from Philipp Dettmer, the author of Kurzgesagt channel, will provide insights&#xA;into the beautiful mechanisms of our immune system. This article is my summary of our immune system, what they are and&#xA;how they protect our body.…

TIL: Packing web app as desktop app on Mac without Electron

gluon &#xA; Recently, I found gluon . It is a framework for building desktop applications&#xA;using web technologies. Unlike Electron, it uses the System installed Chromium or Firefox instead of the bundled&#xA;Chromium. This makes it possible to use the same version of Chromium or Firefox as the one used by the user&rsquo;s browser.&#xA;This also makes the application significantly smaller. At…

Latest JavaScript features in 2022

&#xA; JavaScript is changing fast with a lot of new and exciting features to help us - developers write code better and&#xA;better. These features have been released for a while. Let’s check them out! &#xA; 1. Private fields &#xA; &#xA; Previously, all class fields must be defined in the constructor. And there is no private fields. All fields can be&#xA;accessed from outside. Of course, there are…

TIL: File descriptor 3

Linux &#xA; There are three standard file descriptions, STDIN, STDOUT, and STDERR. They are assigned to 0, 1, and 2 respectively. &#xA; File descriptor 3, 4 and so on can be accessed at: &#xA; /proc/12345/fd/3&#xA; I found it when looking at this Patchset . Chromium&#xA;open --remote-debugging-pipe at file descriptor 3 for output and file descriptor 4 for input. &#xA; Windows?

TIL: git am

TIL: Git &#xA; How to apply a patch from github into the current repository &#xA; gh pr diff --patch 4 | git am&#xA; git am &#xA; Apply a series of patches from a mailbox.

TIL: 10 most relaxing songs to reduce anxiety, according to neuroscientists

According to neuroscientists, music can reduce anxiety and stress. They suggested a list of the ten most relaxing songs&#xA;to reduce anxiety: &#xA; &#xA; &ldquo;Weightless,&rdquo; by Marconi Union &#xA; &ldquo;Electra,&rdquo; by Airstream &#xA; &ldquo;Mellomaniac (Chill Out Mix),&rdquo; by DJ Shah &#xA; &ldquo;Watermark,&rdquo; by Enya &#xA; &ldquo;Strawberry Swing,&rdquo; by Coldplay &#xA;…

TIL: Run Go tests inside WASM

&#xA; &#xA; &#xA;&#xA;&#xA;&#xA; &#xA; &#xA; &#xA; Given the string &#xA; &#xA; &#xA; &#xA; It should have length &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA;&#xA; &#xA;&#xA;&#xA; &#xA; Browse the source files: &#xA; &#xA; init.html &#xA; box1.html &#xA; go/main.go &#xA;

TIL: WASM with Go and run it inside browser

&#xA; &#xA; &#xA;&#xA;&#xA;&#xA; &#xA; &#xA; &#xA; Number of UUIDs: &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA; &#xA;&#xA; &#xA;&#xA;&#xA;&#xA;Enter 1-10 in the above box. It should output UUIDs. &#xA; Writing Go code &#xA; func main () { &#xA; done : = make ( chan struct {} , 0 ) &#xA; js.Global () .Set ( 'wasmGenerateUUIDs' , js.FuncOf ( generateUUIDs )) &#xA; <-done&#xA; } &#xA;…

TIL: Ultralearning, by Scott Young

Ultralearning is a book from Scott Young. He spent time learning a&#xA;lot. Like spending 1 year in 4 non-English countries, each country in 3 months, to learn speaking foreign languages. &#xA; Make a metalearning map &#xA; Design your goals and scopes. Determine exactly what you want at the end. Spend the first 10% of time to answer: &#xA; &#xA; What concepts do I need to understand? &#xA; What…

TIL: Include HTML file in a post with Hugo

Shortcode are simple snippets inside your content files calling built-in or custom templates. &#xA; Include HTML file in a post &#xA; Create layouts/shortcodes/include-html.html : &#xA; {{ $file := .Get 0 }}&#xA; {{ (printf '%s%s' .Page.File.Dir $file) | readFile | safeHTML }}&#xA; Then use it in your content files: &#xA; {{​< include-html 'embedded.html' >}}&#xA;

TIL: Better Memory

Memory tips by BigThink.com &#xA; &#xA; Chronic stress is really bad for our memory. It make us tired and loose attention. Stress hormones mobilize your brain&#xA;and body to respond, to fight, to flee, to react quickly - not to think. &#xA; Get enough sleep. If you don&rsquo;t get enough sleep, your hippocampus might not have enough time to consolidate memories. &#xA; You remember when you pay…

TIL: Beware of Nil UUID when updating database with gorm!

WHERE conditions required &#xA; At work, we are using gorm for dealing with database. It&rsquo;s a popular SQL manipulation&#xA;library in Go. &#xA; But recently, we got a scary error: &#xA; can not update row: id=00000000-0000-0000-0000-000000000000&#xA; WHERE conditions required&#xA; Which happened from this code snippet: &#xA; db , _ := gorm . Open ( ... ) &#xA; &#xA; paper := & Paper { &#xA;…

Compare and swap in Redis

Compare and swap &#xA; Compare and swap is a familiar concept of atomic operation, for dealing with race condition. Suppose we want to build a&#xA;lock for multiple instances to execute some command, and only one can be executed at a given time. An instance must wait&#xA;for the lock to be released before it can take. &#xA; Instance 1: Current value is empty, set it to 1 and take the lock.&#xA;…

Validate zero enum value in Protocol Buffer

How to validate that a Protobuf message does not contain enum fields with zero value? Turn out that is not supported&#xA;directly by Protobuf! We need to look into how protojson package is implemented. &#xA; More and more companies are adopting gRPC with Protobuf for&#xA;communication between internal services. It has the benefits of high performance, supporting multiple programming&#xA;languages,…

Eventual consistency and cache

What is it? &#xA; Eventual consistency is a fancy name of doing something and only expecting the changed state after a while. And there is&#xA;a guarantee that you will eventually get the expected state. Hence, consistency. &#xA; But that won&rsquo;t work well with caching . And I had to deal with that recently when working with WhatsApp API. &#xA; When querying for a list of message templates…

Create an emoji ball-drop game with Matter.js

&#xA; You can&rsquo;t connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the&#xA;dots will somehow connect in your future. &#xA; ⸺ Steve Jobs &#xA; Sometimes, stepping outside of your comfort zone and taking some side projects is a great way to improve as a developer.&#xA;The more skills you acquire, the more you can do. And you may need them…

Front-End development without node_modules using Skypack and Snowpack

Once upon a time, we could simply put an HTML and a script file into an FTP server, quickly have a working website and&#xA;call it a day. &#xA; Today, we have to jump through many hoops just to get the right things in the right places. Suppose Alice wants to spend&#xA;her weekend making a simple to-do app or whatever little idea she enjoys. First, she has to install a big heap of 10k&#xA;npm…

µjson - A minimal JSON parser and transformer in Go

µjson is a minimal JSON parser and transformer that works on unstructured (and trusted) JSON . It works by parsing input and calling the given callback function when encountering each item. &#xA; Motivation &#xA; Sometimes we just want to make some minimal changes to a JSON document or do some generic transformations without fully unmarshalling it. For example, removing blacklisted keys from…