Skip to content

Instantly share code, notes, and snippets.

public Set<String> signatureToWords(String signature){
Set<String> words = new HashSet<String>();
int index = (Collections.binarySearch(dictionary, new WordSig("", signature))*-1-2);
//System.out.println("Index: "+index);
int x = index;
String currentSig = dictionary.get(x).getSig();
String currentWord = dictionary.get(x).getWords();
/**
if(PredictivePrototype.isValidWord(currentWord)){
words.add(currentWord.toLowerCase());
class CommentForm(f.ModelForm):
class Meta:
model = Review
class CommentCreateView(CreateView):
model = Comment
form_class = CommentForm
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
class ReviewForm(f.ModelForm):
class Meta:
model = Review
class CommentCreateView(CreateView):
model = Comment
form_class = CommentForm
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
@graingert
graingert / http.py
Created March 23, 2012 10:19
generic http exception middlware
#encoding: UTF-8
from django.conf import settings
from django.core.exceptions import ViewDoesNotExist
from django.http import HttpResponse
from django.template import RequestContext,Template,loader,TemplateDoesNotExist
from django.utils.importlib import import_module
import httplib
class HttpException(Exception):
from django.forms import ModelForm, HiddenInput, MultipleHiddenInput, Textarea
from models import Thing, Review, UserProfile
from rays.widgets import RangeInput
class ReviewForm(ModelForm):
mentioned = Textarea()
class Meta:
model = Review
exclude = ("author",)
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"),
)