Skip to content

Instantly share code, notes, and snippets.

@nikhilym
nikhilym / build.ps1
Created May 5, 2020 03:29
Custom windows build script, uninstalling AWS SDK libs
#requires -version 3
<#
.SYNOPSIS
PowerShell script for ask-cli's Python-pip code building flow.
.DESCRIPTION
This is the PowerShell version of the build script, for building the AWS Lambda deployable skill code that is written in Python language. This script is only run by the ask-cli whenever a 'requirements.txt' file is found alongside the skill code. The dependencies are installed using 'pip', and are packaged using 'zip'.
.EXAMPLE
build.ps1 archive.zip
This example showcases how to run the build script, to create an AWS Lambda deployable package called 'archive.zip'.
.EXAMPLE
@nikhilym
nikhilym / geolocation_skill.py
Created June 27, 2019 19:52
Geolocation sample skill hosted on HTTPS
# -*- coding: utf-8 -*-
# This is a skill for getting device location.
import logging
from ask_sdk_core.skill_builder import CustomSkillBuilder
from ask_sdk_core.api_client import DefaultApiClient
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.dispatch_components import AbstractExceptionHandler
@nikhilym
nikhilym / python_decorator_guide.md
Created November 29, 2018 06:32 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@nikhilym
nikhilym / audioplayer_sample.py
Created August 24, 2018 23:16
AudioPlayer play, stop stream handlers using ASK Python SDK
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.utils import is_intent_name
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model.response import Response
from ask_sdk_model.ui import StandardCard, Image, SimpleCard
from ask_sdk_model.interfaces.audioplayer import (
PlayDirective, PlayBehavior, AudioItem, Stream, AudioItemMetadata,
StopDirective)
from ask_sdk_model.interfaces import display
@nikhilym
nikhilym / render_template_directive_skill.py
Created August 24, 2018 22:04
Render Template usage in skill with ASK Python SDK
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_core.utils import is_intent_name
from ask_sdk_core.response_helper import get_plain_text_content
from ask_sdk_model.response import Response
from ask_sdk_model.interfaces.display import (
ImageInstance, Image, RenderTemplateDirective,
BackButtonBehavior, BodyTemplate2)
from ask_sdk_model import ui
@nikhilym
nikhilym / display_check.py
Created August 24, 2018 22:00
Display check in ASK Python SDK
def is_display_supported(handler_input):
# type: (HandlerInput) -> bool
"""Check if display is supported by the skill."""
try:
if hasattr(handler_input.request_envelope.context.system.device.supported_interfaces, 'display'):
return handler_input.request_envelope.context.system.device.supported_interfaces.display is not None
except:
return False
@nikhilym
nikhilym / progressive_response_skill.py
Last active September 28, 2022 14:47
Example usage of Progressive Response in ASK Python SDK
from ask_sdk_core.skill_builder import CustomSkillBuilder
from ask_sdk_core.api_client import DefaultApiClient
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.dispatch_components import AbstractExceptionHandler
from ask_sdk_core.utils import is_request_type, is_intent_name
from ask_sdk_model.ui import SimpleCard
from ask_sdk_model.services.directive import (
SendDirectiveRequest, Header, SpeakDirective)
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model.response import Response
@nikhilym
nikhilym / elicit_slot_handler_example.py
Last active September 6, 2018 11:19
Adding ElicitSlotDirective through ASK Python SDK
## Example directive, from https://developer.amazon.com/docs/custom-skills/dialog-interface-reference.html#elicitslot
from ask_sdk_model.dialog import ElicitSlotDirective
from ask_sdk_model import (
Intent, IntentConfirmationStatus, Slot, SlotConfirmationStatus)
directive = ElicitSlotDirective(
slot_to_elicit="fromCity",
updated_intent=Intent(
name="planMyTrip",
@nikhilym
nikhilym / jinja2_file_less.py
Created July 25, 2018 23:29 — forked from wrunk/jinja2_file_less.py
python jinja2 examples
#!/usr/bin/env/python
#
# More of a reference of using jinaj2 without actual template files.
# This is great for a simple output transformation to standard out.
#
# Of course you will need to "sudo pip install jinja2" first!
#
# I like to refer to the following to remember how to use jinja2 :)
# http://jinja.pocoo.org/docs/templates/
#

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream