Skip to content

Instantly share code, notes, and snippets.

View mvantellingen's full-sized avatar

Michael van Tellingen mvantellingen

  • Utrecht, The Netherlands
View GitHub Profile
import datetime
import uuid
import psycopg2.extras
from sqlalchemy import Column, MetaData, Table
from sqlalchemy.types import Integer, DateTime, TypeDecorator
from sqlalchemy.dialects.postgresql import ARRAY, array
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql.expression import cast, literal, select
@view_config(route_name='my-route')
def my_view(request):
# here i want to know if path-1 or path-2 was taken, preferably via a var n matchdict?
config.add_route('my-route', '/path-1/view')
config.add_route('my-route', '/path-2/view')
DELETE FROM catalogue_category;
INSERT INTO catalogue_category (path, depth, numchild, name, description, slug) values ("000J", 1, 13, "category 182", "", "category-182");
INSERT INTO catalogue_category (path, depth, numchild, name, description, slug) values ("000M", 1, 35, "category 1300", "", "category-1300");
INSERT INTO catalogue_category (path, depth, numchild, name, description, slug) values ("000D", 1, 10, "category 101", "", "category-101");
INSERT INTO catalogue_category (path, depth, numchild, name, description, slug) values ("0006", 1, 1, "category 56", "", "category-56");
INSERT INTO catalogue_category (path, depth, numchild, name, description, slug) values ("000B", 1, 69, "category 96", "", "category-96");
INSERT INTO catalogue_category (path, depth, numchild, name, description, slug) values ("000E", 1, 22, "category 114", "", "category-114");
INSERT INTO catalogue_category (path, depth, numchild, name, description, slug) values ("0008", 1, 1, "category 66", "", "category-66");
INSERT INT
(function () {
$(function () {
var jwtUI =
'<div class="input"><input placeholder="JWT Token" id="input_jwt" name="jwt" type="text" size="20"></div>';
$(jwtUI).insertBefore('#api_selector div.input:last-child');
$("#input_apiKey").hide();
$('#input_jwt').change(addAuthorization);
});
function addAuthorization() {
var token = $('#input_jwt').val();

Keybase proof

I hereby claim:

  • I am mvantellingen on github.
  • I am mvantellingen (https://keybase.io/mvantellingen) on keybase.
  • I have a public key ASC8-eS38tVDJR4p9Evixizm-G08LMoxSc786Jew1rVcwAo

To claim this, I am signing this object:

@mvantellingen
mvantellingen / apps.py
Created November 22, 2016 09:58
wagtail performance hack
from django.apps import AppConfig
class CMSConfig(AppConfig):
name = 'myproj.apps.cms'
def ready(self):
from wagtail.wagtailcore.models import Site
root_paths = Site.get_site_root_paths()
@mvantellingen
mvantellingen / cache.py
Last active March 15, 2018 11:03
Wagtail StreamField Optimized
import inspect
import logging
from collections import defaultdict
from wagtail.core import blocks
logger = logging.getLogger(__name__)
class _FieldCacheManager():
@mvantellingen
mvantellingen / code-generation-ast.py
Last active December 18, 2018 12:52
Code Generation blog post
>>> import ast, astunparse
>>> node = ast.parse("value = {'foo': 'bar'}")
>>> print(ast.dump(node))
Module(body=[Assign(
targets=[Name(id='value', ctx=Store())],
value=Dict(keys=[Str(s='foo')], values=[Str(s='bar')])
)])
>>> code = astunparse.unparse(node)
>>> print(code)
class AttributeDefinitionDraftSchema(marshmallow.Schema):
type = helpers.Discriminator(
discriminator_field=("name", "name"),
discriminator_schemas={
"boolean": "AttributeBooleanTypeSchema",
"datetime": "AttributeDateTimeTypeSchema",
},
unknown=marshmallow.EXCLUDE,
allow_none=True
)
import attr, marshmallow, typing
@attr.s(auto_attribs=True, init=False, repr=False)
class Price:
id: typing.Optional[str]
def __init__(self, *, id: typing.Optional[str] = None) -> None:
self.id = id