Skip to content

Instantly share code, notes, and snippets.

View deontologician's full-sized avatar
🦀
🌎

Josh Kuhn deontologician

🦀
🌎
View GitHub Profile
class Tracker(Base):
__tablename__ = 'tracker'
id = Column(Integer, primary_key=True)
state = Column(String, nullable=False)
def __repr__(self):
return 'Tracker<{.id}>'.format(self)
@deontologician
deontologician / gist:7918366
Created December 11, 2013 20:59
webapp snippets
from tornado import web
from tornado import ioloop
from sqlalchemy.engine
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import os
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.associationproxy import association_proxy
Base = declarative_base()
class Machine(Base):
__tablename__ = 'machines'
__table_args__ = {'sqlite_autoincrement': True}
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import *
Base = declarative_base()
class Access(Base):
__tablename__ = 'accesses'
access_id = Column(Integer, primary_key=True)
@deontologician
deontologician / fetch_iana_link_relations.py
Created May 24, 2013 22:46
Grabs currently registered link relations from iana.org
@deontologician
deontologician / test_parse_link_headers.py
Created December 2, 2012 23:42
E2E test for link header parsing in requests
@deontologician
deontologician / PKGBUILD
Created September 7, 2012 18:55
PKGBUILD for openconnect-git
# Contributor: dschauer, Dwight Schauer <[email protected]>
pkgname=openconnect-git
pkgver=20120907
pkgrel=1
pkgdesc="VPN client (intended to be) compatible with Cisco AnyConnect"
arch=(i686 x86_64)
url="http://git.infradead.org/users/dwmw2/openconnect.git"
license=('LGPL')
groups=()
depends=()
@deontologician
deontologician / reltime.py
Created August 28, 2012 20:34
Relative datetimes in python
def reltime(date, compare_to=None, at='@'):
r'''Takes a datetime and returns a relative representation of the
time.
:param date: The date to render relatively
:param compare_to: what to compare the date to. Defaults to datetime.now()
:param at: date/time separator. defaults to "@". "at" is also reasonable.
>>> from datetime import datetime, timedelta
>>> today = datetime(2050, 9, 2, 15, 00)
>>> earlier = datetime(2050, 9, 2, 12)
def dispatch_hook(key, hooks, hook_data):
"""Dispatches a hook dictionary on a given piece of data."""
hooks = hooks or dict()
if key in hooks:
hooks = hooks.get(key)
if hasattr(hooks, '__call__'):
hooks = [hooks]
@deontologician
deontologician / tagify.py
Created July 3, 2012 14:05
Python function to create hash tags from various inputs.
import re
import string as s
def tagify(*args, **kwargs):
r'''Turns the argument strings into tags. so 'my tag' becomes '#MyTag'
Any keyword arguments become tags with values.
>>> tagify('hi there')
['#HiThere']