Skip to content

Instantly share code, notes, and snippets.

View anteverse's full-sized avatar
🐍

Aurelien Didier anteverse

🐍
View GitHub Profile
@anteverse
anteverse / old_downloader.py
Created October 30, 2021 16:43
The old method for the upload of all extracted files from an archive
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):
@anteverse
anteverse / docker_operator_example.py
Created February 13, 2020 13:22
DockerOperator illustration
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
@anteverse
anteverse / fibonacci5.py
Created July 21, 2018 23:12
Full logarithmic version with LRU cache
import sys
import timeit
from functools import lru_cache
index = {0: 0, 1: 1, 2: 1}
def routine(i: int):
try:
return index[i]
@anteverse
anteverse / fibonacci4.py
Created July 21, 2018 22:02
Fully log n implementation
import sys
import timeit
index = {0: 0, 1: 1, 2: 1}
def routine(i: int):
try:
return index[i]
except KeyError:
@anteverse
anteverse / fibonacci3.py
Created July 21, 2018 21:53
Dividing ranks per 2
import sys
import timeit
index = {0: 0, 1: 1, 2: 1}
def fibonacci1(n: int) -> int:
try:
@anteverse
anteverse / fibonacci2.py
Created July 21, 2018 20:27
almost linear version
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]
@anteverse
anteverse / fibonacci1.py
Last active July 21, 2018 20:01
first indexed implementation
import sys
import timeit
index = {0: 0, 1: 1}
def fibonacci(n: int) -> int:
if n in index:
return index[n]
@anteverse
anteverse / fibonacci0.py
Created July 21, 2018 19:34
First non-performant implementation
def fibonacci(n: int) -> int:
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
@anteverse
anteverse / kafka.sh
Created April 12, 2018 22:40
Run a simple Kafka server
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
@anteverse
anteverse / consumed_with_kill_switch.py
Created April 3, 2018 09:16
Kafka consumer that can be killed
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",