Week 26 Homework đť đŚ
New stuff we learned this week: đ¤
Git
git
is a version control system â meant to help you keep track of changes to a set of files over timegit
was created by Linus Torvalds (the creator of Linux) in order to manage the ongoing development of the Linux kernal. It was especially created to be fast, non-linear, and distributed.git
tracks files within a given directory â you can start a new project ingit
by typinggit init
in the directory you want to start tracking.- a
git
-tracked directory is called a repository (or repo) for short git
works all itâs magic by creating and modifying a set of files inside a directory called.git/
inside the repository directory. The.git/
dir is created when yougit init
.git
watches the directory youâre working in (called the working tree) and notices when you add new files, delete files, or make changes. To see whatgit
thinks about the current state of things, you usegit status
â which prints out a status report of new, deleted, modified, and âstagedâ files- git will also show you the differences between the current version of your files, and the most recent saved (committed) versions, using
git diff
- âsavingâ your work in
git
is done by making a commit â a commit is a deliberate set of changes that you want to record, and they have names and descriptions, like âfix bug #32â or âadd goat banjo rodeo to title tagâ. Commits also become points to which you can go back in time. A commit represents a meaningful unit of work. - use
git log
to print out on the screen the commits in your repo.git log
is like looking at a chronological list of save points. - before you can commit your work (create a commit) â you have to tell git what changes you want to be included â because you might not want to include all of your changes in a commit. To tell
git
what changes to include, you usegit add <path-to-file>
- any files that you add using
git add
become staged â that is to say they are designated to go into the next commit, and they turn GREEN when you typegit status
- example:
git add new-file.js
(stages justnew-file.js
) - example:
git add .
(stages everything in the directory.
)
- example:
- think of staging files as putting them on a truck, to go out with the next shipment đ
- once you have some staged files, youâre ready to commit which saves your work (sending off the truck đ). You commit work by running the command
git commit -m "some sweet commit message"
- a git branch is technically just a simple pointer to a commit but it represents the possibility of a fork in the road
- to list all of your current branches use
git branch
- to make a new branch do:
git branch my-rad-branch
- to delete a branch:
git branch -d my-rad-branch
(safe â wonât delete the branch if there are commits that would be lost) - to force-delete a branch:
git branch -D my-rad-branch
(UN-safe â will delete the branch even if it means commits would be lost) - to switch to another branch you use the checkout command:
git checkout my-rad-branch
. This changes the files in place in your repo which is magically awesome! đŽđŽ
Git command summary:
git init
- initialize a directory to be under gitâs control, turning it into a repositorygit status
- view the status of your working directory â a summary of what modified and staged files you have in your current repogit log
- view a list of your commits (most recent first)git diff
- see differences between files and last commitgit add <path>
- stage modified files to be included in next commitgit commit -m "<message>"
- save all staged changes, storing them with a messagegit branch
- list all branchesgit branch <new-branch>
- create a new branchgit branch -d <some-branch>
- safely delete a branchgit branch -D <some-branch>
- dangerously force-delete a branchgit checkout <some-branch>
- checkout a branch
Useful Links:
Homework Plan:
- 1 day adding to and reviewing all flash cards
- 1 days Node Homework
- 1 day Web Homework
- 2 days touch typing practice
- 1 day watch CCCS #24
Homework day 1
- flashcard assignment
- Node Homework
Homework day 2
- touch typing practice
- watch CCCS #24
Homework day 3
- Web Homework
- touch typing practice
Flashcard Assignment
- add 10 new flaschards in a new
git
category â they should match the 10 commands in the âGit command summaryâ section of âNew stuffâ above - review your new
git
cards a few times until you have them memorized - review the rest of your flashcard pile all the way through, repeating any you forgot
Node Homework
- slowly and carefully review the âNew Stuffâ above
- make sure youâve done your âFlashcard Assignmentâ first
- if you get stuck with any of the
Array.*
methods, or node code sharing, review the New Stuff from week 25 and week 23. ssh
into your home dir- type
git config --global --edit
and hit enter, this will bring upvim
â and youâll be able to edit your git username and email. Fill out your name and email, removing the#
comment markers. You only have to do this once per computer you use git on. - make and move into a new dir:
~/node/week26/
- type a command to turn this directory into a git repository
- take a minute and go âspelunkingâ into the
.git
directory. Poke around andcat
some things out, but donât change anything. - now, create a node script called
subtract.js
that usesArray.reduce()
to subtract numbers, starting from zero, with these specifications:- it should use the
convert.js
module you made last week to convert the arguments fromprocess.argv
into numbers - when complete, it should work like this:
- it should use the
$ node subtract.js 3 5 10 20
> -38
$ node subtract.js 100
> -100
- now, ask
git
what it sees that is new - put
subtract.js
on the truck - commit your work with a commit message
- view the list of your commits
- next change your
subtract.js
file so that the first numeric argument supplied becomes the initial value (instead of subtracting from zero), so it works like this:
$ node subtract.js 1000 5 5 5
> 985
$ node subtract 50 1 2 3
> 45
- ask
git
what it sees that is new - ask git to show you the differences in the actual code that you changed
- put your work on the truck, and send it off with a commit message
- view the list of your commits
- make a new node module called
unflat.js
, it should export an array whose members are arrays of numbers â so itâs an array of arrays. It should have at least 3 sub arrays. An example would be:[[1, 2], [2, 3, 50], [5]]
- make a new node script called
flatten.js
that:- imports the
unflat
module you just created - uses
Array.reduce()
to change the array of arrays into a single, flattened array - hint: youâll need to use
Array.concat()
inside your reducer function - it should console.log out the flattened array, so, using the example array I gave above, the script would work like this:
- imports the
$ node flatten.js
> [1, 2, 2, 3, 50, 5]
- once youâve got it working, put both new files on the git truck, and commit your work
- view the list of your commits
- next, weâre going to make a new git âbranchâ in order to add a new âfeatureâ to our node repo. Create a new branch called âsiblingsâ
- type a command to see all of your branches â can you tell what branch youâre on?
- switch over to the new branch you just created
- list the branches again and confirm youâre on the new branch
- quick view your commits â can you see how git is trying to show you that your new branch currently is pointing to the same commit that the
master
branch is also pointing too? See if you can find that little bit of data in the output ofgit log
- now, on your new branch, make a node script called
siblings.js
that:- imports the
/htc-members.js
module file I created last week - uses
Array.reduce()
to build up a list of all siblings of all HTC members - console.logâs them out on one line, (with commas separating), like this:
Charlie, Eden, Ezra, <...>
- it should work like this:
- imports the
$ node siblings.js
> Charlie, Kiah, Eden, Ezra, Willow, Eden, Ezra, Harriet, Huck, Dale, Win, Huck, Dale, Jamie, Janna, Jason
- once youâve got it working, add the new file to your staging area, and commit
- view the list of your commits and see if you can see how the branch youâre on has now moved AHEAD of the
master
branch - now, change the
siblings.js
script so that it removes duplicates from this list, so it works like this:
$ node siblings.js
> Charlie, Kiah, Eden, Ezra, Willow, Harriet, Huck, Dale, Win, Jamie, Janna, Jason
- when youâve got it working, check
git status
andgit diff
and make sure you like everything you see, then commit. - now, switch back to the
master
branch ls
to see that thesiblings.js
file is GONE!!!- then, switch back to the
siblings
branch, andls
again â itâs back!!! Phew. - Kiah Credit: ⨠- modify the
siblings.js
file so that it only prints out siblings of HTC members that are not in HTC, then commit your work. - Kiah Credit: ⨠make a new node module file called
array-map.js
that exports a single function:arrayMap
that re-implments Array.map using Array.reduce under the hood. I should be able to import it and calle it like this:arrayMap([1, 2, 3], sum, 0)
and it should return5
. - Kiah Credit: ⨠Do the same thing as above, but a new module re-implementing
Array.filter()
usingArray.reduce()
so I could do:arrayFilter([1, 2, 3], isOdd)
and get back[1, 3]
. Slack me when youâve got both modules made.
Web Homework
ssh
into your home dir, make and move into a dir:~/www/week26
- make your new dir into a git repo
- as you are working on fulfilling the requirements below, pause at least 4 times at logical stopping points to commit your work with meaningful commit messages
- make a webpage called
index.html
that meets the following requirements:- the javascript and CSS for it should all be on the same page, not in separate files
- it has a lovely background color
- it has a small html form with inputs of at least 3 types
- the form should submit to:
http://server.howtocomputer.link/week24/echo
- it should have a button, that, when clicked, prompts the user for a CSS color keyword, and then takes that color keyword and uses it to change the background color of the site.
- it should have 3 divs that contain an h1 and a p, each with a
git
command as the h1 and a brief description of what that command does
- when youâre done doing all of that, you should have 4 commits already
- next, modify your webpage so that the 3 divs containing info about git line up side by side (using flexbox)
- commit your work
- modify it again, so that they only line up side by side when the screen is larger than 768px, and commit your work
- next, extract the javascript into a file at the path
~/www/week26/assets/script.js
and also extract the CSS into a css file at the path~/www/week26/assets/styles.css
. Modify theindex.html
file so that these two files are connected properly. - commit your work
- next, make a new branch called
some-changes
and switch to it. On the new branch, change a couple of key parts of the CSS or HTML so that the webpage is visibly different. Commit your work, and view your webpage in a browser. - now switch back to the
master
branch and refresh the page in your browser, it should look like it did before you made your new branch. Do you see hownginx
is just serving whatever files are in the directory, andgit
is just switching out the files in place when you change between branches? - make yet another new branch, this one called
temp-lol
, and switch to that branch. Make a few changes creating bugs and general chaos. Commit your work and view your webpage in a browser. Itâs OK if your webpage is broken. - now, switch back to the master branch and delete your
temp-lol
branch.