Thursday, March 2, 2017

Swift Programming (Server-Side) - Kick Start..!

In this post we are going to learn some exciting stuff about Swift programming. Most of us are knowing or heard about the Swift, an additional programming language apart form Objective-C which been offered by ‘Apple Computers’ for developers and programmers to build the native app. Here we will learn quick basics about how to use Swift in Server-Side programming and play around with the web component methods or services and their integrations at high level. Also achieve bit idea of incorporating services with the cloud functionality.

Moving forward, certainly we need to set-up an environment first into the development machine. To do that, refer below links. Please be noted I did this sample in my Mac machine, optionally, it can be achievable for other platforms too –for that I encourage to check guidelines and detailed contents available under same link pages!

Important Links:

Set-up Environment:
·       MacOS Sierra – 10.12.3
·       XCode – 8.2.1
·       Rested – 2.7
·       Swift – 3.0.2
·       Perfect - Server Side Swift [Open Source - powered by Swift Programming Language Framework]
-Perfect is an open source server side Swift framework that helps you write web apps and services using Swift 3. Learn how to get started with Perfect, and create your first server side Swift web app.
-Deploying Perfect in additional environments including Heroku, Amazon Web Services, Docker, Microsoft Azure, Google Cloud, IBM Bluemix CloudFoundry, and IBM Bluemix Docker – stay tuned for future post or refer above link documentation.


Now, lets start with the steps. Once you installed all above software and tools – mentioned under set-up environment. Open Terminal in Mac machine:

$ swift -- version
$ mkdir hello-perfect
$ cd hello-perfect
$ swift package init --type executable
$ swift package generate-xcodeproj
$ open ./hello-perfect.xcodeproj/





Update Package.swift file from here:




               $ swift package update



$ swift package generate-xcodeproj
$ mkdir webroot
$ touch webroot/hello.txt

Update hello.txt file from here:


$ swift package generate-xcodeproj

Set the active scheme -> press Edit scheme -> check ‘Use custom working directory’ and pick the path of the ‘webroot’ folder which does have ‘hello.txt’ file inside before building the app or run it.





  
Copy or update main.swift file from here:

$ swift package generate-xcodeproj

Check on console the status of HTTP Server – after building or running the app, should be started with the http port number (8080). Also, we can check into the browser by typing http://localhost:8080/. It will response the string message which been programmed under main.swift file. Alternatively, you can test the result of the app via ‘Rested tool’, which is available on Apple App store free to download. Below check the output response screenshot for visibility.




The purpose of this post to learn about how to kick start server-side programming skill using Perfect Open Source Framework (i.e., powered by Swift Programming Language) - using instance of HTTPServer API method calls such as, GET, POST and others. This skill will definitely help developers and programmers to use Swift language competency on both client and server side in parallel. Also developers can get benefits to develop native mobile applications in iOS platform without having additional language skills, the approach could be considered in hybrid method architecture too with the aspect of other platform choice.

To learn or explore more about advantages, benefits and possibility of the framework, I encourage to deep dive into the above-shared links, will be useful to kick start with. Thanks!


Saturday, February 18, 2017

Alexa skills from scratch with AWS Lambda, SSML and Amazon S3


Hello, everyone in this post I am going to teach about creating custom Alexa skills from scratch with AWS Lambda based code-functions and walk you through how to use SSML (Speech Synthesis Markup Language) and Amazon S3 inside the skills. As we have many geek code-snippets and webinar material available on cloud or web, but here I tried to cover all noted and important takeaway bullet points – help on creating sample skills in single flow without facing any obstacles or challenges in your development plus implementation phase.  For mobile, cloud & IoT devs and professional, it’s a piece of sample case study, which offers them to accelerate their existing skills from basic to expert level.

Here I recommend to use below links for setup-environment and source management of Alexa skills development and testing of them:

A. First, install Node/NPM into your development machine. Make sure it’s updated with the latest version.

B. Amazon Alexa Skills Kit:
  • The Intent Schema, Custom Slots, and Sample Utterances for this skill, as well as testing instructions are located at http://amzn.to/1LzFrj6

* Create an account first for accessing AWS cloud services.

C. Amazon Developer Console - Services: 

D. Echosim.io (Free Community Edition Beta) – Alexa Skill Testing Tool: In case you don’t have access of Amazon  Echo device, Echosim.io cloud tool help you on developing/testing your custom skills:  


E. Audacity – to create mp3 files in specified format:

Step1: Create an AWS account via Developer Console


Step2: Get Start With the Alexa Skills Kit (ASK)



Step3: Fill the skill-information, such as name, invocation name, ... press Next Get Start With the Alexa Skills Kit (ASK)


Step4: Create interaction model. Essentially all intent schema, slot types and possible utterances details and press Next


Step5: In Configuration page, select option as depicted below except text-field info (required ARN here to fill or linking). Make yourself pause in proceeding to Next button. 


Step6: Open AWS Lambda service via 'Developer Console' and 'Select blueprint'. You can create your own, but for this sample I chosen via filter 'alexa' keyword - 'alexa-skills-kit-color-expert' sample blueprint.  


Step7: Configure triggers in this phase. At this moment only pick the region 'US East (N. Virginia)' to create and test the skills freely. Currently APAC region doesn't allow to add a 'Alexa Skills Kit' ASK trigger that will invoke your function.


Step8: Follow as depicted below and mentioned in above step.


Step9: Follow here as mentioned in above step to invoke your function. Filter/Pick 'Alexa Skills Kit.


Step10: In this step, fill information of 'Configuration Information' page, such as function name, description and desired programming language from. Here I picked Node.js 4.3 


Step11: After you provide the code of your function, fill Lambda function handler and role as depicted below in screenshot. 


Step12: After you provide the code of your function, fill Lambda function handler and role as depicted below in screenshot. Press 'Actions' tab and choose 'Configure test event' option, then select 'Alexa Start Session'. Press 'Save and test' button to check the code function log and desired result outcome.


Step13: After you provide the code of your function, fill Lambda function handler and role as depicted below in screenshot. Here you'll get ARN - copy this one and paste in 'Step5' image and proceed for the Next (i.e., under Developer Console portal - created earlier). 


Step14: Once the above steps been completed and achieved execution result:succeeded. Then time to test the real skills app. Copy the 'strings' as highlighted below and test the app via in-built simulator. 


Step15: Developer can test the SSML based tag command under in-built 'Voice Simulator' option. use/modify SSML tags instead of 'Plaintext' inside the Lambda code function and hear the voice in response. SSML piece still on developing phase, currently support MPEG (.mp3) format in specified way. *Regarding how to create/record audio locally by using 'Audacity app' (i.e., link available above) and upload same content to Amazon S3 - will write separate post, stay tuned.


Step16: We can visualize the request and response in JSON format inside the window - depicted run-time sample in below screenshot.


Step17: Time to test the succeeded app response through Echo cloud device i.e., echosim.io. Press mike button on below screen and use 'utterances' to chat with Alexa Echo device.  Please be noted the echosim.io use same credential of AWS developer console to react/response of  programmed skills queries. Amazing one!


 

Wednesday, December 28, 2016

MEAN Setup and Start with @ Mac OSX..!


Dear Viewer,

This post will help and take you with the following possible steps in regard of installing stack tools associated with the MEAN development platform into your Mac OSX machine. I have seen there are plenty of posts available online for setting up work environment on various cross-platforms. My focus is also quite similar over here; but this write-up is only targeted for Mac OSX  users. Due to large volume API up-gradation and changes in technology cycles frequently many things might not go right in one short of your MEAN development set-up at Mac machine. With having said that, thought to write a post should be meaningful and helpful for target audience. I have been done setup implementation successfully in my Mac OS (i.e., macOS Sierra version 10.12.2). Lets start with the step of set-up implementation after getting bit idea/purpose of MEAN: 

MEAN (Mongo, Express, Angular, Node) - A simple, scalable and easy starting point for full stack JavaScript web development. The MEAN stack represents a thoroughly modern approach to web development: one in which a single language (JavaScript) runs on every tier of your application, from client to server to persistence.

Here understand the short purpose and definition of all stacks:

MongoDB is the leading NoSQL database, empowering businesses to be more agile and scalable. 

Express is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications.

AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop.

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications.


Before you begin, you should make sure you have installed all these prerequisites on your development machine.

The first is to change the owner of “/usr/local” to the with the following command:
$ sudo chown -R $USER /usr/local

It is not recommended to use the npm command with sudo.

The second would be to install the Apple command line developer tools. I think, the best way to do it is by installing XCode. Yes you then have another big IDE, but it installs much more. But this way, you don’t need to have a developer account. I did it by Installing XCode; you can just install the command line tools. XCode can be installed from the Apple AppStore.

Step 1:
Install either Macports or HomeBrew in your Mac machine for easy installation of tools and their dependencies.

The third is to install homebrew. Homebrew is the package manager for MAC. The installation is pretty easy, type the following in you command line:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then run the homebrew doctor like this:

$ brew doctor

After this, you can install tools like this:

$ brew install wget


Step 2: Installing Node.js / Nodes.js Package Manager (NPM)

Download & Install Node.js and the npm package manager, if you encounter any problems, you can also use this Github Gist to install Node.js. Again, we'll let HomeBrew do the heavy lifting:

$ brew install node

The npm executable is already included in the Node.js package.
Before continuing, let's make sure Node.js modules can be found by others (Caution: it's best to copy and paste these commands, as you'd lose the original contents of your .bashrc file if you typed > in place of >>):

$ echo 'export NODE_PATH="./node_modules:/usr/local/lib/node_modules"' >> ~/.bashrc && source ~/.bashrc

To check if the configuration is in effect, execute:

$ echo $NODE_PATH

You should see ./node_modules:/usr/local/lib/node_modules printed out below your command. If you use a different shell than Bash, simply replace ~/.bashrc with your shell configuration file.

Step 3: Installing MongoDB


If you haven't used HomeBrew before, simply execute the following command in a Terminal window:


We will install MongoDB through howebrew. Make sure homebrew is up-to-date by executing this command:

$ brew update

Then lets install MongoDB with the following command:

$ brew install mongodb

To run MongoDB, we have to create de default data directory for our MongoDB by:

$ mkdir -p /data/db

The user monogd must have write access.

Run MongoDB on the default port (27017) with:

$ mongod

Also you can use below command:

$ brew update && brew install mongodb

Homebrew will automatically install all the dependencies for you.

Also install some other package managers:

Install Bower

You’re going to use the Bower Package Manager to manage your front-end packages, in order to install it make sure you’ve installed Node.js and npm, then install bower globally using npm:

$ npm install -g bower

Install Grunt

You’re going to use the Grunt Task Runner to automate your development process, in order to install it make sure you’ve installed Node.js and npm, then install grunt globally using npm:

$ npm install -g grunt-cli

Install Yeoman

MeanJS uses Yeoman, the web’s scaffolding tool for modern web apps.

Install Yeoman globally with:

$ npm install -g yo

Install MeanJS generator for Yeoman

$ npm install -g generator-meanjs

You are now ready to get started with the MEAN.JS generator. The generator will help you create a MEAN.JS application, a CRUD module, Angular Module, and other AngularJS/Express entities. We’ll begin with the application generator.


Step 4: Generating a Fullstack app

Make a directory for your Back End Project projects. Assuming your desktop is your de facto workspace:

$ mkdir ~/Desktop/Back End Projects && cd ~/Desktop/Back End Projects

Now that all the preparations are in place, it's time for the main event:

$ yo angular-fullstack

Step 5: Initializing local Git repository

Tell Git not to track your database:

$ echo "data" >> .gitignore

Turn the directory in which your application is located into a Git repository by running the following commands:

$ git init && git add . && git commit -am 'initial commit'

Step 6: Starting MongoDB

To start MongoDB for the first time in your app's directory, run the following commands in your terminal:

$ mkdir data && echo 'mongod --config /usr/local/etc/mongod.conf --dbpath=data --rest "$@" --httpinterface' > mongod.sh && chmod a+x mongod.sh && ./mongod.sh

From this point on you can simply start MongoDB by executing ./mongod.sh. A few things to note:
        The .conf file directs mongod to write messages to a log file instead of stdout. To view the log, run the following in a separate Terminal tab: less /usr/local/var/log/mongodb/mongo.log.
        Since we're not on Cloud9, we don't need the --nojournal option. Journaling lets you recover the database in case of a mongod crash.
        You have to make a clean database for each project. If you copied the data directory over from an earlier project, mongod will fail to start. If that's the case, just rm -rf data && mkdir data && ./mongod.sh.

Step 7: Application Generator

Installing full stack tools

$ npm install -g express yo grunt grunt-cli generator-angular-fullstack bower

The application generator will help you create a fresh copy of a MEAN.JS application in your working folder. To create your MEAN application, navigate to a new project folder, and then use yo to generate your application:

$ yo meanjs

The generator will ask you a few questions about your new application and will generate it for you. When the installation process is over, you will be able to use grunt to run your new MEAN application:

Open a new Terminal tab by pressing T, and run the following command:

$ grunt serve

Grunt should automatically open your new Angular site's index page as soon as it finishes starting up.
Now you should be able to follow the rest of the Challenge instructions to push to GitHub and Heroku. Just ignore the part about SSH key (#33-36) and replace ~/workspace with your app directory's path.