Skip to content

Instantly share code, notes, and snippets.

View michaelconnor00's full-sized avatar

Mike Connor michaelconnor00

View GitHub Profile
@michaelconnor00
michaelconnor00 / aws_eb_django_commands.md
Last active August 9, 2020 05:46
Run Django Commands from AWS Elastic Beanstalk Virtual Environment

How to run manage.py from AWS Elastic Beanstalk

Note this is for eb python platform, it is different for Docker

Location of Current App:

  cd /opt/python/current/app
@michaelconnor00
michaelconnor00 / kill_runserver.py
Last active December 12, 2015 00:05
Django command to kill runserver. Handy when using Djanog in a docker container and using runserver externally.
import os
import shlex
import subprocess
from subprocess import PIPE, STDOUT
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Kill local processes running runserver command'
@michaelconnor00
michaelconnor00 / boto3_s3_func.py
Created December 22, 2015 23:35
Boto3 S3 upload and Download
# If bucket is private
AWS_ACCESS_KEY = 'your access key'
AWS_SECRET_KEY = 'your secret key'
AWS_REGION = 'your region'
session = boto3.session.Session(
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY,
region_name=AWS_REGION
)
@michaelconnor00
michaelconnor00 / tar_info.sh
Last active December 23, 2015 22:30
Tar Files
# Compress with gzip
tar -zcvf myTar.tar.gz *.files
# Uncompress with gzip, http://www.cyberciti.biz/faq/tar-extract-linux/
tar -xzvf myTar.tar.gz
@michaelconnor00
michaelconnor00 / sql_joins.md
Created December 23, 2015 23:04
SQL Joins

Cheat Sheet

@michaelconnor00
michaelconnor00 / file_discovery.py
Last active March 24, 2016 22:26
File Handling
# http://stackoverflow.com/questions/3964681/find-all-files-in-directory-with-extension-txt-in-python
# Using glob
import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
print(file)
# Using listdir
import os
for file in os.listdir("/mydir"):
@michaelconnor00
michaelconnor00 / odict.py
Created February 25, 2016 23:49
YAML Orderdict representer
"""
FROM: http://blog.elsdoerfer.name/2012/07/26/make-pyyaml-output-an-ordereddict/
Make PyYAML output an OrderedDict.
It will do so fine if you use yaml.dump(), but that generates ugly,
non-standard YAML code.
To use yaml.safe_dump(), you need the following.
"""
def represent_odict(dump, tag, mapping, flow_style=None):
"""Like BaseRepresenter.represent_mapping, but does not issue the sort().
from contextlib import contextmanager
@contextmanager
def tag(name):
print("<%s>" % name)
yield
print("</%s>" % name)
>>> with tag("h1"):
... print("foo")
>>> a, b, c = 1, 2, 3
>>> a, b, c
(1, 2, 3)
>>> a, b, c = [1, 2, 3]
>>> a, b, c
(1, 2, 3)
>>> a, b, c = (2 * i + 1 for i in range(3))
>>> a, b, c
(1, 3, 5)
>>> a, (b, c), d = [1, (2, 3), 4]
@michaelconnor00
michaelconnor00 / reqs.py
Created April 7, 2016 23:21
A snippet for reading install_requires from requirements.txt
req_exclusions = ['setuptools', 'pytest']
def get_requirements():
reqs = []
with open('requirements.txt', 'r') as f:
for line in f:
add = True
for req in req_exclusions:
if req in line: