Skip to content

Instantly share code, notes, and snippets.

View nickretallack's full-sized avatar

Nick Retallack nickretallack

View GitHub Profile
<Routes location="history">
<Route handler={AdminLayout} flux={flux}>
<Route name="home" path="/" handler={FrontPage}/>
</Route>
<Route handler={AuthenticationLayout}>
<Route name="sign-in" path="/sign-in" handler={LoginForm} />
</Route>
</Routes>
@nickretallack
nickretallack / gist:76bcd65cc0305abcd33b
Last active August 29, 2015 14:08
How do I override the query class in Flask-SQLAlchemy?
from flask import *
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy.orm import Query
class MyQuery(Query): pass
db = SQLAlchemy(session_options={'query_cls': MyQuery})
class MyModel(db.Model):
@nickretallack
nickretallack / gist:ec096a8013046c42d8f9
Created October 30, 2014 01:00
LocalProxy and Flask-SQLAlchemy don't play nicely together
from flask import Flask, Response
from flask.ext.sqlalchemy import SQLAlchemy
from werkzeug.local import LocalProxy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config["SQLALCHEMY_ECHO"] = True
db = SQLAlchemy(app)
@nickretallack
nickretallack / add-middle-name.json
Last active August 29, 2015 14:08
Demonstrates how a simplistic JSON PATCH could miss out on an intermediate value due to a race condition.
{
"name":{
"middle":"John"
}
}
@nickretallack
nickretallack / gist:81730aa53ff40fc05a56
Created October 30, 2014 23:51
setting search path messes up extensions?
$ createdb testext
$ psql testext
psql (9.3.5)
Type "help" for help.
testext=# create schema things;
CREATE SCHEMA
testext=# set search_path to things,public;
SET
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Tenant(db.Model):
__tablename__ = 'tenant'
name = db.Column(db.String, nullable=False, unique=True, primary_key=True)
__table_args__ = {"schema_name":"public"}
@nickretallack
nickretallack / env.py
Last active March 16, 2023 20:57
How to run multi-tenant migrations in alembic.
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool, MetaData, Table, ForeignKeyConstraint
from logging.config import fileConfig
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
@nickretallack
nickretallack / joins.py
Last active May 21, 2023 22:18
How do I do a join without a real foreign key constraint?
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey, Integer, String, ForeignKeyConstraint
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, relationship
Model = declarative_base()
class Parent(Model):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
package main
import (
"net/http"
"code.google.com/p/gogoprotobuf/proto"
"path/to/protobufs"
"io/ioutil"
)
func read_protobuf(request *http.Request) *protobufs.MyMessage {
body, err := ioutil.ReadAll(request.Body)
@nickretallack
nickretallack / test_spkac.sh
Last active January 23, 2018 05:28
This should work, right?
openssl genrsa -out private.pem 4096
openssl spkac -key private.pem > public.spkac
echo "CN=test" >> public.spkac
openssl ca -config openssl.conf -extensions client -spkac public.spkac -out signed.pem -batch
openssl pkcs12 -nodes -export -inkey private.pem -in signed.pem -out cert.p12
# No certificate matches private key