Skip to content

Instantly share code, notes, and snippets.

View hatdropper1977's full-sized avatar

John Sobanski hatdropper1977

View GitHub Profile
@hatdropper1977
hatdropper1977 / policy.json
Created April 29, 2017 01:18
This Policy includes logging.
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
@hatdropper1977
hatdropper1977 / policy.json
Created April 29, 2017 01:08
This allows the Lambda function to use ES.
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"es:ESHttpDelete",
"es:ESHttpGet",
"es:ESHttpHead",
"es:ESHttpPost",
"es:ESHttpPut"
@hatdropper1977
hatdropper1977 / app.py
Created April 29, 2017 00:53
A connection test for Lambda functions to connect to an AWS Elasticsearch service
from chalice import Chalice
from boto.connection import AWSAuthConnection
class ESConnection(AWSAuthConnection):
def __init__(self, region, **kwargs):
super(ESConnection, self).__init__(**kwargs)
self._set_auth_region_name(region)
self._set_auth_service_name('es')
@hatdropper1977
hatdropper1977 / fancy_forms.templates.take_quiz_template.html
Created January 9, 2017 02:29
For the "fancy forms" HOWTO on Freshlex.com Raw
<script src="https://gist.github.com/hatdropper1977/a8d9cddb02b0eb6bc074.js"></script>
{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block content %}
<div class="container">
<h3>Please answer this very important essay</h3>
<p>If you don't it'll go on your permanent record!.</p>
<hr>
{{ wtf.quick_form(form) }}
<hr>
@hatdropper1977
hatdropper1977 / fancy_forms.application.py
Created January 9, 2017 02:27
For the "fancy forms" HOWTO on Freshlex.com
#!bin/python
from flask import Flask, render_template, request
from flask_bootstrap import Bootstrap
from models import QuizForm
class Config(object):
SECRET_KEY = '78w0o5tuuGex5Ktk8VvVDF9Pw3jv1MVE'
application = Flask(__name__)
application.config.from_object(Config)
@hatdropper1977
hatdropper1977 / fancy_forms.models.py
Created January 9, 2017 02:26
For the "fancy forms" HOWTO on Freshlex
from flask_wtf import Form
from wtforms import TextField, SubmitField, TextAreaField
from wtforms.validators import Length, Email, Required
# Form ORM
class QuizForm(Form):
essay_question = TextAreaField('Who do you think won the console wars of 1991, Sega Genesis or Super Nintendo? (2048 characters)', validators=[Required(),Length(max=2047)] )
email_addr = TextField('Enter Your Email', validators=[Required(), Email()])
submit = SubmitField('Submit')
from xml.dom import minidom
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
import xml.etree.ElementTree as ET
class Edge(Element):
def __init__(self):
# Create the schema
Element.__init__(self,'edge')
self.append(Element('name'))
self.append(Element('datacenterMoid'))
# application.py
from boto.connection import AWSAuthConnection
from flask import Flask, render_template, request, redirect, url_for, flash
from models import Quiz, QuizForm
from datetime import datetime
from config import DevConfig
import json
from flask_bootstrap import Bootstrap
### BEGIN CELERY
@hatdropper1977
hatdropper1977 / tasks.py
Last active June 9, 2016 09:50
A Celery worker node for HOWTO 5
# tasks.py
from boto.connection import AWSAuthConnection
import requests
from celery import Celery
# Be sure to add your SQS URL below!
application = Celery('tasks',broker='sqs://sqs.us-east-1.amazonaws.com/<your arn>/flask-es')
class ESConnection(AWSAuthConnection):
@hatdropper1977
hatdropper1977 / geo_check.py
Created June 9, 2016 09:37
Uses boto to query an ES document store for files with a "Geo" tag
# geo_check.py
from boto.connection import AWSAuthConnection
class ESConnection(AWSAuthConnection):
def __init__(self, region, **kwargs):
super(ESConnection, self).__init__(**kwargs)
self._set_auth_region_name(region)
self._set_auth_service_name("es")