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
import functools | |
class Dispatcher: | |
def __init__(self, strict=False): | |
self.strict = strict | |
self.__path = [] | |
def __getitem__(self, name): | |
def getitem(obj): |
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
### current bpython session - make changes and save to reevaluate session. | |
### lines beginning with ### will be ignored. | |
### To return to bpython without reevaluating make no changes to this file | |
### or save an empty file. | |
class Int(int): | |
def __call__(self, val): | |
return Int(self + val) | |
num = Int(1) |
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 replace_with_func_name(func): | |
return func.__name__ | |
@replace_with_func_name | |
def func(x, y): | |
return x / y | |
func | |
### 'func' |
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 AlternativeConstructors(): | |
def __init__(self, value): | |
self.value = value | |
@classmethod | |
def from_reversed(cls, value): | |
return cls(value[::-1]) | |
@classmethod |
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
async def f1(x): | |
return x*x | |
async def f2(x, y): | |
return await f1(x) + await f1(y) | |
next(f2(3, 4).__await__()) | |
### Traceback (most recent call last): | |
### File "<input>", line 1, in <module> | |
### next(f2(3, 4).__await__()) |
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
import logging | |
import random | |
import string | |
import time | |
from contextlib import contextmanager | |
@contextmanager | |
def measure_exectime(name, extra_context=None): | |
""" |
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 python | |
# -*- coding: utf-8 -*- | |
""" | |
fabfile for Django | |
------------------ | |
see http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p/ | |
modified for fabric 0.9/1.0 by Hraban (fiëé visuëlle) | |
several additions, corrections and customizations, too |
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
psql database -c "GRANT ALL ON ALL TABLES IN SCHEMA public to user;" | |
psql database -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to user;" | |
psql database -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to user;" |
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.db.models.query import QuerySet | |
from pprint import PrettyPrinter | |
def dprint(object, stream=None, indent=1, width=80, depth=None): | |
""" | |
A small addition to pprint that converts any Django model objects to dictionaries so they print prettier. | |
h3. Example usage | |
>>> from toolbox.dprint import dprint |
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
var formdata = new FormData(); | |
for(var i=0; i<fileInput.files.length; i++){ | |
formdata.append('files', fileInput.files.item(i)); | |
} | |
$.ajax({ | |
url: '/some-url/', | |
type: 'POST', | |
data: formdata, | |
processData: false, |
NewerOlder