Spotify: Find playlists by songs in the playlist - spotify

Let's say I want to find all user playlists that include the track 'Roygbiv' by Boards of Canada. Is it possible to modify the function below to make this happen?
var mySearch = Search.search('Roygbiv');
mySearch.playlists.snapshot().done(function(p){
searchPlaylists.innerHTML = '<h4>Playlists (' + p.length + ')</h4>';
var playlistsResults = [];
for (var i = 0, l = Math.min(p.range.length, maxResults); i < l; i++) {
playlistsResults.push('' + p.get(i).name + '');
}
searchPlaylists.innerHTML += '<p>' + playlistsResults.join(', ') + '...</p>';
});

Related

How to get nlapiGetOldRecord() sublist value

I am trying to get nlapiGetOldRecord sublist values.
var record= nlapiGetOldRecord();
var testCount= record.getLineItemCount('recmachcustrecord_test');
The above linecount api is working and output the number of lines. But when i try to get its line item values it's giving following error "Cannot find function nlapiGetLineItemValue in object nlobjRecord.". My code.
for (var i = 1; i <= testCount; i++) {
var name= record.nlapiGetLineItemText('recmachcustrecord_test', 'custrecord_name', i);
var quantity = record.nlapiGetLineItemValue('recmachcustrecord_test', 'custrecord_qty', i);
nlapiLogExecution('DEBUG', 'Detail: ', name + ' and ' + quantity);
}
I have found the solution. Basically i was trying to get line item text/value using nlapiGetLineItemText api and which is not nlobjRecord api. so for sublist nlobjRecord getLineItemText api works.
var record= nlapiGetOldRecord();
var testCount= record.getLineItemCount('recmachcustrecord_test');
for (var i = 1; i <= testCount; i++) {
var name= record.getLineItemText('recmachcustrecord_test', 'custrecord_name', i);
var quantity = record.getLineItemValue('recmachcustrecord_test', 'custrecord_qty', i);
nlapiLogExecution('DEBUG', 'Detail: ', name + ' and ' + quantity);
}

FOR LOOP in Node js needing the result of the previous iteration

I need to do a loop in Node JS where I need the result of the previous iteration.
function jsonParser(txt_file, cb) {
var perc = 0;
lines = txt_file.split('\n');
insert_communication = 'INSERT INTO communication (account_id, contact_id, type_com_id, coin_id, com_datetime, ' +
'destination_key, destination_st, duration, cost, description, discount) VALUES ';
insert_internet = 'INSERT INTO internet_data (account_id, contact_id, type_com_id, coin_id, com_datetime, ' +
'duration, cost, description, discount) VALUES ';
for (let i = 2; i < lines.length; i++) {
readTextFile2(lines[i], function (cb) {
if (cb[0] == "communication")
insert_communication += cb[1] + ',';
if (cb[0] == "internet")
insert_internet += cb[1] + ',';
});
}
cb(insert_communication);
}
How I am supposed to achieve this?
Thanks
for (let i = 2; i < lines.length; i++) {
const previous = lines[i - 1 ];
const hasPrevious = !!previous;
if(hasPrevious) {
//ok you have a previously value, now you could use it
}
readTextFile2(lines[i], function (cb) {
if (cb[0] == "communication")
insert_communication += cb[1] + ',';
if (cb[0] == "internet")
insert_internet += cb[1] + ',';
});
}

SP.NavigationNode.get_isVisible() broken?

I need to read the "Top Nav", the "Children Nodes" and check if each node is visible.
I am using JSOM to accomplish this. Everything is working fine except for the get_isVisible() function. It always returns true. MSDN: http://msdn.microsoft.com/en-us/library/office/jj246297.aspx
I am on a publishing site in 2013 and I know some of the items are hidden. (My web and context are defined outside of this snippet)
var visParents = [], visChildren = [];
var topNodes = web.get_navigation().get_topNavigationBar();
context.load(topNodes);
context.executeQueryAsync(onQuerySucceeded, onQueryFailed)
function onQuerySucceeded() {
var nodeInfo = '';
var nodeEnumerator = topNodes.getEnumerator();
while (nodeEnumerator.moveNext()) {
var node = nodeEnumerator.get_current();
nodeInfo += node.get_title() + '\n';
if (node.get_isVisible())
visParents.push(node);
}
console.log("Current nodes: \n\n" + nodeInfo);
console.log("Visible Parents", visParents)
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
It is a known issue, it seems that SP.NavigationNode.isVisible property does not correspond to the property that indicates whether navigation node is hidden or shown.
Please refer "Hidden" property of SPNavigationNode for a details
The following function demonstrates how to retrieve hidden node Urls:
function getGlobalNavigationExcludedUrls(Success,Error)
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var subwebs = web.get_webs();
var pagesList = web.get_lists().getByTitle("Pages");
var pageItems = pagesList.getItems(SP.CamlQuery.createAllItemsQuery());
var allProperties = web.get_allProperties();
context.load(web);
context.load(subwebs);
context.load(allProperties);
context.load(pageItems);
context.executeQueryAsync(
function() {
var excludedIds = allProperties.get_item('__GlobalNavigationExcludes').split(';');
var exludedUrls = [];
for (var i = 0; i < excludedIds.length - 1; i++ )
{
for (var j = 0; j < subwebs.get_count(); j++ )
{
var subweb = subwebs.getItemAtIndex(j);
if(subweb.get_id().toString() == excludedIds[i]){
exludedUrls.push(subweb.get_serverRelativeUrl());
break;
}
}
for (var j = 0; j < pageItems.get_count(); j++ )
{
var pageItem = pageItems.getItemAtIndex(j);
if(pageItem.get_item('UniqueId').toString() == excludedIds[i]){
exludedUrls.push(web.get_serverRelativeUrl() + pageItem.get_item('FileRef'));
break;
}
}
}
Success(exludedUrls);
},
Error
);
}
//Usage: print excluded nodes Urls
getGlobalNavigationExcludedUrls(function(excludedNodeUrls){
for (var j = 0; j < excludedNodeUrls.length; j++ )
{
console.log(excludedNodeUrls[j]);
}
},
function(sender,args){
console.log(args.get_message());
});

how to correctly clone an object in WinJS

I have this function for create objects in WinJS:
function BiometricSignatureData() {
this.averageSpeed = "";
this.pressure = new Array();
this.location = new Array();
this.timestamp = new Array();
this.speed = new Array();
this.evt = new Array();
this.spaces = 0;
this.attackPoints = 0;
this.finalPoints = 0;
this.signatureAddress = "";
this.restartObject =
function () {
this.pressure = new Array();
this.location = new Array();
this.timestamp = new Array();
this.averageSpeed = "";
this.speed = new Array();
this.evt = new Array();
this.spaces = 0;
this.attackPoints = 0;
this.finalPoints = 0;
this.signatureAddress = "";
}
this.printBiometricValuesOnRealTime =
function (pressure, location, averageSpeed, spaces, attackPoints, finishPoints) {
pressure.value = this.pressure[this.pressure.length -1];
location.value = "{" + this.location[this.location.length - 1] + "}";
averageSpeed.value = this.averageSpeed;
spaces.value = this.spaces;
attackPoints.value = this.attackPoints;
finishPoints.value = this.finalPoints;
}
}
Basicly creates BiometricSignatureData-type objects with 2 methods
restartObject
printBiometricValuesOnRealTime
and then I created two instances of the same object
var biometricObject = new BiometricSignatureData();
var biometricObjectBackup = new BiometricSignatureData();
my first instance (biometricObject) is filled with data, then I want to clone (not by reference) this instance in my second instance (biometricObjectBackup) by doing this:
function cloneObject(from, to) {// extends 'from' object with members from 'to'. If 'to' is null, a deep clone of 'from' is returned
if (from == null || typeof from != "object") return from;
if (from.constructor != Object && from.constructor != Array) return from;
if (from.constructor == Date || from.constructor == RegExp || from.constructor == Function ||
from.constructor == String || from.constructor == Number || from.constructor == Boolean)
return new from.constructor(from);
to = to || new from.constructor();
for (var name in from) {
to[name] = typeof to[name] == "undefined" ? cloneObject(from[name], null) : to[name];
}
return to;
}
filling second instance with first instance info
console.log("original Array: " + biometricObject.evt.length + ", backup Array: " + biometricObjectBackup.evt.length);
biometricObjectBackup = cloneObject(biometricObject);
console.log("original Array: " + biometricObject.evt.length + ", backup Array: " + biometricObjectBackup.evt.length);
biometricObject.restartObject();
console.log("original Array: " + biometricObject.evt.length + ", backup Array: " + biometricObjectBackup.evt.length);
put three console.log to follow the behavior of the objects getting next output:
original Array: 10, backup Array: 0
original Array: 10, backup Array: 10
original Array: 0, backup Array: 0
If I restart my original object, the second one (the cloned) cleans itself as well, how to do this right???
thanks for the support
you may try this:
var BiometricSignatureData = {
averageSpeed: "",
pressure: new Array(),
location: new Array(),
timestamp: new Array(),
speed: new Array(),
evt: new Array(),
spaces: 0,
attackPoints: 0,
finalPoints: 0,
signatureAddress: "",
restartObject :
function () {
this.pressure = new Array();
this.location = new Array();
this.timestamp = new Array();
this.averageSpeed = "";
this.speed = new Array();
this.evt = new Array();
this.spaces = 0;
this.attackPoints = 0;
this.finalPoints = 0;
this.signatureAddress = "";
},
printBiometricValuesOnRealTime:
function (pressure, location, averageSpeed, spaces, attackPoints, finishPoints) {
pressure.value = this.pressure[this.pressure.length - 1];
location.value = "{" + this.location[this.location.length - 1] + "}";
averageSpeed.value = this.averageSpeed;
spaces.value = this.spaces;
attackPoints.value = this.attackPoints;
finishPoints.value = this.finalPoints;
}
}
var BiometricSignatureDataBackup;
clone function is the same
and the last part:
BiometricSignatureDataBackup = cloneObject(BiometricSignatureData);
console.log("original Array: " + biometricObject.evt.length + ", backup Array: " + biometricObjectBackup.evt.length);
BiometricSignatureData.restartObject();
console.log("original Array: " + BiometricSignatureData.evt.length + ", backup Array: " + BiometricSignatureDataBackup.evt.length);

Asterisk 11 active calls event over AMI

Data I would like to have:
Num From , Num To , Duration, Codec, Context, Hold status
ofc in realtime update
I using node.js + nami
what the best way to get this information?
tried use an action Status(), but this gives me not full information about call and if I run it every second browser dies.
here is what I have:
updateCallList();
function updateCallList() {
socket.emit('GET_ACTIVE_CALLS', function(calls) {
$("#callsList").find("tr:gt(0)").remove();
if (calls.response != 'Success') return;
var calls = calls.events;
for (call in calls) {
if (calls[call].privilege == 'Call') {
var callFrom = calls[call].calleridnum + '<' + calls[call].calleridname + '>';
var callTo = calls[call].extension;
var callDuration = calls[call].seconds;
var callRoute = calls[call].context;
var tmpRow = '<tr>';
tmpRow = tmpRow + '<td>' + callFrom + '</td>';
tmpRow = tmpRow + '<td>' + callTo + '</td>';
tmpRow = tmpRow + '<td>' + callDuration + '</td>';
tmpRow = tmpRow + '<td>' + callRoute + '</td>';
tmpRow = tmpRow + '</tr>';
$('#callsList tr:last').after(tmpRow);
}
}
setInterval(function(){
updateCallList();
},1000);
});
}
server side
socket.on('GET_ACTIVE_CALLS', function (callback) {
action = new namiLib.Actions.Status();
nami.send(action, function (response) {
callback(response);
});
});
You need start daemon which will collect NewExten, Link, Unlink, Hangup events and create list of channels.
http://www.voip-info.org/wiki/view/asterisk+manager+events
Also you can do action command with "core show channels" "core show channel XXXXX", but asterisk will die if you do alot of that.
http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Command

Resources