Is there a way to get the market cap RANK of companies? - google-play

I looked on rapidapi and other places on the net, but I couldn't find it.
//response example:
{
symbol:"AAPL",
rank:1
{

Related

Unable to add remote file node to parent node Gatsby

I'm trying to add File nodes to a gatsby source that doesn't create them automatically (gatsby-source-tumblr in this case). Every node has an array of images associated that I want to download and later convert using Gatsby-Image.
Here's my code so far:
exports.onCreateNode = async ({
node,
actions: { createNode, createNodeField },
store,
cache,
getCache,
createNodeId,
}) => {
if (node.internal.type === `TumblrPost`) {
const pathValue = "/posts/" + node.slug
createNodeField({
node,
name: `path`,
value: pathValue,
})
}
if (
node.internal.type === `TumblrPost` &&
node.photos &&
node.photos.length
) {
await node.photos.map(async photo => {
let fileNode
try {
fileNode = await createRemoteFileNode({
url: photo.original_size.url,
parentNodeId: node.id,
getCache,
createNode,
cache,
createNodeId,
store,
})
// Adds a field `localFile` to the node
// ___NODE appendix tells Gatsby that this field will link to another node
if (fileNode) {
photo.localFile___NODE = fileNode.id
}
} catch (err) {
console.warn(err)
}
})
}
}
As suggested in multiple tutorials I've found, I'm using createRemoteFileNode to download the images and add them as file nodes. This part works, I can see the images being downloaded, and there's a number of items visible in GraphiQL under the allImageSharp category.
However I can't seem to get the association with the parent node to work. Doing something like photo.localFile___NODE = fileNode.id does not seem to have any effect. Experimenting with adding even one image to the parent node (post) doesn't seem to work: When looking at the post node in the GraphiQL inspector, there is no trace of the File node.
I have the feeling I might be missing something obvious, but I've been fiddling with this for hours now and can't seem to figure it out.
Any help would be really appreciated!
I found this answer that helped me fix it. I think the problem was with how I was handling the async loops. I copied the code in which it sets product.images (in that other user's codebase) and adapted it to mine, it worked. I'm guessing the _ await Promise.all_ was the key.
Which is weird to me, because some point I brought in the fantastic async library (something I'm more familiar with than await etc.) to make sure there weren't any issues with the looping, and that didn't work. Ah well, such is life. I'm glad it works now.

GitHub v4 API: Calculate content specific reaction count on a comment

I am trying to get the reaction count for each content using the Github v4 API (GraphQL). Can anyone suggest how can I achieve this?
Github supports the following reactions:
THUMBS_UP
THUMBS_DOWN
LAUGH
HOORAY
CONFUSED
HEART
ROCKET
EYES
For each reaction, I want a count which denotes the number of people who reacted. For eg. I am referring to this comment -> #2190.
Github API provides a feature called reaction group. Refer to the following query...
{
repository(owner: "sindresorhus", name: "refined-github") {
issue(number: 2190) {
reactionGroups {
content
users {
totalCount
}
}
}
}
}
Hope this solves your problem!

Get room/rooms of client [duplicate]

I can get room's clients list with this code in socket.io 0.9.
io.sockets.clients(roomName)
How can I do this in socket.io 1.0?
Consider this rather more complete answer linked in a comment above on the question: https://stackoverflow.com/a/24425207/1449799
The clients in a room can be found at
io.nsps[yourNamespace].adapter.rooms[roomName]
This is an associative array with keys that are socket ids. In our case, we wanted to know the number of clients in a room, so we did Object.keys(io.nsps[yourNamespace].adapter.rooms[roomName]).length
In case you haven't seen/used namespaces (like this guy[me]), you can learn about them here http://socket.io/docs/rooms-and-namespaces/ (importantly: the default namespace is '/')
Updated (esp. for #Zettam):
checkout this repo to see this working: https://github.com/thegreatmichael/socket-io-clients
Using #ryan_Hdot link, I made a small temporary function in my code, which avoids maintaining a patch. Here it is :
function getClient(roomId) {
var res = [],
room = io.sockets.adapter.rooms[roomId];
if (room) {
for (var id in room) {
res.push(io.sockets.adapter.nsp.connected[id]);
}
}
return res;
}
If using a namespace :
function getClient (ns, id) {
return io.nsps[ns].adapter.rooms[id]
}
Which I use as a temporary fix for io.sockets.clients(roomId) which becomes findClientsSocketByRoomId(roomId).
EDIT :
Most of the time it is worth considering avoiding using this method if possible.
What I do now is that I usually put a client in it's own room (ie. in a room whose name is it's clientID). I found the code more readable that way, and I don't have to rely on this workaround anymore.
Also, I haven't tested this with a Redis adapter.
If you have to, also see this related question if you are using namespaces.
For those of you using namespaces I made a function too that can handle different namespaces. It's quite the same as the answer of nha.
function get_users_by_room(nsp, room) {
var users = []
for (var id in io.of(nsp).adapter.rooms[room]) {
users.push(io.of(nsp).adapter.nsp.connected[id]);
};
return users;
};
As of at least 1.4.5 nha’s method doesn’t work anymore either, and there is still no public api for getting clients in a room. Here is what works for me.
io.sockets.adapter.rooms[roomId] returns an object that has two properties, sockets, and length. The first is another object that has socketId’s for keys, and boolean’s as the values:
Room {
sockets:
{ '/#vQh0q0gVKgtLGIQGAAAB': true,
'/#p9Z7l6UeYwhBQkdoAAAD': true },
length: 2 }
So my code to get clients looks like this:
var sioRoom = io.sockets.adapter.rooms[roomId];
if( sioRoom ) {
Object.keys(sioRoom.sockets).forEach( function(socketId){
console.log("sioRoom client socket Id: " + socketId );
});
}
You can see this github pull request for discussion on the topic, however, it seems as though that functionality has been stripped from the 1.0 pre release candidate for SocketIO.

Restrict Google Places Autocomplete to return addresses only

autocomplete = new google.maps.places.Autocomplete(input, { types: ['geocode'] });
returns streets and cities amongst other larger areas. Is it possible to restrict to streets only?
This question is old, but I figured I'd add to it in case anyone else is having this issue. restricting types to 'address' unfortunately does not achieve the expected result, as routes are still included. Thus, what I decided to do is loop through the result and implement the following check:
result.predictions[i].types.includes('street_address')
Unfortunately, I was surprised to know that my own address was not being included, as it was returning the following types: { types: ['geocode', 'premise'] }
Thus, I decided to start a counter, and any result that includes 'geocode' or 'route' in its types must include at least one other term to be included (whether that be 'street_address' or 'premise' or whatever. Thus, routes are excluded, and anything with a complete address will be included. It's not foolproof, but it works fairly well.
Loop through the result predictions, and implement the following:
if (result.predictions[i].types.includes('street_address')) {
// Results that include 'street_address' should be included
suggestions.push(result.predictions[i])
} else {
// Results that don't include 'street_address' will go through the check
var typeCounter = 0;
if (result.predictions[i].types.includes('geocode')) {
typeCounter++;
}
if (result.predictions[i].types.includes('route')) {
typeCounter++;
}
if (result.predictions[i].types.length > typeCounter) {
suggestions.push(result.predictions[i])
}
}
I think what you want is { types: ['address'] }.
You can see this in action with this live sample: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete (use the "Addresses" radio button).

Google Places Autocomplete Remove State and Country from Result

https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete
I have a page similar to the above google places autocomplete demo url whereby if i type Buckingham Palace. It will return results of
Buckingham Palace Road, London, United Kingdom
Buckingham Palace Shop, Buckingham Palace Road, Victoria, London,
United Kingdom
and etc. How do i remove London, United Kingdom from the results?
It seems Google have no interest in sorting it out anytime soon. I have had to resort to the following, might be sufficient for others' needs as well:
document.addEventListener('DOMNodeInserted', function(event) {
var target = $(event.target);
if (target.hasClass('pac-item')) {
target.html(target.html().replace(/, Australia<\/span>$/, "</span>"));
}
});
note that pac-item is the class used on each suggestion. See Google Reference for other classes used. The container with pac-container class seems to drop the items when it is not shown and add new ones when it displays so if these pac-items are getting added to the DOM, it means suggestions are on their way to be displayed and pac-container is about to become visible.
just worked this out so open to improvements.
This also is not a complete solution. When selecting a suggestion with the country removed, autocomplete still adds the country to the geocoding! place_changed is too late a stage to change that so please see the solution above as only part of the answer. I'll update this again once I figure out the rest.
--- update
personally, i ended up not using the google autocomplete at all as i couldn't find a way around the problem of the autocomplete still showing the country once a modified suggestion is selected. a more usable approach was to use twitter typeahead and use the google APIs for getting the suggestions only. this gave me more control over the suggestions but obviously requires more manual work to make up for lost functionality
Here is How I made it work with jQuery auto-complete. Hope it helps someone.
$("#Search").autocomplete({
source: function (request, response) {
var options = {
input: request.term,
types: ['(cities)'],
region: 'US',
componentRestrictions: { country: "us" }
};
function callback(predictions, status) {
for (var i = 0, prediction; prediction = predictions[i]; i++) {
results.push(prediction.description.replace(/, United States$/, ""));
}
response(results);
}
var service = new google.maps.places.AutocompleteService();
service.getPlacePredictions(options, callback);
var results = [];
}
});
This is not possible without manually processing the results. If you think that it would be a useful feature, please file a Places API - Feature Request.

Resources