forked from CoreyMSchafer/code_snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Corey Schafer
authored and
Corey Schafer
committed
Mar 25, 2017
1 parent
47a213b
commit 34653e5
Showing
12 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
HTTP METHODS | ||
|
||
GET <url>/users/123 | ||
PUT | ||
POST | ||
DELETE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|