This file contains hidden or 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
from concurrent.futures import ThreadPoolExecutor | |
# create our url list from targeted hosts and paths | |
hosts = ['http://localhost/', 'http://example.com/'] | |
paths = ['robots.txt', 'does_not_exist.txt'] | |
urls = [host + path for host in hosts for path in paths] | |
# via list comprehension, urls now contains: | |
# [ | |
# 'http://localhost/robots.txt', | |
# 'http://localhost/does_not_exist.txt', |
This file contains hidden or 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
import functools | |
print = functools.partial(print, flush=True) | |
# request a url and return a (url, status code) tuple | |
def request(url): | |
try: | |
response = http.request('GET', url) | |
print(url, response.status) |
This file contains hidden or 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
# configuration | |
THREADS = 10 | |
TIMEOUT = 15 | |
RETRIES = 1 | |
REDIRECTS = 0 | |
# init our timeout/retry objects | |
timeout = urllib3.util.Timeout(connect=TIMEOUT, read=TIMEOUT) | |
retries = urllib3.util.Retry(connect=RETRIES, read=RETRIES, redirect=REDIRECTS) |
This file contains hidden or 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
for (x, y, z) in itertools.combinations_with_replacement(range(3), 3): | |
print(x, y, z) | |
# outputs: | |
# 0 0 0 | |
# 0 0 1 | |
# 0 0 2 | |
# 0 1 1 | |
# 0 1 2 | |
# 0 2 2 |
This file contains hidden or 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
for c in itertools.combinations_with_replacement([1, 2, 3], 2): | |
print(c) | |
# outputs: | |
# (1, 1) | |
# (1, 2) | |
# (1, 3) | |
# (2, 2) | |
# (2, 3) | |
# (3, 3) |
This file contains hidden or 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
# for length of 3 | |
for c in itertools.combinations([1, 2, 3], 3): | |
print(c) | |
# outputs: | |
# (1, 2, 3) | |
# ...since there is only one 3-length combination of [1, 2, 3] | |
# for length of 2 | |
for c in itertools.combinations([1, 2, 3], 2): |
This file contains hidden or 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
for p in itertools.permutations('ABC'): | |
print(p) | |
# outputs: | |
# ('A', 'B', 'C') | |
# ('A', 'C', 'B') | |
# ('B', 'A', 'C') | |
# ('B', 'C', 'A') | |
# ('C', 'A', 'B') | |
# ('C', 'B', 'A') |
This file contains hidden or 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
for p in itertools.permutations([1, 2, 3], 2): | |
print(p) | |
# outputs: | |
# (1, 2) | |
# (1, 3) | |
# (2, 1) | |
# (2, 3) | |
# (3, 1) | |
# (3, 2) |
This file contains hidden or 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
for p in itertools.permutations([1, 2, 3]): | |
print(p) | |
# outputs: | |
# (1, 2, 3) | |
# (1, 3, 2) | |
# (2, 1, 3) | |
# (2, 3, 1) | |
# (3, 1, 2) | |
# (3, 2, 1) |
This file contains hidden or 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
<?php | |
function heart($v) { | |
$heart = ''; //string representing our heart | |
$n = intdiv($v, 2); //heart number | |
//1st row: spacing, top of the heart, cleft, top of the heart, spacing | |
$heart = str_repeat(' ', $n) . str_repeat('*', $v) . str_repeat(' ', $v-2) . str_repeat('*', $v) . "\n"; | |
//expanding section |
NewerOlder