Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@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

@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 / 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__)
@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. '''
@arthuralvim
arthuralvim / pytest-fixture-modularization.md
Created February 11, 2019 21:50 — forked from peterhurford/pytest-fixture-modularization.md
How to modularize your py.test fixtures

Using py.test is great and the support for test fixtures is pretty awesome. However, in order to share your fixtures across your entire module, py.test suggests you define all your fixtures within one single conftest.py file. This is impractical if you have a large quantity of fixtures -- for better organization and readibility, you would much rather define your fixtures across multiple, well-named files. But how do you do that? ...No one on the internet seemed to know.

Turns out, however, you can define fixtures in individual files like this:

tests/fixtures/add.py

import pytest

@pytest.fixture
@arthuralvim
arthuralvim / generate_fixtures.py
Created October 22, 2018 21:09 — forked from jonas-grgt/generate_fixtures.py
Management command for django to dump database data (fixtures) on a per model base.
from django.core.management.base import BaseCommand, CommandError
from django.core import serializers
from optparse import make_option
class Command(BaseCommand):
"""
Generate a fixture file for a specific model.
Useage: ./manage.py generate_fixtures app.models.MyModel --file=MyModelsOutputFile.json
"""