Today's objective is to code something for fun, in a day. It's been far too long I've done something with no purpose other than enjoying the process. An idea has been kicking around my head since (checks timestamps) mid 2020... Time flies ๐Ÿ˜ณ

I want to put a cat on the internet. He chills on his page and you can pet him. Or not. He likes when he's getting pets ๐Ÿˆ That's it. I have more ideas, but minimalism is the name for the game for today.

Technically, I want to keep things simple and lightweight. It should be clean. It should load fast. Interactions should be simple, no manual required. Giving a pat should leave a footprint of sorts.

To make things a bit more fun, this will be a live development thread ๐Ÿงต

Been thinking about moving off to something else, primarily because it's getting far too slow for what it is. Unfortunately things don't look promising, it seems like there's no good way to migrate existing content to the new account, and replacing the engine in-place is also a source of endless issues. is a good writeup from about two years ago that covers some of the issues.

This is very annoying. I guess I could pour a bunch of effort into optimizing, but I so don't want to get involved with python. is amazing and terrifying at the same time.

Amazing because you don't need fancy GPU servers to run an LLM, it can just run in a browser. From purely technical point of view this is mind blowing.

Terrifying because before long every other site will download not just 50 MiB of JavaScript and CSS, but also 6 GiB of neural network so they can grace you with another useless AI assistant ready to sell you whatever garbage they are peddling.

WebLLM | Home

It's high time for y'all to get reminded

Nevkontakte shared a month ago is one of the weirdest butterfly effect bugs I got to debug.

The effect that starts the chain is simple enough, the hash/maphash.TestHashHighBytes test introduced in Go 1.19 is flaky under GopherJS. What does the test do? It checks that the high 32 bits of the hash are actually sort of random.

The 64-bit hash is computed using a 64-bit seed and a 32-bit low-level hash function, here's an abbreviated version:

func rthash(b []byte, seed uint64) uint64 {
	lo := memhash(b, uint32(seed))
	hi := memhash(b, uint32(seed>>32))
	return uint64(hi)<<32 | uint64(lo)

Somehow, half the time the higher 32 bits of the seed are exactly FFFFFFFF. Why would that be?

Well, the seed is generated by this function, which looks innocent enough:

func fastrand64() uint64 {
	return uint64(fastrand())<<32 | uint64(fastrand())

Liberal use of print-debugging reveals that the high 32 bits of the right uint64(fastrand()) operand are FFFFFFFF. So when or-ed with the other side or basically stomps whatever randomness would have been there. What is fastrand then?

func fastrand() uint32 {
	return uint32(js.Global.Get("Math").Call("random").Float() * (1<<32 - 1))

Wat? How could upsizing a uint32 to uint64 possibly yield FFFFFFFF in the high bits?!

WARNING, we are now exiting vanilla Go lands and delving into JavaScript madness that makes GopherJS work.

Because JavaScript is what it is, GopherJS has little choice but use the same number type to represent all non-64-bit integers, throwing a modulo operation here and there to keep up the appearances. Similarly, float64 and float32 are actually also the same number under the hood. That said, JavaScript does give us a tool to pretend there are signed and unsigned integers: >> and >>> respectively. In JS, the following are true: (4294967295 >> 0) === -1 and (4294967295 >>> 0) === 4294967295 (yeah, the infamous === has a little >>> brother, don't ask what happened to <<<).

Going back to GopherJS, it uses this trick to maintain signed and unsigned integers. We almost have our smoking gun. The last piece of the puzzle has to do with the unit32 โ†’ uint64 conversion step. When GopherJS tries to interpret a negative number as uint64, it assumes the number is signed, and sets the high 32 bits to FFFFFFFF as it should. Let's look at fastrand again:

func fastrand() uint32 {
	return uint32(js.Global.Get("Math").Call("random").Float() * (1&lt;&lt;32 - 1))

The js.Global.Get("Math").Call("random").Float() * (1<<32 - 1) is not very interesting, it just gives us a float64 in the range of [0, 2^32). But then it gets converted to unit32. The correct way of doing it is using the >>> 0 trick, but the compiler was emitting >> 0. Which meant any value in the [2^31, 2^32) range would be converted to its two's complement negative number. Boom! The gun fires. When our negative supposedly uint32 value is converted to uint64 the high bits get set to FFFFFFFF; when it gets |'ed with another number, it overrides whatever higher bits the other side had. Bad things happen then.

Today I've heard a wonderful term: cringineer. Now I'm thinking how do I put it into my Linkedin profile.

What would you call renting a room to a sketchy kind of dude?

Sustenance ๐Ÿฅ

Nevkontakte shared a month ago

Another case of a 6-line bug fix accompanies by 160 lines of unit tests.

Nevkontakte shared a month ago

If I were Satan, righteousness would have been my favorite invention. Nothing like it to set people against each other, or blind them to the real consequences of their actions.

Somewhat impulsively, I accomplished two things I've been procrastinating on for months:

  • Upgraded my main PC from 16 to 64 GiB RAM. As neat SFX PCs are, a trivial upgrade like that required taking half of it apart, including the CPU cooler to get to the RAM slots.
  • Added a shim to my main monitor arm to raise it by about 5cm. It gave me a bit more clearance to store junk under it, and also a lot more comfortable level to look at it while leaning back.

Holy Inquisition had it right when they burned books. Every time I open a book, any hope of a productive evening is gone. Worse than alcohol! Think of all the free open source labor I could have provided if not for books!

Right, what page was I on...

It occurred to me that a lot of what I've been doing at work amounts to collecting and redistributing proverbial fishing rods just so that people stop bugging me about the same thing over and over again. And if I ever want to have people stop asking me for fishing rods, I need to move into the business of teaching people to make fishing rods from materials at hand. And all I wanted was just to be left alone and write some software.

(Ignore the sound of the metaphor cracking on its seams)

Nevkontakte shared 2 months ago

A counter-intuitive observation: the more I get done at work in a given day, the more energy I have for some pet project in the evening or weekend.

Interesting... 6 years ago or so I tried the Microsoft Natural Ergonomic Keyboard 4000 (one their split models) at work and after some struggle abandoned it for a more traditional mechanical keyboard. Today I pulled it out of the drawer it was sitting in and gave it a go just because I was bored. Weirdly, I find it a lot more comfortable than I remember and the layout doesn't give me as much of a headache. I don't like how the key press feels, but that's kind of minor.

Maybe I should look into ergonomic keyboards again ๐Ÿค”

Candidate requirements for a job in a ministry of foreign affairs. Wrong answers only.

Caffeine is just energy borrowed from your tomorrow self. Like any loan, could be a useful tool, but also a way to dig yourself into a pit โ˜•