Skip to content

Instantly share code, notes, and snippets.

Oleg Kleshchunov LowerDeez

Block or report user

Report or block LowerDeez

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ordered_set.py
import collections
class OrderedSet(collections.MutableSet):
def __init__(self, iterable=None):
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
if iterable is not None:
self |= iterable
@LowerDeez
LowerDeez / create_sha256_signature.py
Last active Oct 3, 2019 — forked from gjain0/create_sha256_signature.py
Create HMAC SHA256 signature/encryption/encode
View create_sha256_signature.py
"""
https://gist.github.com/Azadehkhojandi/50eaae4cf20b21faef186f2c8ee97873
"""
import hmac
import hashlib
import binascii
# 1
View pipenv.md
sudo apt-get install python3-pip
sudo pip3 install pipenv

If you have any problems with pip or pip3, edit /usr/bin/pip or /usr/bin/pip3 and change the import statement by changing

from pip import main

View Ngixn. Allow access to files from site root
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_connect_timeout 350;
proxy_send_timeout 350;
proxy_read_timeout 350;
proxy_pass http://app_server;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|psd|ai|eo$
root /home/django/public_html;
@LowerDeez
LowerDeez / django_absolute_sum.py
Created Apr 24, 2019 — forked from iandmyhand/django_absolute_sum.py
Django ORM function to sum absolute values.
View django_absolute_sum.py
from django.db.models import Sum
class AbsoluteSum(Sum):
name = 'AbsoluteSum'
template = '%(function)s(%(absolute)s(%(expressions)s))'
def __init__(self, expression, **extra):
super(AbsoluteSum, self).__init__(
expression, absolute='ABS ', output_field=IntegerField(), **extra)
@LowerDeez
LowerDeez / client.py
Created Apr 22, 2019
Python. API Client example
View client.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
import os
import platform
import requests
import requests.exceptions
from requests.compat import json
import traceback
@LowerDeez
LowerDeez / admin.py
Created Oct 24, 2018
Django. Custom views for admin.
View admin.py
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
fieldsets = (
(_('main'), {
'fields': (
'cart', 'date', 'status', 'user', 'name', 'surname', 'phone',
'email', 'delivery_time', 'delivery_type', 'storage_address',
'user_address', 'address_str', 'lift', 'deliverer'
)
}),
@LowerDeez
LowerDeez / decorators.py
Created Oct 19, 2018
Django. Example how to use a class as dacorator
View decorators.py
from functools import wraps
from django.http.response import HttpResponse
from django.utils.decorators import available_attrs
from rest_framework_extensions.settings import extensions_api_settings
from django.utils import six
@LowerDeez
LowerDeez / script.html
Created Oct 8, 2018
Django. Conditions inside mail template
View script.html
{{ order }}: Order
{{ email }}: User email
{% if order.shipping_method.service|lower == "new_post" %}
Новая почта
{% else %}
Не Новая почта
{% endif %}
@LowerDeez
LowerDeez / script.py
Created Oct 1, 2018
Django. Remove GET parameters with specific prefix from querystring
View script.py
qs = request.META.get('QUERY_STRING', '')
querystring = qs.split('&')
filtered_querystring = filter(lambda p: not p.split('=')[0].startswith('utm_'), querystring)
qs = '&'.join(filtered_querystring)
You can’t perform that action at this time.