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
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: |
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 | |
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 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", |
OlderNewer