Skip to content

Instantly share code, notes, and snippets.

import math
import fontPens.marginPen
import fontTools.designspaceLib
import fontTools.feaLib.parser
import ufoLib2
DOT_BELOW_Y_MAX = -50
\documentclass[letterpaper,draft,11pt]{memoir}
\pdfvariable minorversion=7
\usepackage{fontspec}
\usepackage{microtype}
\input{ushyphex}
\defaultfontfeatures{Scale=MatchLowercase}
\setmainfont{TeX Gyre Pagella}
@inklesspen
inklesspen / README.md
Last active September 6, 2023 17:11
Fast and flexible unit tests with live Postgres databases and fixtures

(This gist is pretty old; I've written up my current approach to the Pyramid integration on this blog post, but that blog post doesn't go into the transactional management, so you may still find this useful.)

Fast and flexible unit tests with live Postgres databases and fixtures

I've created a Pyramid scaffold which integrates Alembic, a migration tool, with the standard SQLAlchemy scaffold. (It also configures the Mako template system, because I prefer Mako.)

I am also using PostgreSQL for my database. PostgreSQL supports nested transactions. This means I can setup the tables at the beginning of the test session, then start a transaction before each test happens and roll it back after the test; in turn, this means my tests operate in the same environment I expect to use in production, but they are also fast.

I based my approach on [sontek's blog post](http://sontek.net/blog/

@inklesspen
inklesspen / README.md
Last active May 5, 2023 20:06
py.test session fixtures

Pytest's session fixture scope is really handy, but there are some things which need to execute only once per actual test session. For example, one of my session fixtures sets up DB tables at the start of the test session and tears them down at the end. (I use PostgreSQL's nested transactions to keep from having to drop and recreate tables between each individual test.)

@pytest.fixture(scope='session')
def dbtables(request, sqlengine):
    Base.metadata.create_all(sqlengine)

    def teardown():
        Base.metadata.drop_all(sqlengine)
from sqlalchemy import DateTime
from sqlalchemy.types import TypeDecorator
class AwareDateTime(TypeDecorator):
"""
A DateTime type which can only store tz-aware DateTimes
"""
impl = DateTime(timezone=True)
def process_bind_param(self, value, dialect):
@inklesspen
inklesspen / kernel.patch
Created April 10, 2021 19:12
Clara HD kernel changes, 2018 to 2021
diff --git a/kernel-2018/arch/arm/boot/dts/imx6sll-ntx.dtsi b/kernel-2021/arch/arm/boot/dts/imx6sll-ntx.dtsi
index 5121ada..f6c7d09 100644
--- a/kernel-2018/arch/arm/boot/dts/imx6sll-ntx.dtsi
+++ b/kernel-2021/arch/arm/boot/dts/imx6sll-ntx.dtsi
@@ -52,15 +52,15 @@
operating-points = < /* Core2_1V3_ARM */
/* kHz uV */
996000 1275000
- 792000 1175000
- 396000 1175000
@inklesspen
inklesspen / post-checkout.py
Created June 10, 2014 21:54
Post-checkout hook to detect alembic issues when switching branches.
#!/usr/bin/env python
"""
Provide useful alembic information after switching branches.
"""
import argparse
import subprocess
import os
import os.path
import py.path
@inklesspen
inklesspen / gist:4222841
Created December 6, 2012 08:39
ACLs, context objects, and URL Dispatch in Pyramid
# A worked example based on http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/urldispatch.html#using-pyramid-security-with-url-dispatch
# in your configuration section (typically in myapp/__init__.py)
config.add_route('articles.edit', 'article/{id}/edit', factory='myapp.acl.ArticleACL')
# in myapp/acl.py
class ArticleACL(object):
def __init__(self, request):
# First, we assume this ACL object is used only in routes that provide an article id; if need be, you can add some sanity checking here, or some if/else branching
import base64
import json
def extract_jwt_claims(req):
header = req.headers.get('X-Endpoint-API-UserInfo')
if header is None:
return None
val = json.loads(base64.urlsafe_b64decode(header))
claims_json = val['claims']
claims = json.loads(claims_json)
@inklesspen
inklesspen / __init__.py
Created October 8, 2016 07:55
ACL Example with Pyramid non-traversal
from pyramid.config import Configurator
from pyramid.session import SignedCookieSessionFactory
from pyramid.authentication import SessionAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.security import Allow, Authenticated, Everyone
class Public(object):
__acl__ = [(Allow, Everyone, 'view')]