This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
from rest_framework.compat import coreapi, urlparse | |
from rest_framework.schemas import SchemaGenerator | |
from rest_framework_swagger import renderers | |
from rest_framework.response import Response | |
from rest_framework.views import APIView | |
from rest_framework import exceptions | |
from rest_framework.permissions import AllowAny |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
More details on the implementation and usage can be found at | |
https://www.pyscoop.com/django-jsonfield-attributes-in-admin-filter/ | |
""" | |
from django.contrib import admin | |
from django.core.exceptions import ImproperlyConfigured | |
class JSONFieldFilter(admin.SimpleListFilter): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
https://gist.github.com/Azadehkhojandi/50eaae4cf20b21faef186f2c8ee97873 | |
""" | |
import hmac | |
import hashlib | |
import binascii | |
def create_sha256_signature(key, message): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def filter_dict(src_dict, mapping_dict): | |
for k, v in list(src_dict.items()): | |
if k not in mapping_dict: | |
del src_dict[k] | |
elif isinstance(v, dict) and isinstance(mapping_dict[k], dict): | |
src_dict[k] = filter_dict(v, mapping_dict[k]) | |
return src_dict | |
# ------------------------ TEST ------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
if __name__ == "__main__": | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.settings.base") | |
from django.core.management import execute_from_command_line | |
# ---------- 5 lines ------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: flatten = lambda x: [y for l in x for y in flatten(l)] if type(x) is list else [x] | |
def flatten(x): | |
if type(x) == list: | |
a = [] | |
for l in x: | |
for y in flatten(l): | |
a.append(y) | |
return a | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Fibonacci Number list using tail recursion | |
""" | |
def fib_list(n, a, b, r): | |
if n == 0: return [1] | |
elif n < 0: return [] | |
r.append(a + b) | |
fib(n-1, b, a + b, r) | |
return r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def import_all_items_from_all_modules_in_a_package(): | |
""" | |
Put and call this function in the __init__.py file of the package. | |
This function dynamically loads all non-private classes, functions & variables from all modules | |
with in the current package. this is equivalent to below | |
``` | |
from .abc import * | |
from .xyz import * | |
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.utils import timezone | |
import pytz | |
class ModelMixin: | |
def make_datetime_fields_value_timezone_aware(self): | |
# HACK: Monkey patching to fix TypeError for existing data in DB | |
# TypeError: can't compare offset-naive and offset-aware datetimes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# obfuscated code | |
# install lxml, requests, seleniumbase | |
# python = "3.12" | |
# selenium = "4.18.1" | |
# beautifulsoup4 = "4.12.3" | |
# seleniumbase = "4.24.12" | |
# requests = "2.31.0" |