Skip to content

Commit

Permalink
Added Term snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Schafer authored and Corey Schafer committed Mar 25, 2017
1 parent 47a213b commit 34653e5
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Closure/html_closure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function html_tag(tag) {
function print_tag(text) {
return '<'+tag+'>'+text+'</'+tag+'>'
};
return print_tag
};

h1_tag = html_tag('h1')

console.log(h1_tag('This is a Headline!'))
21 changes: 21 additions & 0 deletions Closure/html_closure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def outer():
x = 10
def inner():
y = 20
inner()
return x + y

my_func = outer

print my_func()

# h1_tag = html_tag('h1')
# print h1_tag

# def html_tag(tag):
# def print_tag(text):
# return '<{0}>{1}</{0}>'.format(tag,text)
# return print_tag

# h1_tag = html_tag('h1')
# print h1_tag('This is a headline!')
11 changes: 11 additions & 0 deletions Combinations-Permutations/comb_perm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import itertools

my_list = [1,2,3]

# combinations = itertools.combinations(my_list, 2)
# for c in combinations:
# print c

permutations = itertools.permutations(my_list, 2)
for p in permutations:
print p
22 changes: 22 additions & 0 deletions Combinations-Permutations/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import itertools

# my_list = [1,2,3,4,5,6]

# combinations = itertools.combinations(my_list, 3)
# permutations = itertools.permutations(my_list, 3)

# print [result for result in combinations if sum(result) == 10]

word = 'sample'
my_letters = 'plmeas'

combinations = itertools.combinations(my_letters, 6)
permutations = itertools.permutations(my_letters, 6)

for p in permutations:
# print p
if ''.join(p) == word:
print 'Match!'
break
else:
print 'No Match!'
14 changes: 14 additions & 0 deletions FC_Functions/fc_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

def html_tag(tag):

def wrap_text(msg):
print('<{0}>{1}</{0}>'.format(tag, msg))

return wrap_text

print_h1 = html_tag('h1')
print_h1('Test Headline!')
print_h1('Another Headline!')

print_p = html_tag('p')
print_p('Test Paragraph!')
6 changes: 6 additions & 0 deletions Idempotence/methods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP METHODS

GET <url>/users/123
PUT
POST
DELETE
15 changes: 15 additions & 0 deletions Idempotence/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# f(x)
# add_ten(num)
def add_ten(num):
return num + 10

# f(f(x)) = f(x)
# f(f(10)) = 30 | f(10) = 20
# print add_ten(add_ten(10))

print abs(abs(abs(-10)))
# abs(-10) == 10
# abs(10) == 10
# abs(10) == 10

a = 10
25 changes: 25 additions & 0 deletions Memoization/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import time

ef_cache = {}

def expensive_func(num):
if num in ef_cache:
return ef_cache[num]

print "Computing {}...".format(num)
time.sleep(1)
result = num*num
ef_cache[num] = result
return result

result = expensive_func(4)
print result

result = expensive_func(10)
print result

result = expensive_func(4)
print result

result = expensive_func(10)
print result
6 changes: 6 additions & 0 deletions Mutable/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

print 'Address of a is: {}'.format(id(a))

# a[0] = ''
# print a
# print 'Address of a is: {}'.format(id(a))
14 changes: 14 additions & 0 deletions Mutable/concat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam']

output = '<ul>\n'

for employee in employees:
output += '\t<li>{}</li>\n'.format(employee)
print 'Address of output is {}'.format(id(output))

output += '</ul>'

print output

print '\n'
8 changes: 8 additions & 0 deletions Mutable/mutable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

a = [1,2,3,4,5]
print a
print 'Address of a is: {}'.format(id(a))

a[0] = 6
print a
print 'Address of a is: {}'.format(id(a))
9 changes: 9 additions & 0 deletions String Interpolation/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = 'Corey'
age = 28

# greeting = 'My name is ' + name + ' and I am ' + str(age) + ' years old'

greeting = 'I am {age} years old and my name is {name}'.format(name=name, age=age)

print greeting

0 comments on commit 34653e5

Please sign in to comment.