Skip to content

Instantly share code, notes, and snippets.

View LowerDeez's full-sized avatar
🇺🇦
Focusing

Oleg Kleshchunov LowerDeez

🇺🇦
Focusing
  • Kyiv, Ukraine
  • 07:01 (UTC +03:00)
View GitHub Profile
from collections import defaultdict
import weakref
__refs__ = defaultdict(weakref.WeakSet)
def clear_refs(cls):
__refs__[cls].clear()
@LowerDeez
LowerDeez / sha256-hmac.md
Created March 5, 2021 15:03 — forked from jasny/sha256-hmac.md
Hashing examples in different languages

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

@LowerDeez
LowerDeez / middleware.py
Created February 18, 2021 07:09 — forked from bryanchow/middleware.py
Django SSL Redirect Middleware - Django middleware for automatically redirecting to HTTPS for specific URLs
# https://gist.github.com/1035190
# See also: Snippets 85, 240, 880 at http://www.djangosnippets.org/
#
# Minimally, the following settings are required:
#
# SSL_ENABLED = True
# SSL_URLS = (
# r'^/some/pattern/',
# )
@LowerDeez
LowerDeez / admin.py
Created December 30, 2020 07:48
Django. Custom views for admin 2
from django import forms
from django.db.models import FilteredRelation, Q
from django.urls import path
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.http import urlencode
from django.utils.translation import ugettext_lazy as _
@LowerDeez
LowerDeez / admin.py
Last active December 30, 2020 07:43
Django. Custom views for admin.
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = [
'name',
'status',
'add_product_action',
'add_mattress_action'
]
list_display_links = ['name', 'status']
readonly_fields = [
@LowerDeez
LowerDeez / attrdict.py
Created December 21, 2020 11:59 — forked from turicas/attrdict.py
Python class with dict-like get/set item
#!/usr/bin/env python
# coding: utf-8
class AttrDict(object):
def __init__(self, init=None):
if init is not None:
self.__dict__.update(init)
def __getitem__(self, key):
return self.__dict__[key]
@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 / handlers.py
Created March 22, 2018 07:40
Django. Signal to check when user login
from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
from django.contrib.gis.geoip2 import GeoIP2
from django.conf import settings
import geoip2
from apps.mailer.tasks import send_template_email
from .models import LoginStatistics
@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