Skip to content

Instantly share code, notes, and snippets.

View happygrizzly's full-sized avatar
🐻

Aleksey Filippov happygrizzly

🐻
View GitHub Profile
@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",
@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__)
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 / 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)
http://ibdeveloper.blogspot.com/2008/09/what-page-size-i-should-use-in-my.html
@happygrizzly
happygrizzly / vuejs-php.md
Created October 19, 2017 14:52
VueJs and PHP

VueJs and PHP

Setup

First test

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
@happygrizzly
happygrizzly / vhost.conf
Created July 7, 2017 08:43
vhost config
<VirtualHost localhost:YOUR_PORT>
ServerName localhost
Define WebDirPath WEB_ROOT_DIR_PATH
DocumentRoot ${WebDirPath}
Alias /YOUR_PROJECT_NAME ${WebDirPath}
<Directory ${WebDirPath}>
Options -Indexes
@happygrizzly
happygrizzly / knockout.bootstrap.glyphicon.tree.css
Created April 14, 2017 07:24 — forked from seiyria/knockout.bootstrap.glyphicon.tree.css
A custom, collapsible navigation tree using knockout.js (and knockout.mapping.js), Bootstrap 3, and glyphicons. Example picture: http://puu.sh/5RWjW.png, fiddle here: http://jsfiddle.net/Ar88e/1/
#nav-bar ul {
list-style-type: none;
}
#nav-bar {
padding-left: 0;
}
#nav-bar > ul {
padding-left: 20px;
CREATE TABLE `documents` (
`id` INT NOT NULL AUTO_INCREMENT,
`id_category` INT NOT NULL,
-- `id_department` INT NOT NULL,
`title` VARCHAR(150) NOT NULL,
`comment` MEDIUMTEXT,
`filename` VARCHAR(150),
`ts` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_category`) REFERENCES categories(`id`) ON DELETE NO ACTION