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 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 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
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 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 localurls import Router | |
router = Router() | |
snapshot = router.url('/snapshot/', method='POST') | |
@snapshot.add(query={'action': 'make'}) | |
def snapshot_make(request): | |
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
-- Возвращает уникальные элементы массива, порядок не сохраняет | |
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 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
#!/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 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 parseStrings(obj) { | |
if (_.isString(obj)) { | |
var f = parseFloat(obj); | |
return Number.isName(f) ? obj : f; | |
} else if (_.isArray(obj)) { | |
obj.forEach(function (v, i) { | |
obj[i] = parseStrings(v); | |
}) | |
} else if (_.isObject(obj)) { | |
_.forOwn(obj, function (v, k) { |
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
# Usage | |
log_key = 'smth:%d:log' % some_id | |
with extra_logging_handler('name', RedisHandler(key=log_key)): | |
# Do your thing | |
# ... | |
# Implementation |
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 MemoizingStream(object): | |
""" | |
Write always to end, read from separate position. | |
""" | |
def __init__(self, fd): | |
print 'create memo' | |
self.memory = StringIO() | |
self.source_fd = fd | |
self.finished = False |
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 gzip, zlib | |
def ungzip_stream(fd): | |
plain_fd = gzip.GzipFile(fileobj=fd, mode="r") | |
# NOTE: this is what GzipFile does on new file start, | |
# we do that directly as GzipFile tries to seek() before it | |
# and fd could be unseekable(). | |
plain_fd._init_read() | |
plain_fd._read_gzip_header() | |
plain_fd.decompress = zlib.decompressobj(-zlib.MAX_WBITS) |
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
[program:celery] | |
; Full path to use virtualenv, honcho to load .env | |
command=/home/ubuntu/venv/bin/honcho run celery -A stargeo worker -l info --no-color | |
directory=/home/ubuntu/app | |
environment=PATH="/home/ubuntu/venv/bin:%(ENV_PATH)s" | |
user=ubuntu | |
numprocs=1 | |
stdout_logfile=/home/ubuntu/logs/celery.log | |
stderr_logfile=/home/ubuntu/logs/celery.err |