Skip to content

Instantly share code, notes, and snippets.

View hellysmile's full-sized avatar
🦆
working hard!

Victor Kovtun hellysmile

🦆
working hard!
View GitHub Profile
from fabric.api import env, local, require
def deploy():
"""fab [environment] deploy"""
require('environment')
maintenance_on()
push()
syncdb()
migrate()
(function () {
'use strict';
var cluster = require('cluster'),
http = require('http'),
os = require('os'),
/*
* ClusterServer object
import mongoengine
class MongoModelSerializer(serializers.ModelSerializer):
def get_default_fields(self):
cls = self.opts.model
opts = get_concrete_model(cls)
#pk_field = opts.pk
fields = []
fields += [getattr(opts, field) for field in opts._fields]
#fields += [field for field in opts.many_to_many if field.serialize]
@hellysmile
hellysmile / repositories.py
Last active February 3, 2023 22:27
django repository pattern
from django.contrib.sites.models import Site
class Object(object):
def __init__(self, model, key):
self.model = model
self.key = key
def __call__(self, *args, **kwargs):
params = {}
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
use:
declOfNum(count, ['найдена', 'найдено', 'найдены']);
@hellysmile
hellysmile / middleware.py
Last active December 18, 2015 22:49 — forked from pmclanahan/middleware.py
httponly support
from types import MethodType
from django.http import CompatCookie, HttpRequest
def _set_cookie(self, key, value='', max_age=None, expires=None, path='/',
domain=None, secure=False, httponly=False):
self._resp_cookies[key] = value
self.COOKIES[key] = value
if max_age is not None:
@hellysmile
hellysmile / gist:5653056
Created May 26, 2013 15:09
python subprocess with timeout
def timeout_command(command, timeout):
"""call shell-command and either return its output or kill it
if it doesn't normally exit within timeout seconds and return None"""
import subprocess, datetime, os, time, signal
start = datetime.datetime.now()
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while process.poll() is None:
time.sleep(0.1)
now = datetime.datetime.now()
if (now - start).seconds> timeout:
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
# -*- coding: utf-8 -*-
'''
Created on 2012-09-24
@author: Sergey <[email protected]>
How to test:
$ head -c 100M /dev/urandom > static_file.bin
$ python
yum install rubygems ruby-devel
yum groupinstall 'Development Tools'
gem install fpm
wget http://nginx.org/download/nginx-1.2.6.tar.gz
tar xvf nginx-1.2.6.tar.gz
cd nginx-1.2.6
./configure \
--user=nginx \
--group=nginx \