Skip to content

Instantly share code, notes, and snippets.

View LowerDeez's full-sized avatar
🇺🇦
Focusing

Oleg Kleshchunov LowerDeez

🇺🇦
Focusing
  • Kyiv, Ukraine
  • 01:07 (UTC +03:00)
View GitHub Profile
@LowerDeez
LowerDeez / script.py
Created November 2, 2020 11:13
Annotate age for user from birthday
from django.db.models import (
Avg,
Count,
DateField,
ExpressionWrapper,
F,
IntegerField,
Min,
Q,
Value
@LowerDeez
LowerDeez / models.py
Created August 17, 2020 08:16
Adding Counters to Models in the Django Admin Panel
from django.utils.functional import lazy
from django.utils.translation import ugettext_lazy as _
from knowledge.models import Article
class ModeratedArticle(Article):
class Meta:
proxy = True
@LowerDeez
LowerDeez / convert_key.sh
Last active December 28, 2019 07:30 — forked from innocuo/convert_key.sh
Convert PuTTY .ppk key to OpenSSH in Ubuntu
sudo apt-get install putty-tools
# Place your keys in some directory, e.g. your home folder. Now convert the PPK keys to SSH keypairs:cache search
# To generate the private key:
puttygen your_private_key.ppk -O private-openssh -o your_new_key
chmod 600 your_new_key
# Move these keys to ~/.ssh and make sure the permissions are set to private for your private key:
mkdir -p ~/.ssh
@LowerDeez
LowerDeez / decorators.py
Last active December 26, 2019 08:52
Celery. Task no simultaneous execution
from functools import wraps
from django.core.cache import cache
from celery.five import monotonic
CACHE_LOCK_EXPIRE = 10
@LowerDeez
LowerDeez / ordered_set.py
Created October 22, 2019 08:59
Ordered set
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 October 3, 2019 08:39 — forked from gauravvjn/create_sha256_signature.py
Create HMAC SHA256 signature/encryption/encode
"""
https://gist.github.com/Azadehkhojandi/50eaae4cf20b21faef186f2c8ee97873
"""
import hmac
import hashlib
import binascii
# 1
@LowerDeez
LowerDeez / pipenv.md
Last active September 16, 2019 08:41
Pipenv
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

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 April 24, 2019 09:02 — forked from iandmyhand/django_absolute_sum.py
Django ORM function to sum absolute values.
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 April 22, 2019 11:53
Python. API Client example
# -*- 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