Skip to content

Instantly share code, notes, and snippets.

View sky-code's full-sized avatar
😱
Kernel panic: …

Ihor Aleksandrov sky-code

😱
Kernel panic: …
View GitHub Profile
def select_fields_from_schema(schema: BaseModel, queryset: QuerySet, extend_include: list[str], exclude: list[str]):
fields = set(schema.model_fields.keys())
if extend_include:
fields = fields.union(extend_include)
if exclude:
fields = fields.difference(exclude)
queryset_model_fields = [f.name for f in queryset.model._meta.get_fields() if f.concrete]
fields = fields.intersection(queryset_model_fields)
return queryset.values(*fields)
@pytest.fixture()
def patch_cls(monkeypatch):
def do_patch_cls(cls: type, mock: Any = None):
if mock is None:
mock = MagicMock(spec=cls)
def mock__new__(_cls, *_args, **_kwargs):
return mock
cls__new__ = cls.__new__
@sky-code
sky-code / .dockerignore
Created June 1, 2020 09:55
python dockerignore
**/__pycache__/
**/.mypy_cache
.pytest_cache
**/.pytest_cache
**/.tox
**/.vscode
**/.idea
**/.coverage
**/.DS_Store
**/.eggs
@sky-code
sky-code / README.md
Created June 24, 2019 00:38
Github export import issue labels
@sky-code
sky-code / __init__.py
Created November 24, 2018 13:15
electron-cash
from electroncash.commands import command, Commands
fullname = 'Get tx height'
description = 'Provides get_tx_height command for rpc daemon'
@command('')
def get_tx_height(self, tx_hash):
height, conf, timestamp = self.wallet.get_tx_height(tx_hash)
# noinspection PyProtectedMember
@sky-code
sky-code / __init__.py
Created November 24, 2018 13:14
electrum plugin for get_tx_height rpc command
from electrum.commands import command, Commands
fullname = 'Get tx height'
description = 'Provides get_tx_height command for rpc daemon'
@command('')
def get_tx_height(self, tx_hash):
tx_mined_status = self.wallet.get_tx_height(tx_hash)
# noinspection PyProtectedMember
000.0x1f4b0.com
001.0x1f4b0.com
002.0x1f4b0.com
003.0x1f4b0.com
004.0x1f4b0.com
005.0x1f4b0.com
006.0x1f4b0.com
007.0x1f4b0.com
008.0x1f4b0.com
009.0x1f4b0.com
@sky-code
sky-code / setup.py
Created August 30, 2018 15:19
setup.py install_requires from pipfile
from setuptools import setup
from pipenv.project import Project
from pipenv.utils import convert_deps_to_pip
def get_packages_from_Pipfile():
pipfile = Project(chdir=False).parsed_pipfile
return convert_deps_to_pip(pipfile['packages'], r=False)
"""
Exports Issues from a specified repository to a json files
Uses basic authentication (Github username + password) to retrieve Issues
from a repository that username has access to. Supports Github API v3.
"""
import json
import requests
@sky-code
sky-code / converters.py
Created April 25, 2018 21:57
django bson ObjectID url path validator
from bson.objectid import ObjectId
class ObjectIDConverter:
regex = '[0-9A-Fa-f]{24}'
def to_python(self, value):
if ObjectId.is_valid(value):
return value
raise ValueError()