Skip to content

Instantly share code, notes, and snippets.

View satr's full-sized avatar

Sergey Smolnikov satr

View GitHub Profile
@satr
satr / CustomProactiveSubscriptionChangedRequestHandler.java
Created June 10, 2019 12:37
CustomProactiveSubscriptionChangedRequestHandler - code only
public class CustomProactiveSubscriptionChangedRequestHandler implements ProactiveSubscriptionChangedRequestHandler {
@Override
public boolean canHandle(HandlerInput input, ProactiveSubscriptionChangedRequest proactiveSubscriptionChangedRequest) {
return true;
}
@Override
public Optional<Response> handle(HandlerInput input, ProactiveSubscriptionChangedRequest proactiveSubscriptionChangedRequest) {
//Put Proactive Subscription Changed event handling code here
@satr
satr / CustomProactiveSubscriptionChangedRequestHandler.java
Created June 10, 2019 12:35
"ProactiveSubscriptionChanged" event handler for Amazon Alexa AWS Lambda function
import com.amazon.ask.dispatcher.request.handler.HandlerInput;
import com.amazon.ask.dispatcher.request.handler.impl.ProactiveSubscriptionChangedRequestHandler;
import com.amazon.ask.model.Response;
import com.amazon.ask.model.events.skillevents.ProactiveSubscriptionChangedRequest;
import java.util.Optional;
/* Skill manifest should contain subscription to the event "SKILL_PROACTIVE_SUBSCRIPTION_CHANGED" (with needed proactive events in "publications")
"permissions": [{"name": "alexa::devices:all:notifications:write"}],
"events": {
@satr
satr / Amazon-Alexa-Skill-Proactive-Media-event-example.json
Created June 9, 2019 05:43
Amazon Alexa Skill Proactive Media event example
{
"timestamp": "2019-06-08T10:12:01.00Z",
"referenceId": "unique-id-of-this-event-instance-abc123456789",
"expiryTime": "2019-06-08T14:00:00.00Z",
"event": {
"name": "AMAZON.MediaContent.Available",
"payload": {
"availability": {
"startTime": "2019-06-08T20:00:00Z",
"provider": {
@satr
satr / alexa-proactive-event-property-in-alexa-skill-manifest.js
Last active June 9, 2019 05:41
Alexa Proactive event property in Alexa Skill manifest
"events": {
"publications": [
{ "eventName": "AMAZON.OrderStatus.Updated" },
{ "eventName": "AMAZON.MediaContent.Available" }
],
"endpoint": {
"uri": "YOUR-AWS-LAMBDA-FUNCTION-ARN"
}
}
@satr
satr / build.gradle
Created June 9, 2019 05:34
Dependencies and jar-task in build.gradle for AWS Lambda function on Java for Amazon Alexa Skill
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.amazon.alexa', name: 'ask-sdk', version:'2.17.2'
compile group: 'com.amazonaws', name: 'aws-lambda-java-log4j2', version:'1.1.0'
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
@satr
satr / JacksonDeserializeObject.java
Created May 17, 2019 09:53
Deserialize an object from JSON with Jackson lib
/*
https://github.com/FasterXML/jackson
Grade.build
dependencies {
compile group:'com.fasterxml.jackson', name:'jackson-bom', version: '2.9.8'
}
Input:
{ "first_name" : "John", "last_name" : "Smith" }
{ "first_name" : "John" }
@satr
satr / json-content-example.js
Created May 16, 2019 05:36
JSON content example
{
"string_value": "some text",
"int_value": "123",
"float_value":"12.345",
"bool_value": "true",
"date_value": "2019-05-10T10:20:35.000+0",
"array_value": [1,2,3,4,5],
"object_value": {
"int_field": "789",
"string_field": "object's text"
@satr
satr / LambdaRequestHandlerWithLoggerTest.java
Created May 15, 2019 18:52
Mock Lambda Context and Logger while testing AWS Lambda RequestHandler (with JUnit4)
//In the test class
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.Mock;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.doAnswer;
@satr
satr / TensorFlowCallbacks.py
Created May 15, 2019 13:52
Usage of TensorFlow callbacks
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
mnist = keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
#plt.imshow(test_images[0])
class FitCallback(tf.keras.callbacks.Callback):
@satr
satr / mnist-fashion-example.py
Created May 4, 2019 08:18
Learn image recognition with fashion_mnist
# Based on https://www.coursera.org/learn/introduction-tensorflow/home/welcome
# Course 1 - Part 4 - Lesson 2 - Notebook
#https://github.com/zalandoresearch/fashion-mnist
import tensorflow as tf
from tensorflow import keras
mnist = keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
import matplotlib.pyplot as plt