contiki: uip_ds6_route_head() vs uip_ds6_route_lookup - contiki

Can anybody tell me the difference uip_ds6_route_head() vs uip_ds6_route_lookup(addr)?
I used to think that the uip_ds6_route_head() returned a route to every child (direct and indirect) for the node that calls the function. However, two nodes had a route to the same child (the r->ipaddr == r->nexthop)?
Thanks

Internally, uip-ds6-route.c keeps its routes in a list called routelist.
uip_ds6_route_head() simply returns the first element in the routelist.
uip_ds6_route_lookup(addr) will iterate over the routelist and return the best matching route for addr.

Related

Get child node by name in Umbraco 7.8.1

My Content structure is:
-Home (the site root node)
-About Us
-Our Sevice1
-Our Sevice2
-Our Sevice3
I created a macro for Our Services.
In macro, I want Our Sevice1, Our Sevice2, Our Sevice3...
But in the list variable About Us also come but I don't want it
I want only our service name of the child node
var list= CurrentPage.Children();
About Us also come on the list but I don't want it.
The reason that you see the About Us page in the collection is because you use the Children method.
With the Children method you ask for the direct child nodes of a parent node traversing one level down. So in this case you ask for all direct children of the home page so this works like expected.
What you are trying to achieve is a collection of of all Service nodes. To accomplish this you could do something like this.
Make sure that you have a seperated Document Type for your service nodes ( like for example doc type Service Page ).
Then you can do the following:
var servicePages = CurrentPage.ServicePages;
You can view the docs about it here:
https://our.umbraco.org/documentation/reference/querying/dynamicpublishedcontent/collections
But all of this is using dynamic syntax, this will be removed in future versions of Umbraco. So I suggest you go and use the strongly type syntax.
Then this can be changed by:
var servicePages = Model.Content.Children.Where(x => x.DocmentTypeAlias == "servicePage");
What this does is take the IPublishedContent object of the current page you are on, which is the Home Page then you take all children which has a document type alias of type servicePage.
Like #Mivaweb mentioned, it's better to not use dynamics (I think for performance in addition to being removed in the future).
However, I don't think you have to create a separate doc type, although that will work too. The predicate for the Where method should handle other expressions such as:
var servicePages = Model.Content.Children.Where(x => x.Name.StartsWith("Our Sevice"));

Grails findById( null ) returning "random" result

I found a very strange behavior in our grails application today that i want to share with you.
We are using grails 2.3.11 on mysql 5.1.48.
We had a DomainObject.findById( id ) in one of your Controller actions.
We failed to check the id for a null value so DomainObject.findById( null )
would be called when no id is passed as an argument.
Normally DomainObject.findById( null )
will return null but there is a special condition that will yield other results!
If the controller action called before that inserted a new record in the database (lets call it Object B), regardless of the domain object stored, the DomainObject.findById( null ) will find the DomainObject with the same Id the Object B got on insert.
So when the controller action called before saved anything the findById(null) will return a row. And that row will have the same id the last inserted element got.
I am totally aware that using findById(null) is not the desired way to do it but I was quite shocked about the results it yielded. But returning any seemingly "random" result seems very strange to me.
I also want to note that DomainObject.get(null) will not suffer from this problem.
Anybody else witnessed this?
There is an active Jira pointing in this direction: https://jira.grails.org/browse/GRAILS-9628 but its not really describing this issue.
We don't really support passing null as an argument to a dynamic finder like that. Dynamic finders have explicit support for querying by null. Instead of DomainClass.findByName(null) you would call DomainClass.findByNameIsNull(). If you have a reference that may or may not be null, instead of passing that as an argument to a dynamic finder, the code can almost always be made cleaner by writing a criteria query or a "where" query that has a conditional in it.
I hope that helps.
Thx for your information scot.
I have further details. This behaviour is also altered by the underlying database.
While mysql suffers from this, maria-db (a mysql clone) does not!
So what happens is bound to the underlying database system.
That should not happen to an abstraction layer ....

Neo4j Uniquness on update unique index value

The
uniqueness=create_or_fail
works great when creating a new node since it throws a 4xx response if a duplicate index key/value already exists.
However, if the node already exists and indexed and the indexed value needs to be updated, there is no way (that i am aware of) to update the value and fail if the new value already exists. That is because the Add Node to Index REST call does not throw a 4xx response if the new value already exists. as far as i can see the add node to index does not even participate in Uniqueness on indexes.
One solution is to delete the node and re-add it but this is not easy since all the other indexes and relationships on this node would have to be recreated.
another solution would be to add the Uniqueness parameter to the Add Node to Index REST call
http://docs.neo4j.org/chunked/1.9.M05/rest-api-indexes.html#rest-api-add-node-to-index
any other ideas on this?
thanks
I happened up on this question and here's what I figured out for a work-around.
During an update do as follows in a REST batch:
Delete all of node's index entries for the desired index
Create a new node using CreateOrFail on the desired index, except instead of using your normal properties just use a dummy property such as DeleteMe=true
Add the node to the desired index because if it got this far the previous step succeeded
Update node's properties
Use a Cypher statement to delete the dummy node Ex:
START n=node:index_name(index_key={value}) WHERE (n.DeleteMe!)=true DELETE n

Getting multiple relationships and children of the same node

Is it possible to get multiple 'children' nodes by relationship. For example, given the following query:
START event=node(4)
MATCH event-[:photoalbum]->photoalbum-[:coverphoto]->coverphoto
RETURN event, photoalbum, coverphoto
I thought it would be possible to also get the location of an event as follows:
START event=node(%i)
MATCH event-[:photoalbum]->photoalbum-[:coverphoto]->coverphoto, event-[:location]->location
RETURN event, photoalbum, coverphoto, location
However I just get an error saying they were expecting a RETURN type.
I have looked through the Cypher documentation but I can't seem to find anything on multiple MATCHes.
It turns out I only briefly read and therefore forgot about incoming/outgoing relationships. It just so happens that the location was an incoming relationship so wouldn't fetch. Instead of --> or <-- I am just using -- so the direction of relationship is generic.
You can try this one, it works fine with me
START event=node(%i)
MATCH location<-[:location]-event-[:photoalbum]->photoalbum-[:coverphoto]->coverphoto
RETURN event, photoalbum, coverphoto, location

Rails difference in object created from a .find(:id) and .where() methods

What is the difference in the objects created with these 2 methods:
tec = Technique.find(6)
tec2 = Technique.where(:korean => 'Jok Sul')
The data returned for each is exactly the same, yet the first object will respond perfectly to an inherited method like update_attributes while the second object will give an error of method not found.
When I do tec.class and tec2.class one is an ActiveRecord::Relation and the other doesn't give me a class at all, it just prints out the content of the object.
Maybe when you use the .where method you get an array, even if there is only one match and therefore you always have to issue the .each method to get at the contents? But that makes it hard to deal with when you want to update records, etc.
Can someone clarify this for me? Specifically, how to deal with matches found through the .where method.
Thanks.
Try:
tec2 = Technique.where(:korean => 'Jok Sul').first
Good question.
tec_scope = Technique.where(:korean => 'Jok Sul') # create an internal query
Remember, here only the query is created, it is not executed. You can programmatically build on top of this query if you so wished. The scope (or query if you so wish) will be executed in 2 ways. "Implicit" or "Explicit". Implicit way of running the query happens for example in the console, which invokes a method on the scope which automatically runs the query for you. This wont happen in your controllers unless you run it explicitly for .e.g
tec_scope.all # returns array
tec_scope.first # retuns one element
Scopes are just adding where clauses/predicates to your query. It's query building and delaying the execution till it is needed.
However,
tec_objects = Technique.find(6) # explicitly runs a query and returns one object (in this case)
This will explicitly run the query there and then. It is a question of the timing of execution of the query.
The difference is subtle but very important.
This hasnt got anything to do with whether you get one result or an array.
Technique.find([4,5]) # will return an array
Technique.find(4) # will return one object
Technique.where(:some_key => "some value").all # will return an array
Technique.where(:id => 5).first # will return one object
The difference is in timing of the execution of the query. Don't let the console fool you into believing there is no difference. Console is implicitly firing the query for you :)
The find(6) returns a single object, because you're specifying the object ID in the database, which is guaranteed to be unique by convention.
The where call returns a collection, which may be only 1 item long, but it still returns a collection, not a single object.
You can reveal this difference. Using your example code, if you call tec.class vs. tec2.class I think you'll find that they aren't the same class of object, as you expect.
That is, the methods available to a collection of objects is different than the methods available on an instance of that object.

Resources