Skip to content

Instantly share code, notes, and snippets.

View atemate's full-sized avatar
🐕

Artem Yushkovskiy atemate

🐕
View GitHub Profile
@atemate
atemate / action.yml
Last active July 24, 2023 13:47
GitHub Action to install a python package from a private GCP repostiroty (artifact registry)
name: Setup private pypi - GCP Artifact Registry
inputs:
central_project:
type: string
required: true
description: GCP project where the Artifact Registry is located
central_repo:
type: string
required: true
@atemate
atemate / .pre-commit-config.yaml
Created July 21, 2023 13:27
My .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: end-of-file-fixer
- id: trailing-whitespace
- id: detect-private-key
- id: no-commit-to-branch
- id: check-toml
@atemate
atemate / export_payload_var.sh
Last active July 19, 2023 16:42
export a variable from a json payload
set -eu
# shortcut for getting payload values
function export_payload_var() {
name="$1"
pattern="$2"
value=$(jq -r "$pattern" "${PAYLOAD}")
if [[ "$value" == "null" ]]; then
echo "Could not find pattern '$pattern' in payload '${PAYLOAD}'"
exit 1
@atemate
atemate / replace-first-entry.sh
Created June 30, 2023 10:57
Replace first entry in a file (with sed)
echo "tag=$tag"
echo "FILE_PATH=$FILE_PATH"
export LINE_MARK="tag:"
sed -i'' -e "0,/$LINE_MARK .*/s//$LINE_MARK $tag/" "$FILE_PATH" # replace first entry
@atemate
atemate / light_data_frame.py
Created May 23, 2023 18:41
Lightweigh pd.DataFrame without pandas
# TODO: use np.array and dtypes there
class _MyIndexer:
def __init__(self, obj) -> None:
self._obj = obj
def __getitem__(self, idx):
print('__getitem__', idx, type(idx), isinstance(idx, (list, tuple)))
if isinstance(idx, str):
@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"]