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
file_object = s3_hook.get_key("path/to/key.zip") | |
with NamedTemporaryFile(mode="wb", delete=True) as f: | |
file_object.download_fileobj(f) | |
f.flush() | |
with ZipFile(f.name, "r") as zipfile: | |
with TemporaryDirectory() as temp_dir: | |
zipfile.extractall(path=temp_dir) | |
for _, _, filenames in os.walk(temp_dir): |
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
from airflow import DAG | |
from airflow.operators.docker_operator import DockerOperator | |
dag = DAG(dag_id="example DAG", default_args=default_args) | |
run_task_with_docker = DockerOperator( | |
task_id='run_task_with_docker', | |
# Assuming this image is already pulled |
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
import sys | |
import timeit | |
from functools import lru_cache | |
index = {0: 0, 1: 1, 2: 1} | |
def routine(i: int): | |
try: | |
return index[i] |
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
import sys | |
import timeit | |
index = {0: 0, 1: 1, 2: 1} | |
def routine(i: int): | |
try: | |
return index[i] | |
except KeyError: |
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
import sys | |
import timeit | |
index = {0: 0, 1: 1, 2: 1} | |
def fibonacci1(n: int) -> int: | |
try: |
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
import sys | |
import timeit | |
index = {0: 0, 1: 1} | |
def fibonacci(n: int, m: int = 0, l: int = 1, k: int = 2) -> int: | |
try: | |
return index[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
import sys | |
import timeit | |
index = {0: 0, 1: 1} | |
def fibonacci(n: int) -> int: | |
if n in index: | |
return index[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
def fibonacci(n: int) -> int: | |
if n <= 1: | |
return n | |
return fibonacci(n-1) + fibonacci(n-2) |
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
docker run -p 2181:2181 -p 9092:9092 \ | |
--env ADVERTISED_HOST=0.0.0.0 \ | |
--env ADVERTISED_PORT=9092 \ | |
--env CONSUMER_THREADS=2 \ | |
--env NUM_PARTITIONS=2 \ | |
--env AUTO_CREATE_TOPICS \ | |
--env TOPICS=topic \ | |
--env ZK_CONNECT=kafka7zookeeper:2181/root/path \ | |
--env GROUP_ID=1 \ | |
-d --name kafka spotify/kafkaproxy |
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
import json | |
from kafka import KafkaConsumer | |
from kafka.structs import OffsetAndMetadata, TopicPartition | |
consumer = KafkaConsumer(bootstrap_servers=['0.0.0.0:9092'], | |
key_deserializer=lambda m: m.decode('utf8'), | |
value_deserializer=lambda m: json.loads(m.decode('utf8')), | |
auto_offset_reset="earliest", |