# EzDev.org

## pop

pop - An extensible iOS and OS X animation library, useful for physics-based interactions.

#### How do I pop two views at once from a navigation controller?

I want to pop to the third view on the navigation stack back to the first view.

I know how to pop one view at once:

But how do I do two at once?

Thanks...

Source: (StackOverflow)

#### What is the order of evaluation in python when using pop(), list[-1] and +=?

a = [1, 2, 3]
a[-1] += a.pop()

This results in [1, 6].

a = [1, 2, 3]
a[0] += a.pop()

This results in [4, 2]. What order of evaluation gives these two results?

Source: (StackOverflow)

#### What is the most pythonic way to pop a random element from a list?

Say I have a list x with unkown length from which I want to randomly pop one element so that the list does not contain the element afterwards. What is the most pythonic way to do this?

I can do it using a rather unhandy combincation of pop, random.randint, and len and would like to see shorter or nicer solutions:

import random
x = [1,2,3,4,5,6]
x.pop(random.randint(0,len(x)-1))

Edit: What I am trying to achieve is consecutively pop random elements from a list. (i.e., randomly pop one element and move it to a dictionary, randomly pop another element and move it to another dictionary, ...)

Note that I am using Python 2.6 and did not find any solutions via the search function.

Source: (StackOverflow)

#### PHP - pop first element of array instead of last (reveresed array_pop)?

Is there a PHP function that would 'pop' first element of array?
array_pop() pops last element, but I'd like to pop the first.

Source: (StackOverflow)

#### Parenthesis/Brackets Matching using Stack algorithm

For example if the parenthesis/brackets is matching in the following:

({})
(()){}()
()

and so on but if the parenthesis/brackets is not matching it should return false, eg:

{}
({}(
){})
(()

and so on. Can you please check this code? Thanks in advance.

public static boolean isParenthesisMatch(String str) {
Stack<Character> stack = new Stack<Character>();

char c;
for(int i=0; i < str.length(); i++) {
c = str.charAt(i);

if(c == '{')
return false;

if(c == '(')
stack.push(c);

if(c == '{') {
stack.push(c);
if(c == '}')
if(stack.empty())
return false;
else if(stack.peek() == '{')
stack.pop();
}
else if(c == ')')
if(stack.empty())
return false;
else if(stack.peek() == '(')
stack.pop();
else
return false;
}
return stack.empty();
}

public static void main(String[] args) {
String str = "({})";
System.out.println(Weekly12.parenthesisOtherMatching(str));
}

Source: (StackOverflow)

#### Equivalent for pop on strings

Given a very large string. I would like to process parts of the string in a loop like this:

large_string = "foobar..."
while large_string:
process(large_string.pop(200))

What is a nice and efficient way of doing this?

Source: (StackOverflow)

#### What do Push and Pop mean for Stacks?

long story short my lecturer is crap, and was showing us infix to prefix stacks via an overhead projector and his bigass shadow was blocking everything so i missed the important stuff

he was referring to push and pop, push = 0 pop = x

he gave an example but i cant see how he gets his answer at all,

2*3/(2-1)+5*(4-1)

step 1 Reverse : )1-4(*5+)1-2(/3*2 ok i can see that

he then went on writing x's and o's operations and i got totally lost

answer 14-5*12-32*/+ then reversed again to get +/*23-21*5-41

if some one could explain to me the push pop so i could understand i would be very greatful, i have looked online but alot stuff im finding seems to be a step above this, so i really need to get an understanding here first

Source: (StackOverflow)

#### Remove Logcat from Java Perspective

How can I remove the logcat window from the Java perspective permanently? Every time I get an error (that I'm expecting) it pops up the logcat window (even if i close it/remove it from the perspective) and shows the output. I only want this showing in the debug perspective. It's very annoying and makes iterative testing difficult when trying to fix known issues. I really don't need eclipse changing my focus to an error I've already seen a few dozen times.

I've tried going to "customize perspective" but I can only see options to add it, and even though it's not checked (and presumably not added) it still pops up.

Source: (StackOverflow)

#### Pop to root view controller without animation crash for the table view

I have 3 view controller in a tab bar controller. Clicking on any tab loads its root view controller in the navigation stack.

e.g. tab1, tab2, and tab3.
The 2nd view controller in the navigation stack (tab2VC2), has a tableView. Click on tab2 show VC in tab2, then tap on tab1, tries to go to its rootVC. Then the app is crashing saying

[UserDetailVC tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0xe0a23b0

If I popToRootVC with animation then its okay. I found viewDidAppear in the tab2VC2 is called where the tableView.reloadData is called, then dealloac, seems in the meantime reloadData starts working, the table is released. in case of animation, it gets some time, so it dont crash. But without animation, it is crashing. Do you think, its an iPhone bug? or I am doing wrong? Since pop to root controller have an option without animation, it should work, not it?

#pragma mark Tab bar controller delegate
- (void)tabBarController:(UITabBarController *)tbController didSelectViewController:(UIViewController *)viewController {
int i = tbController.selectedIndex;
NSArray *mycontrollers = tbController.viewControllers;
[[mycontrollers objectAtIndex:i] popToRootViewControllerAnimated:NO];
}

Source: (StackOverflow)

#### How to get a non-const top element from priority_queue with user-defined objects?

std::priority_queue::top returns a constant value. However, I would like to remove the top element from the priority queue and be able to modify it somewhere else.

priority_queue<SomeClass, vector<SomeClass>, SomeClassCompare > pQueue;
...
SomeClass *toBeModified = &(pQueue.top());
pQueue.pop();
toBeModified->setMember(3); // I would like to do this

Is there a way I can grab the top element from a priority queue (and remove from the queue) and modify it as I wish?

Source: (StackOverflow)

#### fast way to implement pop_front to a std::vector

I'm using some classes and several utility methods that use std::vector.

Now I need to use each frame a pop_front - push_back method on one of those classes (but they are all linked, and work together so I can't change only one).

Most of the operations are iterate over all element and push_back operations, so what I should do for the best work is: fork the repository of those classes and utilities, template everything and use deque or list.

But this means a lot of code rewriting and a lot of testing that will make me miss the deadline.

So I need advice to write an efficient pop_front to a static-size vector (the size will not change).

I've found here a way:

template<typename T>
void pop_front(std::vector<T>& vec)
{
vec.front() = vec.back();
vec.pop_back();
vec.front() = vec.back();  // but should this work?
}

And another idea should be:

template<typename T>
{
vec1.clear();
copy(vec.begin(), vec.end()-1, vec1.begin());
copy(vec1.begin(), vec1.end(), vec.begin());
}

What is the faster of these two solutions? Any other solutions?

Source: (StackOverflow)

#### Javascript "pop" from object

I wrote the following code to "pop" a property from an object as if it were an array. This looks like the kind of code that would get me slapped by more serious programmers, so I was wondering what is the proper way to do this:

// wrong way to pop:
for( key in profiles ){
var profile = profiles[key];  // get first property
profiles[key] = 0;            // Save over property just in case "delete" actually deletes the property contents instead of just removing it from the object
delete profiles[key];         // remove the property from the object
break;                        // "break" because this is a loop
}

I should have mentioned above, that unlike a true "pop", I don't need the objects to come out in any particular order. I just need to get one out and remove it from its parent object.

Source: (StackOverflow)

#### pop Instruction not supported in 64-bit mode using NASM?

I'm working on a more indepth hello world using NASM following this tutorial (section 4). This tutorial essentially teaches you how to handle command line input.
This is the snippet of the code in question:

section .text
global _start

_start:
pop     ebx     ; arg count
pop     ebx     ; arg[0] the program name
pop     ebx     ; arg[1-n] the remainder of the args
; must each be indiviually popped

The code errors out during compilation with error: instruction not supported in 64-bit mode referring to the 3 pop instructions above. Upon viewing the docs it seems that this code only works for 32-bit systems.

Is there a 64-bit pop instruction? Does anyone have a 64 bit tutorial using pop that I can look at?

Source: (StackOverflow)

#### How to limit tab indexes to just an overlay and its elements

I have a complex page with several overlays (lightbox type) that appear based on selections from several drop down menus. This is done with jQuery. The goal is to limit the user to only be able to tab through the elements on the overlay (above positioned lightbox div) via the keyboard. In other words, remove the below lying page elements from the tab sequence.

I am aware that I can set tabindex="-1" attributes on all of the below lying elements using javascript or jQuery, which does work, but with one big drawback.

The problem is that the project might require that some of the below lying elements have specific tab indexes other than the default browser tab index. If there were any existing tab index attributes set on the below lying elements, I will lose them when I set them all to "-1".

So, I am wondering if there is some other way to limit the tab indexing to just the overlay div, or if there is another approach I have not thought of to resolve this? Any help would be greatly appreciated as this one is killing my production time!

Source: (StackOverflow)

#### Why pop takes a parameter in assembly?

popl   %ebp

It seems the %ebp is unnecessary because the pop operation of stack doesn't need a parameter.

Why does it make sense?

Source: (StackOverflow)