Skip to content

Commit 34653e5

Browse files
Corey SchaferCorey Schafer
Corey Schafer
authored and
Corey Schafer
committed
Added Term snippets
1 parent 47a213b commit 34653e5

File tree

12 files changed

+161
-0
lines changed

12 files changed

+161
-0
lines changed

Closure/html_closure.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function html_tag(tag) {
2+
function print_tag(text) {
3+
return '<'+tag+'>'+text+'</'+tag+'>'
4+
};
5+
return print_tag
6+
};
7+
8+
h1_tag = html_tag('h1')
9+
10+
console.log(h1_tag('This is a Headline!'))

Closure/html_closure.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def outer():
2+
x = 10
3+
def inner():
4+
y = 20
5+
inner()
6+
return x + y
7+
8+
my_func = outer
9+
10+
print my_func()
11+
12+
# h1_tag = html_tag('h1')
13+
# print h1_tag
14+
15+
# def html_tag(tag):
16+
# def print_tag(text):
17+
# return '<{0}>{1}</{0}>'.format(tag,text)
18+
# return print_tag
19+
20+
# h1_tag = html_tag('h1')
21+
# print h1_tag('This is a headline!')
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import itertools
2+
3+
my_list = [1,2,3]
4+
5+
# combinations = itertools.combinations(my_list, 2)
6+
# for c in combinations:
7+
# print c
8+
9+
permutations = itertools.permutations(my_list, 2)
10+
for p in permutations:
11+
print p

Combinations-Permutations/examples.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import itertools
2+
3+
# my_list = [1,2,3,4,5,6]
4+
5+
# combinations = itertools.combinations(my_list, 3)
6+
# permutations = itertools.permutations(my_list, 3)
7+
8+
# print [result for result in combinations if sum(result) == 10]
9+
10+
word = 'sample'
11+
my_letters = 'plmeas'
12+
13+
combinations = itertools.combinations(my_letters, 6)
14+
permutations = itertools.permutations(my_letters, 6)
15+
16+
for p in permutations:
17+
# print p
18+
if ''.join(p) == word:
19+
print 'Match!'
20+
break
21+
else:
22+
print 'No Match!'

FC_Functions/fc_functions.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
def html_tag(tag):
3+
4+
def wrap_text(msg):
5+
print('<{0}>{1}</{0}>'.format(tag, msg))
6+
7+
return wrap_text
8+
9+
print_h1 = html_tag('h1')
10+
print_h1('Test Headline!')
11+
print_h1('Another Headline!')
12+
13+
print_p = html_tag('p')
14+
print_p('Test Paragraph!')

Idempotence/methods.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP METHODS
2+
3+
GET <url>/users/123
4+
PUT
5+
POST
6+
DELETE

Idempotence/test.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# f(x)
2+
# add_ten(num)
3+
def add_ten(num):
4+
return num + 10
5+
6+
# f(f(x)) = f(x)
7+
# f(f(10)) = 30 | f(10) = 20
8+
# print add_ten(add_ten(10))
9+
10+
print abs(abs(abs(-10)))
11+
# abs(-10) == 10
12+
# abs(10) == 10
13+
# abs(10) == 10
14+
15+
a = 10

Memoization/sample.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import time
2+
3+
ef_cache = {}
4+
5+
def expensive_func(num):
6+
if num in ef_cache:
7+
return ef_cache[num]
8+
9+
print "Computing {}...".format(num)
10+
time.sleep(1)
11+
result = num*num
12+
ef_cache[num] = result
13+
return result
14+
15+
result = expensive_func(4)
16+
print result
17+
18+
result = expensive_func(10)
19+
print result
20+
21+
result = expensive_func(4)
22+
print result
23+
24+
result = expensive_func(10)
25+
print result

Mutable/code.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
print 'Address of a is: {}'.format(id(a))
3+
4+
# a[0] = ''
5+
# print a
6+
# print 'Address of a is: {}'.format(id(a))

Mutable/concat.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam']
3+
4+
output = '<ul>\n'
5+
6+
for employee in employees:
7+
output += '\t<li>{}</li>\n'.format(employee)
8+
print 'Address of output is {}'.format(id(output))
9+
10+
output += '</ul>'
11+
12+
print output
13+
14+
print '\n'

Mutable/mutable.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
a = [1,2,3,4,5]
3+
print a
4+
print 'Address of a is: {}'.format(id(a))
5+
6+
a[0] = 6
7+
print a
8+
print 'Address of a is: {}'.format(id(a))

String Interpolation/test.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = 'Corey'
2+
age = 28
3+
4+
# greeting = 'My name is ' + name + ' and I am ' + str(age) + ' years old'
5+
6+
greeting = 'I am {age} years old and my name is {name}'.format(name=name, age=age)
7+
8+
print greeting
9+

0 commit comments

Comments
 (0)