Why bson_iter_type is 0x27,0x17? - bson

I used the bson_iter_type() to get the type of iter. But the results (0x27, 0x17,0x1a,0x1b) are not listed in the official document mongodb-api-document. Why?

After bson_iter_init (&iter, my_bson_doc), iter does not point at the first element, but something ahead of the first element. After bson_iter_init (&iter, my_bson_doc) and bson_iter_next (&iter), iter will point at the first element if there are at least one element in bson. So, my problem stems from that the return of bson_iter_type() is not the type of the first element, but other things.
Now, bson_iter_next (&iter) is called to make sure iter point at the first element before bson_iter_type(). My problem is solved.

Related

Get index of an SKPoint in an SKPath

I'm not seeing an IndexOf or FindIndex method for SKPath.Points. I need to be able to get neighbouring points on both sides of a specified point. Path.Iterator only has .Next, so I am looking for using the index of the SKPoint instead.
With IndexOf or FindIndex seemingly missing, I am thinking of inheriting and maintaining a 2nd dataset in the background for getting the index.
Am I missing something obvious? How are others getting the index, so far?
This post helped. Calling IndexOf directly on Array works. Just need to make sure your SKPoint X and Y are unique from other SKPoints stored in the SKPath.Points. It is doing the check based on the SKPoint's position, so if you have multiple SKPoints at (0, 0), for example, it will return the first one at that position.
Luckily, I should never be in the situation for my use case.

How to select repeated element with Capybara

I know how to get the first element, but how can I get the second or third element found with that class x ?
Only way is by choosing from an Array like below? If so, starts at zero or one ?
find(".element")[1]
you can do
find(".element:nth-of-type(1)")
find(".element:nth-of-type(2)")
find(".element:nth-of-type(3)")
or
all(".element")[0]
all(".element")[1]
all(".element")[3]

How to setup the data structure?

First let me explain what I want to do. I have n data elements. Every element needs to be checked with every other element but not with itself. The function that checks the elements returns true if everything is ok. If something is wrong than the function deletes both elements and replace them with new ones. But the new ones need to be checked with every other element too. This will be repeated until every element was checked with every other and all checks are fine.
I am asking how to setup the data structure in a most efficient way. When I test ele1 with all other n-elements and all are fine and then I test ele2 with ele84 and both get replaced I need to check ele1 and ele2 again, if these are now not fine I need to check all for ele1 again. But how to remember in the most efficient way which elements need to be check and which don’t to avoid double checking of elements?
You can use three lists: Main, CurrentNew, and NextNew
Main is initialized with the elements - use a nested loop to check them all, if you delete any elements then add the new elements to NextNew
On the next iteration, NextNew becomes CurrentNew - allocate a new NextNew list. First use a nested loop to check all elements of CurrentNew with the other elements of CurrentNew, then check the elements of Main with the elements of CurrentNew. New elements go to NextNew. Note that you're not checking the elements of Main with the other elements of Main - you already know that they're valid with each other.
On the next and each subsequent iteration, merge CurrentNew into Main, then NextNew becomes CurrentNew, repeat until all elements are valid.

The "getnodevalue" of HTMLUNIT not working on domattr

every time i want to get the Value of my DomAttr i get an TypeError:
My Code:
Wanted = page.getByXPath("//span[contains(.,'Some')]/parent::a/#href");
return this
[DomAttr[name=href value=URLSTRING]]
Now i want to geht the value (=URLSTRING) with Wanted.getNodeName();
but every Time i get the Error
Cannot find function getNodeValue in object [DomAttr[name=href value=
same when i use getValue
please help me
There are some things that make no sense in the code (particularly, because it is not complete). However, I think I can guess what the issue is.
getByXPath is actually returning a List (funny thing you missed the part of the code in which you specify it as a list and replaced it with a Wanted).
Note you should probably also have type warnings in the code too.
Now, you can see that the returned value is in square brackets. That means it is a List (confirming first assumption).
Finally, although you happened to miss that part of the code too, I guess you are directly applying the getValue to the list instead of the DomAttr elements in the list.
How to solve it: If you need more than 1 result iterate over the elements of the list (that Wanted word over there). If you need 1 result then user the getFirstByXPath method.
Were my guesses right?

Prototype $$ returns array, should return one element like $

When using the dollar-dollar-function in prototype I alway get an array of elements back, instead of just one element with the dollar-function. How can I combine the power of CSS-selectors of $$ but still get only one element back?
Changing the structure of the source is not possible, so I can't just select it with the id. It needs to get selected with CSS, but should just return one element.
You can also do
$$('.foo').first()
It looks cleaner than $$('.foo')[0] for my taste :)
It does not make sense to return a single element when selecting by class name because potentially there could be many elements in the DOM that have this class. So you could always use the first element of the returned array if you are sure that it will be unique.
$$('.foo')[0]

Resources