Skip to content

Commit 268f0e4

Browse files
committed
added notes to student directory
1 parent 16f4704 commit 268f0e4

2 files changed

Lines changed: 467 additions & 0 deletions

File tree

Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,349 @@
1+
############################## SESSION01 ##############################
2+
3+
#IPYTHON:
4+
"""
5+
-typing "?" after any object gives you more information
6+
-supports tap completion
7+
"""
8+
9+
10+
#VALUES AND TYPES:
11+
"""
12+
values: pieces of unanmed data
13+
-all values are objects
14+
-dir(42) shows you all the different things the object can do
15+
16+
types: every value belongs to a type.
17+
-numbers
18+
-floating point
19+
-intergers
20+
-text
21+
-boolean
22+
-none
23+
-string
24+
-dict
25+
-list
26+
-tuple
27+
"""
28+
29+
30+
#STATEMENTS VS. EXPRESSIONS
31+
"""
32+
statements: statments do not return a value, but may contain an experssion
33+
"""
34+
#exmaples
35+
line_count = 42 # 42 is actually and expression, but this line is a statment
36+
print "this" # print doesn't return a value
37+
38+
"""
39+
expressions: evaluating an expression results in a value
40+
- expressions are made up of values and operators
41+
"""
42+
#examples:
43+
3 + 7 # result is 7
44+
45+
46+
#PRINT STATEMENT
47+
"""
48+
using the comma in a print statement allows you to suppress the newline
49+
"""
50+
#example
51+
print "the vaue is", 45
52+
53+
54+
#SYMBOLS
55+
"""
56+
symbols: how we give names to values
57+
-symbols can contain any number of sundersores, letters, nd numbers
58+
-a symbol is bound to a value with the assignment operator
59+
-in most languages, symbols are called variables
60+
-in most languages, a symbol is a place in memory that can store values
61+
-this is NOT what a symbol in python is
62+
-a symbol can be bound to a value, but doesn't have anything to do with the
63+
location in memory
64+
"""
65+
#example
66+
a = 5
67+
a = b # both a and b are referring to the same 5
68+
69+
# you can assign multilple symbols at the same time
70+
i,j = 5,4
71+
i,j = j,i # this switches the value of j and i
72+
73+
74+
#TEXT SLICING:
75+
"""
76+
+---+---+---+---+---+---+
77+
| P | y | t | h | o | n |
78+
+---+---+---+---+---+---+
79+
0 1 2 3 4 5 6
80+
-6 -5 -4 -3 -2 -1
81+
"""
82+
83+
############################## SESSION02 ##############################
84+
85+
86+
#FUNCTIONS:
87+
"""
88+
-begins with "def". this means everything folloiwng is the definiton of the function.
89+
-when you execute a fucntion, it creates a fuction object
90+
-the name of the fucntion is now the symbol for the name
91+
"""
92+
#example
93+
def name (x, y):
94+
return x * y
95+
96+
97+
#OPERATORS:
98+
"""
99+
// <-- this will always ignore the interger
100+
"""
101+
102+
103+
#GIT
104+
"""
105+
-git is a graph. A graph is something with "states" and "places" with paths between them.
106+
For example your code will have many versions ("states") with points between them.
107+
-each place in the history of git has a name that identifies it (called a "hash")
108+
-there are labels that can point to the different places in time.
109+
- "Head" is the label at the current point in time that you're looking at.
110+
- "master" is the name that git auomatically gives to the first branch in a repository
111+
- "branch" is a different version of the original master branch
112+
-creating branches allows you to submit just the specific homework you changed in
113+
your pull request
114+
-when you create your pull request, you want to make sure you're comparing your
115+
branch to the master to PCE's repository
116+
-you start with a local database and then pull to the web
117+
-you always start locally; this creates a ".git" folder
118+
119+
-git setup:
120+
-have gui
121+
-have command line
122+
-have github account
123+
124+
-git settings:
125+
-system: settings for your system
126+
-global: settings for your user account
127+
-local: highest prescedence; settings specific for your local project
128+
129+
-initalizing a repository:
130+
-this can happen locally or in the cloud at github.com
131+
-locally:
132+
-"git init" turns an existing project into a git project
133+
-"git init <project_name> creates a new project as a git project
134+
-in the cloud:
135+
-look for "New Repository" and create a repository
136+
-README: this tell others about the project
137+
-.gitignore: this tells git which projects to ignore
138+
139+
-committing:
140+
-changes are commits
141+
-local commits:
142+
-"git status" tells you with files should be committed
143+
-"git add" adds files to the staging area; the purpose of the staging
144+
area is to give users the ability to choose which changes are part of
145+
which commit.
146+
-"git commit -m <message>" will commit the changes; each commit should
147+
be part of a story
148+
-github.com commits:
149+
-use the edit button on the website
150+
-this is good for making simple changes to text files
151+
152+
-diff:
153+
-what changes have you made to your code that hasn't been staged?
154+
-"git diff": this tells you how your working tree (i.e., files) differs
155+
from the staging area
156+
-"git diff --staged" this tells you how your staging area is different
157+
from the lastest commit in history
158+
-"git diff HEAD" how your working tree compares to the HEAD commit
159+
-"git diff --word-diff" easier to read diffs
160+
-"git diff --color-words" easier to read diffs
161+
-"git diff --stat" just tells you the files that have changed
162+
163+
-log:
164+
-"git log" shows all the commits to the repository; new on top, oldest at
165+
the bottom
166+
-"git log --oneline" shows a summary of all the commits
167+
-"git log --stat" shows the commit message with the files for each commit
168+
-"git log --patch" shows the diff between all the commits
169+
-"git log --graph --all --decorate --oneline"
170+
-you can use all of these options together
171+
172+
-removing files:
173+
-"git rm" removes the file from the directory and stages the removal
174+
-"git add -u ." goes through the working tree and stages all deleted files;
175+
the "." means that git will look at all directories in the working tree
176+
-"git rm --cahced <filename>" removes from the git repository but not the
177+
file system
178+
179+
-moved files:
180+
-"git mv <old_path> <new_path>" this will move a file; if you don't use this
181+
command and do the move using the file system, git will think you deleted
182+
then added a file. you can fix this by deleted the old file "git rm <file>"
183+
and adding the new file "git add <file".
184+
-"git add -A ." this finds all the new files and old files and tells git that
185+
they have been moved
186+
187+
-ignore:
188+
-to ignore files, create a ".gitignore" file in the root of the project
189+
-e.g., "touch .gitignore" "git add .gitignore" "git commit -m <message>"
190+
-you can put file names, directories, or wildcard character (i.e., "*")
191+
-you can also have a .gitignore file in a sub directory, which takes presedence
192+
-"git ls-files --others --ignored --exclude-standard" shows all the excluded
193+
files
194+
195+
-branch:
196+
-new features and bug fixes should be done on a new branch
197+
-why use branches?
198+
-the master branch should be a representation of "production"
199+
-"git branch <name>" creates a new branch
200+
-"git branch -d <name>" deletes a branch
201+
-you cannot delete the branch you are currently on
202+
-"git checkout <name>"
203+
-this moves changes in staging area and working directory to new branch
204+
-can't switch to a new branch when moving to that branch affects staging
205+
files or working tree files
206+
-you might see different files when you are on different branches; this
207+
is fine and how git works
208+
-"git branch": lists all the current branches (* is the branch you're on)
209+
-"git branch -v": lists all the current branches with last commit
210+
-"git branch --merged": lists the branches that are already merged into the
211+
branch you're on. branches without a "*" in front are generally fine to delete
212+
-"git branch --no-merged": lists the branches that contain work that hasn't
213+
been merged in
214+
215+
-more branching notes:
216+
-a branch is a movable pointer to one of your commits
217+
-when you first start a git repository, the default branch is named master
218+
and it points to the last commit you made
219+
-creating a new branch creates a new pointer for you to move around; the
220+
default location when you create a new branch is the commit you're currently
221+
on
222+
-how does git know what branch you're on? It keeps a special pointer named
223+
HEAD. HEAD is a pointer to the local branch you're currently on.
224+
-"git checkout" lets you switch to a new branch. This moves HEAD to to point
225+
to the testing branch
226+
-when you make another commit after switching to a new branch, the master
227+
pointer stays where it is and HEAD and the branch pointer move forward
228+
-when switching branches, it's best practice to commit all your changes.
229+
this is because git won't let you switch branches if your working tree has
230+
uncommitted changes the conflict with the branch you're checking out
231+
-when there are conflicts, git will pause the merge. run "git status" to see
232+
which files were not merged. you'll have to manually change the file with
233+
issues. to reslove the conflicts, add the file to the staging area. finally,
234+
commit to finalize the merge
235+
236+
-remote braches:
237+
-remote branches: references to the state of brances on your remote repositories.
238+
they are local branches that can't be moved. instead, they're moved automatically
239+
when you do any network communication. remote branches act as bookmaks to
240+
remind you where the branches on your remote repositories were the last time
241+
you connected to them
242+
-<remote>/<branch>: this is the form of remote branches. for example, the "master"
243+
branch on the "origin" remote would be "origin/master"
244+
-when you clone a git repository from github, git automatically names it "orgin"
245+
and creates a pointer to the master branch named "origin/master" locally.
246+
-git also gives you your own master branch starting at the same place as
247+
"origin/master"
248+
-the "origin/master" pointer doesn't move as long as you stay out of contact
249+
with the github server
250+
-"git fetch origin": this command will sync your work with the server by fetching
251+
data from the server that you don't have and updates your local working
252+
directory. this will also move "origin/master" to a new location. note,
253+
this does not merge any changes to "origin/master" and your local branches.
254+
-when your fetch brings down new branches, you don't automattically have local,
255+
editable copies of them. you can either:
256+
-"git merge <remote/branch>" to merge the remote branch into your current
257+
working branch
258+
-"git checkout -b <local_branch> <remote/branch>": to create and checkout
259+
a new branch based on the remote branch.
260+
-the second method creates a "tracking" branch:
261+
-tracking branches are local branches that have a direct relationship to
262+
a remote branch. therefore, if you're on a tracking branch and you
263+
type "git push", git automattically knows which branch to push to.
264+
-running "git pull" on a "tracking" branch fetches all the remote references
265+
and automatically merges to the corresponding remote branch
266+
-after cloning a repository, a master branch is created that tracks
267+
origin/master, so "git push" and "git pull" automattically work
268+
-"git checkout --track <remote/branch>" will set up the branch you're on
269+
to track a remote branch
270+
-delete a remote branch with "git push <remote> :<branch>".
271+
-"git push <remote> <branch>": this will push a branch to the github server
272+
273+
-git homework workflow:
274+
"git checkout master" # checkout the local master branch
275+
"git pull upstream master" # fetch/merge class repository into local master
276+
"git push" # push changes from class repository to personal repository
277+
[do work]
278+
"git commit -a" # commit local changes
279+
[add a message]
280+
"git push" # push local changes to personal repository
281+
[make a pull request] # request that changes are merged with class repository
282+
283+
"""
284+
285+
286+
#LOCAL VS. GLOBAL SYMBOLS
287+
"""
288+
-global variables: can be used everywhere
289+
-local variables: are only referenced in the function
290+
"""
291+
292+
293+
#PARAMETERS
294+
"""
295+
- positional parameters; they must be entered in the right
296+
- optional parameters --> fun(x=1)
297+
- once you've provided a keyword argument, you can no longer provide any positional aruguments
298+
"""
299+
300+
301+
302+
# if statments
303+
if a:
304+
print 'a'
305+
elif b: # you don't need elif
306+
print 'b'
307+
elif c:
308+
print 'c'
309+
else: #you don't need else
310+
print 'that was unexpected'
311+
312+
# lists
313+
a_list = [2, 3, 5, 9]
314+
a_list_of_strings = ['this', 'that', 'the', 'other']
315+
316+
# tuples
317+
a_tuple = (1, 2, 3, 4)
318+
319+
# loops
320+
a_list = [2, 3, 5, 9]
321+
322+
for item in a_list:
323+
print item
324+
325+
for item in range(6): # range allows you to loop as much as you want
326+
print '*',
327+
328+
# Comments
329+
330+
def print_multi(x):
331+
332+
print locals()
333+
334+
for i in range(x):
335+
i += 1
336+
if (i % 3 == 0) and (i % 5 ==0):
337+
print 'FizzBuzz'
338+
elif i % 3 == 0:
339+
print 'Fuzz'
340+
elif i % 5 == 0:
341+
print 'Buzz'
342+
else:
343+
print i
344+
345+
import math
346+
347+
def distance(cor1, cor2):
348+
print locals()
349+
return math.sqrt( (cor1[0]-cor2[0])**2 + (cor1[0]-cor2[1])**2 )

0 commit comments

Comments
 (0)