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 subprocess | |
# this should work in any directory, whether a git repo or not | |
git_dict = dict( | |
x.split('=') | |
for x in | |
subprocess.check_output( | |
['git','config','--list'] | |
).decode('ascii').strip().split('\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 contextlib | |
import os | |
import tempfile | |
half_lambda_memory = 10**6 * ( | |
int(os.getenv('AWS_LAMBDA_FUNCITON_MEMORY_SIZE', '0')) / 2) | |
@contextlib.contextmanager |
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
#Check the status: | |
sudo service docker status | |
# If there isn’t running: | |
sudo service docker start | |
# And then to auto-start after reboot: | |
sudo systemctl enable docker | |
#Don’t forget to add your ec2-user to the docker group: | |
sudo usermod -aG docker ec2-user | |
# And then reboot or just logoff/login again | |
$ sudo reboot |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
flat_list = [item for sublist in nested_list for item in sublist] | |
# if a list is variable, like [2,3,[2,3],[2,3]], you'll need a function | |
# this creates a generator that will do what you want | |
def flatten(lis): | |
for item in lis: | |
if isinstance(item, list) and not isinstance(item, str): | |
for x in flatten(item): | |
yield x | |
else: |
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
# Pandas settings to include on import | |
import pandas as pd | |
import numpy as np | |
pd.set_option('display.max_rows',1000) | |
pd.set_option('display.max_columns',1000) | |
# Includes commas in outputs > 1,000, and formats as integers if integers | |
# If not integers, formats to two decimal places | |
pd.set_option('display.float_format', lambda x: "{:,.0f}".format(x) if x.is_integer() | |
else "{:,.2f}".format(x)) |
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
.PHONY: clean data lint requirements sync_data_to_s3 sync_data_from_s3 | |
################################################################################# | |
# GLOBALS # | |
################################################################################# | |
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | |
BUCKET = <s3 bucket name> | |
PROFILE = <aws profile name> | |
PROJECT_NAME = <project name> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 pandas as pd | |
import boto3 | |
s3 = boto3.resource('s3') | |
data_file = s3.Object(bucket_name='challenge-1-data-09122019', key='data/wiki_movie_plots_deduped.csv') | |
resp = data_file.get() | |
data = pd.read_csv(resp['Body']) |
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
""" | |
Data access utilities | |
""" | |
from collections.abc import Mapping | |
import os | |
import boto3 | |
import botocore.client | |
class Bucket(Mapping): |
NewerOlder