Skip to content

Instantly share code, notes, and snippets.

View digitalresistor's full-sized avatar
🔒
ALL THE THINGS!

Delta Regeer digitalresistor

🔒
ALL THE THINGS!
  • ::1
View GitHub Profile
from alembic import context
from pyramid.paster import setup_logging
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
# Interpret the config file for Python logging.
# This line sets up loggers basically.
@mmerickel
mmerickel / notfound.py
Created December 1, 2015 04:03
serving cache busted assets without renaming files on disk
_static_regex = re.compile(
r'''
(?P<root>/static/[a-zA-Z0-9._/-]+)
-
(?P<buster>[a-fA-F0-9]+)
(?P<ext>\.[a-zA-Z0-9]+)
$''',
re.VERBOSE,
)
@mmerickel
mmerickel / __init__.py
Last active November 22, 2018 03:08
decorate a bunch of items in a package and expose them as a public api
def _build_facade():
import sys
from .meta.api import scan
this = sys.modules[__name__]
registry = {}
scan(this, registry=registry)
globals().update(registry)
_build_facade()
del _build_facade
@mmerickel
mmerickel / static.py
Last active July 11, 2016 07:48
static asset detection
class StaticFactory(object):
def __init__(self, request):
request.is_static_asset = True
config.add_static_view('static', static_pkg, factory=StaticFactory)
config.add_request_method(lambda r: False, 'is_static_asset', reify=True)
_default_vary = set([
'Cookie',
'Accept',
from sqlalchemy import engine
from sqlalchemy import event
class DbStats():
def __init__(self):
self.clear()
def clear(self):
self.total_queries = 0
self.total_time = 0
class NoRequestParamsPredicate(object):
def __init__(self, val, config):
self.val = bool(val)
def text(self):
return 'no_request_params = %s' % self.val
phash = text
def __call__(self, context, request):
class ExactRequestParamPredicate(object):
def __init__(self, val, config):
val = _as_sorted_tuple(val)
reqs = []
for p in val:
k = p
v = None
if '=' in p:
k, v = p.split('=', 1)
k, v = k.strip(), v.strip()
@btm
btm / ec2_fetchkey
Created May 30, 2013 22:46
FreeBSD + Openstack Notes
#!/bin/sh
# PROVIDE: ec2_fetchkey
# REQUIRE: NETWORKING
# BEFORE: LOGIN ec2_firstboot
# Define ec2_fetchkey_enable=YES in /etc/rc.conf and create /root/firstboot
# to enable SSH key fetching when the system next boots.
#
: ${ec2_fetchkey_enable=NO}
@digitalresistor
digitalresistor / .bash_profile
Created February 10, 2012 22:58
shortcut for lsof
# Add this to your .bash_profile
function lsockets {
lsof -a -c $1 -i -l -P
}
# example:
#
# lsockets steward
#
@digitalresistor
digitalresistor / update-branches.sh
Created March 20, 2011 08:18
Procedure to take a library that contains files for multiple programming languages, and split off the language specific features into separate branches
cat << EOF > /dev/null
These procedures are helpful if you have a structure like this in your source tree and it can be anything like
Google protobuf, grammar syntax, shared source code of some sort that gets transformed to Python and C++, or
really anything that has a common base from which it is derived but when included (subtree'd/submoduled in git)
we only need the language specific part, not the rest.
What we do is create completely new branches in which we place a copy from the proper subdirectory from the
master branch. Yes that technically means we are duplicating files/commits in two different locations, but it
is a better option that having your Python specific source tree carrying around C++ files it does not need.