Header logo.
Small Hallucinations
HomeArchiveTagsAboutFeed

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.

Here's blog post explaining why the void keyword is useful while devving. ⋯

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.

I was intimidated by “the Rust book”. It's a huge book of I don't know how many pages. And I never got past hello world and the curious exclamation mark after println. ⋯

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.

Conclusion: Decided not to pursue a non-hacky solution. Followed my precious friend Elad Silver's post: ⋯

#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.

I created huge mess while trying to resolve a merge conflict. I was using GitHub Desktop. It was ill-equipped to compare and switch between different branches on GitHub Desktop. (And I was ill-equipped to use the commandline.) Thankfully, the web interface is quite advanced by now. Usually, small conflicts that do not involve files being deleted or moved around could be resolved by a few clicks in the browser. This time, though, it did involve files being moved around. That was a huge mess. ⋯

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.

Yet it's not just the lively messiness. A few bus stops away from the down-to-earth supermarkets, shopping malls, and a Taiwanese-owned hotpot restaurant, lies a campus of Gothenburg University and Chalmers, a science park and a bunch of tech companies. ⋯

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.

First, on line {1} we define an app in a. Then we define a window w with title “Hello, you!” on line {2}. ⋯

#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.

We all push buttons for a living. Most of us spend enormous amount of time with the Qwerty keyboard layout. ⋯

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.

This fails to return anything. Removing the quotation marks solved the problem. The correct code is on Line 2. ⋯

“Zulu timezone”

I've been using a pomodoro app that provides a REST API. Through this API, you can query past pomodoros using parameters such as ended_before and ended_after. The response data also contains started_at and ended_at fields.

The values for these fields all look like this: 2022-01-01T07:18:59.000Z. And they are UTC time strings suffixed with a Z. Correctly so, because it indicates this timestring is UTC.

There are fields named local_started_at and local_ended_at. Although those values are clearly not UTC, they are all suffixed with a Z. This confused me a bit at first. (And it seems quite common for people to suffix Z at the end of a time string, regardless of which timezone that time string actually is.)

The default timezone in a Docker container is UTC. The default timezone of AWS is also UTC. (I wrote a script to check just to be sure. But it's actually written somewhere in the documentation.) ⋯

A simple demo of how useCallback works

This is how useCallback works.

In the callback defined on line 🙄, the function body increases the count by 1. We set the dependency list to be shallChange. This way, the count will not increase unless shallChange gets a different value.

If you click Count+ multiple times, the count will only increase once. It will increase again after you click Shall Change? butotn.