Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippets #11

Open
2 tasks
shreshthmohan opened this issue Mar 15, 2022 · 0 comments
Open
2 tasks

Snippets #11

shreshthmohan opened this issue Mar 15, 2022 · 0 comments

Comments

@shreshthmohan
Copy link
Owner

shreshthmohan commented Mar 15, 2022


summary: Oft-used useful code snippets I like keeping handy
url: https://shreshth.dev/blog/snippets

Open a page on mobile when on localhost (Mac)

Get the IP address to check a localhost webpage on the phone when the server is running on the Mac. Don't forget to add the port. (e.g. 192.168.1.34:3000). Note that this works only when both the Mac and your phone are on the same network.

ifconfig | grep inet | grep 192 | awk '{print $2}'

Side note: navigator.clipboard.writeText() won't work on iOS Safari for security reasons (TODO: ref)

Anchor element which opens a link in a new tab, safely.

<a href="https://example.org" target="_blank" rel="noopener noreferrer">link name</a>
  • TODO: explain in short the security issues when using only the target="_blank" attribute-value pair

Brew

Start a service installed via brew.

Optionally use --verbose to debug any issues

brew services start --verbose postgresql@14

Stop a service installed via brew.

brew services stop --verbose postgresql@14

See which services are running via brew

brew services list

List packages installed via brew

brew list

Misc brew commands

brew uninstall --ignore-dependencies node 
brew uninstall --force node 
brew update
brew install nvm 

NVM

Node Version Manager is super useful for switching between node.js versions.

nvm ls
nvm use stable
nvm use v14.19.2
nvm alias default 16.13.2

npm

Install a specific npm version

When using node.js version, a version of npm that ships with that node version will be used by default.
To override, you can specifically install the version of npm you like (of course, you should be aware of the compatibility between those node and npm versions). To achieve this, install a specific npm version like so:

npm install -g npm@8.10.0

Note: When using nvm, if you switch node versions, the paired version of npm will be used.
Explanation: node v14.19.2 ships with npm v6.14.17 and node v16.13.2 came with npm v8.1.2 ; now, if you install a different npm version by using the command above, say for node v14.19.2 you installed npm v8.10.0 ; And now you decided to switch to node v16.13.2 ; When you switch to node v16.13.2 and check npm -v you'll see 8.1.2. So each npm package install instance (?) is tied to a specific node version when using nvm.

More npm commands

  • Todo explain, or at least add a title each.
npm i --legacy-peer-deps
npm i -g sails
npm link local-package
@shreshthmohan shreshthmohan added draft A blog post that is a draft enhancement New feature or request and removed enhancement New feature or request labels Mar 15, 2022
@shreshthmohan shreshthmohan added status:published and removed draft A blog post that is a draft labels Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant