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 / create_diff.sh
Last active March 12, 2018 13:05
Bash script for creating destination diff folder between two source folders
#!/bin/bash
programname=$0
function usage {
echo "usage: $programname -l folder1 -r folder2 -d folder3 [-e lrd]"
echo " -l folder on the left side"
echo " -r folder on the right side"
echo " -d destination folder"
echo " -e exclude l (left side), r (right side) or d (differ)"
@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)/'
}
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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