Skip to content

Instantly share code, notes, and snippets.

🚍
' DROP TABLE user_statuses; --

Rich T. rtt

🚍
' DROP TABLE user_statuses; --
Block or report user

Report or block rtt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View average_image_color.py
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]
View gist:3065741
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)
View gist:3499898
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]]
View gist:3800616
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"]
View gist:3800658
➜ /Users/richtaylor/go/solr ./solr-example
Query: *:*
Title: adadasdad
Latlng: 51.5171,-0.12
Title: 2143wfads22
Latlng: 51.5171,-0.12
Title: asd213
View gist:3818158
/*
* 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])
}
View gist:4147818
> 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);
}
View gist:4162266
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 Dec 3, 2012
php type coercion callback
View gist:4197086
<?php
$converters = array(
'string' => function($s) { return $s.' boobs'; },
'integer' => function($i) { return $i + 1; }
);
$vals = array(
1 => 1,
'str' => 'moar',
You can’t perform that action at this time.