Skip to content

Instantly share code, notes, and snippets.

import random
import copy
ALPHABET = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z", " "]
class Scrambler:
"""A single scrambler unit"""
def __init__(self, seed):
self.routes = range(len(ALPHABET))
random.seed(seed)
random.shuffle(self.routes)
import random
import copy
ALPHABET = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z", " "]
class Scrambler:
"""A single scrambler unit"""
def __init__(self, seed):
self.routes = range(len(ALPHABET))
random.seed(seed)
random.shuffle(self.routes)
# -*- coding: utf-8 -*-
"horfunk.radiopirate models and events handlers"
import datetime
import os
import logging
from django.db import models
from django.contrib.auth.models import User
String template = Exercise 1: Negate a tree (5%%)\n\n" //usually /n's are at the end of the line
+"original tree: \n%s\n"
+"original tree negated: \n%s\n"
+"original tree negated twice (same as original): \n%s\n"
+"empty tree: \n%s\n";
System.out.println();
System.out.printf(template, TreeOps.toString(x), Ex2.negateAll(x), Ex2.negateAll(Ex2.negateAll(x)), Ex2.negateAll(new Tree()));
@graingert
graingert / 1a.java
Created February 10, 2012 16:49 — forked from anonymous/1a.java
/**
* @param word String to be turned into T9 code
* @return the T9 code of the input string
*
* Method returns the order of buttons of digipad buttons to be pressed to
* get the input String from a T9 predictive text dictionary.
*
* This method assumes the order of the buttons is as follows and ignores case:
*
* 2= a,b,c
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 ReviewForm(f.ModelForm):
class Meta:
model = Review
class CommentCreateView(CreateView):
model = Comment
form_class = CommentForm
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
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):
@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",)