Skip to content

Instantly share code, notes, and snippets.

View atemate's full-sized avatar
🐒

Artem Yushkovskiy atemate

🐒
View GitHub Profile
@atemate
atemate / jq_get_unique_dirs.sh
Created May 17, 2023 11:58
jq_get_unique_dirs.sh
modified_dirs='["a", "a/b", "b/c/d", "c/d/e.txt"]'
modified_dirs=$(echo $modified_files | jq -r '[ .[] | split("/") | .[0] ] | unique')
@atemate
atemate / delete_all_dynamodb_items.sh
Created April 28, 2023 14:40
Delete all DymamoDB items
table="..."
for pk in $(aws dynamodb scan --table-name ${table} | jq -r '.Items | .[].pk.S'); do
aws_cli dynamodb delete-item --table-name "${table}" --key '{"pk":{"S":"'$pk'"}}' &
sleep 0.01
echo "Deleted: $table / $pk"
done
@atemate
atemate / check_http.py
Created April 14, 2023 14:27
Check http health using python
python -c "import http.client; \
c = http.client.HTTPConnection('localhost:8080'); \
r = c.request('GET', '/health'); \
r = c.getresponse(); \
assert r.status == 200, (r.status, r.reason)"
python -c 'import httpx; r = httpx.get("http://localhost:8080/health"); r.raise_for_status()'
@atemate
atemate / gh-workflow-caching-poetry.yaml
Created February 3, 2023 15:17
gh-workflow-caching-poetry
# not sure if it's best way. Maybe better just:
# - name: Install Python 3.8
# uses: actions/setup-python@v4
# with:
# python-version: 3.8
# cache: poetry
- name: Configure docker
uses: docker/login-action@v2
@atemate
atemate / construct_json_list_of_values.py
Created February 2, 2023 12:05
Helper script for GitHub Actions to construct json from individual values (to be used by matrix and fromJson)
# Usage:
# $ export KEY=kek OTHER_KEYS="aa bb" OTHER_VALS="AA BB"
# $ echo "12 34" | python .github/workflows/helpers/construct_json_list_of_values.py
# [{"kek": "12", "aa": "AA", "bb": "BB"}, {"kek": "34", "aa": "AA", "bb": "BB"}]
import json
import os
import sys
KEY = os.environ["KEY"]
@atemate
atemate / workflow.yml
Created January 5, 2023 17:34
GitHub Actions workflow to use git to calculate last change on a directory/file
...
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # checkout pull request HEAD commit instead of merge commit
fetch-depth: 0 # fetch all history for all branches and tags
- name: Set env variables
id: setup-vars
run: |
@atemate
atemate / log_release_history.sh
Last active January 5, 2023 15:30
List history of the "tag: " line changes in a charts repo
FILE_PATH=path/to/config/file.yaml
LINE_MARK="tag: "
line_number=$(awk "/$LINE_MARK/ {print FNR}" $FILE_PATH)
test $line_number # TODO: better error reporting
git log --oneline --decorate --pretty=format:"%cs [%h] by %aN%n" -u -L ${line_number},${line_number}:$FILE_PATH \
| grep -v "diff --git\|---\|+++\|@@\|- \|^$"
@atemate
atemate / .flake8
Last active November 10, 2022 17:22
Pre-commit config for typical python projects
[flake8]
max-line-length = 88
extend-ignore = \
E203, \ # whitespace before ':'
F841, \ # local variable name is assigned to but never used
E266, \ # too many leading '#' for block comment
per-file-ignores =
*/__init__.py: F401
@atemate
atemate / action.yml
Created October 10, 2022 10:25
GH Action to Transform input json, similar to jq
name: Transform input json, similar to jq
inputs:
input_json: {type: string, required: true}
transform: {type: string, required: true}
outputs:
result:
value: ${{ steps.parse.outputs.result }}
@atemate
atemate / export-vars__action.yaml
Created October 7, 2022 13:13
GH Action to accept arguments as json dict with some value to overload
name: Setup env variables
inputs:
vars_json: {type: string, default: "{}"}
# TODO: add argument "by_workflow_call: bool" to skip some steps
# env vars to override:
PAYLOAD: {type: string, default: ""}
TRAIN_IMAGE_TAG: {type: string, default: ""}
outputs: