Skip to content

Instantly share code, notes, and snippets.

View asolera's full-sized avatar

Andrew Solera asolera

  • Secretaria Municipal de Direitos Humanos e Cidadania
  • São Paulo
View GitHub Profile
@asolera
asolera / fix-crlf.sh
Created April 23, 2021 18:32
Fix CRLF git problems
#!/bin/bash
# https://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf
git config --global core.autocrlf false
git rm --cached -r .
git reset --hard
@asolera
asolera / docker-debug.sh
Created April 16, 2021 18:00
Docker swarm debug commands that shows errors on service deploy
#!/bin/bash
# Credits/thanks to: https://stackoverflow.com/questions/45372848/docker-swarm-how-to-find-out-why-service-cant-start
docker service ps --no-trunc {serviceName}
journalctl -u docker.service | tail -n 50
@asolera
asolera / cloudformation.yml
Created April 14, 2021 14:28
AWS CloudFormation Template for EC2 (AMI) with Docker
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation Template for EC2 (AMI) with Docker
Parameters:
EC2AvailabilityZoneParam:
Type: String
Default: us-east-1a
EC2ImageNameParam:
Type: String
Default: ami-0533f2ba8a1995cf9
@asolera
asolera / .env
Last active April 12, 2021 14:53
Vagrant with dot env without plugins
EXAMPLE_ENV_A=Hello
EXAMPLE_ENV_B=world
@asolera
asolera / git-fetch-branches.sh
Last active April 7, 2021 18:46
Git fetch all remote branches to local machine
#!/bin/bash
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
@asolera
asolera / tag.sh
Created March 25, 2021 14:47
Tagging AWS Cloudwatch Alarms via AWS CLI
#!/bin/bash
aws cloudwatch tag-resource --resource-arn arn:aws:cloudwatch:us-east-1:012345678901:alarm:Alarm-Name --tags Key=Example,Value=OK Key=Another,Value=Okay
@asolera
asolera / lambda_function.py
Created March 23, 2021 18:14
Stop AWS EC2 Instances with Lambda
import boto3
import time
# Enter the region your instances are in, e.g. 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['i-03c24cxbd9x10ex51']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
@asolera
asolera / lambda_function.py
Created March 23, 2021 18:13
Start AWS EC2 Instances with Lambda
import boto3
import time
# Enter the region your instances are in, e.g. 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['i-0ab7xdx71x8xeff33']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.start_instances(InstanceIds=instances)
@asolera
asolera / docker-ami.md
Last active June 3, 2022 19:25
Docker install on Amazon Linux 2 (AMI)

I've created this document just in case the original one (https://gist.github.com/npearce/6f3c7826c7499587f00957fee62f8ee9) get deleted.

sudo yum update -y
sudo amazon-linux-extras install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo chkconfig docker on
sudo yum install -y git
sudo reboot
@asolera
asolera / url_encode.sh
Created March 19, 2021 20:23
URL Encode with Shell Script
#!/usr/bin/env bash
#
# Credits to Meleu @ https://meleu.sh/urlencode/
# Usage: urlencode "#" => will output "%23"
urlencode() {
local LC_ALL=C
local string="$*"
local length="${#string}"
local char