Review of Week 3 Day 2 Learning Objectives

Node.js lesson

  1. Define NodeJS as distinct from browser based JavaScript runtimes.

JavaScript (like most programming languages) has mutltiple runtimes, each of which is a full implementation of the language and supporting libraries. With JavaScript, the two implementations (runtimes) that we care about are V8 (used in Chrome, and also the Node.js runtime) and Spidermonkey (used in Firefox).

  1. Write a program that reads in a dictionary file using node’s FS API and reads a line of text from the terminal input. The program should ‘spell check’ by putting asterisks around every word that is NOT found in the dictionary.
const readline = require('readline');
const fs = require('fs');
let dictionary = [];

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

function askQuestion() {
    rl.question('What would you like to spell check? ', (answer) => {
        let wordsToCheck = answer.split(' ');
        let result = [];
        for (let i =0; i < wordsToCheck.length; i++) {
            if (dictionary.includes(wordsToCheck[i])) {
                result.push(wordsToCheck[i]);
            } else {
                result.push("*" + wordsToCheck[i] + "*");
            }
        }
        rl.close();
        console.log(result.join(' '));
    });
}


fs.readFile('dictionary.txt', 'utf8', (err, data) => {
    if (err) {
        console.log(err);
        return;
    }
    console.log(data);
    dictionary = data.split('\n');
    //using callback chaining
    askQuestion();
});

Git lesson

  1. Use Git to initialize a repo
$ git init

This will create a .git hidden folder inside your new repository.

  1. Explain the difference between Git and GitHub

Git is a distributed version control system that allows us to build up patch sets and changes.

GitHub is a company that provides git repository hosting as well as project management features like code review, issues, wiki, etc.

  1. Given ‘adding to staging’, ‘committing’, and ‘pushing to remote’, match attributes that apply to each.

Adding to Staging:

Committing:

Pushing to Remote:

  1. Use Git to clone an existing repo from GitHub

After discovering the repository url (from GitHub, Bitbucket, etc. or if someone sends you a link to their privately hosted git repository)

$ git clone <repo_url>
  1. Use Git to push a local commit to a remote branch

The changes tracked by your local branch called branch_name can be pushed to any remote with the git push command.

$ git push <remote> <branch_name>
  1. Use git to make a branch, push it to github, and make a pull request on GitHub to merge it to master

Assuming you are working on an existing project. First create a branch

$ git checkout -b <my_branch>

Make your changes, add them and commit them

$ git add -p
$ git commit -m 'my awesome changes.'

Push your newly created branch.

$ git push origin <my_branch>

Then point your browser at the GitHub repository, and follow the onscreen prompts to create a pull request.

  1. Given a git merge conflict, resolve it

Once you’ve done the mental work of correcting the conflicting errors, use git add and git commit to commit the resolved code.

  1. Match the three types of git reset with appropriate descriptions of the operation.

Hard (git reset --hard <ref>):

Soft (git reset --soft <ref>):

Mixed (git reset <ref>):

  1. Use Git reset to rollback local-only commits.
$ git reset --hard HEAD
  1. Identify what the git rebase command does

git rebase allows us to rewrite the history of the current branch my changing commit contents, or adding commits to our history and replaying all the commits since that moment on top of them. Rebase allows us to clean up mistakes in our history, or to avoid adding “merge commits” by adding the commits from another branch into our branches’ history.

  1. Use git diff to compare a local ‘staging’ branch and ‘master’ branch.
$ git checkout staging
$ git diff master
  1. Use git checkout to check out a specific commit by commit id

This will leave your git repository in a “headless” state, which you cannot apply commits on top of.

$ git checkout <ref>