Skip to content

Instantly share code, notes, and snippets.

View redmoses's full-sized avatar

redmoses redmoses

  • Toronto
View GitHub Profile
@redmoses
redmoses / Makefile
Last active March 5, 2016 20:30
Flaskshell Makefile
cont=flaskshell
mysql_cont=flaskshell_mysql
nginx_cont=flaskshell_nginx
mysql_cmd=docker exec -ti $(mysql_cont) mysql -uroot -proot
build:
docker-compose build
prepare:
-@$(mysql_cmd) -e "DROP DATABASE flaskshell; CREATE DATABASE flaskshell;"; \
@redmoses
redmoses / Dockerfile
Created March 5, 2016 20:04
Flaskshell docker file
FROM ubuntu:trusty
MAINTAINER Red Moses <[email protected]>
# create required directories
RUN mkdir -p /app/flaskshell/logs
# create app user
RUN useradd -ms /bin/bash -d /app/flaskshell mr_app
# install system packages
RUN apt-get update; apt-get install -y python3-pip mysql-client supervisor
# copy requirements.pip
COPY config/ /app/flaskshell/config
@redmoses
redmoses / docker-compose.yml
Last active March 5, 2016 20:03
Flaskshell docker-compose file
nginx:
image: nginx:latest
container_name: flaskshell_nginx
ports:
- "80:80"
volumes_from:
- app
links:
- app:app
volumes:
@redmoses
redmoses / app.py
Last active July 2, 2020 09:29
Using Flask to run shell commands
from flask import Flask
from flask import request
import subprocess
app = Flask('flaskshell')
ip_whitelist = ['192.168.1.2', '192.168.1.3']
query_success = "SELECT COUNT(*) FROM flasktest.tasks WHERE task_status='Success'"
query_pending = "SELECT COUNT(*) FROM flasktest.tasks WHERE task_status='Pending'"
query_failed = "SELECT COUNT(*) FROM flasktest.tasks WHERE task_status='Failed'"
@redmoses
redmoses / server.py
Created December 19, 2015 18:03
Gunicorn Example
from __future__ import unicode_literals
import multiprocessing
import gunicorn.app.base
from gunicorn.six import iteritems
from ladon.server.wsgi import LadonWSGIApplication
from os.path import abspath, dirname
# The ladon wsgi application
application = LadonWSGIApplication(
['calculator'],
@redmoses
redmoses / calculator.py
Created December 19, 2015 18:02
Ladon Service Example App
from ladon.ladonizer import ladonize
class Calculator(object):
#ladonize the method
@ladonize(int, int, rtype=int)
def add(self, a, b):
return a + b
@redmoses
redmoses / Proxy-README.md
Last active February 28, 2016 13:33
SSH tunnelling using dynamic proxy

SSH Proxy Script by Red Moses

http://redmoses.me

This script connects to a SSH server to create a dynamic tunnel proxy. I'm assuming you use a private key for authenticating to the server.

Script configuration

To use this script you must first configure it according to your details. I have supplied some dummy values for the configuration fields to start with.

# SSH user
@redmoses
redmoses / downloader.py
Created April 6, 2014 10:37
RSS Downloader
"""
RSS Downloader
~~~~~~~~~~~~~~
The application parses rss feeds from a given url and downloads the files
from the feed to a given output directory.
Features:
~ Resume partially completed download
~ Supports http, and ftp protocols
@redmoses
redmoses / Nginx Configuration
Last active September 1, 2021 07:30
Nginx Tuning
Requirement: Serve around 200 requests/second with with a system of 4 CPU core and 8 Gb of memory
Given Configuration
===============================================================
user www-data;
worker_processes 8;
pid /var/run/nginx.pid;
events {
worker_connections 4096;
@redmoses
redmoses / __init__.py
Last active August 29, 2015 13:58
AWS Instance Creator
# So that python treats the directory as a package and config.py can be imported
__author__ = 'Musa Nasrullah'