moving a cli to the browser with WebAssembly

TLDR; i had a bunch of golang code printing data to terminal, using some new features in go1.6 (embed, GOOS=js GOARCH=wasm, etc.) I moved it to HTML

Before we dive in, you can see this run here.

If you stare at that output for a while, you’ll notice you are watching a very long download. You are always somewhere in a ~15 day cycle but try and look at the left side column and ignore the right side.

I have the data (exact utc unix timestamp) of each new moon and each full moon in a 138492 byte file.

All I had to do was:

//go:embed *.csv

var embededFiles embed.FS

fsys, err := fs.Sub(embededFiles, ".")

Now I can just pass that fsys around and the rest of my go code can read that virtual filesystem with the csv file embeded in my go binary.

It’s so much nicer having this file embeded in the .wasm file some javascript will load.

I had to make some small changes to the logic that was doing stuff like:

fmt.Printf(“\n”)

to

fmt.Printf(“<br/>”)

But that’s about it. If you go build the original cli and run ./wolfschedule -f you’ll see the same output you now see at wolfschedule.com.

Oh, and why would anyone want/need this cli? I say at the start “try and look at the left side column and ignore the right side” because forgetting about our “Saturdays” and “Sundays” as “the weekend” is this wonderfully liberating shift. You can run your life in these little ~15 day mini-marathons instead. You get MORE days off this way. As you “watch the download” and get closer and closer to event day, go ahead and stop working 2 days before the event to get ready.

Then enjoy the day of the event!

And then take 2 days to recover.

With normal Monday thru Friday, 52 weeks a year, you get 104 days off. With this schedule you get a total of 120 days off.

But sometimes you do need to know if it’s Monday! And this is why the right side column is there. But only line up a day to the right side if you have to.

Is it ok to just stare at the page and watch the download?

Absolutely! It’s great meditation. I’ve gotten into this habit of whenever I’m not sure what to do with some time, I run ./wolfschedule -f and take a 15 min break.