reverse

django-cms: urls used by apphooks don't work with reverse() or {% url %}

廉价感情. 提交于 2019-11-29 07:28:56
问题 I'm using django-cms with apphooks to display book detail information. I need the page with the app hook to accept a slug that specifies which book to display. I created a page called 'books' and added the apphook 'BookDetailApp'. Here's what my books.cms_app file looks like: class BooksApp (CMSApp): name = _('Book Detail Page Application') urls = ['books.urls'] apphook_pool.register(BooksApp) Here's what my books.urls looks like: urlpatterns = patterns('', url(r'^(?P<slug>[\w\-]+)?',

Reverse DataFrame column order

妖精的绣舞 提交于 2019-11-29 06:21:21
问题 I want to simply reverse the column order of a given DataFrame. My DataFrame: data = {'year': [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012], 'team': ['Bears', 'Bears', 'Bears', 'Packers', 'Packers', 'Lions', 'Lions', 'Lions'], 'wins': [11, 8, 10, 15, 11, 6, 10, 4], 'losses': [5, 8, 6, 1, 5, 10, 6, 12]} football = pd.DataFrame(data, columns=['year', 'team', 'wins', 'losses']) Actual output: year team wins losses 0 2010 Bears 11 5 1 2011 Bears 8 8 2 2012 Bears 10 6 3 2011 Packers 15 1 4 2012

Android - Reverse listview as message display

孤者浪人 提交于 2019-11-29 06:12:39
I've got a little question for my Android App. I searched for a long time but found nothing about my problem. Scenario : I've to display a revert listview (as Facebook Messenger). And when the user scrolls to the top, load more messages. Problem : After notifiyDataAsChanged() call, the scroll is not the same! I want to conserve exactly the same position as before loading. I tried that code : // save index and top position int index = list.getFirstVisiblePosition()+result.size(); View v = list.getChildAt(index); int top = (v == null) ? 0 : v.getTop(); // ... // restore list.setSelectionFromTop

Linked list head double pointer passing

冷暖自知 提交于 2019-11-29 05:15:17
I have seen this in some book/ tutorial. When you pass in the head pointer (of linked list) into a function, you need to pass it as a double pointer. For eg: // This is to reverse a linked list where head points to first node. void nReverse(digit **head) { digit *prev=NULL; digit *curr=*head; digit *next; while(curr!=NULL) { next=curr->next; curr->next=prev; prev=curr; curr=next; } *head=prev; return; } This works fine. It also works when I use single pointer like, void nReverse(digit *head) { digit *prev=NULL; digit *curr=head; digit *next; while(curr!=NULL) { next=curr->next; curr->next=prev

ReverseParentheses - Codefights

蹲街弑〆低调 提交于 2019-11-29 04:17:37
问题 I'm having a really tough time solving this problem with JavaScript You are given a string s that consists of English letters, punctuation marks, whitespace characters and brackets. It is guaranteed that the brackets in s form a regular bracket sequence. Your task is to reverse the strings in each pair of matching parenthesis, starting from the innermost one. Example For string "s = a(bc)de" the output should be reverseParentheses(s) = "acbde". Input/Output [time limit] 4000ms (js) [input]

How does this code work to reverse bits in number?

浪尽此生 提交于 2019-11-29 02:52:20
问题 unsigned reverse_bits(unsigned input) { //works on 32-bit machine input = (input & 0x55555555) << 1 | (input & 0xAAAAAAAA) >> 1; input = (input & 0x33333333) << 2 | (input & 0xCCCCCCCC) >> 2; input = (input & 0x0F0F0F0F) << 4 | (input & 0xF0F0F0F0) >> 4; input = (input & 0x00FF00FF) << 8 | (input & 0xFF00FF00) >> 8; input = (input & 0x0000FFFF) << 16 | (input & 0xFFFF0000) >> 16; return input; } how does this work? 回答1: Suppose I have a hand of 8 cards: 7 8 9 10 J Q K A How can we reverse

android - reverse the order of an array

本小妞迷上赌 提交于 2019-11-29 01:26:02
问题 I have an array of objects. Is it possible to make a new array that is a copy of this array, but in reverse order? I was looking for something like this. // my array ArrayList<Element> mElements = new ArrayList<Element>(); // new array ArrayList<Element> tempElements = mElements; tempElements.reverse(); // something to reverse the order of the array 回答1: You can do this in two steps: ArrayList<Element> tempElements = new ArrayList<Element>(mElements); Collections.reverse(tempElements); 回答2:

Can somebody explain this Javascript method?

こ雲淡風輕ζ 提交于 2019-11-28 21:13:51
Original source: http://twitter.com/tobeytailor/status/8998006366 (x=[].reverse)() === window // true I've noticed that this behavior affects all the native types. What exactly is happening here? This is to do with the weird way this binding works in JavaScript. [].reverse is the method reverse on an empty list. If you call it, through one of: [].reverse(); []['reverse'](); ([].reverse)(); then it executes with this bound to the list instance [] . But if you detach it: x= [].reverse; x(); it executes with no this -binding, so this in the function points to the global ( window ) object, in one

Reverse Modulus Operator

蓝咒 提交于 2019-11-28 19:11:51
Over 3 years after asking the question I found the solution. I have included it as an answer . I have an expression with modulus in it that needs to be put in terms of x. (a + x) mod m = b I can't figure out what to do with the modulus. Is there a way to get x by itself, or am I out of luck on this one? Edit : I realize that I can get multiple answers, but I'm looking for an answer that falls within the range of m. I was revisiting this question and realized it is possible based off of the answer @Gorcha gave. (a + x) mod m = b a + x = nm + b x = nm + b - a for some integer n I don't know why

How do i pass GET parameters using django urlresolvers reverse

☆樱花仙子☆ 提交于 2019-11-28 17:21:40
I am using django 1.2 and going from one view to another using the urlresolvers reverse method. url = reverse(viewOne) and I want to pass a get parameter, for example name = 'joe' so that in the viewOne if I do def viewOne(request): request.GET['name'] I will get joe how do I do that ? GET parameters have nothing to do with the URL as returned by reverse . Just add it on at the end: url = "%s?name=joe" % reverse(viewOne) A safer and more flexible way: import urllib from django.core.urlresolvers import reverse def build_url(*args, **kwargs): get = kwargs.pop('get', {}) url = reverse(*args, *