Skip to content

Instantly share code, notes, and snippets.

View andybp85's full-sized avatar
🏠
Working from home

Andrew Stanish andybp85

🏠
Working from home
View GitHub Profile
@andybp85
andybp85 / simplelistenpost.py
Last active August 29, 2015 14:21
Simple Python HTTP POST Redirector
"""Simple Python HTTP POST Redirector - Redirects POST requests with data.
Author: Andrew Stanish, May 2015
Uncomment the two pprint lines to write the POST data to the console.
Change the address in this line to send wherever you like:
requests.post('http://10.8.0.10:8080', data=form.value, headers=headers )
"""
import cgi, requests, BaseHTTPServer
#import pprint as pp
@andybp85
andybp85 / manage.py
Last active May 18, 2016 22:29
Flask-Script with watch command - run tests on reload
#! /usr/bin/env python
from flask.ext.script import Manager
from flask.ext.script.commands import ShowUrls, Clean
from app import create_app, db
app = create_app("development")
manager = Manager(app)
@andybp85
andybp85 / authenticatedBlueprints.py
Last active June 4, 2016 08:09
subclasses of Flask Blueprint that utilize Flask Security to implement authorization on all routes.
from flask import Blueprint, request, make_response, current_app
from flask.ext.security.decorators import _check_token
from flask.ext.security import current_user
class TokenAuthBlueprint(Blueprint):
def __init__(self, *args, **kwargs):
Blueprint.__init__(self, *args, **kwargs)
Blueprint.before_request(self, self.checkToken)
@andybp85
andybp85 / AppSecurity.py
Last active June 30, 2019 15:48
subclass of flask-security to demonstrate adding routes to security blueprint. implements a '/check' route to check and refresh tokens.
from flask import request, current_app
from flask.json import jsonify
from flask.ext.security import Security, SQLAlchemyUserDatastore, current_user
from flask.ext.security.views import create_blueprint
from flask.ext.security.decorators import auth_token_required
from flask.ext.security.utils import url_for_security, md5
from flask.ext.login import make_secure_token
from werkzeug.local import LocalProxy
@andybp85
andybp85 / init.vim
Last active March 22, 2018 16:32
This is now in a repo: https://github.com/andybp85/nvim
" General {{{
" vim options {{{{
set nocompatible " be iMproved, required
set encoding=utf-8
set ffs=unix,dos,mac
set number
set relativenumber
set ruler
set tabstop=4
@andybp85
andybp85 / git-finish.sh
Last active June 27, 2016 13:07
zsh function to add all, commit, and push. Just enter the commit message after the command, no quotes or anything needed.
# example: > git-finish this is my commit message
git-finish () { git add -A && git commit -m "$*" && git push; }
# Usage:
# @progress(db.users.find().count())
# def users(cb):
# users = []
# for u in db.users.find():
# users.append( user(u) )
# cb()
# return users
from progressbar import ProgressBar, Percentage, Bar
@andybp85
andybp85 / conftest.py
Created July 27, 2016 16:48
pytest conftest for setup and rollback with postgres
import pytest
from app import create_app
from app.database import db as _db
# from tests.client import ApiTestingResponse
@pytest.yield_fixture(scope='session')
def app():
app = create_app('testing.py')
@andybp85
andybp85 / autocommit.py
Last active August 15, 2016 12:47
UNTESTED - Real autocommit mode for Postgres/Flask-SQLAlchemy
##################################################
# Real autocommit mode for psycopg2
# ie, does not auto-start a transacation.
# from http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
# UNTESTED
##################################################
class AUTOCOMMITAlchemy(SQLAlchemy):
def apply_driver_hacks(self, app, info, options):
if not "isolation_level" in options:
options["isolation_level"] = "AUTOCOMMIT" # For example
@andybp85
andybp85 / security_resources.txt
Created April 11, 2017 18:49
random security resources I use for running a Cpanel, AWS, Wordpress environment
http://cpanel.net/news/
http://krebsonsecurity.com/category/latest-warnings/
http://www.exploit-db.com/
https://web.nvd.nist.gov/view/vuln/search
http://www.cvedetails.com/
http://blog.sucuri.net/category/wordpress-security
http://www.pcworld.com/category/security/
http://www.gk-root.com/GK-Blog/secure-your-cpanel-server/
https://wpvulndb.com/