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.test.runner import DiscoverRunner | |
class NoDbTestRunner(DiscoverRunner): | |
""" A test runner to test without database creation """ | |
def setup_databases(self, **kwargs): | |
""" Override the database creation defined in parent class """ | |
pass |
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
{% for block in self.body %} | |
<section class="{{ block.block_type }}"> | |
{% if block.block_type == 'fooblock' %} | |
{% get_foo block.value request %} | |
{% else %} | |
{{ block}} | |
{% endif %} | |
</section> | |
{% endfor %} |
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 inspect | |
def fmap(f, functor): | |
def _dict_map(f, functor): | |
result = {} | |
for key, value in functor.items(): | |
result[key] = f(value) | |
return result | |
def _object_map(f, functor): |
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 | |
def compose(*functions): | |
return functools.reduce(lambda f, g: lambda x: f(g(x)), functions, lambda x: x) | |
def curry(fn): | |
def curried(*args, **kwargs): | |
if len(args) + len(kwargs) >= fn.__code__.co_argcount: | |
return fn(*args, **kwargs) |
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
;[true, true, false].every(id => id) // false | |
;[true, true, true].reduce((x, y) => x && y) // true |
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
# filter_by :: [Kwarg] -> lambda QuerySet | |
def filter_by(**kwargs): | |
return lambda qs: qs.filter(**kwargs) | |
# filter_by_type :: QuerySet -> QuerySet | |
filter_by_type = lambda x: filter_by(type=x) | |
# filter_by_project :: QuerySet -> QuerySet |
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
@curry | |
def safe_cast(to_type, value): | |
try: | |
return Just.of(to_type(value)) | |
except: | |
return Nothing | |
to_float = safe_cast(float) | |
to_int = safe_cast(int) | |
to_str = safe_cast(str) |
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
# get_fields :: Model -> [Field] | |
def get_fields(model): | |
return model._meta.get_fields() | |
# get_field :: String -> Model -> Field | |
@curry | |
def get_field(name, model): | |
return model._meta.get_field(name) |
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
const identity = x => x | |
// Monoid | |
Array.empty = () => [] | |
Array.prototype.empty = Array.empty | |
// Monad | |
Array.prototype.chain = function (f) { | |
return Function.prototype.apply.bind([].concat, []) (this.map(f)) | |
} |
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
export const $ = (selector, scope=document) => | |
Array | |
.of(scope.querySelector(selector)) | |
.filter(x => x) | |
export const $$ = (selector, scope=document) => | |
Array.from(scope.querySelectorAll(selector)) |