Skip to content

Instantly share code, notes, and snippets.

View Sovetnikov's full-sized avatar
🙂

Sovetnikov

🙂
View GitHub Profile
import logging
import os
ABSOLUTE_PATH = lambda x: os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), x))
# For Django 1.7.7 sqlite and spatialite
# Uses monkeypatch
#
# Runs tests as:
# 1. Create initial db and apply all migrations if it does not exists
@Sovetnikov
Sovetnikov / run_celery_cam.py
Created February 13, 2017 19:10
How to run celery cam to save memory by not loading all modules of your app
import os
import time
from copy import copy
from celery.events.snapshot import evcam
from qiwichain import settings as novtest_settings
from qiwichain.celery import app
DATABASES = copy(novtest_settings.DATABASES)
import os
import subprocess
import unittest
from datetime import timedelta
from random import SystemRandom
from celery import Celery
from kombu import Exchange
from kombu import Queue
@Sovetnikov
Sovetnikov / socks.py
Created January 14, 2018 16:19
SocksiPy рабочий для Python 3.4
"""SocksiPy - Python SOCKS module.
Version 1.00
Copyright 2006 Dan-Haim. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
import random
import re
import socket
import ssl
from urllib.parse import urlparse
from urllib.request import urlopen
import socks
from shared.enum import StrEnum
@Sovetnikov
Sovetnikov / dramatiq_eager_broker.py
Created June 27, 2019 13:20
Dramatiq eager broker for unittest
from dramatiq import Worker
from dramatiq.brokers.stub import StubBroker
from dramatiq.worker import _WorkerThread, _ConsumerThread
class EagerBroker(StubBroker):
def __init__(self, *args, **kwargs):
super(EagerBroker, self).__init__(*args, **kwargs)
self.worker = Worker(self, worker_timeout=100)
@Sovetnikov
Sovetnikov / fsm_log_inline.py
Last active July 30, 2019 20:50
django-fsm-log admin model inline for Django 1.7.7
from django.contrib.admin import TabularInline
from django.contrib.admin.utils import flatten_fieldsets
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.forms import BaseInlineFormSet, BaseModelFormSet
from django_fsm_log.models import StateLog
# Making possible to show django inline model admin without actual foreign key to parent model
# Works by making new model that has required FK (just to pass startup checks) and overriding actual queryset generated in FormSet
# For Django 1.7.7
@Sovetnikov
Sovetnikov / original_theme.scss
Created November 26, 2020 10:13
Remove all unmodified css from customized buefy theme
// Import Bulma's core
@import "../../node_modules/bulma/sass/utilities/_all";
// Import Bulma and Buefy styles
@import "../../node_modules/bulma/bulma.sass";
@import "../../node_modules/buefy/src/scss/buefy";