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
@app.route('/api/service/<product_id>/vote/<any(up,down):direction>') | |
@xhr_required | |
@login_required | |
def api_service_vote(product_id, direction): | |
''' thi api need for vote up/down the services''' | |
product = Product.query.get_or_404(product_id) | |
query = Product_Vote.query.filter(Product_Vote.voter_id == g.user.id, | |
Product_Vote.product_id == product.id) |
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
#!/bin/sh | |
FILES=`git diff --cached --name-status | awk '$1 != "D" {print $2}' | grep -E '[.]py$' | grep -v migrations` | |
[ "$NOCHECK" != "" ] || [ "$FILES" = "" ] || flake8 $FILES || exit 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
def plural(n, word, suffix='s'): | |
show_suffix = n % 10 == 1 and n % 100 != 11 | |
return '%d %s%s' % (n, word, '' if show_suffix else suffix) | |
# @register.filter | |
def human_timedelta(delta, precision=2): | |
units = ['year', 'month', 'day', 'hour', 'minute'] | |
unit_delta = [getattr(delta, unit + 's'), unit for unit in units] | |
terms = [plural(n, unit) for n, unit in units if n > 0] | |
terms = terms[:precision] |
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
rat samples: 100%|█████████████████████████████████████████████████████████████████████████████████████████| 94550/94550 [00:11<00:00, 7999.22it/s] | |
mouse samples: 100%|█████████████████████████████████████████████████████████████████████████████████████| 184785/184785 [00:20<00:00, 8892.27it/s] | |
human samples: 100%|█████████████████████████████████████████████████████████████████████████████████████| 894400/894400 [01:32<00:00, 9682.03it/s] | |
Traceback (most recent call last): | |
File "./manage.py", line 11, in <module> | |
execute_from_command_line(sys.argv) | |
File "/home/ubuntu/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line | |
utility.execute() | |
File "/home/ubuntu/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute | |
self.fetch_command(subcommand).run_from_argv(self.argv) |
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 itertools import imap | |
from collections import namedtuple | |
from django.db.models.query import QuerySet, ValuesQuerySet | |
class NamedTuplesQuerySet(ValuesQuerySet): | |
def iterator(self): | |
# Purge any extra columns that haven't been explicitly asked for | |
extra_names = self.query.extra_select.keys() |
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 localurls import Router | |
router = Router() | |
snapshot = router.url('/snapshot/', method='POST') | |
@snapshot.add(query={'action': 'make'}) | |
def snapshot_make(request): | |
pass |
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
-- Возвращает уникальные элементы массива, порядок не сохраняет | |
create or replace function array_uniq(anyarray) returns anyarray as $$ | |
select array(select distinct unnest($1)) | |
$$ language sql immutable strict; | |
-- Аггрегирующая функция для конкатенации массивов | |
create aggregate array_concat ( | |
sfunc = array_cat, | |
basetype = anyarray, | |
stype = anyarray, |
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
# Original code | |
from funcy import ireductions | |
def itemcollector(last, x): | |
if "Node ID" in x: | |
return x | |
if "files" not in last: | |
last["files"] = [] | |
last["files"].append(x) |
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
In [1]: class T(tuple): pass | |
In [2]: t = (1, 2) | |
In [3]: t.__class__ = T | |
TypeError: __class__ assignment: only for heap types |
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 funcy import join | |
def apply_el(data, el): | |
if isinstance(el, str): | |
return {el: data.get(el)} | |
elif isinstance(el, dict): | |
return { | |
k: apply_schema(data.get(k), v) | |
for k, v in el.items() | |
} |