Skip to content

Instantly share code, notes, and snippets.

View markph0204's full-sized avatar

Mark Hurley markph0204

View GitHub Profile
@markph0204
markph0204 / application.py
Created November 1, 2016 23:10
Python hug API ran on AWS Elastic Beanstalk
from main import __hug_wsgi__ as application
# Create a new virtualenv using the last component of path name
# Activate immediately when created
function pyenv_easy_3() {
result=${PWD##*/}
printf 'Create virtualenv for named local path...'
printf '%s\n' $result
pyenv virtualenv 3.6.1 $result
printf 'Setting local to new virtualenv...\n'
pyenv local $result
@markph0204
markph0204 / gist:da62dfe78cfae01077192b61392f0431
Created May 11, 2017 22:49
Remove development paths from Spotlight
touch ~/Library/Caches/.metadata_never_index
touch ~/Library/Developer/.metadata_never_index
killall Finder
import requests
from time import sleep
import os
import asyncio
import aiohttp
async def submit_and_wait():
print('Submitting request')
request_url = '<base url>/create_request'
@markph0204
markph0204 / aws-bash-aliases
Created November 20, 2017 18:12
AWS profile management
# create new profile, prior step
# aws configure --profile=name123
# use profile with tools
alias aws_name123='export AWS_PROFILE=name123'
@markph0204
markph0204 / app_list_routes.py
Created December 14, 2017 11:27
Flask list routes
from collections import defaultdict
@app.cli.command("list_routes")
def list_routes():
"""
Roll through Flask's URL rules and print them out
Thank you to Jonathan Tushman
And Thank you to Roger Pence
Sourced http://flask.pocoo.org/snippets/117/ "Helper to list routes (like Rail's rake routes)"
@markph0204
markph0204 / app_handle_errors.py
Last active December 14, 2017 11:31
Handling invalid requests with Flask - Implementing API Exceptions
# http://flask.pocoo.org/docs/0.12/patterns/apierrors/
from flask import jsonify
class InvalidUsage(Exception):
status_code = 400
def __init__(self, message, status_code=None, payload=None):
Exception.__init__(self)
@markph0204
markph0204 / jupyter-notebook-starter.py
Created December 20, 2017 17:31
I normally use notebooks in a `notebooks` sub path in my project repository and often need to import modules that are apart of that project.
import sys
sys.path.append("../") # go to parent dir
from customFunctions import *
# Then, to affect changes in customFunctions.py,
%load_ext autoreload
%autoreload 2
#ref: https://stackoverflow.com/a/42727538/23991
@markph0204
markph0204 / direnv+pycharm.sh
Created December 26, 2017 21:49
direnv with pycharm
# enable direnv for python
# this will enable the commandline support as well as support pycharm
# 1 install direnv (Homebrew / pip)
# 2 edit your .bashrc, .bash_profile or .bash_aliases
function venv-here {
# you could just use 'layout python' here for 2.7.x
echo "layout python3" > .envrc
echo "ln -s .direnv/\$(basename \$VIRTUAL_ENV)/ .env" >> .envrc
}
@markph0204
markph0204 / pytest_monkey_open.py
Created June 14, 2018 23:16
Pytest monkey patching builtins open
import builtins
import pytest
from io import StringIO
import yaml
TEST_CONFIG = """
environment: prod
"""