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 logging | |
import os | |
import pandas as pd | |
LOG = logging.getLogger(__name__) | |
def read_dataframe_from_pickle_or_url(url: str, path: str) -> pd.DataFrame: | |
"""Read JSON data from the URL and convert to a pandas dataframe. | |
The dataframe is cached locally at the supplied path. |
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 hello_gist(name): | |
return f"Hello {name}, this code was imported from a gist." |
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 typing import List, Any | |
def only_strings(n): | |
result = [] | |
for i in range(int(n)): | |
result.append(["col1", "col2"]) | |
return result | |
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 asyncio | |
import numpy as np | |
from io import BytesIO | |
from contextlib import closing | |
from aiokafka import AIOKafkaConsumer | |
async def kafka_topic_subscription(topic: str, server: str, fps: str) -> np.ndarray: | |
"""Subscribe to a numpy array from a Kafka topic""" | |
consumer = AIOKafkaConsumer( | |
topic, bootstrap_servers=server, 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 asyncio | |
async def async_counter(stop: int, updates_per_second: int) -> int: | |
"""Asynchronously generates a sequence of numbers up to stop at a rate of updates_per_second.""" | |
for i in range(stop): | |
await asyncio.sleep(1.0 / updates_per_second) | |
yield 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 time | |
def counter(stop: int, updates_per_second: int) -> int: | |
"""Generates a sequence of numbers up to stop at a rate of updates_per_second.""" | |
for i in range(stop): | |
time.sleep(1.0 / updates_per_second) | |
yield i |