Header logo.
Tonghe's Notes

Don't Edit Hosts File With Nano on a Mac

TLDR: If you are using a Mac, don't edit your hosts file with Nano and save it in Mac format. It will cause bizarre bugs in places you won't expect. If you are seeing bugs on a Mac with errors saying localhost is missing, try opening the hosts file and save it with Unix line ending.

I learned this while working on a React Native project, where Expo's development server just wouldn't start up. After a long and patient wait, an elaborate error message showed up. In which the most eye-catching line said:

RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received 65536.

Dull joke 1

You are at your best friend's place. They — of course, you are the kind of people who are woke enough to have friends with expressed preferences over pronouns, in this case, the singular they — They are having an awesome party to celebrate their ...


On the twenty-ninth, of... ⋯

Comparing Arrays by Value in JavaScript

I didn't know I didn't know the answer when my friend showed me a simple piece of JavaScript code and asked me what would happen.

He said this caused a bug in a project he was working on and it took him hours to debug. Since I knew arrays in JavaScript are objects. And objects are only equal when they refer to the same thing in memory. If you do it as shown in ex. {2}, the result will certainly be true, because x and y indeed refer to the same thing.

In ex. {1}, a and b are defined differently. And I felt very clever when I correctly said the code on line 🕶 will produce a false. But — ⋯

Creating My Own Static Site Generator

Since I take a lot of notes, rcently I thought I could edit some of my notes and turn them into a blog. I wasn't satisfied with WordPress, because it's bloated. I didn't feel like to get familiar with the settings and configurations of other static site generators either. So I decided to write my own. I named it “Lysekil”, where I visited in late March and loved it there. I published it on GitHub and provided a brief documentation.

The color scheme used in the template was borrowed from the default “Red Graphite” theme of Bear, my favorite note-taking app. (It also happens to be Andy Matuschak's favorite note-taking app. I used to dither over a few other options, including Obsidian, RemNote and RoamResearch. In the end I would always come back to Bear.)

I used third-party Python packages to process markdown, generate the Atom feed and highlight code syntax. ⋯

Emulating Python's zip() and zip_longest() in JavaScript

This is essentially how you emulate the way Python's zip() function works using JavaScript.

What makes this possible is the fact that JavaScript array methods — map(), forEach() and even filter() — take up to three arguments (element, index, array) while they iterate through the array.

In which element is the element that the iterator points to at each step, index is the index of this item in the original array. And it's worth noting the third argument is the original array. ⋯