Skip to content

Instantly share code, notes, and snippets.

View jaylett's full-sized avatar

James Aylett jaylett

View GitHub Profile
@jaylett
jaylett / multiform_cbv.py
Created February 17, 2011 12:58
CBV for multi-form round trip
class WorkEditView(DetailDisplayView, ModelFormMixin):
"""Shows the edit page for a work."""
get_object = user_check("user_can_edit")(DetailDisplayView.get_object)
queryset = Work.objects.all()
template_resource_name = "work"
template_name = 'artists/work_edit.html'
def get(self, request, *args, **kwargs):
@jaylett
jaylett / restpose.conf
Created September 15, 2011 13:05
Upstart conf for restpose
description "Restpose search server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
script
/usr/bin/setuidgid restpose /usr/bin/restpose -p 7777 -d /var/lib/restpose >> /var/log/restpose.log 2>&1
@jaylett
jaylett / userhelpers.py
Created July 24, 2012 14:50
Django template filters for getting various user-specific things off models
"""
Some simple filters
* `user_can`, which filters an object taking a string
parameter, returning True or False depending on whether the current
user "can" do the action in the parameter. This is done by calling
`user_can_<action>` on the object.
Anonymous users always return `False`.
* `user_has`, which pulls the result of the `user_has_<feature>()`;
@jaylett
jaylett / memoize.py
Created July 27, 2012 10:04
Latest memoize
import functools
import cPickle
from django.conf import settings
# shamelessly stolen from
# http://wiki.python.org/moin/PythonDecoratorLibrary?action=recall&rev=111#Memoize
class memoize(object):
'''Decorator. Caches a function's return value each time it is called.
If called later with the same arguments, the cached value is returned
@jaylett
jaylett / djcelery.plugin.py
Created July 27, 2012 10:24
Django-celery plugin for munin
#!/usr/bin/python
# -*- python-mode -*-
import datetime
import sys
import os
import os.path
if os.path.isdir('/home/af-web/releases/current'):
# live
@jaylett
jaylett / redis.plugin.py
Created July 27, 2012 10:24
Redis plugin for munin
#!/usr/bin/python
# -*- python-mode -*-
import sys
import redis
c = redis.Redis() # if you need a password or to monitor non-defaults...
# We draw a number of graphs:
#
@jaylett
jaylett / elb_status.plugin.py
Created July 27, 2012 10:25
ELB status plugin for munin
#!/usr/bin/python
# -*- python-mode -*-
import boto.ec2.elb
import sys
elbs = [ 'my_elb' ] # or whatever
AWS_ACCESS_KEY_ID = '' # fill this out!
AWS_SECRET_ACCESS_KEY = '' # this too!
@jaylett
jaylett / equi2.py
Last active December 12, 2015 09:39 — forked from tomwolber/equi2.py
tests = [
([-7, 1, 5, 2, -4, 3, 0], [3,6]),
([1, 2, 3, 4, 3, 2, 1], [3]),
([99, 0, 66, 32, 1] , [1]),
([1, -1, 1, -1, 1, -1, 1], [0,1,2,3,4,5,6]),
([0,0,0], [0,1,2]),
([0,53,9], -1),
([0,1,-1], [0]),
([-1, 0, 1], -1),
]
(function() {
var menuOpen = false;
$('.hamburger').click(function(){
if( menuOpen ) {
menuOpen = false;
$('#header ul').slideUp(function() {
$('#header ul').removeAttr("style");
});
} else {
menuOpen = true;
@jaylett
jaylett / gist:6730838
Created September 27, 2013 15:57
restpose build error
make[2]: Entering directory `/media/fort/7e6babdb-eb0b-4e79-b97e-cab980e57e92/wikipedia/restpose/restpose'
/bin/bash ./libtool --tag=CXX --mode=link g++ -Wall -W -Wredundant-decls -Wpointer-arith -Wcast-qual -Wcast-align -Wno-long-long -Wformat-security -fno-gnu-keywords -Wundef -Wshadow -Woverloaded-virtual -Wstrict-null-sentinel -Wshadow -Wstrict-overflow=1 -Winit-self -Wlogical-op -Wmissing-declarations -g -O2 -o restpose src/restpose.o libmongoimporter.a libhttpserver.a librest.a libfeatures.a libserver.a libjsonxapian.a libjsonmanip.a libngramcat.a libcjktokenizer.a liblogger.a libdbgroup.a libutils.a libpostingsources.a libmatchspies.a libgeospatial.a libxapiancommon.a libmongocdriver.a libcli.a libjsoncpp.a libs/libmicrohttpd/src/daemon/libmicrohttpd.la -lxapian
libtool: link: g++ -Wall -W -Wredundant-decls -Wpointer-arith -Wcast-qual -Wcast-align -Wno-long-long -Wformat-security -fno-gnu-keywords -Wundef -Wshadow -Woverloaded-virtual -Wstrict-null-sentinel -Wshadow -Wstrict-overflow=1 -Winit-s