Install PostgreSQL 16 and have it work with zsh

https://www.postgresql.org/download/macosx/

I first installed PostgreSQL via HomeBrew, but it installed version 14 when I needed to match a server at version 16. When I installed it again via HomeBrew using brew install postgresql@16, I couldn’t access commands such as psql.

I’m sure there are ways to fix all of these aliases, but I have seen how command line apps silently accumulate (plus I am a pleb). So I went with the application download option.

Going this route does NOT connect with zsh by default.

You’ll need to edit your “/Users/YOUR_USERNAME/.zshrc file and add the following PATH alias at the bottom of the file.

export PATH=$PATH:/Library/PostgreSQL/16/bin

Restart Terminal, and you should be in business.

How to make a React useRef() mutable

If you aren’t careful, Typescript assumes that your useRef() declarations are immutable (aka read-only). Which means you will get errors if you try to useRef() to store persistent variables, for example.

Here’s a breakdown from https://stackoverflow.com/questions/58017215/what-typescript-type-do-i-use-with-useref-hook-when-setting-current-manually

The function is set up with overflows if | null is added to the type.

function useRef<T>(initialValue: T): MutableRefObject<T>;
function useRef<T>(initialValue: T | null): RefObject<T>;

You get a read-only error if you type something like this: useRef<HTMLElement>(null)

You will NOT get a read-only error if you include | null in the generic typing.“

useRef<HTMLElement | null>(null); // 🎉

Vite Errors, such as Cannot find type definition file for ‘vite/client’

In the context of Sanity CMS, this only applies to the studio or cms folder.

You’ll need to create a vite.end.ts in the root of your studio folder with the following code:

/// <reference types="vite/client" />

interface ImportMetaEnv {
  readonly VITE_APP_TITLE: string;
  // more env variables...
}

interface ImportMeta {
  readonly env: ImportMetaEnv;
}

See full instructions here:

https://vitejs.dev/guide/env-and-mode#intellisense-for-typescript

Numerical Operations in SASS Functions

They don’t work.

Sorry.

If you try to do @if statements with comparisons, say < or >, you’ll get an error. If you try any math functions, error. Module ‘math’ won’t be found, or you’ll end up with an undefined operation.

The upside is that you haven’t done anything wrong, and they will work elsewhere. If I find a solution, I’ll update this post.

Github Multiple SSH Accounts

Say you are working for multiple clients and each requires a separate GitHub account, plus your personal account. You can automate logging into all of them.

Step 1: Create your first SSH key.

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

In GitHub’s instructions, they recommend:

$ ssh-keygen -t ed25519 -C "your_email@example.com"

I slightly modified this to look like:

$ ssh-keygen -f dmrobbins03 -C "mygithubaccountemail@gmail.com"

-f is the encoding type, dmrobbins03 is the file name prefix (it will generate dmrobbins03_id_rsa).

One tutorial (https://www.youtube.com/watch?v=N2hMGEeYR7c) recommended -f for their keygen, and that looked more familiar to me than the -t output. I am confident that either one works; I was just frustrated at the time.

For me, my config file looked like this:

# Default - dmrobbins03
Host github.com
   HostName github.com
   IdentityFile ~/.ssh/dmrobbins03_id_rsa

You do NOT want to put your default GitHub SSH key under Host * – it will override everything!

I found this counter-intuitive since I assumed increased specificity would have priority. I guess not.

Be sure to follow all of the instructions on the first GitHub link. You’ll need to copy-paste your SSH keys to each of your accounts under Settings > SSH & GPG Keys.

Step 2: Create your second SSH key.

Follow the same instructions as above.

$ ssh-keygen -f clientdavid -C "myclientgithub@gmail.com"

My config then became:

# Default - dmrobbins03
Host github.com
   HostName github.com
   IdentityFile ~/.ssh/dmrobbins03_id_rsa

# Client Account
Host github.com-clientdavid
  HostName github.com
  IdentityFile ~/.ssh/clientdavid_id_rsa

Step 3: Verify

In terminal, use the following commands to verify your SSH is working with GitHub.

ssh -T git@github.com

If you’re successful, you’ll see this:

Hi dmrobbins03! You’ve successfully authenticated, but GitHub does not provide shell access.

Now try your alternate account.

ssh -T git@github.com-clientdavid

You should see this:

Hi client-david! You’ve successfully authenticated, but GitHub does not provide shell access.

THE IMPORTANT PART IS YOUR USERNAME.

I wasted more minutes than I should have because I did not notice that both verifications were using my default account. This was because I had set originally up my host to be *.

Now how do you use this damn thing?

Step 4: Using the damn thing.

When you clone a GitHub repository with SSH, your command will look something like this:

git clone git@github.com:someonesaccount/my-repository.git

That uses your default account. In order to use your secondary (tertiary, etc) accounts, your command will need to be modified as follows:

git clone git@github.com-clientdavid:someonesaccount/my-repository.git

Just change github.com to github.com-clientdavid and that’s it. You’ll have the correct authentication from this point forward.

Additional references:

https://gist.github.com/oanhnn/80a89405ab9023894df7

https://gist.github.com/jexchan/2351996