Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@arthuralvim
arthuralvim / pizza.py
Created July 12, 2020 22:55
Máquina escolha minha pizza, por favor.
import random
from collections import Counter
random.seed(3)
pizzas = ['caipira', 'portuguesa', 'pepperoni', '4 queijos']
print(Counter([random.sample(pizzas, 1)[0] for r in range(1000)]))
@arthuralvim
arthuralvim / ipdb-jupyter.py
Last active August 19, 2020 13:22
ipdb-jupyter
IPython.core.debugger.Pdb.set_trace()
# DeprecationWarning: `Tracer` is deprecated since version 5.1, directly use `IPython.core.debugger.Pdb.set_trace()`
from IPython.core.debugger import Tracer; Tracer()()
@arthuralvim
arthuralvim / logout.js
Created June 5, 2020 11:47
HTTP AUTH LOGOUT
// paste it in your console and change the url to your needs.
function logout(to_url) {
var out = window.location.href.replace(/:\/\//, '://log:out@');
jQuery.get(out).error(function() {
window.location = to_url;
});
}
@arthuralvim
arthuralvim / basic_math_utils.py
Last active April 21, 2020 23:22
Basic Math Utils
from math import gcd
from functools import reduce
# or
# def gcd(a, b):
# """Return greatest common divisor using Euclid's Algorithm."""
# while b:
# a, b = b, a % b
# return a
@arthuralvim
arthuralvim / postgres_table_row_count.sql
Created April 9, 2020 18:01
SQL to count rows in all PostgreSQL tables.
# credits for -> https://www.sisense.com/blog/exact-row-counts-for-every-database-table/
CREATE OR REPLACE FUNCTION
count_rows(schema text, tablename text) RETURNS integer
AS
$BODY$
DECLARE
result integer;
query varchar;
BEGIN
@arthuralvim
arthuralvim / aws_create_site.yml
Created February 19, 2020 13:00 — forked from ruzickap/aws_create_site.yml
Ansible playbook which creates instances and tag volumes
---
- name: Create Instance in AWS
hosts: localhost
connection: local
gather_facts: false
vars:
aws_access_key: "xxxxxx"
aws_secret_key: "xxxxxx"
security_token: "xxxxxx"
@arthuralvim
arthuralvim / ansible-aws-inventory-main.yml
Created February 13, 2020 14:03 — forked from nivleshc/ansible-aws-inventory-main.yml
The main inventory file - declare variables here. This calls the worker file (which must be prese
---
# Name: ansible-aws-inventory-main.yml
# Description: this is the main file that calls the worker file (ansible-aws-inventory-worker.yml) to create an inventory of all the
# specific aws resources.
# Below are the resources that will be inventoried
# - vpc
# - subnet
# - igw
# - cgw
# - vgw
@arthuralvim
arthuralvim / ansible-aws-inventory-worker.yml
Created February 13, 2020 14:03 — forked from nivleshc/ansible-aws-inventory-worker.yml
Ansible Inventory Worker file. This is the file which actually carries out all the inventory tasks. It is called by the main file
# Name: ansible-aws-inventory-worker.yml
# Description: this is the worker file that called the main file (ansible-aws-inventory-main.yml) to to create an inventory of all the
# specific aws resources. This file, the worker file and the ansible inventory file must be placed in the same folder
# Prerequisites:
# - the worker file (ansible-aws-inventory-worker.yml) and the ansible hosts file must be present in the same folder as this file (ansible-aws-inventory-main.yml)
# - this script requires read access to all resources it will be querying. An AWS IAM user account must be created with the necessary permissions and with access keys enabled.
# At a minimum, to query all the resources mentioned above, the following permissions are required
# - AmazonVPCReadOnlyAccess
# - AmazonEC2ReadOnlyAccess
# - ElasticLoadBalancingReadOnly
@arthuralvim
arthuralvim / Dockerfile
Created February 5, 2020 12:33 — forked from katzefudder/Dockerfile
AWS CLI dockerized with Alpine Linux
FROM alpine:3.7
ENV AWSCLI_VERSION "1.14.10"
RUN apk add --update \
python \
python-dev \
py-pip \
build-base \
&& pip install awscli==$AWSCLI_VERSION --upgrade --user \
@arthuralvim
arthuralvim / AWS Lambda: Hello World.md
Created January 31, 2020 21:23 — forked from steinwaywhw/AWS Lambda: Hello World.md
An extremely simple AWS Lambda example in Python 3.

Preface

In general, AWS services can be accessed using

  1. AWS web interface,
  2. API libraries in a programming language, such as boto3 for Python 3,
  3. AWS command-line interface, i.e. awscli.

I opted for the API library since it is