Skip to content

Instantly share code, notes, and snippets.

View jw-jenrise's full-sized avatar

John Wilfred Adaikalam Selvaraj jw-jenrise

View GitHub Profile
@jw-jenrise
jw-jenrise / AWS - Proper noun filtering
Last active June 27, 2019 01:03
AWS - Proper noun filtering
// AWS Comprehence
//http://www.jsonquerytool.com/
var filteredToken = _.filter(
input.SyntaxTokens,
function(token) {
return token.PartOfSpeech.Tag == "PROPN" && token.PartOfSpeech.Score > 0.95;
}).sort(function(t1,t2){
return t2.PartOfSpeech.Score - t1.PartOfSpeech.Score;
}).map(function(token){
return {
var promiseRemoteData = new Promise(function(resolve,reject){
// 1. Perform ASYNC operation
// 2. On completion of remote operation call
// - resolve to notify success (pass any values that is required)
// - reject to notify error condition
}
function getPromiseRemoteData(url){
var promiseRemoteData = new Promise(function(resolve,reject){
// Initiate call
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; //Uncomment this line if you are using it in node js environment.
// 1. Create the request
var xhr = new XMLHttpRequest();
// 2. Create the URL
var delay = Math.floor(Math.random() * 9) + 1;
function getRemoteData(url){
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; //Uncomment this line if you are using it in node js environment.
// 1. Create the request
var xhr = new XMLHttpRequest();
// 2. Create the URL
var delay = Math.floor(Math.random() * 9) + 1;
// Open the URL
function printRemoteData(url, message){
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; //Uncomment this line if you are using it in node js environment.
var xhr = new XMLHttpRequest();
var delayedUrl = url + "?delay=" + (Math.floor(Math.random() * 9) + 1);
console.log(delayedUrl);
xhr.open("GET", delayedUrl, true);
xhr.onload = function(){
if (message){
console.log(message);
}
console.log("Begin example - 6");
// Adding of three numbers using a function
// Define an add function that can work for three or less arguments
function add(a,b,c){
var d = ( (a) ? a : 0 ) + // Using ternary operator we can check the
( (b) ? b : 0 ) + // Truthy/Falsy of the parameter and then
( (c) ? c : 0 ) ; // Substitue with numeral zero so that NaN is avoided.
return d;
}
console.log("Begin example - 5");
// Adding of three numbers using a function
// Define an add function
function add(a,b,c){
return a + b + c;
}
// EXTRA ARGUMENT IS IGNORED
var e = add(1,2,3,4);
console.log("Begin example - 4");
// Adding of three numbers using a function
// Define an add function
function add(a,b,c){
return a + b + c;
}
// Calling the function
var d = add(10,20,30);
console.log("Begin example - 3");
var p = 0; // Try replacing this with null, undefined, NaN
console.log("Value of p = " + p);
console.log("Boolean equivalent of p = " + Boolean(p)); // Truthy or Falsy value
// Example usage of truthy or falsy
if (p){
console.log("I am happy");
} else {
console.log("I am not sure");
}
// Variables declared by default are undefined
console.log("Begin example - 2");
var x,y = 10;
console.log("Value of x = " + x); // X value is not defined, hence has undefiend
console.log("Value of y = " + y);
// Types demystified
console.log("Type of x = " + typeof(x)); // Type of undefined is undefined.
console.log("--");