This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="https://example.com/?w=100&h=100&q=50" | |
alt="I will load from another domain"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |