Node Rest Client

Making REST calls
Each API call takes a set of data in JSON format and returns data also in JSON format. The exception to this is a GET request, which instead takes its data as a query string. I didn’t want to have to deal with this detail, so I cobbled together a wrapper function that would produce data in the correct format and issue the request.

var querystring = require('querystring');
var https = require('https');

var host = 'www.thegamecrafter.com';
var username = 'JonBob';
var password = '*****';
var apiKey = '*****';
var sessionId = null;
var deckId = '68DC5A20-EE4F-11E2-A00C-0858C0D5C2ED';

function performRequest(endpoint, method, data, success) {
  var dataString = JSON.stringify(data);
  var headers = {};
  
  if (method == 'GET') {
    endpoint += '?' + querystring.stringify(data);
  }
  else {
    headers = {
      'Content-Type': 'application/json',
      'Content-Length': dataString.length
    };
  }
  var options = {
    host: host,
    path: endpoint,
    method: method,
    headers: headers
  };

  var req = https.request(options, function(res) {
    res.setEncoding('utf-8');

    var responseString = '';

    res.on('data', function(data) {
      responseString += data;
    });

    res.on('end', function() {
      console.log(responseString);
      var responseObject = JSON.parse(responseString);
      success(responseObject);
    });
  });

  req.write(dataString);
  req.end();
}

https://rapiddg.com/blog/calling-rest-api-nodejs-script

https://www.npmjs.com/package/node-rest-client

Share

Cesium – AJAX to update InfoBox ?


var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

var handlerA = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  handlerA.setInputAction(function(click) {
    var pickedObject = scene.pick(click.position);
    if (Cesium.defined(pickedObject)) {
      $.ajax({

        type: 'GET',
        url: 'InfoBox.php',
        data: (pickedObject.id.id).val(),

        success: function(result) {
          pickedObject.id.description = "The temperatur of " + result.town + " is " + result.temp + " degrees...";
        }
      }); 
    }
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

pickedObject.id is the entity.

Share

cesium – Updating a CZML ‘description’ upon opening the InfoBox ?

updating-CZML-description

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

//------ create CZML ------

var czml = 
 [{"id" : "document",
 "version" : "1.0"
 },{"id" : "Boston",
 "label":{"text":"Boston"},
 "position":{"cartographicDegrees":[-71.0589,42.3601,0]},
 "description":"Boston is a city...",
 },{"id" : "New York City",
 "label":{"text":"New York"},
 "description":"New York is a city...",
 "position":{"cartographicDegrees":[-74.0059,40.7127,0]},
 }];

var promise = Cesium.CzmlDataSource.load(czml);
promise.then(function(dataSource) {
 viewer.dataSources.add(dataSource);

   //------ Get the array of entities
 var entities = dataSource.entities.values;
   //------ Loop entities
   for (var i = 0; i < entities.length; i++) {
     var entity = entities[i];
     var name = entity.label;
     entity.label.translucencyByDistance = new Cesium.NearFarScalar(100000,1.0,500000,0.0);
   }
}).otherwise(function(error){
   //------ Display error
 window.alert(error);
});

    //------ Use SSEH to update to current description

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(click) {
  var pickedObject = scene.pick(click.position);
  if (Cesium.defined(pickedObject)) {

    pickedObject.id.description =  'The current temperature is...';
   }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);    

Setting the description property should update it.  Here is an example:


var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(click) {
    var pickedObject = scene.pick(click.position);
    if (Cesium.defined(pickedObject)) {
        pickedObject.id.description = 'New description';
    }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);


pickedObject.id is the entity.
Share

cesium – How to enable javascript in InfoBox ?

phpmind-cesiumjs-show-name

The InfoBox does indeed run in an iframe for security and sanitation purposes. You can remove all restrictions by calling the below line of code after creating the view:

viewer.infoBox.frame.removeAttribute('sandbox');

Only do this if you are in complete control of the data that will be loaded into the InfoBox, otherwise it is a security issue.

You can style the infoBox just as easy by injecting any css you want into the viewer.infoBox.frame for example:

            var cssLink = frameDocument.createElement("link");
            cssLink.href = buildModuleUrl('Path/To/Your/CSS/File.css');
            cssLink.rel = "stylesheet";
            cssLink.type = "text/css";
            viewer.infoBox.frame.contentDocument.head.appendChild(cssLink);

By default, we inject the contents of Widgets/InfoBox/InfoBoxDescription.css

You can also style outer InfoBox properties by overriding the CSS classes defined in Widgets/InfoBox/InfoBox.css in your own apps css file. I’m not sure if you’ll be able to add draggable support in this way, but you can do a bunch of other stuff.

If you want to replace the infoBox completely, then simply pass “infoBox: false” to the Viewer constructor. It’s then up to you to bring up your own widget when an entity is selected. The InfoBox simply displayed the content of the entity.description property. You could copy/paste the existing InfoBox code as a starting point.

http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/

Share

Export php array to CSV – Download CSV File

Export php array to CSV
CSV (comma-separated values) is the most widely supported format for transferring tabular data. Exporting data in CSV format is very common in web applications. This simple example will help you get started with CSV and PHP. The main goal is to create a simple way to export data from your website or web application into a CSV that can be downloaded by the user.


    $data = array(
        array('name' => 'A', 'mail' => 'a@gmail.com', 'age' => 43),
        array('name' => 'C', 'mail' => 'c@gmail.com', 'age' => 24),
        array('name' => 'B', 'mail' => 'b@gmail.com', 'age' => 35),
        array('name' => 'G', 'mail' => 'f@gmail.com', 'age' => 22),
        array('name' => 'F', 'mail' => 'd@gmail.com', 'age' => 52),
        array('name' => 'D', 'mail' => 'g@gmail.com', 'age' => 32),
        array('name' => 'E', 'mail' => 'e@gmail.com', 'age' => 34),
        array('name' => 'K', 'mail' => 'j@gmail.com', 'age' => 18),
        array('name' => 'L', 'mail' => 'h@gmail.com', 'age' => 25),
        array('name' => 'H', 'mail' => 'i@gmail.com', 'age' => 28),
        array('name' => 'J', 'mail' => 'j@gmail.com', 'age' => 53),
        array('name' => 'I', 'mail' => 'l@gmail.com', 'age' => 26),
    );

$fileName_1 = 'Manifest.csv';
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header('Content-Description: File Transfer');
        header("Content-type: text/csv");
        header("Content-Disposition: attachment; filename={$fileName_1}");
        header("Expires: 0");
        header("Pragma: public");
        $fh1 = @fopen( 'php://output', 'w' );
        $headerDisplayed1 = false;

        foreach ( $data as $data1 ) {
            // Add a header row if it hasn't been added yet
            if ( !$headerDisplayed1 ) {
                // Use the keys from $data as the titles
                fputcsv($fh1, array_keys($data1));
                $headerDisplayed1 = true;
            }

            // Put the data into the stream
            fputcsv($fh1, $data1);
        }
    // Close the file
        fclose($fh1);
    // Make sure nothing else is sent, our file is done
        exit;

Share

Build Alexa-enabled Apps

This is reference of my collection from different sources.

Image From Wikipedia

Skill to learn – 

Custom Slot Types
Writing Alexa Skills with Node.js
Deployment
Integrating Testing an Alexa Skill
Alexa Cards Interaction: displaying data on cards
Voice User Interface Design
Speech Synthesis Markup Language
Internet of Things Interaction
Account Linking
Skill Submission
Providing Updates
No preference

API to use for testing or for real  –  http://services.faa.gov/docs/services/

Useful links –

Developers Resources For ASK & AVS Developers

Training / Tutorials

Amazon Echo Dev Portal

Amazon Alexa Dev Portal

Amazon Web Services Events & Webinars Portal – subscribe via RSS to be notified of new events in your area(s) of interest

Udemy – Introduction to Voice Design with Amazon’s Alexa

Big Nerd Ranch – Alexa Skills Kit – course(s) not yet released, but you can sign up to be notified when available on the linked page

w3schools JSON Tutorial

Anythings Alexa Skills Kit Tutorial

ToBuildSomething’s Amazon Alexa Skills Kit SDK: The Ultimate Guide

Ruuvu: Building An Alexa Skill For IMDB Ratings With Alexa-app

 

ASK / Alexa Dev Communities

Amazon Developer Forum – Alexa Skills Kit

Amazon Developer Forum – Alexa Voice Service

Stack Overflow – Latest Alexa Skills Kit Questions

Stack Overflow – Latest Alexa Skills Questions

Stack Overflow: Latest Alexa Voice Service Questions

Seattle Area Meetup for Alexa Devs

NYC Area Meetup for Alexa Devs

Los Angeles Area Meetup for Alexa Devs

Boston Area Meetup for Alexa Devs

Columbus Area Meetup for Alexa Devs

 

Sample Code / Developer Toolkits

Matt Kruse’s Alexa App Node Module

Nicholas Clawson’s Alexa-bility Skills Framework For Node:
Interactive Demo
Documentation
Examples
Toolkit

Amazon’s Github Repository for Alexa Skills Kit Dev in Java

Amazon’s Github Repository for Alexa Skills Kit Dev in Javascript

Anjishnu’s Github Repository: Python ASK Developer Toolkit

Rocktavious’s Github Repository: Django ASK Developer Toolkit

stefann42’s Github Repository: .NET ASK Developer Toolkit

develpr’s Github Repository: Laravel & Lumen Classes to Make ASK Development Easier

 

Miscellaneous

Amazon’s Alexa Device Source Code Repository

MSDN Speech Synthesis Markup Language (SSML) Reference Library

JSON.org JSON Reference Library

Nodejs.org Node Reference Library

ASK Developer Wiki on Reddit

My own developer guide to Using Session Attributes in Javascript – free pdf, can be printed or downloaded

How To Check Amazon Server Status, Streaming Service Status

Amazon Alexa/Echo Team Twitter Account

Amazon Alexa Tech Business Developer Marion Desmazieres Twitter Account

Share

php how to return all dates between two dates in an array ?

add($interval);

    $period = new DatePeriod(
         new DateTime($start),
         $interval,
         $realEnd
    );

    foreach($period as $date) { 
        $array[] = $date->format('Y-m-d'); 
    }

    return $array;
}

// Call the function
$dates = getDatesFromRange('2015-10-01', '2015-12-05');

// Print the output
print_r($dates);

Array
(
    [0] => 2015-10-01
    [1] => 2015-10-02
    [2] => 2015-10-03
    [3] => 2015-10-04
    [4] => 2015-10-05
    [5] => 2015-10-06
    [6] => 2015-10-07
    [7] => 2015-10-08
    [8] => 2015-10-09
    [9] => 2015-10-10
    [10] => 2015-10-11
    [11] => 2015-10-12
    [12] => 2015-10-13
    [13] => 2015-10-14
    [14] => 2015-10-15
    [15] => 2015-10-16
    [16] => 2015-10-17
    [17] => 2015-10-18
    [18] => 2015-10-19
    [19] => 2015-10-20
    [20] => 2015-10-21
    [21] => 2015-10-22
    [22] => 2015-10-23
    [23] => 2015-10-24
    [24] => 2015-10-25
    [25] => 2015-10-26
    [26] => 2015-10-27
    [27] => 2015-10-28
    [28] => 2015-10-29
    [29] => 2015-10-30
    [30] => 2015-10-31
    [31] => 2015-11-01
    [32] => 2015-11-02
    [33] => 2015-11-03
    [34] => 2015-11-04
    [35] => 2015-11-05
    [36] => 2015-11-06
    [37] => 2015-11-07
    [38] => 2015-11-08
    [39] => 2015-11-09
    [40] => 2015-11-10
    [41] => 2015-11-11
    [42] => 2015-11-12
    [43] => 2015-11-13
    [44] => 2015-11-14
    [45] => 2015-11-15
    [46] => 2015-11-16
    [47] => 2015-11-17
    [48] => 2015-11-18
    [49] => 2015-11-19
    [50] => 2015-11-20
    [51] => 2015-11-21
    [52] => 2015-11-22
    [53] => 2015-11-23
    [54] => 2015-11-24
    [55] => 2015-11-25
    [56] => 2015-11-26
    [57] => 2015-11-27
    [58] => 2015-11-28
    [59] => 2015-11-29
    [60] => 2015-11-30
    [61] => 2015-12-01
    [62] => 2015-12-02
    [63] => 2015-12-03
    [64] => 2015-12-04
    [65] => 2015-12-05
)
Share

How to Detecting Ad Blockers on Your Website using JavaScript ?

ad_blocker_phpmind
This code snippet will display a short message to the user on every page load if ad blockers in place.

It encourages readers to disable ad blocking from your site, which is as easy for them as a couple of clicks.

 
Share