Skip to content

Instantly share code, notes, and snippets.

View rtt's full-sized avatar
🚍
' DROP TABLE user_statuses; --

Rich Taylor rtt

🚍
' DROP TABLE user_statuses; --
View GitHub Profile
@rtt
rtt / average_image_color.py
Created April 24, 2012 12:50 — forked from olooney/average_image_color.py
Average Image Color
from PIL import Image
def average_image_color(filename):
i = Image.open(filename)
h = i.histogram()
# split into red, green, blue
r = h[0:256]
g = h[256:256*2]
b = h[256*2: 256*3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pamhutils/messaging/models.py", line 15, in send
with JSONAMQPPublisher(amqp_dsn=amqp_dsn, queue=queue) as publisher:
File "pamhutils/amqp/publishers.py", line 12, in __init__
self.setup()
File "pamhutils/amqp/publishers.py", line 32, in setup
promise = self.client.queue_declare(queue=self.queue, durable=True)
File "/Users/rtt/.../pamhutils/lib/python2.7/site-packages/puka/client.py", line 19, in wrapper
p = method(*args, **kwargs)
@rtt
rtt / gist:3499898
Created August 28, 2012 16:23
Itempath
def itempath(pth, obj):
"""Evaluate a dotted 'item path' on object"""
parts = pth.split('.', 1)
try:
parts[0] = int(parts[0])
except ValueError:
pass
if len(parts) == 1:
return obj[parts[0]]
func DecodeJsonToDocCollection (blob []byte) *DocumentCollection {
var cont interface{}
err := json.Unmarshal(blob, &cont)
if err != nil {
fmt.Println("Decode error")
}
response := cont.(map[string] interface{})["response"]
➜ /Users/richtaylor/go/solr ./solr-example
Query: *:*
Title: adadasdad
Latlng: 51.5171,-0.12
Title: 2143wfads22
Latlng: 51.5171,-0.12
Title: asd213
/*
* Similar to python's itertools.izip_longest;
* takes an array and chunks it according to a given size
*/
func chunk(s []interface{}, sz int) [][]interface{} {
r := [][]interface{}{}
j := len(s)
for i := 0; i < j; i+=sz {
r = append(r, s[i:i+sz])
}
> exit()
Mon Nov 26 11:46:30 ReferenceError: exit is not defined (shell):1
>
>
> qut
Mon Nov 26 11:46:32 ReferenceError: qut is not defined (shell):1
> quit
function () {
return nativeHelper.apply(quit_, arguments);
}
def valid_loc(loc):
'''Validates a lat,lng string value to ensure both lat and lng are within their correct bounds'''
try:
lng, lat = loc.split(',')
lng = float(lng)
lat = float(lat)
except:
pass
else:
@rtt
rtt / gist:4197086
Created December 3, 2012 18:54
php type coercion callback
<?php
$converters = array(
'string' => function($s) { return $s.' boobs'; },
'integer' => function($i) { return $i + 1; }
);
$vals = array(
1 => 1,
'str' => 'moar',