Skip to content

Instantly share code, notes, and snippets.

View mmerickel's full-sized avatar

Michael Merickel mmerickel

View GitHub Profile
@mmerickel
mmerickel / keybase.md
Created May 23, 2014 16:14
keybase.md

Keybase proof

I hereby claim:

  • I am mmerickel on github.
  • I am mmerickel (https://keybase.io/mmerickel) on keybase.
  • I have a public key whose fingerprint is CC1A 48C9 57AC 6ABE F05B 2C59 6BC9 77B0 56B8 29E5

To claim this, I am signing this object:

@mmerickel
mmerickel / pyramid_services.py
Last active August 29, 2015 14:04
pyramid services
from pyramid.interfaces import IRequest
from zope.interface.registry import Components
def includeme(config):
config.add_request_method(find_service)
config.add_request_method(lambda _: Components(), 'service_cache',
reify=True)
config.add_directive('register_service', register_service)
config.add_directive('register_service_factory', register_service_factory)
@mmerickel
mmerickel / gist:926c8437b5224b281376
Created February 5, 2015 22:18
pyramid view lookup patch
diff --git a/pyramid/router.py b/pyramid/router.py
index ba4f85b..a11e556 100644
--- a/pyramid/router.py
+++ b/pyramid/router.py
@@ -1,10 +1,12 @@
from zope.interface import (
implementer,
providedBy,
+ Interface,
)
@mmerickel
mmerickel / env.py
Last active August 29, 2015 14:20
parsing settings from a pastedeploy-style ini file
import logging.config
import os.path
from alembic import context
from sqlalchemy import create_engine, pool
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
@mmerickel
mmerickel / models:__init__.py
Last active August 29, 2015 14:22
model with separate modules
from .meta import DBSession
from .users import User
from .entries import Entry
@mmerickel
mmerickel / App.js
Last active August 29, 2015 14:23
redux bindActions decorator
import React from 'react';
import {connect} from 'redux/react';
import {bindActions} from './utils/bindActions';
import * as Actions from './actions';
@connect(state => ({
activePage: state.activePage,
}))
@bindActions({
def commit_veto(environ, status, headers):
for good in ('1', '2', '3'):
if status.startswith(good):
break
else:
return True
for header_name, header_value in headers:
if header_name.lower() == 'x-tm-abort':
return True
@mmerickel
mmerickel / root.py
Created January 27, 2011 00:20 — forked from wwitzel3/root.py
class DayZeroContainer(ModelContainer):
def __init__(self, request, cls):
self.cls = cls
self.request = request
@property
def __acl__(self):
return [
(Allow, 'owner:{0}'.format(cls.ownerid), ('add', 'edit)),
# ... some other acls for this particular resource?
@mmerickel
mmerickel / gist:805439
Created February 1, 2011 05:00
How to setup sqlalchemy without scoped_sessions or circular imports.
# tutorial/__init__.py
from pyramid.config import Configurator
from tutorial.model.meta import init_model
from tutorial.request import TutorialRequest
def main(global_config, **settings):
init_model(settings)
@mmerickel
mmerickel / resources.py
Created February 9, 2011 23:21
Adapted example from rocky on #pylons for wrapping SQLA objects into a resource tree for pyramid's traversal algorithm.
from pyramid.decorator import reify
from pyramid_traversalwrapper import LocationProxy
class traversable_attrs(object):
""" A decorator that adds a "wrap" attribute to the given class
in the form of a dict-like class that does item lookup based on
the attrs given.
"""