A clarification on Google Firestore query pagination - javascript

I am currently struggling in understanding how to paginate a firestore collection.
Say I have a collection with 10 docs and I have stored doc5 in my vue.js-based app.
If I wanted to fetch doc6 and doc7, I would issue the following pseudo-command:
query.startAt(doc5).limit(2).get().then(snapshot => ...)
What If I wanted to go two docs backwards relative to doc5? My first guess was to issue the following pseudo-command:
query.endBefore(doc5).limit(2).get().then(snapshot => ...)
Unfortunately, my guess is not correct. I actually obtain doc1 and doc2. This thing is driving me nuts. It is quite evident that I didn't understand the logic behind endBefore(). I did read the firebase docs but couldn't find any light.
May I ask for your merciful help?
If needed, I can provide more context... I am trying to isolate the issue and be as clear as possible.

Related

Image4io and NodeJS: Documentation is clearly outdated. How do I upload an image?

I guess this is as much a call to attention on the fact that the documentation seems to be outright incorrect in its application, as well as just generally lacking. Normally, I would send that part of the message to them personally, but, their contact form is also giving me errors and not sending, so it's not like I have the means to anyway. In the mean time, I'm more worried about getting this code to work, so hopefully someone experienced with this SDK or an Image4io team member sees this and can provide a public answer for others stumbling into this road block.
For starters, I initialized the Image4io object as described in the github here: https://github.com/Image4IO/image4ionodeSDK/
website documentation: https://image4.io/en/documentation/api-sdk/#operation/UploadImage
The image upload example provided on the website's documentation looks like this:
let client=new Image4ioAPI.Image4ioAPI(apiKey,apiSecret);
var request = new Models.UploadImagesRequest("/folderName", true, true);
request.Add("/path/to/image/location/name-of-the-image.jpg", "name-of-the-image", "name-of-the-image.jpg");
let response=client.UploadImage(request);
3 out of the very sparse 4 lines of code they provide give errors. Where did this Models object come from? There is no corresponding class in the import and the code example obviously doesn't show where it was defined. Just what is it and where did it come from?
Well, I found a matching function "UploadImagesRequest" in the original import class, so my guess is Models was deprecated and its functionality was moved into the Image4io class object. If that was the case the solution would be to simply access that function instead... But it's not used the same. It has 4 arguments, the 4th being a "Image4io.UploadFile[]" type. This type has no use examples in the documentation or further details describing what it is exactly. I assume image byte data goes in there somehow, but how?
Finally we have request.Add... except we don't because that isn't a function :( it looks like this was used to actually get the image data (maybe of the type UploadFile?) based on the path of the image. If this function is gone now, how do get file data for use in the upload request function?
Any and all help in figuring out this SDK would be greatly appreciated. Google searches yielded no meaningful results, so hopefully we can help in that department as well. For all I know I just got the wrong version somehow. I guess I could try downgrading to a version that matches the documentation but... that's not a fix in my eyes at all.
Let me know if there's any more info I could provide to help
You can upload image like this:
var client=new Image4ioClient(API_KEY,API_SECRET);
var files=Array();
files.push(new UploadFile("./test.jpg","test.jpg"));
client.UploadImage(new UploadImagesRequest("/",true,false,files))
.then(res=>console.log(res))
If you have binary data at hand, you can write it to a temporary file and then upload them.

How do I add a chart to firebase?

im currently creating an app where the user is suppose to click a couple of buttons and get a chart back. So far so good. But I want them to be able to save the chart in their profile so they can look at it whenever they want. I have no idea how to do it. I have played around with Auth but I just dont get it. I have googled to no avail. I have checked firebase website but im not sure what im looking for.
I tried repeating some of the steps for when it saves the account user and password.. but I dont know if im missing a specific set of syntax for this or I just dont know the proper command.
Does anyone know how to solve this or point in the right direction? Can it even be done?
I have been at it the whole day....
A chart is simply a presentation of data. You add the data to firebase and then you can later retrieve that data to present in anyway you wish (as a chart in your case).
Take a look at this example that uses canvasjs to present data as a chart: https://canvasjs.com/react-charts/chart-index-data-label/
If you're following some steps but are running into an issue you have to be specific because without more detailed information it's anyone's guess what the issue is as to why it isn't working.
but I dont know if im missing a specific set of syntax for this or I
just dont know the proper command.
How do you know something is not working? What's the result and what's the expected result?
Your first step would be to get authentication working. You can follow this documentation to help you get setup using the web: https://firebase.google.com/docs/auth/web/password-auth
After that you want to use create a database that has a collection, say 'charts' where each document could have the 'uid' of the users.
Take a look at this step-by-step tutorial.: https://www.youtube.com/watch?v=4d-gIPGzmK4&list=PL4cUxeGkcC9itfjle0ji1xOZ2cjRGY_WB
It guides you through authentication as well as storing data. Once you get that setup, viewing your data as a chart would be a front-end presentational thing and depend on what you're using to display the data. If you're using reactjs, https://react-charts.js.org looks like a good option.

Here API findpickups example doesn't work

We are trying to use the findpickup api to find the best route for several waypoints. Despite the fact that we trying to understand how the pickup and drop params exactly work we were not able to get a successfully response from the example at
https://developer.here.com/documentation/routing-waypoints/dev_guide/topics/example-pickup.html
https://wse.ls.hereapi.com/2/findpickups.json?mode=fastest;car;traffic:disabled&start=waypoint0;50.115620,8.631210;pickup:GRAPEFRUITS,value:1000&departure=2016-10-14T07:30:00+02:00&vehicleCost=0.29&driverCost=20&maxDetour=60&restTimes=disabled&end=waypoint7;50.132540,8.649280&destination0=waypoint1;50.118578,8.636551;drop:APPLES,value:30&destination1=waypoint2;50.122540,8.631070;pickup:BANANAS&destination2=waypoint3;50.128920,8.629830;drop:BANANAS,value:30&destination3=waypoint4;50.118654,8.619956;pickup:APPLES&destination4=waypoint5;50.123998,8.640626;drop:PEACHES,value:50&destination5=waypoint6;50.130299,8.613031;pickup:PEACHES&apiKey={YOUR_API_KEY}
It is always complaining not finding a match for a street.
After finding a similar question on stackoverflow describing this problem
Here Map findpickups Cannot match onto a road link with 1000.0m search radius
we switched to the alternative domain. But now the entire pickup/drop thing confused us even more after reading the error message that drop-off point is missing.
Regardless where we are changing params for pickup/drop it stills complains that a contraint for pickup is not fullfilled.
Would be awesome if someone has any idea what is going wrong with the example from the HERE Docs.
And more importantly if someone can explain how the pickup/drop implementation actually works.
#HERE developer support
Thanks a lot for your reply.
My new additional notes would be too long as a comment. So I edited my questions with further information for describing the actually problem we have.
Obviously makes sense that GRAPEFRUIT has to be removed in a pickup waypoint. We already tried that. Sorry that we didn't mentioned that.
The thing is that in our use case will drop or pickup multiple items on each waypoint.
According docs this must work.
https://developer.here.com/documentation/routing-waypoints/dev_guide/topics/api-reference-type-waypoint.html .
Unfortunately it doesn't work. See following request
https://fleet.ls.hereapi.com/2/findpickups.json?driverCost=20&mode=fastest;car&vehicleCost=0.20&start=wp1;50.41256,8.02943&destination1=wp2;50.0766,8.22699;pickup:item1&destination2=wp3;50.07735,8.22185;pickup:item2&destination3=wp4;50.06563,8.19155;drop:item1,value:100;drop:item2,value:100&end=wp5;50.41256,8.02943&apikey=YOUR_API_KEY
Would love to get some hints and a solution for our use case.
You would have to switch to the new domain https://fleet.ls.hereapi.com/2/findpickups.json and also change the departure time format as well as remove the pickup condition for the GRAPEFRUITS. The below request should work:
https://fleet.ls.hereapi.com/2/findpickups.json?mode=fastest;car;traffic:disabled&start=waypoint0;50.115620,8.631210&driverCost=20&maxDetour=60&restTimes=disabled&destination0=waypoint1;50.118578,8.636551;drop:APPLES,value:30&destination1=waypoint2;50.122540,8.631070;pickup:BANANAS&destination3=waypoint4;50.118654,8.619956;pickup:APPLES&destination4=waypoint5;50.123998,8.640626;drop:PEACHES,value:50&destination5=waypoint6;50.130299,8.613031;pickup:PEACHES&departure=2016-10-14T07:30:00&vehicleCost=0.29&end=waypoint7;50.132540,8.649280&destination2=waypoint3;50.18920,8.629830;drop:BANANAS,value:30&apikey=YOUR_API_KEY
We have reported the issue to API team, ask is to correct/simplify the example.

How to Modify Tile Data in mapbox-gl-js ? (callback or any structure to decode tile binary data)

summery ->
in our company, we use our own vector-tile-servers for displaying base maps. we encode both tile-url and Tile data in some way for protection.
now, we are going to start using mapbox-gl-js in our webApps.
problem ->
I cannot find the callback or any solution to modifying each tile data after they've got fetched. it seems there is no solution defined in docs or forums.
what I am seeking for ->
if there is any solution defined already, please leave a sample or the address to it's doc for me.
this is really vital. if u got any soluttion for this problem pls let me know about it.
after lots of googling and trying, and also based on this issue, I assure you currently there is no way but modifying source of mapboxgl-js.

XPages: How to fetch documents in view and read values?

I am a beginner with XPages, and I have looked at the TLCC Intro free training. I have also seen tutorials here. I have no experience with Lotus Notes, XPages or flat-structured databases. But, I do have some experience in JavaScript and good experience (IMO) in Java and Android.
I am facing the following problems.
1) I am trying to implement a very basic login mechanism.
Currently, I add users manually, based on a form. Now, I want to create a login page. I take a user and a password, and click on a button.
In the button, I want to read all documents associated with a view (that displays all usernames/passwords), compare with entered value, and if it exists check if the password fields match too.
Can someone please guide me in the correct direction? I can't figure out which functions to use. Also, should I be using Scope Variables? Is there a good document/tutorial regarding that?
I have tried the "view.getAllEntries()" method but it always returns null.
Am I approaching this correctly? Are there in-depth tutorials that can help me with this?
2) What is the method to debug SSJS? I am currently putting everything in a try/catch and printing the error there.
I apologize if this question has been asked elsewhere, I haven't really found anything regarding this. Please point me if there is this is a duplicate.
1.
Use view.getDocumentByKey(theUserName) to find a user document in your view. It returns the user document as NotesDocument or null if user is not in view. The view has to have a first sorted column with the usernamens.
2.
As of Notes Domino version 9 you can debug SSJS.

Categories

Resources