Skip to content

Instantly share code, notes, and snippets.

View happygrizzly's full-sized avatar
🐻

Aleksey Filippov happygrizzly

🐻
View GitHub Profile
http://ibdeveloper.blogspot.com/2008/09/what-page-size-i-should-use-in-my.html
@happygrizzly
happygrizzly / audit_mixin.py
Created December 5, 2017 15:04 — forked from mjhea0/audit_mixin.py
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
class ArticleCardsListItemDefinition extends window.wagtailStreamField.blocks.StructBlockDefinition {
render(placeholder, prefix, initialState, initialError) {
const block = super.render(placeholder, prefix, initialState, initialError);
const categoryField = document.getElementById(prefix + '-category');
const pageField = document.getElementById(prefix + '-page');
const observer = new MutationObserver((mutationList, observer) => {
@happygrizzly
happygrizzly / middleware.py
Created November 16, 2023 12:46 — forked from danizen/middleware.py
Django middleware to collect slow queries using force_debug_cursor
import logging
import time
from django.conf import settings
from django.db import connection
THRESHOLD = getattr(settings, 'SLOW_REQUEST_THRESHOLD', 1.0)
LOG_SQL = getattr(settings, 'SLOW_REQUEST_LOG_SQL', False)
LOG = logging.getLogger(__name__)
@happygrizzly
happygrizzly / logging_config.py
Created November 16, 2023 17:10
Logging config
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S",
},
'sql': {
'format': "[%(asctime)s] %(levelname)s [%(module)s:%(lineno)s] %(message)s",