Skip to content

Instantly share code, notes, and snippets.

View philipcristiano's full-sized avatar

Philip Cristiano philipcristiano

View GitHub Profile
@philipcristiano
philipcristiano / faces_example.py
Created June 18, 2013 14:10
Resize and crop an image based on OpenCV detected faces
import sys
from PIL import Image, ImageDraw
try:
import cv
except ImportError:
print 'Could not import cv, trying opencv'
import opencv.cv as cv
@philipcristiano
philipcristiano / tornado_queue_connection.py
Last active January 3, 2019 03:23
Simple Tornado/Pika wrapper. Part of an internal library so it raises an error on init instead of importing
try:
import pika
from pika.adapters.tornado_connection import TornadoConnection
except ImportError:
pika = None
try:
import tornado
import tornado.ioloop
except ImportError:
@philipcristiano
philipcristiano / main.yml
Created January 20, 2017 17:00
Route53 Zones per Namespace
--
- name: Create DNS zone
route53_zone:
zone: "{{ item }}.{{ domain }}"
state: present
comment: Created with Ansible
with_items: "{{ dns_zone_namespaces }}"
register: dns_zones
@philipcristiano
philipcristiano / 0_reuse_code.js
Created October 28, 2016 15:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@philipcristiano
philipcristiano / first_value.py
Created September 2, 2013 20:51
Python parse first value
def first_value(l):
for (value, time) in l:
if value is not None:
return value
@philipcristiano
philipcristiano / first_value.erl
Created September 2, 2013 20:39
Retrieve the first non `null` value from Graphite datapoints
first_value([[null,Time]|T]) ->
first_value(T);
first_value([[Value, Time]|T]) ->
{ok, Value};
first_value(_)->
{error, no_value}.
@philipcristiano
philipcristiano / datapoints.erl
Created September 2, 2013 20:35
Graphite Datapoint Parsing
[[null,1378153440],
[1.0,1378153380],
[1.0|...],
[...]|...]
@philipcristiano
philipcristiano / gist:5854546
Last active December 18, 2015 22:29
Gunicorn worker hook with health check
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)
@philipcristiano
philipcristiano / example_app.py
Created June 24, 2013 23:04
Minimal WSGI application
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
@philipcristiano
philipcristiano / gunicorn_hook-py
Last active December 18, 2015 22:28
gunicorn worker hook
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