Header logo.
Small Hallucinations
HomeArchiveTagsAboutFeed

Copy and paste on Ubuntu

On a Mac, if you press Command-C while not selecting anything, nothing happens. I didn't realize this was a behavior that had been designed and implemented by someone until I did the same on Ubuntu.

On Ubuntu, what happens when you press Ctrl-C while not selecting anything is two things:

I'm saying as if this is an Ubuntu problem. But I don't really know. It is most likely handled by Gnome alongside (in my case) X11 according to Reddit.

And you would think the clipboard is a solved problem since it was invented in 1973.

“Asia/Beijing” doesn’t exist

I was writing a Python script last week and the ORM threw a tantrum, asking for an “offset-aware” datetime.

ChatGPT (GPT-4o) suggested I use the zoneinfo package and simply specify the name of the timezone.

Naturally, I assumed the timezone name for Beijing would be “Asia/Beijing” and asked GPT-4o for confirmation.

Fixing addon bugs for Anki 23

I've been using Anki for years. Anki has recently changed its version numbers to year.month. From version 23.10, FSRS algorithm is implemented for scheduling reviews. Without thinking too much, I upgraded to the latest version.

Not surprisingly, this upgrade broke a few addons on my computer:

Fixing them was easier than I had thought.

When you start Anki, you are greeted with this alert if there's a bug in an addon. ⋯

Something clever in the syntax of Elixir

I find this quite clever in the syntax of Elixir.

There are two sets of boolean operators in Elixir and, or, not versus &&, ||, !.

The difference is that and, or, not only take literal boolean values. In contrast, &&, ||, ! can take values of all types. And all values except false and nil will evaluate to true.

When you think about it, it makes a lot of sense. Because literal boolean values -- true and false -- are words. It's only natural that they go with words: and, or, not.

Adding a new context and define associations in Phoenix

I'm still doing Dockyard's tutorial of Elixir and Phoenix.

So far I've progressed to building a blog context. Now I'm trying to add a comment context to the app. This would also allow the user to post a comment and list all the comments below a post.

This exercise is designed to teach you about how to create one-to-many relations in Phoenix.

Although the concept is easy to grasp, there are a few steps you need to take and quite a few files you need to change. ⋯

Ecto search keyword interpolation

Updated on 2023-11-27:

Now I realize I didn't need to use a fragment. I could have used ilike.

The difference between ilike and like is that ilike is explicitly case-insensitive, whereas like could be case sensitive based on the database you are using.

Original post:

Untracking files in Git

Normally you can avoid tracking files in Git by adding files to .gitignore.

But if files have been previously added for tracking, they will still be tracked even after appending them to .gitignore.

We need to first remove tracked files from cache. And add back all the files – including .gitignore – in the current directory. Now .gitignore will take effect.

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 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 meantime, I'd create flashcards in Anki if I find what I'm learning really useful.

The downside of this is, when you are in the middle of debugging, it feels costly to pause and change the mode from debugging to note-taking. (To reduce the friction while collecting information in Obsidian, I've enabled global hotkeys. Hope this can be helpful.) ⋯

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