Skip to content

Instantly share code, notes, and snippets.

@wilsaj
wilsaj / flaskplotlib.py
Created March 9, 2011 13:09
Example of rendering a matplotlib image directly to Flask view
from flask import Flask, make_response
app = Flask(__name__)
@app.route("/simple.png")
def simple():
import datetime
import StringIO
import random
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
@asimihsan
asimihsan / bokeh-virtualenv-instructions.md
Last active August 29, 2015 13:56
Installing Bokeh in a virtualenv

You can't install Bokeh in a virtualenv without modifying /home/asim.ihsan/Programming/envs/default/lib/python2.7/site.py to add the getsitepackages() from the Python 2.7 version of the file in e.g. /usr/lib64/python2.7/site.py. This is because virtualenv uses a Python 2.6 version of this file. This is an open bug:

pypa/virtualenv#355

In your virtualenv site.py search for addsitepackages() and

@mangecoeur
mangecoeur / concurrent.futures-intro.md
Last active July 20, 2024 10:30
Easy parallel python with concurrent.futures

Easy parallel python with concurrent.futures

As of version 3.3, python includes the very promising concurrent.futures module, with elegant context managers for running tasks concurrently. Thanks to the simple and consistent interface you can use both threads and processes with minimal effort.

For most CPU bound tasks - anything that is heavy number crunching - you want your program to use all the CPUs in your PC. The simplest way to get a CPU bound task to run in parallel is to use the ProcessPoolExecutor, which will create enough sub-processes to keep all your CPUs busy.

We use the context manager thusly:

with concurrent.futures.ProcessPoolExecutor() as executor:
@superjamie
superjamie / raspberry-pi-vpn-router.md
Last active July 2, 2024 07:48
Raspberry Pi VPN Router

Raspberry Pi VPN Router

This is a quick-and-dirty guide to setting up a Raspberry Pi as a "router on a stick" to PrivateInternetAccess VPN.

Requirements

Install Raspbian Jessie (2016-05-27-raspbian-jessie.img) to your Pi's sdcard.

Use the Raspberry Pi Configuration tool or sudo raspi-config to: