Home

Awesome

Learning Bash Scripts

Just one of the things I'm learning. https://github.com/hchiam/learning

A nice article on key things to know: https://www.joshwcomeau.com/javascript/terminal-for-js-devs (my own summary notes are below)

To enable running a script upon click, you need to edit permissions. For example, for chrome-incognito-shortcut.app:

chmod 744 chrome-incognito-shortcut.app

Related Repos

https://github.com/hchiam/learning-powershell

https://github.com/hchiam/learning-dependency-cruiser

https://github.com/hchiam/learning-https-server

> and < and >> and << in bash

https://superuser.com/questions/480599/with-regards-to-piping-commands-what-are-the-greater-than-and-less-than

Useful git commands

From https://stackoverflow.com/questions/4348590/how-can-i-make-git-ignore-future-revisions-to-a-file/39776107#39776107 :

From https://www.smashingmagazine.com/make-life-easier-when-using-git/ :

git bisect start
git bisect good c5ba734 # if c5ba734 is a commit without the bug
git bisect bad 6c093f4 #if 6c093f4 is a commit with the bug
# run test: git bisect run ./test-bug  (or: git bisect run jest)
git bisect bad # if the current commit has the bug
git bisect good # if current commit does not have the bug
# (repeats until find the first commit with the bug)
git bisect reset # or: git bisect reset HEAD (or: git bisect reset <commit-id>)
git rebase -i --exec "yarn test" d294ae9 # test all commits from d294ae9 to HEAD, until hit first failing commit

From https://dev.to/g_abud/advanced-git-reference-1o9j#git-commands :

From https://www.youtube.com/watch?v=ecK3EnyGD8o :

How to revert changes of a git push:

This shows the commit hash: (looks like l0ngStr1ng0fL3t7er5AndNum83rz)

git log

then use the hash of the commit you want to revert: (and when you're in the in-CLI editor, type :qa and then hit Enter)

git revert l0ngStr1ng0fL3t7er5AndNum83rz

How to create a branch with no history

https://stackoverflow.com/a/34954852

git checkout --orphan <name_you_choose_for_orphan_branch>
git commit
git push <remote-name> <branch-name>

Random Notes

Get file info like edit date: stat filename

Example of script used by Travis CI npm run build to copy files to /public folder: copy-to-public-folder.sh

Example of script used to generate and insert a package SemVer number for a JS file: package.sh

Exit/quit:

exit

Get list of globally installed packages

yarn global list

npm list -g --depth 0 for just top-level

npm list -g browser-sync or a specific package (this example checks if browser-sync is installed globally)

npm scripts that accept parameters

Examples I set up in package.json:

{
  "test": "tsc $npm_config_name.ts --lib es6,dom && node $npm_config_name.js",
  "demo": "echo \"HELLO $npm_config_file_name.ts GOODBYE (\\$npm_config_whatever will match --whatever=...)\""
}

So you can do this:

npm run demo --file_name=someFileName
# prints out: HELLO someFileName.ts GOODBYE [...]

and:

npm run test --name=sameFileName
# will run: tsc sameFileName.ts --lib es6,dom && node sameFileName.js

Install package without dynamic version (i.e. without caret ^)

npm install <package-name> --save-exact

so you get 1.2.3 instead of ^1.2.3 in your package.json

https://stackoverflow.com/questions/58638817/what-is-the-purpose-of-using-save-exact#:~:text=--save-exact%20will%20generate%20the%20next%20package.json%20code

Actually upgrade node

You can upgrade to the latest npm with npm install -g npm@latest

But installing node manually doesn't always work, and using n or clean cache didn't seem to work for me. https://stackoverflow.com/questions/23940172/not-seeing-latest-version-when-updating-node-js-via-installer-msi-windows-7/31229369#31229369

For Mac/OSX, try this first:

brew install node

Otherwise this:

nvm install node --lts
node -v

If you accidentally installed the latest but want to downgrade to the last stable instead:

nvm install 14.15.0 # whatever the latest unstable versioni on https://nodejs.org/en/
nvm use 14.15.0

switching from bash to zsh: (and back)

https://github.com/hchiam/learning-zsh

Format whole directory instead of waiting for each file save in VSCode

prettier --write .

or

npx prettier --write .

how to sync forked repo with the original repo

https://stackoverflow.com/questions/7244321/how-do-i-update-or-sync-a-forked-repository-on-github

git remote add upstream https://github.com/<owner>/<repo>.git
git fetch upstream

gh CLI commands

https://github.com/hchiam/learning-gh

setting up GitHub PATs (Personal Access Tokens)

For gh CLI: copy your PAT, run gh auth login, and paste your PAT when prompted to.

For npm pkg: copy your PAT, open ~/.npmrc, and paste your PAT to be the "TOKEN" part of a string //npm.pkg.github.com/:_authToken=TOKEN in that ~/.npmrc file.

quickly set up a basic server to serve index.html (or whatever's in the current folder)

python3 -m http.server 8000

or set up shortcut srv in .bash_profile:

alias srv='python3 -m http.server 8000'

https://www.joshwcomeau.com/javascript/terminal-for-js-devs

more to learn for unix:

5 linux command tricks from fireship.io

https://www.youtube.com/shorts/fwBIZRq-vzY