This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import string | |
DICT_FILE = '/usr/share/dict/words' | |
def get_matches(word, guess): | |
word_set = set([c for c in word]) | |
guess_set = set([c for c in guess]) | |
return len(word_set.intersection(guess_set)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/usr/bin/env python | |
# coding: utf-8 | |
# http://en.wikipedia.org/wiki/Tower_of_Hanoi#Binary_solution | |
def iterative_hanoi(n): | |
# Optimal play will result in (2^n)-1 moves. This is a pretty fun proof! | |
total_moves = pow(2, n) - 1 | |
for i in range(total_moves): | |
start = (i & i+1) % 3 | |
end = ((i | i+1)+1) % 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Fixes newline endings created in Windows. Run in Unix.""" | |
for i in range(1, 17): | |
output_path = '../output{}.txt'.format(i) | |
with open(output_path, 'r') as output_file: | |
sequence = output_file.readline().strip() | |
with open(output_path, 'w') as output_file: | |
output_file.write(sequence + '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here's the current folder hierarchy: | |
- run.py | |
- util/ | |
- __init__.py | |
- entry.py | |
- winrate.py | |
Let's say winrate.py straight up imports entry: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def copy(lst): | |
"""Returns a copy of the linked list.""" | |
if lst.rest is Link.empty: | |
return Link(lst.first) | |
else: | |
return Link(lst.first, copy(lst.rest)) | |
def repeat(lst, n): | |
if n == 0: | |
return Link.empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import json | |
def main(): | |
with open('messages.htm', 'r') as infile: | |
soup = BeautifulSoup(infile) | |
bchus = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
def fix(s): | |
return s.strip().lower().translate(string.maketrans('', ''), string.punctuation) | |
print(fix(" He@#@LL%^O WorL@#D@$")) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise = require 'bluebird' | |
bcrypt = Promise.promisifyAll(require 'bcrypt') | |
bookshelf = require 'app/utils/db' | |
logger = require 'app/utils/logger' | |
User = bookshelf.Model.extend | |
tableName: 'users' | |
hasTimestamps: ['createdAt', 'updatedAt'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it 'should fail authentication with an incorrect password', (done) -> | |
userMock.create() | |
.then (user) -> | |
return user.save() | |
.then (model) -> | |
return User.login model.get('email'), 'xyzzy' | |
.then (match) -> | |
expect(match).to.be.false | |
done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it 'should authenticate with correct password', (done) -> | |
unhashed = null | |
userMock.create() | |
.then (user) -> | |
unhashed = user.get 'password' | |
return user.save() | |
.then (model) -> | |
return User.login model.get('email'), unhashed | |
.then (match) -> |
OlderNewer