This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def post_worker_init(worker): | |
env = { | |
'REQUEST_METHOD': 'GET', | |
'PATH_INFO': '/_status', | |
} | |
def start_response(*args, **kwargs): | |
_send_udp(args[0]) | |
worker.wsgi(env, start_response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from werkzeug.wrappers import Request, Response | |
@Request.application | |
def application(request): | |
resp = Response('Hello World!') | |
if request.path == '/_status': | |
resp.status = '200 OK' | |
else: | |
resp.status ='404 Not Found' | |
return resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
def post_worker_init(worker): | |
_send_udp('200 OK\n') | |
def _send_udp(message): | |
udp_ip = "127.0.0.1" | |
udp_port = 4012 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo 'Killing children of ' $1; | |
children=$(pgrep -P $1) | |
for child in $children | |
do | |
echo 'Killing' $child | |
kill $child | |
response=$(timeout 60 nc -w 0 -ul 4012) | |
if [ "$response" != '200 OK' ]; then | |
echo 'BROKEN' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def draw_faces(image_, faces): | |
"Draw a rectangle around each face discovered" | |
image = image_.copy() | |
drawable = ImageDraw.Draw(image) | |
for x, y, w, h in faces: | |
absolute_coords = (x, y, x + w, y + h) | |
drawable.rectangle(absolute_coords) | |
return image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
face_buffer = 0.5 * (target_height - all_faces_height) | |
top_of_crop = top_of_faces - face_buffer | |
coords = (0, top_of_crop, target_width, top_of_crop + target_height) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def faces_from_pil_image(pil_image): | |
"Return a list of (x,y,h,w) tuples for faces detected in the PIL image" | |
storage = cv.CreateMemStorage(0) | |
facial_features = cv.Load('haarcascade_frontalface_alt.xml', storage=storage) | |
cv_im = cv.CreateImageHeader(pil_image.size, cv.IPL_DEPTH_8U, 3) | |
cv.SetData(cv_im, pil_image.tostring()) | |
faces = cv.HaarDetectObjects(cv_im, facial_features, storage) | |
# faces includes a `neighbors` field that we aren't going to use here | |
return [f[0] for f in faces] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PIL import Image, ImageDraw | |
try: | |
import cv | |
except ImportError: | |
print 'Could not import cv, trying opencv' | |
import opencv.cv as cv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
import pika | |
from pika.adapters.tornado_connection import TornadoConnection | |
except ImportError: | |
pika = None | |
try: | |
import tornado | |
import tornado.ioloop | |
except ImportError: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT "metric", 1+1; | |
SELECT "now", NOW(); |