Skip to content

Instantly share code, notes, and snippets.

View phpdude's full-sized avatar
🏠
Working from home

Alexandr Shurigin phpdude

🏠
Working from home
View GitHub Profile
@phpdude
phpdude / middleware.py
Created December 4, 2011 14:15
Django subdomains Full support
Adds Django full subdomains urls upport for urlpatterns and reverse resolving.
Requires installation into settings.py
Allows you route and generate views various urls.
'''
Example:
'domain.com' -> ''
'domain.com/doc' -> 'doc'
@phpdude
phpdude / nginx.conf
Last active October 6, 2024 19:22
Nginx image filter + caching of results.
location /resize {
alias /tmp/nginx/resize;
set $width 150;
set $height 100;
set $dimens "";
if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" ) {
set $width $1;
set $height $2;
set $image_path $3;
[{"distance": "0.14 miles", "statezip": "New York, NY 10012", "name": "St. Anthonys School", "url": "http://www.greatschools.org/new-york/new-york-city/5320-St.-Anthonys-School/", "grade": "n/a", "address": "60 Mac Dougal Street", "type": "Private"}, {"distance": "0.17 miles", "statezip": "New York, NY 10013", "name": "Chelsea Career and Technical Education High School", "url": "http://www.greatschools.org/new-york/new-york-city/1948-Chelsea-Career-And-Technical-Education-High-School/", "grade": "9-12", "address": "131 Ave of the Americas", "type": "Public"}, {"distance": "0.17 miles", "statezip": "Manhattan, NY 10013", "name": "NYC Ischool", "url": "http://www.greatschools.org/new-york/manhattan/13270-NYC-Ischool/", "grade": "9-11", "address": "131 Ave of the Americas", "type": "Public"}, {"distance": "0.25 miles", "statezip": "New York, NY 10012", "name": "University Plaza Nursery School", "url": "http://pk.greatschools.org/new-york/new-york-city/preschools/University-Plaza-Nursery-School/11467/", "grade":
@phpdude
phpdude / middleware.py
Last active August 29, 2015 13:56
Django user timezones
from django.conf import settings
from django.utils import timezone
import pygeoip
import pytz
db_loaded = False
db = None
def load_db():
@phpdude
phpdude / Boot log
Last active August 29, 2015 13:56
Django Settings Splitter
Loading project.settings submodules: env, paths, apps, assets, cache, celery, compressor, crispy, db, emails, facebook, geoip, i18n, logging, middleware, paypal, portal, security, sessions, template, urls, wsgi
@phpdude
phpdude / middleware.py
Last active October 11, 2017 13:50
Django LocaleByDomainMiddleware - Locale By Domain Middleware
from django.conf import settings
from django.utils import translation
class LocaleByDomainMiddleware():
def process_request(self, request):
host = request.META['HTTP_HOST'].lower()
locales = dict(settings.LOCALE_DOMAINS)
if not host in locales:
@phpdude
phpdude / asyncemail.py
Created March 9, 2014 14:54
Django Simple asynchronous email backend (Celery 3.1+)
from celery import shared_task
from celery.contrib.methods import task_method
from django.core.mail.backends.smtp import EmailBackend as BaseEmailBackend
class FakeLock(object):
__enter__ = lambda x: None
__exit__ = lambda a, b, c, d: None
@phpdude
phpdude / Git hook sync modification time to last commit time
Last active May 20, 2018 23:56
Git post-merge & post-checkout hook for sync changed files timestamps with last commit time (Linux, FreeBSD, Mac OS)
Git hook post-merge and post-checkout for sync modification time to last commit time.
You can download scripts manually and install them yourself, or you can install it with command
> curl -s https://gist.githubusercontent.com/phpdude/9464925/raw/install | sh
This command will download post-merge script, chmod it, and create post-checkout symlink to post-merge hook.
You can also start this script manually with environment variable $GIT_MERGE_LIMIT=100 to updated timestamp of last 100 commits for example.
@phpdude
phpdude / jquery.ezPhotoUploader.js
Created September 1, 2014 15:52
@md5 jQuery ezPhotoUploader.js
(function($) {
var defaults = {
'buttonTitle':'загрузить фотографию',
'url':'/ajax/upload/',
'urlDelete':'/ajax/delete/',
'filesDir':'/upload/',
'allowedExtensions':'jpg,jpeg,png,gif,bmp',
'limit':5, // number of files
'limitSize':4, // filesize limit in Mb
'data':null, // additional data
@phpdude
phpdude / jsonrequest.py
Created October 10, 2014 20:24
JSONRequestMiddleware
import json
from django.http import QueryDict
class JSONMiddleware(object):
"""
Process application/json requests data from GET and POST requests.
"""