Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Alexandr Shurigin phpdude

🏠
Working from home
View GitHub Profile
View admin.py
from django.contrib.admin import ModelAdmin, register, SimpleListFilter
from django.db.models.functions import Length, StrIndex, Substr, NullIf, Coalesce
from django.db.models import Value as V
from .models import Item
class AlphanumericSignatureFilter(SimpleListFilter):
title = 'Signature (alphanumeric)'
parameter_name = 'signature_alphanumeric'
View README.md

Simplest Async Email Backend for Django

What is this?

It is simplest email backend for Django which supports async email delivery in parallel threads. Keep it simple! It has various analogs, you can google for it yourself.

Requirements

Django async email backend requires futures library. So you need to install it with pip install futures.

@phpdude
phpdude / nginx.conf
Last active November 19, 2022 11:26
Nginx image filter + caching of results.
View nginx.conf
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;
@phpdude
phpdude / clean.py
Created December 10, 2019 16:20
Efficent way to remove docstrings in python source code
View clean.py
import ast
import astor # read more at https://astor.readthedocs.io/en/latest/
parsed = ast.parse(open('source.py').read())
for node in ast.walk(parsed):
# let's work only on functions & classes definitions
if not isinstance(node, (ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef)):
continue
@phpdude
phpdude / linux-curl-cryptopro.md
Last active March 11, 2022 15:55
linux curl с поддержкой КРИПТОПРО
View linux-curl-cryptopro.md

Ремарка: все тесты были на Ubuntu Server 14.04, так же все это справедливо для версии openssl >= 1.0.0. Не советую использовать эту сборку curl для всего что угодно, так как она может быть сильно хуже по возможностям стандартной, так как я компилировал утилиту всего с 1 флагом, и соответственно мог упустить уйму важных ее возможностей. Советую использовать ее как доп утилиту в папке проекта или где попало, не советую в продакшен использовать везде где попало, ну или если с головой подходить к флагам компиляции и сделать это хорошо и по настоящему, у меня такой цели не стоит, делаю на скорую руку, просто как рабочее решение.

  1. Устанавливаем openssl

    apt-get install -y openssl

  2. Настраиваем в linux curl программе (не путать с библиотеками языков типа php_curl.so, там уже сами, но принцип тот же) поддержку криптографических движков:

    GOST2001-GOST89-GOST89 >

@phpdude
phpdude / middleware.py
Created December 4, 2011 14:15
Django subdomains Full support
View middleware.py
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 / vmware-ec2.md
Created December 20, 2017 23:14 — forked from RJ/vmware-ec2.md
Exporting VMWare images (OVA) from EC2
View vmware-ec2.md

How to provision VMWare compatible .ova images on EC2

EC2 only lets you export instances as VMWare-compatible OVA files if you originally imported that instance from an OVA. Presumably it preserves the metadata and XML gubbins for the instance, and just wraps it up again using that metadata on export.

In order to provision arbitrary VMs in an OVA-exportable way, we abuse the volume snapshots on one VM.

Prep work:

  • Make a fresh install of ubuntu server or whatever your base distro is, in VMWare, export as OVA file. (single disk only!)
  • Untar the OVA and import the VMDK file into ec2 using ec2-instance-import onto an HVM instance type (ie, no xen kernel needed)
@phpdude
phpdude / Readme.md
Last active April 18, 2021 05:17
Настройка собственного VPN сервера в два клика
View admin.py
from django.contrib.admin import ModelAdmin, register
from django.db.models import IntegerField
from django.db.models.functions import Cast
from django.db.models.expressions import Func, Value
from .models import Foo
class RegexpMatches(Func):
function = 'REGEXP_MATCHES'
@phpdude
phpdude / yeah!
Created December 14, 2019 17:27
Top ranked in a week =)
View yeah!
Can do it :)