tel:+7-927-728-67-99
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
import gevent.monkey | |
gevent.monkey.patch_all() | |
from gevent.wsgi import WSGIServer | |
import pp | |
import ujson | |
pool = pp.PostgresConnectionPool("dbname=api-performance-challenge_development", maxsize=20) | |
HEAD = ('id', 'text', 'created_at', 'likes_count', 'liked') | |
def application(environ, start_response): |
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
SELECT array_to_json(array_agg(row_to_json(t))) | |
FROM | |
(SELECT id, text, Cast(created_at AS text), | |
likes_count, | |
CASE | |
WHEN l.value THEN TRUE | |
ELSE FALSE | |
END AS liked | |
FROM posts | |
LEFT OUTER JOIN |
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
import sys | |
from importlib.machinery import ModuleSpec, SourceFileLoader | |
pundles = dict([item.strip() for item in line.split(',')] for line in open('Pundlerfile').readlines()) | |
class PundlerFinder(object): | |
def find_spec(self, fullname, path, target_module): | |
if path is not None: |
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
>>> import code | |
>>> import dis | |
>>> def func(): | |
... d = {} | |
... d.update({'a': 2, 'b':3}) | |
... | |
>>> dis.dis(func.__code__) | |
2 0 BUILD_MAP 0 | |
3 STORE_FAST 0 (d) |
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
- import json | |
- def ku(text): | |
h2 | |
- yield text | |
p | |
- yield "Awesome" | |
!doctype/ | |
head | |
title "magic is a pony" |
Захотелось мне сделать шаблонизатор, чтобы как slim, теги чтобы автоматом закрывались и прочее. Красиво же так:
html
head
title
- yield "Плюшка!" + " Чашка чаю!"
Но и этого мне мало, хочу чтобы не было своего недоязыка, хочу чтобы просто питоновские конструкции. А кто захочет себе в ногу стрельнуть и бизнес логики в шаблоны навалить, то это проблема начинашек, мне зачем мучаться размазывая код вьюх в папки типа utils, template_tags и прочее?
А и еще можно кстати угореть так уж угореть - а пусть шаблоны через новый махнизм импорта в python 3 тянутся. И если надо что-то от другого шаблона себе вставить, то тоже пусть также работает.
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
import sys | |
import time | |
import threading | |
import queue | |
from subprocess import Popen | |
from watchdog.observers import Observer | |
from watchdog.events import LoggingEventHandler | |
EVENTS = ['modified', 'deleted', 'created', 'moved'] |
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
list_or_string = (t.List(t.String(allow_blank=True)) >> first) | t.String(allow_blank=True) | |
check_comma_string = list_or_string >> (lambda s: s.split(',')) >> t.List(t.String(allow_blank=True) >> str.strip) | |
list_or_string_date = (t.List(t.String(allow_blank=True)) >> first) | t.String(allow_blank=True) | |
parse_ga_qs = t.Dict({ | |
t.Key('start-date') >> 'start': list_or_string_date, | |
t.Key('end-date') >> 'end': list_or_string_date, | |
t.Key('dimensions', optional=True): check_comma_string, |
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 input(name, type="text"): | |
input.form-control{"name": name, "type": type, "value": request.args.get(name, '')} | |
- def form_control(name): | |
div.form-group | |
label.col-sm-2.control-label | |
= name | |
div.col-sm-4 | |
== input(name) |