Header logo.
A study of bugs
HomeArchiveTagsAboutFeed

Using Readwise

I realized I read quite a lot on the web. I spend a lot of time browsing answers on StackOverflow and reading documentation.

For the most part, such information is only useful once and it's OK to forget it. But occasionally, I'd come across a new bug that reminds of me of an older problem I had seen before. At that time, I'd wish I could remember how I solved that problem earlier.

I take notes in Obsidian when I try to seriously learn something new. In the mean time, I'd create flashcards in Anki if I find what I'm learning really useful. ⋯

ts2322

A moment ago I got an error that reads like this:

I was really confused for a moment. Then I realized (() => void) | null means: Either a) a function that neither takes any argument nor returns any value; or b) null.

And () => void | null means a function that does not take any argument. And there are two possibilities when this function returns: Either it doesn't return anything or it returns a null. ⋯

Learning fun but irrelevant things

Last week, my friend Joe asked me what's the best way to learn a programming language.

I replied: Go through the basics as quickly as possible. Then begin building things with it. This is how I learn Golang.

I had been curious about Rust for a while. And a coworker talked about how Rust was his favorite language with a lot of exuberance. I thought to myself, maybe I could do the same with Rust. ⋯

Bug report: Linter doesn't run in SourceTree

Description of bug: Using SourceTree on React project running on Node. When committing, linter fails to run with a complaint saying something like “node not found”.

Investigation: Googled a bit, the problem might have been caused by nvm`` or it's something aboutzsh`. Good people on StackOverflow also shared how they solved their similar bugs on their system.

But... Somehow I was using Volta to manage different versions of Node. Can't think of a good reason why I decided to do so. ⋯

#19

I went through my finances using beancount. Double-entry bookkeeping seemed boring at first. But with the help of VSCode extensions for beancount that enable syntax highlighting and formatting, it became somewhat enjoyable.

I ran into problems over different currencies. I have a few transactions in USD and EUR. I wrote a Python script to convert bank statement formats to that of beancount.

Did you know you could use calc in Tailwind CSS? I was first mind-blown then felt it wrong. One should not choose to use the dark magic that is calc() unless it is her last option. Besides, by using Tailwind, we are telling ourselves now we are one step removed from the nuts and bolts of CSS. Using arbitrary numbers in brackets already feels “unidiomatic” in Tailwind. Last week when I found myself resorting to something like h-[calc(100%-20rem)] I grimaced very hard. ⋯

#18

I bought YouTube Premium to skip ads. Now I play background music on the TV. It feels quite nice. And I found a channel called “Greenred Productions” very calming and helpful for concentration.

Gothenburg

I moved to Gothenburg from Stockholm. And I like Gothenburg better.

Stockkholm feels like an archipelago of settlements connected by highways, subways and pendeltåg. In the middle of the city, we have touristy areas in Gamla Stan, commercial areas in Norrmalm and Södermalm. And really fancy areas in Östermalm. Beyond these quarters, the city feels more like non-contiguous dots of inhabited areas separated by woods. Some of these dots are bustling urban areas in their own right, such as Solna and other centers of communes in Greater Stockholm Area. But at the same time, a lot of them feel like villages.

Gothenburg as a city is held together more closely. The downtown area of Gothenburg is more walkable than that of Stockholm. I live in Hisingen and I love the lively messiness around here. ⋯

Trying out Fyne

The idea of building a piece of software once and run it everywhere is certainly charming. And Go supports cross-compiling out of the box.

Fyne is a very promising GUI package for Go that helps you build a GUI app and cross-compile it for (almost) all devices and OSes.

For a quick example, this code gives you a small window with a label and an input field. Grab this piece of code, init a mod and tidy it, and you are good to go. ⋯

#15

Go has superb built-in support for good programming practices, such as test-driven development. In fact, I'm learning a lot about TDD while learning Go from this book: “Learn Go with Tests”.

If you want to test a bunch of similar inputs and outputs, it's handy to run table-driven tests. What you do is list input values and expected output in an array, then loop through all the test cases.

I found this blog post by Lorenzo Peppoloni quite helpful. It gives examples in both Golang and Python for table-driven tests. ⋯

Using prepared statements & pointers in Golang

I changed the name of this blog to “a study of bugs”. This makes it easier for me to think of what to write about -- bugs, of course.

In MySQL, you can use a question mark (?) in a prepared statement to stand in for a value.

In the Go code above, dbconn is a connection to a MySQL server. Line 1 defines a prepared statement. And Line 3 queries the table for a row where the name column matches the value of variable name. I assumed the ? in this query would be interpolated with an actual string. I added quotation marks since they are needed around strings in MySQL CLI. ⋯