Skip to content

Instantly share code, notes, and snippets.

View TobKed's full-sized avatar

Tobiasz Kędzierski TobKed

View GitHub Profile
@TobKed
TobKed / tag_from_ref.sh
Last active June 19, 2023 10:28
Get docker tag from GITHUB_REF env variable within GitHub Actions
#!/usr/bin/env bash
# Make GITHUB_REF safe for use as docker tag
#
# Examples:
# $ ./tag_from_ref.sh "refs/pull/2/merge" # -> 'pr-2'
# $ ./tag_from_ref.sh "refs/heads/master" # -> 'master'
# $ ./tag_from_ref.sh "refs/heads/feature/branch" # -> 'feature-branch'
# $ ./tag_from_ref.sh "refs/heads/releases/v1" # -> 'releases-v1'
# $ ./tag_from_ref.sh "refs/tags/v1.2.3" # -> 'v1.2.3'
@TobKed
TobKed / README.md
Created November 30, 2022 09:09 — forked from mik-laj/README.md
Dataflow examples on Cloud Build

Dataflow jobs

Java

gcloud builds submit \
    --config=cloudbuild-java.yaml \
    --substitutions=_APACHE_BEAM_VERSION="2.22.0",_PIPELINE_WAIT_UNTIL_FINISH=false

Python

@TobKed
TobKed / parallelisation.py
Created April 6, 2022 15:34
Futures and easy parallelisation
"""
Snippet from:
https://wrongsideofmemphis.com/2022/02/17/futures-and-easy-parallelisation/
"""
import time
from concurrent.futures import ThreadPoolExecutor
import requests
from urllib.parse import urljoin
@TobKed
TobKed / bash_script_template.sh
Created February 7, 2021 17:17
bash script template
#!/usr/bin/env bash
# https://betterdev.blog/minimal-safe-bash-script-template/
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
"""
Translate nested json to flattened csv
"""
import argparse
import csv
import json
from typing import Any, Tuple, Optional
def parse_args() -> Tuple[str, str, dict]:
@TobKed
TobKed / jira_subtask_creation_automation.py
Last active August 18, 2020 14:52
Creating subtasks in JIRA by parsing comments
import os
import re
from atlassian import Jira
# comment to be parsed:
# // TODO: Java core test failing on windows, JIRA HERE ##io.LocalResourceIdTest.testResolveInWindowsOS##
USERNAME = os.environ["USERNAME"]
PASSWORD = os.environ["PASSWORD"]
# https://stackoverflow.com/questions/3589311/get-defining-class-of-unbound-method-object-in-python-3/25959545#25959545
def get_class_that_defined_method(meth):
if inspect.ismethod(meth):
for cls in inspect.getmro(meth.__self__.__class__):
if cls.__dict__.get(meth.__name__) is meth:
return cls
if inspect.isfunction(meth):
return getattr(inspect.getmodule(meth),
meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0])
#!/usr/bin/env python3
"""
you can run this script on your Raspberry Pi by running the following command:
curl -sSL https://gist.githubusercontent.com/TobKed/75337ec7b73a0ac59a415b837927e4ee/raw/docker_on_raspbian.py | python3
"""
import subprocess
def run(s):
subprocess.run(s, check=True, shell=True)
#!/usr/bin/env python2.7
# source: https://stackoverflow.com/a/20365264/9951157
import datetime
import requests.adapters
import grequests
import gevent
__CONCURRENT_LIMIT__ = 80
DEFAULT_BURST_WINDOW = datetime.timedelta(seconds=5)
# https://youtu.be/Jd8ulMb6_ls
# Larry Hastings - Solve Your Problem With Sloppy Python - PyCon 2018
import subprocess
def run(s):
subprocess.run(s, check=True, shell=True)