Tom's Two-up Two-down

Letterbox


Travel Cents

I participated in a Small Business Hackathon, and my cross-functional team researched, designed, and built a React front-end prototype to help small businesses in the hospitality sector. You can read more about it in my portfolio on the first floor.


Eloquent Tips

I was cleaning out a notebook, and I noticed several tips I'd written down about NaN, null, and undefined while reading Eloquent Javascript.

NaN is the only value in JavaScript that is not equal to itself

> NaN == NaN // false

Accidental type conversions often return NaN, which is worth remembering when debugging.

> let five // undefined
> five + 2 // NaN
> five = 5
> five + 2 // 7
> five = "five"
> five + 2 // "five2"
> five * 2 // NaN

Build Command - Nil Points!

I forgot to update the Netlify build command on my latest project, monkeyCatRobot. I installed and configured Rollup to bundle my code, and everything worked fine locally. But there was an error when I deployed to Netlify's CDN. I spent a good bit of time rummaging around the interweb with no luck, and I drafted a question, which I almost posted to Stack Overflow. Then I remembered I had made the same mistake on my last project. Fool meself once... The correct build command: rollup -c && eleventy. Nil points.

Here is the question I nearly posted to Stack Overflow:


Shuffle a Deck of Cards

How do you shuffle a deck of playing cards? I created a shuffle function using the Fisher–Yates Shuffle for a game I was working on, and I've tweaked that code a bit for this example. We will swap a random card from the unshuffled portion of a deck with the last unshuffled card in the deck. We then decrement the number of unshuffled cards and repeat. Got that?

Lets take a look at the code. First, I generate a new deck, which is an array of card objects. Then I pass the deck to a shuffle function.


11ty Collections Tags Scheme

I use 11ty's collections tags to organise my blog content. In each blog post's front matter, I assign values to the tags key. All blog entries have a tags key of "post," and I break out posts into three different letterbox tags: article, note, and card.


Today Has an "a"

We can use the logical && and || operators to determine whether to invoke a function depending on an expression's truthy/falsy value. Here is a simple example:

  • The day of the week includes the letter "a", and I need to blog
  • Either I already blogged today (stop evaluating), or I need to blog

And this is how that looks in JavaScript: