Skip to content

Instantly share code, notes, and snippets.

@yprez
yprez / nginx.conf
Created Mar 27, 2017 — forked from AysadKozanoglu/jail.conf
fail2ban nginx 404 400 403 444 filter /etc/fail2ban/filter.d/nginx-4xx.conf
View nginx.conf
# nano /etc/fail2ban/filter.d/nginx-4xx.conf
#
[Definition]
failregex = ^<HOST>.*"(GET|POST).*" (404|444|403|400) .*$
ignoreregex =
@yprez
yprez / managers.py
Created Jan 13, 2016
Django - EstimateCountManager (faster, but innacurate counts for PostgreSQL)
View managers.py
from django.db import connection
from django.db import models
class EstimateCountManager(models.Manager):
def estimate_count(self):
"""
Postgres really sucks at full table counts, this is a faster version
see: http://wiki.postgresql.org/wiki/Slow_Counting
"""
@yprez
yprez / fields.py
Last active Jul 22, 2020
Django rest framework - Base64 image field
View fields.py
import base64
from django.core.files.base import ContentFile
from rest_framework import serializers
class Base64ImageField(serializers.ImageField):
def from_native(self, data):
if isinstance(data, basestring) and data.startswith('data:image'):
# base64 encoded image - decode
@yprez
yprez / email_list_field.py
Created Oct 6, 2013
Email list field for Django Rest Framework
View email_list_field.py
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
class EmailListField(serializers.EmailField):
default_error_messages = {
'invalid': _('Invalid E-mail address.'),
}
@yprez
yprez / 5.1
Created Dec 1, 2012
MySQL set unicode as default
View 5.1
[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
[client]
default-character-set=utf8
@yprez
yprez / gist:4127960
Created Nov 21, 2012
Installing pip + virtualenv on Ubuntu
View gist:4127960

Install pip and virtualenv:

sudo apt-get install python_setuptools
sudo easy_install pip
sudo pip install virtualenv virtualenvwrapper

Set the following in ~/.bashrc:

WORKON_HOME=/home/yuri/virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
@yprez
yprez / gist:4061556
Last active Oct 12, 2015
Enable all logging
View gist:4061556
import logging
logging.basicConfig()
logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
You can’t perform that action at this time.