Skip to content

Instantly share code, notes, and snippets.

View daniyel's full-sized avatar
🎯
Focusing

Danijel H daniyel

🎯
Focusing
View GitHub Profile
@daniyel
daniyel / ecssd_cleanup.py
Created October 17, 2018 07:24
Lambda function for cleaning Route53 SRV and A records when container services are restarted or stopped
from __future__ import print_function
# Copyright 2016-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
# http://aws.amazon.com/apache2.0/
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
import json
import boto3
import http.client
@daniyel
daniyel / ecssd_create.py
Created October 17, 2018 07:20
Lambda function for creating SRV records in Route53 (AWS) for container services
import boto3
import pprint
import os
import re
environment = os.environ.get('ENVIRONMENT', 'development')
domain = os.environ.get('DOMAIN', f'sd-{environment}.internal')
cluster = f'{environment}-ECSCluster'
DEFAULT_TTL = 0
DEFAULT_WEIGHT = 1
@daniyel
daniyel / nginx.conf.tmpl
Created October 16, 2018 11:01
nginx proxy config
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log debug;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@daniyel
daniyel / get_ubuntu_ami.sh
Created September 7, 2018 12:35
Get list of Ubuntu 16.04 LTS latest AMIs for AWS CloudFormation
#!/bin/sh
remove_last_comma() { sed '
$x;$G;/\(.*\),/!H;//!{$!d
}; $!x;$s//\1/;s/^\n//'
}
response=$(curl -s "https://cloud-images.ubuntu.com/locator/ec2/releasesTable" | remove_last_comma)
regions=$(echo $response | jq -c '.aaData[] | select(contains(["16.04", "hvm:ebs"])) | .[0]' | sed 's/"//g')
@daniyel
daniyel / list_ami_images.sh
Created July 4, 2018 11:56
Get a list of AMI images for CloudFormation use.
#!/bin/bash -xe
REGIONS=$(aws ec2 describe-regions --query "Regions[].RegionName" --output text)
for region in $REGIONS; do
ami=$(aws --region $region ec2 describe-images --filters "Name=name,Values=amzn-ami-hvm-2018.03.0.20180508-x86_64-gp2" --query "Images[0].ImageId" --output "text")
printf "$region:\n AMI: '$ami'\n"
done
@daniyel
daniyel / Makefile-golang
Last active June 24, 2018 08:33
Example Makefile for building go binary file for linux 64 platform
init:
./dep_wrapper.sh init
./dep_wrapper.sh ensure
ensure:
./dep_wrapper.sh ensure
build:
mkdir -p ./src
cp -R ./vendor/. ./src/
@daniyel
daniyel / dep_wrapper.sh
Created June 24, 2018 08:29
Wrapper for go dep dependency management tool to fix GOPATH for existing go project
#!/bin/sh
CURR_DIR="$(PWD)"
PARENT_DIR="$(dirname $CURR_DIR)"
export GOPATH="$(mktemp -d "/tmp/dep.XXXXXXXX")"
trap "rm -rf \"${GOPATH}\"" EXIT HUP INT
SRCDIR="${GOPATH}/src/$PARENT_DIR"
mkdir -p "$(dirname "${SRCDIR}")"
@daniyel
daniyel / aws-cfn-self-referencing-sg.yaml
Created June 24, 2018 08:23
Example of self-referencing security group in AWS
Parameters:
VPC:
Description: VPC that will be used for Cluster.
Type: AWS::EC2::VPC::Id
Resources:
MyTestSecurityGroup:
Type: AWS::EC2::SecurityGroup
@daniyel
daniyel / textCoding.js
Created May 30, 2018 10:26
Helper class for converting text from CP-1251 to UTF-8 encoding
/**
* @class TextCoding
*
* @constructor
*/
function TextCoding() {}
/**
* Replaces CP-1251 encodings in string with UTF-8
*
@daniyel
daniyel / .bash_profile
Created March 13, 2018 14:10
Just my personal bash profile
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\] \w\[\033[01;31m\]\$(parse_git_branch)\$\[\033[00m\] "
# aliases
alias lt='ls -al --time-style=+%D | grep $(date +%D)'
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}