Skip to content

Instantly share code, notes, and snippets.

@nealtodd
nealtodd / settings_test_snippet.py
Last active November 14, 2019 01:25
Skip migrations for a Django 1.7 test run
# If your test settings file doesn't import any other settings file
# then you can use the function directly:
def prevent_tests_migrate(db):
import django
from django.db import connections
from django.db.migrations.executor import MigrationExecutor
django.setup()
ma = MigrationExecutor(connections[db]).loader.migrated_apps
return dict(zip(ma, ['{a}.notmigrations'.format(a=a) for a in ma]))
@addyosmani
addyosmani / package.json
Last active May 29, 2024 15:54
npm run-scripts boilerplate
{
"name": "my-app",
"version": "1.0.0",
"description": "My test app",
"main": "src/js/index.js",
"scripts": {
"jshint:dist": "jshint src/js/*.js",
"jshint": "npm run jshint:dist",
"jscs": "jscs src/*.js",
"browserify": "browserify -s Validating -o ./dist/js/build.js ./lib/index.js",
@NotSqrt
NotSqrt / settings_test_snippet.py
Last active May 1, 2022 01:34 — forked from nealtodd/settings_test_snippet.py
Another shot at this problem ..
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return "notmigrations"
MIGRATION_MODULES = DisableMigrations()
# HTTPS youtube embeds for wagtail
# Put this file in your project and add the following to your settings:
# WAGTAILEMBEDS_EMBED_FINDER = 'myapp.embeds.custom_embed_finder'
import json
import re
from six.moves.urllib.request import Request, urlopen
from six.moves.urllib.error import URLError
from wagtail.wagtailcore.models import get_page_models
from wagtail.wagtailcore.utils import resolve_model_string
class SinglePageInstanceMixin(object):
@classmethod
def clean_parent_page_types(cls):
"""
Rewrite wagtailcore.models.Page.clean_parent_page_models to ensure that
@vkurup
vkurup / generate_factories.py
Last active April 16, 2021 20:03 — forked from tobiasmcnulty/generate_factories.py
Django management command to generate factory-boy boilerplate factory definitions for all the models in a given app. The code is not intended to be usable right off the bat, it just provides a few sane defaults based on the structure of your models.
from django.core.management.base import BaseCommand
from django.db.models import get_models, get_app, fields
from django.db.models.fields import related
class Command(BaseCommand):
help = """Generate factory-boy factories for the given app"""
def handle(self, *args, **options):
assert len(args) == 1, 'Must specify app name as first and only argument'
@paulirish
paulirish / what-forces-layout.md
Last active May 31, 2024 22:37
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@davecranwell
davecranwell / responsive_image.py
Last active December 16, 2020 21:37
Responsive image tag for Wagtail CMS
from django import template
from django.template import Context
from django.template.base import parse_bits
from wagtail.wagtailimages.templatetags.wagtailimages_tags import ImageNode
from wagtail.wagtailimages.models import Filter, SourceImageIOError, InvalidFilterSpecError
from britishswimming.utils.models import SocialMediaSettings
register = template.Library()
from django.utils import timezone
from wagtail.wagtailsearch.backends.elasticsearch import ElasticSearch, ElasticSearchQuery
from wagtail.wagtailcore.models import Page
from wagtail.wagtailimages.models import AbstractImage
from wagtail.wagtaildocs.models import Document
class ElasticSearchQueryWithRecency(ElasticSearchQuery):
@alexgleason
alexgleason / file-extensions.json
Last active December 14, 2018 02:54
Human readable descriptions for file extensions. Scraped from https://en.wikipedia.org/wiki/List_of_filename_extensions
{"DD": [{"description": "Macintosh file archive", "used_by": "DISKDOUBLER"}], "CHZ": [{"description": "Archive", "used_by": "CHARC"}], "EUI": [{"description": "Ensoniq EPS family CD image", "used_by": "AWAVE"}], "INI": [{"description": "Initialization file", "used_by": ""}], "CHI": [{"description": "ChiWriter Document", "used_by": "ChiWriter - Chiview"}], "OCT": [{"description": "Musical file", "used_by": "Pctalizer"}], "GFO": [{"description": "SGI Radiosity", "used_by": ""}], "QVD": [{"description": "QlikView Document (Data)", "used_by": "QlikView Compressed Database File"}], "MCW": [{"description": "Text file", "used_by": "MacWrite II"}], "HI": [{"description": "Game high scores table", "used_by": ""}], "ZUR": [{"description": "High level compressed file", "used_by": ""}], "FPU": [{"description": "Configuration file", "used_by": "FoxPro for Unix"}], "F": [{"description": "Archive", "used_by": "FREEZE"}, {"description": "Forth language source code file", "used_by": "Forth development systems"}, {"description