I have a node.js object variable.
var json_sample =
{
'81': { length: '2', data: [ '11', '22' ] },
'82': { length: '1', data: [ 'ab' ] },
'83': { length: '2', data: [ '21', 'ac' ] },
'84': { length: '3', data: [ 'af', 'de', 'ad' ], }
};
When I do console.log(json_sample ), I can see the printed output.
However, when I want to use WebStorm debugger to view the object contents, I cannot see the content values. All I see is some properties of __proto__ which are not useful for my debugging.
Is this a limitation of WebStorm debugger in not being able to view object contents? Is one limited to using console.log() for debugging objects?
Look at the screenshot: it looks for me like this in the WebStorm 11.0.3 as well as WebStorm 2016.1
Could you provide a full code example?
For some reason, Webstorm debugger cannot show the object if the property name is a number.
This will not work on Webstorm.
var json_sample =
{
'81': { length: '2', data: [ '11', '22' ] },
'82': { length: '1', data: [ 'ab' ] },
'83': { length: '2', data: [ '21', 'ac' ] },
'84': { length: '3', data: [ 'af', 'de', 'ad' ], }
};
To show the object on Webstorm debugger, make this change.
var json_sample =
{
'aa': { length: '2', data: [ '11', '22' ] },
'bb': { length: '1', data: [ 'ab' ] },
'cc': { length: '2', data: [ '21', 'ac' ] },
'dd': { length: '3', data: [ 'af', 'de', 'ad' ], }
};
Related
I have the following custom JointJS element defined:
joint.shapes.webtp.BowTie = joint.dia.Element.define('webtp.BowTie',
{
size: { width: 400, height: 100 },
attrs: {
body: {
strokeWidth: 2,
stroke: '#000000',
fill: '#FFFFFF',
},
},
},
{
markup: [
{
tagName: 'g',
selector: 'g1',
attributes: {
class: 'rotatable',
},
children: [
{
tagName: 'g',
selector: 'g2',
attributes: {
class: 'scalable',
},
children: [
{
tagName: 'path',
selector: 'body',
attributes: {
d: 'm0,0l0,100l200,-25l200,25l0,-100l-200,25l-200,-25',
},
},
]
}
]
},
],
});
Using resize or scale on the shape does not resize it, however. It always ends up being 400x100.
I thought the issue originally was that it needed to be wrapped in a class="scalable" <g> but that didn't fix it either.
I also tried using<line>s instead of <path> but no luck.
Thanks!
The answer is in the refDResetOffset attribute, which (like the other ref custom attributes scales with the parent):
joint.shapes.webtp.BowTie = joint.dia.Element.define('webtp.BowTie',
{
attrs: {
body: {
strokeWidth: 2,
stroke: '#000000',
fill: '#FFFFFF',
refDResetOffset: 'm0,0l0,100l200,-25l200,25l0,-100l-200,25l-200,-25'
},
},
},
{
markup: [
{
tagName: 'g',
selector: 'g1',
attributes: {
class: 'rotatable',
},
children: [
{
tagName: 'g',
selector: 'g2',
attributes: {
class: 'scalable',
},
children: [
{
tagName: 'path',
selector: 'body',
},
]
}
]
},
],
});
I parse 'body' and save it to my var jsonNew getting 'results'.
let json = JSON.parse(body);
var jsonNew = json['results'];
jsonNew gives me:
[
{
address_components: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
],
formatted_address: 'Germany',
geometry: {
location: [Object],
location_type: 'ROOFTOP',
viewport: [Object]
},
place_id: '123',
plus_code: {
compound_code: '123',
global_code: '132+86'
},
types: [ 'street_address' ]
}
]
How can I access geometry.location to get 'lat' and 'lng'?
Which are the search terms I need to google to find the solution? What exactly do I have here?
"geometry" : {
"location" : {
"lat" : 1234,
"lng" : 12345
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 5555,
"lng" : 6666
},
"southwest" : {
"lat" : 555,
"lng" : 666
}
}
}
I was able to solve this getting [0] of the array - I am stupid!
var jsonNew = json['results'][0].geometry.location;
I need to assign the genre field to a new array but I am not sure how to only get that field, or how to call that field
var SpotifyWebApi = require('spotify-web-api-node');
var spotifyApi = new SpotifyWebApi();
spotifyApi.setAccessToken('-----');
spotifyApi.searchArtists('artist:queen')
.then(function(data) {
console.log('Search tracks by "queen" in the artist name', data.body.artists.items);
}, function(err) {
console.log('Something went wrong!', err);
});
This is the terminal when calling it.
I only want the first response.
PS C:\Users\g\Documents\js> node spotifyTest
Search tracks by "queen" in the artist name [ { external_urls:
{ spotify: 'https://open.spotify.com/artist/1dfeR4HaWDbWqFHLkxsg1d' },
followers: { href: null, total: 19579534 },
genres: [ 'glam rock', 'rock' ],
href: 'https://api.spotify.com/v1/artists/1dfeR4HaWDbWqFHLkxsg1d',
id: '1dfeR4HaWDbWqFHLkxsg1d',
images: [ [Object], [Object], [Object], [Object] ],
name: 'Queen',
popularity: 90,
type: 'artist',
uri: 'spotify:artist:1dfeR4HaWDbWqFHLkxsg1d' },
{ external_urls:
{ spotify: 'https://open.spotify.com/artist/3nViOFa3kZW8OMSNOzwr98' },
followers: { href: null, total: 1087117 },
genres: [ 'deep pop r&b', 'pop', 'r&b' ],
href: 'https://api.spotify.com/v1/artists/3nViOFa3kZW8OMSNOzwr98',
id: '3nViOFa3kZW8OMSNOzwr98',
images: [ [Object], [Object], [Object] ],
name: 'Queen Naija',
popularity: 68,
type: 'artist',
uri: 'spotify:artist:3nViOFa3kZW8OMSNOzwr98' } ]
You can access a field in a JSON object using the dot notation. Here's an example of replacing the genres of the first response with a new array.
let responseItems = [
{ external_urls: { spotify: 'https://open.spotify.com/artist/1dfeR4HaWDbWqFHLkxsg1d' },
followers: { href: null, total: 19579534 },
genres: [ 'glam rock', 'rock' ],
href: 'https://api.spotify.com/v1/artists/1dfeR4HaWDbWqFHLkxsg1d',
id: '1dfeR4HaWDbWqFHLkxsg1d',
images: [ [Object], [Object], [Object], [Object] ],
name: 'Queen',
popularity: 90,
type: 'artist',
uri: 'spotify:artist:1dfeR4HaWDbWqFHLkxsg1d'
},
{
external_urls: { spotify: 'https://open.spotify.com/artist/3nViOFa3kZW8OMSNOzwr98' },
followers: { href: null, total: 1087117 },
genres: [ 'deep pop r&b', 'pop', 'r&b' ],
href: 'https://api.spotify.com/v1/artists/3nViOFa3kZW8OMSNOzwr98',
id: '3nViOFa3kZW8OMSNOzwr98',
images: [ [Object], [Object], [Object] ],
name: 'Queen Naija',
popularity: 68,
type: 'artist',
uri: 'spotify:artist:3nViOFa3kZW8OMSNOzwr98'
}
];
let firstResponse = responseItems[0];
console.log(JSON.stringify(firstResponse.genres, null, 2));
let newGenres = [ 'rock', 'jazz' ];
firstResponse.genres = newGenres;
console.log(JSON.stringify(firstResponse.genres, null, 2));
This should show the following in the console:
[
"glam rock",
"rock"
]
[
"rock",
"jazz"
]
I use the following function within a Jenkins pipeline in order to process unit test results and display them in the Jenkins build page:
def check_test_results(String path) {
step([
$class: 'XUnitBuilder',
testTimeMargin: '3000',
thresholdMode: 1,
thresholds: [
[$class: 'FailedThreshold', failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '', unstableThreshold: ''],
[$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']
],
tools: [
[$class: 'JUnitType', deleteOutputFiles: true, failIfNotNew: false, pattern: path, skipNoTestFiles: false, stopProcessingIfError: true]
]
])
}
I'm aware to the fact that the J/Xunit results are displayed in the Jenkins build page but I want to have the ability to send a Slack notification (slack notifications are already configured and working) if a unit test fails and more importantly when it fails, is that possible?
You can use a try/catch for this for the suite of unit tests, but perhaps not individually.
def check_test_results(String path) {
try {
step([
$class: 'XUnitBuilder',
testTimeMargin: '3000',
thresholdMode: 1,
thresholds: [
[$class: 'FailedThreshold', failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '', unstableThreshold: ''],
[$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']
],
tools: [
[$class: 'JUnitType', deleteOutputFiles: true, failIfNotNew: false, pattern: path, skipNoTestFiles: false, stopProcessingIfError: true]
]
])
}
catch(error) {
slackSend message: error
}
}
and customize the Slack notification to your liking.
I want the goal completions by page from the Analytics API. The dates are the same, and sampling is off.
API:
{ kind: 'analytics#gaData',
id: 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga:90090243&dimensions=ga:hostname,+ga:pagePath&metrics=ga:users,ga:goalCompletionsAll,ga:goalValueAll&start-date=2015-01-05&end-date=2015-01-05',
query:
{ 'start-date': '2015-01-05',
'end-date': '2015-01-05',
ids: 'ga:90090243',
dimensions: 'ga:hostname, ga:pagePath',
metrics: [ 'ga:users', 'ga:goalCompletionsAll', 'ga:goalValueAll' ],
'start-index': 1,
'max-results': 1000,
samplingLevel: 'HIGHER_PRECISION' },
itemsPerPage: 1000,
totalResults: 10,
selfLink: 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga:12345678&dimensions=ga:hostname,+ga:pagePath&metrics=ga:users,ga:goalCompletionsAll,ga:goalValueAll&start-date=2015-01-05&end-date=2015-01-05',
profileInfo:
{ profileId: '12345678',
accountId: '12345678',
webPropertyId: 'UA-12345678-1',
internalWebPropertyId: '12345678',
profileName: 'All Web Site Data',
tableId: 'ga:90090243' },
containsSampledData: false,
columnHeaders:
[ { name: 'ga:hostname',
columnType: 'DIMENSION',
dataType: 'STRING' },
{ name: 'ga:pagePath',
columnType: 'DIMENSION',
dataType: 'STRING' },
{ name: 'ga:users', columnType: 'METRIC', dataType: 'INTEGER' },
{ name: 'ga:goalCompletionsAll',
columnType: 'METRIC',
dataType: 'INTEGER' },
{ name: 'ga:goalValueAll',
columnType: 'METRIC',
dataType: 'CURRENCY' } ],
totalsForAllResults:
{ 'ga:users': '155',
'ga:goalCompletionsAll': '0',
'ga:goalValueAll': '0.0' },
rows:
[ [ 'mydomain.com', '/', '1', '0', '0.0' ],
[ 'mydomain.com',
'/brand-business-bundle',
'1',
'0',
'0.0' ],
[ 'mydomain.com',
'/brand-business-internet',
'1',
'0',
'0.0' ],
[ 'mydomain.com', '/business-bundle', '1', '0', '0.0' ],
[ 'mydomain.com',
'/business-fiber-internet',
'22',
'0',
'0.0' ],
[ 'mydomain.com', '/business-internet', '37', '0', '0.0' ],
[ 'mydomain.com', '/business-phone', '84', '0', '0.0' ],
[ 'mydomain.com', '/privacy-policy', '1', '0', '0.0' ],
[ 'mydomain.com',
'/small-business-internet',
'6',
'0',
'0.0' ],
[ 'co.lumb.co', '/', '1', '0', '0.0' ] ] }
Here's what I see in the Analytics dashboard:
Things I have tried:
Different sampling levels (no effect)
Removing other dimensions from the query (total is correct, but I want per-page data)
Different dates (no effect)
Why am I getting back such low values from the API when the dashboard shows otherwise?
The most befuddling thing about this was that it worked for about 2 months and suddenly broke. I suspect a bug was introduced to the Analytics API.
The workaround is to use ga:goalCompletionLocation instead of ga:pagePath. I call it a workaround instead of a solution because you cannot combine ga:goalCompletionLocation with much else as far as metrics go.