This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # 16078734 | |
| (lambda i,s,b,l: i(s(b()),l(s(...))<<i()**i()+i(b(i))))(int,str,bool,len) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lambda i: i++ (lambda j: j()**j())(type(i)) | |
| lambda i: (sum(range(x))*2)/x # decrement | |
| lambda i: 2*i-(sum(range(i))*2)/i # banermatt | |
| lambda i: __import__('functools').partial(i.__add__, 1)() | |
| lambda i: i+(i is i) # SFJulie1 (kind of) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function _mvsub_complete() | |
| { | |
| local word=${COMP_WORDS[COMP_CWORD]} | |
| local filename subname | |
| if [[ $COMP_CWORD = 1 ]]; then | |
| # Only allow subtitles files (*.srt) | |
| COMPREPLY=($(compgen -f -X "!*.srt" -- "${word}")) | |
| else | |
| # Only complete non-subtitles files that don't have a matching subtitle | |
| COMPREPLY=() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create(request): # django.views.generic.CreateView | |
| """Create a new model object and save it to the database.""" | |
| if request.method == 'post': | |
| form = ModelFormClass(request.POST) | |
| if form.isvalid(): | |
| form.save() | |
| return redirect(...) | |
| else: | |
| form = ModelFormClass() | |
| return render('your_template.html', {'form': form}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| django.views.generic.base: | |
| View: | |
| The most basic class. All other class based views inherit from it. | |
| To use it, create a method for each HTTP verb (get, post, put, ...). | |
| These method get passed a request obejct as the first argument, as well | |
| as whatever was captured in the url (*args, or **kwargs). | |
| The request, the *args and **kwargs are stored on the instance. | |
| To instanciate a view in your code, use `view_name = ClassBasedView.as_view()`. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import template | |
| register = template.Library() | |
| class SumNode(template.Node): | |
| def __init__(self, sequence, loopvar, loopitem): | |
| self.sequence = template.Variable(sequence) | |
| self.loopvar = loopvar | |
| self.loopitem = template.Variable(loopitem) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| #-*- coding:utf-8 -*- | |
| SYNTAXERROR_TEMPLATE = "%s = ())" # Unbalanced parentheses | |
| def get_offset(varname): | |
| """Trigger a syntax error that uses the given variable name and return the | |
| exception's offset, e.g. the position of the syntax error. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NewsLetterSignupForm(forms.ModelForm): | |
| class Meta: | |
| model = NewsLetterSignup | |
| fields = ['email'] | |
| def save(self, commit=True): | |
| """Return an existing instance if one exists with the same email. | |
| Create and return it otherwise. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "pk": "01", | |
| "model": "yourapp.yourmodel", | |
| "fields": { | |
| "region": 82, | |
| "name": "Ain" | |
| } | |
| }, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.auth.forms import UserCreationForm | |
| class SignupForm(UserCreationForm): | |
| pass |