Skip to content

Instantly share code, notes, and snippets.

View darius's full-sized avatar

Darius Bacon darius

View GitHub Profile
#!/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):
# (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)
"""
no-vowel words: one beat
silent: -e -ed -es[er, usually]
one beat:
ae
ai
au
ea
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
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':
"""
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
"""
machine = assignment*.
assignment = lvalue _? '=' _? expr _? '\n'.
expr = lvalue _ lvalue _ lvalue.
lvalue = name ('.' literal)*.
literal = '0' | '1' | name.
name = /[^.]+/.
_ = /\s+/.
comment = /#.*/.
"""
*** 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
"""
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 = {}
## b = InitialChessBoard()
## print str(b)
#. rnbqkbnr
#. pppppppp
#.
#.
#.
#.
#. PPPPPPPP
#. RNBQKBNR