Skip to content

Instantly share code, notes, and snippets.

View onelharrison's full-sized avatar

Onel Harrison onelharrison

View GitHub Profile
@onelharrison
onelharrison / pandas_write_to_s3_using_s3fs.py
Last active May 10, 2022 01:23
Demo script for writing a pandas data frame to a CSV file on S3 using s3fs-supported pandas APIs
"""
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")
@onelharrison
onelharrison / pandas_read_from_s3_using_s3fs.py
Last active February 20, 2021 23:41
Demo script for reading a CSV file from S3 into a pandas data frame using s3fs-supported pandas APIs
"""
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")
@onelharrison
onelharrison / pandas_write_to_s3_using_boto3.py
Last active August 19, 2021 03:16
Demo script for writing a pandas data frame to a CSV file on S3 using the boto3 library
"""
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
@onelharrison
onelharrison / pandas_read_from_s3_using_boto3.py
Last active April 28, 2021 01:11
Demo script for reading a CSV file from S3 into a pandas data frame using the boto3 library
"""
Demo script for reading a CSV file from S3 into a pandas data frame using the boto3 library
"""
import os
import boto3
import pandas as pd
"""
The following code explores the presentation of contacts
in an on-screen phone book in which a contact's
first name xor last name may be missing and contacts can
be sorted by first name xor last name.
A true sort by first name and last name is implemented as well as
correspending sort procedures with a presentation bias. In effect,
the presentation bias makes the contacts in the on-screen phone book
appear to be sorted by their intended sort key but in really this may
@onelharrison
onelharrison / extract_employee_record.py
Last active December 19, 2020 07:31
Extract function for employee record
import time
from dataclasses import dataclass
from typing import Optional
@dataclass
class Employee:
name: str
age: Optional[int] = None
job_title: str
@onelharrison
onelharrison / extract_medium_story.py
Last active December 19, 2020 19:23
Extract function for medium story data
import time
def extract_medium_story(story):
medium_story = MediumStory()
medium_story.title = story["title"]
medium_story.description = story["description"]
medium_story.body = story["body"]
medium_story.published_at = story["published_at"]
# notice in the example data that
@onelharrison
onelharrison / medium_story_data.py
Created December 19, 2020 03:22
Medium story data
from dataclasses import dataclass
from typing import Optional
@dataclass
class MediumStory:
title: str
description: str
body: str
published_at: int
featured_image_url: Optional[str] = None
@onelharrison
onelharrison / dig.py
Last active January 8, 2021 09:09
Implementation of a dig function in Python
from functools import reduce
def dig(collection, *keys, default=None):
"""Get values from a potentially nested collection without raising errors"""
return reduce(lambda x, y: safe_get(x, y, default), keys, collection)
@onelharrison
onelharrison / safe_get.py
Created December 17, 2020 22:43
Implementation of a safe get function in Python
def safe_get(collection, key, default=None):
"""Get values from a collection without raising errors"""
try:
return collection.get(key, default)
except TypeError:
pass
try:
return collection[key]