Skip to content

Instantly share code, notes, and snippets.

View Menziess's full-sized avatar

Stefan Schenk Menziess

View GitHub Profile
function install_tar {
s=$1 # Used for string substitution
if [[ "$1" == *.tar.gz ]]
then
tar -xvzf "$1" | sudo xargs mv -t /usr/local/bin/
elif [[ "$1" == *.tar ]]
then
tar -xvf "$1" | sudo xargs mv -t /usr/local/bin/
else
echo Must have extension: *.tar.gz / *.tar.
@Menziess
Menziess / gist:3c1f99fdfe816af0382bbe4371ca5575
Created October 26, 2021 13:53
Substitute environment variable names with environment variable values in bash/shell (linux)
➜ export LOL=lol
➜ echo "Hello there, ${LOL}" > example.txt
➜ envsubst < example.txt
Hello there, lol
@Menziess
Menziess / Quotes.md
Last active July 17, 2020 12:54
Interesting sayings.

"Most of the Evil in This World Is Done by People with Good Intentions." Ayn Rand "The road to hell is paved with good intentions."

"Power corrupts." The founding fathers

"Those who would give up essential liberty, to purchase a little temporary safety, deserve neither liberty nor safety." Benjamin Franklin (1706-1790)

“If the freedom of speech is taken away then dumb and silent we may be led, like sheep to the slaughter.” George Washington

"I disapprove of what you say, but I will defend to the death your right to say it." Voltaire

@Menziess
Menziess / Makefile
Created June 5, 2020 19:07
Install specific Hugo version script.
HUGO_VERSION=0.68.3
run:
export HUGO_VERSION=$(HUGO_VERSION)
hugo server -FD
install-hugo:
# https://api.github.com/repos/gohugoio/hugo/releases
rm -f hugo*_Linux-64bit.deb
curl -s url -s https://api.github.com/repos/gohugoio/hugo/releases \
@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=[]
):
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
# 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()
#!/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
@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)
@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(