Skip to content

Instantly share code, notes, and snippets.

View gist:1147447
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)
View gist:1147493
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)
View gist:1157299
# -*- 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
View printf
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()));
View 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
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();
/**
if(PredictivePrototype.isValidWord(currentWord)){
words.add(currentWord.toLowerCase());
View gist:1839730
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):
View gist:1839734
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 Mar 23, 2012
generic http exception middlware
View http.py
#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",)