Skip to content

Instantly share code, notes, and snippets.

View Zifah's full-sized avatar

Hafiz Adewuyi Zifah

View GitHub Profile
@Zifah
Zifah / databricks_write_to_azure_blob.py
Created February 9, 2019 21:26
Write data directly to an Azure blob storage container from an Azure Databricks notebook
# Configure blob storage account access key globally
spark.conf.set(
"fs.azure.account.key.%s.blob.core.windows.net" % storage_name,
sas_key)
output_container_path = "wasbs://%s@%s.blob.core.windows.net" % (output_container_name, storage_name)
output_blob_folder = "%s/wrangled_data_folder" % output_container_path
# write the dataframe as a single file to blob storage
(dataframe
@Zifah
Zifah / write_dataframe_to_blob.py
Last active February 9, 2019 20:28
Write a Spark dataframe to an Azure blob storage container mounted on Databricks filesystem
mount_name = "/mnt/financial_survey_data"
write_path = "%s/wrangled_data_folder" % mount_name
(dataframe
# .coalesce(1) # uncomment this line to ensure that the data is written to just one file
.write
.option("header", "true")
.mode("overwrite") # overwrite any pre-existing data at the path that we're writing to
.csv(write_path)
)
@Zifah
Zifah / mounting_to_databricks.py
Last active February 9, 2019 20:08
Mounting an Azure blob storage container to Azure databricks file system
container_name = '{azure-blob-container-name}'
storage_name = '{azure-blob-storage-instance-name}'
mount_name = '/mnt/financial_survey_data' # This path can be used to access the contents of the blob container
sas_key = '{access-key-from-azure-portal}'
dbutils.fs.mount(
source = "wasbs://%s@%s.blob.core.windows.net" % (container_name, storage_name),
mount_point = mount_name,
extra_configs = {"fs.azure.sas.%s.%s.blob.core.windows.net" % (container_name, storage_name) : sas_key })
@Zifah
Zifah / ExtractParamsAttribute.cs
Last active March 31, 2018 22:36
A .NET MVC filter attribute which can parse parameters out of a USSD short-code using regular expression
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using System.Text.RegularExpressions;
namespace Ussd.Application.Filters
{