Skip to content

Instantly share code, notes, and snippets.

View scott2b's full-sized avatar

Scott Bradley scott2b

  • Northwestern University
  • Evanston
View GitHub Profile
@scott2b
scott2b / runes.py
Created November 4, 2019 23:25
The runes
*
/
+
-
2 + 2
import os
import re
class ConfigurationError(Exception): pass
def replacer(m):
var = m.group(2)[2:-1].strip()
try:
return f'{m.group(1)}{os.environ[var]}{m.group(3)}'
@scott2b
scott2b / _messages.html
Last active November 9, 2020 16:25
Request template context with messages for Starlette+Jinja2
{% if request.session.messages %}
<ul>
{% for message in request.session.messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{{ request.clear_messages() }}
{% endif %}
@scott2b
scott2b / cachedecorator.py
Created February 14, 2022 23:07 — forked from mminer/cachedecorator.py
An example of a Python decorator to simplify caching a function's result.
"""An example of a cache decorator."""
import json
from functools import wraps
from redis import StrictRedis
redis = StrictRedis()
def cached(func):
@scott2b
scott2b / test-sqlite-bigints.py
Last active November 2, 2022 17:41
attempting to isolate an issue with sqlite and large integer values in piccolo
"""
Original code by @dantownsend
Minor tweets by @scott2b
See: https://github.com/piccolo-orm/piccolo/issues/662
"""
from piccolo.table import Table
from piccolo.columns.column_types import Integer, JSON
from piccolo.engine.sqlite import SQLiteEngine
@scott2b
scott2b / mlflowproxy.py
Last active November 30, 2022 16:32
A simple authentication proxy for mlauth implemented in Starlette
"""
****
CAUTION: This is the wrong approach and will not work for all requests!
Instead of parsing out the json data, the content body should just simply be passed
through to mlflow. I will get a fix in soon.
****
A simple proxy to put an authentication layer in front of mlflow.
@scott2b
scott2b / simpletemplate.py
Last active December 1, 2022 14:43
A simple templating engine that handles nested context
import re
from functools import partial
L_BR = "__LBR__"
R_BR = "__RBR__"
class SimpleTemplate:
"""A super simple templating engine that will handle arbitrarily nested context.
Templated properties are marked by `{ ... }`. Attributes of the context are dot-delimited.