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
()> app git:(master) ✗ ipython
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
def extract_locale(flask_globals):
def f(endpoint, values):
flask_globals.locale = values.pop('locale', None) if values else localise()
return f
# beware...
def some_func():
return lambda x: x['foo'] == 'bar'
# somewhere else...
filter(some_func, some_iterable)
@rtt
rtt / gist:5029885
Last active January 15, 2022 19:50
python / jinja2 bytecode cache for Redis
from jinja2 import BytecodeCache
class RedisTemplateBytecodeCache(BytecodeCache):
'''Implements a Jinja2 bytecode cache on top of a pyredis.StrictRedis
connection
See: http://jinja.pocoo.org/docs/2.10/api/#bytecode-cache
'''
def __init__(self, redis_cnx, template_cache_key_prefix=None, ttl=86400):
@rtt
rtt / geocoder.php
Last active December 14, 2015 19:18
A Geocoder
<?php
class ReportableHTTPGeocodingFailure extends Exception {}
class HTTPGeocodingFailure extends Exception {}
class GeoLocation {
function __construct($lng, $lat) {
$this->lng = $lng;
$this->lat = $lat;
}
@rtt
rtt / gist:5144366
Last active December 14, 2015 20:29
#!/usr/bin/env bash
sudo pip install pygments simplejson
echo "alias ppjson='python -c \"import simplejson; import sys; print simplejson.dumps(simplejson.loads(sys.stdin.read()), indent=4)\" | pygmentize -f console -l js'" >> ~/.bash_profile
var infinite_scroll_config = {
binder: $(window),
el: '.infinite-scroll',
offset: 750,
in_req: false,
at_end: false
};
var infinite_scroll = function () {
$.fn.slideTo = function(data) {
var width = parseInt($('#slider').css('width'));
var transfer = $('<div class="transfer"></div>').css({ 'width': (2 * width) + 'px' });
var current = $('<div class="current"></div>').css({ 'width': width + 'px', 'left': '0', 'float': 'left' }).html($('#slider').html());
var next = $('<div class="next"></div>').css({ 'width': width + 'px', 'left': width + 'px', 'float': 'left' }).html(data);
transfer.append(current).append(next);
$('#slider').html('').append(transfer);
transfer.animate({ 'margin-left': '-' + width + 'px' }, 300, function () {
$('#slider').html(data);
@rtt
rtt / gist:5875621
Last active December 19, 2015 01:28
simple redis publisher
import redis
import threading
class Worker(threading.Thread):
'''Generic Main Worker class'''
def __init__(self, r, channels):
# init super
threading.Thread.__init__(self)
@rtt
rtt / gist:6079283
Last active December 20, 2015 05:29
trackday

Track day check list

  • Tape
  • Mirror caps
  • Spanner to undo mirrors
  • 14mm Spanner + screwdriver for suspension adjusting + owners handbook
  • Oil (500ml between the two of us?)
  • pressure gauge