It is possible to advance an indexeddb cursor to a given position:
cursor.advance(100)
But, is it position to get current position of the cursor? (i.e. return the 100)
No.
You have to keep track of cursor offset yourself. Try to avoid it whenever possible, but instead use keys to locate cursor.
Related
I have a list of anything from 10-500 records appearing on screen as a graphical array using standard NG-REPEAT, visualisation is a row of photographs
What I would like to achieve, but cant quite get my head around if its even possible is this...
A 'window' on screen that will only show 10 records - Done
You can scroll left or right through the entire list - Done
HOWEVER
What i would LIKE to achieve is that when the end of the list is reached, the list starts again from the beginning but in an infinite style loop. Both directions
I have never done anything like this and not quite sure how I would achieve this of my ng-repeat (item in ListofItems)
So I assume that the best solution is
when the user gets 40 records through 100 records, i push() the first 20 records from my $scope.ListofItems to the end of the array, and remove the equivalent first 20 records from the front.. this keeps a constant list of 100 records, no massive memory usage.. i can even do this on an individual record basis.. remove one record from end or beginning and add at the beginning or end of the list.
The user experience is an infinite scroll, but I suspect the browser experience could be slow and stuttering due to the processing going on
Push(), Pull(), Tracking and indexing would play a part but any suggestions would be appreciated whether this is even technically possible
EDIT : After some research. maybe
$scope.ListofItems.push($scope.ListofItems.shift());
could be a solution to move beginning to end, but not sure how to trigger this or go the other way (pull?)
EDIT2 : Just did a manually called function for the above and it shifts front item to end of list, though i would have no clue how to read the screen position to know when to fire the function
Going the other way around could be
$scope.ListofItems.unshift($scope.ListofItems.pop());
As a side note, I think it's important to keep in mind for large arrays that shift() and unshift() naturally cause a full reindexing and have a time complexity of O(n) where n is the length of the array, as opposed to push() and pop() which have a time complexity of O(1)
I am working on an animation in AS2 which requires that all text MovieClips (instance names starting with "txt_") will be manually placed initially on stage and I need to store their own initial placed positions (x,y) so they will be retrievable later when I want to animate them to these same final coordinates regardless of where they move around in the meantime.
So the following steps needed:
All these text movieclips are placed on stage manually from library (not dynamically) matching their expected target keyframe end position (x,y) to get desired final screen layout.
Then a frame script loops through all these MovieClip instances on stage before rendering them on stage and stores their initial (also future target) (mc.targetPosX or mc.targetPosY) positions.
Then frame script also moves all of these MovieClip instances before rendering them on stage and moves/offsets them elsewhere on stage (eg. mc._x +=25px;) and hides them (eg. mc._alpha =0;)
Finally by using a tween like Greensock I want to use their stored target end position to animate each of them to their stored final target position.
(eg. TweenLite.to(mc, 1,{_alpha:100, _x:mc.targetPosX, ease:Quad.easeOut});)
I was able to create a loop to get "txt_" movieclips but then I don't know how to save their target positions with their instance and use them outside the loop afterwards.
Thank you in advance,
Attila
I don't know what problems do you have trying store some variables inside instances, but here my suggestions about proccess you described.
First of all we have loop which do all thing you described at question.
To do so we must have some list of you mc's or pattern to make this list dynamically. From you question i suppose that you use this kind of loop.
for(var i=0, txtCount=10; i<txtCount; i++){
textMc = this['txt_'+i];
//do stuff
...
}
From here on your points.
You already did it.
Use loop described above to store current object properties inside his instance
textMc.storedX=textMc._x;
textMc.storedY=textMc._y;
Here is same loop place object wherever you like
textMc._x+=25;
textMc._alpha=0;
Finally right after that in the same loop use greensock.
TweenLite.to(textMc, 1,{_alpha:100, _x:mc.storedX, ease:Quad.easeOut});
That's it.
Before this block was up there in position 1.
Once I shifted the position of some blocks, not replaced it with her on top again.
What is the name of this block and how can I reposition it to position 1?
Check if you have any problem with your CSS styling on that block, position: absolute or something similar
Try clearing the cache (/admin/config/performance/clear-cache or drush cc all )
Revert back the changes to debug the issue:
May be you introduced something new , you are not aware of , or you can't think of .
I am trying to get forward and backwards pagination working for a query I have on my app.
I have started with the example at: https://developers.google.com/appengine/docs/python/ndb/queries#cursors
I would expect that example to do a typical forward/back pagination to create cursors that you can pass to your template in order to be used in a subsequent request for the page after/before the current one. But what it is doing is getting cursors for the same page, one from the beginning and the other from the end (if I have understood correctly).
What I want is a cursor to the beginning of the following page, and a cursor to the beginning of the previous page, to use in my UI.
I have managed to almost get that with the following code, based on the mentioned example:
curs = Cursor(urlsafe=self.request.get('cur'))
q = MyModel.query(MyModel.usett == usett_key)
q_forward = q.order(-MyModel.sugerida)
q_reverse = q.order(MyModel.sugerida)
ofus, next_curs, more = q_forward.fetch_page(num_items_page,
start_cursor=curs)
rev_cursor = curs.reversed()
ofus1, prev_curs, more1 = q_reverse.fetch_page(num_items_page,
start_cursor=rev_cursor)
context = {}
if more and next_curs:
context['next_curs'] = next_curs.urlsafe()
if more1 and prev_curs:
context['prev_curs'] = prev_curs.reversed().urlsafe()
The problem, and the point of this question, is that I use more and more1 to see if there is a next page. And that is not working in the backwards sense. For the first page, more1 is True, in the second page more1 is False, and subsequent pages give True.
I would need something that gives False for the first page and True for every other page. It seems like this more return value is the thing to use, but maybe I have a bad Query setup, or any other thing wrong.
Thanks everyone!
Edit: Since I didn't find a simple solution for this, I switched to using ndbpager.
There's no such thing.
You know thats theres (at least) one page before the current page if you started the query with a cursor (the first page usualy dosnt have a cursor).
A common trick to access the previous page is inverting the sort-order.
If you have a list, sorted by creationdate desc, you could take the creationdate of the first element of your current page, query for elements with creationdate < this creationdate using inverted sort order. This will return the oldest elements which are newer then the given creationdate. Flip the list of retrived elements (to bring them into the correct order again) and there you have the elements of the page before, without using a cursor.
Note: this requires the values of your sortorder beeing distinct.
In some cases, its also possible to use a prebuild index allowing random-access to different pages, see https://bitbucket.org/viur/server/src/98de79b91778bb9b16e520acb28e257b21091790/indexes.py for more.
I have a workaround and not the best solution. it is baiscally redirecting back to the previous page.
Previous
I think PagedQuery has the capability but still waiting for someone to post a more comprehensive tutorial about it.
I have a application that will capture the screen and I want to write the captured information to an array, this takes AGES as the array ends up being +2million values. I am iterating and adding the values to the array, is there any way quicker (eg binary operations)? Should it be this slow? Why is it?
Assuming your GetPixel'ing the screen pixel by pixel, its the GetPixel call that's slow (it interrogates the display driver) not the (pre-dimensioned) array assignment.
You can instead use the getdibits() api which will copy the DC's colour info into a buffer in a single call.
Here is a C++ example, but the methodology & call sequence is the same as for VB.
Figured out why it was so slow, it was because I was using ReDim on every iteration of the loop - thanks for the help anyways
Martin