# HG changeset patch # User Jeff Hammel # Date 1388264166 28800 # Node ID d4522af2c6e5126c933eb8756cb7a24f3b5bd6d5 # Parent cb1d2164858873bde041d1de3d6acf88586b6d1d refactor diff -r cb1d21648588 -r d4522af2c6e5 bitsyauth/dictionary.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bitsyauth/dictionary.py Sat Dec 28 12:56:06 2013 -0800 @@ -0,0 +1,29 @@ +import random + +class Dictionary(object): + def __init__(self, dictionary_file='/usr/share/dict/american-english'): + self.dictionary_file = dictionary_file + with open(dictionary_file) as f: + self.wordlist = [] + for line in f: + line = line.strip() + if not line or not line.isalpha(): + continue + line = line.lower() + self.wordlist.append(line) + self.wordlist = tuple(self.wordlist) + self._min_lengths = {} + + def random_word(self, min_length=5): + """ + choose random word + + min_length -- minimum word length + """ + + if min_length not in self._min_lengths: + # cache + self._min_lengths[min_lengths] = [i for i in self.wordlist + if len(i) > min_length] + return random.Random().choice(self._min_lengths[min_length]) + diff -r cb1d21648588 -r d4522af2c6e5 example/persona.html --- a/example/persona.html Fri Dec 27 20:13:04 2013 -0800 +++ b/example/persona.html Sat Dec 28 12:56:06 2013 -0800 @@ -47,11 +47,13 @@ } }); + var signinLink = document.getElementById('signin'); if (signinLink) { -signinLink.onclick = function() { navigator.id.request(); +signinLink.onclick = function() { +navigator.id.request(); nclicks += 1; -$('clickcounter').append('
  • This is click ' + nclicks + '
  • '); +$('#clickcounter').append('
  • This is click ' + nclicks + '
  • '); }; }