Skip to content

Instantly share code, notes, and snippets.

View lbenitez000's full-sized avatar

Luis Benitez lbenitez000

  • Uber Technologies
  • Santiago (CL) / São Paulo (BR)
View GitHub Profile
@lbenitez000
lbenitez000 / env_loader.py
Last active May 2, 2024 02:11
Loads environment variables from a .envrc or .env file into os.environ. Also useful to load .env environment variables into PyCharm's Python Console
# Loads environment variables from a .envrc or .env file into os.environ
# Also useful to load .env environment variables into PyCharm's Python Console
# Usage: Download this file into your project's directory and add the following snippet
# to the Python Console's Starting Script.
# Settings > Build, Execution, Deployment > Console > Python Console > Starting script
# ```
# from env_loader import load
# load(".env")
# del load
# ```
@lbenitez000
lbenitez000 / payload.py
Created October 23, 2015 17:18
A payload parser middleware for the Falcon Framework <http://falconframework.org/>
""" A payload parser middleware for the Falcon Framework <http://falconframework.org/>
Currently it only works with Content-Type: application/json.
It is easily extendable for other Content-Types
"""
__author__ = "Luis Benitez"
__license__ = "MIT"
import falcon
import json
@lbenitez000
lbenitez000 / boto_decimal_monkeypatch.py
Last active March 16, 2017 16:02
A monkey patch for boto's Decimal context to allow inexact and rounded representation of floats. Used to store any float in DynamoDB when inexactitude is allowed.
# Monkey patch Decimal's default Context to allow
# inexact and rounded representation of floats
import decimal
from boto.dynamodb.types import DYNAMODB_CONTEXT
# Inhibit Inexact Exceptions
DYNAMODB_CONTEXT.traps[decimal.Inexact] = 0
# Inhibit Rounded Exceptions
DYNAMODB_CONTEXT.traps[decimal.Rounded] = 0
@lbenitez000
lbenitez000 / cors.py
Last active December 20, 2016 00:51
A CORS middleware for the Falcon Framework <http://falconframework.org/>
""" A CORS middleware for the Falcon Framework <http://falconframework.org/>
"""
__author__ = "Luis Benitez"
__license__ = "MIT"
from falcon import HTTP_METHODS
class CorsMiddleware(object):
"""Implements (partially) the Cross Origin Resource Sharing specification