Skip to content

Instantly share code, notes, and snippets.

View christabor's full-sized avatar
😅
I may be slow to respond.

Chris Tabor christabor

😅
I may be slow to respond.
View GitHub Profile
@christabor
christabor / Notes.md
Last active October 15, 2016 03:42
plugin system with flask

Concept

Plugins should be easy to add, decoupled, and configurable, using a standard spec, as defined by the software creator.

In this case, we keep plugins in any directory on the host, using an environment variable. This could point to say, ~/.myapp/plugins for example. And within that, each plugin has a folder, with a config.json file (or whatever, really, this is just an example) that houses the config. If the config is not there, then it won't load.

@christabor
christabor / dict2nt.py
Last active September 7, 2016 17:38
dict 2 namedtuple
from collections import namedtuple
"""We have this:"""
Mynt = namedtuple('Mynt', 'foo bar baz')
mynt = Mynt(foo=1, bar=2, baz=3)
print(mynt.foo)
"""And this is handy too:"""
@christabor
christabor / apps_composition.py
Last active August 30, 2016 05:19
Application composition ideas in python
"""Compose apps in an intuitive way."""
class App(object):
def __init__(self, apps=None):
self.apps = apps or dict()
def __setitem__(self, appname, app):
self.apps[appname] = app
@christabor
christabor / venv.pp
Last active June 27, 2016 16:46
proper virtualenv in puppet
# Activate the virtualenv and install reqs at the same time.
# It's important these are run in the same line and Exec statement
# otherwise Puppet will exit the subshell for the next command,
# thus negating our use of virtualenv.
# Note the use of `;` instead of `&&`. This ensures the command is run serially.
exec {'activate_venv':
command => ". ${venv_bin}/activate; pip install -r ${reqs_file}",
cwd => $basedir,
provider => 'shell',
require => [
@christabor
christabor / fallbacks-dict.py
Created June 6, 2016 20:14
interesting python dict fallback syntax
# .get.get.get etc...
x = somedict.get('foo', {'foo': {'bar': []}}).get('bar', {})
@christabor
christabor / namehooks.py
Created June 1, 2016 05:40
Metaclass hookery
class Meta(type):
"""Thangz."""
def __new__(mcl, name, bases, cdict):
ret = type.__new__(mcl, name, bases, cdict)
setattr(ret, 'is_testsuite', name.endswith('TestCase'))
setattr(ret, 'is_boring', name.startswith('SomeClass'))
return ret
@christabor
christabor / hofgen.py
Last active September 2, 2016 23:18
Higher order functions and generators
"""Customizable (partially applied) HOF (closures) that return generators."""
from functools import partial
def filter_endswith(suffix):
def _f(things):
for thing in things:
if not thing.endswith(suffix):
yield thing
@christabor
christabor / reqs.txt
Created June 1, 2016 04:17
Youtube videos to mp3 for music!
youtube-dl
https://github.com/andyp123/mp4_to_mp3.git
license: MIT
@christabor
christabor / .block
Created May 12, 2016 06:55
Recursion
license: MIT