thoughtSpace
TwitterGithubRSS Feed

Note Space

Hints, cheat sheets and notes on code.

Commands

Useful Javascript Commands

npm init -y, // create package.json
npm i -D package_name // install dev dependencies
node index.js, // run Node server
nodemon file.js //run server that constantly watches so no need to restart server
npm update // update node dependencies
npx degit <remote-url>// does a git clone and removes the git directory 
npx unlighthouse --site <sitename> // get lighthouse score of a site 

Useful Angular commands

ng serve // CLI command to run angular application locally. http://localhost:4200/ is the port
ng new app-name // for a new app
ng g c home/ng // generate component product-alerts create new components
ng g s services/file-upload // generate service
ng g class models/file-upload --type=model // generate model
ng add @angular/material // add material to app

Useful Laravel Commands

php artisan config:cache // clear cache
php artisan route:clear // clear route cache
php artisan view:clear // clear view cache
php artisan optimize:clear // clear LL cache
php artisan event:generate // Generate Events
php artisan queue:work // Run Laravel job

Useful python Commands

pip cache purge # Clear cache
python -m venv venv # Create Virtual environment
# venv\Scripts\activate - Activate Virtual environment
pip install -e git+https://github.com/guettli/django-htmx-fun.git # clone and pip install from repo

Useful Git Commands

esc :wq! # Quit Vim

git config --global user.name "Victor-Nyangi"
git config --global user.email "gichuivictor@gmail.com"
git init
git add .
git commit -m "Initial commit"
git remote add origin remote_url
git branch -M main
git push -uf origin main
rmdir /s .git to undo git init
git remote set-url origin <remote-url> # update a remote url

git remote add origin <remote-url> # add a remote url
git branch -a #check branches in local and remote repo
git branch --delete <branch_name> #delete a branch but checkout from it first

git branch -m <old-name> <new-name> # rename a git branch

git remote remove origin
heroku git:remote -a my-project #create a remote connection with Heroku specifically and also create a branch on that remote for you and your app name will be the name you provided
git subtree push --prefix server heroku master  # telling git to push a subtree, or in other words a subdirectory, from our current git repo. The --prefix flag comes before that subdirectory that we want to push, in our case it is server. And lastly we're telling it to push to the remote heroku our master branch.

#switch branches
#switch to develop branch 
git checkout develop 
#switch to a new branch branch_name, it's good if remote and local branch have the same names
git checkout -b <branch_name> 

# Merge the documentation branch into the parent branch
# need to be in parent branch to do the merge
git merge --no-ff documentation

git push -u origin <branch_name>

git rm -r --cached . to clear and gitignore afresh

git reset --soft HEAD~1 # Undo last commit changes

Using git: https://jigarius.com/blog/multiple-git-remote-repositories

git stash - takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy. At which point you're free to make changes, create new commits, switch branches, and perform any other Git operations; then come back and re-apply your stash when you're ready.

git stash pop - removes the changes from your stash and reapplies them to your working copy.

git stash apply - reapply the changes to your working copy and keep them in your stash

git stash show -p stash@{0} -preview stashed changes

git stash apply stash@{1} - apply stash chanegs without deleting it

git clone --single-branch --branch <branch_name> - clone into a repo's branch

git commit --amend --no-edit // make the amendment to your commit without changing its commit message.

git commit --amend -m "an updated commit message" // ammend previously made commit message

git fetch && git rebase origin/<branch> // fetch chanegs from remote branch and add current changes on top of pulled changes

git reset --hard HEAD 1 // delete latest commit

git reset --hard origin/dev // reset local to be at par with remote

--soft: uncommit changes, changes are left staged (index).
--mixed (default): uncommit + unstage changes, changes are left in working tree.
--hard: uncommit + unstage + delete changes, nothing left.
console.table(object)

let startTime = Date.now()
console.time("Loop")
for (let i=0; i < 100000; i++) {
    // Do something
}
console.log("Loop")

const elem = document.querySelector("div")
console.dir(elem)

Useful SQL commands

SELECT * FROM information_schema.columns WHERE table_schema = '' AND table_name = '';

SELECT TABLE_NAME,
       CONSTRAINT_TYPE,CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME='table_name';

HttpClient commands

lt --port 8001 --local-host "127.0.0.1" #Run local tunnel
ngrok http 127.0.0.1:8000 #Run on ngrok
expose share http://127.0.0.1:8001 --subdomain=vicg

Useful docker commands

docker --version #Check Docker version
docker pull <image_name> #Download Docker image
docker image ls #List local Docker images
docker container ls #List running containers
docker container run -it <image_name> bash #Start interactive container shell
docker container stop <container_id> #Stop a docker container
docker image rm <image_name> #Remove a container
docker rmi <image_name> #Delete a Docker image
docker image build -t <image_name> <path_to_dockerfile> #Build Docker image from Dockerfile
docker-compose up #Start containers with Docker Compose
docker container logs <container_id> #View container logs:
docker container exec -it <container_id> <command> #Execute command inside container:
docker network create <network_name> #Create custom Docker network
docker volume create <volume_name> #Create named volume for persistent data storage
docker-compose down #Stop and remove containers with Docker Compose
docker container stats #Display container resource stats
docker image save -o <output_file.tar> <image_name> #Save Docker image to tarball file
docker image load -i <input_file.tar> #Load Docker image from tarball file
docker swarm init #Initialize Docker Swarm mode cluster:
docker service ls #List services in Docker Swarm cluster

Note Space © 2022 — Published with Nextjs

HomeTopicsLinksDefinitionsCommandsSnippetsMy works