Skip to content

Instantly share code, notes, and snippets.

View mehd-io's full-sized avatar
🎥
Coding as much as recording

Mehdi OUAZZA mehd-io

🎥
Coding as much as recording
View GitHub Profile
@mehd-io
mehd-io / slack_failed_task.md
Last active February 25, 2019 10:28
Airflow - proper Slack notifications

Define the custom function in the dag :

sc = SlackClient(my_slack_token)

def slack_failed_task(contextDictionary, **kwargs):
        base_url = mybasedUrl
        task_instance = contextDictionary.get('task_instance')
        log_url = '{task_instance.log_url}'.format(**locals())
 failed_alert = sc.api_call('chat.postMessage',
# List hadoop conf while running a pyspark job
hadoopConf = {}
iterator = sc._jsc.hadoopConfiguration().iterator()
while iterator.hasNext():
prop = iterator.next()
hadoopConf[prop.getKey()] = prop.getValue()
for item in sorted(hadoopConf.items()):
@mehd-io
mehd-io / medium-devcontainer-devcontainer.json
Created January 8, 2021 09:45
medium-devcontainer-devcontainer.json
{
"name": "Python 3.8",
"build": {
"dockerfile": "../docker/dev.Dockerfile",
"context": "..",
// Update 'VARIANT' to pick a Python version. Rebuild the container
// if it already exists to update. Available variants: 3, 3.6, 3.7, 3.8
"args": { "VARIANT": "3.8" }
},
@mehd-io
mehd-io / version.sh
Created November 22, 2021 11:01
medium-python-api-boilerplate managing version of dockerfile
#!/bin/bash
# Simple bash script to generate version based on hash of files or git command
ROOT=$(git rev-parse --show-toplevel)
OS=$(uname -s)
if [ "$OS" = "Linux" ]; then
md5_cmd="md5sum
elif [ "$OS" = "Darwin" ]; then
md5_cmd="md5 -r"
@mehd-io
mehd-io / Makefile
Created November 22, 2021 11:11
medium-python-api-boilerplate Make target get-img
get-img:
@echo 🐳 $@
@if [ "$$DOCKER_LAYER" != "base" ]; then\
echo 🔨 Pulling/Building base image first...; \
$(MAKE) pull-img DOCKER_LAYER=base || $(MAKE) _build-img DOCKER_LAYER=base;\
fi;\
$(MAKE) pull-img || $(MAKE) _build-img
@if [ "$$PUSH_IMAGE" = "true" ]; then\
echo ✨ Pushing the images to docker registry...; \
$(MAKE) push-img DOCKER_LAYER=base; \
@mehd-io
mehd-io / build.yml
Created November 22, 2021 11:32
medium-python-api-boilerplate Github Actions snippet
- name: Prepare CI image
run: |
make get-img DOCKER_LAYER=dev PUSH_IMAGE=true
- name: Test
run: |
make test
- name: Build & Push app image
run: |
@mehd-io
mehd-io / test_cloud_run.py
Created May 24, 2022 18:24
medium-tftest-infra
import pytest
import tftest
from pathlib import Path
@pytest.fixture
def plan():
file_path = Path(__file__).resolve()
base_dir = file_path.parent.parent.parent.absolute()
tf = tftest.TerraformTest(tfdir="terraform", basedir=base_dir)
@mehd-io
mehd-io / test_hello.py
Created May 24, 2022 18:25
medium-tftest-api-hello
import json
import pytest
from google.auth.transport.requests import AuthorizedSession
from .cloud_run_client import request_wrapper
@pytest.mark.integration
def test_health_check(auth_session: AuthorizedSession):
@mehd-io
mehd-io / conftest.py
Last active May 24, 2022 18:32
medium-tftest-api-conftest
from pathlib import Path
import pytest
import tftest
from google.auth.transport.requests import AuthorizedSession
from .cloud_run_client import (
get_auth_session,
get_service_account_file_path,
get_token_credentials_from_service_account,
@mehd-io
mehd-io / csv_to_parquet.sh
Created March 21, 2023 16:23
Convert CSV to Parquet using DuckDB CLI
#!/bin/bash
# You can put this in your .bashrc or .zshrc
function csv_to_parquet() {
file_path="$1"
duckdb -c "COPY (SELECT * FROM read_csv_auto('$file_path')) TO '${file_path%.*}.parquet' (FORMAT PARQUET);"
}