Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Merickel mmerickel

View GitHub Profile
@mmerickel
mmerickel / pyramid_resources.py
Created Jun 28, 2020
Support annotating resource objects with a URL and using them for view lookup.
View pyramid_resources.py
from pyramid.interfaces import IResourceURL
from pyramid.traversal import traversal_path
import venusian
from zope.interface import implementedBy, providedBy
from zope.interface.interfaces import IInterface
class resource_config(object):
"""
A class decorator for defining resources.
View tunnel.sh
#!/usr/bin/env bash
set -eEo pipefail
SSH_TRACE=
[[ "$TRACE" = "1" ]] && set -x && SSH_TRACE="-vvv"
SSH_TARGET=merickel.org
CONTROL_PATH=$(pwd)/.ssh-${SSH_TARGET}
SOCKET_PATH=$(pwd)/docker.sock
@mmerickel
mmerickel / .env
Last active Feb 25, 2020
render an ini file based on env vars
View .env
##############################################################################
# Settings made available in site.ini.in.
#
# After making changes re-run render-config
#
# Override settings by making a .env.local file.
##############################################################################
DEBUG=yes
WEB_CONCURRENCY=10
@mmerickel
mmerickel / cli.py
Last active Nov 20, 2019
wrap a wired service layer into pyramid_services
View cli.py
from myapp.services import make_service_factory
from myapp.utils.tm import tm_context
class CLI:
@reify
def service_factory(self):
return make_service_factory(self.settings)
View main.py
from .tm_context import tm_context
with tm_context(request.tm):
...
@mmerickel
mmerickel / readme.md
Created Sep 1, 2019 — forked from frostbtn/readme.md
rocket.chat web-hook to post messages silently
View readme.md

This is a Rocket.Chat incoming web hook. Hook gets an array of "messages" and silently creates chat messages directly in the Rocket's database without disturbing users with notifications or alerts - messages just appear in the channels. Messages appear silently even if the user has the channel openned: no refresh or re-enter is required (this is not this script's feature, it's how Rocket works).

This script can post messages to channels and groups by name (if message destination set to #name), or by api roomId (no prefixes in destination). And it can post DM to a user (if destination is set to @username). Please note, in this case DM between message author and destination user must already be created.

This hook expects request.content: ISilentMessage[];

ISilentMessage {
  // Message body.
  text: string;
@mmerickel
mmerickel / commands.py
Last active Aug 23, 2019
subparse base cli
View commands.py
from subparse import command
@command('.shell')
def shell(parser):
""" Launch a python interpreter."""
@command('.run')
def run(parser):
""" Run a script.
View wsgi.py
import plaster
import sys
def main():
if '--reload' in sys.argv:
import hupper
reloader = hupper.start_reloader(__name__ + '.main')
reloader.watch_files(['site.ini'])
loader = plaster.get_loader('site.ini', protocols=['wsgi'])
View alembic_env.py
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.
View access_token.py
from pyramid.decorator import reify
from .principals import Principals as P
class AccessToken:
def __init__(self, type, user=None, claims=None):
self.type = type
self.user = user
self.claims = claims or []
You can’t perform that action at this time.