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
#!/bin/bash -x | |
# Merge the master branch into the current checked out branch | |
CURRENT=`git branch | grep "*" | awk '{print $2}'` | |
git checkout master | |
git fetch | |
git merge origin/master | |
git checkout ${CURRENT} | |
git merge master ${CURRENT} |
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 boto3 | |
bucket_name = 'my_bucket_name' | |
prefix = 'some/path/' | |
print("Getting list of all folder names in S3 bucket {} under prefix {}".format(bucket_name, prefix)) | |
folders_list = [] | |
client = boto3.client('s3') | |
results = client.list_objects(Bucket=bucket_name, Prefix=prefix, Delimiter='/') | |
for folder in results.get('CommonPrefixes'): |
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 logging | |
import boto3 | |
from botocore.exceptions import ClientError, BotoCoreError | |
import requests | |
from requests import RequestException | |
def get_instance_name(): | |
try: |
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
# Delete all files in bucket | |
BUCKET_NAME=my_bucket | |
gsutil -m rm gs://$BUCKET_NAME/** | |
# Delete bucket | |
gsutil rb -f gs://$BUCKET_NAME |
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
# https://cloud.google.com/kms/docs/iam | |
# Add IAM policy binding to a specific KMS keyring with the cryptoKeyEncrypterDecrypter role | |
KEYRING=my_keyring_name | |
USER_EMAIL=serviceAccount:[email protected] | |
gcloud kms keyrings add-iam-policy-binding $KEYRING --location global --member user:$USER_EMAIL --role roles/cloudkms.cryptoKeyEncrypterDecrypter | |
# Add IAM policy binding to a specific KMS key with the cryptoKeyEncrypterDecrypter role | |
KEY=my_key_name | |
KEYRING=my_keyring_name |
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
# Function to convert python object to Java objects | |
def _to_java_object_rdd(rdd): | |
""" Return a JavaRDD of Object by unpickling | |
It will convert each Python object into Java object by Pyrolite, whenever the | |
RDD is serialized in batch or not. | |
""" | |
rdd = rdd._reserialize(AutoBatchedSerializer(PickleSerializer())) | |
return rdd.ctx._jvm.org.apache.spark.mllib.api.python.SerDe.pythonToJava(rdd._jrdd, True) | |
# Convert DataFrame to an RDD |
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
# Delete all tables within a BigQuery dataset | |
from google.cloud import bigquery | |
bigquery_client = bigquery.Client() | |
bq_dataset = 'my_dataset' | |
dataset_ref = bigquery_client.dataset(bq_dataset) | |
tables = list(bigquery_client.list_dataset_tables(dataset_ref)) | |
for table in tables: | |
bigquery_client.delete_table(table) |
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
################################################################################ | |
# The following demonstrates how to recursively replace specific characters | |
# from within keys of a nested dictionary or JSON object, leaving values as is. | |
################################################################################ | |
# Given the following example dictionary with characters needing to be replaced: | |
example = [ | |
{ | |
"_id": "5ae2821988fc6a16af73aeb0", | |
"index": 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
from google.cloud import storage | |
# Define Google Cloud Storage bucket | |
storage_client = storage.Client() | |
bucket = storage_client.lookup_bucket(bucket_name) | |
if bucket: | |
print("Using bucket '{}'.".format(bucket.name)) | |
else: | |
# Create Google Cloud Storage bucket if it doesn't exist | |
print("Bucket '{}' doesn't exist. Creating bucket...".format(bucket_name)) |