Skip to content

Instantly share code, notes, and snippets.

@bertomartin
bertomartin / 0-README.md
Created August 20, 2017 03:53 — forked from alexcasalboni/0-README.md
AWS Lambda: Advanced Coding Session - clda.co/aws-lambda-webinar

AWS Lambda: Advanced Coding Session (slides)

Live demos:

  1. Amazon API Gateway Access Control
  2. Amazon Kinesis Streams processing
  3. Amazon Cognito Sync trigger
  4. AWS CloudFormation Custom Resources
@bertomartin
bertomartin / boto3_getpolicy.py
Created August 20, 2017 03:53 — forked from alexcasalboni/boto3_getpolicy.py
AWS IAM Policy body with Python and boto3
import boto3
iam = boto3.resource('iam')
def get_policy_body(arn, version_id=None):
""" Return IAM Policy JSON body """
if version_id:
version = iam.PolicyVersion(arn, version_id)
else:
policy = iam.Policy(arn)
@bertomartin
bertomartin / amazon-rekognition.md
Created August 20, 2017 03:52 — forked from alexcasalboni/amazon-rekognition.md
Amazon Rekognition - Python Code Samples

Amazon Rekognition - Python Code Samples

  1. Labels Detection
  2. Faces Detection
  3. Faces Comparison
  4. Faces Indexing
  5. Faces Search
@bertomartin
bertomartin / aws-lambda-demo1-restful-api.py
Created August 17, 2017 16:45 — forked from alexcasalboni/aws-lambda-demo1-restful-api.py
AWS Lambda Coding Session - clda.co/webinar-lambda
def lambda_handler(event, context):
name = event.get('name') or 'World'
print("Name: %s" % name)
return "Hello %s!" % name
@bertomartin
bertomartin / deploy.sh
Created August 17, 2017 16:40 — forked from alexcasalboni/deploy.sh
Simple AWS Lambda deployment script - Zip & upload Deployment Package with initial dependencies to S3
#!/bin/bash
BUCKET="YOUR_BUCKET_NAME" # bucket name
FILENAME="deployment-package.zip" # upload key
TMP_FOLDER="/tmp/lambda-env-tmp/" # will be cleaned
OUTPUT_FOLDER="/tmp/lambda-env/" # will be cleaned
HERE=${BASH_SOURCE%/*} # relative path to this file's folder
LAMBDA_FOLDER="$HERE/lambda/" # relative path
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bertomartin
bertomartin / from_sklearn.py
Created November 21, 2016 19:13 — forked from napjon/from_sklearn.py
Method to convert docs using sklearn to pyLDAVis
def from_sklearn(docs,vect,lda,**kwargs):
"""Create Prepared Data from sklearn's vectorizer and Latent Dirichlet
Application
Parameters
----------
docs : Pandas Series.
Documents to be passed as an input.
vect : Scikit-Learn Vectorizer (CountVectorizer,TfIdfVectorizer).
@bertomartin
bertomartin / useful_pandas_snippets.py
Created November 16, 2016 15:57 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bertomartin
bertomartin / tf-idf.py
Created September 9, 2016 19:57 — forked from michael-erasmus/tf-idf.py
Tf-idf example
import os
import math
import re
import pandas as pd
from collections import Counter
from sklearn.datasets import fetch_20newsgroups
#get a subset of the dataset
categories = [