Skip to content

Instantly share code, notes, and snippets.

View gist:1830956
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();
View gist:1839734
class CommentForm(f.ModelForm):
class Meta:
model = Review
class CommentCreateView(CreateView):
model = Comment
form_class = CommentForm
def dispatch(self, *args, **kwargs):
View gist:1839730
class ReviewForm(f.ModelForm):
class Meta:
model = Review
class CommentCreateView(CreateView):
model = Comment
form_class = CommentForm
def dispatch(self, *args, **kwargs):
graingert /
Created Mar 23, 2012
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):
View gist:2304275
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",)
View gist:2368857
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)
from django_browserid.views import Verify
from django_browserid.auth import BrowserIDBackend
class EmailNotWhitelistedError(Exception):
def create_user(email):
if email.rsplit('@', 1)[0] in ("",""):
print email
return BrowserIDBackend().create_user(email)
View gist:2416323
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 / gist:2830859
Created May 29, 2012
Finding a communications tree 4
View gist:2830859
if waitB is 0 and no unlabelled pins
send B to Parent //Tell parent we’re done
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
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
urlpatterns = patterns('',
url(r'^$', ReservationCreateView.as_view(), name="index"),