Skip to content

Instantly share code, notes, and snippets.

View Menziess's full-sized avatar

Stefan Schenk Menziess

View GitHub Profile
@Menziess
Menziess / Python base64 encode decode
Last active December 25, 2017 23:22
Python base64 encoding decoding
import base64
path = "image_path.png"
encoded_path = "encoded.txt"
decoded_path = "image_restored.png"
with open(path, 'rb') as file:
data = base64.encodestring(file.read())
with open(encoded_path, "wb") as txt:
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
@Menziess
Menziess / new.sh
Last active November 11, 2018 21:47
Create basic python project quickly.
#!/bin/bash
GREEN='\033[1;32m'
WHITE='\033[0m'
EDITORCONFIG='https://gist.githubusercontent.com/Menziess/97ce53ea86d70e4e95eef6097ea40a72/raw/d0780eba0$
SETTINGS_JSON='https://gist.githubusercontent.com/Menziess/dc3d46c4c7743c08626ea2d325d313a3/raw/05411512$
if [ $# -eq 0 ]
then
echo "Please provide a new project name" && exit 1
name hp attack attack_spd attack_type role
1 Abathur 685 26 1.43 Melee Specialist
2 Anub'arak 1926 99 1 Melee Warrior
3 Artanis 2335 111 1 Melee Warrior
4 Arthas 2382 99 1 Melee Warrior
5 Azmodan 2738 85 1 Ranged Specialist
6 Brightwing 1470 85 1.11 Ranged Support
7 Chen 2556 84 1.11 Melee Warrior
8 Cho 3528 120 0.91 Melee Warrior
9 Dehaka 2434 110 1.11 Melee Warrior
@Menziess
Menziess / solution.py
Created February 11, 2019 11:48
Parquet data source does not support struct<some_field:null> data type.;
"""
The solution is to make sure that structs in the DataFrame schema are not of NullType.
"""
def replace_nulls_struct_fields(df):
"""
Convert NullType fields in structs.
"""
old_schema = df.schema
new_schema = old_schema.fromJson(
@Menziess
Menziess / logging_example.py
Created September 4, 2019 11:27
Setting basic config for logging.
# Specify format for logging
format = '%(asctime)s - %(message)s'
# Set logging config
logging.basicConfig(stream=sys.stdout,
level=logging.INFO,
format=format)
#!/bin/bash
#
# Usage: curl https://pyenv.run | bash
#
# For more info, visit: https://raw.githubusercontent.com/pyenv/pyenv-installer
#
set -e
echo "> Prechecks"
if [[ -z "$http_proxy" ]]; then
# Databricks notebook source
dbutils.widgets.removeAll()
def mount(source, mount_point, extra_configs):
try:
dbutils.fs.mount(
source=source,
mount_point=mount_point,
extra_configs=extra_configs)
dbutils.widgets.removeAll()
def deep_ls(path: str, max_depth=1, reverse=False, key=None, keep_hidden=False):
"""List all files in base path recursively.
List all files and folders in specified path and subfolders within maximum recursion depth.
Parameters
----------
path : str
The path of the folder from which files are listed
max_depth : int
@Menziess
Menziess / cdc.py
Created March 29, 2020 20:12
Change Data Capture
from pyspark.sql import DataFrame, Window
def change_data_capture(
df: DataFrame,
partition_col,
valid_from_col,
valid_to_col,
capture_columns=[]
):