Skip to content

Instantly share code, notes, and snippets.

@saberg1
Forked from ericweissman/mod0_session2_exercises.md
Last active January 12, 2021 21:04
Show Gist options
  • Save saberg1/6cdcd90b3211d473e4c688bc35745d2f to your computer and use it in GitHub Desktop.
Save saberg1/6cdcd90b3211d473e4c688bc35745d2f to your computer and use it in GitHub Desktop.

Session 2 Practice Tasks

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

CAREFULLY READ ALL THE INSTRUCTIONS BEFORE STARTING THESE EXERCISES!

To start this assignment:

  1. Click the button in the upper right-hand corner that says Fork. This is now your copy of the document.
  2. Click the Edit button when you're ready to start adding your answers.
  3. 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:

  315  mkdir session_3_practice
  316  cd session_3_practice
  317  mkdir practice
  318  mkdir notes
  319  cd practice
  320  mkdir projects
  321  cd projects
  322  touch game.js
  323  cd ..
  324  touch git_practice
  325  cd ..
  326  touch budget.csv
  327  touch mentors.txt
  328  cd notes
  329  touch git_notes.txt
  330  touch command_line_notes.txt

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)

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. Use git status to ensure you are set up for tracking using Git
  4. Add your quotes.txt file to the staging area
  5. Check the git status
  6. Create an initial commit (Note: Be sure to follow the correct message format for your first commit!)
  7. Check the git status
  8. Add your favorite quote to the quotes.txt file
  9. Check the git status
  10. Check the changes you've made using git diff
  11. Add the changes to the staging area
  12. Commit the new changes (Note: Be sure to follow convention for commit messages!)
  13. Check the status
  14. Show the log of your work in oneline format using git log (This will likely require some Googling)

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

Steven@newusers-MBP ~ % mkdir git_homework
Steven@newusers-MBP ~ % cd git_homework
Steven@newusers-MBP git_homework % touch quotes.txt
Steven@newusers-MBP git_homework % git init
Initialized empty Git repository in /Users/Steven/git_homework/.git/
Steven@newusers-MBP git_homework % git add .     
Steven@newusers-MBP git_homework % git status
On branch main

No commits yet

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

Steven@newusers-MBP git_homework % git commit -m "initial commit"
[main (root-commit) f0df790] initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 quotes.txt
Steven@newusers-MBP git_homework % git status
On branch main
nothing to commit, working tree clean
Steven@newusers-MBP git_homework % atom quotes.txt
Steven@newusers-MBP git_homework % git diff
diff --git a/quotes.txt b/quotes.txt
index e69de29..740d24e 100644
--- a/quotes.txt
+++ b/quotes.txt
@@ -0,0 +1 @@
+"injustice anywhere is a threat to justice everywhere"
Steven@newusers-MBP git_homework % git status
On branch main
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")
Steven@newusers-MBP git_homework % git add .
Steven@newusers-MBP git_homework % git commit -m "add quote"
[main 8f4879f] add quote
 1 file changed, 1 insertion(+)
Steven@newusers-MBP git_homework % git status
On branch main
nothing to commit, working tree clean
Steven@newusers-MBP git_homework % git log --oneline
8f4879f (HEAD -> main) add quote
f0df790 initial commit
Steven@newusers-MBP git_homework % 



IMPORTANT: Do NOT remove this git_homework directory. You will be using this directory during the next session.

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

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

Class: ConvenienceStore

Attributes:
- totalSales (integer)
- hours (integer)
- address (string)
- storeName (string)
- isOpen (boolean)
- paymentApproval (boolean)
- candyInventory (array)
- employeeName (array) **EXTENSION**

Methods:
- closeStore (updates the isOpen attribute to false)
- updateTotalSales (updates the totalSales attribute with new sales data)
- itemSold (updates the candyInventory attribute with new sale data)
- doorOpen (udpates customerCount attribute with new client data)
- itemRestock (updates the cigaretteInventory attriubte with new on hand data)

4. Modify your Zsh Prompt (10 min)

  • Make sure that your shell is set to zsh by running the following command: $ chsh -s /bin/zsh. Remember to omit the $! Note that macOS Catalina and later operating systems already use zsh as the default shell.

  • Watch this video and follow each step to modify your own zshrc configuration file. As mentioned in the video, you will need this snippet below:

# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '%b'

# Determine if current working directory is a git repository
git_branch_color() {
  if current_git_status=$(git status 2> /dev/null); then
    parse_git_dirty
  else
    echo ""
  fi
}

# Change branch color if working tree is clean
parse_git_dirty() {
  if current_git_status=$(git status | grep 'Changes to be committed:\|Untracked files:\|modified:|deleted:' 2> /dev/null); then
    echo "%F{red}"
  else
    echo "%F{green}"
  fi
}

# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%F{white}%d $(git_branch_color)${vcs_info_msg_0_} %f$'

5. Self Assess

Using the rubric below, assess how you did with these exercises. These are the same metrics your instructors will use to determine if you are prepared for Mod 1!

  • I read carefully read ALL directions
  • I completed all parts of the exercises (not including Extensions) to the best of my ability
  • I used correct syntax, spacing and naming conventions
  • I followed ALL formatting instructions
  • I pushed myself out of my comfort zone and experimented/broke things to try to learn
  • I spent no longer than 20-30 mins Googling a specific problem before asking for help
  • I went back to the lesson to search for clarification before asking for help

Stuck? Having Issues?

Are you stuck on something? Here is the BEST way to ask for help:

  • Find the Session 2 HW Thread in your Mod 0 Slack channel
  • Start or reply in the thread with the problem you are facing. Be sure to follow the guidelines for asking questions below:
    • I can explain what I am trying to do or accomplish
    • I can what I have tried so far and/or what resources I've tried online
    • I can describe specifically what I am stuck on
    • I provided screenshots and/or code examples to give context
      • If I provided short code examples, I used inline code formatting for single lines of code/error messages
      • If I provided larger blocks of code, I used a code snippet in the correct format (such as .js or .rb)
  • Usually, your classmates will be able to answer your question or point you in the right direction very quickly! If not, an instructor will reply within 24-48 hours

Extensions

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

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

@mschae16
Copy link

@StevenTheBearded - Nice job on this assignment. Your terminal output for the file/directory practice and git basics looks good. Quick reminder about the importance of including those file extensions - that helps the OS figure out what kind of application can open and read the file. No need to update here, but in future, you'll want to capitalize those commit messages (ie. "Initial commit", "Add quote"). Your attributes for the ConvenienceStore class look good! For your methods, how about including some of those action verbs in your method names - for example, itemSold could become sellItem. How did part 4 go on modifying your zsh prompt? Keep up the great work!

@saberg1
Copy link
Author

saberg1 commented Jan 12, 2021

🦀

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