Skip to content

Instantly share code, notes, and snippets.

View ghelobytes's full-sized avatar

Angelo Arboleda ghelobytes

View GitHub Profile
@ghelobytes
ghelobytes / Makefile
Last active February 8, 2024 17:38
Add prompt to confirm correct cluster but doesn't prompt when CI=true (GH actions)
delete-namespace: check-cluster
kubectl delete namespace sandbox
check-cluster:
@if [ -z "$(CI)" ]; then current_context=$(shell kubectl config current-context); \
echo "The current context is `tput bold`$$current_context`tput sgr0`."; \
read -p "Is this the correct context? (y/n): " answer; if [ "$$answer" != "y" ]; \
then echo "Aborted."; exit 1; fi; echo "Proceeding..."; \
fi
@ghelobytes
ghelobytes / kdecsec.sh
Last active February 9, 2024 01:29
List kubernetes secret easily
kdecsec(){kubectl get secret $1 -o go-template='{{range $k,$v := .data}}{{printf "%s => " $k}}{{if not $v}}{{$v}}{{else}}{{$v | base64decode}}{{end}}{{"\n"}}{{end}}';}
kgpf(){kubectl get svc -o json | jq '.items[] | {name:.metadata.name, p:.spec.ports[] } | select( .p.nodePort != null ) | "\(.name): localhost:\(.p.nodePort) -> \(.p.port) -> \(.p.targetPort)"';}
@ghelobytes
ghelobytes / _k8_scripts.sh
Last active October 12, 2023 22:00
k8 scripts
# Show disk space info for all pod
n=mynamespace bash -c 'for pod in $(kubectl get pods -n $n -o=jsonpath="{.items[*].metadata.name}"); do echo $pod; kubectl exec -it $pod -n $n -- df -h; echo "\n"; done'
@ghelobytes
ghelobytes / Gemfile
Created July 3, 2022 07:10 — forked from bosskovic/Gemfile
Devise as authentication solution for rails API
gem 'devise', '3.2.4'
gem 'simple_token_authentication', '1.5.0'
@ghelobytes
ghelobytes / async_to_sync.py
Created December 1, 2021 23:28
Reuse existing async methods
# from: https://gist.github.com/phizaz/20c36c6734878c6ec053245a477572ec
import asyncio
import functools
import asyncio
def force_async(fn):
'''
turns a sync function to async function using threads
'''
from concurrent.futures import ThreadPoolExecutor
@ghelobytes
ghelobytes / geotiff_info.py
Created October 7, 2021 14:34
geotiff sanity check
from osgeo import gdal
raster_file = "some_geotiff.tif"
print("gdal.__version__:", gdal.__version__)
print("############ Get STATS using GetStatistics() ############")
ds = gdal.Open(raster_file)
band_count = ds.RasterCount
print("band_count:", band_count)
@ghelobytes
ghelobytes / rename.sh
Created May 27, 2020 19:35
Mass rename commiter
git filter-branch --env-filter '
WRONG_EMAIL="wrong@example.com"
NEW_NAME="New Name Value"
NEW_EMAIL="correct@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
import json
def mapper(source, template):
def _get(d, keys, splitter="."):
if isinstance(keys, str):
keys = keys.split(splitter)[1:]
if not keys or d is None:
return d
@ghelobytes
ghelobytes / script.sh
Created December 19, 2019 23:43
Passing flagged parameters to bash script
#!/usr/bin/env bash
while getopts u:d:p:b: option
do
case "${option}"
in
u) _USER=${OPTARG};;
p) _PASSWORD=${OPTARG};;
b) _BUILD=${OPTARG};;
esac
@ghelobytes
ghelobytes / app.py
Last active December 10, 2019 18:36
TMS proxy to write ZXY on tiles
import flask
import requests
from flask import Flask
from flask_restful import Resource, Api
from PIL import Image, ImageDraw, ImageFont
from io import BytesIO
app = Flask(__name__)
api = Api(app)