Skip to content

Instantly share code, notes, and snippets.

@Andrey-1992
Forked from ericweissman/mod0_session2_exercises.md
Last active February 8, 2021 20:25
Show Gist options
  • Save Andrey-1992/85796877669c83538e6b04e114b68b61 to your computer and use it in GitHub Desktop.
Save Andrey-1992/85796877669c83538e6b04e114b68b61 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.

Use commands in your terminal to create the directories and files structured exactly how they appear in the image below.

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:

  449  ls
  450  mkdir session_3_practice
  451  cd session_3_practice
  452  touch budget.csv
  453  touch mentors.txt
  454  mkdir notes
  455  mkdir practice
  456  cd notes
  457  touch git_notes.txt
  458  touch command_line_notes.txt
  459  cd ..
  460  cd practice
  461  touch git_practice.txt
  462  mkdir projects
  463  cd projects
  464  touch game.js

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):

/Users/andrey92
andrey92@Andreys-MBP ~ % ls
Applications	Documents	Library		Music		Public		notes
Desktop		Downloads	Movies		Pictures	echo		to_do
andrey92@Andreys-MBP ~ % mkdir git_homework
andrey92@Andreys-MBP ~ % cd git_homework
andrey92@Andreys-MBP git_homework % touch quotes.txt
andrey92@Andreys-MBP git_homework % git init
Initialized empty Git repository in /Users/andrey92/git_homework/.git/
andrey92@Andreys-MBP git_homework % git status
On branch main

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)
andrey92@Andreys-MBP git_homework % git add quotes.txt
andrey92@Andreys-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

andrey92@Andreys-MBP git_homework % git commit -m "Initial commit"
[main (root-commit) 784a8c3] Initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 quotes.txt
andrey92@Andreys-MBP git_homework % git status
On branch main
nothing to commit, working tree clean
andrey92@Andreys-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")
andrey92@Andreys-MBP git_homework % git diff quotes.txt
diff --git a/quotes.txt b/quotes.txt
index e69de29..8be1ace 100644
--- a/quotes.txt
+++ b/quotes.txt
@@ -0,0 +1 @@
+I'm learning to use git and is great !
andrey92@Andreys-MBP git_homework % git add quotes.txt
andrey92@Andreys-MBP git_homework % git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   quotes.txt

andrey92@Andreys-MBP git_homework % git commit -m "Second Commit File"
[main 2eb40b4] Second Commit File
 1 file changed, 1 insertion(+)
andrey92@Andreys-MBP git_homework % git status
On branch main
nothing to commit, working tree clean
andrey92@Andreys-MBP git_homework % git log --oneline
2eb40b4 (HEAD -> main) Second Commit File
784a8c3 Fist Commit File
andrey92@Andreys-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)
- cashRegister (integer)
- address (string)
- warehouse (string)
- isOpen (boolean)
- serviceTwentyfourHours (boolean)
- candyInventory (array)
- aisleSelection (array) **EXTENSION**

Methods:
- closeStore (updates the isOpen attribute to false)
- updateTotalSales (updates the totalSales attribute with new sales data)
- organizeAisle (updates the aisleSelection attribute with products selection)
- checkInventory (updates the candyInventory attribute with product inventories)
- registerSales (update the cashRegister with the daily sales report)

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.

@Andrey-1992
Copy link
Author

Andrey-1992 commented Feb 6, 2021

Completed Refactoring Checklist from Task 3 🦀

@mschae16
Copy link

mschae16 commented Feb 6, 2021

@Andrey-1992 - Nice work on this assignment. Your terminal output for both the file/directory and git practice look good. No need to update here, but one thing to be aware of for future commit messages - usually they follow the present imperative tense in terms of syntax and give a description of what was changed or modified. For example, on your second commit you would write something like "Add quote" rather than "Second commit File", for example. The exception to this is the "Initial commit" message. How did part 4 go on modifying your zsh prompt? Keep up the great work!

@Andrey-1992
Copy link
Author

Andrey-1992 commented Feb 8, 2021

@Andrey-1992 - Nice work on this assignment. Your terminal output for both the file/directory and git practice look good. No need to update here, but one thing to be aware of for future commit messages - usually they follow the present imperative tense in terms of syntax and give a description of what was changed or modified. For example, on your second commit you would write something like "Add quote" rather than "Second commit File", for example. The exception to this is the "Initial commit" message. How did part 4 go on modifying your zsh prompt? Keep up the great work!

@mschae16 Great Margo, I will have on mind for the next exercises, thank you very much ! About modifying my zsh prompt was good, I’m still making some changes and trying different things !

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