This file contains 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 _lol(value): | |
vt = type(value) | |
isuuid = isinstance(value, UUID) | |
isuuidsub = None | |
cls = None | |
def idhashs(): | |
from uuid import uuid4, UUID | |
return id(uuid4), id(UUID), hash(uuid4), hash(UUID) | |
uuid4id, uuidid, uuid4hash, uuidhash = idhashs() |
This file contains 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
> mktmpenv --python=`which python3` | |
> pip install pip setuptools --upgrade | |
> pip install pip-tools | |
> echo "django-imagekit" > requirements.in | |
> pip-compile | |
> cat requirements.txt |
This file contains 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 truthynumber(*args): | |
""" | |
>>> truthynumber(True, True) | |
3 | |
>>> truthynumber(True, False, 1, 3, True) | |
5 | |
""" | |
ints = (str(int(arg)) for arg in args | |
if arg is True or arg is False) | |
bin_ints = ''.join(ints) |
This file contains 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
LOOKUP_SEP = '__' # fake it. | |
def Q(**kws): # fake it. | |
return kws | |
def make(relation_str, sep=LOOKUP_SEP): | |
""" | |
Given something like: | |
'a__b__c__d__e' | |
return a Q object composed of: |
This file contains 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.forms import Form | |
>>> from django.contrib.auth import get_user_model | |
>>> from django.forms.models import ModelMultipleChoiceField | |
>>> class MyForm(Form): | |
>>> field = ModelMultipleChoiceField(queryset=get_user_model().objects.all()) | |
>>> myform = MyForm(initial={'field': [1]}) | |
>>> myform.as_p() | |
# this should include | |
# <select multiple="multiple" id="id_field" name="field">\n<option value="1" selected="selected">kezabelle</option> |
This file contains 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.sites.shortcuts import get_current_site | |
from django.utils.functional import SimpleLazyObject | |
def current_site(request): | |
def wrapped_get_current_site(): | |
return get_current_site(request=request) | |
return { | |
'CURRENT_SITE': SimpleLazyObject(wrapped_get_current_site), | |
} |
This file contains 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 collections import OrderedDict | |
>>> set(dir(OrderedDict())) - set(dir({})) | |
set(['__dict__', '__module__', '__weakref__']) |
This file contains 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($window, $document, $, selector) { | |
var readyup = function () { | |
var previousScroll = 0; | |
var showNav = false; | |
var didScroll = false; | |
var windowHeight; | |
var documentHeight; | |
var $selector = $(selector); | |
if ($selector.length < 1) { |
This file contains 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 () { | |
var root = angular.element(document.getElementsByTagName('body')); | |
var watchers = []; | |
var f = function (element) { | |
angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) { | |
if (element.data() && element.data().hasOwnProperty(scopeProperty)) { | |
angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) { | |
watchers.push(watcher); |
This file contains 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 MyThing(Model): | |
def has_value_x_y(self): | |
assert hasattr(self, '_prefetched_objects_cache'), \ | |
"needs prefetch_related()" | |
# `my_thing__set` becomes `my_thing` in the prefetch cache ... | |
assert 'RELATION' in self._prefetched_objects_cache, \ | |
"needs prefetch_related('RELATION_set')" | |
count = (True for x in self.RELATION_set.all()) | |
return any(count) |