Skip to content

Instantly share code, notes, and snippets.

@dirkakrid
dirkakrid / README.md
Created June 23, 2018 12:46 — forked from rduplain/README.md
Flask-Script: demo passing in configuration file.

This demonstrates that you can configure a Flask application through Flask-Script, without having to create a Flask instance or deal with circular dependencies. Note that Flask-Script's Manager accepts a factory function in place of a Flask app object.

Running:

python manage.py runserver

gives "Hello, world!" on http://localhost:5000/, while running:

python manage.py runserver -c development.cfg
@dirkakrid
dirkakrid / README.md
Created June 23, 2018 12:37 — forked from rduplain/README.md
Demo of the Python `code` module, for interaction and DSLs.

import code

This is a demonstration of the Python [code][1] module, which allows for an interactive interpreter to be embedded into a Python program.

code.interact(banner=None, readfunc=None, local=None)

Convenience function to run a read-eval-print loop. This creates a new instance of [InteractiveConsole][2] and sets readfunc to be used as the

<html>
<head>
<title>Responsive Images</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<img src="example.png"/>
<img src="example2.png"/>
<img src="example3.png"/>
@dirkakrid
dirkakrid / gist:58c85a819bace31489437da049a84022
Created September 16, 2017 05:45
Remove Atom editor OSX
rm -rf ~/.atom
rm /usr/local/bin/atom
rm /usr/local/bin/apm
rm -rf ~/Library/Preferences/com.github.atom*
rm -rf ~/Library/Application\ Support/com.github.atom*
rm -rf ~/Library/Application\ Support/Atom/
@dirkakrid
dirkakrid / html_logger.py
Created September 4, 2017 23:54 — forked from ColinDuquesnoy/html_logger.py
HTML logger for python (inspired by the Horde3D logger)
"""
HTML logger inspired by the Horde3D logger.
Usage:
- call setup and specify the filename, title, version and level
- call dbg, info, warn or err to log messages.
"""
import logging
import time
@dirkakrid
dirkakrid / connect
Created June 19, 2017 00:26 — forked from Dalrik/connect
#!/bin/bash
############################
# SSH Connection Script v3.0
# Jeff Heidel 2012
# Ian Thompson 2014
############################
##
@dirkakrid
dirkakrid / postfix-to-json.py
Created June 13, 2017 09:58
Postfix log parser to json, just queue-id, message-id and status with remote server response.
#!/usr/bin/env python
'''
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://www.wtfpl.net/ for more details.
'''
import re
# Email SQLite Backup Hack
# 2015
# Lewis Cowles
# Nasty Python 2.7 Compatible E-Mail Backup (Once done)
import imaplib, email, sqlite3
from email.utils import *
from datetime import datetime
# Setup DB
@dirkakrid
dirkakrid / app.py
Created May 14, 2017 17:46 — forked from Lewiscowles1986/app.py
Python Flask REST server (Works for me on 2.7 & 3.4. 2.7 used to run tests)
from flask import Flask
from flask import g, abort, redirect, Response, request
import json
import sqlite3
import datetime
app = Flask(__name__)
@app.before_request
@dirkakrid
dirkakrid / ckedit.py
Created April 24, 2017 09:30 — forked from mrjoes/ckedit.py
Flask-Admin and CKEditor WYSIWYG textarea integration. Basically, all you have to do: 1. Create new wtforms widget which will emit 'ckeditor' class 2. Make new wtforms field which will use this widget 3. Create new jinja2 template, which includes ckeditor javascript 4. Tell flask-admin to use new field and new template
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext import admin, wtf
from flask.ext.admin.contrib import sqlamodel
app = Flask(__name__)
app.config['SECRET_KEY'] = '123456790'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite'
db = SQLAlchemy(app)