Skip to content

Instantly share code, notes, and snippets.

@patjenk
patjenk / better_dir.py
Created September 22, 2019 17:04
a slightly better dir function
def bdir(obj):
import types
type_name = type(obj)
dir_output = dir(obj)
methods = []
properties = []
for dir_entry in dir_output:
if dir_entry in types.__builtins__.keys():
pass
elif hasattr(obj, dir_entry) and type(getattr(obj, dir_entry)) == types.MethodType:
@patjenk
patjenk / django-on-heroku.md
Last active March 7, 2020 16:58
Steps for deploying a Django application on Heroku

Steps to deploy a Django app to heroku

  1. make sure your requirements.txt file is in the top directory.
  2. create a Procfile in the top directory
    • contents: "web: gunicorn --pythonpath .wsgi --log-file -"
    • install gunicorn
  3. create runtime.txt in the top directory
    • contents: "python-3.6.10"
  4. modify your settings.py
  • install whitenoise
@patjenk
patjenk / jinja2_file_less.py
Created September 15, 2016 20:59 — forked from wrunk/jinja2_file_less.py
python jinja2 examples
#!/usr/bin/env/python
#
# More of a reference of using jinaj2 without actual template files.
# This is great for a simple output transformation to standard out.
#
# Of course you will need to "sudo pip install jinja2" first!
#
# I like to refer to the following to remember how to use jinja2 :)
# http://jinja.pocoo.org/docs/templates/
#
@patjenk
patjenk / rabbitmq_firehose.py
Last active November 17, 2016 22:33 — forked from khomenko/rabbitmq_firehose.py
simple rabbitmq debug firehose consumer
"""
# Usage
1. Turn on the rabbitmq firehose: `sudo rabbitmqctl trace_on`
2. install pika: `pip install pika`
3. run this script: `python rabbitmq_firehose.py`
4. examine output
5. stop this script: ctrl-c
6. Turn off the rabbitmq firehose: `sudo rabbitmqctl trace_off`
# Helpful notes:
#!/usr/bin/env python
"""
A script to query the Amazon Web Services usage reports programmatically.
Ideally this wouldn't exist, and Amazon would provide an API we can use
instead, but hey - that's life.
Basically takes your AWS account username and password, logs into the
website as you, and grabs the data out. Always gets the 'All Usage Types'