Skip to content

Instantly share code, notes, and snippets.

redmoses redmoses

Block or report user

Report or block redmoses

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@redmoses
redmoses / Makefile
Last active Mar 5, 2016
Flaskshell Makefile
View 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 Mar 5, 2016
Flaskshell docker file
View Dockerfile
FROM ubuntu:trusty
MAINTAINER Red Moses <musa@redmoses.me>
# 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 Mar 5, 2016
Flaskshell docker-compose file
View docker-compose.yml
nginx:
image: nginx:latest
container_name: flaskshell_nginx
ports:
- "80:80"
volumes_from:
- app
links:
- app:app
volumes:
@redmoses
redmoses / app.py
Last active Aug 15, 2018
Using Flask to run shell commands
View app.py
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 Dec 19, 2015
Gunicorn Example
View server.py
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 Dec 19, 2015
Ladon Service Example App
View calculator.py
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 Feb 28, 2016
SSH tunnelling using dynamic proxy
View Proxy-README.md

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
View downloader.py
"""
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
View Nginx Configuration
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 Aug 29, 2015
AWS Instance Creator
View __init__.py
# So that python treats the directory as a package and config.py can be imported
__author__ = 'Musa Nasrullah'
You can’t perform that action at this time.