Skip to content

Instantly share code, notes, and snippets.

@yumike
yumike / middleware.py
Last active August 23, 2018 14:29
cian-statprof
# coding: utf-8
from cian_statprof.profiler import Profiler
from cian_statprof.sampler import Sampler
profiler = Profiler(Sampler(), Logger(), {'is_enabled': True})
class StatisticalProfilerMiddleware(object):
def process_request(self, request):
@yumike
yumike / base.py
Last active August 23, 2018 14:29
cian-slowlog
# coding: utf-8
import threading
import time
from collections import deque
from datetime import datetime
from functools import wraps
from django.utils.encoding import smart_text
@yumike
yumike / base.py
Last active August 23, 2018 14:29
cian-prof
# coding: utf-8
import re
from collections import defaultdict, deque
from statsd.client import StatsClient, Timer
class Prof(object):
"""Инструмент для профилирования времени исполнения кода в контексте
HTTP-запроса или команды.
@yumike
yumike / feed.py
Last active December 22, 2015 17:58
from django.contrib.syndication.views import Feed
from django.views.generic import View
class FeedView(View, Feed):
def get(self, request, *args, **kwargs):
return self(request, *args, **kwargs)
@yumike
yumike / application.coffee
Last active December 17, 2015 02:59
skel.js usage preview
class Item extends Backbone.Model
initialize: ->
@variants = new Backbone.Collection(@get('variants'))
class Items extends Backbone.Collection
url: '/api/items'
model: Item
parse: (response) -> response.objects
@yumike
yumike / test.py
Created February 19, 2013 11:57
pytest <3
@pytest.mark.parametrize(('uri', 'method', 'expected'), [
('/api/user', 'GET', True),
('/api/user/syncs', 'POST', True),
('/api/user/hooks', 'GET', True),
('/api/user/hooks/1', 'PATCH', True),
('/api/user/repos', 'GET', True),
])
def test_requires_auth(app, uri, method, expected):
with app.test_client() as client:
response = client.open(uri, method=method)
Commit:
- id
- hash
- ref
- compare_url
- committer_name
- committer_email
- message
Push 1:
@yumike
yumike / gist:4085104
Created November 16, 2012 07:28
nginx_site state example
project:
nginx_site:
- managed
- source: salt://projects/files/nginx_site_config
- enable: true
- require:
- service: nginx
@yumike
yumike / gist:3486169
Created August 27, 2012 06:19
How to install all pythons
git clone https://github.com/collective/buildout.python ~/.pythons
cd ~/.pythons
python bootstrap-1.4.4.py --distribute
./bin/buildout
@yumike
yumike / dev.sh
Created August 5, 2012 21:06
start tmux session for project
#!/bin/sh
if [ ! $1 ]; then
echo "Error: project name is not specified."
exit 1
fi
PROJECT_NAME="$1"
SESSION_NAME=${PROJECT_NAME//\./-}
PROJECT_PATH="$PROJECT_HOME/$PROJECT_NAME"