Skip to content

Instantly share code, notes, and snippets.

@Suor
Suor / Review.md
Last active August 29, 2015 14:15
WaypointsMover review

Отступы

Не нужно смешивать табы с пробелами. Конкретно для тебя проблема решается автозаменой таба на 4 пробела по всему коду. Также стоит настроить редактор, чтобы он заменял табы на пробелы при вводе.

Функциональность

Класс реализует две пересекающиеся функциональности. Возможно, имеет смысл разделить на два? Стоит помнить, что разделение, хоть и упрощает каждый класс в отдельности, всю систему может усложнить или хотя бы банально привести к большему количеству кода.

Альтернатива разделению - обособление частей кода отвечающих за линейное и за криволинейное движение. Сейчас это сделано для методов, но остаются аттрибуты, вызовы этих методов и хак в конструкторе.

@Suor
Suor / pre-commit
Last active August 29, 2015 14:15
Never commit prints again
#!/bin/sh
PRINTS=`git diff --cached -U0 | grep ^+ | grep -E '\bprint(\b|_)'`
if [ -n "$PRINTS" ]; then
echo "ERROR: you are going to commit prints:\n"
git diff --cached -U0 -G'\bprint(\b|_)'
exit 1
fi
@Suor
Suor / 0_initial.py
Last active August 29, 2015 14:16
Text Justify Code Review
import textwrap
# def task_with_text(text, width):
# new_text = textwrap.TextWrapper()
# new_text.width = width
# return new_text
#print task_with_text("Napoleon was born on the island of Corsica to a relatively modest family of noble Italian ancestry.", 7)
# def justify_line(line, width):
@Suor
Suor / keybase.md
Created March 2, 2015 05:11
keybase.md

Keybase proof

I hereby claim:

  • I am Suor on github.
  • I am hackflow (https://keybase.io/hackflow) on keybase.
  • I have a public key whose fingerprint is 6702 5527 9A65 45AE AADD 4C03 19CE B1F1 C0BE 3351

To claim this, I am signing this object:

@Suor
Suor / test_works.py
Created March 12, 2015 09:31
Test against real database with pytest-django
import pytest
@pytest.fixture()
def real_db(_django_cursor_wrapper):
_django_cursor_wrapper.enable()
def test_index(client, real_db):
response = client.get('/')
@Suor
Suor / README.md
Last active August 29, 2015 14:18
Sublime Reform plugin showcase

Sublime Reform plug-in showcase

Here I will demonstrate a few things Reform plug-in is capable of.

Navigation

You can move up and down by function declarations, blocks of code and words.

[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
@Suor
Suor / ungzip_stream.py
Last active August 29, 2015 14:23
Ungzip stream on the fly in Python 2
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)
@Suor
Suor / memo_stream.py
Created July 3, 2015 02:56
Memoizing IO Stream
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
@Suor
Suor / redis_logger.py
Last active August 29, 2015 14:27
A decorator/context manager to route logging to redis
# Usage
log_key = 'smth:%d:log' % some_id
with extra_logging_handler('name', RedisHandler(key=log_key)):
# Do your thing
# ...
# Implementation