Skip to content

Instantly share code, notes, and snippets.

@vulcan25
vulcan25 / cprofile.py
Created November 6, 2021 21:02 — forked from rfong/cprofile.py
Django profiling decorator
import cProfile
import pstats
from django.utils.functional import wraps
def cprofile(sort_by='cumulative', n=20):
"""Decorator to profile a function."""
def decorator(func):
@wraps(func)
@vulcan25
vulcan25 / flask_profiler.py
Created October 28, 2021 16:51 — forked from shreyansb/flask_profiler.py
A profiler for Flask apps
"""
This module provides a simple WSGI profiler middleware for finding
bottlenecks in web application. It uses the profile or cProfile
module to do the profiling and writes the stats to the stream provided
To use, run `flask_profiler.py` instead of `app.py`
see: http://werkzeug.pocoo.org/docs/0.9/contrib/profiler/
and: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling
"""
@vulcan25
vulcan25 / README.md
Last active February 29, 2024 13:26
Create ZIP file in memory from PIL images and serve with Flask

First do pip install flask Pillow in your venv :)

@vulcan25
vulcan25 / main.py
Created July 17, 2020 23:24 — forked from stewartadam/main.py
Simple Python proxy server based on Flask and Requests with support for GET and POST requests.
"""
A simple proxy server, based on original by gear11:
https://gist.github.com/gear11/8006132
Modified from original to support both GET and POST, status code passthrough, header and form data passthrough.
Usage: http://hostname:port/p/(URL to be proxied, minus protocol)
For example: http://localhost:5000/p/www.google.com
"""
import re
@vulcan25
vulcan25 / app.py
Created March 18, 2020 19:31 — forked from seanbehan/app.py
Flask with Django ORM
'''
Run the following commands (bc. gists don't allow directories)
pip install flask django dj-database-url psycopg2
mkdir -p app/migrations
touch app/__init__.py app/migrations/__init__.py
mv models.py app/
python manage.py makemigrations
python manage.py migrate
@vulcan25
vulcan25 / tcpdump.md
Created January 22, 2020 20:21
tcpdump cheatsheet

TCPDUMP

OPTIONS

-i any : Listen on all interfaces just to see if you’re seeing any traffic. -i eth0 : Listen on the eth0 interface. -D : Show the list of available interfaces -n : Don’t resolve hostnames. -nn : Don’t resolve hostnames or port names. -q : Be less verbose (more quiet) with your output.

@vulcan25
vulcan25 / app.py
Last active May 4, 2020 09:39 — forked from MortallaSane/app.py
Flask tiny project
from flask import Flask, render_template
# Because gists don't support subfolders, we pass the `template_folder` argument
# to `Flask` to set it as the current directory. If you wish you can create a
# subfolder called `templates/` in the project, moving the HTML files there, then
# remove that argument from the next line.
app = Flask(__name__, template_folder='.')
@app.route("/")
def index():
@vulcan25
vulcan25 / README.md
Last active November 29, 2022 14:11
Flask + sqlalchemy declarative base example

TODO: write readme

@vulcan25
vulcan25 / app.py
Last active December 27, 2019 15:17
Flask: Example of periodically refreshing a page, pending rq job completion.
from flask import Flask, redirect, url_for, render_template_string
from time import sleep
from rq import Queue
from rq.job import Job
from redis import Redis
r = Redis(host='redisserver')
q = Queue(connection=r)
@vulcan25
vulcan25 / run.py
Last active January 11, 2023 13:52
psycopg2 flask implementation with connection pooling support
from flask import Flask, g, jsonify
import werkzeug, os
from werkzeug.utils import secure_filename
import psycopg2
from psycopg2 import pool
def get_db():
print ('GETTING CONN')
if 'db' not in g: