Skip to content

Instantly share code, notes, and snippets.

View toshke's full-sized avatar

Nikola Tosic toshke

  • Buffer Overflow
  • Melbourne, Australia
  • X @thetoske
View GitHub Profile
@toshke
toshke / aws_friendly_region_names.json
Created April 13, 2020 01:00
Friendly AWS region names JSON
{
"ap-northeast-1": "Asia Pacific (Tokyo)",
"ap-northeast-2": "Asia Pacific (Seoul)",
"ap-southeast-1": "Asia Pacific (Singapore)",
"ap-southeast-2": "Asia Pacific (Sydney)",
"ap-south-1": "Asia Pacific (Mumbai)",
"eu-central-1": "EU (Frankfurt)",
"eu-north-1": "Europe (Stockholm)",
"eu-west-1": "EU (Ireland)",
"eu-west-2": "Europe (London)",
@toshke
toshke / cloudwatch_metrics_batch.py
Created March 3, 2020 03:58
batch put cloudwatch metrics
pushed = 0
namespace = 'my cw space'
while pushed < len(metric_data):
left = pushed
if len(metric_data) - pushed >= 20:
right = left + 20
else:
right = len(metric_data)
pushed += (right - left)
to_push = metric_data[left:right]
@toshke
toshke / validate_all.sh
Created February 21, 2020 05:37
Validate all cloudformation templates
#!/usr/bin/env bash
for f in *.yaml; do
printf "Check ${f}..."
aws cloudformation validate-template --template-body "file://${f}" > /dev/null 2>&1
if [ "$?" != "0" ]; then
echo "\n${f} failed, run following for details"
echo " aws cloudformation validate-template --template-body file://${f}\n\n"
exit 1
fi
printf " [OK]\n"
@toshke
toshke / convert-video-for-youtube.sh
Created September 25, 2018 05:49
convert mov to mp4 MacOS
#!/bin/bash
ffmpeg -i $1 -vcodec h264 -acodec aac -r 24 -crf 15 $2
@toshke
toshke / python_code_deploy.py
Created July 30, 2018 11:20
python code deploy
#!/usr/bin/env python -u
import boto3
import os
import time
import sys
codedeploy = boto3.client('codedeploy',region_name=os.environ['AWS_REGION'])
application = os.environ['APPLICATION']
codedeploy_bucket = os.environ['CODEDEPLOY_BUCKET']
codedeploy_path = os.environ['CODEDEPLOY_PATH']
@toshke
toshke / cr_response.py
Last active November 23, 2020 10:53
cloudformation custom resource respond wrapper
import logging
from urllib.request import urlopen, Request, HTTPError, URLError
import json
logger = logging.getLogger()
class CustomResourceResponse:
def __init__(self, event):
self.event = event
self.response = {
import boto3
def pull_s3_prefix(dst_dir, bucket, prefix):
client = boto3.client('s3')
resource = boto3.resource('s3')
download_dir(client, resource, prefix, prefix, dst_dir, bucket)
def download_dir(client, resource, prefix, start_prefix, local, bucket ):
paginator = client.get_paginator('list_objects')
for result in paginator.paginate(Bucket=bucket, Delimiter='/', Prefix=prefix):
@toshke
toshke / copy_aws_ssm_parameters.py
Created July 2, 2018 01:56
Copy AWS System Manager Parameters from one path to another path
import boto3;
client = boto3.client('ssm')
src_path = '/source/ssm/path'
dst_path = '/destination/ssm/path'
ssm_key_id = '<<keyidhere>>'
def printparams(params):
for p in params['Parameters']:
new_path = p['Name'].replace(src_path, dst_path)
@toshke
toshke / gitalias.sh
Last active April 16, 2020 08:38
Useful git aliases push pull rebase master upstream
git config --global alias.plom '!git pull origin master'
git config --global alias.psom '!git push origin master'
git config --global alias.plod '!git pull origin develop'
git config --global alias.psod '!git push origin develop'
git config --global alias.plum '!git pull upstream master'
git config --global alias.plud '!git pull upstream develop'
git config --global alias.plrum '!git pull --rebase upstream master'
git config --global alias.plrom '!git pull --rebase origin master'
@toshke
toshke / sns2slack.py
Created May 29, 2018 06:19
AWS Lambda SNS to Slack Message
import json
import base64
import sys
import os
def lambda_handler(event, context):
url = os.environ['slack_incoming_hook']
headers = {