Example inputs:
Variable | Value |
---|---|
key | the shared secret key here |
message | the message to hash here |
Reference outputs for example inputs above:
| Type | Hash |
class AfterFetchQuerySetMixin: | |
""" | |
QuerySet mixin to enable functions to run immediately | |
after records have been fetched from the DB. | |
""" | |
# This is most useful for registering 'prefetch_related' like operations | |
# or complex aggregations that need to be run after fetching, but while | |
# still allowing chaining of other QuerySet methods. | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) |
from fractions import Fraction | |
def number_str_to_float(amount_str:str) -> (any, bool): | |
""" | |
Take in an amount string to return float (if possible). | |
Valid string returns: | |
Float | |
Boolean -> True |
""" | |
Custom django checks. | |
H001: Field has no verbose name. | |
H002: Verbose name should use gettext. | |
H003: Words in verbose name must be all upper case or all lower case. | |
H004: Help text should use gettext. | |
H005: Model must define class Meta. | |
H006: Model has no verbose name. | |
H007: Model has no verbose name plural. |
# This is a hack so that French translation falls back to English translation, | |
# not German translation (which is the default locale and the original | |
# strings). | |
from django.utils.translation import trans_real | |
class MyDjangoTranslation(trans_real.DjangoTranslation): | |
def _add_fallback(self, localedirs=None): | |
if self._DjangoTranslation__language[:2] in {'de', 'en'}: | |
return super()._add_fallback(localedirs) |
Example inputs:
Variable | Value |
---|---|
key | the shared secret key here |
message | the message to hash here |
Reference outputs for example inputs above:
| Type | Hash |
# 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/', | |
# ) |
#!/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] |
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 |
""" | |
https://gist.github.com/Azadehkhojandi/50eaae4cf20b21faef186f2c8ee97873 | |
""" | |
import hmac | |
import hashlib | |
import binascii | |
# 1 |
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) |