Skip to content

Instantly share code, notes, and snippets.

View MattHealy's full-sized avatar

Matt Healy MattHealy

View GitHub Profile
@MattHealy
MattHealy / tools.py
Last active June 10, 2020 20:56
Sample Python code to upload a file to the local server, then upload to AWS S3 with a background task queue
# Adapted from https://github.com/doobeh/Flask-S3-Uploader
# Improved to store the data on the local server and process
# the upload via a celery task queue
from uuid import uuid4
import boto
import os.path
from flask import current_app as app
from werkzeug.utils import secure_filename
from .. import celery
@MattHealy
MattHealy / supervisord
Last active September 28, 2015 03:42
An Init script for supervisord running on AWS EC2 Linux AMI
#!/bin/bash
#
# supervisord This scripts turns supervisord on
#
# Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
# Jason Koppe <jkoppe@indeed.com> adjusted to read sysconfig,
# use supervisord tools to start/stop, conditionally wait
# for child processes to shutdown, and startup later
# Mikhail Mingalev <mingalevme@gmail.com> Merged
# redhat-init-jkoppe and redhat-sysconfig-jkoppe, and
@MattHealy
MattHealy / backup-s3.cgi
Created November 27, 2015 07:24
Simple Perl script to mirror a website to Amazon S3
#!/usr/bin/perl
($sec,$min,$hour,$mday,$mon,$year,$nothing,$nothing,$nothing)=localtime(time);
if ($mon<12) {
$mon++;
}
if ($pmon<12) {
$pmon++;
}
@MattHealy
MattHealy / mariadb_check_restart.sh
Last active April 26, 2016 09:14
Check if MySQL/MariaDB is down, and if so, restart it.
#!/bin/sh
PORT=3306
HP=:$PORT
echo 'Checking to see if MariaDB is up...'
if ( /usr/sbin/lsof -Pni $HP | grep "$PORT (LISTEN)" 2>&1 >/dev/null ); then
echo 'MariaDB is up';
else
echo 'MariaDB is down, restarting...';
/sbin/service mariadb restart
fi
@MattHealy
MattHealy / apache_check_restart.sh
Last active April 22, 2022 10:58
Check if Apache is running, and if not, restart it
#!/bin/sh
PORT=80
HP=:$PORT
echo 'Checking to see if Apache is up...'
if ( /usr/sbin/lsof -Pni $HP | grep "$PORT (LISTEN)" 2>&1 >/dev/null ); then
echo 'Apache is up';
else
echo 'Apache is down, restarting...';
/sbin/service httpd restart
logger -p mail.info apache_check_restart.sh restarting Apache
@MattHealy
MattHealy / virtual.conf
Created April 24, 2016 03:26
Nginx conf file - example for hosting flask app
server {
listen 80;
server_name my-app.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_connect_timeout 300s;
# Set some HTTP headers so that our app knows where the
# request really came from
proxy_set_header Host $host;
@MattHealy
MattHealy / siecje.py
Created May 2, 2016 07:16 — forked from doobeh/example.html
Checkbox WTForms Example (in Flask)
from flask import Flask, render_template
from flask.ext.wtf import Form, widgets, SelectMultipleField
SECRET_KEY = 'development'
app = Flask(__name__)
app.config.from_object(__name__)
class MultiCheckboxField(SelectMultipleField):
widget = widgets.ListWidget(prefix_label=False)
@MattHealy
MattHealy / install-redis.sh
Created May 11, 2016 11:50 — forked from four43/install-redis.sh
Install Redis
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://gist.githubusercontent.com/four43/e00d01ca084c5972f229/raw/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
@MattHealy
MattHealy / landing-page.html
Created May 29, 2016 07:29
Boilerplate for a basic landing page consisting of an image.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My awesome site!</title>
<style type="text/css">
html {
width:100%;
height:100%;
background:url(logo.png) center center no-repeat;
@MattHealy
MattHealy / AESCipher.py
Created May 29, 2016 13:06 — forked from swinton/AESCipher.py
Encrypt & Decrypt using PyCrypto AES 256 From http://stackoverflow.com/a/12525165/119849
#!/usr/bin/env python
import base64
from Crypto import Random
from Crypto.Cipher import AES
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]