Skip to content

Instantly share code, notes, and snippets.

@malefs
malefs / Python3, Pip3, Virtualenv and Virtualenvwrapper Setup
Created October 15, 2018 15:31 — forked from IamAdiSri/Python3, Pip3, Virtualenv and Virtualenvwrapper Setup
Setting up and using Python3, Pip3, Virtualenv (for Python3) and Virtualenvwrapper (for Python3)
First install pip for Python2. Download the get-pip.py file from https://bootstrap.pypa.io/get-pip.py
$ cd <download location>
$ sudo -H python ./get-pip.py
Installing pip also installs Python3
To run Python3
$ python3
Install pip3 by just executing the same file as in the step above, but this time using Python3
$ sudo -H python3 ./get-pip.py
@malefs
malefs / mongo_test_restaurants.py
Created October 4, 2018 05:54 — forked from vinovator/mongo_test_restaurants.py
Script to interact with MongoDB using pymongo driver
# mongo_test_restaurants.py
# Python 2.7.6
"""
Test script to connect to MongoDB collections using pymongo library
Connects to an already imported connection named "restaurants"
source - https://docs.mongodb.org/getting-started/python/
"""
from pymongo import MongoClient, ASCENDING, DESCENDING
@malefs
malefs / gist:a37cc9744ddd97305f3cd2579c25aa10
Created October 4, 2018 05:52 — forked from ealogar/gist:6698348
tutorial of pymongo: - Recommendations of use - Examples - Useful readings
#-*- coding: utf-8 -*-
u"""
MOD: pymongo
"""
import pymongo
#===============================================================================
# -*- coding: utf-8 -*-
import paho.mqtt.client as mqtt
import time
import json
import base64
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
dev_eui = 'ZZZZZ'
#!/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:
@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
@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 / 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 / setup.md
Created May 28, 2018 10:50 — forked from davidbradway/setup.md
Set Up Docker On Raspberry Pi Raspbian Stretch Lite
@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