Skip to content

Instantly share code, notes, and snippets.

View mikefromit's full-sized avatar

Mike from the IT department mikefromit

View GitHub Profile
@mikefromit
mikefromit / one_flask.py
Last active May 5, 2021 10:37
a one file flask app for trying stuff
# THIS PROJECT IS AN EXAMPLE APP. SOME CODE MAY NOT BE ACTUALLY USEFUL
# FOR DEMONSTRATION PURPOSES ONLY
# YOUR MILEAGE MAY VARY
# Requirements are Flask, Flask-WTF, Flask-SQLAlchemy
import os
from flask import (Flask,
Blueprint,
redirect,
@mikefromit
mikefromit / jinja2_markdown_filter.md
Last active August 29, 2021 11:21
Markdown filter for jinja2

markdown.py

@environmentfilter
def markdown(env, value):
    """
    Markdown filter with support for extensions.
    """
    try:
        import markdown as md
[defaults]
hash_behaviour=merge
roles_path=../common/roles:./roles
host_key_checking=False
pipelining=True
@mikefromit
mikefromit / sqlalchemy_example.py
Created September 12, 2016 20:03
A quick script using sqlalchemy for query development
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import sessionmaker
def create_sa_connection(connection_string):
""" A nice helper function for creating the session and engine required
for sqlalchemy interactions with the database.
:param connection:
:return:
@mikefromit
mikefromit / glog.md
Last active September 5, 2016 23:09
Google style logging

logging.py

def setup_logging():
    """Setup Google-style logging

    From: https://github.com/twitter/commons/blob/master/src/python/twitter/common/log/formatters/glog.py
    """
    fmt = '%(levelletter)s%(asctime)s.%(msecs).03d %(process)d %(filename)s:%(lineno)d] %(message)s'
@mikefromit
mikefromit / install_virtualenvwrapper.md
Last active June 28, 2016 15:50
A simple ansible example to install virtualenvwrapper and config

config_virtualenvwrapper.yml

---
- name: virtualenv setup
  hosts: localhost
  vars:
    venv_dir: ~/.environments

  tasks: