Prework Flashcards
Command, regardless of where we currently are, will take us to our home folder
cd ~
Command to create a file
touch file.txt
Command to open a file
open joke.txt
Command to see whats in a file without opening it
cat file.txt
Command to create a folder
mkdir folder
command to move a file into a folder
mv joke.txt funny_things/
command for remove
rm
options to commands format
Options to commands are always of the format –word or
-letter
Command for copying folders
cp -r folder copy_of_folder
Command Line
A text-based interface.
Synonyms: command-line interface (CLI), console
Terminal
An OSX application that provides text-based access to the operating system;
Any device or application used for data entry and display in a computer system
Synonyms: client, computer terminal, terminal emulator
File System
A file system is a systematic way to control how information is stored and retrieved. It describes where one piece of information stops and where the next one begins. Each file system has its own structure and logic.
Synonyms: NTFS (Windows’ File System), HFS+ (Apple’s File System), file allocation table, GFS (Global File System)
Directory
An organizational unit, or container, used to organize computer files into a hierarchical structure.
Synonyms: folder, catalog, drawer
Path
A sequence of symbols and names that identifies a file or directory. The path always starts from your working directory or from the root directory, and each subdirectory is followed by a forward slash.
An absolute or full path begins with the root directory and specifies every directory above the terminating file or directory name.
A relative path does not include the root or parent directory names, and refers to a file or directory directly below the current working directory.
Synonyms: pathname
Command
The action we want the computer to take; always a single word.
Synonyms: utility
Option
Follows the “command” in a command line, to modify the behavior of the command in some way.
Synonyms: flag
Argument
Follows the “command” and “options” (if any) in a command line, and is used to explain what we want the command to act on.
The number of arguments used generally depends on the command: some don’t need arguments, some require exactly one argument, some require lots of arguments, and some are flexible in the number they can take.
Prints the working directory; returns the absolute path name of the current directory.
pwd -options
Lists directory contents.
ls [-options] [path/to/directory]
Changes the current working directory to the specificed directory.
cd [-options] [path/to/directory]
Makes a new directory
mkdir [-options] [path/to/directory]
Removes directories or files permanently
rm -r [path/to/file] [path/to/file] …
Moves directories or files to a new local
mv [-options] [path/to/file] [path/to/directory]
Renames a file or directory.
mv [-options] [path/to/file] [NEW_FILE_NAME]
version control
making a saving multiple versions of a project so you can restore an old version
command to list files including hidden files
ls -a
git init
hides a .git file in the directory you are working in so it can use the git stuff. turns directory into a git repository or “repo”
update on the status of a git project
git status
git
An open source program for tracking changes in text files. It was written by the author of the Linux operating system, and is the core technology that GitHub, the social and user interface, is built on top of.
Commit
An individual change to a file (or set of files).
It’s like when you save a file, except with Git, every time you save it creates a unique ID (a.k.a. the “SHA” or “hash”) that allows you to keep record of what changes were made when and by who.
Commits usually contain a commit message which is a brief description of what changes were made.
Synonyms: a revision
Diff
A diff is the difference in changes between two commits, or saved changes.
The diff will visually describe what was added or removed from a file since its last commit.
Remote
The version of something that is hosted on a server, most likely GitHub.com. It can be connected to local clones so that changes can be synced.
Repository
The most basic element of Git.
A repository is a project’s folder, containing all of the project files (including documentation), and stores each file’s revision history. Repositories can have multiple collaborators and can be either public or private.
Fork
A personal copy of another user’s repository that lives on your account.
Forks allow you to freely make changes to a project without affecting the original.
Forks remain attached to the original, allowing you to submit a pull request to the original’s author to update with your changes.
Clone
A copy of a repository that lives on your computer instead of on a website’s server somewhere, or the act of making that copy.
With your clone you can edit the files in your preferred editor and use Git to keep track of your changes without having to be online.
It is, however, connected to the remote version so that changes can be synced between the two.
You can push your local changes to the remote to keep them synced when you’re online.
Push
Pushing refers to sending your committed changes to a remote repository such as GitHub.com.
For instance, if you change something locally, you’d want to then push those changes so that others may access them.
Tells Git to start monitoring the current folder you’re in. In other words, for my working directory, create a new “timeline” where we can manage our source code.
git init
git status
Get the current status of Git. Files that are “staged” (about to be committed), and files that are unstaged (files that have changed since the last commit, but are not about to be committed) will both show up here
git add path/to/directory/or/file
Add a file to the “stage”. The stage can be thought of as an inbetween state between the last commit and what is ready to be committed. Once the command git commit is run, all staged files will be committed to the timeline.
Commit all staged files to the timeline. If -m “Commit messsage” is ommitted, Git will open your default text editor (typically Vim) to enter a longer message. If for any reason Vim is opened, you can close it by typing :q.
git commit -m “Commit message”
Visualize the timeline. You can scroll with the arrow keys or j, k, and it can be exited by typing q.
git log
Show the changes of the given file or directory.
git diff path/to/directory/or/file
Create a new local git repo copied from a remote one
git clone http://path/to/repo
Send local changes to tracked remote repository
git push origin master
Equality
==
ex. 10 == ‘10’
Strict equality
===
(2 * 5) === 10
Inequality
!=
9 != 10
Strict inequality
!==
‘10’ !== 10
Greater than or equal
> =
Ternary Operator
(expression) ? ‘if true’ : ‘if false’;
if else syntax
if (condition1) { // Code to be executed if condition1 is true } else if (condition2) { // Code to be executed if condition1 is false and condition2 is true } else if (condition3) { // Code to be executed if condition1 and condition2 are false, and condition3 is true } else { // Code to be executed if condition1, condition2, and condition3 are false }
switch statement syntax
switch (expression) { case value1: // Code to be executed if expression === value1 break; case value2: // Code to be executed if expression === value2 break; default: // Code to be executed if expression is different from both value1 and value2 }
while Loops
while loops can run indefinitely, so long as the condition remains true.
The loop’s condition is re-evaluated each time the block finishes running.
for Loops
A ‘for’ loop will generally run a fixed number of times, not indefinitely.
The three parameters for a for loop, in order, are (1) an initialization, (2) a condition, and (3) a final expression.
function
A function is a custom operation that can be run on command. It can be use both as an operator (accepting input values and calculating output values) and as a subroutine (do this thing... then do this thing...). Functions must be defined before they can be used. To define a function, use the following recipe: var myFunctionName = function() { // Body of the function } To use, or call a function, simply type the name of your function, followed by () (plus any inputs that you might be passing in).
return statements
In addition to specifying a final value for the function to give back as a result, a return statement will cause the function that contains it to immediately end when that line is run. For example, if the function below is operating on a number greater than ten, it will stop executing at its second line, and return 15, not x. var someFunc = function(x) { if (x > 10) { return 15; } return x; }
array functions
In addition to storing a set of values, arrays also have a number of in-built properties and functions that they can use.
.length gives you the length of the array you call it on.
.push() adds a new element to the end of an array, and returns that element.
.pop() removes the last element in an array, and returns that element.
.indexOf() searches within your array for the first element that matches its parameter, and returns the index of that match; if no match is found, it returns -1.
for loops
for (var i = 0; i
.map()
creates a new array with the results of calling a provided function on every element in this array.
.forEach()
executes some function once for each element in the array it’s called on.
associative array
myassociativeArray[‘myKey’]
myAssociativeArray[‘myKey’] = ‘aValue’
myAssociativeArray[‘someNewKey’] = ‘someNewValue’
Math.floor()
rounds down
Math.ceil()
rounds up
helper method
method inherent for specific data type
‘string’.toUpperCase()
STRING
parseInt(‘123’)
123
parseInt(‘123asd’)
123
parseInt(‘asd123’)
NaN
Number(‘123’)
123
4.2 % 1
0.200000000
parseFloat(‘123.34’)
123.34
array.unshift(‘thing’)
puts in array at front as opposed to push
array.shift()
like pop but cuts off the front
for loop classic structure
for (var i = 0; i
{ …..
…..}
block
{
curly brace
!
bang
opposite
true to false
or !=
switch syntax
var food = 'apple'; switch(food) { case 'pear': console.log('I like pears'); break; case 'apple': console.log('i like apples') break; default: console.log('i don't like food); }
for key in object subject
for (key in Object){
console.log(key);
}
npm
node package manager
higher order objects
objects
array
functions/methods
core library
core library
Math Array String Number Function
some objects
objects array functions Math Array String Number Function
where does javascript get executed
browser or node
parameters vs arguments
when you define - parameters when you receive - arguments function myFunction(parm1, parm2) - formal parameters function myFunction(2,3) - receiving arguments
javascript arguments always optional?
yes
Argument Evaluation
- there are no datatypes for formal parameters
- there is no type-checking for passed arguments
- argument length is never compared to formal parameteres and thus will never throw an argument miss match
- any missing arguments (fewer than the formal params), no error, but it will receive ‘undefined’ for the named params.
- extra arguments are simply appended to the _arguments_object.
.map example !!
function length_map(arr){ var L = arr.map(function(el){ return el.length; }); return L; };
Dry
dont repeat yourself
javascript only has functional scope
javascript only has functional scope
mdn constructor functions
look up documentation
constructor function metaphore
like a cookie cutter, but can make different things