Skip to content

Instantly share code, notes, and snippets.

@Guest007
Guest007 / a2dp.py
Created November 9, 2020 09:20 — forked from pylover/a2dp.py
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04, 16.10 and also debian jessie, with bluez5.
#! /usr/bin/env python3.5
"""
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04 and also debian jessie, with bluez5.
Workaround for bug: https://bugs.launchpad.net/ubuntu/+source/indicator-sound/+bug/1577197
Run it with python3.5 or higher after pairing/connecting the bluetooth stereo headphone.
This will be only fixes the bluez5 problem mentioned above .
@Guest007
Guest007 / donotuse3.py
Created September 25, 2020 09:17 — forked from MineRobber9000/donotuse3.py
How to NEVER use lambdas - Python 3 edition
###########################################################
# How to NEVER use lambdas. An inneficient and yet educa- #
# tonal [sic] guide to the proper misuse of the lambda #
# construct in Python 3.x. [DO NOT USE ANY OF THIS EVER] #
# original by (and apologies to): e000 (13/6/11) #
# now in Python 3 courtesy of: khuxkm (17/9/20) #
###########################################################
## Part 1. Basic LAMBDA Introduction ##
# If you're reading this, you've probably already read e000's
@Guest007
Guest007 / admin.py
Created August 25, 2020 10:51
django admin filter for GenericForeignKey field
# https://djangosnippets.org/snippets/10564/
list_filter = [
'name',
get_generic_foreign_key_filter(
u'Filter Target',
content_type_id_field='target_ct',
object_id_field='target_id'
)
]
@Guest007
Guest007 / README.md
Created July 7, 2020 08:16 — forked from MineRobber9000/README.md
Import Python modules from GitHub

githubimport

Allows you to import Python modules from the top level of a GitHub repository. Basically, golang's import semantics but in Python fashion.

>>> import githubimport
>>> from MineRobber9000.test_modules import blah
>>> blah.foo()
"bar"
@Guest007
Guest007 / admin.py
Created June 29, 2020 07:19 — forked from gauravvjn/admin.py
Use JSONField properties in Django admin filter Raw
"""
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):
@Guest007
Guest007 / model_relationship.py
Created June 6, 2020 20:17 — forked from mrworksome/model_relationship.py
async databases return relationship post
#________________microblog schema.py___________________
class PostBase(BaseModel):
title: str
text: str
date: datetime
class PostCreate(PostBase):
@Guest007
Guest007 / settings.py
Created May 14, 2020 09:32 — forked from ipmb/settings.py
Django logging example
import logging.config
import os
from django.utils.log import DEFAULT_LOGGING
# Disable Django's logging setup
LOGGING_CONFIG = None
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()
logging.config.dictConfig({
@Guest007
Guest007 / json_schemed_field.py
Created March 21, 2020 09:31 — forked from Bahus/json_schemed_field.py
Django JSONField with Pydantic schema support
from functools import partial
import pydantic
import logging
from django.contrib.postgres.fields import JSONField
from typing import Type, Union, Tuple
from django.core.serializers.json import DjangoJSONEncoder
@Guest007
Guest007 / django_migration_pk_to_uuid.py
Created February 20, 2020 20:06 — forked from smcoll/django_migration_pk_to_uuid.py
Django migration converting integer pk table to UUID pk table
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import uuid
from django.db import migrations, models
def fill_mymodel_uuid(apps, schema_editor):
db_alias = schema_editor.connection.alias
MyModel = apps.get_model('myapp', 'MyModel')
@Guest007
Guest007 / make_crud.py
Created December 23, 2019 18:26 — forked from Bobronium/make_crud.py
FastAPI CRUD fabric to reduce amount of boilerplate code
import inspect
from functools import partial
from typing import Type, Literal, Callable, Dict, TypeVar, List, Generic
from fastapi import APIRouter, Depends
from pydantic.generics import GenericModel
# import your database base model here
# from db_model import BaseDBModel