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 | |
""" | |
Given Python2 source files, print out all the string literals that look | |
like they were meant to be raw strings, but are ordinary strings instead. | |
Exit status: 1 if any warnings, else 0. | |
""" | |
import token, tokenize | |
def main(argv): |
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
# (Python 2) | |
# Developed from an example by Dave Long, but don't blame him! | |
from dis import cmp_op, dis, hascompare, hasjabs, hasjrel, opmap, HAVE_ARGUMENT | |
from itertools import chain | |
import types | |
class Clutch(object): | |
def __init__(self, *args, **kwargs): | |
for arg in args: setattr(self, arg.__name__, arg) |
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
""" | |
no-vowel words: one beat | |
silent: -e -ed -es[er, usually] | |
one beat: | |
ae | |
ai | |
au | |
ea |
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
http://wry.me/hacking/dequebot/demo.html | |
OK, not sure what to do next. Things I have in mind: | |
- Values on the left as a stack | |
- Primitives parameterized by those values | |
- bf<> | |
- +-*/~ (~ is reciprocal) | |
- = (how do we say 'less than'?) | |
- Digits push numbers, and we need ',' or ' ' to separate them |
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 main(): | |
board = Board() | |
with Terminal() as ui: | |
keys = ui.gen_key_events() | |
while True: | |
ui.render(board.view()) | |
if board.ended(): | |
break | |
for k in keys: | |
if k == '^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
""" | |
Generate a random token. | |
""" | |
# After reading Zooko's, I was like oops, I'm an idiot. | |
# I should probably use his, but anyway here's a fix: | |
# correct cryptogen.sample() to cryptogen.choice(). | |
import math | |
from random import SystemRandom |
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
""" | |
machine = assignment*. | |
assignment = lvalue _? '=' _? expr _? '\n'. | |
expr = lvalue _ lvalue _ lvalue. | |
lvalue = name ('.' literal)*. | |
literal = '0' | '1' | name. | |
name = /[^.]+/. | |
_ = /\s+/. | |
comment = /#.*/. |
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
""" | |
*** OBSOLETE | |
*** SEE FIXED FORK: http://gist.github.com/375850 | |
Test out 20 binary-search functions harvested from | |
http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/ | |
See results at the bottom. | |
""" | |
import random |
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
""" | |
Test out 20 binary-search functions harvested from | |
http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/ | |
See results at the bottom. | |
""" | |
import random | |
failures = {} |
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
## b = InitialChessBoard() | |
## print str(b) | |
#. rnbqkbnr | |
#. pppppppp | |
#. | |
#. | |
#. | |
#. | |
#. PPPPPPPP | |
#. RNBQKBNR |
OlderNewer