This file contains hidden or 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
""" | |
Demo script for writing a pandas data frame to a CSV file on S3 using the boto3 library | |
""" | |
import io | |
import os | |
import boto3 | |
import pandas as pd |
This file contains hidden or 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
""" | |
Demo script for reading a CSV file from S3 into a pandas data frame using s3fs-supported pandas | |
APIs | |
""" | |
import os | |
import pandas as pd | |
AWS_S3_BUCKET = os.getenv("AWS_S3_BUCKET") |
This file contains hidden or 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
""" | |
Demo script for writing a pandas data frame to a CSV file on S3 using s3fs-supported pandas APIs | |
""" | |
import os | |
import pandas as pd | |
AWS_S3_BUCKET = os.getenv("AWS_S3_BUCKET") | |
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID") |
This file contains hidden or 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 redis | |
r = redis.Redis(host='localhost', port=6379, db=1) | |
r.set('hello', 'world') # True | |
value = r.get('hello') | |
print(value) # b'world' | |
r.delete('hello') # True |
This file contains hidden or 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
#!/usr/bin/env python | |
import logging | |
import operator as op | |
import sys | |
from typing import Any, List, Union | |
logging.getLogger(__name__).setLevel("INFO") | |
supported_operators = {"+": op.add, "-": op.sub, "*": op.mul, "/": op.truediv} |
This file contains hidden or 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 first_name(full_name: str) -> str: | |
"""Extracts and returns the first name from a full name""" | |
return full_name.split(" ")[0] | |
def square(n: int) -> int: | |
"""Returns the square of the given number""" | |
return n ** 2 | |
This file contains hidden or 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 math import floor, sqrt | |
def is_even(num: int) -> bool: | |
"""Returns True if a given number is even, otherwise False""" | |
return num % 2 == 0 | |
def is_prime(num: int) -> bool: | |
"""Returns True if a given number is prime, otherwise False""" |
This file contains hidden or 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 Any, Tuple | |
Pair = Tuple[Any, Any] | |
def pair_first(pair: Pair) -> Any: | |
"""Returns the first item in a given pair""" | |
return pair[0] | |
This file contains hidden or 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 log_before(f): | |
def _wrapper(*args, **kwargs): | |
print("logging before...") | |
f(*args, **kwargs) | |
return _wrapper | |
def log_after(f): | |
def _wrapper(*args, **kwargs): |
This file contains hidden or 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 itertools import chain, combinations | |
from typing import Collection, Iterable, Optional | |
def subsets( | |
collection: Collection, min_size: int = 0, max_size: Optional[int] = None | |
) -> Iterable: | |
"""Produce all the subsets of `collection` with cardinalities between | |
`min_size` and `max_size` (inclusive).""" |