A page from the codebook of coolguy.website

Coolian

A command line spell to convert today’s date into a Coolian day
I wanted a more personal date-keeping system for coolguy.website (and maybe just life?). I use the command line a lot, so needed a spell I could invoke to fit into my workflow.


The Coolian Day

In western astronomy, there is a date-keeping system called the Julian Day. It is defined as “The number of days since 24 November, 4714 BC”. This date marks the beginning of the “Julian period” and is useful because it marked the beginning of several cycles, like solar and lunar cycles and also, and the Roman tax periods.

I came upon the Julian Day while I was doing a heavy, lockdown inspired, dive into astronomical calculations so I could draw a moon on my frontpage. A lot of the standard moon calculations involve taking some date, referred to as an epoch, and recreating the moon’s cycle from that day to the present moment. The standard date used for this was the Julian day.

While struggling through these calculations, I got all angry about dates and time. They are deceptively hard to work with in programming, and it is because of all these arbitrary human adjustments on a natural cycle. If we just organized our time around the moon’s phase, things would be simple. Instead, we base it off Julian or Gregorian calendars and try to get the moon and seasons to fit into this awkardly constructed, “rational” grid. It is literally fitting a circle into a square hole and leads to moon phase calculators like moonpage.com needing caveats like:

These calculations incorporate the switch to the English New Style (N.S.)—i.e., Gregorian—calendar after Wednesday, 02 September 1752; the next day became Thursday, 14 September, skipping eleven days. (Please also note that, while fairly accurate, these calculations remain a bit buggy.)

I was annoyed by standard dates but was charmed by the idea of randomly deciding upon a date you deem ‘THE EPOCH’, So I decided to start using the Coolian Day, which is the number of days from the start of coolguy.website, which I defined as the day I registered the domain and uttered the name ‘coolguy.website’ to all the nameservers across the world.


How I made it

Making this spell requires two parts:

  1. Figuring out the coolguy epoch.

  2. Writing a script to calculate days from the epoch.

Figuring out the epoch

I, sadly, did not write down the day I started coolguy. Luckily, the internet remembers for me!

You can get registration info for any domain using the spell whois, or the “Internet domain name and network number directory service”, by typing whois DOMAIN into your , e.g.:

whois coolguy.website

This returns too much information, but you can use the grep spell to filter it down—-in this case I want the creation date…

whois coolguy.website | grep 'Creation Date'

which returns…

Creation Date: 2015-11-23T20:52:59Z

My personal epoch is “23 November 2015”—- which is coincidentally quite close (save a few thousand years) to the Julian day!

Writing the Spell

I wrote the spell in , which is a beautiful language that, historically , is ill-suited for command-line spells. Luckily, a hero named Michael Bork created babashka which enables running clojure for command line spells.

I love using babashka because it integrates with my text editor so I can have a live coding environment…I can call a function after I write it to see what it would return, to easily double check my work and iterate upon it naturally. It makes coding feel like sculpting clay or riffing on a melody.

I don’t wanna do a big ol’ code walkthrough, but the whole (short) script lives in coolguy’s tools folder and is fully commented: Check out coolian.clj!.

Invoking the spell

Babashka lives in the command line and you call upon it to interpret a file for you. So if i wanted to run coolian.clj, I would type:

bb ./coolian.clj

More easily, You can add instructions at the top of a file to declare which spirit should interpret yr program. These top-of-file instructions are called, colourfully, “hashbangs”. At the top of ‘coolian.clj’ I added this hashbang:

#!/usr/bin/env bb

And now(after making coolian.clj executable) I can call it directly.

chmod +x ./coolian.clj # make it executable
./coolian.clj          # call it

BUT I CAN GO EVEN HARDER.

I have a directory in my named ~/bin, and I added this to my PATH. The PATH is a set of folders I’ve told the command line to look in to help figure out how to answer my prompts. So if I type hey computer, the computer will look in all the path folders for some sort of spirit named “hey” and if it can’t find it after this exhaustive search will say, command not found: hey.

The command line also has a notion of “symbolic links”, which lets you create a symbol in any directory that links to some file. What this means is that I can symbolically link a name from anywhere on my computer to this file.

In this case, I link coolian.clj to the name ~/bin/coolian with the invocation:

sudo ln -s \
  $HOME/Coolguy/tools/coolian/coolian.clj \
  $HOME/bin/coolian

Which now enables me to just type…

coolian

and receive…

2165

Hahaha, a lot of smoke for a tiny fire…but it is a powerful fire! It is literally a new word that my computer understands and i can use in any sort of longer invocation.

echo "Hello! today is CD $(coolian)"
"Hello! today is CD 2165"

For now, I use this tiny fire in my taglog project–invoking it to generate the git tags that drive that project.