Categories
Tech

JavaScript Set

As part of my learning regimen, I’ve been doing a daily code challenge on Codewars. So far, it’s been going very smoothly, and I can often think up an algorithm and get it coded in under an hour–with some solutions coming to me immediately.

Today, however, I had to use my first life line, after racking my brain for over an hour.

The problem, as described in the “Kata”, involved finding unique characters in a string. Specifically, checking whether a given string was a “pangram”, which is a sentence that contains every letter of the alphabet (e.g. “the quick brown fox jumps over the lazy dog”).

Of course, my first naive approach involved all kinds of desperate Regex patterns, and keeping a counter, and then checking whether the total count was at least 26 (one for each letter of the alphabet), but I had to abandon this path when I realized just how lost I had gotten.

Fortunately, it didn’t take much time to search online for a hint, and my pal “Google” led me to Set, which immediately got me to my solution. (Yes, I know I don’t need the “i” flag, but I was so excited to submit my solution, that I accidentally left it in).

I know every experienced coder will tell you that the best skill one can have is Googling the solution, and I strongly agree with that, but it also feels nice to be able to think up an algorithm all by myself. However, I won’t beat myself up too much, because the next time I need to find unique values in a set, I’ll know exactly where to look!

Categories
Tech

iCloud and node_modules

Update: Unfortunately, there are open issues with webpack and create-react-app that prevent the usage of symlinks, at least easily or without work that I’m unable to do. Sad times.

For now, I’ve opted to remove all my Node projects out of iCloud, and instead make a habit of creating remote repos on Github.

If you’re not using React, the following solution should still work, and I’d still recommend it!

I’ve been using the COVID-19 lockdown as an opportunity to learn new skills and expand on the ones I’ve already got. For the most part, this has been in the realm of coding.

I’m not quite ready to share the projects I’ve been working on (most of them are really basic little web apps that are more for learning than for a portfolio), but I wanted to share one quick little tip for anyone developing adds with Node.js that uses iCloud.

By default, any new file or directory that you store in iCloud on macOS gets uploaded and synced. In the case of a Node.js project, this means that the monster that is node_modules gets uploaded, as well. This is unnecessary usage of bandwidth and also takes quite a toll on your battery and hard disk.

Fortunately, some smart person made a utility for dealing with exactly this scenario: nosync-icloud.

You can read about it on their site, but the short version is that you can run a command in each of your Node.js project folders, and it will look for a node_modules folder, append .nosync to the folder name (which disables iCloud syncing), symlinks node_modules to the newly un-synced folder, and then adds both to your .gitignore.

Brilliant!