Skip to content

Instantly share code, notes, and snippets.

View joarleymoraes's full-sized avatar

Joarley Moraes joarleymoraes

View GitHub Profile
from pynamodb.attributes import UnicodeAttribute
from pynamodb.models import Model
from pynamodb.indexes import LocalSecondaryIndex, AllProjection
class SimpleIndex(LocalSecondaryIndex):
class Meta:
projection = AllProjection()
id = UnicodeAttribute(hash_key=True)
common_field = UnicodeAttribute(range_key=True)
import dlib
import os
from skimage import io
training_xml_path = '/tmp/faces/training.xml'
testing_xml_path = '/tmp/faces/testing.xml'
predictor_out_path = '/tmp/predictor.dat'
predictor_options = dlib.shape_predictor_training_options()
predictor_options.be_verbose = True
<img src="https://example.com/?w=100&h=100&q=50"
alt="I will load from another domain">
@app.after_request
def add_header(response):
if response.status_code == 200:
response.cache_control.max_age = CACHE_MAX_AGE
response.cache_control.public = True
return response
@joarleymoraes
joarleymoraes / app.py
Last active November 27, 2017 15:45
app.py
def image_transform(filename, ops):
(...)
with Image(filename=filename) as src:
with src.clone() as img:
if 'w' in ops and 'h' in ops:
w, h = int(ops['w']), int(ops['h']),
img.resize(w, h)
elif 'w' in ops:
@joarleymoraes
joarleymoraes / app.py
Last active November 25, 2017 03:06
imgy HTTP Handler
@app.route('/<s3_key>', methods=['GET'])
def transform(s3_key):
ops = request.args.to_dict()
img_filename = s3.download(BUCKET, s3_key)
if img_filename:
output_img = image_transform(img_filename, ops)
else:
abort(404)