Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@arthuralvim
arthuralvim / Ec2MetricsPolicy.json
Created January 29, 2020 14:23
Ec2MetricsPolicy for Cloudwatch monitoring.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SendDataCW",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData",
"ec2:DescribeTags",
"cloudwatch:GetMetricStatistics",
@arthuralvim
arthuralvim / scroll.py
Created January 22, 2020 13:50 — forked from hmldd/scroll.py
Example of Elasticsearch scrolling using Python client
# coding:utf-8
from elasticsearch import Elasticsearch
import json
# Define config
host = "127.0.0.1"
port = 9200
timeout = 1000
index = "index"
@arthuralvim
arthuralvim / ec2-user-bootstrap.sh
Created January 17, 2020 17:37
AWS EC2 Setup (Amazon Linux 2)
#!/bin/bash
sudo yum update
# AWS Monitoring Tool (Matches perfectly with an Instance)
sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64
cd /home/ec2-user
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O
unzip CloudWatchMonitoringScripts-1.2.2.zip
rm CloudWatchMonitoringScripts-1.2.2.zip
(crontab -l 2>/dev/null; echo "*/5 * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron") | crontab -
# Docker, Git, Python, Nginx
@arthuralvim
arthuralvim / app.py
Created January 3, 2020 13:06 — forked from imwilsonxu/app.py
[Flask + Wtforms + Select2] #flask
# -*- coding: utf-8 -*-
from flask import Flask, request, render_template, current_app
from flask_wtf import Form
from wtforms.validators import DataRequired
from wtforms import SelectField, SelectMultipleField, SubmitField
app = Flask(__name__)

sudo apt-get install cowsay fortunes

or

brew install cowsay fortune

cowsay -l
fortune | cowsay
@arthuralvim
arthuralvim / restart_bluetooth.sh
Created June 13, 2019 19:20
Script to restart Bluetooth on Mac OSX.
#!/bin/bash
# blueutil
if which blueutil &> /dev/null; then
echo "blueutil installed!"
else
echo "blueutil installing..."
brew install blueutil
echo "blueutil installed!"
fi
@arthuralvim
arthuralvim / example_envattrs.py
Created May 28, 2019 03:05 — forked from doi-t/example_envattrs.py
Simple example of envattrs for aws lambda function
# echo '{}' > event.json; mkdir -p libs; pip install attrs envattrs -t libs; \
# export YOUR_PREFIX_SLACK_CHANNEL=your_project-staging; \
# export YOUR_PREFIX_S3_BUCKET=pyconapac-bucket; \
# export YOUR_PREFIX_THRESHOLD=50; \
# python-lambda-local -l libs/ -f handler -t 5 lambda_pyconapac.py event.json
from typing import Dict
import attr
import envattrs
@arthuralvim
arthuralvim / aws_lambda_cloudwatch_logs_exporter.md
Created May 28, 2019 03:02 — forked from doi-t/aws_lambda_cloudwatch_logs_exporter.md
Export logs from CloudWatch Logs to S3 with AWS Lambda

event example

TASK_NAME=${1:-'export_logs'}
FROM=${2:-'2017-12-24 12:00'}
TO=${3:-'2017-12-24 12:05'}
cat <<-EOF > event.json
{
    "taskName": "$TASK_NAME",
    "fromTime": `gdate --date="$FROM" +%s%3N`,
 "toTime": `gdate --date="$TO" +%s%3N`
@arthuralvim
arthuralvim / getting-start-with-AWS-Batch.md
Created May 28, 2019 02:57 — forked from doi-t/getting-start-with-AWS-Batch.md
A log of getting start with AWS Batch.
@arthuralvim
arthuralvim / use_pfx_with_requests.py
Created April 17, 2019 18:35 — forked from erikbern/use_pfx_with_requests.py
How to use a .pfx file with Python requests – also works with .p12 files
import contextlib
import OpenSSL.crypto
import os
import requests
import ssl
import tempfile
@contextlib.contextmanager
def pfx_to_pem(pfx_path, pfx_password):
''' Decrypts the .pfx file to be used with requests. '''