Skip to content

Instantly share code, notes, and snippets.

View kayehld's full-sized avatar
🙈
emoji statuses - what is this, slack?

Kevin Dawe kayehld

🙈
emoji statuses - what is this, slack?
View GitHub Profile
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',
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)
# 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)
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
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)
# 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):
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')
for p in itertools.permutations([1, 2, 3], 2):
print(p)
# outputs:
# (1, 2)
# (1, 3)
# (2, 1)
# (2, 3)
# (3, 1)
# (3, 2)
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)
@kayehld
kayehld / heart.php
Last active February 8, 2020 22:30
<?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