Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pJanks/284ccb9d55bd0567d3d7cf88f4152e0f to your computer and use it in GitHub Desktop.
Save pJanks/284ccb9d55bd0567d3d7cf88f4152e0f to your computer and use it in GitHub Desktop.
Mod 0 Session 2 Practice Tasks

Session 2 Practice Tasks

The assignments listed here should take you approximately 55 total minutes.

To start this assignment, click the button in the upper right-hand corner that says Fork. This is now your copy of the document. Click the Edit button when you're ready to start adding your answers. To save your work, click the green button in the bottom right-hand corner. You can always come back and re-edit your gist.

1. Creating Files and Directories (10 min)

Need help? You can go back to the files/directories portion of the lesson here.

Scroll down to the bottom of this page and look at the image of the directories and files. Use commands in your terminal to create the directories and files structured exactly how they appear in the image.

When you're done, type history to see your commands. Copy and paste the commands that were used to create the directory and files:

  211  mkdir session_3_practice
  212  cd session_3_practice
  213  touch budget.csv
  214  touch mentors.txt
  215  mkdir notes
  216  cd notes
  217  touch git_notes.txt
  218  touch command_line_notes.txt
  219  ls
  220  cd
  221  ls
  222  cd session_3_practice
  223  mkdir practice
  224  cd practice
  225  touch git_practice.txt
  226  mkdir projects
  227  cd projects
  228  touch game.js
  229  history
Johnnys-MacBook-Pro:projects johnnycassidy$ 

Since this is just a practice directory, feel free to remove the parent directory session_3_practice when you're done with this exercise.

2. Git Practice (15 min)

You can reference the files/directories portion of the lesson here.

Follow the steps below to practice the git workflow. Be ready to copy-paste your terminal output as confirmation of your practice.

  1. Create a directory called git_homework. Inside of there, create a file called quotes.txt.
  2. Initialize the directory
  3. Check the git status
  4. Add your quotes.txt file to the staging area
  5. Check the git status
  6. Create an initial commit
  7. Check the status
  8. Add your favorite quote to the quotes.txt file
  9. Check the status
  10. Check the diff
  11. Add the changes to the staging area
  12. Commit the new changes
  13. Check the status
  14. Show the log in oneline (yes, oneline, not a spelling error) format

Copy and paste all of the terminal text from this process below (not just the history):

Last login: Fri Sep  6 00:19:11 on ttys000
Johnnys-MacBook-Pro:~ johnnycassidy$ mkdir git_homework
Johnnys-MacBook-Pro:~ johnnycassidy$ cd git_homework
Johnnys-MacBook-Pro:git_homework johnnycassidy$ touch quotes.txt
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git init
Initialized empty Git repository in /Users/johnnycassidy/git_homework/.git/
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	quotes.txt

nothing added to commit but untracked files present (use "git add" to track)
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git add quotes.txt
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   quotes.txt

Johnnys-MacBook-Pro:git_homework johnnycassidy$ git commit -m "initial commit"
[master (root-commit) c9bb201] initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 quotes.txt
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git status
On branch master
nothing to commit, working tree clean
Johnnys-MacBook-Pro:git_homework johnnycassidy$ atom .
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   quotes.txt

no changes added to commit (use "git add" and/or "git commit -a")
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git diff
diff --git a/quotes.txt b/quotes.txt
index e69de29..c9a1bf5 100644
--- a/quotes.txt
+++ b/quotes.txt
@@ -0,0 +1 @@
+"your favorite quote"
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git commit -m "Added your favorite quote"
On branch master
Changes not staged for commit:
	modified:   quotes.txt

no changes added to commit
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git add quotes.txt
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git commit -m "added your favorite quote"
[master 4b1cd54] added your favorite quote
 1 file changed, 1 insertion(+)
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git status
On branch master
nothing to commit, working tree clean
Johnnys-MacBook-Pro:git_homework johnnycassidy$ git log --oneline
4b1cd54 (HEAD -> master) added your favorite quote
c9bb201 initial commit
Johnnys-MacBook-Pro:git_homework johnnycassidy$ 

IMPORTANT: Do not remove this git_homework directory. You will be using this directory during Thursday's session.

3. Classes, Attributes, and Methods (15 min)

Look at the template below for a CardboardBox class. Fill in missing blanks with additional attributes and methods.

Class: CardboardBox

Attributes:

  • width (integer)
  • depth (integer)
  • color (string)
  • condition (string)

Methods:

  • break_down
  • stack
  • carry
  • close/open

4. Modify your Bash Profile (10 min)

  • Watch this video and follow each step to modify your own bash profile. As mentioned in the video, you will need this snippet below:
# get current branch in git repo
function parse_git_branch() {
  BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
  if [ ! "${BRANCH}" == "" ]
  then
    STAT=`parse_git_dirty`
    echo "[${BRANCH}${STAT}]"
  else
    echo ""
  fi
}

# get current status of git repo
function parse_git_dirty {
  status=`git status 2>&1 | tee`
  dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
  untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
  ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
  newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
  renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
  deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
  bits=''
  if [ "${renamed}" == "0" ]; then
    bits=">${bits}"
  fi
  if [ "${ahead}" == "0" ]; then
    bits="*${bits}"
  fi
  if [ "${newfile}" == "0" ]; then
    bits="+${bits}"
  fi
  if [ "${untracked}" == "0" ]; then
    bits="?${bits}"
  fi
  if [ "${deleted}" == "0" ]; then
    bits="x${bits}"
  fi
  if [ "${dirty}" == "0" ]; then
    bits="!${bits}"
  fi
  if [ ! "${bits}" == "" ]; then
    echo " ${bits}"
  else
    echo ""
  fi
}

export PS1="\u\w\`parse_git_branch\`$ "

5. Questions/Comments/Confusions

If you have any questions, comments, or confusions that you would an instructor to address, list them below:

Extensions

  1. If time permits and you want extra git practice and alternative explanations (it's often beneficial to have something explained in many different ways), check out Codecademy's Git Course, particularly the first free item on the syllabus, "Basic Git Workflow". In Mod 0, we will not cover anything beyond Codecademy's intro section; however, you are welcome to check out the other git lessons listed on the syllabus if you want a head start.

  2. This course is how I personally learned command line. If time permits, I highly recommend reading and practicing.

  3. Also recommended by Jeff Casimir: Michael Hartl's Learn Enough Command Line.

  4. Add tab completion to make your life easier: Type Less. Do More.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment