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 / 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.
@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 / 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 / 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 / _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 %}
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 / runes.py
Created November 4, 2019 23:25
The runes
*
/
+
-
2 + 2
"""
To run as a standalone script, set your CONSUMER_KEY and CONSUMER_SECRET. To
call search from code, pass in your credentials to the search_twitter function.
Script to fetch a twitter search of tweets into a directory. Fetches all available
tweet history accessible by the application (7 days historical).
USAGE:
$ python search.py [--new|--nozip] query terms
@scott2b
scott2b / gist:8faf1f35dc8845be702d8f3a60827914
Created March 4, 2019 21:35
TimlineJS3 minimal React example
<!DOCTYPE html>
<html>
<head>
<script crossorigin src="https://unpkg.com/react@16.7.0/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16.7.0/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<link title="timeline-styles" rel="stylesheet" href="https://cdn.knightlab.com/libs/timeline3/latest/css/timeline.css">
<script src="https://cdn.knightlab.com/libs/timeline3/latest/js/timeline.js"></script>
<style>
div#timeline-embed {
time="2018-08-03T19:07:57Z" level=debug msg="Global configuration loaded {\"LifeCycle\":{\"RequestAcceptGraceTimeout\":0,\"GraceTimeOut\":10000000000},\"GraceTimeOut\":0,\"Debug\":false,\"CheckNewVersion\":true,\"SendAnonymousUsage\":false,\"AccessLogsFile\":\"\",\"AccessLog\":null,\"TraefikLogsFile\":\"\",\"TraefikLog\":null,\"Tracing\":null,\"LogLevel\":\"DEBUG\",\"EntryPoints\":{\"http\":{\"Address\":\":80\",\"TLS\":null,\"Redirect\":null,\"Auth\":null,\"WhitelistSourceRange\":null,\"WhiteList\":null,\"Compress\":false,\"ProxyProtocol\":null,\"ForwardedHeaders\":{\"Insecure\":true,\"TrustedIPs\":null}},\"traefik\":{\"Address\":\":8080\",\"TLS\":null,\"Redirect\":null,\"Auth\":null,\"WhitelistSourceRange\":null,\"WhiteList\":null,\"Compress\":false,\"ProxyProtocol\":null,\"ForwardedHeaders\":{\"Insecure\":true,\"TrustedIPs\":null}}},\"Cluster\":null,\"Constraints\":[],\"ACME\":null,\"DefaultEntryPoints\":[\"http\"],\"ProvidersThrottleDuration\":2000000000,\"MaxIdleConnsPerHost\":200,\"IdleTimeout\":0,\"Inse