Category Archives: Tutorials

Alexa App Development – Important Notes

Alexa Develpoment

  • Alexa Skills Kit
  • JavaScript ES6 (EcmaScript 2015) || write code in ES5
    • babel transpiler needed
      • If you use babel. I would suggest you have it compile on save.
  • Break your API calls down into modules
  • Keep your entry page clean and easy to read.

Files

speechAssets/

  • IntentSchema.json
    • JSON file that should contain your Alexa Skill Intents

root “intents

{ "intents" : [] }
Intents is an array that will hold all of your intent objects

Intent Objects

{ "intent": "myIntent", "slots" : [ ] }
The intent object contains the name of your intent under the key intent and any slots you may need.

Slots

"slots": [{ "name": "MySlot", "type": "MY_SLOT_TYPE" }]
Custom slot types are like your parameters. Some one says an Utterance of … “Tell me about my boots” … boots would be the slot type. The Utterance will resemble.
me about my {item}
Where item will be brought into your Alexa Skill Entry Point as an argument with a value of “boots”.

  • SampleUtterances.txt

TypeScript : Functions : Optional Parameters

Problem

I need to allow a parameter to be optional in TypeScript. Optional parameters in TypeScript have to be declared.

Answer

Use “?” next to the parameter name to allow the parameter to be optional. The optional parameter must come last in the parameter list but before a REST parameter.

Example

MyFunction(myString: string, myNumberOpt?: number) { ... }

Upload Images to Amazon S3 Server using Node and Express.js

The code below will walk you through the process to get a working example created for uploading an image file to your Amazon S3 Server. You should already have a bucket created and have your key and secret on hand. We will add those strings to a config file. Once your done you will be able to upload an image file to your Amazon S3 server and verify the image was uploaded by refreshing your S3 Admin portal or view the image from your returned code.

Get the code from Github : https://github.com/wesleyduff/AmazonS3FileUpload

Continue reading

Use of !! in JavaScript

BANG BANG

Want to find out if something is false if it is a string, number, obj etc….


var x = “No”
typeof x
// string

var xBools = !!x;
//true – because variable x has a string of No, could be a string of false as well. A string is an object and that object has alpha characters
typeof xBools
// boolean

var emptyString = “”;
typeof emptyString 
// string

var emptyStringBools = !!emptyString;
//false – because the string is empty
typeof emptyStringBools 
// Boolean

var nulls = null;
typeof nulls
// object

var nullsBools = !!nulls;
//false
typeof nullsBools
// boolean

var under;
typeof under
// undefined

var underBools = !!under;
//false
typeof underBools
// boolean

Check to see if a variable has a value and if that value is usable.

How to : Add custom validation to a Mongoose Model

I need to add a custom validation to my mongoose model before I save to my Mongo Database.

Answer –

  • Custom validation is declared by passing a validation function.

Example

  • Note* Custom validation – method signature = validate(obj, [errorMsg])
 

var phoneValidator = [
 function(_value){ 
   return /d{3}-d{3}-d{4}/.test(v); 
 },
 "Please provide a valid phone number"
];

var customerSchema = new Schema(
 { 
   phone : 
   { 
     type: String, 
     validate: phoneValidator 
   }
 }
); 

var Customer = mongoose.model('customer', customerSchema);  

HOW TO: Incorporate an Email Service in your Node.js App with Nodemailer + SendGrid

In this tutorial we will use the github code provided from a previous post to get our Node + Express + Jade app up and running. Then we will talk about how to send emails using nodemailer and SendGrid.

Find the finished code on github here

Continue reading

HOW TO: Setup a Node.js Server using Express.js and Jade

In this tutorial I will cover the steps needed to get started with Node.js and Express.js from the ground up. Express does come with a generator but I do not go into generated Express apps. This tutorial is a bare bones example of getting Node, Express and Jade to work together to display a home page.

Continue reading

AngularJS : Gotchas and What to Look Out For

When dealing with Angular and you plan on expanding your code to production then it is very important you create your modules, controllers, services, factories and directives with the proper syntax. As with any piece of JavaScript you can write your code badly. Here are some best practices that should be put in place when writing your AngularJS code.
Continue reading

ADVANCED : JAVASCRIPT FUNCTIONS!

What are functions in JavaScript?

Functions are like any other item in JavaScript, functions are “OBJECTS”. Think about all the advanced things you can do with objects. Now apply that to functions. I have run across scripts written by all levels of UI developers and I rarely see anyone use a function to its full potential. Below I list some of the familiar and not so familiar features of a JavaScript function.

Continue reading