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 sys | |
import logging | |
'''Usage: | |
from database import Database | |
db = Database(attributes) | |
db.connect() | |
sql = "SELECT * FROM TABLE" | |
dataframe = pandas.read_sql(sql, db.connection) |
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
#!/usr/bin/env python3 | |
# Create tables and insert data into SQL Server 2014 from all CSV files in a directory. The process involves: | |
# - Read all CSV files in a directory | |
# - Ensure all headers are the same | |
# - Generate DTS (Data Transformation Service) files for all CSV files | |
# - Execute all .dtsx files to bulk insert the CSV | |
import os |
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
# Install Apache Maven | |
cd /opt | |
wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz | |
tar xzf apache-maven-3.3.9-bin.tar.gz | |
ln -s apache-maven-3.3.9 maven | |
echo 'export M2_HOME=/opt/maven' >> /etc/profile.d/maven.sh | |
echo 'PATH=${M2_HOME}/bin:${PATH}' >> /etc/profile.d/maven.sh | |
source /etc/profile.d/maven.sh |
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 | |
import signal | |
from retrying import retry | |
class Timeout: | |
def __init__(self, seconds=1, error_message='Timeout'): | |
self.seconds = seconds | |
self.error_message = error_message | |
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 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)) |
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
################################################################################ | |
# 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 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 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 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:example-compute@developer.gserviceaccount.com | |
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 |
OlderNewer