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", |
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 KafkaProducer, TopicPartition | |
from kafka.partitioner import RoundRobinPartitioner | |
# given that topic `topic` has at least 2 partitions | |
partitioner = RoundRobinPartitioner(partitions=[ | |
TopicPartition(topic='topic', partition=0), | |
TopicPartition(topic='topic', partition=1) |
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.coordinator.assignors.roundrobin import RoundRobinPartitionAssignor | |
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')), |
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 KafkaProducer | |
producer = KafkaProducer(bootstrap_servers=['0.0.0.0:9092'], | |
key_serializer=lambda m: m.encode('utf8'), | |
value_serializer=lambda m: json.dumps(m).encode('utf8')) | |
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", |
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
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
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
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, 2: 1} | |
def fibonacci1(n: int) -> int: | |
try: |
OlderNewer