Skip to content

Instantly share code, notes, and snippets.

@malefs
malefs / rest-server.py
Created April 24, 2018 15:05 — forked from miguelgrinberg/rest-server.py
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask.ext.httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
import cv2
import time
import glob
import multiprocessing.pool as mp
def process_img(image_file):
if '_canny.jpg' not in image_file:
print 'processing', image_file
img = cv2.imread(image_file)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
@malefs
malefs / multithreaded_image_scrapper.py
Created April 25, 2018 14:20 — forked from DollarAkshay/multithreaded_image_scrapper.py
Multithreaded Image Scraper in Python (Insanely fast on Ryzen 7)
import cv2
import numpy as np
import urllib.request
import time
import threading
import math
def getPokemon(start, end):
print("Started worker for range :", start, "to", end)
@malefs
malefs / MC Cheat Sheet
Created April 26, 2018 14:00 — forked from samiraguiar/MC Cheat Sheet
Midnight Commander Cheat Sheet
Shortcut Description
---------------------------------------------------------------
C-o Drop to the console
Insert Select/deselect file
* Invert selection on files
+ Specify file selection options (including custom pattern)
- The same as above, but for deselecting
F5/F6 Copy/move selected files
@malefs
malefs / flask_nginx_gunicorn.md
Created May 25, 2018 19:33 — forked from xaratustrah/flask_nginx_gunicorn.md
Flask nginx gunicorn Raspberry Pi

Python Flask + nginx + gunicorn

Setting up a python flask web application using nginx, gunicorn and systemd on a Rasperry Pi

In the following, we assume a working Flask application with the name of SCRIPT_NAME. First we need to install a couple of things:

sudo apt-get update && sudo apt-get upgrade

Installing nginx will fail if apache is running. If your installation breaks half ways, then remove the fragments, stop apache (and I actually suggest removing it in case not needed) and then install nginx again:

sudo apt-get remove nginx* --purge

sudo /etc/init.d/apache2 stop

@malefs
malefs / setup.md
Created May 28, 2018 10:50 — forked from davidbradway/setup.md
Set Up Docker On Raspberry Pi Raspbian Stretch Lite
@malefs
malefs / motion_215.py
Created May 31, 2018 12:47 — forked from waveform80/motion_215.py
Motion detection with a circular buffer and file recording in picamera
#!/usr/bin/env python
import io
import time
import picamera
import picamera.array
import numpy as np
from PIL import Image, ImageDraw
@malefs
malefs / docker.md
Created June 1, 2018 09:58 — forked from developerinlondon/docker.md
Docker saving and loading images

Here's how to save and load docker images:

Example scenario: To save a docker image from a docker repository and save it as a tar file locally.

  1. Save the image as a tarball

docker save repositoryname:tag > repotag.tar

  1. Zip the image
@malefs
malefs / server.py
Created June 12, 2018 13:59 — forked from peterkuma/server.py
A flask server for serving all JPEG images in a local directory and subdirectories. Uses unveil.js for lazy-loading of images. Thumbnails are created on the fly by PIL.
#!/bin/python
import os
from flask import Flask, Response, request, abort, render_template_string, send_from_directory
import Image
import StringIO
app = Flask(__name__)
WIDTH = 1000
#!/bin/bash
##
# File:
# nginx_modsite
# Description:
# Provides a basic script to automate enabling and disabling websites found
# in the default configuration directories:
# /etc/nginx/sites-available and /etc/nginx/sites-enabled
# For easy access to this script, copy it into the directory: